Skip to content

[clang][bytecode] Diagnose invalid declrefs differently if we've... #113140

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

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6097,7 +6097,8 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {

if (VD->evaluateValue())
return revisit(VD);
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E), E);
return this->emitInvalidDeclRef(cast<DeclRefExpr>(E),
/*InitializerFailed=*/true, E);
}
}
} else {
Expand All @@ -6123,7 +6124,7 @@ bool Compiler<Emitter>::visitDeclRef(const ValueDecl *D, const Expr *E) {
}

if (const auto *DRE = dyn_cast<DeclRefExpr>(E))
return this->emitInvalidDeclRef(DRE, E);
return this->emitInvalidDeclRef(DRE, /*InitializerFailed=*/false, E);
return false;
}

Expand Down
13 changes: 11 additions & 2 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2818,9 +2818,18 @@ inline bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind,
return false;
}

inline bool InvalidDeclRef(InterpState &S, CodePtr OpPC,
const DeclRefExpr *DR) {
inline bool InvalidDeclRef(InterpState &S, CodePtr OpPC, const DeclRefExpr *DR,
bool InitializerFailed) {
assert(DR);

if (InitializerFailed) {
const SourceInfo &Loc = S.Current->getSource(OpPC);
const auto *VD = cast<VarDecl>(DR->getDecl());
S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
S.Note(VD->getLocation(), diag::note_declared_at);
return false;
}

return CheckDeclRef(S, OpPC, DR);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ByteCode/Opcodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ def InvalidCast : Opcode {
}

def InvalidDeclRef : Opcode {
let Args = [ArgDeclRef];
let Args = [ArgDeclRef, ArgBool];
}

def SizelessVectorElementSize : Opcode;
Expand Down
13 changes: 13 additions & 0 deletions clang/test/AST/ByteCode/openmp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=expected,both -fopenmp %s
// RUN: %clang_cc1 -verify=ref,both -fopenmp %s

int test1() {
int i;
int &j = i; // both-note {{declared here}}
float *f;
// both-note@+2 {{initializer of 'j' is not a constant expression}}
// both-error@+1 {{integral constant expression}}
#pragma omp for simd aligned(f:j)
for (int i = 0; i < 10; ++i);
}

Loading