diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 763bc3ac15932..f2f6988a1f5c1 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -505,6 +505,8 @@ Bug Fixes to C++ Support - Fix a crash when parsing a pseudo destructor involving an invalid type. (#GH111460) - Fixed an assertion failure when invoking recovery call expressions with explicit attributes and undeclared templates. (#GH107047, #GH49093) +- Fixed a compiler crash that occurred when processing malformed code involving `sizeof` with + an invalid type argument. (#GH111594) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 4e37385710af5..b0bd216c5dc10 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4629,6 +4629,9 @@ ExprResult Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, TInfo->getType()->isVariablyModifiedType()) TInfo = TransformToPotentiallyEvaluated(TInfo); + if (!TInfo) + return ExprError(); + // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t. return new (Context) UnaryExprOrTypeTraitExpr( ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd()); diff --git a/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp new file mode 100644 index 0000000000000..900fb8aa332f5 --- /dev/null +++ b/clang/test/SemaCXX/unary-expr-or-type-trait-invalid.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused-value %s +// +// Note: This test is ensure the code does not cause a crash as previously +// reported in (#GH111594). The specific diagnostics are unimportant. + +a() {struct b c (sizeof(b * [({ {tree->d* next)} 0 + +// expected-error@6 0+{{}} +// expected-error@11 0+{{}} +// expected-note@6 0+{{}} +