Commit Graph

1709 Commits

Author SHA1 Message Date
Chandler Carruth c933221826 Factor out (some of) the checking for invalid forms of pointer
arithmetic into a couple of common routines. Use these to make the
messages more consistent in the various contexts, especially in terms of
consistently diagnosing binary operators with invalid types on both the
left- and right-hand side. Also, improve the grammar and wording of the
messages some, handling both two pointers and two (different) types.

The wording of function pointer arithmetic diagnostics still strikes me
as poorly phrased, and I worry this makes them slightly more awkward if
more consistent. I'm hoping to fix that with a follow-on patch and test
case that will also make them more helpful when a typedef or template
type parameter makes the type completely opaque.

Suggestions on better wording are very welcome, thanks to Richard Smith
for some initial help on that front.

llvm-svn: 133906
2011-06-27 08:02:19 +00:00
John McCall 8766a83a2f Two more test cases which have been long uncommitted.
llvm-svn: 133842
2011-06-24 23:30:52 +00:00
Eli Friedman 1408bc9a55 Fix Sema::CheckVectorOperands so that it doesn't try to insert a cast expression into the LHS of a compound assignment. Fixes compound assignment of various "compatible" vector types, including NEON-vector and gcc-vector types.
<rdar://problem/9640356>

llvm-svn: 133737
2011-06-23 18:10:35 +00:00
Fariborz Jahanian 33e022650a Issue warning if weak_import attribute is added to an already
declared variable and ignore it. // rdar://9538608

llvm-svn: 133654
2011-06-22 22:08:50 +00:00
Manuel Klimek f2b4b69346 Changes ParenListExpr to always require a type.
Removes dead code found in the process.
Adds a test to verify that ParenListExprs do not have NULL types.

llvm-svn: 133637
2011-06-22 20:02:16 +00:00
Chandler Carruth 4352b0b876 Fix a crash when a pointer-to-member function is called in the condition
expression of '?:'. Add a test case for this pattern, and also test the
code that led to the crash in a "working" case as well.

llvm-svn: 133523
2011-06-21 17:22:09 +00:00
Argyrios Kyrtzidis 01bf777597 Warn for un-parenthesized '&' inside '|' (a & b | c), rdar://9553326.
Patch by Henry Mason with tweaks by me.

llvm-svn: 133453
2011-06-20 18:41:26 +00:00
Chandler Carruth 5f380da06f Fix a problem with the diagnostics of invalid arithmetic with function
pointers I found while working on the NULL arithmetic warning. We here
always assuming the LHS was the pointer, instead of using the selected
pointer expression.

llvm-svn: 133428
2011-06-20 07:52:11 +00:00
Argyrios Kyrtzidis c30661f3a8 Don't emit 'unavailable' errors inside an unavailable function. rdar://9623855.
llvm-svn: 133264
2011-06-17 17:28:30 +00:00
Chandler Carruth f8e06c96ca Make the presentation of the warnings on 'x + y ? 1 : 0' a bit more
pretty. In particular this makes it much easier for me to read messages
such as:

  x.cc:42: ?: has lower ...

Where I'm inclined to associate the third ':' with a missing column
number, but in fact column numbers have been turned off. Similar
punctuation collisions happened elsewhere as well.

llvm-svn: 133121
2011-06-16 01:05:12 +00:00
Douglas Gregor 88336839b9 Don't add redundant FormatAttr, ConstAttr, or NoThrowAttr attributes,
either imlicitly (for builtins) or explicitly (due to multiple
specification of the same attributes). Fixes <rdar://problem/9612060>.

llvm-svn: 133045
2011-06-15 05:45:11 +00:00
Nico Weber 0870debb8b Warn on "void f(int a[10]) { sizeof(a); }"
llvm-svn: 133036
2011-06-15 02:47:03 +00:00
Ted Kremenek 70f05fdfee Sema: show shift result in hexadecimal
Change the output for -Wshift-overflow and
-Wshift-sign-overflow to an unsigned hexadecimal. It makes
more sense for looking at bits than a signed decimal does.
Also, change the diagnostic's wording from "overrides"
to "sets".

This uses a new optional argument in APInt::toString()
that adds the '0x' prefix to hexademical numbers.

This fixes PR 9651.

Patch by nobled@dreamwidth.org!

llvm-svn: 133033
2011-06-15 00:54:52 +00:00
Fariborz Jahanian d53eca68f0 Bad table discription of fromat-y2k causes
no-format-y2k turn off -Wformat altogether. 
// rdar://9504680

llvm-svn: 133015
2011-06-14 21:54:00 +00:00
Chris Lattner f35de48c90 when compiling in a GNU mode (e.g. gnu99) treat VLAs with a size that can be folded to a constant
as constant size arrays.  This has slightly different semantics in some insane cases, but allows
us to accept some constructs that GCC does.  Continue to be pedantic in -std=c99 and other
modes.  This addressed rdar://8733881 - error "variable-sized object may not be initialized"; g++ accepts same code

llvm-svn: 132983
2011-06-14 06:38:10 +00:00
David Majnemer c75d1a1098 Properly diagnose using abstract and incomplete types in va_arg
- Move a test from test/SemaTemplate/instantiate-expr-3.cpp, it did not belong there
- Incomplete and abstract types are considered hard errors

llvm-svn: 132979
2011-06-14 05:17:32 +00:00
Chris Lattner ee7286f02d fix rdar://9546171 - -Wshorten-64-to-32 shouldn't warn on vector bitcasts.
llvm-svn: 132975
2011-06-14 04:51:15 +00:00
Eli Friedman 51dd0185d6 Make __gnu_inline__ functions in gnu99 mode work the same way as inline functions in gnu89 mode in terms of redefinitions.
rdar://9559708 .

llvm-svn: 132953
2011-06-13 23:56:42 +00:00
Hans Wennborg de2e67e546 Handle overloaded operators in ?: precedence warning
This is a follow-up to r132565, and should address the rest of PR9969:

Warn about cases such as

int foo(A a, bool b) {
 return a + b ? 1 : 2; // user probably meant a + (b ? 1 : 2);
}

also when + is an overloaded operator call.

llvm-svn: 132784
2011-06-09 17:06:51 +00:00
Bob Wilson 8b51f19ec1 Add isVCVT_N flag to identify Neon VCVT_N intrinsics, which require special
range checking for immediate operands.  Radar 9558930.

llvm-svn: 132783
2011-06-09 17:03:27 +00:00
Eli Friedman 6b3411b2fd Second try at fixing this test, this time without breaking 32-bit Darwin builders.
llvm-svn: 132694
2011-06-06 22:25:48 +00:00
Eli Friedman 9ed3cde1fa Start fixing up clang tests to work on the clang-native-arm-cortex-a9 builder.
llvm-svn: 132691
2011-06-06 21:23:05 +00:00
Hans Wennborg cf9bac4bc9 Warn about missing parentheses for conditional operator.
Warn in cases such as "x + someCondition ? 42 : 0;",
where the condition expression looks arithmetic, and has
a right-hand side that looks boolean.

This (partly) addresses http://llvm.org/bugs/show_bug.cgi?id=9969

llvm-svn: 132565
2011-06-03 18:00:36 +00:00
Ted Kremenek fb43639926 Rename -Wunknown-attributes to -Wattributes to match GCC.
llvm-svn: 132422
2011-06-01 20:09:40 +00:00
Chandler Carruth e54ff6cc3e Expand the coverage of the warning for constants on the RHS of logical operands:
return f() || -1;

where the user meant to write '|'.

This bootstraps without any additional warnings.

Patch by Richard Trieu.

llvm-svn: 132327
2011-05-31 05:41:42 +00:00
Francois Pichet 6f7289d9c5 Add a Microsoft C test following r131201.
llvm-svn: 131202
2011-05-11 22:28:19 +00:00
John McCall dfbf9341ad Use a heralded conversion to bool in inline-asm constraints.
llvm-svn: 131170
2011-05-10 23:39:47 +00:00
Ted Kremenek efdb7fe53b Fix crash in -Wuninitialized when using switch statments whose condition is a logical operation.
llvm-svn: 131158
2011-05-10 22:10:35 +00:00
John McCall e155a3d8aa __builtin_va_list is void* on ARM, not char*.
rdar://problem/9391966

llvm-svn: 131080
2011-05-09 02:19:37 +00:00
Chad Rosier f897d3b88b Fixed test case asserts due to checkin of r130710.
llvm-svn: 130720
2011-05-02 20:39:21 +00:00
Ted Kremenek b5fabb2f9f Convert assertion in memset checking to a runtime check (because real code may provide a deviant definition of memset).
llvm-svn: 130368
2011-04-28 01:38:02 +00:00
John Wiegley 1c0675e155 Parsing/AST support for Structured Exception Handling
Patch authored by Sohail Somani.

Provide parsing and AST support for Windows structured exception handling.

llvm-svn: 130366
2011-04-28 01:08:34 +00:00
Argyrios Kyrtzidis ae40e4e10e Gcc pads the size of an array using the alignment of its elements.
The size of the array may not be aligned according to alignment of its elements if an alignment attribute is
specified in a typedef. Fixes rdar://8665729 & http://llvm.org/PR5637.

llvm-svn: 130242
2011-04-26 21:05:39 +00:00
Fariborz Jahanian 6b4e26bee2 Add ms_struct attribute on record typee
(and ignore it for now) - wip.

llvm-svn: 130224
2011-04-26 17:54:40 +00:00
Argyrios Kyrtzidis a9b630e4d7 Emit a -Wnull-dereference warning for "*null" not just "*null = something". Addresses rdar://9269271.
llvm-svn: 130207
2011-04-26 17:41:22 +00:00
Ted Kremenek 8dcc466886 When generating printf fixits, preserve the original formating for unsigned integers (e.g., 'x', 'o').
llvm-svn: 130164
2011-04-25 22:32:59 +00:00
Fariborz Jahanian 743dda49d9 Recognize gcc's ms_struct pragma (and ignore for now).
This is wip.

llvm-svn: 130138
2011-04-25 18:49:15 +00:00
Eli Friedman ea7b85bfe0 PR4304: Add warning for designators in strict c89 mode.
llvm-svn: 130117
2011-04-24 22:14:22 +00:00
Chandler Carruth b009b14971 There were some frustrating problems with the implementation of
-Wwrite-strings. First and foremost, once the positive form of the flag
was passed, it could never be disabled by passing -Wno-write-strings.
Also, the diagnostic engine couldn't in turn use -Wwrite-strings to
control diagnostics (as GCC does) because it was essentially hijacked to
drive the language semantics.

Fix this by giving CC1 a clean '-fconst-strings' flag to enable
const-qualified strings in C and ObjC compilations. Corresponding
'-fno-const-strings' is also added. Then the driver is taught to
introduce '-fconst-strings' in the CC1 command when '-Wwrite-strings'
dominates.

This entire flag is basically GCC-bug-compatibility driven, so we also
match GCC's bug where '-w' doesn't actually disable -Wwrite-strings. I'm
open to changing this though as it seems insane.

llvm-svn: 130051
2011-04-23 06:30:43 +00:00
Argyrios Kyrtzidis ad8b4d402e For -Wlogical-op-parentheses, point at '&&', not '||'. Fixes rdar://9125333.
llvm-svn: 130009
2011-04-22 19:16:27 +00:00
Argyrios Kyrtzidis 1618023018 We regard a function as 'unused' from the codegen perspective, so our warnings diverge from
gcc's unused warnings which don't get emitted if the function is referenced even in an unevaluated context
(e.g. in templates, sizeof, etc.). Also, saying that a function is 'unused' because it won't get codegen'ed
is somewhat misleading.

- Don't emit 'unused' warnings for functions that are referenced in any part of the user's code.
- A warning that an internal function/variable won't get emitted is useful though, so introduce
  -Wunneeded-internal-declaration which will warn if a function/variable with internal linkage is not
  "needed" ('used' from the codegen perspective), e.g:

  static void foo() { }

  template <int>
  void bar() {
    foo();
  }

test.cpp:1:13: warning: function 'foo' is not needed and will not be emitted
static void foo() { }
            ^

Addresses rdar://8733476.

llvm-svn: 129794
2011-04-19 19:51:10 +00:00
Peter Collingbourne 133587f08b Add a new expression classification, CL_AddressableVoid
CL_AddressableVoid is the expression classification used for void
expressions whose address can be taken, i.e. the result of [], *
or void variable references in C, as opposed to things like the
result of a void function call.

llvm-svn: 129783
2011-04-19 18:51:51 +00:00
Matt Beaumont-Gay ceb763e23a Fix line endings
llvm-svn: 129740
2011-04-19 00:23:31 +00:00
Ted Kremenek 1551d55295 Improve diagnostics on GNU attributes by warning about attributes that should have no arguments or parameters. Patch by Michael Han!
llvm-svn: 129560
2011-04-15 05:49:29 +00:00
Peter Collingbourne 3d9cbdc3e6 C1X: implement static asserts
llvm-svn: 129555
2011-04-15 00:35:57 +00:00
Peter Collingbourne 9114759641 C1X: implement generic selections
As an extension, generic selection support has been added for all
supported languages.  The syntax is the same as for C1X.

llvm-svn: 129554
2011-04-15 00:35:48 +00:00
Chandler Carruth 016ef400c4 Enhance the diagnostic for literal float -> int conversions to suggest
rewriting the literal when the value is integral. It is not uncommon to
see code written as:

  const int kBigNumber = 42e5;

Without any real awareness that this is no longer an ICE. The note helps
automate and ease the process of fixing code that violates the warning.

llvm-svn: 129243
2011-04-10 08:36:24 +00:00
Chandler Carruth 42983aef34 Switch 'is possibly uninitialized' to 'may be uninitialized' based on
Chris's feedback.

llvm-svn: 129127
2011-04-08 06:47:15 +00:00
Chandler Carruth 278f89732f Now that the analyzer is distinguishing between uninitialized uses that
definitely have a path leading to them, and possibly have a path leading
to them; reflect that distinction in the warning text emitted.

llvm-svn: 129126
2011-04-08 06:33:38 +00:00
Chandler Carruth 78c7e34485 Commit a bit of a hack to fully handle the situation where variables are
marked explicitly as uninitialized through direct self initialization:

  int x = x;

With r128894 we prevented warnings about this code, and this patch
teaches the analysis engine to continue analyzing subsequent uses of
'x'. This should wrap up PR9624.

There is still an open question of whether we should suppress the
maybe-uninitialized warnings resulting from variables initialized in
this fashion. The definitely-uninitialized uses should always be warned.

llvm-svn: 128932
2011-04-05 21:36:30 +00:00
Chandler Carruth b5d4831f83 Fix PR9624 by explicitly disabling uninitialized warnings for direct self-init:
int x = x;

GCC disables its warnings on this construct as a way of indicating that
the programmer intentionally wants the variable to be uninitialized.
Only the warning on the initializer is turned off in this iteration.

This makes the code a lot more ugly, but starts commenting the
surprising behavior here. This is a WIP, I want to refactor it
substantially for clarity, and to determine whether subsequent warnings
should be suppressed or not.

llvm-svn: 128894
2011-04-05 17:41:31 +00:00
Ted Kremenek 378819342e Fix PR 9626 (duplicated self-init warnings under -Wuninitialized) with numerous CFG and UninitializedValues analysis changes:
1) Change the CFG to include the DeclStmt for conditional variables, instead of using the condition itself as a faux DeclStmt.
2) Update ExprEngine (the static analyzer) to understand (1), so not to regress.
3) Update UninitializedValues.cpp to initialize all tracked variables to Uninitialized at the start of the function/method.
4) Only use the SelfReferenceChecker (SemaDecl.cpp) on global variables, leaving the dataflow analysis to handle other cases.

The combination of (1) and (3) allows the dataflow-based -Wuninitialized to find self-init problems when the initializer
contained control-flow.

llvm-svn: 128858
2011-04-04 23:29:12 +00:00
Ted Kremenek b8d8c4ec56 -Wuninitialized: use "self-init" warning when issue uninitialized values warnings from the dataflow analysis that include within the initializer of a variable.
llvm-svn: 128843
2011-04-04 20:56:00 +00:00
Ted Kremenek 35d800c39f -Wuninitialized: don't issue fixit for initializer if a variable declaration already has an initializer.
llvm-svn: 128838
2011-04-04 19:43:57 +00:00
Ted Kremenek 99a337eed0 When emitting a "too many arguments to function call..." error, also include a note with a location for the function prototype.
llvm-svn: 128833
2011-04-04 17:22:27 +00:00
Ted Kremenek 77361761fb -Wuninitialized should not warn about variables captured by blocks as byref.
Note this can potentially be enhanced to detect if the __block variable
is actually written by the block, or only when the block "escapes" or
is actually used, but that requires more analysis than it is probably worth
for this simple check.

llvm-svn: 128681
2011-03-31 22:32:41 +00:00
Anton Yartsev 530deb9a39 AltiVec vector comparison logic now affect only vectors of fundamental AltiVec vector types. It fixes bug 9347.
llvm-svn: 128381
2011-03-27 15:36:07 +00:00
Anton Yartsev 28ccef788b supported: AltiVec vector initialization with a single literal according to PIM section 2.5.1 - after initialization all elements have the value specified by the literal
llvm-svn: 128375
2011-03-27 09:32:40 +00:00
Douglas Gregor 7735c53664 Test attribute merging for the availability attribute.
llvm-svn: 128334
2011-03-26 10:47:34 +00:00
Douglas Gregor 7ab142b55a Extend the new 'availability' attribute with support for an
'unavailable' argument, which specifies that the declaration to which
the attribute appertains is unavailable on that platform.

llvm-svn: 128329
2011-03-26 03:35:55 +00:00
Ted Kremenek dcc4c38970 Fix CFG-construction bug when run from AnalysisBasedWarnings::IssueWarnings() where block-level expressions that need
to be recorded in the Stmt*->CFGBlock* map were not always done so.  Fixes <rdar://problem/9171946>.

llvm-svn: 128170
2011-03-23 21:33:21 +00:00
Fariborz Jahanian 16f92ce539 Support for Transparent unions used as overloadable
function parameter. // rdar:// 9129552
and PR9406.

llvm-svn: 128159
2011-03-23 19:50:54 +00:00
Douglas Gregor 20b2ebd785 Implement a new 'availability' attribute, that allows one to specify
which versions of an OS provide a certain facility. For example,

  void foo()
  __attribute__((availability(macosx,introduced=10.2,deprecated=10.4,obsoleted=10.6)));

says that the function "foo" was introduced in 10.2, deprecated in
10.4, and completely obsoleted in 10.6. This attribute ties in with
the deployment targets (e.g., -mmacosx-version-min=10.1 specifies that
we want to deploy back to Mac OS X 10.1). There are several concrete
behaviors that this attribute enables, as illustrated with the
function foo() above:

  - If we choose a deployment target >= Mac OS X 10.4, uses of "foo"
    will result in a deprecation warning, as if we had placed
    attribute((deprecated)) on it (but with a better diagnostic)
  - If we choose a deployment target >= Mac OS X 10.6, uses of "foo"
    will result in an "unavailable" warning (in C)/error (in C++), as
    if we had placed attribute((unavailable)) on it
  - If we choose a deployment target prior to 10.2, foo() is
    weak-imported (if it is a kind of entity that can be weak
    imported), as if we had placed the weak_import attribute on it.

Naturally, there can be multiple availability attributes on a
declaration, for different platforms; only the current platform
matters when checking availability attributes.

The only platforms this attribute currently works for are "ios" and
"macosx", since we already have -mxxxx-version-min flags for them and we
have experience there with macro tricks translating down to the
deprecated/unavailable/weak_import attributes. The end goal is to open
this up to other platforms, and even extension to other "platforms"
that are really libraries (say, through a #pragma clang
define_system), but that hasn't yet been designed and we may want to
shake out more issues with this narrower problem first.

Addresses <rdar://problem/6690412>.

As a drive-by bug-fix, if an entity is both deprecated and
unavailable, we only emit the "unavailable" diagnostic.

llvm-svn: 128127
2011-03-23 00:50:03 +00:00
John McCall 92d627e1b0 Fix an error with the declaration of block parameters that depend
on previous block parameters that crept in as part of my captures
work a month or so ago.

llvm-svn: 128121
2011-03-22 23:15:50 +00:00
John McCall aa01737782 Warn about unused declaration-specifiers on tag declarations.
llvm-svn: 128118
2011-03-22 23:00:04 +00:00
Ted Kremenek 97d8d03855 Make test more portable.
llvm-svn: 127799
2011-03-17 04:16:45 +00:00
Ted Kremenek c15a4e4b37 Extend -Wuninitialized to support vector types.
llvm-svn: 127794
2011-03-17 03:06:11 +00:00
Ted Kremenek 61c74a1423 Rename -Wuninitialized-maybe to -Wconditional-uninitialized.
llvm-svn: 127793
2011-03-17 03:06:07 +00:00
Ted Kremenek 6cd0187718 Remove warning for null characters in CFString literals. Clang handles them just fine, and GCC 4.2 doesn't warn here either.
We added this warning back in 2007 when we were comparing against GCC 4.0.

llvm-svn: 127704
2011-03-15 21:18:52 +00:00
Ted Kremenek ea6c20adaf Take 2: merge -Wuninitialized-experimental into -Wuninitialized. Only *must-be-uninitialized* warnings are reported, with *maybe-uninitialized* under a separate flag. I await any fallout/comments/feedback, although hopefully this will produce no noise for users.
llvm-svn: 127670
2011-03-15 05:22:33 +00:00
Ted Kremenek c8c4e5f371 Split warnings from -Wuninitialized-experimental into "must-be-initialized" and "may-be-initialized" warnings, each controlled by different flags.
llvm-svn: 127666
2011-03-15 04:57:38 +00:00
Ted Kremenek 792798549f Remove old UninitializedValues analysis.
llvm-svn: 127656
2011-03-15 03:17:01 +00:00
Douglas Gregor 364f7db063 When we're determining whether to complain about a conversion from one
enumeration type to another in C, classify enumeration constants as if
they had the type of their enclosing enumeration. Fixes
<rdar://problem/9116337>.

llvm-svn: 127514
2011-03-12 00:14:31 +00:00
NAKAMURA Takumi 4e8c365e9a include/clang/Basic/BuiltinsX86.def: __builtin_ia32_crc32**() should be defined to take unsigned args and to return unsigned value.
mingw-w64's intrin.h declares __builtin_ia32_crc32**() as external.

llvm-svn: 127329
2011-03-09 12:00:19 +00:00
Carl Norum 58d489fc6e Fix tests to account for new warning "expected ';' at end of declaration list". Sorry, folks!
llvm-svn: 127188
2011-03-07 22:57:45 +00:00
John McCall 80ee5963fd Pretty up the wrong-number-of-arguments-for-attribute diagnostic by
using a custom plural form.  Split out the range diagnostics as their
own message.

llvm-svn: 126840
2011-03-02 12:15:05 +00:00
Ted Kremenek e96dad9544 Don't warn about unused values in ternary ?: expressions unless both the LHS and RHS are "unused" (side-effect free).
Patch by Justin Bogner!  Fixes PR 8282.

llvm-svn: 126779
2011-03-01 20:34:48 +00:00
Ted Kremenek 26bbc3d494 Don't warning about shifting by too many bits in dead code.
llvm-svn: 126770
2011-03-01 19:13:22 +00:00
Ted Kremenek 63657fe995 Don't wanr about "negative shifts" in code that is unreachable. Fixes PR 5544.
llvm-svn: 126762
2011-03-01 18:09:31 +00:00
John McCall 4b13633082 Don't crash during constant-evaluation of 1/(1/0). PR9262.
llvm-svn: 126541
2011-02-26 08:27:17 +00:00
Peter Collingbourne 54f43b87dc Rename test/Sema/expr-comma-c89.c to expr-comma-c99.c. Spotted by
Anton Lokhmotov.

llvm-svn: 126482
2011-02-25 12:37:11 +00:00
Ted Kremenek b6f9ab6378 Teach TextDiagnosticPrinter to print out '-Werror' in addition to the warning flag for a warning mapped to an error.
For example:

t.c:7:9: error: using the result of an assignment as a condition without parentheses [-Werror,-Wparentheses]

llvm-svn: 126466
2011-02-25 01:28:26 +00:00
Ted Kremenek a8890833f2 Don't warn about using PredefinedExprs as format string literals. These never can be a real security issue.
Fixes PR 9314.

llvm-svn: 126447
2011-02-24 23:03:04 +00:00
Chandler Carruth e721185799 Simplify messages as requested by Chris.
llvm-svn: 126389
2011-02-24 17:13:15 +00:00
Chandler Carruth 4c6fdca035 Implement a warning for known shift overflows on constant shift
expressions. Consider the code:

  int64_t i = 10 << 30;

This compiles fine, but most developers expect it to produce the value
for 10 gigs, not -2 gigs. This is actually undefined behavior because
the LHS is a signed integer type.

The warning is currently gated behind -Wshift-overflow.

There is a special case where only the sign bit is overridden that gets
a custom error message and is by default ignored. This case is much less
likely to cause observed buggy behavior, it's just undefined behavior
according to the spec. This warning can be enabled with
-Wshift-sign-overflow.

Original patch by Oleg Slezberg, with style tweaks and some correctness
fixes by me.

llvm-svn: 126342
2011-02-23 23:34:11 +00:00
Chandler Carruth e71b378dc7 Fix the behavior of -Wignored-qualifiers on return type qualifiers in
several ways. We now warn for more of the return types, and correctly
locate the ignored ones. Also adds fix-it hints to remove the ignored
qualifiers. Fixes much of PR9058, although not all of it.

Patch by Hans Wennborg, a couple of minor style tweaks from me.

llvm-svn: 126321
2011-02-23 18:51:59 +00:00
Ted Kremenek 1a241d1619 Teach CFGBuilder about null pointer constants in conditionals, and how they can be used to prune branches. Fixes false null pointer dereference warning in PR 8183.
llvm-svn: 126305
2011-02-23 05:11:46 +00:00
Ted Kremenek ef59fe7845 Add test case (from PR 8876) for suppressing 'indirection of non-volatile null pointer...' warning due to reachability analysis.
llvm-svn: 126294
2011-02-23 02:15:19 +00:00
Ted Kremenek 3427fac7c8 Enhance Sema::DiagRuntimeBehavior() to delay some diagnostics to see if the related code is reachable. This suppresses some
diagnostics that occur in unreachable code (e.g., -Warray-bound).

We only pay the cost of doing the reachability analysis when we issue one of these diagnostics.

llvm-svn: 126290
2011-02-23 01:52:04 +00:00
Douglas Gregor 996a735b88 We need a longer long when testing this pathe Microsoft fixed-underlying-type extension for enumeration types
llvm-svn: 126250
2011-02-22 21:42:31 +00:00
Douglas Gregor a1aec29a2d Enable enumeration types with a fixed underlying type, e.g.,
enum X : long { Value = 0x100000000 };

when in Microsoft-extension mode (-fms-extensions). This (now C++0x)
feature has been supported since Microsoft Visual Studio .NET 2003.

llvm-svn: 126243
2011-02-22 20:32:04 +00:00
Douglas Gregor e2f943b5cb Implement the GNU C extension which permits the initialization of an
array from a constant array compound literal. Fixes PR9261.

llvm-svn: 126230
2011-02-22 18:29:51 +00:00
Douglas Gregor a78f193e7e Warn about implicit conversions between values of different, named
enumeration types. Fixes <rdar://problem/8559831>.

llvm-svn: 126183
2011-02-22 02:45:07 +00:00
Anders Carlsson 4fc229ef69 Move some Objective-C tests to SemaObjC and CodeGenObjC.
llvm-svn: 126175
2011-02-22 01:23:29 +00:00
Chandler Carruth 468b5cbd40 Allow -Wformat to be enabled without -Wformat-security. GCC gates
-Wformat-security on -Wformat, not vice-versa.

Fixes PR8486. Patch by Oleg Slezberg.

llvm-svn: 126096
2011-02-21 00:07:51 +00:00
Chris Lattner 29eb47bd68 Fix PR9253, allowing attribute(aligned) to reduce the alignment of
a typedef.

llvm-svn: 126059
2011-02-19 22:55:41 +00:00
Chandler Carruth a8bea4b90e Initial steps to improve diagnostics when there is a NULL and
a non-pointer on the two sides of a conditional expression.

Patch by Stephen Hines and Mihai Rusu.

llvm-svn: 125995
2011-02-18 23:54:50 +00:00
Chris Lattner 9ba479bd2c fix rdar://9024687, a crash on invalid that we used to silently ignore.
llvm-svn: 125962
2011-02-18 21:16:39 +00:00
Chris Lattner 0f79084117 break testcase over multiple lines to make it easier to read.
llvm-svn: 125810
2011-02-18 01:25:14 +00:00
Chris Lattner cab02a60d2 Step #2/N of __label__ support: keep pushing LabelDecl forward,
making them be template instantiated in a more normal way and 
make them handle attributes like other decls.

This fixes the used/unused label handling stuff, making it use
the same infrastructure as other decls.

llvm-svn: 125771
2011-02-17 20:34:02 +00:00
Chandler Carruth 22c7a79a1d Implement a sub-group of -Wconversion: -Wliteral-conversion. This
specifically targets literals which are implicitly converted, a those
are more often unintended and trivial to fix. This can be especially
helpful for diagnosing what makes 'const int x = 1e6' not an ICE.

Original patch authored by Jim Meehan with contributions from other
Googlers and a few cleanups from myself.

llvm-svn: 125745
2011-02-17 11:05:49 +00:00
Chris Lattner c8e630e4db Step #1/N of implementing support for __label__: split labels into
LabelDecl and LabelStmt.  There is a 1-1 correspondence between the
two, but this simplifies a bunch of code by itself.  This is because
labels are the only place where we previously had references to random
other statements, causing grief for AST serialization and other stuff.

This does cause one regression (attr(unused) doesn't silence unused
label warnings) which I'll address next.

This does fix some minor bugs:
1. "The only valid attribute " diagnostic was capitalized.
2. Various diagnostics printed as ''labelname'' instead of 'labelname'
3. This reduces duplication of label checking between functions and blocks.

Review appreciated, particularly for the cindex and template bits.

llvm-svn: 125733
2011-02-17 07:39:24 +00:00
Ted Kremenek 197fcd4418 Fix assertion failure in -Warray-bounds on template parameters used as arrays.
llvm-svn: 125693
2011-02-16 23:39:09 +00:00
Ted Kremenek 3a854f8ad2 Placate Doug and change capitalization of diagnostic note.
llvm-svn: 125688
2011-02-16 22:08:28 +00:00
Ted Kremenek 108b2d56bf Tweak -Warray-bounds diagnostics based on feedback from Chandler.
llvm-svn: 125649
2011-02-16 04:01:44 +00:00
Ted Kremenek 64699befcd Add trivial buffer overflow checking in Sema.
llvm-svn: 125640
2011-02-16 01:57:07 +00:00
Peter Collingbourne e91b2dbdf1 OpenCL: standardise naming of test cases
llvm-svn: 125590
2011-02-15 19:46:41 +00:00
Fariborz Jahanian 178259710a Fix a block sema bug where result type of initializer
is unqualified but its initialized is qualified.
This is for c only and fixes the imm. problem.
c++ is more involved and is wip.
// rdar://8979379

llvm-svn: 125386
2011-02-11 18:46:17 +00:00
John McCall 7a198cef04 When checking the 'weak' and 'weakref' attributes, look for non-external
linkage rather than the presence of the 'static' storage class specifier.
Fixes rdar://problem/8814626.

llvm-svn: 125126
2011-02-08 22:35:49 +00:00
John McCall 653dac4b0a dgregor accidentally killed this assert, but on investigation, it can fire
on invalid code and we don't really care, so kill it harder.

llvm-svn: 125068
2011-02-08 01:59:10 +00:00
Ted Kremenek e6a12a97d4 Move uninitialized variable checking back under -Wuninitialized-experimental. It is clear from user feedback that this warning is not quite ready.
llvm-svn: 125007
2011-02-07 17:38:38 +00:00
Ted Kremenek 436cc8ffe7 Reenable -Wuninitialized warning for captured block variables.
llvm-svn: 124782
2011-02-03 06:51:50 +00:00
Ted Kremenek b3dbe28e31 Based on user feedback, swap -Wuninitialized diagnostics to have the warning refer to the bad use, and the note to the variable declaration.
llvm-svn: 124758
2011-02-02 23:35:53 +00:00
John McCall 71de91cc09 When diagnosing address-space changes, apply array-to-pointer decay first.
llvm-svn: 124702
2011-02-01 23:28:01 +00:00
Ted Kremenek ba357296e7 Enhance -Wuninitialized to better reason about || and &&, tracking dual dataflow facts and properly merging them.
Fixes PR 9076.

llvm-svn: 124666
2011-02-01 17:43:18 +00:00
John McCall 4fff8f6cff Perform the bad-address-space conversions check as part of
CheckPointerTypesForAssignment.

llvm-svn: 124632
2011-02-01 00:10:29 +00:00
Argyrios Kyrtzidis 857dd06605 Fix the diagnostic when we are shadowing an external variable and there exists a locally scoped extern with the same name.
llvm-svn: 124580
2011-01-31 07:04:50 +00:00
Argyrios Kyrtzidis 819f610942 Diagnose if extern local variable is followed by non-extern and vice-versa.
llvm-svn: 124579
2011-01-31 07:04:46 +00:00
Argyrios Kyrtzidis f41860c882 'extern' variables in functions don't shadow externs in global scope. Fixes rdar://8883302.
llvm-svn: 124578
2011-01-31 07:04:41 +00:00
Ted Kremenek 1be4a59a11 Teach -Wuninitialized about indirect goto. Fixes PR 9071.
llvm-svn: 124394
2011-01-27 18:51:39 +00:00
Argyrios Kyrtzidis ff115a2f35 Allow #pragma unused to be used on global variables like gcc. Fixes rdar://8793832.
llvm-svn: 124383
2011-01-27 18:16:48 +00:00
Ted Kremenek 93a313869f Teach -Wuninitialized not to assert when analyzing
blocks that reference captured variables.

llvm-svn: 124348
2011-01-27 02:29:34 +00:00
Ted Kremenek e543be3531 Merge -Wuninitialized-experimental into -Wuninitialized.
llvm-svn: 124279
2011-01-26 04:49:48 +00:00
Ted Kremenek 33ddd9692d Tweak -Wuninitialized-experimental to not emit
a warning for uses of an uninitialized variable
when the use is a void cast, e.g. (void) x.

llvm-svn: 124278
2011-01-26 04:49:43 +00:00
Argyrios Kyrtzidis 7e71884ecb Correct r124242 making sure function chunk that gets diagnosed is really about the block.
Clairvoyance by John!

llvm-svn: 124264
2011-01-26 01:26:44 +00:00
Argyrios Kyrtzidis 4e52cc7de4 Diagnose calling convention attribute incompatibilities. Fixes rdar://8876096.
llvm-svn: 124244
2011-01-25 23:16:40 +00:00
Argyrios Kyrtzidis 20ad245e3e Change error "function cannot return array type" -> "blocks cannot return array type" when blocks are involved.
Addresses rdar://8876238.

llvm-svn: 124242
2011-01-25 23:16:33 +00:00
Ted Kremenek bcf848f70a Teach -Wuninitialized-experimental to also warn
about uninitialized variables captured by blocks.

llvm-svn: 124213
2011-01-25 19:13:48 +00:00
John McCall 4bb483629f Change the wording of the bad-decl-for-attribute warning and error
to make it clear that we're talking about the declarations and not the types.

llvm-svn: 124175
2011-01-25 03:51:08 +00:00
Ted Kremenek 8f01420d9d Teach -Wuninitialized-experimental about sizeof().
llvm-svn: 124076
2011-01-23 17:53:04 +00:00
Ted Kremenek 33d4b5eb66 Provide -Wuninitialized-experimental fixits
for floats, and also check if 'nil' is declared
when suggesting it for initializing ObjC pointers.

llvm-svn: 124004
2011-01-21 22:49:49 +00:00
Ted Kremenek 2959fdd087 Add basic fixits for -Wuninitialized-experimental
to suggest initializations for pointer and
ObjC pointer types.

llvm-svn: 123995
2011-01-21 19:41:46 +00:00
Ted Kremenek 39fa056342 Enhance -Wuninitialized-experimental diagnostics
to issue the warning at an uninitialized variable's
declaration, but to issue notes at possible
uninitialized uses (which could be multiple).

llvm-svn: 123994
2011-01-21 19:41:41 +00:00
Ted Kremenek b82ddd6ada Add rudimentary path-sensitivity to UnintializedValuesV2
analysis for short-circuited operations.  For branch written like "if (x && y)",
we maintain two sets of dataflow values for the outgoing
branches.  This suppresses some common false positives
for -Wuninitialized-experimental.

This change introduces some assertion failures
when running on the LLVM codebase.  WIP.

llvm-svn: 123923
2011-01-20 17:37:17 +00:00
John McCall 33ddac05bb Change the canonical representation of array types to store qualifiers on the
outermost array types and not on the element type.  Move the CanonicalType
member from Type to ExtQualsTypeCommonBase;  the canonical type on an ExtQuals
node includes the qualifiers on the ExtQuals.  Assorted optimizations enabled
by this change.

getQualifiers(), hasQualifiers(), etc. should all now implicitly look through
array types.

llvm-svn: 123817
2011-01-19 10:06:00 +00:00
Ted Kremenek b63931eef6 Teach UninitializedValuesV2 to implicitly reason about C++
references by monitoring whether an access to
a variable is solely to compute it's lvalue or
to do an lvalue-to-rvalue conversion (i.e., a load).

llvm-svn: 123777
2011-01-18 21:18:58 +00:00
Argyrios Kyrtzidis e84389bf68 Properly do a float -> _Complex double conversion, fixes rdar://8875946.
llvm-svn: 123759
2011-01-18 18:49:33 +00:00
Ted Kremenek c8d55da05a Correctly enable test/Sema/unit-variables.c,
thus identifying a minor logical flaw in
UninitializedValuesV2.cpp.

llvm-svn: 123734
2011-01-18 05:00:42 +00:00
Ted Kremenek cab479f0ee Teach UninitializedValuesV2 about "int x = x" and
also properly handle confluence of loops.

llvm-svn: 123733
2011-01-18 04:53:25 +00:00
Francois Pichet 7d92ee3852 Remove a c++ file test I inadvertently added in Sema last week.
llvm-svn: 123608
2011-01-17 01:08:01 +00:00
Ted Kremenek b749a6d62a Add initial prototype for implementation of
-Wuninitialized based on CFG dataflow analysis.  WIP.

llvm-svn: 123512
2011-01-15 02:58:47 +00:00
Abramo Bagnara 1339223186 Added warning about invalid register specification for local variables.
llvm-svn: 123236
2011-01-11 15:16:52 +00:00
Francois Pichet bf711d90ed In Microsoft mode, force 64 bit hex integer constants to signed type if the LL or i64 suffix is used. This MSVC behavior.
For example:

void f(long long){ printf("long long"); }
void f(unsigned long long) { printf("unsigned long long"); }
int main() {
   f(0xffffffffffffffffLL);
}
Will print "long long" using MSVC.

This patch also fixes 16 compile errors related to overloading issues when parsing the MSVC 2008 C++ standard lib.

llvm-svn: 123231
2011-01-11 12:23:00 +00:00
Ted Kremenek bf4832cda8 Add semantic checking that the "thousands grouping"
prefix in a printf format string is matched
with the appropriate conversion specifier.

llvm-svn: 123055
2011-01-08 05:28:46 +00:00
Ted Kremenek a322cae011 Add printf format string parsing support for '
prefix to format conversions (POSIX extension).

llvm-svn: 123054
2011-01-08 05:28:38 +00:00
Ted Kremenek ef81e9e243 Fix crash in CFGBuilder on invalid code. We still need
to reject this code, but at least clang doesn't
crash anymore.

Crash reported in PR 8880.

llvm-svn: 123017
2011-01-07 19:37:16 +00:00
John McCall 3882ace207 Refactor the application of type attributes so that attributes from
the declaration-specifiers and on the declarator itself are moved
to the appropriate declarator chunk.  This permits a greatly
simplified model for how to apply these attributes, as well as
allowing a much more efficient query for the GC attribute.
Now all qualifier queries follow the same basic strategy of
"local qualifiers, local qualifiers on the canonical type,
then look through arrays".  This can be easily optimized by
changing the canonical qualified-array-type representation.

Do not process type attributes as decl attributes on declarations
with declarators.

When computing the type of a block, synthesize a prototype
function declarator chunk if the decl-spec type was not a
function.  This simplifies the logic for building block signatures.

Change the logic which inserts an objc_read_weak on a block
literal to only fire if the block has a __weak __block variable,
rather than if the return type of the block is __weak qualified,
which is not actually a sensible thing to ask.

llvm-svn: 122871
2011-01-05 12:14:39 +00:00
Chandler Carruth a92409c3ec Enhance the diagnostic for negative array sizes to include the
declaration name of the array when present. This ensures that
a poor-man's C++03 static_assert will include the user error message
often embedded in the name.

Update all the tests to reflect the new wording, and add a test for the
name behavior.

llvm-svn: 122802
2011-01-04 04:44:35 +00:00
Douglas Gregor bfe022caa1 When we attempt to create a built-in that involves a library type we
don't have access to (e.g., fprintf, which needs the library type
FILE), fail with a warning and forget about the builtin
entirely. Previously, we would actually provide an error, which breaks
autoconf's super-lame checks for fprintf, longjmp, etc. Fixes PR8316.

llvm-svn: 122744
2011-01-03 09:37:44 +00:00
Rafael Espindola 478abcab3d Produce a better error message for invalid register names.
llvm-svn: 122670
2011-01-01 21:47:03 +00:00