[clang] Enclose code in nondebug in #ifndef NDEBUG/#endif (PR #142189)

via cfe-commits cfe-commits at lists.llvm.org
Fri May 30 10:58:42 PDT 2025


https://github.com/DeanSturtevant1 updated https://github.com/llvm/llvm-project/pull/142189

>From 2a78358b97c8a050cb75842094b0b69ece8e49e9 Mon Sep 17 00:00:00 2001
From: DeanSturtevant1 <dsturtevant at google.com>
Date: Fri, 30 May 2025 13:41:21 -0400
Subject: [PATCH 1/2] Enclose code that does nothing useful in nondebug in
 #ifndef NDEBUG/#endif in InterpBuiltin.cpp

---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index bfad4e763692f..55e0061702874 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -763,12 +763,13 @@ static bool interp__builtin_ffs(InterpState &S, CodePtr OpPC,
 static bool interp__builtin_addressof(InterpState &S, CodePtr OpPC,
                                       const InterpFrame *Frame,
                                       const CallExpr *Call) {
+#ifndef NDEBUG
   assert(Call->getArg(0)->isLValue());
-  [[maybe_unused]] PrimType PtrT =
+  PrimType PtrT =
       S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
   assert(PtrT == PT_Ptr &&
          "Unsupported pointer type passed to __builtin_addressof()");
-  (void)PtrT;
+#endif
   return true;
 }
 

>From 445b4377aff383f02eac1aaef30da713e84bc76f Mon Sep 17 00:00:00 2001
From: Dean Sturtevant <dsturtevant at google.com>
Date: Fri, 30 May 2025 13:58:25 -0400
Subject: [PATCH 2/2] clang-format

---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 55e0061702874..89c626dd3cee8 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -765,8 +765,7 @@ static bool interp__builtin_addressof(InterpState &S, CodePtr OpPC,
                                       const CallExpr *Call) {
 #ifndef NDEBUG
   assert(Call->getArg(0)->isLValue());
-  PrimType PtrT =
-      S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
+  PrimType PtrT = S.getContext().classify(Call->getArg(0)).value_or(PT_Ptr);
   assert(PtrT == PT_Ptr &&
          "Unsupported pointer type passed to __builtin_addressof()");
 #endif



More information about the cfe-commits mailing list