From beffb833dce6d5d1025da4e887918c71d5d6c123 Mon Sep 17 00:00:00 2001 From: Richard Trieu Date: Tue, 15 Apr 2014 23:47:53 +0000 Subject: [PATCH] Make -Wabsolute-value C++-aware. Warn on std::abs() with unsigned argument. Suggest std::abs as replacement for the C absolute value functions. Suggest C++ headers if the specific std::abs overload is not found. llvm-svn: 206340 --- .../clang/Basic/DiagnosticSemaKinds.td | 2 +- clang/lib/Sema/SemaChecking.cpp | 149 +++- .../SemaCXX/warn-absolute-value-header.cpp | 74 +- clang/test/SemaCXX/warn-absolute-value.cpp | 823 ++++++++++++++++++ clang/test/SemaCXX/warn-absolute-value2.cpp | 13 - 5 files changed, 974 insertions(+), 87 deletions(-) create mode 100644 clang/test/SemaCXX/warn-absolute-value.cpp delete mode 100644 clang/test/SemaCXX/warn-absolute-value2.cpp diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 76b314ead50e..180e088d39b2 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -35,7 +35,7 @@ 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">; + "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; diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index b824ec4825b5..e2a69d998fd7 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -3862,54 +3862,107 @@ static unsigned getAbsoluteValueFunctionKind(const FunctionDecl *FDecl) { // 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); - R.suppressDiagnostics(); - 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; + unsigned AbsKind, QualType ArgType) { + bool EmitHeaderHint = true; + const char *HeaderName = 0; + const char *FunctionName = 0; + if (S.getLangOpts().CPlusPlus && !ArgType->isAnyComplexType()) { + FunctionName = "std::abs"; + if (ArgType->isIntegralOrEnumerationType()) { + HeaderName = "cstdlib"; + } else if (ArgType->isRealFloatingType()) { + HeaderName = "cmath"; + } else { + llvm_unreachable("Invalid Type"); } - } else { // FoundFunction - if (R.isSingleResult()) { - if (R.getFoundDecl() != FD) { - AbsName = "::" + AbsName; + + // Lookup all std::abs + if (NamespaceDecl *Std = S.getStdNamespace()) { + LookupResult R(S, &S.PP.getIdentifierTable().get("abs"), Loc, + Sema::LookupAnyName); + R.suppressDiagnostics(); + S.LookupQualifiedName(R, Std); + + for (const auto *I : R) { + const FunctionDecl *FDecl = 0; + if (const UsingShadowDecl *UsingD = dyn_cast(I)) { + FDecl = dyn_cast(UsingD->getTargetDecl()); + } else { + FDecl = dyn_cast(I); + } + if (!FDecl) + continue; + + // Found std::abs(), check that they are the right ones. + if (FDecl->getNumParams() != 1) + continue; + + // Check that the parameter type can handle the argument. + QualType ParamType = FDecl->getParamDecl(0)->getType(); + if (getAbsoluteValueKind(ArgType) == getAbsoluteValueKind(ParamType) && + S.Context.getTypeSize(ArgType) <= + S.Context.getTypeSize(ParamType)) { + // Found a function, don't need the header hint. + EmitHeaderHint = false; + break; + } + } + } + } else { + FunctionName = S.Context.BuiltinInfo.GetName(AbsKind); + HeaderName = S.Context.BuiltinInfo.getHeaderName(AbsKind); + + if (HeaderName) { + DeclarationName DN(&S.Context.Idents.get(FunctionName)); + LookupResult R(S, DN, Loc, Sema::LookupAnyName); + R.suppressDiagnostics(); + S.LookupName(R, S.getCurScope()); + + if (R.isSingleResult()) { + FunctionDecl *FD = dyn_cast(R.getFoundDecl()); + if (FD && FD->getBuiltinID() == AbsKind) { + EmitHeaderHint = false; + } else { + return; + } + } else if (!R.empty()) { + return; } - } else if (!R.empty()) { - AbsName = "::" + AbsName; } } S.Diag(Loc, diag::note_replace_abs_function) - << AbsName << FixItHint::CreateReplacement(Range, AbsName); + << FunctionName << FixItHint::CreateReplacement(Range, FunctionName); - if (!FoundFunction) { - S.Diag(Loc, diag::note_please_include_header) - << S.Context.BuiltinInfo.getHeaderName(AbsKind) - << S.Context.BuiltinInfo.GetName(AbsKind); + if (!HeaderName) + return; + + if (!EmitHeaderHint) + return; + + S.Diag(Loc, diag::note_please_include_header) << HeaderName << FunctionName; +} + +static bool IsFunctionStdAbs(const FunctionDecl *FDecl) { + if (!FDecl) + return false; + + if (!FDecl->getIdentifier() || !FDecl->getIdentifier()->isStr("abs")) + return false; + + const NamespaceDecl *ND = dyn_cast(FDecl->getDeclContext()); + + while (ND && ND->isInlineNamespace()) { + ND = dyn_cast(ND->getDeclContext()); } + + if (!ND || !ND->getIdentifier() || !ND->getIdentifier()->isStr("std")) + return false; + + if (!isa(ND->getDeclContext())) + return false; + + return true; } // Warn when using the wrong abs() function. @@ -3920,7 +3973,8 @@ void Sema::CheckAbsoluteValueFunction(const CallExpr *Call, return; unsigned AbsKind = getAbsoluteValueFunctionKind(FDecl); - if (AbsKind == 0) + bool IsStdAbs = IsFunctionStdAbs(FDecl); + if (AbsKind == 0 && !IsStdAbs) return; QualType ArgType = Call->getArg(0)->IgnoreParenImpCasts()->getType(); @@ -3929,13 +3983,20 @@ void Sema::CheckAbsoluteValueFunction(const CallExpr *Call, // Unsigned types can not be negative. Suggest to drop the absolute value // function. if (ArgType->isUnsignedIntegerType()) { + const char *FunctionName = + IsStdAbs ? "std::abs" : Context.BuiltinInfo.GetName(AbsKind); Diag(Call->getExprLoc(), diag::warn_unsigned_abs) << ArgType << ParamType; Diag(Call->getExprLoc(), diag::note_remove_abs) - << FDecl + << FunctionName << FixItHint::CreateRemoval(Call->getCallee()->getSourceRange()); return; } + // std::abs has overloads which prevent most of the absolute value problems + // from occurring. + if (IsStdAbs) + return; + AbsoluteValueKind ArgValueKind = getAbsoluteValueKind(ArgType); AbsoluteValueKind ParamValueKind = getAbsoluteValueKind(ParamType); @@ -3953,7 +4014,7 @@ void Sema::CheckAbsoluteValueFunction(const CallExpr *Call, return; emitReplacement(*this, Call->getExprLoc(), - Call->getCallee()->getSourceRange(), NewAbsKind); + Call->getCallee()->getSourceRange(), NewAbsKind, ArgType); return; } @@ -3969,7 +4030,7 @@ void Sema::CheckAbsoluteValueFunction(const CallExpr *Call, << FDecl << ParamValueKind << ArgValueKind; emitReplacement(*this, Call->getExprLoc(), - Call->getCallee()->getSourceRange(), NewAbsKind); + Call->getCallee()->getSourceRange(), NewAbsKind, ArgType); return; } diff --git a/clang/test/SemaCXX/warn-absolute-value-header.cpp b/clang/test/SemaCXX/warn-absolute-value-header.cpp index 01aaabcc0021..96e6a3154021 100644 --- a/clang/test/SemaCXX/warn-absolute-value-header.cpp +++ b/clang/test/SemaCXX/warn-absolute-value-header.cpp @@ -1,37 +1,53 @@ // 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); +extern "C" { + int abs(int); + float fabsf(float); +} -// Wrong signature -int fabsf(int); +namespace std { + int abs(int); + float abs(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, 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 test(long long ll, double d, int i, float f) { + // Suggest including cmath (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" + // expected-note@-2{{use function 'std::abs' instead}} + // expected-note@-3{{please include the header or explicitly provide a declaration for 'std::abs'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs" + + (void)fabsf(d); + // 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 'std::abs' instead}} + // expected-note@-3{{please include the header or explicitly provide a declaration for 'std::abs'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs" + + // Suggest including cstdlib + (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 'std::abs' instead}} + // expected-note@-3{{please include the header or explicitly provide a declaration for 'std::abs'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"std::abs" + (void)fabsf(ll); + // expected-warning@-1{{using floating point absolute value function 'fabsf' when argument is of integer type}} + // expected-note@-2{{use function 'std::abs' instead}} + // expected-note@-3{{please include the header or explicitly provide a declaration for 'std::abs'}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:14}:"std::abs" + + // Proper function already called, no warnings. + (void)abs(i); + (void)fabsf(f); + + // Declarations found, suggest name change. + (void)fabsf(i); + // expected-warning@-1{{using floating point absolute value function 'fabsf' when argument is of integer type}} + // expected-note@-2{{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + (void)abs(f); + // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} + // expected-note@-2{{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"std::abs" } diff --git a/clang/test/SemaCXX/warn-absolute-value.cpp b/clang/test/SemaCXX/warn-absolute-value.cpp new file mode 100644 index 000000000000..8a8a6fd67d34 --- /dev/null +++ b/clang/test/SemaCXX/warn-absolute-value.cpp @@ -0,0 +1,823 @@ +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value -std=c++11 +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only %s -Wabsolute-value -fdiagnostics-parseable-fixits -std=c++11 2>&1 | FileCheck %s + +extern "C" { +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); +} + +namespace std { + +inline namespace __1 { +int abs(int); +long int abs(long int); +long long int abs(long long int); +} + +float abs(float); +double abs(double); +long double abs(long double); + +template +double abs(T); + +} + +void test_int(int x) { + (void)std::abs(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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (void)cabsf(x); + // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of integer type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of integer type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of integer type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" +} + +void test_long(long x) { + (void)std::abs(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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (void)cabsf(x); + // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of integer type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of integer type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of integer type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" +} + +void test_long_long(long long x) { + (void)std::abs(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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (void)cabsf(x); + // expected-warning@-1 {{using complex absolute value function 'cabsf' when argument is of integer type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of integer type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of integer type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" +} + +void test_float(float x) { + (void)std::abs(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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"std::abs" + (void)labs(x); + // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (void)llabs(x); + // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" +} + +void test_double(double x) { + (void)std::abs(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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"std::abs" + (void)labs(x); + // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (void)llabs(x); + // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" +} + +void test_long_double(long double x) { + (void)std::abs(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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"std::abs" + (void)labs(x); + // expected-warning@-1 {{using integer absolute value function 'labs' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (void)llabs(x); + // expected-warning@-1 {{using integer absolute value function 'llabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + (void)cabs(x); + // expected-warning@-1 {{using complex absolute value function 'cabs' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:13}:"std::abs" + (void)cabsl(x); + // expected-warning@-1 {{using complex absolute value function 'cabsl' when argument is of floating point type}} + // expected-note@-2 {{use function 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:14}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:22}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" + + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:23}:"std::abs" + (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 'std::abs' instead}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"std::abs" +} + +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)std::abs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned int' has no effect}} + // expected-note@-2 {{remove the call to 'std::abs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:17}:"" + + (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)std::abs(x); + // expected-warning@-1 {{taking the absolute value of unsigned type 'unsigned long' has no effect}} + // expected-note@-2 {{remove the call to 'std::abs' since unsigned values cannot be negative}} + // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:17}:"" + + (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/clang/test/SemaCXX/warn-absolute-value2.cpp b/clang/test/SemaCXX/warn-absolute-value2.cpp deleted file mode 100644 index 5f7e8918787f..000000000000 --- a/clang/test/SemaCXX/warn-absolute-value2.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value - -extern "C" { -int abs(int); -double fabs(double); -} - -using ::fabs; - -double test(double x) { - return ::abs(x); - // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}} -}