Author: Timm Baeder
Date: 2024-09-21T09:58:56+02:00
New Revision: c57b9f5a138d9a7ce0744e4fdb85ff31dc5f2cac

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

LOG: [clang][bytecode] Fix reporting non-constant variables in C (#109516)

We need to call FFDiag() to get the usual "invalid subexpression"
diagnostic.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp
    clang/test/Sema/annotate-type.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 65b4c0a9cb7660..ede52de1c5e7b2 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -90,10 +90,12 @@ static bool diagnoseUnknownDecl(InterpState &S, CodePtr 
OpPC,
 
 static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
                                      const ValueDecl *VD) {
-  if (!S.getLangOpts().CPlusPlus)
+  const SourceInfo &Loc = S.Current->getSource(OpPC);
+  if (!S.getLangOpts().CPlusPlus) {
+    S.FFDiag(Loc);
     return;
+  }
 
-  const SourceInfo &Loc = S.Current->getSource(OpPC);
   if (const auto *VarD = dyn_cast<VarDecl>(VD);
       VarD && VarD->getType().isConstQualified() &&
       !VarD->getAnyInitializer()) {

diff  --git a/clang/test/Sema/annotate-type.c b/clang/test/Sema/annotate-type.c
index 901cef7ffa8b3a..bf1632d302e554 100644
--- a/clang/test/Sema/annotate-type.c
+++ b/clang/test/Sema/annotate-type.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify
+// RUN: %clang_cc1 %s -fsyntax-only -verify 
-fexperimental-new-constant-interpreter
 
 const char *some_function();
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to