[libc-commits] [libc] [SandboxIR] Implement the InsertElementInst class (#102404) (PR #113416)

Roland McGrath via libc-commits libc-commits at lists.llvm.org
Tue Oct 22 21:30:13 PDT 2024


https://github.com/frobtech created https://github.com/llvm/llvm-project/pull/113416

Heavily based on work by @vporpo.

>From cb03afec79d410238478c17c20d1dc53cec09880 Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Tue, 22 Oct 2024 21:25:09 -0700
Subject: [PATCH] [libc] Use `if constexpr` for compile-time conditionals

Don't use plain `if` for things that are compile-time constants.
Instead, use `if constexpr`.  This both ensures that these are
properly wired up constant expressions as intended, and prevents
warnings from the compiler about useless `if` checks that look in
the source like they're meant to do something at runtime but will
just be compiled away.
---
 libc/test/UnitTest/FPMatcher.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h
index bdcc22ef94e76b..7fcc6a32025b5d 100644
--- a/libc/test/UnitTest/FPMatcher.h
+++ b/libc/test/UnitTest/FPMatcher.h
@@ -124,35 +124,35 @@ template <typename T, TestCond Condition> class CFPMatcher : public Matcher<T> {
 
   bool match(T actualValue) {
     actual = actualValue;
-    if (cpp::is_complex_type_same<T, _Complex float>())
+    if constexpr (cpp::is_complex_type_same<T, _Complex float>())
       return matchComplex<float>();
-    else if (cpp::is_complex_type_same<T, _Complex double>())
+    else if constexpr (cpp::is_complex_type_same<T, _Complex double>())
       return matchComplex<double>();
-    else if (cpp::is_complex_type_same<T, _Complex long double>())
+    else if constexpr (cpp::is_complex_type_same<T, _Complex long double>())
       return matchComplex<long double>();
 #ifdef LIBC_TYPES_HAS_CFLOAT16
-    else if (cpp::is_complex_type_same<T, cfloat16>)
+    else if constexpr (cpp::is_complex_type_same<T, cfloat16>)
       return matchComplex<float16>();
 #endif
 #ifdef LIBC_TYPES_HAS_CFLOAT128
-    else if (cpp::is_complex_type_same<T, cfloat128>)
+    else if constexpr (cpp::is_complex_type_same<T, cfloat128>)
       return matchComplex<float128>();
 #endif
   }
 
   void explainError() override {
-    if (cpp::is_complex_type_same<T, _Complex float>())
+    if constexpr (cpp::is_complex_type_same<T, _Complex float>())
       return explainErrorComplex<float>();
-    else if (cpp::is_complex_type_same<T, _Complex double>())
+    else if constexpr (cpp::is_complex_type_same<T, _Complex double>())
       return explainErrorComplex<double>();
-    else if (cpp::is_complex_type_same<T, _Complex long double>())
+    else if constexpr (cpp::is_complex_type_same<T, _Complex long double>())
       return explainErrorComplex<long double>();
 #ifdef LIBC_TYPES_HAS_CFLOAT16
-    else if (cpp::is_complex_type_same<T, cfloat16>)
+    else if constexpr (cpp::is_complex_type_same<T, cfloat16>)
       return explainErrorComplex<float16>();
 #endif
 #ifdef LIBC_TYPES_HAS_CFLOAT128
-    else if (cpp::is_complex_type_same<T, cfloat128>)
+    else if constexpr (cpp::is_complex_type_same<T, cfloat128>)
       return explainErrorComplex<float128>();
 #endif
   }



More information about the libc-commits mailing list