[Sema] Don't crash trying to diagnose abs called on a pointer type
Clang tries to figure out if a call to abs is suspicious by looking through implicit casts to look at the underlying, implicitly converted type. Interestingly, C has implicit conversions from pointer-ish types like function to less exciting types like int. This trips up our 'abs' checker because it doesn't know which variant of 'abs' is appropriate. Instead, diagnose 'abs' called on function types upfront. This sort of thing is highly suspicious and is likely indicative of a missing pointer dereference/function call/array index operation. This fixes PR25532. llvm-svn: 253156
This commit is contained in:
@@ -5085,6 +5085,19 @@ void Sema::CheckAbsoluteValueFunction(const CallExpr *Call,
|
||||
return;
|
||||
}
|
||||
|
||||
// Taking the absolute value of a pointer is very suspicious, they probably
|
||||
// wanted to index into an array, dereference a pointer, call a function, etc.
|
||||
if (ArgType->isPointerType() || ArgType->canDecayToPointerType()) {
|
||||
unsigned DiagType = 0;
|
||||
if (ArgType->isFunctionType())
|
||||
DiagType = 1;
|
||||
else if (ArgType->isArrayType())
|
||||
DiagType = 2;
|
||||
|
||||
Diag(Call->getExprLoc(), diag::warn_pointer_abs) << DiagType << ArgType;
|
||||
return;
|
||||
}
|
||||
|
||||
// std::abs has overloads which prevent most of the absolute value problems
|
||||
// from occurring.
|
||||
if (IsStdAbs)
|
||||
|
||||
Reference in New Issue
Block a user