Skip to content

Commit

Permalink
Avoid setting tbaa on the store of return type of call to inline asse…
Browse files Browse the repository at this point in the history
…mbler.

In 32bit mode, attaching TBAA metadata to the store following the call
to inline assembler results in describing the wrong type by making a
fake lvalue(i.e., whatever the inline assembler happens to leave in
EAX:EDX.) Even if inline assembler somehow describes the correct type,
setting TBAA information on return type of call to inline assembler is
likely not correct, since TBAA rules need not apply to inline assembler.

Differential Revision: https://reviews.llvm.org/D115320
  • Loading branch information
schittir committed Dec 15, 2021
1 parent 794b4df commit 4706a29
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CGStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2454,7 +2454,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
const ABIArgInfo &RetAI = CurFnInfo->getReturnInfo();
if (RetAI.isDirect() || RetAI.isExtend()) {
// Make a fake lvalue for the return value slot.
LValue ReturnSlot = MakeAddrLValue(ReturnValue, FnRetTy);
LValue ReturnSlot = MakeAddrLValueWithoutTBAA(ReturnValue, FnRetTy);
CGM.getTargetCodeGenInfo().addReturnRegisterOutputs(
*this, ReturnSlot, Constraints, ResultRegTypes, ResultTruncRegTypes,
ResultRegDests, AsmString, S.getNumOutputs());
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/CodeGen/CodeGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,13 @@ class CodeGenFunction : public CodeGenTypeCache {
BaseInfo, TBAAInfo);
}

LValue
MakeAddrLValueWithoutTBAA(Address Addr, QualType T,
AlignmentSource Source = AlignmentSource::Type) {
return LValue::MakeAddr(Addr, T, getContext(), LValueBaseInfo(Source),
TBAAAccessInfo());
}

LValue MakeNaturalAlignPointeeAddrLValue(llvm::Value *V, QualType T);
LValue MakeNaturalAlignAddrLValue(llvm::Value *V, QualType T);

Expand Down
11 changes: 11 additions & 0 deletions clang/test/CodeGen/avoidTBAAonASMstore.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -O2 -disable-llvm-passes -fasm-blocks %s -emit-llvm -o - | FileCheck --check-prefix=STORE-LINE %s
double foo(double z) {
// STORE-LINE-LABEL: define{{.*}} double @_Z3food
unsigned short ControlWord;
__asm { fnstcw word ptr[ControlWord]}
;
// STORE-LINE: store i64 %{{.*}}, i64* %{{.*}},
// STORE-LINE-NOT: align 4, !tbaa
// STORE-LINE-SAME: align 4
return z;
}

0 comments on commit 4706a29

Please sign in to comment.