diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -1856,6 +1856,7 @@ .addAttribute(Attribute::NoAlias) .addAttribute(Attribute::NoCapture) .addAttribute(Attribute::NonNull) + .addAlignmentAttr(1) // the int here is ignored .addDereferenceableAttr(1) // the int here is ignored .addDereferenceableOrNullAttr(1) // the int here is ignored .addAttribute(Attribute::ReadNone) @@ -1866,6 +1867,10 @@ .addByValAttr(Ty) .addByRefAttr(Ty); + // Some attributes can apply to all "values" but there are no `void` values. + if (Ty->isVoidTy()) + Incompatible.addAttribute(Attribute::NoUndef); + return Incompatible; } diff --git a/llvm/test/Transforms/DeadArgElim/returned.ll b/llvm/test/Transforms/DeadArgElim/returned.ll --- a/llvm/test/Transforms/DeadArgElim/returned.ll +++ b/llvm/test/Transforms/DeadArgElim/returned.ll @@ -43,6 +43,12 @@ ret %Ty* %this } +; Drop all these attributes +; CHECK-LABEL: define internal void @test6 +define internal align 8 dereferenceable_or_null(2) noundef noalias i8* @test6() { + ret i8* null +} + define %Ty* @caller(%Ty* %this) { %1 = call %Ty* @test1(%Ty* %this) %2 = call %Ty* @test2(%Ty* %this) @@ -51,5 +57,6 @@ ; ...instead, drop 'returned' form the call site ; CHECK: call void @test5(%Ty* %this) %5 = call %Ty* @test5(%Ty* returned %this) + %6 = call i8* @test6() ret %Ty* %this }