[clang] [CLANG] Fixes the issue with using bool in builtin_bswapg (PR #169285)
Ebin Jose via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 23 23:08:30 PST 2025
https://github.com/ebinjose02 created https://github.com/llvm/llvm-project/pull/169285
Fixes #168690
Prevents assertion in CGBuiltin for i1 - returns identity. Created test file for the same.
>From e6c895d1d7684898da0c631fdf6aced542d175ed Mon Sep 17 00:00:00 2001
From: ebinjose02 <ebin371 at gmail.com>
Date: Mon, 24 Nov 2025 07:02:26 +0000
Subject: [PATCH] Fixes #168690 Prevents assertion in CGBuiltin for i1 -
returns identity. Created test file for the same.
---
clang/lib/CodeGen/CGBuiltin.cpp | 2 ++
clang/test/CodeGen/builtin_bswapg.cpp | 8 ++++++++
2 files changed, 10 insertions(+)
create mode 100644 clang/test/CodeGen/builtin_bswapg.cpp
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 %{{.*}}
More information about the cfe-commits
mailing list