Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang][bytecode] Fix reporting non-constant variables in C #109516

Merged
merged 1 commit into from
Sep 21, 2024

Conversation

tbaederr
Copy link
Contributor

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

We need to call FFDiag() to get the usual "invalid subexpression"
diagnostic.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 21, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 21, 2024

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/109516.diff

2 Files Affected:

  • (modified) clang/lib/AST/ByteCode/Interp.cpp (+4-2)
  • (modified) clang/test/Sema/annotate-type.c (+1)
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 17cf3ccdeb6a94..d8e9fa838abaa8 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();
 

@tbaederr tbaederr merged commit c57b9f5 into llvm:main Sep 21, 2024
11 checks passed
augusto2112 pushed a commit to augusto2112/llvm-project that referenced this pull request Sep 26, 2024
)

We need to call FFDiag() to get the usual "invalid subexpression"
diagnostic.
xgupta pushed a commit to xgupta/llvm-project that referenced this pull request Oct 4, 2024
)

We need to call FFDiag() to get the usual "invalid subexpression"
diagnostic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants