Skip to content

[clang][bytecode] Simplify diagnoseUnknownDecl if we're not diagnosing #141910

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
May 29, 2025
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
7 changes: 7 additions & 0 deletions clang/lib/AST/ByteCode/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
const ValueDecl *VD);
static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC,
const ValueDecl *D) {
// This function tries pretty hard to produce a good diagnostic. Just skip
// tha if nobody will see it anyway.
if (!S.diagnosing())
return false;

if (isa<ParmVarDecl>(D)) {
if (D->getType()->isReferenceType())
Expand Down Expand Up @@ -168,6 +172,9 @@ static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC,

static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
const ValueDecl *VD) {
if (!S.diagnosing())
return;

const SourceInfo &Loc = S.Current->getSource(OpPC);
if (!S.getLangOpts().CPlusPlus) {
S.FFDiag(Loc);
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ static QualType getElemType(const Pointer &P) {

static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
unsigned ID) {
if (!S.diagnosing())
return;

auto Loc = S.Current->getSource(OpPC);
if (S.getLangOpts().CPlusPlus11)
S.CCEDiag(Loc, diag::note_constexpr_invalid_function)
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/AST/ByteCode/InterpState.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class InterpState final : public State, public SourceMapper {
InterpState(const InterpState &) = delete;
InterpState &operator=(const InterpState &) = delete;

bool diagnosing() const { return getEvalStatus().Diag != nullptr; }

// Stack frame accessors.
Frame *getSplitFrame() { return Parent.getCurrentFrame(); }
Frame *getCurrentFrame() override;
Expand Down
Loading