Author: Sindhu Chittireddy Date: 2021-12-14T17:40:33-08:00 New Revision: 4706a297fb9ebe6af91ee2c92e5eb196dc2785f7
URL: https://github.com/llvm/llvm-project/commit/4706a297fb9ebe6af91ee2c92e5eb196dc2785f7 DIFF: https://github.com/llvm/llvm-project/commit/4706a297fb9ebe6af91ee2c92e5eb196dc2785f7.diff LOG: Avoid setting tbaa on the store of return type of call to inline assembler. 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 Added: clang/test/CodeGen/avoidTBAAonASMstore.cpp Modified: clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CodeGenFunction.h Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index d399ff919cc39..ef0068cd3b0c9 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -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()); diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index ff5b6634da1c2..2fabeb2061937 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -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); diff --git a/clang/test/CodeGen/avoidTBAAonASMstore.cpp b/clang/test/CodeGen/avoidTBAAonASMstore.cpp new file mode 100644 index 0000000000000..107963a8710bd --- /dev/null +++ b/clang/test/CodeGen/avoidTBAAonASMstore.cpp @@ -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; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits