[clang] 46ad7ff - [clang][bytecode] Diagnose non-const initialiers in diagnoseUnknownDecl (#113276)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 22 20:50:33 PDT 2024


Author: Timm Baeder
Date: 2024-10-23T05:50:30+02:00
New Revision: 46ad7ff4b78fd7e6540d9eebe7e17ae423b29dd9

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

LOG: [clang][bytecode] Diagnose non-const initialiers in diagnoseUnknownDecl (#113276)

This is more similar to the diagnostic output of the current interpreter

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp
    clang/test/SemaCXX/c99-variable-length-array.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index fdc4b38b8aa6dc..b7a6c224c80f8e 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -81,11 +81,17 @@ static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC,
     return false;
   }
 
-  if (!D->getType().isConstQualified())
+  if (!D->getType().isConstQualified()) {
     diagnoseNonConstVariable(S, OpPC, D);
-  else if (const auto *VD = dyn_cast<VarDecl>(D);
-           VD && !VD->getAnyInitializer())
-    diagnoseMissingInitializer(S, OpPC, VD);
+  } else if (const auto *VD = dyn_cast<VarDecl>(D)) {
+    if (!VD->getAnyInitializer()) {
+      diagnoseMissingInitializer(S, OpPC, VD);
+    } else {
+      const SourceInfo &Loc = S.Current->getSource(OpPC);
+      S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
+      S.Note(VD->getLocation(), diag::note_declared_at);
+    }
+  }
 
   return false;
 }

diff  --git a/clang/test/SemaCXX/c99-variable-length-array.cpp b/clang/test/SemaCXX/c99-variable-length-array.cpp
index 82ddb0fd2e2337..d9eb65e4355c31 100644
--- a/clang/test/SemaCXX/c99-variable-length-array.cpp
+++ b/clang/test/SemaCXX/c99-variable-length-array.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wvla-extension %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wvla-extension %s -fexperimental-new-constant-interpreter
 struct NonPOD {
   NonPOD();
 };


        


More information about the cfe-commits mailing list