summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/exprs.c
Commit message (Collapse)AuthorAgeFilesLines
* [Diagnostics] Warn for comparison with string literals expanded from macro ↵Dávid Bolvanský2019-11-241-1/+1
| | | | | | | | | | | | | | | | | | (PR44064) Summary: As noted in PR, we have a poor test coverage for this warning. I think macro support was just overlooked. GCC warns in these cases. Clang missed a real bug in the code I am working with, GCC caught it. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70624
* [Diagnostics] Teach -Wnull-dereference about address_space attributeDávid Bolvanský2019-11-071-5/+15
| | | | | | | | | | | | | | | | | | | | | | Summary: Clang should not warn for: > test.c:2:12: warning: indirection of non-volatile null pointer will be deleted, > not trap [-Wnull-dereference] > return *(int __attribute__((address_space(256))) *) 0; > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Solves PR42292. Reviewers: aaron.ballman, rsmith Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69664
* Add support for GCC's '__auto_type' extension, per the GCC manual:Richard Smith2015-11-111-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | https://gcc.gnu.org/onlinedocs/gcc/Typeof.html Differences from the GCC extension: * __auto_type is also permitted in C++ (but only in places where it could appear in C), allowing its use in headers that might be shared across C and C++, or used from C++98 * __auto_type can be combined with a declarator, as with C++ auto (for instance, "__auto_type *p") * multiple variables can be declared in a single __auto_type declaration, with the C++ semantics (the deduced type must be the same in each case) This patch also adds a missing restriction on applying typeof to a bit-field, which GCC has historically rejected in C (due to lack of clarity as to whether the operand should be promoted). The same restriction also applies to __auto_type in C (in both GCC and Clang). This also fixes PR25449. Patch by Nicholas Allegra! llvm-svn: 252690
* [Sema]. Warn when logical expression is a pointerFariborz Jahanian2014-11-141-1/+5
| | | | | | | which evaluates to true. rdar://18716393. Reviewed by Richard Trieu llvm-svn: 222009
* Revert r221702 until I address Richard Trieu'sFariborz Jahanian2014-11-111-5/+1
| | | | | | comments. llvm-svn: 221714
* Patch to warn when logical evaluation of operand evalutes to a true value;Fariborz Jahanian2014-11-111-1/+5
| | | | | | | That this is a c-only patch. c++ already has this warning. This addresses rdar://18716393 llvm-svn: 221702
* Diagnose uses of 'alignof' on functions in -pedantic mode.Richard Smith2013-03-181-1/+1
| | | | llvm-svn: 177354
* Tweak wording and add diagnostic groups to misc diagnostics.Eli Friedman2012-11-021-1/+1
| | | | llvm-svn: 167274
* Further improvement to wording of overload resolution diagnostics, and includingRichard Smith2012-05-151-3/+6
| | | | | | the sole parameter name in the diagnostic in more cases. Patch by Terry Long! llvm-svn: 156807
* PR11857: When the wrong number of arguments are provided for a functionRichard Smith2012-05-111-2/+8
| | | | | | | which expects exactly one argument, include the name of the argument in the diagnostic text. Patch by Terry Long! llvm-svn: 156607
* Add fixit notes for -Wconstant-logical-operand.Matt Beaumont-Gay2011-08-151-9/+23
| | | | llvm-svn: 137620
* Fix an inconsistency in Sema::ConvertArgumentsForCall in thatPeter Collingbourne2011-07-291-1/+1
| | | | | | | the callee note diagnostic was not emitted in the case where there were too few arguments. llvm-svn: 136437
* Expand the coverage of the warning for constants on the RHS of logical operands:Chandler Carruth2011-05-311-0/+18
| | | | | | | | | | | | return f() || -1; where the user meant to write '|'. This bootstraps without any additional warnings. Patch by Richard Trieu. llvm-svn: 132327
* Emit a -Wnull-dereference warning for "*null" not just "*null = something". ↵Argyrios Kyrtzidis2011-04-261-0/+6
| | | | | | Addresses rdar://9269271. llvm-svn: 130207
* When emitting a "too many arguments to function call..." error, also include ↵Ted Kremenek2011-04-041-1/+1
| | | | | | a note with a location for the function prototype. llvm-svn: 128833
* Fix CFG-construction bug when run from ↵Ted Kremenek2011-03-231-0/+8
| | | | | | | | 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
* Teach CFGBuilder about null pointer constants in conditionals, and how they ↵Ted Kremenek2011-02-231-0/+8
| | | | | | can be used to prune branches. Fixes false null pointer dereference warning in PR 8183. llvm-svn: 126305
* Add test case (from PR 8876) for suppressing 'indirection of non-volatile ↵Ted Kremenek2011-02-231-0/+18
| | | | | | null pointer...' warning due to reachability analysis. llvm-svn: 126294
* When deciding whether to complain about the type of a boolean condition, useJohn McCall2010-12-041-0/+9
| | | | | | the type of the expression *after* array/function decay. llvm-svn: 120895
* C's comma operator performs lvalue conversion on both its operands;John McCall2010-10-121-0/+7
| | | | | | require them to have complete types. llvm-svn: 116297
* turn down the logical bitwise confusion warning to not warn Chris Lattner2010-07-241-1/+4
| | | | | | | | | 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
* restrict the && -> & warning to cover a case daniel noted.Chris Lattner2010-07-151-0/+2
| | | | | | | Don't warn about "logically bool" expressions on the RHS, even if they fold to a constant. llvm-svn: 108388
* Add a warning to catch a bug recently caught by code review, like this:Chris Lattner2010-07-131-0/+3
| | | | | | | | | | | 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
* implement PR7569, warning about assignment to null, which Chris Lattner2010-07-071-0/+8
| | | | | | | | people seem to write when they want a deterministic trap. Suggest instead that they use a volatile pointer or __builtin_trap. llvm-svn: 107756
* Add a testcase for PR6501 (too many/too few arguments to a function call).Eric Christopher2010-04-191-0/+6
| | | | llvm-svn: 101800
* Remove fixit for string literal comparison. Telling the user to use ↵Ted Kremenek2010-04-091-1/+1
| | | | | | | | | '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
* Don't emit string-comparison or self-comparison warnings inDouglas Gregor2010-01-121-0/+4
| | | | | | | | | | 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
* use DiagRuntimeBehavior to silence the div/rem by zero warning whenChris Lattner2010-01-121-0/+2
| | | | | | not in an evaluated context. This removes some bogus warnings. llvm-svn: 93258
* implement PR6004, warning about divide and remainder by zero.Chris Lattner2010-01-121-0/+8
| | | | llvm-svn: 93256
* Update tests to use %clang_cc1 instead of 'clang-cc' or 'clang -cc1'.Daniel Dunbar2009-12-151-1/+1
| | | | | | | | | - 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
* fix rdar://7446395, a crash on invalid, by fixing a broken assertion.Chris Lattner2009-12-051-0/+2
| | | | llvm-svn: 90647
* Remove unnecessary -fblocks=0.Daniel Dunbar2009-11-291-1/+1
| | | | llvm-svn: 90070
* Implement PR5242: don't desugar a type more than once in a diagnostic. ThisChris Lattner2009-10-201-0/+9
| | | | | | | | | | | | | | 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
* Update testsAnders Carlsson2009-09-141-2/+2
| | | | llvm-svn: 81802
* reimplement vector comparisons as [fi]cmp+sext instead of using v[if]cmp.Chris Lattner2009-07-081-5/+2
| | | | | | | Also, enable them in sema so that they are tested, and now that the x86 backend has stablized. llvm-svn: 74983
* Parse typeof-specifier the same way as sizeof/alignof are parsed.Argyrios Kyrtzidis2009-05-221-1/+1
| | | | | | | | -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
* Simplify the scheme used for keywords, and change the classification Eli Friedman2009-04-281-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Improve "assignment to cast" diagnostic.Daniel Dunbar2009-04-151-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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
* Strip paren expressions when trying to diagnose "cast as lvalue"Daniel Dunbar2009-04-141-0/+1
| | | | | | extension. llvm-svn: 69100
* Driver: Manually translate a number of -f with no- variants options toDaniel Dunbar2009-04-071-1/+1
| | | | | | | | | | | | 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
* Codegen sometimes crashes on comparisons that aren't legal, justChris Lattner2009-03-311-0/+13
| | | | | | | disable this feature for now, to err on the side of rejecting instead of sometimes crashing. rdar://6326239 llvm-svn: 68088
* Fix rdar://6719156 - clang should emit a better error when blocks are ↵Chris Lattner2009-03-271-1/+7
| | | | | | | | | disabled but are used anyway by changing blocks from being disabled in the parser to being disabled in Sema. llvm-svn: 67816
* Rename clang to clang-cc.Daniel Dunbar2009-03-241-1/+1
| | | | | | Tests and drivers updated, still need to shuffle dirs. llvm-svn: 67602
* do not warn about -=/=- confusion with macros, thanks to rdogra for a testcase.Chris Lattner2009-03-091-0/+4
| | | | llvm-svn: 66416
* undefined -> unspecified. Thanks Mike.Chris Lattner2009-03-081-1/+1
| | | | llvm-svn: 66388
* implement PR3753, warning about comparisons with a string literal.Chris Lattner2009-03-081-1/+6
| | | | llvm-svn: 66387
* refine the "use of unary operator that may be intended as compound ↵Chris Lattner2009-03-081-1/+4
| | | | | | | | | assignment (+=)" warning to only trigger when there is whitespace or something else after the + as suggested by Eli. llvm-svn: 66370
* Fix a long standard problem with clang retaining "too much" sugar Chris Lattner2009-02-191-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* If x is an invalid field decl, don't construct an expression for P->x, Chris Lattner2009-02-131-0/+7
| | | | | | just silently return an error to avoid bogus diagnostics. llvm-svn: 64491
* Implement C99 6.5.3.4p1, rejecting sizeof(bitfield)Chris Lattner2009-01-241-2/+5
| | | | llvm-svn: 62936
OpenPOWER on IntegriCloud