Skip to content

Commit 4efe7a5

Browse files
authored
[clang][bytecode] Simplify diagnoseUnknownDecl if we're not diagnosing (#141910)
See the added comment. This improves compile times a bit: https://llvm-compile-time-tracker.com/compare.php?from=ac62f73f19ae9fb415d3fc423949b8d7543e8717&to=0d6cf47197a4ee11cdd1ee4a48ea38a2907c3d45&stat=instructions:u
1 parent 6769a83 commit 4efe7a5

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
136136
const ValueDecl *VD);
137137
static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC,
138138
const ValueDecl *D) {
139+
// This function tries pretty hard to produce a good diagnostic. Just skip
140+
// tha if nobody will see it anyway.
141+
if (!S.diagnosing())
142+
return false;
139143

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

169173
static void diagnoseNonConstVariable(InterpState &S, CodePtr OpPC,
170174
const ValueDecl *VD) {
175+
if (!S.diagnosing())
176+
return;
177+
171178
const SourceInfo &Loc = S.Current->getSource(OpPC);
172179
if (!S.getLangOpts().CPlusPlus) {
173180
S.FFDiag(Loc);

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ static QualType getElemType(const Pointer &P) {
152152

153153
static void diagnoseNonConstexprBuiltin(InterpState &S, CodePtr OpPC,
154154
unsigned ID) {
155+
if (!S.diagnosing())
156+
return;
157+
155158
auto Loc = S.Current->getSource(OpPC);
156159
if (S.getLangOpts().CPlusPlus11)
157160
S.CCEDiag(Loc, diag::note_constexpr_invalid_function)

clang/lib/AST/ByteCode/InterpState.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class InterpState final : public State, public SourceMapper {
5353
InterpState(const InterpState &) = delete;
5454
InterpState &operator=(const InterpState &) = delete;
5555

56+
bool diagnosing() const { return getEvalStatus().Diag != nullptr; }
57+
5658
// Stack frame accessors.
5759
Frame *getSplitFrame() { return Parent.getCurrentFrame(); }
5860
Frame *getCurrentFrame() override;

0 commit comments

Comments
 (0)