[clang] [CLANG] Fixes the issue with using bool in builtin_bswapg (PR #169285)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 23 23:09:17 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Ebin Jose (ebinjose02)
<details>
<summary>Changes</summary>
Fixes #<!-- -->168690
Prevents assertion in CGBuiltin for i1 - returns identity. Created test file for the same.
---
Full diff: https://github.com/llvm/llvm-project/pull/169285.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+2)
- (added) clang/test/CodeGen/builtin_bswapg.cpp (+8)
``````````diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 93f691e4c2267..8bcc2c8e7d8fe 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3653,6 +3653,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Value *ArgValue = EmitScalarExpr(E->getArg(0));
llvm::IntegerType *IntTy = cast<llvm::IntegerType>(ArgValue->getType());
assert(IntTy && "LLVM's __builtin_bswapg only supports integer variants");
+ if (IntTy->getBitWidth() == 1)
+ return RValue::get(ArgValue);
assert(((IntTy->getBitWidth() % 16 == 0 && IntTy->getBitWidth() != 0) ||
IntTy->getBitWidth() == 8) &&
"LLVM's __builtin_bswapg only supports integer variants that has a "
diff --git a/clang/test/CodeGen/builtin_bswapg.cpp b/clang/test/CodeGen/builtin_bswapg.cpp
new file mode 100644
index 0000000000000..8e9af98a58d35
--- /dev/null
+++ b/clang/test/CodeGen/builtin_bswapg.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64 -O0 -emit-llvm -o - %s | FileCheck %s
+
+auto test_bswapg(bool c) {
+ return __builtin_bswapg(c);
+}
+
+// CHECK-LABEL: define{{.*}} i1 @_Z11test_bswapgb(
+// CHECK: ret i1 %{{.*}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/169285
More information about the cfe-commits
mailing list