[clang] 4a10069 - Fix a failing assertion when emitting a note diagnostic

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Jul 20 09:52:25 PDT 2023


Author: Aaron Ballman
Date: 2023-07-20T12:49:39-04:00
New Revision: 4a100690461022625dc5d2a21e2e028a926149d9

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

LOG: Fix a failing assertion when emitting a note diagnostic

When noting the previous declaration for a builtin, the diagnostic
expects two arguments, but none were being passed. We now pass
arguments for the note (and the arguments are unused for several of the
possible notes we emit, but that is something the diagnostic engine is
fine with).

Fixes https://github.com/llvm/llvm-project/issues/63967

Added: 
    

Modified: 
    clang/lib/Sema/SemaDecl.cpp
    clang/test/SemaCXX/builtins.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0cbf608fc2be10..8db77f8558083c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3696,10 +3696,10 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
       !canRedefineFunction(Old, getLangOpts())) {
     if (getLangOpts().MicrosoftExt) {
       Diag(New->getLocation(), diag::ext_static_non_static) << New;
-      Diag(OldLocation, PrevDiag);
+      Diag(OldLocation, PrevDiag) << Old << Old->getType();
     } else {
       Diag(New->getLocation(), diag::err_static_non_static) << New;
-      Diag(OldLocation, PrevDiag);
+      Diag(OldLocation, PrevDiag) << Old << Old->getType();
       return true;
     }
   }
@@ -4386,7 +4386,7 @@ static void diagnoseVarDeclTypeMismatch(Sema &S, VarDecl *New, VarDecl* Old) {
   SourceLocation OldLocation;
   std::tie(PrevDiag, OldLocation)
     = getNoteDiagForInvalidRedeclaration(Old, New);
-  S.Diag(OldLocation, PrevDiag);
+  S.Diag(OldLocation, PrevDiag) << Old << Old->getType();
   New->setInvalidDecl();
 }
 

diff  --git a/clang/test/SemaCXX/builtins.cpp b/clang/test/SemaCXX/builtins.cpp
index 82d1820bf9f31b..af6e565100aaeb 100644
--- a/clang/test/SemaCXX/builtins.cpp
+++ b/clang/test/SemaCXX/builtins.cpp
@@ -165,3 +165,7 @@ template<typename T> void test_builtin_complex(T v, double d) {
 template void test_builtin_complex(double, double);
 template void test_builtin_complex(float, double); // expected-note {{instantiation of}}
 template void test_builtin_complex(int, double); // expected-note {{instantiation of}}
+
+// This previously would cause an assertion when emitting the note diagnostic.
+static void _mm_sfence(); // expected-error {{static declaration of '_mm_sfence' follows non-static declaration}} \
+                             expected-note {{'_mm_sfence' is a builtin with type 'void () noexcept'}}


        


More information about the cfe-commits mailing list