[clang] [clang] Remove an incorrect assertion in ConstantFoldAttrs (PR #105789)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 17 04:47:16 PST 2025


AaronBallman wrote:

> For
> 
> ```c++
> void f() {
>   [[clang::annotate("B", (void)1, (void)2, 7)]] int j = 0;
> }
> ```
> 
> The IR is:
> 
> ```llvm
> @.str = private unnamed_addr constant [2 x i8] c"B\00", section "llvm.metadata"
> @.str.1 = private unnamed_addr constant [10 x i8] c"array.cpp\00", section "llvm.metadata"
> @.args = private unnamed_addr constant { i8, i8, i32 } { i8 undef, i8 undef, i32 7 }, section "llvm.metadata
> 
> ; Function Attrs: mustprogress noinline nounwind optnone uwtable
> define dso_local void @_Z1fv() #0 {
> entry:
>   %j = alloca i32, align 4
>   call void @llvm.var.annotation.p0.p0(ptr %j, ptr @.str, ptr @.str.1, i32 187, ptr @.args)
>   store i32 0, ptr %j, align 4
>   ret void
> }
> ```
> 
> So the void arguments get translated to `undef`. Is that acceptable?

That's an interesting situation! I'm not sure what I'd expect the LLVM IR to be there. For Clang AST, we want to keep around the expression AST nodes. But for LLVM IR, perhaps it makes sense to drop anything without a value rather than mark it as undef?

https://github.com/llvm/llvm-project/pull/105789


More information about the cfe-commits mailing list