diff options
author | Vitaly Buka <vitalybuka@google.com> | 2022-09-03 13:12:49 -0700 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2022-09-03 13:12:49 -0700 |
commit | 9905dae5e18cd55ee6bb8678c95fed940ded1ef9 (patch) | |
tree | 56f85c024d3f3323466086d127ba9e2ded24b89b /clang/lib/Sema/SemaChecking.cpp | |
parent | 0e68f483d48d5d468addfd3a8c68a8862aa60222 (diff) | |
download | llvm-9905dae5e18cd55ee6bb8678c95fed940ded1ef9.zip llvm-9905dae5e18cd55ee6bb8678c95fed940ded1ef9.tar.gz llvm-9905dae5e18cd55ee6bb8678c95fed940ded1ef9.tar.bz2 |
Revert "[Clang][CodeGen] Avoid __builtin_assume_aligned crash when the 1st arg is array type"
Breakes windows bot.
This reverts commit 3ad2fe913ae08ca062105731ad2da2eae825c731.
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 71 |
1 files changed, 14 insertions, 57 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index de132b8..897ab70 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -128,28 +128,6 @@ static bool checkArgCountAtLeast(Sema &S, CallExpr *Call, << Call->getSourceRange(); } -/// Checks that a call expression's argument count is at most the desired -/// number. This is useful when doing custom type-checking on a variadic -/// function. Returns true on error. -static bool checkArgCountAtMost(Sema &S, CallExpr *Call, unsigned MaxArgCount) { - unsigned ArgCount = Call->getNumArgs(); - if (ArgCount <= MaxArgCount) - return false; - return S.Diag(Call->getEndLoc(), - diag::err_typecheck_call_too_many_args_at_most) - << 0 /*function call*/ << MaxArgCount << ArgCount - << Call->getSourceRange(); -} - -/// Checks that a call expression's argument count is in the desired range. This -/// is useful when doing custom type-checking on a variadic function. Returns -/// true on error. -static bool checkArgCountRange(Sema &S, CallExpr *Call, unsigned MinArgCount, - unsigned MaxArgCount) { - return checkArgCountAtLeast(S, Call, MinArgCount) || - checkArgCountAtMost(S, Call, MaxArgCount); -} - /// Checks that a call expression's argument count is the desired number. /// This is useful when doing custom type-checking. Returns true on error. static bool checkArgCount(Sema &S, CallExpr *Call, unsigned DesiredArgCount) { @@ -170,20 +148,6 @@ static bool checkArgCount(Sema &S, CallExpr *Call, unsigned DesiredArgCount) { << Call->getArg(1)->getSourceRange(); } -static bool convertArgumentToType(Sema &S, Expr *&Value, QualType Ty) { - if (Value->isTypeDependent()) - return false; - - InitializedEntity Entity = - InitializedEntity::InitializeParameter(S.Context, Ty, false); - ExprResult Result = - S.PerformCopyInitialization(Entity, SourceLocation(), Value); - if (Result.isInvalid()) - return true; - Value = Result.get(); - return false; -} - /// Check that the first argument to __builtin_annotation is an integer /// and the second argument is a non-wide string literal. static bool SemaBuiltinAnnotation(Sema &S, CallExpr *TheCall) { @@ -7680,45 +7644,38 @@ bool Sema::SemaBuiltinAllocaWithAlign(CallExpr *TheCall) { /// Handle __builtin_assume_aligned. This is declared /// as (const void*, size_t, ...) and can take one optional constant int arg. bool Sema::SemaBuiltinAssumeAligned(CallExpr *TheCall) { - if (checkArgCountRange(*this, TheCall, 2, 3)) - return true; - unsigned NumArgs = TheCall->getNumArgs(); - Expr *FirstArg = TheCall->getArg(0); - { - ExprResult FirstArgResult = DefaultFunctionArrayLvalueConversion(FirstArg); - if (FirstArgResult.isInvalid()) - return true; - TheCall->setArg(0, FirstArgResult.get()); - } + if (NumArgs > 3) + return Diag(TheCall->getEndLoc(), + diag::err_typecheck_call_too_many_args_at_most) + << 0 /*function call*/ << 3 << NumArgs << TheCall->getSourceRange(); // The alignment must be a constant integer. - Expr *SecondArg = TheCall->getArg(1); - if (convertArgumentToType(*this, SecondArg, Context.getSizeType())) - return true; - TheCall->setArg(1, SecondArg); + Expr *Arg = TheCall->getArg(1); // We can't check the value of a dependent argument. - if (!SecondArg->isValueDependent()) { + if (!Arg->isTypeDependent() && !Arg->isValueDependent()) { llvm::APSInt Result; if (SemaBuiltinConstantArg(TheCall, 1, Result)) return true; if (!Result.isPowerOf2()) return Diag(TheCall->getBeginLoc(), diag::err_alignment_not_power_of_two) - << SecondArg->getSourceRange(); + << Arg->getSourceRange(); if (Result > Sema::MaximumAlignment) Diag(TheCall->getBeginLoc(), diag::warn_assume_aligned_too_great) - << SecondArg->getSourceRange() << Sema::MaximumAlignment; + << Arg->getSourceRange() << Sema::MaximumAlignment; } if (NumArgs > 2) { - Expr *ThirdArg = TheCall->getArg(2); - if (convertArgumentToType(*this, ThirdArg, Context.getSizeType())) - return true; - TheCall->setArg(2, ThirdArg); + ExprResult Arg(TheCall->getArg(2)); + InitializedEntity Entity = InitializedEntity::InitializeParameter(Context, + Context.getSizeType(), false); + Arg = PerformCopyInitialization(Entity, SourceLocation(), Arg); + if (Arg.isInvalid()) return true; + TheCall->setArg(2, Arg.get()); } return false; |