Skip to content

Commit c57b9f5

Browse files
authored
[clang][bytecode] Fix reporting non-constant variables in C (llvm#109516)
We need to call FFDiag() to get the usual "invalid subexpression" diagnostic.
1 parent f5f61c8 commit c57b9f5

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

clang/lib/AST/ByteCode/Interp.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC,
9090

9191
static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
9292
const ValueDecl *VD) {
93-
if (!S.getLangOpts().CPlusPlus)
93+
const SourceInfo &Loc = S.Current->getSource(OpPC);
94+
if (!S.getLangOpts().CPlusPlus) {
95+
S.FFDiag(Loc);
9496
return;
97+
}
9598

96-
const SourceInfo &Loc = S.Current->getSource(OpPC);
9799
if (const auto *VarD = dyn_cast<VarDecl>(VD);
98100
VarD && VarD->getType().isConstQualified() &&
99101
!VarD->getAnyInitializer()) {

clang/test/Sema/annotate-type.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 %s -fsyntax-only -verify
2+
// RUN: %clang_cc1 %s -fsyntax-only -verify -fexperimental-new-constant-interpreter
23

34
const char *some_function();
45

0 commit comments

Comments
 (0)