Skip to content

Conversation

@ebinjose02
Copy link

Fixes #168690
Prevents assertion in CGBuiltin for i1 - returns identity. Created test file for the same.

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Nov 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 24, 2025

@llvm/pr-subscribers-clang

Author: Ebin Jose (ebinjose02)

Changes

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 --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 %{{.*}} 
@llvmbot
Copy link
Member

llvmbot commented Nov 24, 2025

@llvm/pr-subscribers-clang-codegen

Author: Ebin Jose (ebinjose02)

Changes

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 --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 %{{.*}} 
@github-actions
Copy link

github-actions bot commented Nov 28, 2025

🐧 Linux x64 Test Results

  • 84775 tests passed
  • 1122 tests skipped
  • 1 test failed

Failed Tests

(click on a test name to see its output)

Clang

Clang.CodeGen/builtin_bswapg.c
Exit Code: 1 Command Output (stdout): -- # RUN: at line 1 /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/22/include -nostdsysteminc -triple x86_64 -O0 -emit-llvm -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/builtin_bswapg.c | /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/builtin_bswapg.c # executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 -internal-isystem /home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/22/include -nostdsysteminc -triple x86_64 -O0 -emit-llvm -o - /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/builtin_bswapg.c # note: command had no output on stdout or stderr # executed command: /home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/builtin_bswapg.c # .---command stderr------------ # | /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/builtin_bswapg.c:7:17: error: CHECK-LABEL: expected string not found in input # | // CHECK-LABEL: define{{.*}} i1 @_Z11test_bswapgb( # | ^ # | <stdin>:1:1: note: scanning from here # | ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/builtin_bswapg.c' # | ^ # | <stdin>:7:13: note: possible intended match here # | define dso_local zeroext i1 @test_bswapg(i1 noundef zeroext %c) #0 { # | ^ # | # | Input file: <stdin> # | Check file: /home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/builtin_bswapg.c # | # | -dump-input=help explains the following input dump. # | # | Input was: # | <<<<<< # | 1: ; ModuleID = '/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/builtin_bswapg.c' # | label:7'0 X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found # | 2: source_filename = "/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CodeGen/builtin_bswapg.c" # | label:7'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | 3: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" # | label:7'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | 4: target triple = "x86_64" # | label:7'0 ~~~~~~~~~~~~~~~~~~~~~~~~~ # | 5: # | label:7'0 ~ # | 6: ; Function Attrs: noinline nounwind optnone # | label:7'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | 7: define dso_local zeroext i1 @test_bswapg(i1 noundef zeroext %c) #0 { # | label:7'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | label:7'1 ? possible intended match # | 8: entry: # | label:7'0 ~~~~~~~ # | 9: %c.addr = alloca i8, align 1 # | label:7'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | 10: %storedv = zext i1 %c to i8 # | label:7'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | 11: store i8 %storedv, ptr %c.addr, align 1 # | label:7'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | 12: %0 = load i8, ptr %c.addr, align 1 # | label:7'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # | . # | . # | . # | >>>>>> # `----------------------------- # error: command failed with exit status: 1 -- 

If these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the infrastructure label.

Prevents assertion in CGBuiltin for i1 - returns identity. Created test file for the same.
// RUN: %clang_cc1 -triple x86_64 -O0 -emit-llvm -o - %s | FileCheck %s
#include <stdbool.h>
bool test_bswapg(bool c) {
return __builtin_bswapg(c);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there some existing test file where we can add this?

@@ -3583,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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe if (IntTy->getBitWidth() == 1 ||IntTy->getBitWidth() == 8)?

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

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category

3 participants