From: Nico Weber Date: Thu, 10 Oct 2019 21:34:32 +0000 (+0000) Subject: Revert 374450 "Fix __builtin_assume_aligned with too large values." X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f638ec612bbf3a88c2e3f5c5bbb05557b6aa640e;p=clang Revert 374450 "Fix __builtin_assume_aligned with too large values." The test fails on Windows, with error: 'warning' diagnostics expected but not seen: File builtin-assume-aligned.c Line 62: requested alignment must be 268435456 bytes or smaller; assumption ignored error: 'warning' diagnostics seen but not expected: File builtin-assume-aligned.c Line 62: requested alignment must be 8192 bytes or smaller; assumption ignored git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374456 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 68f2b37950..bcd059be91 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -2853,10 +2853,6 @@ def err_alignment_dependent_typedef_name : Error< def err_attribute_aligned_too_great : Error< "requested alignment must be %0 bytes or smaller">; -def warn_assume_aligned_too_great - : Warning<"requested alignment must be %0 bytes or smaller; assumption " - "ignored">, - InGroup>; def warn_redeclaration_without_attribute_prev_attribute_ignored : Warning< "%q0 redeclared without %1 attribute: previous %1 ignored">, InGroup; diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index e6369d80cd..0562a623ae 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -2048,10 +2048,11 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, Value *AlignmentValue = EmitScalarExpr(E->getArg(1)); ConstantInt *AlignmentCI = cast(AlignmentValue); + unsigned Alignment = (unsigned)AlignmentCI->getZExtValue(); EmitAlignmentAssumption(PtrValue, Ptr, /*The expr loc is sufficient.*/ SourceLocation(), - AlignmentCI, OffsetValue); + Alignment, OffsetValue); return RValue::get(PtrValue); } case Builtin::BI__assume: diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 2ec9e91e31..682a7ccb49 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -4569,7 +4569,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, llvm::Value *Alignment = EmitScalarExpr(AA->getAlignment()); llvm::ConstantInt *AlignmentCI = cast(Alignment); EmitAlignmentAssumption(Ret.getScalarVal(), RetTy, Loc, AA->getLocation(), - AlignmentCI, OffsetValue); + AlignmentCI->getZExtValue(), OffsetValue); } else if (const auto *AA = TargetDecl->getAttr()) { llvm::Value *AlignmentVal = CallArgs[AA->getParamIndex().getLLVMIndex()] .getRValue(*this) diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index c7f279d28e..0b9271b1d3 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -294,7 +294,8 @@ public: Value *AlignmentValue = CGF.EmitScalarExpr(AVAttr->getAlignment()); llvm::ConstantInt *AlignmentCI = cast(AlignmentValue); - CGF.EmitAlignmentAssumption(V, E, AVAttr->getLocation(), AlignmentCI); + CGF.EmitAlignmentAssumption(V, E, AVAttr->getLocation(), + AlignmentCI->getZExtValue()); } /// EmitLoadOfLValue - Given an expression with complex type that represents a diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index fa4304d7e5..e50cdb1b67 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -1519,14 +1519,14 @@ static void emitAlignedClause(CodeGenFunction &CGF, if (!CGF.HaveInsertPoint()) return; for (const auto *Clause : D.getClausesOfKind()) { - size_t ClauseAlignment = 0; + unsigned ClauseAlignment = 0; if (const Expr *AlignmentExpr = Clause->getAlignment()) { auto *AlignmentCI = cast(CGF.EmitScalarExpr(AlignmentExpr)); - ClauseAlignment = AlignmentCI->getZExtValue(); + ClauseAlignment = static_cast(AlignmentCI->getZExtValue()); } for (const Expr *E : Clause->varlists()) { - size_t Alignment = ClauseAlignment; + unsigned Alignment = ClauseAlignment; if (Alignment == 0) { // OpenMP [2.8.1, Description] // If no optional parameter is specified, implementation-defined default @@ -1542,8 +1542,7 @@ static void emitAlignedClause(CodeGenFunction &CGF, if (Alignment != 0) { llvm::Value *PtrValue = CGF.EmitScalarExpr(E); CGF.EmitAlignmentAssumption( - PtrValue, E, /*No second loc needed*/ SourceLocation(), - llvm::ConstantInt::get(CGF.SizeTy, Alignment)); + PtrValue, E, /*No second loc needed*/ SourceLocation(), Alignment); } } } diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 3f9a52ab76..41b7f2f4b1 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -2056,10 +2056,25 @@ void CodeGenFunction::EmitAlignmentAssumption(llvm::Value *PtrValue, } } +void CodeGenFunction::EmitAlignmentAssumption(llvm::Value *PtrValue, + QualType Ty, SourceLocation Loc, + SourceLocation AssumptionLoc, + unsigned Alignment, + llvm::Value *OffsetValue) { + llvm::Value *TheCheck; + llvm::Instruction *Assumption = Builder.CreateAlignmentAssumption( + CGM.getDataLayout(), PtrValue, Alignment, OffsetValue, &TheCheck); + if (SanOpts.has(SanitizerKind::Alignment)) { + llvm::Value *AlignmentVal = llvm::ConstantInt::get(IntPtrTy, Alignment); + EmitAlignmentAssumptionCheck(PtrValue, Ty, Loc, AssumptionLoc, AlignmentVal, + OffsetValue, TheCheck, Assumption); + } +} + void CodeGenFunction::EmitAlignmentAssumption(llvm::Value *PtrValue, const Expr *E, SourceLocation AssumptionLoc, - llvm::Value *Alignment, + unsigned Alignment, llvm::Value *OffsetValue) { if (auto *CE = dyn_cast(E)) E = CE->getSubExprAsWritten(); diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index bb4fed8083..ea78309a06 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -2829,8 +2829,13 @@ public: llvm::Value *Alignment, llvm::Value *OffsetValue = nullptr); + void EmitAlignmentAssumption(llvm::Value *PtrValue, QualType Ty, + SourceLocation Loc, SourceLocation AssumptionLoc, + unsigned Alignment, + llvm::Value *OffsetValue = nullptr); + void EmitAlignmentAssumption(llvm::Value *PtrValue, const Expr *E, - SourceLocation AssumptionLoc, llvm::Value *Alignment, + SourceLocation AssumptionLoc, unsigned Alignment, llvm::Value *OffsetValue = nullptr); //===--------------------------------------------------------------------===// diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index b35d591a7f..07d3648dc9 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -6063,16 +6063,6 @@ bool Sema::SemaBuiltinAssumeAligned(CallExpr *TheCall) { if (!Result.isPowerOf2()) return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two) << Arg->getSourceRange(); - - // FIXME: this should probably use llvm::Value::MaximumAlignment, however - // doing so results in a linking issue in GCC in a couple of assemblies. - // Alignment calculations can wrap around if it's greater than 2**28. - unsigned MaximumAlignment = - Context.getTargetInfo().getTriple().isOSBinFormatCOFF() ? 8192 - : 268435456; - if (Result > MaximumAlignment) - Diag(TheCall->getBeginLoc(), diag::warn_assume_aligned_too_great) - << Arg->getSourceRange() << MaximumAlignment; } if (NumArgs > 2) { diff --git a/test/Sema/builtin-assume-aligned.c b/test/Sema/builtin-assume-aligned.c index a669ed172d..057a500b32 100644 --- a/test/Sema/builtin-assume-aligned.c +++ b/test/Sema/builtin-assume-aligned.c @@ -58,7 +58,3 @@ void *test_no_fn_proto() __attribute__((assume_aligned)); // expected-error {{'a void *test_no_fn_proto() __attribute__((assume_aligned())); // expected-error {{'assume_aligned' attribute takes at least 1 argument}} void *test_no_fn_proto() __attribute__((assume_aligned(32, 45, 37))); // expected-error {{'assume_aligned' attribute takes no more than 2 arguments}} -int pr43638(int *a) { - a = __builtin_assume_aligned(a, 4294967296); // expected-warning {{requested alignment must be 268435456 bytes or smaller; assumption ignored}} -return a[0]; -}