diff options
author | David Majnemer <david.majnemer@gmail.com> | 2015-11-15 03:04:34 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2015-11-15 03:04:34 +0000 |
commit | 7f77eb90a54c96168d6cce8ad3a85d1454cdb80c (patch) | |
tree | 9209507d1706b1af523846a7b3b30661fc35e8f5 /clang/test/Sema | |
parent | 07fa1766699ed035a2d5388f7b492c4fd9e54028 (diff) | |
download | bcm5719-llvm-7f77eb90a54c96168d6cce8ad3a85d1454cdb80c.tar.gz bcm5719-llvm-7f77eb90a54c96168d6cce8ad3a85d1454cdb80c.zip |
[Sema] Don't crash trying to diagnose abs called on a pointer type
Clang tries to figure out if a call to abs is suspicious by looking
through implicit casts to look at the underlying, implicitly converted
type.
Interestingly, C has implicit conversions from pointer-ish types like
function to less exciting types like int. This trips up our 'abs'
checker because it doesn't know which variant of 'abs' is appropriate.
Instead, diagnose 'abs' called on function types upfront. This sort of
thing is highly suspicious and is likely indicative of a missing
pointer dereference/function call/array index operation.
This fixes PR25532.
llvm-svn: 253156
Diffstat (limited to 'clang/test/Sema')
-rw-r--r-- | clang/test/Sema/warn-absolute-value.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/clang/test/Sema/warn-absolute-value.c b/clang/test/Sema/warn-absolute-value.c index 70601db63a1..109d515d3b2 100644 --- a/clang/test/Sema/warn-absolute-value.c +++ b/clang/test/Sema/warn-absolute-value.c @@ -1,5 +1,5 @@ -// 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 +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value -Wno-int-conversion +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only %s -Wabsolute-value -Wno-int-conversion -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s int abs(int); long int labs(long int); @@ -780,3 +780,19 @@ void test_unsigned_long(unsigned long x) { // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:24}:"" } +long long test_array() { + return llabs((long long[]){1}); + // expected-warning@-1 {{absolute value of array type}} +} +long long test_function_pointer() { + return llabs(&test_function_pointer); + // expected-warning@-1 {{absolute value of pointer type}} +} +long long test_void_pointer(void *x) { + return llabs(x); + // expected-warning@-1 {{absolute value of pointer type}} +} +long long test_function() { + return llabs(test_function); + // expected-warning@-1 {{absolute value of function type}} +} |