Skip to content

Conversation

fennecJ
Copy link
Contributor

@fennecJ fennecJ commented Sep 23, 2025

Fix #160287

@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 Sep 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Sep 23, 2025

@llvm/pr-subscribers-clang

Author: None (fennecJ)

Changes

Fix #160287


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

1 Files Affected:

  • (modified) clang/lib/AST/ByteCode/InterpBuiltin.cpp (+2-11)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index aaab8ade0ae01..5423d3ca73c81 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -666,16 +666,6 @@ static bool interp__builtin_abs(InterpState &S, CodePtr OpPC,
   return true;
 }
 
-static bool interp__builtin_knot(InterpState &S, CodePtr OpPC,
-                                 const InterpFrame *Frame,
-                                 const CallExpr *Call) {
-  APSInt Val =
-      popToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(0)->getType()));
-  APInt Result = ~Val;
-  pushInteger(S, APSInt(std::move(Result), true), Call->getType());
-  return true;
-}
-
 static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
                                      const InterpFrame *Frame,
                                      const CallExpr *Call) {
@@ -3659,7 +3649,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
   case X86::BI__builtin_ia32_knothi:
   case X86::BI__builtin_ia32_knotsi:
   case X86::BI__builtin_ia32_knotdi:
-    return interp__builtin_knot(S, OpPC, Frame, Call);
+    return interp__builtin_elementwise_int_unaryop(
+        S, OpPC, Call, [](const APSInt &Src) { return ~Src; });
 
   case X86::BI__builtin_ia32_kaddqi:
   case X86::BI__builtin_ia32_kaddhi:

Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - cheers!

@RKSimon RKSimon enabled auto-merge (squash) September 23, 2025 16:26
@fennecJ
Copy link
Contributor Author

fennecJ commented Sep 23, 2025

Thank you for reviewing! 😄

@RKSimon RKSimon merged commit d5f8578 into llvm:main Sep 23, 2025
9 checks passed
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][x86][bytecode] Replace interp__builtin_knot with static bool interp__builtin_elementwise_int_unaryop callback

3 participants