Skip to content

Conversation

AdityaC4
Copy link
Contributor

@AdityaC4 AdityaC4 commented Oct 3, 2025

fixes: #161685

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:bytecode Issues for the clang bytecode constexpr interpreter labels Oct 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 3, 2025

@llvm/pr-subscribers-clang

Author: Aditya Chaudhari (AdityaC4)

Changes

fixes: #161685


Full diff: https://github.com/llvm/llvm-project/pull/161755.diff

1 Files Affected:

  • (modified) clang/lib/AST/ByteCode/PrimType.h (+19)
diff --git a/clang/lib/AST/ByteCode/PrimType.h b/clang/lib/AST/ByteCode/PrimType.h
index 54fd39ac6fcc8..e1c2bf58a75e6 100644
--- a/clang/lib/AST/ByteCode/PrimType.h
+++ b/clang/lib/AST/ByteCode/PrimType.h
@@ -262,6 +262,25 @@ static inline bool aligned(const void *P) {
     }                                                                          \
   } while (0)
 
+#define NUMERIC_TYPE_SWITCH(Expr, B)                                           \
+  do {                                                                         \
+    switch (Expr) {                                                            \
+      TYPE_SWITCH_CASE(PT_Sint8, B)                                            \
+      TYPE_SWITCH_CASE(PT_Uint8, B)                                            \
+      TYPE_SWITCH_CASE(PT_Sint16, B)                                           \
+      TYPE_SWITCH_CASE(PT_Uint16, B)                                           \
+      TYPE_SWITCH_CASE(PT_Sint32, B)                                           \
+      TYPE_SWITCH_CASE(PT_Uint32, B)                                           \
+      TYPE_SWITCH_CASE(PT_Sint64, B)                                           \
+      TYPE_SWITCH_CASE(PT_Uint64, B)                                           \
+      TYPE_SWITCH_CASE(PT_IntAP, B)                                            \
+      TYPE_SWITCH_CASE(PT_IntAPS, B)                                           \
+      TYPE_SWITCH_CASE(PT_Float, B)                                            \
+    default:                                                                   \
+      llvm_unreachable("Not an integer or floating point value");              \
+    }                                                                          \
+  } while (0)
+
 #define TYPE_SWITCH_ALLOC(Expr, B)                                             \
   do {                                                                         \
     switch (Expr) {                                                            \

@tbaederr
Copy link
Contributor

tbaederr commented Oct 4, 2025

So, the problem is that in general IntAP, IntAPS and Floating are different from the other numeric types because they _might_require memory to be allocated. That's currently handled transparently in pushInteger(), but for floats that doesn't automatically happen. That's why e.g. builtin_inf calls allocFloat.

I believe that's a non-issue for the code from #161302:

  if (ElemPT == PT_Float) {
    S.Stk.push<Floating>(Vec.elem<Floating>(Index));
    return true;
  }

because we're simply pushing an already existing, allocated, float on the stack. But we can't easily verify that that's always the case.

@AdityaC4
Copy link
Contributor Author

@tbaederr Thanks for the context. Since Floating still needs an explicit allocFloat while pushInteger already handles the IntAP/IntAPS allocations, maybe we should drop the new NUMERIC_TYPE_SWITCH. If not we could add a helper that checks needsAlloc<T>() and singleWord() so the float path auto-allocates when needed, which would let us make a unified switch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:bytecode Issues for the clang bytecode constexpr interpreter clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Clang][ByteCode] Add numeric-only TYPE_SWITCH to avoid Pointer/MemberPointer instantiation in vector handlers

3 participants