[clang] a5ab650 - [clang] Fix a crash in constant evaluation

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 31 01:09:39 PDT 2022


Author: Kadir Cetinkaya
Date: 2022-08-31T10:09:24+02:00
New Revision: a5ab650714d05c2e49ec158dc99156118a893027

URL: https://github.com/llvm/llvm-project/commit/a5ab650714d05c2e49ec158dc99156118a893027
DIFF: https://github.com/llvm/llvm-project/commit/a5ab650714d05c2e49ec158dc99156118a893027.diff

LOG: [clang] Fix a crash in constant evaluation

This was showing up in our internal crash collector. I have no idea how
to test it out though, open for suggestions if there are easy paths but
otherwise I'd move forward with the patch.

Differential Revision: https://reviews.llvm.org/D132918

Added: 
    

Modified: 
    clang/lib/AST/ExprConstant.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 3df0e4292b6ca..2b1a30f8354fb 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -4794,6 +4794,11 @@ static bool getDefaultInitValue(QualType T, APValue &Result) {
       Result = APValue((const FieldDecl *)nullptr);
       return true;
     }
+    // Can't access properties of an incomplete type.
+    if (!RD->hasDefinition()) {
+      Result = APValue();
+      return false;
+    }
     Result = APValue(APValue::UninitStruct(), RD->getNumBases(),
                      std::distance(RD->field_begin(), RD->field_end()));
 


        


More information about the cfe-commits mailing list