Commit Graph

1600 Commits

Author SHA1 Message Date
Abramo Bagnara 5d3e724fc5 Fixed cast to union with anonymous bitfields.
llvm-svn: 115979
2010-10-07 21:20:44 +00:00
Fariborz Jahanian c74073cd20 Patch for adding message to unavailable attribute.
And its documentation.
Finishes off // rdar: // 6734520.

llvm-svn: 115862
2010-10-06 23:12:32 +00:00
Fariborz Jahanian 55106310ae Add message to attribute(deprecated).
attribute(unavailable) to do next.
// rdar:// 6734520.

llvm-svn: 115842
2010-10-06 21:18:44 +00:00
Fariborz Jahanian 4801cc6315 Issue deprecated warning when typeof uses typedef
based on underlying type's deprecatedness.

llvm-svn: 115800
2010-10-06 17:00:02 +00:00
Chandler Carruth a64aedb34b Remove hard CRLF end-of-line markers from two files. These should be added
automatically when syncing due to the auto-props selecting svn:eol-style of
'native'.

llvm-svn: 115758
2010-10-06 06:50:05 +00:00
John McCall 2551c1bbcd Provide a slightly specialized diagnostic for tautological comparisons
of an enum value.

llvm-svn: 115725
2010-10-06 00:25:24 +00:00
Fariborz Jahanian 121f5148fd Issue deprecated warning when typeof uses an
expression of deprecated type.

llvm-svn: 115713
2010-10-05 23:24:00 +00:00
Chris Lattner 3be167f606 diagnose errors when a builtin that require constant arguments don't have them.
For example, on:

#include <emmintrin.h>
int foo(int N) {
 __m128i white2;
 white2 = _mm_slli_si128(white2, N);
 return 0;
} 

we used to get:
fatal error: error in backend: Cannot yet select: intrinsic %llvm.x86.sse2.psll.dq

now we get:
/Users/sabre/t.c:4:11: error: argument to '__builtin_ia32_pslldqi128' must be a
      constant integer
 white2 = _mm_slli_si128(white2, N);
          ^~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Users/sabre/t.c:1:
/Volumes/Projects/cvs/llvm/Debug+Asserts/lib/clang/2.9/include/emmintrin.h:781:13: note: instantiated from:
  ((__m128i)__builtin_ia32_pslldqi128((__m128i)(VEC), (IMM)*8))
            ^                                         ~~~~~~~
1 error generated.

llvm-svn: 115374
2010-10-01 23:23:24 +00:00
Daniel Dunbar 8caf6415a8 Add support for attribute((naked)), patch by Zoxc on cfe-commits!
- Minor style tweaks by me.

llvm-svn: 115056
2010-09-29 18:20:25 +00:00
Argyrios Kyrtzidis 9f48354b71 Don't warn for an unused label if it has 'unused' attribute. Fixes rdar://8483139.
llvm-svn: 114954
2010-09-28 14:54:07 +00:00
Abramo Bagnara b59a5b6784 Fixed isConstantInitializer for __builtin_choose_expr.
llvm-svn: 114820
2010-09-27 07:13:32 +00:00
Ted Kremenek 6274be47fa When warning about comparing an unsigned int to being >= 0, don't issue a warning if the zero value was an
enum or was expanded from a macro.

Fixes: <rdar://problem/8414119>
llvm-svn: 114695
2010-09-23 21:43:44 +00:00
Nate Begeman abb5a7370d Check in support for OpenCL conditional operator on vector types.
llvm-svn: 114371
2010-09-20 22:41:17 +00:00
Argyrios Kyrtzidis 40cec8326c Revert r114316, -Wunused-value enabled by default was intended.
llvm-svn: 114318
2010-09-19 23:03:35 +00:00
Argyrios Kyrtzidis 3698bf1c6d Make -Wunused-value off by default, matching GCC. Fixes rdar://7126194.
llvm-svn: 114316
2010-09-19 21:21:44 +00:00
Argyrios Kyrtzidis 72664df103 Implement -Wunused-label.
llvm-svn: 114315
2010-09-19 21:21:25 +00:00
Argyrios Kyrtzidis 9096341310 Warn when an expression result in a LabelStmt is unused.
llvm-svn: 114314
2010-09-19 21:21:10 +00:00
Chris Lattner 516790870e improve the "enumeration value 'g' not handled in switch"
warning to handle multiple enumerators with one warning.

llvm-svn: 114093
2010-09-16 17:09:42 +00:00
Ted Kremenek 8eeec5bd03 Do not warn about empty bodies for 'if' statements if the body is expanded from a macro.
Fixes <rdar://problem/8436021>.

llvm-svn: 114049
2010-09-16 00:37:05 +00:00
Ted Kremenek 853734e558 For self-comparison warning, check the source location of both the LHS and RHS to see if they
are expanded from macros (and if so, omit the warning).  Previously we were just looking at the
location of the binary expression.

Fixes <rdar://problem/8435950>.

llvm-svn: 114044
2010-09-16 00:03:01 +00:00
Francois Pichet f657b639fd Microsoft's flexible array rules relaxation:
- in union
   - as the only element of a struct/class.

llvm-svn: 113909
2010-09-15 00:14:08 +00:00
Abramo Bagnara 3aabb4b452 Congruent diagnostic for void* arithmetic.
llvm-svn: 113740
2010-09-13 06:50:07 +00:00
Douglas Gregor 6a6dac2fbf Support strlen() and __builtin_strlen() as constant expressions with
the call argument is a string literal. Fixes
<rdar://problem/8413477>.

llvm-svn: 113580
2010-09-10 06:27:15 +00:00
Ted Kremenek b8176da314 Check format strings when a called function has more than one FormatAttr (one for 'scanf' and one for 'printf'). Fixes <rdar://problem/8409437>.
llvm-svn: 113472
2010-09-09 04:33:05 +00:00
Ted Kremenek 1520dae606 It appears that technically a null format string is not warned under -Wformat-nonliteral, as
the function processing the format string can decided whether or not to accept a null format string (e.g., asl_log).  Fixes <rdar://problem/8269537>.

llvm-svn: 113469
2010-09-09 03:51:42 +00:00
Ted Kremenek f2b0a1bfa0 Enhance -Wunreachable-code to not consider the 'default:' branch of a switch statement live if a switch on an enum value has
explicit 'case:' statements for each enum value.

llvm-svn: 113451
2010-09-09 00:06:10 +00:00
Ted Kremenek 50205744c3 Enhance -Wreturn-type to not warn when control-flow is most likely limited by a switch statement explicitly covering
all the cases for an enum value.

llvm-svn: 113450
2010-09-09 00:06:07 +00:00
Daniel Dunbar 53c9ac30f9 tests: Use -ffreestanding when including stdint.h, to avoid platform dependencies.
llvm-svn: 113301
2010-09-07 22:54:28 +00:00
Fariborz Jahanian 56603ef7b2 Have Sema check for validity of CGString literal
instead of asserting in IRGen. Fixes radar 8390459.

llvm-svn: 113253
2010-09-07 19:38:13 +00:00
Douglas Gregor a7d6e3d0f5 Provide a specific diagnostic when trying to redefine an "extern
inline" function outside of GNU89 mode. Fixes
<rdar://problem/6880464>.

llvm-svn: 113204
2010-09-07 15:51:01 +00:00
Chris Lattner ee8df8f167 fix PR7192 by defining wchar_t in a more conventional way. The
type of L"x" can change based on command line arguments.

llvm-svn: 113127
2010-09-05 23:29:49 +00:00
Chris Lattner 9dd55103c1 print "const intptr_t" instead of "intptr_t const"
llvm-svn: 113091
2010-09-05 00:07:29 +00:00
Chris Lattner 53fa04909c make clang print types as "const int *" instead of "int const*",
which is should have done from the beginning.  As usual, the most
fun with this sort of change is updating all the testcases.

llvm-svn: 113090
2010-09-05 00:04:01 +00:00
Anders Carlsson af7534f084 Get rid of the "functions declared 'noreturn' should have a 'void' result type" warning.
The rationale behind this is that it is normal for callback functions to have a non-void return type
and it should still be possible to mark them noreturn. (JavaScriptCore is a good example of this).

llvm-svn: 112918
2010-09-03 00:25:02 +00:00
Chris Lattner 0073962025 when emitting an error about a missing } in a compound statement, emit
a "to match this {" note, pointing out the opener.

llvm-svn: 112709
2010-09-01 15:49:26 +00:00
Eric Christopher a613f56559 With lax vector conversions (the default) make sure we convert between two
vectors that are the same size. Fix up testcases accordingly and add a new one
to make sure we still error if lax vector conversions are disabled.

Fixes rdar://8328190

llvm-svn: 112122
2010-08-26 00:42:16 +00:00
Douglas Gregor 334a10a343 Implement __builtin_printf, __builtin_fprintf. Fixes <rdar://problem/8336581>.
llvm-svn: 112049
2010-08-25 15:47:31 +00:00
Argyrios Kyrtzidis dfffabd0e9 Recursive functions should be marked when used from another function. Fixes http://llvm.org/PR7923.
llvm-svn: 112045
2010-08-25 10:34:54 +00:00
Ted Kremenek 5f0c066062 Fix printf format string checking for '%lc' (which expects a wint_t or compatible argument). Fixes PR 7981.
llvm-svn: 111978
2010-08-24 22:24:51 +00:00
Eli Friedman 4202c34539 Fix for PR7911 and PR7921: make isIntegralOrEnumerationType return false
for incomplete enum types.  An incomplete enum can't really be treated as
an "integral or enumeration" type, and the incorrect treatment leads to
bad behavior for many callers.

This makes isIntegralOrEnumerationType equivalent to isIntegerType; I think
we should globally replace the latter with the former; thoughts?

llvm-svn: 111512
2010-08-19 04:39:37 +00:00
Ted Kremenek 50e0105f1c Add warning for functions/blocks that have attribute 'noreturn' but return a non-void result. (<rdar://problem/7562925>)
llvm-svn: 111492
2010-08-19 00:52:13 +00:00
Douglas Gregor caa1bf434d Emit an error if an array is too large. We're slightly more strict
than GCC 4.2 here when building 32-bit (where GCC will allow
allocation of an array for which we can't get a valid past-the-end
pointer), and emulate its odd behavior in 64-bit where it only allows
63 bits worth of storage in the array. The former is a correctness
issue; the latter is harmless in practice (you wouldn't be able to use
such an array anyway) and helps us pass a GCC DejaGNU test.

Fixes <rdar://problem/8212293>.

llvm-svn: 111338
2010-08-18 00:39:00 +00:00
Argyrios Kyrtzidis 1b30d9c0f0 Commit improved version of 111026 & 111027.
Unused warnings for functions:
-static functions
-functions in anonymous namespace
-class methods in anonymous namespace
-class method specializations in anonymous namespace
-function specializations in anonymous namespace

Unused warnings for variables:
-static variables
-variables in anonymous namespace
-static data members in anonymous namespace
-static data members specializations in anonymous namespace

Reveals lots of opportunities for dead code removal in llvm codebase that will
interest my esteemed colleagues.

llvm-svn: 111086
2010-08-15 01:15:20 +00:00
Eli Friedman 9571953f36 PR7884: Fix the implementations of __real__ and __imag__ on real floats.
llvm-svn: 111080
2010-08-14 20:52:13 +00:00
Eli Friedman df2392572e PR3344: Downgrade "too many braces around scalar initializer" to a warning.
llvm-svn: 111067
2010-08-14 03:14:53 +00:00
Argyrios Kyrtzidis 98703d3883 Revert 111026 & 111027, build breakage.
llvm-svn: 111036
2010-08-13 20:13:06 +00:00
Argyrios Kyrtzidis 540bc01f50 Expand the unused warnings for functions. Warn for:
-static function declarations
-functions in anonymous namespace
-class methods in anonymous namespace
-class method specializations in anonymous namespace
-function specializations in anonymous namespace

llvm-svn: 111026
2010-08-13 18:42:29 +00:00
John McCall 2b5c1b2516 Implement -Wcast-align. The initial design of this diagnostic diverges
from GCC's in that we warn on *any* increase in alignment requirements, not
just those that are enforced by hardware.  Please let us know if this causes
major problems for you (which it shouldn't, since it's an optional warning).

llvm-svn: 110959
2010-08-12 21:44:57 +00:00
Eli Friedman 88f4ed9011 Fix redefinition of typedefs of fixable variably-modified array types; should
fix an issue compiling <windows.h>.

llvm-svn: 110651
2010-08-10 03:13:15 +00:00
Douglas Gregor 7260905918 Make sure that we diagnose attribute((overloadable)) functions without
prototypes. Fixes PR7738.

llvm-svn: 110443
2010-08-06 13:50:58 +00:00
Douglas Gregor 59e8b3bd7b Introduce implicit conversions between AltiVec vectors and GCC
vectors, from Anton Yartsev!

llvm-svn: 110437
2010-08-06 10:14:59 +00:00
John McCall 4a33fa95c0 Labels (and case statement) don't create independent scope parents for the
purposes of the jump checker.  Also extend Ted's iteration fix to labels.

Fixes PR7789.

llvm-svn: 110082
2010-08-02 23:33:14 +00:00
Douglas Gregor 17ea3f5dbd Allow a looser form of compatibility checking (which ignores
qualifiers) when checking a K&R function definition against a previous
prototype. Fixes <rdar://problem/8193107>.

llvm-svn: 109751
2010-07-29 15:18:02 +00:00
Douglas Gregor da2955ed74 Reword the empty struct/union warning in C to note that such structs and unions have size 0 in C, size 1 in C++. Put this warning under -Wc++-compat.
llvm-svn: 109748
2010-07-29 14:29:34 +00:00
Douglas Gregor 45bd34a104 Make the pointer arguments to the __sync_* builtins pointers to
volatile-qualified types. Fixes <rdar://problem/8228293>.

llvm-svn: 109618
2010-07-28 18:42:27 +00:00
Benjamin Kramer e93c39045a Mark __builtin_eh_return as noreturn. Patch by Dimitry Andric.
llvm-svn: 109452
2010-07-26 22:04:15 +00:00
Chris Lattner 938533db60 turn down the logical bitwise confusion warning to not warn
when the RHS of the ||/&& is ever 0 or 1.  This handles a variety of
creative idioms for "true" used in C programs and fixes many false 
positives at the expense of a few false negatives.  This fixes
rdar://8230351.

llvm-svn: 109314
2010-07-24 01:10:11 +00:00
Fariborz Jahanian 946274471d Allow __func__ and __FUNCTION__ and __PRETTY_FUNCTION__ inside blocks.
Radar 8218839.

llvm-svn: 109272
2010-07-23 21:53:24 +00:00
Douglas Gregor 5cc2c8b9c3 Vectors are not integer types, so the type system should not classify
them as such. Type::is(Signed|Unsigned|)IntegerType() now return false
for vector types, and new functions
has(Signed|Unsigned|)IntegerRepresentation() cover integer types and
vector-of-integer types. This fixes a bunch of latent bugs.

Patch from Anton Yartsev!

llvm-svn: 109229
2010-07-23 15:58:24 +00:00
Ted Kremenek 4407ea4948 Hookup checking for invalid length modifiers in scanf format strings.
llvm-svn: 108907
2010-07-20 20:04:47 +00:00
Ted Kremenek 6cd694233d Don't warn when a '%%' or '%*d' (scanf) is used in a format string with positional arguments, since
these don't actually consume an argument.

llvm-svn: 108757
2010-07-19 22:01:06 +00:00
Ted Kremenek ce81542d61 Hook up 'invalid conversion' warning for scanf format strings.
llvm-svn: 108750
2010-07-19 21:25:57 +00:00
Ted Kremenek 5c3e1b9a54 Add missing conversion specifier parsing for 'u', 'x', 'o', and 's'. Fixes <rdar://problem/8204052>.
llvm-svn: 108742
2010-07-19 19:47:40 +00:00
Chandler Carruth bc8cab16c5 Improve the representation of the atomic builtins in a few ways. First, we make
their call expressions synthetically have the "deduced" types based on their
first argument. We only insert conversions in the AST for arguments whose
values require conversion to match the value type expected. This keeps PR7600
closed by maintaining the return type, but avoids assertions due to unexpected
implicit casts making the type unsigned (test case added from Daniel).

The magic is moved into the codegen for the atomic builtin which inserts the
casts as needed at the IR level to raise the type to an integer suitable for
the LLVM intrinsic. This shouldn't cause any real change in functionality, but
now we can make the builtin be more truly polymorphic.

llvm-svn: 108638
2010-07-18 07:23:17 +00:00
Eli Friedman e98194d9e8 Check for casts to an incomplete type in C. Improves diagnostics for cast to
incomplete union (PR5692) and incomplete enum, and fixes obscure
accepts-invalid on cast to incomplete struct.

llvm-svn: 108630
2010-07-17 20:43:49 +00:00
Ted Kremenek 0030be81f5 Remove unicode quotes characters that somehow made it into a recent commit of mine.
llvm-svn: 108552
2010-07-16 20:49:01 +00:00
Ted Kremenek d7b31cc60d Hook up warning for an incomplete scanlist in scanf format strings.
llvm-svn: 108542
2010-07-16 18:28:03 +00:00
Ted Kremenek c618728e8d Tweak zero-field width in scanf format string diagnostic.
llvm-svn: 108541
2010-07-16 18:27:56 +00:00
Daniel Dunbar 84336ba3f8 Sema: Fix a bug with #pragma options align=reset, reset against an empty stack
is well defined, it resets to the default alignment.

llvm-svn: 108508
2010-07-16 04:54:16 +00:00
Ted Kremenek 5530131bb7 Add initial test cases for scanf format string checking.
llvm-svn: 108503
2010-07-16 02:11:34 +00:00
Daniel Dunbar 999daa57c7 Builtins/ARM: __clear_cache doesn't seem to have a consistent prototype, declare
the builtin as void __clear_cache(...) to workaround this, which appears to
match what GCC does.

llvm-svn: 108487
2010-07-16 00:31:23 +00:00
Douglas Gregor cb2b662283 Make the "unused result" warning a warning about run-time behavior, so
that we don't warn when there isn't going to be any computation anyway.

llvm-svn: 108442
2010-07-15 18:47:04 +00:00
Chris Lattner deee7a3c0b restrict the && -> & warning to cover a case daniel noted.
Don't warn about "logically bool" expressions on the RHS,
even if they fold to a constant.

llvm-svn: 108388
2010-07-15 00:26:43 +00:00
Chandler Carruth cb3b5a483f Wire up '-Wignored-qualifiers' to the warning on 'const' in 'const int f()'.
This flag and warning match GCC semantics. Also, move it to -Wextra as this is
a largely cosmetic issue and doesn't seem to mask problems. Subsequent fixes to
the tests which no longer by default emit the warning. Added explicit test
cases for both C and C++ behavior with the warning turned on.

llvm-svn: 108325
2010-07-14 06:36:18 +00:00
Chris Lattner 8406c5197b Add a warning to catch a bug recently caught by code review, like this:
t2.c:2:12: warning: use of logical && with constant operand; switch to bitwise &
      or remove constant [-Wlogical-bitwise-confusion]
  return x && 4;
           ^  ~

wording improvement suggestions are welcome.

llvm-svn: 108260
2010-07-13 19:41:32 +00:00
Douglas Gregor 603d81bf8d When forming a function call or message send expression, be sure to
strip cv-qualifiers from the expression's type when the language calls
for it: in C, that's all the time, while C++ only does it for
non-class types. 

Centralized the computation of the call expression type in
QualType::getCallResultType() and some helper functions in other nodes
(FunctionDecl, ObjCMethodDecl, FunctionType), and updated all relevant
callers of getResultType() to getCallResultType().

Fixes PR7598 and PR7463, along with a bunch of getResultType() call
sites that weren't stripping references off the result type (nothing
stripped cv-qualifiers properly before this change).

llvm-svn: 108234
2010-07-13 08:18:22 +00:00
Ted Kremenek 424ce75f8d Add test case for <rdar://problem/8177927> (which triggered an assertion failure in SemaChecking).
llvm-svn: 108159
2010-07-12 17:35:39 +00:00
Chandler Carruth 65a38183f0 Fix another aspect of PR7047, macro expansions. Previously, this was hacked
around by exempting enums from the check, but this doesn't handle a lot of
cases. A better approach is to directly check if the operator comes from
a macro expansion.

I've removed a reference to the rdar that originally led to the enum
suppression when removing it's overly contrived test case. Let me know if that
number or a more reasilistic test case involving enums is still needed.

llvm-svn: 108128
2010-07-12 06:23:38 +00:00
Chris Lattner 33919e7450 fix PR7280 by making the warning on code like this:
int test1() {
  return;
}

default to an error.

llvm-svn: 108108
2010-07-11 23:34:02 +00:00
Chandler Carruth 741e5cea77 Fix PR7600, and correctly convert the result of an atomic builtin to the
expected value type. This is necessary as the builtin is internally represented
as only operating on integral types.

Also, add a FIXME to add support for floating point value types.

llvm-svn: 108002
2010-07-09 18:59:35 +00:00
Douglas Gregor 8014df4c21 Refer to implicit "conversions" rather than implicit "casts", which
don't technically exist in the language. <rdar://problem/8085982>

llvm-svn: 107995
2010-07-09 18:18:35 +00:00
Chandler Carruth dd1bc0f1b5 Add support for differentiating between attributes ignored when handled and
unknown attributes that we discard. Add a diagnostic group for unknown
attribute warnings to allow turning these off when we don't care. Also
consolidates the tests for this case.

llvm-svn: 107864
2010-07-08 09:42:26 +00:00
Nate Begeman 5da51d38d7 Fix an issue with opencl init list checking.
llvm-svn: 107824
2010-07-07 22:26:56 +00:00
Chris Lattner 3956106543 implement PR7569, warning about assignment to null, which
people seem to write when they want a deterministic trap.
Suggest instead that they use a volatile pointer or 
__builtin_trap.

llvm-svn: 107756
2010-07-07 06:14:23 +00:00
Douglas Gregor bc0c79b4ab Clean up the diagnostic complaining about the element type of a vector
type so that it actually complains about the element type itself.

llvm-svn: 107299
2010-06-30 17:30:41 +00:00
Douglas Gregor 2187266120 Complain about the application of a transparent_union attribute to a
union whose first field has integral vector type. Also, clean up this
diagnostic a bit. Thanks to Eli for spotting this change in semantics
last week.

llvm-svn: 107296
2010-06-30 17:24:13 +00:00
Argyrios Kyrtzidis 639ffb0c07 Fix rdar://8139785 "implement warning on dead expression in comma operator"
As a bonus, fix the warning for || and && operators; it was emitted even if one of the operands had side effects, e.g:

x || test_logical_foo1();

emitted a bogus "expression result unused" for 'x'.

llvm-svn: 107274
2010-06-30 10:53:14 +00:00
Douglas Gregor 5823da3ab0 Re-improve recovery when the condition of a switch statement does not
have integral or enumeration type, so that we still check the contents
of the switch body. My previous patch made this worse; now we're back
to where we were previously.

llvm-svn: 107223
2010-06-29 23:25:20 +00:00
Douglas Gregor f4ea725d38 Factor the conversion from a switch condition to an integral or
enumeration type out into a separate, reusable routine. The only
functionality change here is that we recover a little more
aggressively from ill-formed switch conditions.

llvm-svn: 107222
2010-06-29 23:17:37 +00:00
Daniel Dunbar f35e76552f Sema: Fix a subtle i64 -> i32 truncation which broke layout of large structures
with bit-fields.

llvm-svn: 107185
2010-06-29 18:34:35 +00:00
Douglas Gregor 56980d688b With packed enums, an enumerator's value may be stored in more bits
than the enumeration type itself takes. Fixes PR7477.

llvm-svn: 107163
2010-06-29 17:12:35 +00:00
Daniel Dunbar ec1bee907a tests: Spell %clang_cc1 correctly.
llvm-svn: 107152
2010-06-29 16:52:18 +00:00
Fariborz Jahanian 4f9c9d6591 Fixes a regression when redeclaration of a global satic
is an extern local to a function. Radar 8125274.

llvm-svn: 106773
2010-06-24 18:50:41 +00:00
Douglas Gregor a3208f9e7c Vector types are not arithmetic types, either. Note that we now ban
__real myvec and __imag myvec, since they aren't all that useful (it's
just an identity function) but we might want to use them in more
restricted cases in the future (e.g., "__real mycomplexvec" could
extract the real parts of a vector of complex numbers).

llvm-svn: 106601
2010-06-22 23:41:02 +00:00
Douglas Gregor c646d13054 Teach Type::isRealType() that vector types are never real types. All
of the callers of isRealType() already assumed this, and one of them
(increment/decrement) mistakenly permitted increments of vector types
because of it.

llvm-svn: 106596
2010-06-22 23:13:52 +00:00
Douglas Gregor 49b4d73451 Type Type::isRealFloatingType() that vectors are not floating-point
types, updating callers of both isFloatingType() and
isRealFloatingType() accordingly. Caught at least one issue where we
allowed one to declare a vector of vectors (!), along with cleaning up
the standard-conversion logic for C++.

llvm-svn: 106595
2010-06-22 23:07:26 +00:00
Tom Care 3f272b853f Bug 7377: printf checking fails to flag some undefined behavior
http://llvm.org/bugs/show_bug.cgi?id=7377

Updated format string highlighting and fixits to take advantage of the new CharSourceRange class.
- Change HighlightRange to allow highlighting whitespace only in a CharSourceRange (for warnings about the ' ' (space) flag)
- Change format specifier range helper function to allow for half-open ranges (+1 to end)
- Enabled previously failing tests (FIXMEs/XFAILs removed)
- Small fixes and additions to format string test cases

M       test/Sema/format-strings.c
M       test/Sema/format-strings-fixit.c
M       lib/Frontend/TextDiagnosticPrinter.cpp
M       lib/Sema/SemaChecking.cpp

llvm-svn: 106480
2010-06-21 21:21:01 +00:00
Fariborz Jahanian cc99b3ca9e Fixes a corner case bug whereby declaring and defining an extern variable in a
particular sequence causes its definition to not be generated in the object file.
(fixes radar 8071804).

llvm-svn: 106424
2010-06-21 16:08:37 +00:00
Douglas Gregor 8fba4f22ce Don't complain about missing field initializers when the initializer
list is completely empty, from Lasse Kärkkäinen! Fixes PR7413.

llvm-svn: 106320
2010-06-18 21:43:10 +00:00
Douglas Gregor 77e274fbc6 Merge the "regparm" attribute from a previous declaration of a
function to redeclarations of that function. Fixes PR7025.

llvm-svn: 106317
2010-06-18 21:30:25 +00:00
Tom Care 6e4ea2db7f Printf format strings: Added some more tests and fixed some minor bugs.
- Precision toStrings shouldn't print a dot when they have no value.
- Length of char length modifier is now returned correctly.
- Added several fixit tests.

Note: fixit tests are currently broken due to a bug in HighlightRange. Marking as XFAIL for now.

M    test/Sema/format-strings-fixit.c
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp

llvm-svn: 106275
2010-06-18 03:02:16 +00:00
Tom Care b49ec6907b Bug 7377: Fixed several bad printf format string bugs.
- Added warning for undefined behavior when using field specifier
- Added warning for undefined behavior when using length modifier
- Fixed warnings for invalid flags
- Added warning for ignored flags
- Added fixits for the above warnings
- Fixed accuracy of detecting several undefined behavior conditions
- Receive normal warnings in addition to security warnings when using %n
- Fix bug where '+' flag would remain on unsigned conversion suggestions

Summary of changes:
- Added expanded tests
- Added/expanded warnings
- Added position info to OptionalAmounts for fixits
- Extracted optional flags to a wrapper class with position info for fixits
- Added several methods to validate a FormatSpecifier by component, each checking for undefined behavior
- Fixed conversion specifier checking to conform to C99 standard
- Added hooks to detect the invalid states in CheckPrintfHandler::HandleFormatSpecifier

Note: warnings involving the ' ' (space) flag are temporarily disabled until whitespace highlighting no longer triggers assertions. I will make a post about this on cfe-dev shortly.

M    test/Sema/format-strings.c
M    include/clang/Basic/DiagnosticSemaKinds.td
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp
M    lib/Sema/SemaChecking.cpp

llvm-svn: 106233
2010-06-17 19:00:27 +00:00
Ted Kremenek 98008a47a0 Fix format string checking of '%c' by treating it as an integer conversion. Fixes PR 7391.
llvm-svn: 106196
2010-06-17 01:12:20 +00:00
Ted Kremenek 64c235e4c6 Extend format string type-checking to include '%p'. Fixes remaining cases PR 4468.
llvm-svn: 106151
2010-06-16 21:23:04 +00:00
John McCall 45d30c3e36 When deciding whether an expression has the boolean nature, don't look through
explicit casts.  Fixes PR7359.

llvm-svn: 105871
2010-06-12 01:56:02 +00:00
Tom Care 00554634db Small fixes regarding printf fix suggestions.
- Added some handling of flags that become invalid when changing the conversion specifier.
- Changed fixit behavior to remove unnecessary length modifiers.
- Separated some tests out and added some comments.

modified:
  lib/Analysis/PrintfFormatString.cpp
  test/Sema/format-strings-fixit.c

llvm-svn: 105807
2010-06-11 04:22:02 +00:00
Tom Care b704270779 Added FixIt support to printf format string checking.
- Refactored LengthModifier to be a class.
- Added toString methods in all member classes of FormatSpecifier.
- FixIt suggestions keep user specified flags unless incorrect.

Limitations:
- The suggestions are not conversion specifier sensitive. For example, if we have a 'pad with zeroes' flag, and the correction is a string conversion specifier, we do not remove the flag. Clang will warn us on the next compilation.

A    test/Sema/format-strings-fixit.c
M    include/clang/Analysis/Analyses/PrintfFormatString.h
M    lib/Analysis/PrintfFormatString.cpp
M    lib/Sema/SemaChecking.cpp

llvm-svn: 105680
2010-06-09 04:11:11 +00:00
Douglas Gregor ec170db73d Warn about comparisons between arrays and improve self-comparison
warnings, from Troy Straszheim! Fixes PR6163.

llvm-svn: 105631
2010-06-08 19:50:34 +00:00
Rafael Espindola e971b9a260 Correctly align large arrays in x86-64. This fixes PR5599.
llvm-svn: 105500
2010-06-04 23:15:27 +00:00
Fariborz Jahanian 9f718743a1 Changed text of 'empty enum' diagnostics to say so.
llvm-svn: 105013
2010-05-28 22:43:53 +00:00
Fariborz Jahanian 6e81492151 Empty enum in c is now error to match gcc's behavior.
(radar 8040068).

llvm-svn: 105011
2010-05-28 22:23:22 +00:00
Daniel Dunbar 9c84d4a8a0 Parse/Sema: Add support for '#pragma options align=packed', which, it should be
noted, is not the same as __attribute__((packed)). That would be ridiculous!

llvm-svn: 104865
2010-05-27 18:42:17 +00:00
Daniel Dunbar 663e8094ae Parse/Sema: Add support for '#pragma options align=native'.
llvm-svn: 104864
2010-05-27 18:42:09 +00:00
Daniel Dunbar 6da1098b4b Sema: Add initial support for '#pragma options align=mac68k'.
- Docs are fairly sketchy, if someone wants to pore through gcc to look for
   holes I'd appreciate any failing test cases!

llvm-svn: 104809
2010-05-27 05:45:51 +00:00
Daniel Dunbar bd60652ace Sema: Reject '#pragma options align=mac68k' everywhere except i386-apple-darwin.
llvm-svn: 104789
2010-05-27 00:35:16 +00:00
Daniel Dunbar 69dac58e7d Sema: Support for #pragma options align={reset,natural}. '#pragma options align'
shares the stack with '#pragma pack', who knew!?

llvm-svn: 104786
2010-05-27 00:04:40 +00:00
Douglas Gregor 9af03022ff Tell the string literal parser when it's not permitted to emit
diagnostics. That would be while we're parsing string literals for the
sole purpose of producing a diagnostic about them. Fixes
<rdar://problem/8026030>.

llvm-svn: 104684
2010-05-26 05:35:51 +00:00
Douglas Gregor 959d5a0cbd Implement support for variable length arrays in C++. VLAs are limited
in several important ways:

  - VLAs of non-POD types are not permitted.
  - VLAs cannot be used in conjunction with C++ templates.

These restrictions are intended to keep VLAs out of the parts of the
C++ type system where they cause the most trouble. Fixes PR5678 and
<rdar://problem/8013618>.

llvm-svn: 104443
2010-05-22 16:17:30 +00:00
John McCall d3dfbd6f4f If a switch condition is constant, don't warn about missing enum cases.
If a switch condition is constant, warn if there's no case for it.

Constant switch conditions do come up in reasonable template code.

llvm-svn: 104010
2010-05-18 03:19:21 +00:00
John McCall ef8b9b3cde Correct spelling of expected error message. Apparently I forgot to re-run
the test suite after modifying this diagnostic.

llvm-svn: 103537
2010-05-12 01:15:36 +00:00
John McCall cf819ab383 When checking scopes for indirect goto, be more permissive (but still safe)
about the permitted scopes.  Specifically:
  1) Permit labels and gotos to appear after a prologue of variable initializations.
  2) Permit indirect gotos to jump out of scopes that don't require cleanup.
  3) Diagnose possible attempts to indirect-jump out of scopes that do require
     cleanup.
This requires a substantial reinvention of the algorithm for checking indirect
goto.  The current algorithm is Omega(M*N), with M = the number of unique
scopes being jumped from and N = the number of unique scopes being jumped to,
with an additional factor that is probably (worst-case) linear in the depth
of scopes.  Thus the entire thing is likely cubic given some truly bizarre
ill-formed code;  on well-formed code the additional factor collapses to
an amortized constant (when amortized over the entire function) and so
the algorithm is quadratic.  Even this requires every label to appear in
its own scope, which would be very unusual for indirect-goto code (and
extremely unlikely for well-formed code);  it is far more likely that
all labels will be in the same scope and so the algorithm becomes linear.
For such a marginal feature, I am fairly happy with this result.

(this is using JumpDiagnostic's definition of scope, where successive
variables in a block appear in their own scope)

llvm-svn: 103536
2010-05-12 00:58:13 +00:00
Douglas Gregor 0bbe94d6df Don't complain about an __builtin_va_arg expression's result being
unused, since the operation has side effects.

llvm-svn: 103360
2010-05-08 22:41:50 +00:00
Rafael Espindola a1f9cc1bec Fix PR4386 by implementing gcc's old behaviour (4.2) when initializing
variables with a comparison of a function pointer with 0.

llvm-svn: 103253
2010-05-07 15:18:43 +00:00
John McCall 7ddbcf4f4b After some discussion, conservatively extend our sentinel check to discard
casts, but still require the (casted) type to be a pointer.  Fixes PR5685.

llvm-svn: 103216
2010-05-06 23:53:00 +00:00
John McCall cc7e5bff5c Rearchitect -Wconversion and -Wsign-compare. Instead of computing them
"bottom-up" when implicit casts and comparisons are inserted, compute them
"top-down" when the full expression is finished.  Makes it easier to
coordinate warnings and thus implement -Wconversion for signedness
conversions without double-warning with -Wsign-compare.  Also makes it possible
to realize that a signedness conversion is okay because the context is
performing the inverse conversion.  Also simplifies some logic that was
trying to calculate the ultimate comparison/result type and getting it wrong.
Also fixes a problem with the C++ explicit casts which are often "implemented"
in the AST with a series of implicit cast expressions.

llvm-svn: 103174
2010-05-06 08:58:33 +00:00
Douglas Gregor c8be95274d When instantiating a function that was declared via a typedef, e.g.,
typedef int functype(int, int);
    functype func;

also instantiate the synthesized function parameters for the resulting
function declaration. 

With this change, Boost.Wave builds and passes all of its regression
tests.

llvm-svn: 103025
2010-05-04 18:18:31 +00:00
Douglas Gregor 0be628ff64 Fix a thinko that caused us not to compute __builtin_offset as a
constant expression in C. 

llvm-svn: 102762
2010-04-30 20:35:01 +00:00
Abramo Bagnara b639ab9ffc Attribute noreturn is now put in declaration attributes. Fixed a double warning generation.
llvm-svn: 102705
2010-04-30 09:13:03 +00:00
Douglas Gregor 10982ea3f9 Diagnose __builtin_offsetof expressions that refer to bit-fields
llvm-svn: 102548
2010-04-28 22:36:06 +00:00
Daniel Dunbar edd5bae86c Revert "Fix for PR6953: per gcc, regparm and noreturn affect the compatibility of", it is breaking the builds of quite a few projects (emacs, dovecot, gnutar, bison).
llvm-svn: 102501
2010-04-28 16:20:58 +00:00
Eli Friedman 7955e52f5c Fix for PR6953: per gcc, regparm and noreturn affect the compatibility of
function types.

This could potentially have unexpected side-effects, so look here if there are
new regressions.

llvm-svn: 102464
2010-04-27 21:07:06 +00:00
Anders Carlsson 58e24a8fd8 Change the 'declared at' diagnostic to say 'declared here'.
llvm-svn: 102163
2010-04-23 02:20:12 +00:00
Daniel Dunbar f812506912 ARM/APCS: Don't respect bit-field types when laying out structures.
- This fixes the last known ABI issues with ARM/APCS.

 - I've run the first 1k ABITests with '--no-unsigned --no-vector --no-complex'
   on {armv6, armv7} x {-mno-thumb, -mthumb}, and the first 10k tests for armv7
   -mthumb, for both function return types and single argument calls. These all
   pass now (they failed horribly before without --no-bitfield).

llvm-svn: 102070
2010-04-22 16:14:54 +00:00
Douglas Gregor 4f4946aaaa Whenever we complain about a failed initialization of a function or
method parameter, provide a note pointing at the parameter itself so
the user does not have to manually look for the function/method being
called and match up parameters to arguments. For example, we now get:

t.c:4:5: warning: incompatible pointer types passing 'long *' to
parameter of
      type 'int *' [-pedantic]
  f(long_ptr);
    ^~~~~~~~
t.c:1:13: note: passing argument to parameter 'x' here
void f(int *x);
            ^

llvm-svn: 102038
2010-04-22 00:20:18 +00:00
John Thompson 359675d036 Altivec vector literal initializer count mismatch error removed.
llvm-svn: 101868
2010-04-20 05:01:46 +00:00
Eric Christopher 5c6525fbee Add a testcase for PR6501 (too many/too few arguments to a function call).
llvm-svn: 101800
2010-04-19 18:39:43 +00:00
Eric Christopher ca6638f950 Temporarily XFAIL this test on windows.
llvm-svn: 101796
2010-04-19 18:26:40 +00:00
Eric Christopher 63448c3de2 Remove the argument number from the constant integer diagnostic.
Update all of the testcases accordingly.

llvm-svn: 101795
2010-04-19 18:23:02 +00:00
Daniel Dunbar 8387488f14 tests: Don't force triple in x86-builtin-palignr test, this test should be
portable.

llvm-svn: 101719
2010-04-18 15:30:18 +00:00
Eric Christopher 0dd32fe068 New test to verify that we see constant integers here.
llvm-svn: 101611
2010-04-17 02:36:08 +00:00
Eric Christopher 8d0c621ca6 Consolidate most of the integer constant expression builtin requirement
checking into a single function and use that throughout. Remove some
now unnecessary diagnostics and update tests with now more accurate
diagnostics.

llvm-svn: 101610
2010-04-17 02:26:23 +00:00
Chris Lattner 4ebae65d6a make our existing "switch on bool" warning work for C. Since
the result of comparisons are 'int' in C, it doesn't work to
test just the result type of the expression.

llvm-svn: 101576
2010-04-16 23:34:13 +00:00
Anders Carlsson 7a4a25de1e Improve the bit-field too wide error message.
llvm-svn: 101384
2010-04-15 18:47:32 +00:00
Douglas Gregor 2bf2d3d016 When diagnosing suspicious precedence or assignments, move the fix-it
that adds parentheses from the main diagnostic down to a new
note. This way, when the fix-it represents a choice between two
options, each of the options is associted with a note. There is no
default option in such cases. For example:

/Users/dgregor/t.c:2:9: warning: & has lower precedence than ==; ==
will be
      evaluated first [-Wparentheses]
  if (x & y == 0) {
        ^~~~~~~~
/Users/dgregor/t.c:2:9: note: place parentheses around the &
expression to
      evaluate it first
  if (x & y == 0) {
        ^
      (    )
/Users/dgregor/t.c:2:9: note: place parentheses around the ==
expression to
      silence this warning
  if (x & y == 0) {
        ^
          (     )

llvm-svn: 101249
2010-04-14 16:09:52 +00:00
Chris Lattner dad4062b4d implement altivec.h and a bunch of support code, patch by Anton Yartsev!
llvm-svn: 101215
2010-04-14 03:54:58 +00:00
Ted Kremenek 800b66be9d Remove fixit for string literal comparison. Telling the user to use 'strcmp' is bad, and
we don't have enough information to tell them how to use 'strncmp'.  Instead, change the
diagnostic to indicate they should use 'strncmp'.

llvm-svn: 100890
2010-04-09 20:26:53 +00:00
Douglas Gregor b10646d4ce Improve diagnostics like "initializing <type> from an expression of
type..." with "initializing <type> with an expression of type...",
which reads better. Thanks to John for the improved wording.

llvm-svn: 100873
2010-04-09 17:53:29 +00:00
Chris Lattner 8a651c7116 Don't warn about unused static functions if they are marked with
attr constructor or destructor.  Patch by Jean-Daniel Dupas!

llvm-svn: 100870
2010-04-09 17:25:05 +00:00
Douglas Gregor c68e140657 Improve diagnostics when we fail to convert from a source type to a
destination type for initialization, assignment, parameter-passing,
etc. The main issue fixed here is that we used rather confusing
wording for diagnostics such as

t.c:2:9: warning: initializing 'char const [2]' discards qualifiers,
      expected 'char *' [-pedantic]
  char *name = __func__;
        ^      ~~~~~~~~

We're not initializing a 'char const [2]', we're initializing a 'char
*' with an expression of type 'char const [2]'. Similar problems
existed for other diagnostics in this area, so I've normalized them all
with more precise descriptive text to say what we're
initializing/converting/assigning/etc. from and to. The warning for
the code above is now:

t.c:2:9: warning: initializing 'char *' from an expression of type
      'char const [2]' discards qualifiers [-pedantic]
  char *name = __func__;
        ^      ~~~~~~~~

Fixes <rdar://problem/7447179>.

llvm-svn: 100832
2010-04-09 00:35:39 +00:00
Ted Kremenek e1a38ab422 Use '%clang_cc1' instead of '%clang' to make the warning output more consistent across
platforms (for this test).

llvm-svn: 100827
2010-04-08 23:17:16 +00:00
Douglas Gregor f19ac0ede9 Downgrade the "declaration does not declare anything" error to a
warning. It's not harmful to have such pointless declarations, and GCC
does not diagnose this issue consistently.

llvm-svn: 100814
2010-04-08 21:33:23 +00:00
Ted Kremenek 5c7f596b4c Match GCC's behavior and do not include '-Wunused-parameter' in '-Wunused'.
llvm-svn: 100810
2010-04-08 21:10:56 +00:00
Ted Kremenek a0859f1e7d Update test case.
llvm-svn: 100801
2010-04-08 18:51:47 +00:00
Ted Kremenek a1de6fc575 Include all warnings under '-Wunused' in '-Wmost' and '-Wall'.
llvm-svn: 100786
2010-04-08 17:54:28 +00:00
Chris Lattner 4b73cfabac rename llvm::llvm_report_error -> llvm::report_fatal_error
llvm-svn: 100708
2010-04-07 22:58:06 +00:00
Ted Kremenek 43a9c9626f Don't emit an 'unused expression' warning for '||' and '&&' expressions that contain assignments
or similar side-effects.

llvm-svn: 100676
2010-04-07 18:49:21 +00:00
John McCall 1bff99322a Teach -Wsign-compare to treat 1 << blah as "idiomatically non-negative".
Fixes a spurious warning in LLVM.

llvm-svn: 100595
2010-04-07 01:14:35 +00:00
John McCall 2351cb9139 Devote a special diagnostic to the typo
(void*) someFunction(5, 10, 15, 20);
where the cast is presumably meant to be to 'void'.

llvm-svn: 100574
2010-04-06 22:24:14 +00:00
John McCall cef1582923 Support __attribute__((unused)) on types. This suddenly started firing
a lot for me on selfhosts, I dunno why.

llvm-svn: 99981
2010-03-31 02:47:45 +00:00
John McCall eae5acbbd0 Fix PR6327: restore invariants when there's a parse error in an initializer.
llvm-svn: 99980
2010-03-31 02:13:20 +00:00
Douglas Gregor c48a10d652 Support __attribute__((packed)) (along with other attributes) at the
end of a struct/class/union in C++, from Justin Bogner!

llvm-svn: 99811
2010-03-29 14:42:08 +00:00
Ted Kremenek 4d745dd5cb Fix two bugs in format-string checking:
(1) Do not assume the data arguments start after the format string
(2) Do not use the fact that a function is variadic to treat it like a va_list printf function

Fixes PR 6697.

llvm-svn: 99480
2010-03-25 03:59:12 +00:00
Douglas Gregor b8ddb138a9 Control warnings about GNU extensions with -Wgnu, which has a subgroup
for GNU designated-initializer syntax (-Wgnu-designator).

llvm-svn: 99421
2010-03-24 20:42:51 +00:00
Duncan Sands de4fe3538a Ignore a more comprehensive set of gcc-special format attributes.
llvm-svn: 99277
2010-03-23 14:44:19 +00:00
Ted Kremenek a3ab0d7666 For forward-declared static inline functions, delay CFG-based warnings until we
encounter a definition.

llvm-svn: 99243
2010-03-23 01:37:12 +00:00
Ted Kremenek 0b40532b5e Only perform CFG-based warnings on 'static inline' functions that
are called (transitively) by regular functions/blocks within a
translation untion.

llvm-svn: 99233
2010-03-23 00:13:23 +00:00
Chris Lattner 12161d3d1a (re)implement PR6542, accepting and discarding the __gcc_tdiag__
format attribute specifier.

llvm-svn: 99213
2010-03-22 21:08:50 +00:00
Chris Lattner cb5a828a45 merge some tests.
llvm-svn: 99212
2010-03-22 21:05:15 +00:00
Chris Lattner 42ed9a6a2b rename test
llvm-svn: 99211
2010-03-22 21:02:58 +00:00
Chris Lattner e783d10bc0 merge two tests.
llvm-svn: 99209
2010-03-22 21:02:14 +00:00
Chris Lattner bbd72654fb rename test.
llvm-svn: 99208
2010-03-22 21:01:10 +00:00
Chris Lattner 05332cad33 move a test to a more appropriate directory
llvm-svn: 99200
2010-03-22 20:31:04 +00:00
John McCall df8b37c3f8 -Wshadow should only warn about parameter declarations when we're
entering a function or block definition, not on every single declaration.
Unfortunately we don't have previous-lookup results around when it's time
to make this decision, so we have to redo the lookup.  The alternative is
to use delayed diagnostics.

llvm-svn: 99172
2010-03-22 09:20:08 +00:00
Rafael Espindola 568586ff22 Fix PR6618.
If a struct has an invalid field, mark it as invalid. Also avoid producing
errors about incomplete types that are invalid.

llvm-svn: 99150
2010-03-21 22:56:43 +00:00
Eric Christopher 595ecbe5c4 Add sse4.2 support to this test.
llvm-svn: 99052
2010-03-20 07:48:45 +00:00
John McCall 2d8c760df7 Implement -Wshadow for parameter declarations as well.
llvm-svn: 99037
2010-03-20 04:12:52 +00:00
Eric Christopher 576a9f2508 Add include for smmintrin.h to this test.
llvm-svn: 99019
2010-03-20 01:06:48 +00:00
John McCall ef01f71a5a Pretty-print anonymous types using their kind and presumed location.
Fixes PR6643.  Patch by Mike M!

llvm-svn: 98946
2010-03-19 07:56:44 +00:00
Douglas Gregor 319aa6c4b5 Remove warning about shadowing a built-in; built-ins aren't actually
considered to be a part of the translation unit unless they're named
in a way that brings them into existence.

llvm-svn: 98729
2010-03-17 16:03:44 +00:00
Fariborz Jahanian fa24e1066f Issue error when a byref array is accessed in a block
literal. Fixes radar 7760213.

llvm-svn: 98693
2010-03-16 23:39:51 +00:00
John McCall 9a9ae00442 Forgot the testcases.
llvm-svn: 98685
2010-03-16 21:50:59 +00:00
John McCall c33dec3664 Add support for -Wwrite-strings. Patch by Mike M! Fixes PR 4804.
llvm-svn: 98541
2010-03-15 10:54:44 +00:00
John McCall 44c064be73 Check compatibility of vector types using their canonicalizations.
Fixes an assertion arising C overload analysis, but really I can't imagine
that this wouldn't cause a thousand other uncaught failures.

Fixes PR6600.

llvm-svn: 98400
2010-03-12 23:14:13 +00:00
John McCall c493a73240 Improve the unused-value check to look into comma expressions and filter out
voids in sub-expressions.  Patch by Mike M!

Fixes PR4806.

llvm-svn: 98335
2010-03-12 07:11:26 +00:00
John McCall 71d8d9b468 Warn about comparing an unsigned expression with 0 in tautological ways.
Patch by mikem!

llvm-svn: 98279
2010-03-11 19:43:18 +00:00
John McCall 6b0dcd9dd1 Remember the PR number.
llvm-svn: 98276
2010-03-11 19:33:57 +00:00
John McCall e40b58ec2f Implement -Wmissing-field-initializers. Patch by mikem!
llvm-svn: 98275
2010-03-11 19:32:38 +00:00
Tanya Lattner 5029d56cc1 Implement missing-braces warning and add a test case.
llvm-svn: 97893
2010-03-07 04:17:15 +00:00
Fariborz Jahanian af9553a23a Allow use of byref (__block attributed) arrays inside
the block. Fixes radar 7671883.

llvm-svn: 97863
2010-03-06 01:58:53 +00:00
Chris Lattner b2bc4b9880 Emit warning on indirect goto that potentially violates
scope instead of error, PR6517

llvm-svn: 97826
2010-03-05 20:38:02 +00:00
Chris Lattner 2df50e6573 address PR6502 by downgrading the scope checker's address
of label error to a warning controllable with a -W flag.

llvm-svn: 97815
2010-03-05 19:26:49 +00:00
Douglas Gregor 9a28e84b32 Keep an explicit stack of function and block scopes, each element of
which has the label map, switch statement stack, etc. Previously, we
had a single set of maps in Sema (for the function) along with a stack
of block scopes. However, this lead to funky behavior with nested
functions, e.g., in the member functions of local classes.

The explicit-stack approach is far cleaner, and we retain a 1-element
cache so that we're not malloc/free'ing every time we enter a
function. Fixes PR6382.

Also, tweaked the unused-variable warning suppression logic to look at
errors within a given Scope rather than within a given function. The
prior code wasn't looking at the right number-of-errors count when
dealing with blocks, since the block's count would be deallocated
before we got to ActOnPopScope. This approach works with nested
blocks/functions, and gives tighter error recovery.

llvm-svn: 97518
2010-03-01 23:15:13 +00:00
Chris Lattner efc83e60d3 fix PR5933: don't warn about unused variables if a function has other errors in it.
llvm-svn: 97498
2010-03-01 21:06:03 +00:00
Ted Kremenek 80263e5905 Allow a '0' precision in format strings (as the man page says it is okay).
Fixes <rdar://problem/7700339>.

llvm-svn: 97482
2010-03-01 19:22:33 +00:00
Douglas Gregor a070ffa7b8 Don't warn about case-value conversions from a negative value to a
larger unsigned value, since this is implementation-defined
behavior. (We previously suppressed this warning when converting from
a signed value to an unsigned value of the same size).

llvm-svn: 97430
2010-03-01 01:04:55 +00:00
Chris Lattner fd48afe412 Implement PR6423 by using one token of lookahead to disambiguate
an *almost* always incorrect case.  This only does the lookahead
in the insanely unlikely case, so it shouldn't impact performance.

On this testcase:

struct foo {
}
typedef int x;

Before:

t.c:3:9: error: cannot combine with previous 'struct' declaration specifier
typedef int x;
        ^

After:

t.c:2:2: error: expected ';' after struct
}
 ^
 ;

llvm-svn: 97403
2010-02-28 18:18:36 +00:00
Ted Kremenek 09597b461d Fix crasher caused by setting a bit in a possibly empty bitvector while
doing printf format string checking.  This is a recent regression.

llvm-svn: 97318
2010-02-27 08:34:51 +00:00
Ted Kremenek d166819c26 For printf format string checking, add support for positional format strings.
Along the way, coelesce some of the diagnostics.

llvm-svn: 97297
2010-02-27 01:41:03 +00:00
Ted Kremenek 4a49d9818b For printf format string checking, move the tracking of the data argument index out of
Sema and into analyze_printf::ParseFormatString().  Also use a bitvector to determine
what arguments have been covered (instead of just checking to see if the last argument consumed is the max argument).  This is prep. for support positional arguments (an IEEE extension).

llvm-svn: 97248
2010-02-26 19:18:41 +00:00
Chandler Carruth 8fa1e7eec4 Add a new conversion rank to classify conversions between complex and scalar
types. Rank these conversions below other conversions. This allows overload
resolution when the only distinction is between a complex and scalar type. It
also brings the complex overload resolutin in line with GCC's.

llvm-svn: 97128
2010-02-25 07:20:54 +00:00
Ted Kremenek 4e5f30cae5 Disable one test case because of the inconsistent results it is giving on
Windows and Mac OS X.  Will investigate later.

llvm-svn: 97016
2010-02-24 02:28:29 +00:00
Charles Davis 2996796972 When we encounter a function-specific attribute in a declaration specifier,
apply it only to the function itself, and never to the return type. Fixes part
of PR6408.

llvm-svn: 97015
2010-02-24 02:27:18 +00:00
Zhongxing Xu a396e617b5 Always add CallExpr as block-level expression. Inline-based interprocedural
analysis needs this.

llvm-svn: 97014
2010-02-24 02:19:28 +00:00
Ted Kremenek 74a4ce7f1e Add support for '%C' and '%S' printf conversion specifiers.
llvm-svn: 97005
2010-02-24 00:05:54 +00:00
John McCall ff96ccd337 Don't assert on compound assignment operators that operate in FP types when
the result is integral.  Fixes <rdar://problem/7676608>.

llvm-svn: 96970
2010-02-23 19:22:29 +00:00
Charles Davis 8e495e78a5 When comparing two calling conventions after redeclaring a function, compare
the canonical calling conventions instead of comparing the raw calling
conventions directly. Fixes PR6361.

llvm-svn: 96895
2010-02-23 06:13:55 +00:00
Charles Davis 3fc5107cd9 When a reference to a field of a struct/union/class is passed to the
__alignof__ operator, make sure to take into account the packed alignment
of the struct/union/class itself. Matches GCC's behavior and fixes PR6362.

llvm-svn: 96884
2010-02-23 04:52:00 +00:00
Chris Lattner dd1cb5b2ec Add 'previous declaration is here' note for param redefinition
errors, e.g.:

t.c:1:21: error: redefinition of parameter 'x'
int test(int x, int x);
                    ^
t.c:1:14: note: previous declaration is here
int test(int x, int x);
             ^

llvm-svn: 96769
2010-02-22 00:40:25 +00:00
Charles Davis 9fcead75ee Also don't warn about force_align_arg_pointer on function typedefs. (This will
break if you declare an actual function using that typedef. Come to think of it,
maybe I should make this part of the type.)

llvm-svn: 96570
2010-02-18 04:56:59 +00:00
Charles Davis cb9572e7b3 Two fixes related to force_align_arg_pointer:
- Also recognize __force_align_arg_pointer__.
- Don't warn if it's used on a function pointer typedef.

llvm-svn: 96568
2010-02-18 04:39:19 +00:00
Charles Davis fea4845609 Allow redefinitions of extern inline functions in GNU89 mode, just as GCC
does. Fixes PR5253.

llvm-svn: 96553
2010-02-18 02:00:42 +00:00
Douglas Gregor e5ad57a3ed Don't diagnose overflow in case statements when the conversion is a
signed<->unsigned conversion with the same bit width. Fixes
<rdar://problem/7658121>.

llvm-svn: 96545
2010-02-18 00:56:01 +00:00
Douglas Gregor 12ea0f4ef9 For -Wswitch-enum warnings, be sure to look through typedefs of enum
types. Fixes <rdar://problem/7643909>.

llvm-svn: 96531
2010-02-17 23:29:11 +00:00
Douglas Gregor c0b8c81a07 When diagnosing enumerator values outside of the range of 'int', be
sure that we get the "too large" vs. "too small" part of the
diagnostic correct.

llvm-svn: 96524
2010-02-17 22:40:11 +00:00
Daniel Dunbar d95638df44 Fix test to not force triple, and also to not need stdint.h.
llvm-svn: 96499
2010-02-17 19:26:59 +00:00
Tanya Lattner 339c89bce2 Do not add functions marked with the unused attribute to the list of unused functions to warn about. Update test case.
llvm-svn: 96452
2010-02-17 04:48:01 +00:00
Tanya Lattner 8aefcbed49 Fix unused function warning to handle used attributes and redeclarations. Update test case.
llvm-svn: 96444
2010-02-17 02:17:21 +00:00
Charles Davis 61170a19e3 Revert r95939, as suggested by Alexandre Julliard from the Wine project (and
our own Chris Lattner).

llvm-svn: 96431
2010-02-17 00:44:47 +00:00
Daniel Dunbar 29a32dab4a Disable warn_unused_function for now, its breaking various project builds due to
false positives.

llvm-svn: 96375
2010-02-16 19:44:56 +00:00
Charles Davis 163855f46d dllimport and dllexport are declspec attributes, too. They're also
Win32-specific.

Also, fix a test to use FileCheck instead of grepping LLVM IR.

llvm-svn: 96364
2010-02-16 18:27:26 +00:00
Ted Kremenek 588fc83c74 Add test case to show that Clang now checks the format string
arguments of asprintf (<rdar://problem/6657191>).

llvm-svn: 96319
2010-02-16 02:14:24 +00:00
Ted Kremenek ccf701d375 Fix test case.
llvm-svn: 96311
2010-02-16 01:47:05 +00:00
Ted Kremenek c8b188d541 Refactor the logic for printf argument type-checking into analyze_printf::ArgTypeResult.
Implement printf argument type checking for '%s'.

Fixes <rdar://problem/3065808>.

llvm-svn: 96310
2010-02-16 01:46:59 +00:00
Benjamin Kramer 634fc10fe1 Add Sema support for __builtin_fpclassify by extending the existing check for __builtin_isinf and friends. Part of PR6083.
llvm-svn: 96291
2010-02-15 22:42:31 +00:00
Eli Friedman d5c9399696 Fix for PR6274: teach constant folding to evaluate __builtin_expect.
llvm-svn: 96054
2010-02-13 00:10:10 +00:00
Fariborz Jahanian 5ec502e35b Complain if block-literal expression's parameter name is
missing (in c/objc mode). Fixes radar 7528255.

llvm-svn: 96017
2010-02-12 21:53:14 +00:00
Tanya Lattner 90073804fb Implementing unused function warning.
llvm-svn: 95940
2010-02-12 00:07:30 +00:00
Charles Davis a90f7ca591 Warn about using the new force_align_arg_pointer attribute on a function
pointer. If you don't like the new warning, you can turn it off with
-Wno-force-align-arg-pointer.

llvm-svn: 95939
2010-02-11 23:57:08 +00:00
John McCall 81472e34b2 Make this test not rely on the system <limits.h>. Hopefully fixes the
MSVC build.

llvm-svn: 95932
2010-02-11 22:45:16 +00:00
John McCall 739908faf6 Test case for warnings with carets inside macro instantiations.
llvm-svn: 95893
2010-02-11 18:52:49 +00:00
Ted Kremenek d31b2637ab Patch by Cristian Draghici:
Enhance the printf format string checking when using the format
specifier flags ' ', '0', '+' with the 'p' or 's' conversions (since
they are nonsensical and undefined).  This is similar to GCC's
checking.

Also warning when a precision is used with the 'p' conversin
specifier, since it has no meaning.

llvm-svn: 95869
2010-02-11 09:27:41 +00:00
Charles Davis bbc0aa5166 Add support for the force_align_arg_pointer attribute. This is an x86-specific
attribute, so it uses Anton's new target-specific attribute support. It's
supposed to ensure that the stack is 16-byte aligned, but since necessary
support is lacking from LLVM, this is a no-op for now.

llvm-svn: 95820
2010-02-10 23:06:52 +00:00
Douglas Gregor e6565625f4 Migrate the mish-mash of declaration checks in
Sema::ActOnUninitializedDecl over to InitializationSequence (with
default initialization), eliminating redundancy. More importantly, we
now check that a const definition in C++ has an initilizer, which was
an #if 0'd code for many, many months. A few other tweaks were needed
to get everything working again:

  - Fix all of the places in the testsuite where we defined const
    objects without initializers (now that we diagnose this issue)
  - Teach instantiation of static data members to find the previous
    declaration, so that we build proper redeclaration
    chains. Previously, we had the redeclaration chain but built it
    too late to be useful, because...
  - Teach instantiation of static data member definitions not to try
    to check an initializer if a previous declaration already had an
    initializer. This makes sure that we don't complain about static
    const data members with in-class initializers and out-of-line
    definitions.
  - Move all of the incomplete-type checking logic out of
    Sema::FinalizeDeclaratorGroup; it makes more sense in
    ActOnUnitializedDecl.

There may still be a few places where we can improve these
diagnostics. I'll address that as a separate commit.

llvm-svn: 95657
2010-02-09 07:26:29 +00:00
Douglas Gregor bd683973c1 Warn when cases are missing from a switch on a value of enumeration
type (-Wswitch), from Michal! 

llvm-svn: 95592
2010-02-08 22:24:16 +00:00
John McCall ab26cfa58d Standardize the parsing of function type attributes in a way that
follows (as conservatively as possible) gcc's current behavior:  attributes
written on return types that don't apply there are applied to the function
instead, etc.  Only parse CC attributes as type attributes, not as decl attributes;
don't accepet noreturn as a decl attribute on ValueDecls, either (it still
needs to apply to other decls, like blocks).  Consistently consume CC/noreturn
information throughout codegen;  enforce this by removing their default values
in CodeGenTypes::getFunctionInfo().

llvm-svn: 95436
2010-02-05 21:31:56 +00:00
John McCall cddbad000d Allow calling convention attributes to apply to types. Patch by Chip Davis!
llvm-svn: 95291
2010-02-04 05:44:44 +00:00
Douglas Gregor 2973d406ba When determining whether a function without a prototype is compatible
with a function with a prototype, treat parameters of enumeration type
based on the enumeration type's promotion type.

llvm-svn: 95238
2010-02-03 19:27:29 +00:00
Douglas Gregor b92a1565c3 Implement the lvalue-to-rvalue conversion where needed. The
lvalue-to-rvalue conversion adjusts lvalues of qualified, non-class
type to rvalue expressions of the unqualified variant of that
type. For example, given:

  const int i;
  (void)(i + 17);

the lvalue-to-rvalue conversion for the subexpression "i" will turn it
from an lvalue expression (a DeclRefExpr) with type 'const int' into
an rvalue expression with type 'int'. Both C and C++ mandate this
conversion, and somehow we've slid through without implementing it. 

We now have both DefaultFunctionArrayConversion and
DefaultFunctionArrayLvalueConversion, and which gets used depends on
whether we do the lvalue-to-rvalue conversion or not. Generally, we do
the lvalue-to-rvalue conversion, but there are a few notable
exceptions:
  - the left-hand side of a '.' operator
  - the left-hand side of an assignment
  - a C++ throw expression
  - a subscript expression that's subscripting a vector

Making this change exposed two issues with blocks:
  - we were deducing const-qualified return types of non-class type
  from a block return, which doesn't fit well
  - we weren't always setting the known return type of a block when it
  was provided with the ^return-type syntax

Fixes the current Clang-on-Clang compile failure and PR6076.

llvm-svn: 95167
2010-02-03 00:27:59 +00:00
Douglas Gregor a71cc15361 Implement promotion for enumeration types.
WHAT!?!

It turns out that Type::isPromotableIntegerType() was not considering
enumeration types to be promotable, so we would never do the
promotion despite having properly computed the promotion type when the
enum was defined. Various operations on values of enum type just
"worked" because we could still compute the integer rank of an enum
type; the oddity, however, is that operations such as "add an enum and
an unsigned" would often have an enum result type (!). The bug
actually showed up as a spurious -Wformat diagnostic
(<rdar://problem/7595366>), but in theory it could cause miscompiles.

In this commit:
  - Enum types with a promotion type of "int" or "unsigned int" are
  promotable.
  - Tweaked the computation of promotable types for enums
  - For all of the ABIs, treat enum types the same way as their
  underlying types (*not* their promotion types) for argument passing
  and return values
  - Extend the ABI tester with support for enumeration types

llvm-svn: 95117
2010-02-02 20:10:50 +00:00
Chris Lattner afe6a840d4 the declspec of a declaration can have storage-class specifiers,
type qualifiers and type specifiers in any order.   For example,
this is valid: struct x {...} typedef y;

This fixes PR6208.

llvm-svn: 95094
2010-02-02 17:32:27 +00:00
Chris Lattner cf25141d14 Implement PR6180, substantially improving the diagnostics we get from
forgetting a ';' at the end of a struct.  For something like:

class c {
}
void foo() {}

we now produce:

t.cc:3:2: error: expected ';' after class
}
 ^
 ;

instead of:

t.cc:4:1: error: cannot combine with previous 'class' declaration specifier
void foo() {}
^
t.cc:2:7: error: 'class c' can not be defined in the result type of a function
class c {
      ^

GCC produces:

t.cc:4: error: new types may not be defined in a return type
t.cc:4: note: (perhaps a semicolon is missing after the definition of ‘c’)
t.cc:4: error: two or more data types in declaration of ‘foo’

I *think* I got the follow set right, but if I forgot anything, we'll start 
getting spurious "expected ';' after class" errors, let me know if you see
any.

llvm-svn: 95042
2010-02-02 01:23:29 +00:00
Douglas Gregor 6791a0d43b Improve handling of enumerator values for C and C++, including:
- In C++, prior to the closing '}', set the type of enumerators
    based on the type of their initializer. Don't perform unary
    conversions on the enumerator values.
  - In C++, handle overflow when an enumerator has no initializer and
    its value cannot be represented in the type of the previous
    enumerator.
  - In C, handle overflow more gracefully, by complaining and then
    falling back to the C++ rules.
  - In C, if the enumerator value is representable in an int, convert the
    expression to the type 'int'.

Fixes PR5854 and PR4515.

llvm-svn: 95031
2010-02-01 23:36:03 +00:00
Ted Kremenek 016b605266 Add format string type checking support for 'long double'.
llvm-svn: 95026
2010-02-01 23:23:50 +00:00
Ted Kremenek cd83106151 Format string checking: selectively ignore implicit casts to 'int'
when checking if the format specifier matches the type of the data
argument and the length modifier indicates the data type is 'char' or
'short'.

llvm-svn: 94992
2010-02-01 19:28:15 +00:00
Sam Weinig deb55d5123 Fix for PR5185. C99 [*] VLA notation should be disallowed in function definitions.
llvm-svn: 94972
2010-02-01 05:02:49 +00:00
Chandler Carruth 00216980fb Really trivial patch to accept pointer to const void in indirect goto. Despite
the lack of documentation, this matches the behavior of GCC.

llvm-svn: 94954
2010-01-31 10:26:25 +00:00
Daniel Dunbar 19b70bd46c Recognize 'q' as a format length modifier (from BSD).
llvm-svn: 94894
2010-01-30 15:49:20 +00:00
Ted Kremenek 9ff02052dd Add format string checking of 'double' arguments. Fixes <rdar://problem/6931734>.
llvm-svn: 94867
2010-01-30 01:02:18 +00:00
Ted Kremenek c3bdff7c8c Add basic type checking of format string conversion specifiers and their arguments. Thanks to Cristian Draghici for his help with this patch!
llvm-svn: 94864
2010-01-30 00:49:51 +00:00
Ted Kremenek 605b0113f3 Be a little more permissive than C99: allow 'unsigned' to be used for
the field width and precision of a format specifier instead of just
'int'.  This matches GCC, and fixes <rdar://problem/6079850>.

llvm-svn: 94856
2010-01-29 23:32:22 +00:00