[clang] f5b5426 - [clang] Fix a crash on CheckArgAlignment.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Wed May 19 04:29:44 PDT 2021


Author: Haojian Wu
Date: 2021-05-19T13:29:28+02:00
New Revision: f5b5426433c9e6c24615ef1286d72c527b0b15dd

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

LOG: [clang] Fix a crash on CheckArgAlignment.

We might encounter an undeduced type before calling getTypeAlignInChars.

NOTE: this retrieves the fix from
8f80c66bd2982788a8eede4419684ca72f48b9a2, which was removed in Adam's
followup fix fbfcfdbf6828b8d36f4ec0ff5f4eac11fb1411a5. We originally
thought the crash was caused by recovery-ast, but it turns out it can
occur for other cases, e.g. typo-correction.

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaChecking.cpp
    clang/test/SemaCXX/typo-correction-crash.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f3f1ccd77528..5daa88dcdbe1 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4571,7 +4571,8 @@ void Sema::CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl,
 
   // Find expected alignment, and the actual alignment of the passed object.
   // getTypeAlignInChars requires complete types
-  if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType())
+  if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() ||
+      ParamTy->isUndeducedType() || ArgTy->isUndeducedType())
     return;
 
   CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);

diff  --git a/clang/test/SemaCXX/typo-correction-crash.cpp b/clang/test/SemaCXX/typo-correction-crash.cpp
index 49ea4c1bf16c..2a77c9df505e 100644
--- a/clang/test/SemaCXX/typo-correction-crash.cpp
+++ b/clang/test/SemaCXX/typo-correction-crash.cpp
@@ -42,3 +42,12 @@ class S {
   }
 };
 }
+
+namespace NoCrashOnCheckArgAlignment {
+template <typename a> void b(a &);
+void test() {
+  for (auto file_data :b(files_db_data)); // expected-error {{use of undeclared identifier 'files_db_data'; did you mean 'file_data'?}} \
+                                          // expected-note {{'file_data' declared here}} \
+                                          // expected-error {{cannot use type 'void' as a range}}
+}
+}


        


More information about the cfe-commits mailing list