Author: Haojian Wu Date: 2022-04-26T10:08:30+02:00 New Revision: d6f9000ecabeca5819f4f03d774548c7cbb1ff21
URL: https://github.com/llvm/llvm-project/commit/d6f9000ecabeca5819f4f03d774548c7cbb1ff21 DIFF: https://github.com/llvm/llvm-project/commit/d6f9000ecabeca5819f4f03d774548c7cbb1ff21.diff LOG: [clang] Fix a constant evaluator crash on a NULL-type expr. Differential Revision: https://reviews.llvm.org/D124384 Added: Modified: clang/lib/AST/ExprConstant.cpp clang/test/SemaCXX/recovery-expr-type.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 3ad44d5e2da80..70a1e0bbd91aa 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -8631,7 +8631,7 @@ static bool evaluateLValueAsAllocSize(EvalInfo &Info, APValue::LValueBase Base, return false; const Expr *Init = VD->getAnyInitializer(); - if (!Init) + if (!Init || Init->getType().isNull()) return false; const Expr *E = Init->IgnoreParens(); diff --git a/clang/test/SemaCXX/recovery-expr-type.cpp b/clang/test/SemaCXX/recovery-expr-type.cpp index 94b275c9a362f..3db11466529e1 100644 --- a/clang/test/SemaCXX/recovery-expr-type.cpp +++ b/clang/test/SemaCXX/recovery-expr-type.cpp @@ -151,3 +151,13 @@ enum Circular { // expected-note {{not complete until the closing '} // Enumerators can be evaluated (they evaluate as zero, but we don't care). static_assert(Circular_A == 0 && Circular_A != 0, ""); // expected-error {{static_assert failed}} } + +namespace test14 { +extern "C" void *memset(void *, int b, unsigned long) { + int * const c(undef()); // expected-error {{undeclared identifier}} + // Verify we do not crash on evaluating *c whose initializer is a NULL-type ParenListExpr! + memset(c, 0, *c); // crash1 + + b = __builtin_object_size(c, 0); // crash2 +} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits