[clang] [clang][bytecode] Check `diagnosing()` in `Invalid()` (PR #227640)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 30 03:13:23 PDT 2026


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/227640

In large C TUs, it happens pretty frequently that we reject something via `Invalid()`, but nobody ever gets to see the diagnostics we emit. Just don't emit a diagnostic in that case.

>From fc0dbc52c4e08d09f33ada561037b32efb68836b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 30 Sep 2026 11:01:35 +0200
Subject: [PATCH] Invalid

---
 clang/lib/AST/ByteCode/InterpHelpers.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpHelpers.h b/clang/lib/AST/ByteCode/InterpHelpers.h
index 50f0462a93f16..25881bbfe1a3b 100644
--- a/clang/lib/AST/ByteCode/InterpHelpers.h
+++ b/clang/lib/AST/ByteCode/InterpHelpers.h
@@ -126,9 +126,10 @@ static inline llvm::RoundingMode getRoundingMode(FPOptions FPO) {
 }
 
 inline bool Invalid(InterpState &S, CodePtr OpPC) {
-  const SourceLocation &Loc = S.Current->getLocation(OpPC);
-  S.FFDiag(Loc, diag::note_invalid_subexpr_in_const_expr)
-      << S.Current->getRange(OpPC);
+  if (S.diagnosing())
+    S.FFDiag(S.Current->getSource(OpPC),
+             diag::note_invalid_subexpr_in_const_expr)
+        << S.Current->getRange(OpPC);
   return false;
 }
 



More information about the cfe-commits mailing list