Commit Graph

49 Commits

Author SHA1 Message Date
Matt Beaumont-Gay 0a0ba9d883 Add fixit notes for -Wconstant-logical-operand.
llvm-svn: 137620
2011-08-15 17:50:06 +00:00
Peter Collingbourne 3bc84ca376 Fix an inconsistency in Sema::ConvertArgumentsForCall in that
the callee note diagnostic was not emitted in the case where
there were too few arguments.

llvm-svn: 136437
2011-07-29 00:24:42 +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
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 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 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
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
John McCall 29cb2fdbc1 When deciding whether to complain about the type of a boolean condition, use
the type of the expression *after* array/function decay.

llvm-svn: 120895
2010-12-04 06:09:13 +00:00
John McCall 73d3618223 C's comma operator performs lvalue conversion on both its operands;
require them to have complete types.

llvm-svn: 116297
2010-10-12 07:14:40 +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
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
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
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
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
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 49862b8285 Don't emit string-comparison or self-comparison warnings in
unevaluated contexts, because they only matter for code that will
actually be evaluated at runtime.

As part of this, I had to extend PartialDiagnostic to support fix-it
hints.

llvm-svn: 93266
2010-01-12 23:18:54 +00:00
Chris Lattner 7011795ee4 use DiagRuntimeBehavior to silence the div/rem by zero warning when
not in an evaluated context.  This removes some bogus warnings.

llvm-svn: 93258
2010-01-12 21:30:55 +00:00
Chris Lattner faa5417264 implement PR6004, warning about divide and remainder by zero.
llvm-svn: 93256
2010-01-12 21:23:57 +00:00
Daniel Dunbar 8fbe78f6fc Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.
- This is designed to make it obvious that %clang_cc1 is a "test variable"
   which is substituted. It is '%clang_cc1' instead of '%clang -cc1' because it
   can be useful to redefine what gets run as 'clang -cc1' (for example, to set
   a default target).

llvm-svn: 91446
2009-12-15 20:14:24 +00:00
Chris Lattner 9a152e2570 fix rdar://7446395, a crash on invalid, by fixing a broken assertion.
llvm-svn: 90647
2009-12-05 05:40:13 +00:00
Daniel Dunbar be95682389 Remove unnecessary -fblocks=0.
llvm-svn: 90070
2009-11-29 09:32:38 +00:00
Chris Lattner bd19b18100 Implement PR5242: don't desugar a type more than once in a diagnostic. This
implements a framework that allows us to use information about previously
substituted values to simplify subsequent ones.  Maybe this would be useful
for C++'y stuff, who knows.  We now get:

t.c:4:21: error: invalid operands to binary expression ('size_t' (aka 'unsigned long *') and 'size_t')
  return (size_t) 0 + (size_t) 0;
         ~~~~~~~~~~ ^ ~~~~~~~~~~

on the testcase.  Note that size_t is only aka'd once.

llvm-svn: 84604
2009-10-20 05:36:05 +00:00
Anders Carlsson 2898af59dc Update tests
llvm-svn: 81802
2009-09-14 22:00:20 +00:00
Chris Lattner 2a7deb64c0 reimplement vector comparisons as [fi]cmp+sext instead of using v[if]cmp.
Also, enable them in sema so that they are tested, and now that the x86 backend
has stablized.

llvm-svn: 74983
2009-07-08 01:08:03 +00:00
Argyrios Kyrtzidis f5cc7ac4d5 Parse typeof-specifier the same way as sizeof/alignof are parsed.
-Makes typeof consistent with sizeof/alignof
-Fixes a bug when '>' is in a typeof expression, inside a template type param:
  A<typeof(x>1)> a;

llvm-svn: 72255
2009-05-22 10:22:18 +00:00
Eli Friedman 2b680b43e9 Simplify the scheme used for keywords, and change the classification
scheme to be more useful.

The new scheme introduces a set of categories that should be more 
readable, and also reflects what we want to consider as an extension 
more accurately.  Specifically, it makes the "what is a keyword" 
determination accurately reflect whether the keyword is a GNU or 
Microsoft extension.

I also introduced separate flags for keyword aliases; this is useful 
because the classification of the aliases is mostly unrelated to the 
classification of the original keyword.

This patch treats anything that's in the implementation 
namespace (prefixed with "__", or "_X" where "X" is any upper-case 
letter) as a keyword without marking it as an extension.  This is 
consistent with the standards in that an implementation is allowed to define 
arbitrary extensions in the implementation namespace without violating 
the standard. This gets rid of all the nasty "extension used" warnings 
for stuff like __attribute__ in -pedantic mode.  We still warn for 
extensions outside of the the implementation namespace, like typeof.
If someone wants to implement -Wextensions or something like that, we 
could add additional information to the keyword table.

This also removes processing for the unused "Boolean" language option; 
such an extension isn't supported on any other C implementation, so I 
don't see any point to adding it.

The changes to test/CodeGen/inline.c are required because previously, we 
weren't actually disabling the "inline" keyword in -std=c89 mode.

I'll remove Boolean and NoExtensions from LangOptions in a follow-up 
commit.

llvm-svn: 70281
2009-04-28 03:13:54 +00:00
Daniel Dunbar c2223ab255 Improve "assignment to cast" diagnostic.
- Strip off extra parens when looking for casts.
 - Change the location info to point at the cast (instead of the
   assignment).

For example, on
  
  int *b;
  #define a ((void*) b)
  void f0() {
    a = 10;
  }
  
we now emit:
  
  /tmp/t.c:4:3: error: assignment to cast is illegal, lvalue casts are not supported
    a = 10;
    ^ ~
  /tmp/t.c:2:12: note: instantiated from:
  #define a ((void*) b)
            ~^~~~~~~~~~
  
instead of:
  
  /tmp/t.c:4:5: error: expression is not assignable
    a = 10;
    ~ ^

llvm-svn: 69114
2009-04-15 00:08:05 +00:00
Daniel Dunbar 9351c02bef Strip paren expressions when trying to diagnose "cast as lvalue"
extension.

llvm-svn: 69100
2009-04-14 23:26:44 +00:00
Daniel Dunbar d18049ab1d Driver: Manually translate a number of -f with no- variants options to
clang.
 - We will eventually want some more driver infrastructre for this
   probably.

 - For now, the clang-cc interface stays relatively the same, but we
   don't accept multiple instances anymore, or the [no-] variants
   directly.

llvm-svn: 68550
2009-04-07 21:16:11 +00:00
Chris Lattner 5d68896c7b Codegen sometimes crashes on comparisons that aren't legal, just
disable this feature for now, to err on the side of rejecting instead
of sometimes crashing.  rdar://6326239

llvm-svn: 68088
2009-03-31 07:46:52 +00:00
Chris Lattner 9eac931b5f Fix rdar://6719156 - clang should emit a better error when blocks are disabled but are used anyway
by changing blocks from being disabled in the parser to being disabled
in Sema.

llvm-svn: 67816
2009-03-27 04:18:06 +00:00
Daniel Dunbar a45cf5b6b0 Rename clang to clang-cc.
Tests and drivers updated, still need to shuffle dirs.

llvm-svn: 67602
2009-03-24 02:24:46 +00:00
Chris Lattner ed9f14c4c9 do not warn about -=/=- confusion with macros, thanks to rdogra for a testcase.
llvm-svn: 66416
2009-03-09 07:11:10 +00:00
Chris Lattner 40dc267160 undefined -> unspecified. Thanks Mike.
llvm-svn: 66388
2009-03-08 19:52:14 +00:00
Chris Lattner 222b8bd6ad implement PR3753, warning about comparisons with a string literal.
llvm-svn: 66387
2009-03-08 19:39:53 +00:00
Chris Lattner 36c39c9b0a refine the "use of unary operator that may be intended as compound assignment (+=)"
warning to only trigger when there is whitespace or something else after the + as
suggested by Eli.

llvm-svn: 66370
2009-03-08 06:51:10 +00:00
Chris Lattner 810d330cd3 Fix a long standard problem with clang retaining "too much" sugar
information about types.  We often print diagnostics where we say 
"foo_t" is bad, but the user doesn't know how foo_t is declared 
(because it is a typedef).  Fix this by expanding sugar when present
in a diagnostic (and not one of a few special cases, like vectors).

Before:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' and 'typeof(F)')
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                             ^

After:
t.m:5:2: error: invalid operands to binary expression ('typeof(P)' (aka 'struct mystruct') and 'typeof(F)' (aka 'float'))
 MAX(P, F);
 ^~~~~~~~~
t.m:1:78: note: instantiated from:
#define MAX(A,B)    ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
                                                                             ^

llvm-svn: 65081
2009-02-19 23:45:49 +00:00
Chris Lattner 303284acfc If x is an invalid field decl, don't construct an expression for P->x,
just silently return an error to avoid bogus diagnostics.

llvm-svn: 64491
2009-02-13 22:08:30 +00:00
Chris Lattner 5eca6ada3a Implement C99 6.5.3.4p1, rejecting sizeof(bitfield)
llvm-svn: 62936
2009-01-24 21:29:22 +00:00
Chris Lattner 8dff017695 Fix PR3386 by handling GCC's rules for alignof, which are substantially
different than those for sizeof.  Reject alignof(bitfield) like gcc does.

llvm-svn: 62928
2009-01-24 20:17:12 +00:00
Chris Lattner dca17ceb19 add expected diag
llvm-svn: 60927
2008-12-12 05:59:56 +00:00
Chris Lattner 053441f39d Fix rdar://6095061 - gcc allows __builtin_choose_expr as an lvalue
llvm-svn: 60924
2008-12-12 05:35:08 +00:00
Chris Lattner 8cd9b96ee1 add a silly testcase
llvm-svn: 59877
2008-11-22 19:57:03 +00:00
Chris Lattner 40bb0c83d4 print a type in a diagnostic.
llvm-svn: 59829
2008-11-21 18:27:34 +00:00
Chris Lattner 9b3bbe9db7 Implement rdar://6319320: give a good diagnostic for cases where people
are trying to use the old GCC "casts as lvalue" extension.  We don't and
will hopefully never support this.

llvm-svn: 59460
2008-11-17 19:51:54 +00:00
Chris Lattner ea71438a93 add a simple check to warn people who type "=+" when they probably meant
"+=".

llvm-svn: 55131
2008-08-21 18:04:13 +00:00
Chris Lattner ec8996d771 Add support for __extension__ as an lvalue. rdar://6097308
llvm-svn: 54033
2008-07-25 18:07:19 +00:00
Chris Lattner c43926fe67 Implement support for __extension__ which silences extwarnings in its
scope.  This is part of the fix for PR1966

llvm-svn: 46669
2008-02-02 20:20:10 +00:00