From 4a7f7947a3f66658d68926182842e08d40d93d45 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Wed, 26 Feb 2014 01:17:28 +0000 Subject: [PATCH] Add -Wabsolute-value, warnings about absolute value functions. The warnings fall into three groups. 1) Using an absolute value function of the wrong type, for instance, using the int absolute value function when the argument is a floating point type. 2) Using the improper sized absolute value function, for instance, using abs when the argument is a long long. llabs should be used instead. From these two cases, an implicit conversion will occur which may cause unexpected behavior. Where possible, suggest the proper absolute value function to use, and which header to include if the function is not available. 3) Taking the absolute value of an unsigned value. In addition to this warning, suggest to remove the function call. This usually indicates a logic error since the programmer assumed negative values would have been possible. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202211 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticGroups.td | 1 + include/clang/Basic/DiagnosticSemaKinds.td | 15 + include/clang/Sema/Sema.h | 4 + lib/Sema/SemaChecking.cpp | 325 ++++++++ test/Sema/warn-absolute-value-header.c | 36 + test/Sema/warn-absolute-value.c | 782 ++++++++++++++++++++ test/SemaCXX/warn-absolute-value-header.cpp | 37 + 7 files changed, 1200 insertions(+) create mode 100644 test/Sema/warn-absolute-value-header.c create mode 100644 test/Sema/warn-absolute-value.c create mode 100644 test/SemaCXX/warn-absolute-value-header.cpp diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 5d527ab9e8..d80b4931dc 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -18,6 +18,7 @@ def Implicit : DiagGroup<"implicit", [ // Empty DiagGroups are recognized by clang but ignored. def : DiagGroup<"abi">; +def AbsoluteValue : DiagGroup<"absolute-value">; def : DiagGroup<"address">; def AddressOfTemporary : DiagGroup<"address-of-temporary">; def : DiagGroup<"aggregate-return">; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index aaebf59d8a..41d683fcb8 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -30,6 +30,21 @@ def warn_duplicate_enum_values : Warning< "been assigned">, InGroup>, DefaultIgnore; def note_duplicate_element : Note<"element %0 also has value %1">; +// Absolute value functions +def warn_unsigned_abs : Warning< + "taking the absolute value of unsigned type %0 has no effect">, + InGroup; +def note_remove_abs : Note< + "remove the call to %0 since unsigned values cannot be negative">; +def warn_abs_too_small : Warning< + "absolute value function %0 given an argument of type %1 but has parameter " + "of type %2 which may cause truncation of value">, InGroup; +def warn_wrong_absolute_value_type : Warning< + "using %select{integer|floating point|complex}1 absolute value function %0 " + "when argument is of %select{integer|floating point|complex}2 type">, + InGroup; +def note_replace_abs_function : Note<"use function '%0' instead">; + def warn_infinite_recursive_function : Warning< "all paths through this function will call itself">, InGroup, DefaultIgnore; diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 54f71620d5..3659214ec6 100644 --- a/include/clang/Sema/Sema.h +++ b/include/clang/Sema/Sema.h @@ -7941,6 +7941,10 @@ private: SourceLocation Loc, SourceRange range, llvm::SmallBitVector &CheckedVarArgs); + void CheckAbsoluteValueFunction(const CallExpr *Call, + const FunctionDecl *FDecl, + IdentifierInfo *FnInfo); + void CheckMemaccessArguments(const CallExpr *Call, unsigned BId, IdentifierInfo *FnName); diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index c978a1e5b1..936399ed96 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -851,6 +851,8 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, if (!FnInfo) return false; + CheckAbsoluteValueFunction(TheCall, FDecl, FnInfo); + unsigned CMId = FDecl->getMemoryFunctionKind(); if (CMId == 0) return false; @@ -3582,6 +3584,328 @@ void Sema::CheckFormatString(const StringLiteral *FExpr, } // TODO: handle other formats } +//===--- CHECK: Warn on use of wrong absolute value function. -------------===// + +// Returns the related absolute value function that is larger, of 0 if one +// does not exist. +static unsigned getLargerAbsoluteValueFunction(unsigned AbsFunction) { + switch (AbsFunction) { + default: + return 0; + + case Builtin::BI__builtin_abs: + return Builtin::BI__builtin_labs; + case Builtin::BI__builtin_labs: + return Builtin::BI__builtin_llabs; + case Builtin::BI__builtin_llabs: + return 0; + + case Builtin::BI__builtin_fabsf: + return Builtin::BI__builtin_fabs; + case Builtin::BI__builtin_fabs: + return Builtin::BI__builtin_fabsl; + case Builtin::BI__builtin_fabsl: + return 0; + + case Builtin::BI__builtin_cabsf: + return Builtin::BI__builtin_cabs; + case Builtin::BI__builtin_cabs: + return Builtin::BI__builtin_cabsl; + case Builtin::BI__builtin_cabsl: + return 0; + + case Builtin::BIabs: + return Builtin::BIlabs; + case Builtin::BIlabs: + return Builtin::BIllabs; + case Builtin::BIllabs: + return 0; + + case Builtin::BIfabsf: + return Builtin::BIfabs; + case Builtin::BIfabs: + return Builtin::BIfabsl; + case Builtin::BIfabsl: + return 0; + + case Builtin::BIcabsf: + return Builtin::BIcabs; + case Builtin::BIcabs: + return Builtin::BIcabsl; + case Builtin::BIcabsl: + return 0; + } +} + +// Returns the argument type of the absolute value function. +static QualType getAbsoluteValueArgumentType(ASTContext &Context, + unsigned AbsType) { + if (AbsType == 0) + return QualType(); + + ASTContext::GetBuiltinTypeError Error = ASTContext::GE_None; + QualType BuiltinType = Context.GetBuiltinType(AbsType, Error); + if (Error != ASTContext::GE_None) + return QualType(); + + const FunctionProtoType *FT = BuiltinType->getAs(); + if (!FT) + return QualType(); + + if (FT->getNumParams() != 1) + return QualType(); + + return FT->getParamType(0); +} + +// Returns the best absolute value function, or zero, based on type and +// current absolute value function. +static unsigned getBestAbsFunction(ASTContext &Context, QualType ArgType, + unsigned AbsFunctionKind) { + unsigned BestKind = 0; + uint64_t ArgSize = Context.getTypeSize(ArgType); + for (unsigned Kind = AbsFunctionKind; Kind != 0; + Kind = getLargerAbsoluteValueFunction(Kind)) { + QualType ParamType = getAbsoluteValueArgumentType(Context, Kind); + if (Context.getTypeSize(ParamType) >= ArgSize) { + if (BestKind == 0) + BestKind = Kind; + else if (Context.hasSameType(ParamType, ArgType)) { + BestKind = Kind; + break; + } + } + } + return BestKind; +} + +enum AbsoluteValueKind { + AVK_Integer, + AVK_Floating, + AVK_Complex +}; + +static AbsoluteValueKind getAbsoluteValueKind(QualType T) { + if (T->isIntegralOrEnumerationType()) + return AVK_Integer; + if (T->isRealFloatingType()) + return AVK_Floating; + if (T->isAnyComplexType()) + return AVK_Complex; + + llvm_unreachable("Type not integer, floating, or complex"); +} + +// Changes the absolute value function to a different type. Preserves whether +// the function is a builtin. +static unsigned changeAbsFunction(unsigned AbsKind, + AbsoluteValueKind ValueKind) { + switch (ValueKind) { + case AVK_Integer: + switch (AbsKind) { + default: + return 0; + case Builtin::BI__builtin_fabsf: + case Builtin::BI__builtin_fabs: + case Builtin::BI__builtin_fabsl: + case Builtin::BI__builtin_cabsf: + case Builtin::BI__builtin_cabs: + case Builtin::BI__builtin_cabsl: + return Builtin::BI__builtin_abs; + case Builtin::BIfabsf: + case Builtin::BIfabs: + case Builtin::BIfabsl: + case Builtin::BIcabsf: + case Builtin::BIcabs: + case Builtin::BIcabsl: + return Builtin::BIabs; + } + case AVK_Floating: + switch (AbsKind) { + default: + return 0; + case Builtin::BI__builtin_abs: + case Builtin::BI__builtin_labs: + case Builtin::BI__builtin_llabs: + case Builtin::BI__builtin_cabsf: + case Builtin::BI__builtin_cabs: + case Builtin::BI__builtin_cabsl: + return Builtin::BI__builtin_fabsf; + case Builtin::BIabs: + case Builtin::BIlabs: + case Builtin::BIllabs: + case Builtin::BIcabsf: + case Builtin::BIcabs: + case Builtin::BIcabsl: + return Builtin::BIfabsf; + } + case AVK_Complex: + switch (AbsKind) { + default: + return 0; + case Builtin::BI__builtin_abs: + case Builtin::BI__builtin_labs: + case Builtin::BI__builtin_llabs: + case Builtin::BI__builtin_fabsf: + case Builtin::BI__builtin_fabs: + case Builtin::BI__builtin_fabsl: + return Builtin::BI__builtin_cabsf; + case Builtin::BIabs: + case Builtin::BIlabs: + case Builtin::BIllabs: + case Builtin::BIfabsf: + case Builtin::BIfabs: + case Builtin::BIfabsl: + return Builtin::BIcabsf; + } + } + llvm_unreachable("Unable to convert function"); +} + +unsigned getAbsoluteValueFunctionKind(const FunctionDecl *FDecl) { + const IdentifierInfo *FnInfo = FDecl->getIdentifier(); + if (!FnInfo) + return 0; + + switch (FDecl->getBuiltinID()) { + default: + return 0; + case Builtin::BI__builtin_abs: + case Builtin::BI__builtin_fabs: + case Builtin::BI__builtin_fabsf: + case Builtin::BI__builtin_fabsl: + case Builtin::BI__builtin_labs: + case Builtin::BI__builtin_llabs: + case Builtin::BI__builtin_cabs: + case Builtin::BI__builtin_cabsf: + case Builtin::BI__builtin_cabsl: + case Builtin::BIabs: + case Builtin::BIlabs: + case Builtin::BIllabs: + case Builtin::BIfabs: + case Builtin::BIfabsf: + case Builtin::BIfabsl: + case Builtin::BIcabs: + case Builtin::BIcabsf: + case Builtin::BIcabsl: + return FDecl->getBuiltinID(); + } + llvm_unreachable("Unknown Builtin type"); +} + +// If the replacement is valid, emit a note with replacement function. +// Additionally, suggest including the proper header if not already included. +static void emitReplacement(Sema &S, SourceLocation Loc, SourceRange Range, + unsigned AbsKind) { + std::string AbsName = S.Context.BuiltinInfo.GetName(AbsKind); + + // Look up absolute value function in TU scope. + DeclarationName DN(&S.Context.Idents.get(AbsName)); + LookupResult R(S, DN, Loc, Sema::LookupAnyName); + S.LookupName(R, S.TUScope); + + // Skip notes if multiple results found in lookup. + if (!R.empty() && !R.isSingleResult()) + return; + + FunctionDecl *FD = 0; + bool FoundFunction = R.isSingleResult(); + // When one result is found, see if it is the correct function. + if (R.isSingleResult()) { + FD = dyn_cast(R.getFoundDecl()); + if (!FD || FD->getBuiltinID() != AbsKind) + return; + } + + // Look for local name conflict, prepend "::" as necessary. + R.clear(); + S.LookupName(R, S.getCurScope()); + + if (!FoundFunction) { + if (!R.empty()) { + AbsName = "::" + AbsName; + } + } else { // FoundFunction + if (R.isSingleResult()) { + if (R.getFoundDecl() != FD) { + AbsName = "::" + AbsName; + } + } else if (!R.empty()) { + AbsName = "::" + AbsName; + } + } + + S.Diag(Loc, diag::note_replace_abs_function) + << AbsName << FixItHint::CreateReplacement(Range, AbsName); + + if (!FoundFunction) { + S.Diag(Loc, diag::note_please_include_header) + << S.Context.BuiltinInfo.getHeaderName(AbsKind) + << S.Context.BuiltinInfo.GetName(AbsKind); + } +} + +// Warn when using the wrong abs() function. +void Sema::CheckAbsoluteValueFunction(const CallExpr *Call, + const FunctionDecl *FDecl, + IdentifierInfo *FnInfo) { + if (Call->getNumArgs() != 1) + return; + + unsigned AbsKind = getAbsoluteValueFunctionKind(FDecl); + if (AbsKind == 0) + return; + + QualType ArgType = Call->getArg(0)->IgnoreParenImpCasts()->getType(); + QualType ParamType = Call->getArg(0)->getType(); + + // Unsigned types can not be negative. Suggest to drop the absolute value + // function. + if (ArgType->isUnsignedIntegerType()) { + Diag(Call->getExprLoc(), diag::warn_unsigned_abs) << ArgType << ParamType; + Diag(Call->getExprLoc(), diag::note_remove_abs) + << FDecl + << FixItHint::CreateRemoval(Call->getCallee()->getSourceRange()); + return; + } + + AbsoluteValueKind ArgValueKind = getAbsoluteValueKind(ArgType); + AbsoluteValueKind ParamValueKind = getAbsoluteValueKind(ParamType); + + // The argument and parameter are the same kind. Check if they are the right + // size. + if (ArgValueKind == ParamValueKind) { + if (Context.getTypeSize(ArgType) <= Context.getTypeSize(ParamType)) + return; + + unsigned NewAbsKind = getBestAbsFunction(Context, ArgType, AbsKind); + Diag(Call->getExprLoc(), diag::warn_abs_too_small) + << FDecl << ArgType << ParamType; + + if (NewAbsKind == 0) + return; + + emitReplacement(*this, Call->getExprLoc(), + Call->getCallee()->getSourceRange(), NewAbsKind); + return; + } + + // ArgValueKind != ParamValueKind + // The wrong type of absolute value function was used. Attempt to find the + // proper one. + unsigned NewAbsKind = changeAbsFunction(AbsKind, ArgValueKind); + NewAbsKind = getBestAbsFunction(Context, ArgType, NewAbsKind); + if (NewAbsKind == 0) + return; + + Diag(Call->getExprLoc(), diag::warn_wrong_absolute_value_type) + << FDecl << ParamValueKind << ArgValueKind; + + emitReplacement(*this, Call->getExprLoc(), + Call->getCallee()->getSourceRange(), NewAbsKind); + return; +} + //===--- CHECK: Standard memory functions ---------------------------------===// /// \brief Takes the expression passed to the size_t parameter of functions @@ -7518,3 +7842,4 @@ void Sema::CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, << ArgumentExpr->getSourceRange() << TypeTagExpr->getSourceRange(); } + diff --git a/test/Sema/warn-absolute-value-header.c b/test/Sema/warn-absolute-value-header.c new file mode 100644 index 0000000000..e3bf9ee1e6 --- /dev/null +++ b/test/Sema/warn-absolute-value-header.c @@ -0,0 +1,36 @@ +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only %s -Wabsolute-value -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s + +int abs(int); + +// Wrong signature +int fabsf(int); +// expected-warning@-1{{incompatible redeclaration of library function 'fabsf'}} +// expected-note@-2{{'fabsf' is a builtin with type 'float (float)'}} + +void test_int(int i, unsigned u, long long ll, float f, double d) { + (void)abs(i); + + // Remove abs call + (void)abs(u); + // expected-warning@-1{{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2{{remove the call to 'abs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"" + + int llabs; + (void)llabs; + // Conflict in names, no notes + (void)abs(ll); + // expected-warning@-1{{absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}} + + // Conflict in names, no notes + (void)abs(f); + // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} + + // Suggest header. + (void)abs(d); + // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} + // expected-note@-2{{use function 'fabs' instead}} + // expected-note@-3{{please include the header or explicitly provide a declaration for 'fabs'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs" +} diff --git a/test/Sema/warn-absolute-value.c b/test/Sema/warn-absolute-value.c new file mode 100644 index 0000000000..70601db63a --- /dev/null +++ b/test/Sema/warn-absolute-value.c @@ -0,0 +1,782 @@ +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only %s -Wabsolute-value -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s + +int abs(int); +long int labs(long int); +long long int llabs(long long int); + +float fabsf(float); +double fabs(double); +long double fabsl(long double); + +float cabsf(float _Complex); +double cabs(double _Complex); +long double cabsl(long double _Complex); + +void test_int(int x) { + (void)abs(x); + (void)labs(x); + (void)llabs(x); + + (void)fabsf(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of integer type}} + // expected-note@-2 {{use function 'abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"abs" + (void)fabs(x); + // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of integer type}} + // expected-note@-2 {{use function 'abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"abs" + (void)fabsl(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of integer type}} + // expected-note@-2 {{use function 'abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"abs" + + (void)cabsf(x); + // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of integer type}} + // expected-note@-2 {{use function 'abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"abs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of integer type}} + // expected-note@-2 {{use function 'abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"abs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of integer type}} + // expected-note@-2 {{use function 'abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"abs" + + (void)__builtin_abs(x); + (void)__builtin_labs(x); + (void)__builtin_llabs(x); + + (void)__builtin_fabsf(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_abs" + (void)__builtin_fabs(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_abs" + (void)__builtin_fabsl(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_abs" + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsf' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_abs" + (void)__builtin_cabs(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabs' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_abs" + (void)__builtin_cabsl(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsl' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_abs" +} + +void test_long(long x) { + (void)abs(x); // no warning - int and long are same length for this target + (void)labs(x); + (void)llabs(x); + + (void)fabsf(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of integer type}} + // expected-note@-2 {{use function 'labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"labs" + (void)fabs(x); + // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of integer type}} + // expected-note@-2 {{use function 'labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"labs" + (void)fabsl(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of integer type}} + // expected-note@-2 {{use function 'labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"labs" + + (void)cabsf(x); + // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of integer type}} + // expected-note@-2 {{use function 'labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"labs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of integer type}} + // expected-note@-2 {{use function 'labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"labs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of integer type}} + // expected-note@-2 {{use function 'labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"labs" + + (void)__builtin_abs(x); // no warning - int and long are same length for + // this target + (void)__builtin_labs(x); + (void)__builtin_llabs(x); + + (void)__builtin_fabsf(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_labs" + (void)__builtin_fabs(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_labs" + (void)__builtin_fabsl(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_labs" + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsf' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_labs" + (void)__builtin_cabs(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabs' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_labs" + (void)__builtin_cabsl(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsl' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_labs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_labs" +} + +void test_long_long(long long x) { + (void)abs(x); + // expected-warning@-1{{absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}} + // expected-note@-2{{use function 'llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"llabs" + (void)labs(x); + // expected-warning@-1{{absolute value function 'labs' given an argument of type 'long long' but has parameter of type 'long' which may cause truncation of value}} + // expected-note@-2{{use function 'llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"llabs" + (void)llabs(x); + + (void)fabsf(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of integer type}} + // expected-note@-2 {{use function 'llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"llabs" + (void)fabs(x); + // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of integer type}} + // expected-note@-2 {{use function 'llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"llabs" + (void)fabsl(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of integer type}} + // expected-note@-2 {{use function 'llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"llabs" + + (void)cabsf(x); + // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of integer type}} + // expected-note@-2 {{use function 'llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"llabs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of integer type}} + // expected-note@-2 {{use function 'llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"llabs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of integer type}} + // expected-note@-2 {{use function 'llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"llabs" + + (void)__builtin_abs(x); + // expected-warning@-1{{absolute value function '__builtin_abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}} + // expected-note@-2{{use function '__builtin_llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_llabs" + (void)__builtin_labs(x); + // expected-warning@-1{{absolute value function '__builtin_labs' given an argument of type 'long long' but has parameter of type 'long' which may cause truncation of value}} + // expected-note@-2{{use function '__builtin_llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_llabs" + (void)__builtin_llabs(x); + + (void)__builtin_fabsf(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_llabs" + (void)__builtin_fabs(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_llabs" + (void)__builtin_fabsl(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_llabs" + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsf' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_llabs" + (void)__builtin_cabs(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabs' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_llabs" + (void)__builtin_cabsl(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsl' when argument is of integer type}} + // expected-note@-2 {{use function '__builtin_llabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_llabs" +} + +void test_float(float x) { + (void)abs(x); + // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"fabsf" + (void)labs(x); + // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"fabsf" + (void)llabs(x); + // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabsf" + + (void)fabsf(x); + (void)fabs(x); + (void)fabsl(x); + + (void)cabsf(x); + // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabsf" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"fabsf" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabsf" + + (void)__builtin_abs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_abs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_fabsf" + (void)__builtin_labs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_labs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_fabsf" + (void)__builtin_llabs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_llabs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabsf" + + (void)__builtin_fabsf(x); + (void)__builtin_fabs(x); + (void)__builtin_fabsl(x); + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsf' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabsf" + (void)__builtin_cabs(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_fabsf" + (void)__builtin_cabsl(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsl' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabsf" +} + +void test_double(double x) { + (void)abs(x); + // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"fabs" + (void)labs(x); + // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"fabs" + (void)llabs(x); + // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabs" + + (void)fabsf(x); + // expected-warning@-1{{absolute value function 'fabsf' given an argument of type 'double' but has parameter of type 'float' which may cause truncation of value}} + // expected-note@-2{{use function 'fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabs" + (void)fabs(x); + (void)fabsl(x); + + (void)cabsf(x); + // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"fabs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabs" + + (void)__builtin_abs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_abs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_fabs" + (void)__builtin_labs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_labs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_fabs" + (void)__builtin_llabs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_llabs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabs" + + (void)__builtin_fabsf(x); + // expected-warning@-1{{absolute value function '__builtin_fabsf' given an argument of type 'double' but has parameter of type 'float' which may cause truncation of value}} + // expected-note@-2{{use function '__builtin_fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabs" + (void)__builtin_fabs(x); + (void)__builtin_fabsl(x); + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsf' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabs" + (void)__builtin_cabs(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_fabs" + (void)__builtin_cabsl(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsl' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabs" +} + +void test_long_double(long double x) { + (void)abs(x); + // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"fabsl" + (void)labs(x); + // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"fabsl" + (void)llabs(x); + // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabsl" + + (void)fabsf(x); + // expected-warning@-1{{absolute value function 'fabsf' given an argument of type 'long double' but has parameter of type 'float' which may cause truncation of value}} + // expected-note@-2{{use function 'fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabsl" + (void)fabs(x); + // expected-warning@-1{{absolute value function 'fabs' given an argument of type 'long double' but has parameter of type 'double' which may cause truncation of value}} + // expected-note@-2{{use function 'fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"fabsl" + (void)fabsl(x); + + (void)cabsf(x); + // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabsl" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"fabsl" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of floating point type}} + // expected-note@-2 {{use function 'fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"fabsl" + + (void)__builtin_abs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_abs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_fabsl" + (void)__builtin_labs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_labs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_fabsl" + (void)__builtin_llabs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_llabs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabsl" + + (void)__builtin_fabsf(x); + // expected-warning@-1{{absolute value function '__builtin_fabsf' given an argument of type 'long double' but has parameter of type 'float' which may cause truncation of value}} + // expected-note@-2{{use function '__builtin_fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabsl" + (void)__builtin_fabs(x); + // expected-warning@-1{{absolute value function '__builtin_fabs' given an argument of type 'long double' but has parameter of type 'double' which may cause truncation of value}} + // expected-note@-2{{use function '__builtin_fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_fabsl" + (void)__builtin_fabsl(x); + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsf' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabsl" + (void)__builtin_cabs(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabs' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_fabsl" + (void)__builtin_cabsl(x); + // expected-warning@-1 {{using complex absolute value function '__builtin_cabsl' when argument is of floating point type}} + // expected-note@-2 {{use function '__builtin_fabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_fabsl" +} + +void test_complex_float(_Complex float x) { + (void)abs(x); + // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"cabsf" + (void)labs(x); + // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsf" + (void)llabs(x); + // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf" + + (void)fabsf(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf" + (void)fabs(x); + // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsf" + (void)fabsl(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsf" + + (void)cabsf(x); + (void)cabs(x); + (void)cabsl(x); + + (void)__builtin_abs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_abs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_cabsf" + (void)__builtin_labs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_labs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsf" + (void)__builtin_llabs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_llabs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf" + + (void)__builtin_fabsf(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf" + (void)__builtin_fabs(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsf" + (void)__builtin_fabsl(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsf' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsf" + + (void)__builtin_cabsf(x); + (void)__builtin_cabs(x); + (void)__builtin_cabsl(x); +} + +void test_complex_double(_Complex double x) { + (void)abs(x); + // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"cabs" + (void)labs(x); + // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabs" + (void)llabs(x); + // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabs" + + (void)fabsf(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of complex type}} + // expected-note@-2 {{use function 'cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabs" + (void)fabs(x); + // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabs" + (void)fabsl(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of complex type}} + // expected-note@-2 {{use function 'cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabs" + + (void)cabsf(x); + // expected-warning@-1 {{absolute value function 'cabsf' given an argument of type '_Complex double' but has parameter of type '_Complex float' which may cause truncation of value}} + // expected-note@-2 {{use function 'cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabs" + (void)cabs(x); + (void)cabsl(x); + + (void)__builtin_abs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_abs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_cabs" + (void)__builtin_labs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_labs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabs" + (void)__builtin_llabs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_llabs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabs" + + (void)__builtin_fabsf(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabs" + (void)__builtin_fabs(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabs" + (void)__builtin_fabsl(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabs" + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{absolute value function '__builtin_cabsf' given an argument of type '_Complex double' but has parameter of type '_Complex float' which may cause truncation of value}} + // expected-note@-2 {{use function '__builtin_cabs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabs" + (void)__builtin_cabs(x); + (void)__builtin_cabsl(x); +} + +void test_complex_long_double(_Complex long double x) { + (void)abs(x); + // expected-warning@-1 {{using integer absolute value function 'abs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"cabsl" + (void)labs(x); + // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsl" + (void)llabs(x); + // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsl" + + (void)fabsf(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsf' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsl" + (void)fabs(x); + // expected-warning@-1 {{using floating point absolute value function 'fabs' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsl" + (void)fabsl(x); + // expected-warning@-1 {{using floating point absolute value function 'fabsl' when argument is of complex type}} + // expected-note@-2 {{use function 'cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsl" + + (void)cabsf(x); + // expected-warning@-1 {{absolute value function 'cabsf' given an argument of type '_Complex long double' but has parameter of type '_Complex float' which may cause truncation of value}} + // expected-note@-2 {{use function 'cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"cabsl" + (void)cabs(x); + // expected-warning@-1 {{absolute value function 'cabs' given an argument of type '_Complex long double' but has parameter of type '_Complex double' which may cause truncation of value}} + // expected-note@-2 {{use function 'cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"cabsl" + (void)cabsl(x); + + (void)__builtin_abs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_abs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"__builtin_cabsl" + (void)__builtin_labs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_labs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsl" + (void)__builtin_llabs(x); + // expected-warning@-1 {{using integer absolute value function '__builtin_llabs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsl" + + (void)__builtin_fabsf(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsf' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsl" + (void)__builtin_fabs(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabs' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsl" + (void)__builtin_fabsl(x); + // expected-warning@-1 {{using floating point absolute value function '__builtin_fabsl' when argument is of complex type}} + // expected-note@-2 {{use function '__builtin_cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsl" + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{absolute value function '__builtin_cabsf' given an argument of type '_Complex long double' but has parameter of type '_Complex float' which may cause truncation of value}} + // expected-note@-2 {{use function '__builtin_cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"__builtin_cabsl" + (void)__builtin_cabs(x); + // expected-warning@-1 {{absolute value function '__builtin_cabs' given an argument of type '_Complex long double' but has parameter of type '_Complex double' which may cause truncation of value}} + // expected-note@-2 {{use function '__builtin_cabsl' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"__builtin_cabsl" + (void)__builtin_cabsl(x); +} + +void test_unsigned_int(unsigned int x) { + (void)abs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'abs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"" + (void)labs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'labs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"" + (void)llabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'llabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + + (void)fabsf(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'fabsf' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + (void)fabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'fabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"" + (void)fabsl(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'fabsl' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + + (void)cabsf(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'cabsf' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + (void)cabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'cabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"" + (void)cabsl(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'cabsl' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + + (void)__builtin_abs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_abs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"" + (void)__builtin_labs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_labs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"" + (void)__builtin_llabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_llabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" + + (void)__builtin_fabsf(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_fabsf' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" + (void)__builtin_fabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_fabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"" + (void)__builtin_fabsl(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_fabsl' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_cabsf' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" + (void)__builtin_cabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_cabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"" + (void)__builtin_cabsl(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_cabsl' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" +} + +void test_unsigned_long(unsigned long x) { + (void)abs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'abs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"" + (void)labs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'labs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"" + (void)llabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'llabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + + (void)fabsf(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'fabsf' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + (void)fabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'fabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"" + (void)fabsl(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'fabsl' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + + (void)cabsf(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'cabsf' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + (void)cabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'cabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"" + (void)cabsl(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'cabsl' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"" + + (void)__builtin_abs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_abs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"" + (void)__builtin_labs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_labs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"" + (void)__builtin_llabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_llabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" + + (void)__builtin_fabsf(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_fabsf' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" + (void)__builtin_fabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_fabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"" + (void)__builtin_fabsl(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_fabsl' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" + + (void)__builtin_cabsf(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_cabsf' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" + (void)__builtin_cabs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_cabs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"" + (void)__builtin_cabsl(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to '__builtin_cabsl' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" +} + diff --git a/test/SemaCXX/warn-absolute-value-header.cpp b/test/SemaCXX/warn-absolute-value-header.cpp new file mode 100644 index 0000000000..01aaabcc00 --- /dev/null +++ b/test/SemaCXX/warn-absolute-value-header.cpp @@ -0,0 +1,37 @@ +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only %s -Wabsolute-value -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s + +extern "C" int abs(int); + +// Wrong signature +int fabsf(int); + +void test_int(int i, unsigned u, long long ll, float f, double d) { + (void)abs(i); + + // Remove abs call + (void)abs(u); + // expected-warning@-1{{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2{{remove the call to 'abs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"" + + int llabs; + (void)llabs; + // Conflict in names, suggest qualified name + (void)abs(ll); + // expected-warning@-1{{absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}} + // expected-note@-2{{use function '::llabs' instead}} + // expected-note@-3{{please include the header or explicitly provide a declaration for 'llabs'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"::llabs" + + // Conflict in names, no notes + (void)abs(f); + // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} + + // Suggest header. + (void)abs(d); + // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} + // expected-note@-2{{use function 'fabs' instead}} + // expected-note@-3{{please include the header or explicitly provide a declaration for 'fabs'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs" +} -- 2.40.0