Commit Graph

3571 Commits

Author SHA1 Message Date
David Bolvansky 275e4df115 [Diagnostics] Handle tautological left shifts in boolean context
llvm-svn: 372749
2019-09-24 13:14:18 +00:00
David Bolvansky 849fd28cf0 [Diagnostics] Do not diagnose unsigned shifts in boolean context (-Wint-in-bool-context)
I was looking at old GCC's patch. Current "trunk" version avoids warning for unsigned case, GCC warns only for signed shifts.

llvm-svn: 372708
2019-09-24 09:14:33 +00:00
David Bolvansky 28b38c277a [Diagnostics] Warn for enum constants in bool context (-Wint-in-bool-context; GCC compatibility)
Extracted from D63082.

llvm-svn: 372664
2019-09-23 22:09:49 +00:00
David Bolvansky 84ea41fd17 [Diagnostics] Warn if '<<' in bool context with -Wint-in-bool-context (GCC compatibility)
Extracted from D63082, addressed review comments related to a warning message.

llvm-svn: 372612
2019-09-23 14:21:08 +00:00
David Bolvansky 116e6cf36e [Diagnostics] Avoid -Wsizeof-array-div when dividing the size of a nested array by the size of the deepest base type
llvm-svn: 372600
2019-09-23 12:54:35 +00:00
Craig Topper e4c1765124 [X86] Require last argument to LWPINS/LWPVAL builtins to be an ICE. Add ImmArg to the llvm intrinsics.
Update the isel patterns to use timm instead of imm.

llvm-svn: 372534
2019-09-22 23:48:50 +00:00
David Bolvansky fb218170b4 [Diagnostics] Warn if ?: with integer constants always evaluates to true
Extracted from D63082. GCC has this warning under -Wint-in-bool-context, but as noted in the D63082's review, we should put it under TautologicalConstantCompare.

llvm-svn: 372531
2019-09-22 22:00:48 +00:00
Yonghong Song 91d5c2a035 [CLANG][BPF] permit any argument type for __builtin_preserve_access_index()
Commit c15aa241f8 ("[CLANG][BPF] change __builtin_preserve_access_index()
signature") changed the builtin function signature to
  PointerT __builtin_preserve_access_index(PointerT ptr)
with a pointer type as the argument/return type, where argument and
return types must be the same.

There is really no reason for this constraint. The builtin just
presented a code region so that IR builtins
  __builtin_{array, struct, union}_preserve_access_index
can be applied.

This patch removed the pointer type restriction to permit any
argument type as long as it is permitted by the compiler.

Differential Revision: https://reviews.llvm.org/D67883

llvm-svn: 372516
2019-09-22 17:33:48 +00:00
Richard Trieu 4c05de8c1d Merge and improve code that detects same value in comparisons.
-Wtautological-overlap-compare and self-comparison from -Wtautological-compare
relay on detecting the same operand in different locations.  Previously, each
warning had it's own operand checker.  Now, both are merged together into
one function that each can call.  The function also now looks through member
access and array accesses.

Differential Revision: https://reviews.llvm.org/D66045

llvm-svn: 372453
2019-09-21 03:02:26 +00:00
Richard Trieu 6541c7988b Improve -Wtautological-overlap-compare
Allow this warning to detect a larger number of constant values, including
negative numbers, and handle non-int types better.

Differential Revision: https://reviews.llvm.org/D66044

llvm-svn: 372448
2019-09-21 02:37:10 +00:00
Yonghong Song c15aa241f8 [CLANG][BPF] change __builtin_preserve_access_index() signature
The clang intrinsic __builtin_preserve_access_index() currently
has signature:
  const void * __builtin_preserve_access_index(const void * ptr)

This may cause compiler warning when:
  - parameter type is "volatile void *" or "const volatile void *", or
  - the assign-to type of the intrinsic does not have "const" qualifier.
Further, this signature does not allow dereference of the
builtin result pointer as it is a "const void *" type, which
adds extra step for the user to do type casting.

Let us change the signature to:
  PointerT __builtin_preserve_access_index(PointerT ptr)
such that the result and argument types are the same.
With this, directly dereferencing the builtin return value
becomes possible.

Differential Revision: https://reviews.llvm.org/D67734

llvm-svn: 372294
2019-09-19 02:59:43 +00:00
Erik Pilkington 5741d19f04 [Sema] Suppress -Wformat diagnostics for bool types when printed using %hhd
Also, add a diagnostic under -Wformat for printing a boolean value as a
character.

rdar://54579473

Differential revision: https://reviews.llvm.org/D66856

llvm-svn: 372247
2019-09-18 19:05:14 +00:00
Erik Pilkington 5c62152275 [Sema] Split of versions of -Wimplicit-{float,int}-conversion for Objective-C BOOL
Also, add a diagnostic group, -Wobjc-signed-char-bool, to control all these
related diagnostics.

rdar://51954400

Differential revision: https://reviews.llvm.org/D67559

llvm-svn: 372183
2019-09-17 21:11:51 +00:00
Erik Pilkington a1e29a3407 Use 'BOOL' instead of BOOL in diagnostic messages
Type names should be enclosed in single quotes.

llvm-svn: 372152
2019-09-17 18:02:45 +00:00
Richard Smith 9864269a0d Fix reliance on lax vector conversions in tests for x86 intrinsics.
llvm-svn: 372062
2019-09-17 03:56:28 +00:00
David Bolvansky b8185153f3 [Diagnostics] Added silence note for -Wsizeof-array-div; suggest extra parens
llvm-svn: 371924
2019-09-14 19:38:55 +00:00
David Goldman 6d18650421 [Sema][Typo Correction] Fix potential infite loop on ambiguity checks
Summary:
This fixes a bug introduced in D62648, where Clang could infinite loop
if it became stuck on a single TypoCorrection when it was supposed to
be testing ambiguous corrections. Although not a common case, it could
happen if there are multiple possible corrections with the same edit
distance.

The fix is simply to wipe the TypoExpr from the `TransformCache` so that
the call to `TransformTypoExpr` doesn't use the `CachedEntry`.

Reviewers: rsmith

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67515

llvm-svn: 371859
2019-09-13 14:43:24 +00:00
Richard Smith c624510f13 For PR17164: split -fno-lax-vector-conversion into three different
levels:

 -- none: no lax vector conversions [new GCC default]
 -- integer: only conversions between integer vectors [old GCC default]
 -- all: all conversions between same-size vectors [Clang default]

For now, Clang still defaults to "all" mode, but per my proposal on
cfe-dev (2019-04-10) the default will be changed to "integer" as soon as
that doesn't break lots of testcases. (Eventually I'd like to change the
default to "none" to match GCC and general sanity.)

Following GCC's behavior, the driver flag -flax-vector-conversions is
translated to -flax-vector-conversions=integer.

This reinstates r371805, reverted in r371813, with an additional fix for
lldb.

llvm-svn: 371817
2019-09-13 06:02:15 +00:00
Jonas Devlieghere 4aaa77e48d Revert "For PR17164: split -fno-lax-vector-conversion into three different"
This breaks the LLDB build. I tried reaching out to Richard, but haven't
gotten a reply yet.

llvm-svn: 371813
2019-09-13 05:16:59 +00:00
Richard Smith 49c4e58b75 For PR17164: split -fno-lax-vector-conversion into three different
levels:

 -- none: no lax vector conversions [new GCC default]
 -- integer: only conversions between integer vectors [old GCC default]
 -- all: all conversions between same-size vectors [Clang default]

For now, Clang still defaults to "all" mode, but per my proposal on
cfe-dev (2019-04-10) the default will be changed to "integer" as soon as
that doesn't break lots of testcases. (Eventually I'd like to change the
default to "none" to match GCC and general sanity.)

Following GCC's behavior, the driver flag -flax-vector-conversions is
translated to -flax-vector-conversions=integer.

llvm-svn: 371805
2019-09-13 02:20:00 +00:00
David Bolvansky 82d9e0e122 [NFC] Added triple to test file to avoid arm buildbots failures
llvm-svn: 371646
2019-09-11 18:55:56 +00:00
David Bolvansky 3240ad4ced [Diagnostics] Add -Wsizeof-array-div
Summary: Clang version of https://www.viva64.com/en/examples/v706/

Reviewers: rsmith

Differential Revision: https://reviews.llvm.org/D67287

llvm-svn: 371605
2019-09-11 10:59:47 +00:00
Reid Kleckner 7b4237d3cc Emit -Wmicrosoft-enum-value warning instead of error in MS ABI
Summary:
The first NFC change is to replace a getCXXABI().isMicrosoft() check
with getTriple().isWindowsMSVCEnvironment(). This code takes effect in
non-C++ compilations, so it doesn't make sense to check the C++ ABI. In
the MS ABI, enums are always considered to be "complete" because the
underlying type of an unfixed enum will always be 'int'. This behavior
was moved from -fms-compatibility to MS ABI back in r249656.

The second change is functional, and it downgrades an error to a warning
when the MS ABI is used rather than only under -fms-compatibility. The
reasoning is that it's unreasonable for the following code to reject the
following code for all MS ABI targets with -fno-ms-compatibility:
  enum Foo { Foo_Val = 0xDEADBEEF };
This is valid code for any other target, but in the MS ABI, Foo_Val just
happens to be negative. With this change, clang emits a
-Wmicrosoft-enum-value warning on this code, but compiles it without
error.

Fixes PR38478

Reviewers: hans, rsmith, STL_MSFT

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67304

llvm-svn: 371581
2019-09-11 01:01:06 +00:00
Richard Smith 045b2270ce When evaluating a __builtin_constant_p conditional, always enter
constant-folding mode regardless of the original evaluation mode.

In order for this to be correct, we need to track whether we're checking
for a potential constant expression or checking for undefined behavior
separately from the evaluation mode enum, since we don't want to clobber
those states when entering constant-folding mode.

llvm-svn: 371557
2019-09-10 21:24:09 +00:00
Craig Topper ce2cb0f09e [X86] Allow _MM_FROUND_CUR_DIRECTION and _MM_FROUND_NO_EXC to be used together on instructions that only support SAE and not embedded rounding.
Current for SAE instructions we only allow _MM_FROUND_CUR_DIRECTION(bit 2) or _MM_FROUND_NO_EXC(bit 3) to be used as the immediate passed to the inrinsics. But these instructions don't perform rounding so _MM_FROUND_CUR_DIRECTION is just sort of a default placeholder when you don't want to suppress exceptions. Using _MM_FROUND_NO_EXC by itself is really bit equivalent to (_MM_FROUND_NO_EXC | _MM_FROUND_TO_NEAREST_INT) since _MM_FROUND_TO_NEAREST_INT is 0. Since we aren't rounding on these instructions we should also accept (_MM_FROUND_CUR_DIRECTION | _MM_FROUND_NO_EXC) as equivalent to (_MM_FROUND_NO_EXC). icc allows this, but gcc does not.

Differential Revision: https://reviews.llvm.org/D67289

llvm-svn: 371430
2019-09-09 17:48:05 +00:00
David Bolvansky 454e40eaf3 [NFCI] Unbreak buildbots
llvm-svn: 371226
2019-09-06 16:30:44 +00:00
David Bolvansky d1cc181d03 [NFC] Added new tests for r371222
llvm-svn: 371223
2019-09-06 16:18:18 +00:00
David Bolvansky fd07568074 [Diagnostics] Refactor code for -Wsizeof-pointer-div, catch more cases; also add -Wsizeof-array-div
Previously, -Wsizeof-pointer-div failed to catch:
const int *r;
sizeof(r) / sizeof(int);

Now fixed.
Also introduced -Wsizeof-array-div which catches bugs like:
sizeof(r) / sizeof(short);

(Array element type does not match type of sizeof operand).

llvm-svn: 371222
2019-09-06 16:12:48 +00:00
David Candler a59bffb576 [ARM] Add support for the s,j,x,N,O inline asm constraints
A number of inline assembly constraints are currently supported by LLVM, but rejected as invalid by Clang:

Target independent constraints:

s: An integer constant, but allowing only relocatable values

ARM specific constraints:

j: An immediate integer between 0 and 65535 (valid for MOVW)
x: A 32, 64, or 128-bit floating-point/SIMD register: s0-s15, d0-d7, or q0-q3
N: An immediate integer between 0 and 31 (Thumb1 only)
O: An immediate integer which is a multiple of 4 between -508 and 508. (Thumb1 only)

This patch adds support to Clang for the missing constraints along with some checks to ensure that the constraints are used with the correct target and Thumb mode, and that immediates are within valid ranges (at least where possible). The constraints are already implemented in LLVM, but just a couple of minor corrections to checks (V8M Baseline includes MOVW so should work with 'j', 'N' and 'O' shouldn't be valid in Thumb2) so that Clang and LLVM are in line with each other and the documentation.

Differential Revision: https://reviews.llvm.org/D65863

Change-Id: I18076619e319bac35fbb60f590c069145c9d9a0a
llvm-svn: 371079
2019-09-05 15:17:25 +00:00
Gabor Horvath 6f98400189 [LifetimeAnalysis] Fix some false positives
Differential Revision: https://reviews.llvm.org/D66806

llvm-svn: 370773
2019-09-03 16:17:24 +00:00
Dmitri Gribenko d94b42f422 [Wdocumentation] fixes an assertion failure with typedefed function and block pointer
Summary:
The assertion happens when compiling with -Wdocumentation with variable declaration to a typedefed function pointer. I not too familiar with the ObjC syntax but first two tests assert without this patch.

Fixes https://bugs.llvm.org/show_bug.cgi?id=42844

Reviewers: gribozavr

Reviewed By: gribozavr

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66706

llvm-svn: 370677
2019-09-02 18:24:33 +00:00
Richard Smith 5030928d60 [c++20] Implement semantic restrictions for C++20 designated
initializers.

This has some interesting interactions with our existing extensions to
support C99 designated initializers as an extension in C++. Those are
resolved as follows:

 * We continue to permit the full breadth of C99 designated initializers
   in C++, with the exception that we disallow a partial overwrite of an
   initializer with a non-trivially-destructible type. (Full overwrite
   is OK, because we won't run the first initializer at all.)

 * The C99 extensions are disallowed in SFINAE contexts and during
   overload resolution, where they could change the meaning of valid
   programs.

 * C++20 disallows reordering of initializers. We only check for that for
   the simple cases that the C++20 rules permit (designators of the form
   '.field_name =' and continue to allow reordering in other cases).
   It would be nice to improve this behavior in future.

 * All C99 designated initializer extensions produce a warning by
   default in C++20 mode. People are going to learn the C++ rules based
   on what Clang diagnoses, so it's important we diagnose these properly
   by default.

 * In C++ <= 17, we apply the C++20 rules rather than the C99 rules, and
   so still diagnose C99 extensions as described above. We continue to
   accept designated C++20-compatible initializers in C++ <= 17 silently
   by default (but naturally still reject under -pedantic-errors).

This is not a complete implementation of P0329R4. In particular, that
paper introduces new non-C99-compatible syntax { .field { init } }, and
we do not support that yet.

This is based on a previous patch by Don Hinton, though I've made
substantial changes when addressing the above interactions.

Differential Revision: https://reviews.llvm.org/D59754

llvm-svn: 370544
2019-08-30 22:52:55 +00:00
Richard Smith 33e9be6c8b Refactor InitListChecker to check only a single (explicit) initializer
list, rather than recursively checking multiple lists in C.

This simplification is in preparation for making InitListChecker
maintain more state that's specific to the explicit initializer list,
particularly when handling designated initialization.

llvm-svn: 370418
2019-08-29 22:49:33 +00:00
Artem Dergachev e5c0994ddf [CFG] Fix CFG for statement-expressions in return values.
We're building the CFG from bottom to top, so when the return-value expression
has a non-trivial CFG on its own, we need to continue building from the entry
to the return-value expression CFG rather than from the block to which
we've just appended the return statement.

Fixes a false positive warning "control may reach end of non-void function".

llvm-svn: 370406
2019-08-29 20:37:28 +00:00
Aaron Ballman 1d93522056 Replace some custom C11 extension warnings with the generic warning.
llvm-svn: 370066
2019-08-27 14:41:39 +00:00
Aaron Ballman 99178faf59 Quote the token being diagnosed for C11 extensions.
llvm-svn: 370059
2019-08-27 13:47:51 +00:00
Aaron Ballman 3c5bd65154 Fixing a weird copy-pasta to get bots back to green.
llvm-svn: 369960
2019-08-26 20:46:20 +00:00
Aaron Ballman 33d563e59e Reword the C11 extension diagnostic.
This makes it more consistent with other language extension diagnostics.

llvm-svn: 369957
2019-08-26 20:29:08 +00:00
Aaron Ballman 774bd6ef1c Diagnose use of _Thread_local as an extension when not in C11 mode.
llvm-svn: 369954
2019-08-26 19:44:07 +00:00
Dmitri Gribenko c955e4a910 [Wdocumentation] improve wording of a warning message
Based on @davezarzycki remarks in D64696 improved the wording of the warning
message.

Differential Revision: https://reviews.llvm.org/D66700

Patch by Mark de Wever.

llvm-svn: 369873
2019-08-25 18:20:18 +00:00
Gabor Horvath 665a64265e Fix a test to test what the name suggest.
llvm-svn: 369820
2019-08-23 22:26:49 +00:00
Gabor Horvath 6379e5c8a4 [LifetimeAnalysis] Make it possible to disable the new warnings
llvm-svn: 369817
2019-08-23 22:21:33 +00:00
Nathan Huckleberry cc01d6421f [Sema] Don't warn on printf('%hd', [char]) (PR41467)
Summary: Link: https://bugs.llvm.org/show_bug.cgi?id=41467

Reviewers: rsmith, nickdesaulniers, aaron.ballman, lebedev.ri

Reviewed By: nickdesaulniers, aaron.ballman, lebedev.ri

Subscribers: lebedev.ri, nickdesaulniers, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D66186

llvm-svn: 369791
2019-08-23 18:01:57 +00:00
David Goldman fd4d77707f [Sema][Typo] Fix assertion failure for expressions with multiple typos
Summary:
As Typo Resolution can create new TypoExprs while resolving typos,
it is necessary to recurse through the expression to search for more
typos.

This should fix the assertion failure in `clang::Sema::~Sema()`:
  `DelayedTypos.empty() && "Uncorrected typos!"`

Notes:
- In case some TypoExprs are created but thrown away, Sema
  now has a Vector that is used to keep track of newly created
  typos.
- For expressions with multiple typos, we only give suggestions
  if we are able to resolve all typos in the expression
- This patch is similar to D37521 except that it does not eagerly
  commit to a correction for the first typo in the expression.
  Instead, it will search for corrections which fix all of the
  typos in the expression.

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62648

llvm-svn: 369427
2019-08-20 19:03:15 +00:00
Nathan Huckleberry 1e0affb6e5 [Attr] Support _attribute__ ((fallthrough))
Summary: Fixed extraneous matches of non-NullStmt

Reviewers: aaron.ballman, rsmith, efriedma, xbolva00

Reviewed By: aaron.ballman, rsmith, xbolva00

Subscribers: riccibruno, arphaman, ziangwan, ojeda, xbolva00, nickdesaulniers, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D64838

llvm-svn: 369414
2019-08-20 17:16:49 +00:00
Gabor Horvath eaee4de503 [LifetimeAnalysis] Add support for free functions
Differential Revision: https://reviews.llvm.org/D66303

llvm-svn: 369408
2019-08-20 16:45:06 +00:00
Stephan Bergmann 982b105d2f Rudimentary support for Doxygen \retval command
...so that at least a preceding \param etc. that lacks a description gets a
-Wdocumentation warning (instead of erroneously treating the \retval ... text as
its paragraph).

Differential Revision: https://reviews.llvm.org/D66350

llvm-svn: 369345
2019-08-20 08:36:21 +00:00
David Bolvansky b4806822d2 [Diagnostics] Improve -Wsizeof-pointer-div
Emit diag note with a location of pointer declaration.
Revisited/added tests.

llvm-svn: 369206
2019-08-18 10:10:09 +00:00
Aaron Ballman ce1750d964 Rename this file from cx2.c to c2x.c; NFC.
llvm-svn: 369035
2019-08-15 18:37:30 +00:00
Aaron Ballman 2ed4573e8f Allow standards-based attributes to have leading and trailing underscores.
This gives library implementers a way to use standards-based attributes that do not conflict with user-defined macros of the same name. Attributes in C2x require this behavior normatively (C2x 6.7.11p4), but there's no reason to not have the same behavior in C++, especially given that such attributes may be used by a C library consumed by a C++ compilation.

llvm-svn: 369033
2019-08-15 18:35:44 +00:00