Commit Graph

2839 Commits

Author SHA1 Message Date
Tom Stellard d097e94abb AMDGPU: Add support for 's' and 'v' asm constraints
Summary: 's' is used to specify sgprs and 'v' is used to specify vgprs.

Reviewers: arsenm, echristo

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D14307

llvm-svn: 253610
2015-11-19 22:11:58 +00:00
Alexey Bataev f278eb10b7 PR10235: support for vector mode attributes + warning, by Dmitry Polukhin.
Add support for vector mode attributes like "attribute((mode(V4SF)))". Also add warning about deprecated vector modes like GCC does.
Differential Revision: http://reviews.llvm.org/D14744

llvm-svn: 253551
2015-11-19 10:13:11 +00:00
Akira Hatanaka 8c26ea663d Produce a better diagnostic for global register variables.
Currently, when there is a global register variable in a program that
is bound to an invalid register, clang/llvm prints an error message that
is not very user-friendly.

This commit improves the diagnostic and moves the check that used to be
in the backend to Sema. In addition, it makes changes to error out if
the size of the register doesn't match the declared variable size.

e.g., volatile register int B asm ("rbp");

rdar://problem/23084219

Differential Revision: http://reviews.llvm.org/D13834

llvm-svn: 253405
2015-11-18 00:15:28 +00:00
David Majnemer 7f77eb90a5 [Sema] Don't crash trying to diagnose abs called on a pointer type
Clang tries to figure out if a call to abs is suspicious by looking
through implicit casts to look at the underlying, implicitly converted
type.
Interestingly, C has implicit conversions from pointer-ish types like
function to less exciting types like int.  This trips up our 'abs'
checker because it doesn't know which variant of 'abs' is appropriate.

Instead, diagnose 'abs' called on function types upfront.  This sort of
thing is highly suspicious and is likely indicative of a missing
pointer dereference/function call/array index operation.

This fixes PR25532.

llvm-svn: 253156
2015-11-15 03:04:34 +00:00
Akira Hatanaka 7828b1e604 Add support for function attribute 'disable_tail_calls'.
The ``disable_tail_calls`` attribute instructs the backend to not
perform tail call optimization inside the marked function.

For example, 

int callee(int);

int foo(int a) __attribute__((disable_tail_calls)) {
  return callee(a); // This call is not tail-call optimized.
}

Note that this attribute is different from 'not_tail_called', which
prevents tail-call optimization to the marked function.

rdar://problem/8973573

Differential Revision: http://reviews.llvm.org/D12547

llvm-svn: 252986
2015-11-13 00:42:21 +00:00
Richard Smith 03fd3915ee Additional tests from r252690 that I forgot to 'svn add'.
From a patch by Nicholas Allegra!

llvm-svn: 252955
2015-11-12 21:42:39 +00:00
Richard Smith e301ba2b48 Add support for GCC's '__auto_type' extension, per the GCC manual:
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
2015-11-11 02:02:15 +00:00
Evgeniy Stepanov ae6ebd3af5 Implement __attribute__((internal_linkage)).
The attrubite is applicable to functions and variables and changes
the linkage of the subject to internal.

This is the same functionality as C-style "static", but applicable to
class methods; and the same as anonymouns namespaces, but can apply
to individual methods of a class.

Following the proposal in
http://lists.llvm.org/pipermail/cfe-dev/2015-October/045580.html

llvm-svn: 252648
2015-11-10 21:28:44 +00:00
Akira Hatanaka c866762272 Add support for function attribute 'not_tail_called'.
This attribute is used to prevent tail-call optimizations to the marked
function. For example, in the following piece of code, foo1 will not be
tail-call optimized: 

int __attribute__((not_tail_called)) foo1(int);

int foo2(int a) {
  return foo1(a); // Tail-call optimization is not performed.
}

The attribute has effect only on statically bound calls. It has no
effect on indirect calls. Also, virtual functions and objective-c
methods cannot be marked as 'not_tail_called'.

rdar://problem/22667622

Differential Revision: http://reviews.llvm.org/D12922

llvm-svn: 252369
2015-11-06 23:56:15 +00:00
Aaron Ballman b035cd7ea4 The control expression for a _Generic selection expression should have
its type decayed and qualifiers stripped when determining which
selection it matches. Fixes PR16340.

llvm-svn: 252104
2015-11-05 00:06:05 +00:00
Aaron Ballman 853273f8a9 Improving the diagnostic for cases where the attribute only appertains to a function with a prototype.
llvm-svn: 252055
2015-11-04 16:09:04 +00:00
Tim Northover 935d79b0b1 watchOS & tvOS: add a few more tests.
llvm-svn: 251832
2015-11-02 21:14:48 +00:00
Tim Northover 7a73cc71d7 Support tvOS and watchOS availability attributes
llvm-svn: 251711
2015-10-30 16:30:49 +00:00
John McCall 03107a4ef0 Add support for __builtin_{add,sub,mul}_overflow.
Patch by David Grayson!

llvm-svn: 251651
2015-10-29 20:48:01 +00:00
George Burgess IV 148e0d3d5d [Sema] Implement -Wdouble-promotion for clang.
GCC has a warning called -Wdouble-promotion, which warns you when
an implicit conversion increases the width of a floating point type.

This is useful when writing code for architectures that can perform
hardware FP ops on floats, but must fall back to software emulation for
larger types (i.e. double, long double).

This fixes PR15109 <https://llvm.org/bugs/show_bug.cgi?id=15109>.

Thanks to Carl Norum for the patch!

llvm-svn: 251588
2015-10-29 00:28:52 +00:00
Nico Weber 0e631639be Tweak how -Wunused-value interacts with macros
1. Make the warning more strict in C mode. r172696 added code to suppress
   warnings from macro expansions in system headers, which checks
   `SourceMgr.isMacroBodyExpansion(E->IgnoreParens()->getExprLoc())`. Consider
   this snippet:

   #define FOO(x) (x)
   void f(int a) {
     FOO(a);
   }

   In C, the line `FOO(a)` is an `ImplicitCastExpr(ParenExpr(DeclRefExpr))`,
   while it's just a `ParenExpr(DeclRefExpr)` in C++. So in C++,
   `E->IgnoreParens()` returns the `DeclRefExpr` and the check tests the
   SourceLoc of `a`. In C, the `ImplicitCastExpr` has the effect of checking the
   SourceLoc of `FOO`, which is a macro body expansion, which causes the
   diagnostic to be skipped. It looks unintentional that clang does different
   things for C and C++ here, so use `IgnoreParenImpCasts` instead of
   `IgnoreParens` here. This has the effect of the warning firing more often
   than previously in C code – it now fires as often as it fires in C++ code.

2. Suppress the warning if it would warn on `UNREFERENCED_PARAMETER`.
   `UNREFERENCED_PARAMETER` is a commonly used macro on Windows and it happens
   to uselessly trigger -Wunused-value. As discussed in the thread
   "rfc: winnt.h's UNREFERENCED_PARAMETER() vs clang's -Wunused-value" on
   cfe-dev, fix this by special-casing this specific macro. (This costs a string
   comparison and some fast-path lexing per warning, but the warning is emitted
   rarely. It fires once in Windows.h itself, so this code runs at least once
   per TU including Windows.h, but it doesn't run hundreds of times.)

http://reviews.llvm.org/D13969

llvm-svn: 251441
2015-10-27 19:47:40 +00:00
George Burgess IV 2a6150d932 [Sema] Fix address-of + enable_if overloading logic
Previously, our logic when taking the address of an overloaded function
would not consider enable_if attributes, so long as all of the enable_if
conditions on a given candidate were true. So, two functions with
identical signatures (one with enable_if attributes, the other without),
would be considered equally good overloads. If we were calling the
function instead of taking its address, then the function with enable_if
attributes would be preferred.

This patch makes us prefer the candidate with enable_if regardless of if
we're calling or taking the address of an overloaded function.

Differential Revision: http://reviews.llvm.org/D13795

llvm-svn: 250486
2015-10-16 01:17:38 +00:00
George Burgess IV 5f21c71800 [Sema] Make `&function_with_enable_if_attrs` an error
This fixes a bug where one can take the address of a conditionally
enabled function to drop its enable_if guards. For example:

  int foo(int a) __attribute__((enable_if(a > 0, "")));
  int (*p)(int) = &foo;
  int result = p(-1); // compilation succeeds; calls foo(-1)

Overloading logic has been updated to reflect this change, as well.

Functions with enable_if attributes that are always true are still
allowed to have their address taken.

Differential Revision: http://reviews.llvm.org/D13607

llvm-svn: 250090
2015-10-12 19:57:04 +00:00
George Burgess IV 4546181e12 [Sema] Allow C conversions in C overload logic
C allows for some implicit conversions that C++ does not, e.g. void* ->
char*. This patch teaches clang that these conversions are okay when
dealing with overloads in C.

Differential Revision: http://reviews.llvm.org/D13604

llvm-svn: 249995
2015-10-11 20:13:20 +00:00
Aaron Ballman 6269236a8e Amending r249721 to properly handle pathological attribute-related names like __ and ____.
Patch by Adrian Zgorzalek!

llvm-svn: 249833
2015-10-09 13:53:24 +00:00
Eric Fiselier 18677d51e0 Skip NonNull sema checks in unevaluated contexts.
Summary:
Currently when a function annotated with __attribute__((nonnull)) is called in an unevaluated context with a null argument a -Wnonnull warning is emitted. 
This warning seems like a false positive unless the call expression is potentially evaluated. Change this behavior so that the non-null warnings use DiagRuntimeBehavior so they wont emit when they won't be evaluated.

Reviewers: majnemer, rsmith

Subscribers: mclow.lists, cfe-commits

Differential Revision: http://reviews.llvm.org/D13408

llvm-svn: 249787
2015-10-09 00:17:57 +00:00
David Majnemer dc9be216c0 [MSVC Compat] Try to treat an implicit, fixed enum as an unfixed enum
consider the following:
enum E *p;
enum E { e };

The above snippet is not ANSI C because 'enum E' has not bee defined
when we are processing the declaration of 'p'; however, it is a popular
extension to make the above work.  This would fail using the Microsoft
enum semantics because the definition of 'E' would implicitly have a
fixed underlying type of 'int' which would trigger diagnostic messages
about a mismatch between the declaration and the definition.

Instead, treat fixed underlying types as not fixed for the purposes of
the diagnostic.

llvm-svn: 249674
2015-10-08 10:04:46 +00:00
David Majnemer 475f9eabc2 Update a few more tests in response to the MS ABI enum semantics
Our self hosting buildbots found a few more tests which weren't updated
to reflect that the enum semantics are part of the Microsoft ABI.

llvm-svn: 249670
2015-10-08 08:28:09 +00:00
David Majnemer e4e3e6a5bf [Sema] Tweak incomplete enum types on MSVC ABI targets
Enums without an explicit, fixed, underlying type are implicitly given a
fixed 'int' type for ABI compatibility with MSVC.  However, we can
enforce the standard-mandated rules on these types as-if we didn't know
this fact if the tag is not part of a definition.

llvm-svn: 249667
2015-10-08 07:45:35 +00:00
David Majnemer c10b8381f7 Update tests touched by r249656
These test updates almost exclusively around the change in behavior
around enum: enums without a definition are considered incomplete except
when targeting MSVC ABIs.  Since these tests are interested in the
'incomplete-enum' behavior, restrict them to %itanium_abi_triple.

llvm-svn: 249660
2015-10-08 06:31:22 +00:00
Eric Fiselier a3a7c56143 Diagnose const atomics in __atomic builtins.
Diagnose when a pointer to const T is used as the first argument in at atomic
builtin unless that builtin is a load operation. This is already checked for
C11 atomics builtins but not for __atomic ones.

This patch was given the LGTM by rsmith when it was part
of a larger review. (See http://reviews.llvm.org/D10407)

llvm-svn: 249252
2015-10-04 00:11:02 +00:00
George Burgess IV ced56e6eca Teach -Wtautological-overlap-compare about enums
Prior to this patch, -Wtautological-overlap-compare would only warn us
if there was a sketchy logical comparison between variables and
IntegerLiterals. This patch makes -Wtautological-overlap-compare aware
of EnumConstantDecls, so it can apply the same logic to them.

llvm-svn: 249053
2015-10-01 18:47:52 +00:00
Anastasia Stulova e6e082348d [OpenCL] Add missing OpenCL LangOpts in address space compatibility checks
and test checking broken (due to CL specific diagnostics) C functionality

M    test/Sema/address_spaces.c
M    lib/Sema/SemaExpr.cpp

llvm-svn: 248902
2015-09-30 13:49:55 +00:00
DeLesley Hutchins 2b504dce14 Thread Safety Analysis: allow capability attribute on unions.
llvm-svn: 248805
2015-09-29 16:24:18 +00:00
DeLesley Hutchins dc0541f12f Thread Safety Analysis: fix before/after checks so that they work on global
variables as well member variables.

llvm-svn: 248803
2015-09-29 15:25:51 +00:00
Nico Weber b9d79250c1 Make a test a bit shorter. No behavior change.
llvm-svn: 248456
2015-09-24 01:34:27 +00:00
Alexander Musman 8e261be911 Fix assertion in inline assembler IR gen
Several inputs may not refer to one output constraint in inline assembler
insertions, clang was failing on assertion on such test case.

llvm-svn: 248158
2015-09-21 14:41:00 +00:00
Charles Davis c7d5c94f78 Support __builtin_ms_va_list.
Summary:
This change adds support for `__builtin_ms_va_list`, a GCC extension for
variadic `ms_abi` functions. The existing `__builtin_va_list` support is
inadequate for this because `va_list` is defined differently in the Win64
ABI vs. the System V/AMD64 ABI.

Depends on D1622.

Reviewers: rsmith, rnk, rjmccall

CC: cfe-commits

Differential Revision: http://reviews.llvm.org/D1623

llvm-svn: 247941
2015-09-17 20:55:33 +00:00
Stephen Canon ca8eefddb7 Prevent implicit re-interpret casts between ExtVector and Scalar types.
Previously, in certain cases lax vector conversions could occur between scalar floating-point values and ExtVector types; these conversions would be simple bitcasts.  We need to allow them with other vector types to support some common headers, but we don't need them for ExtVector.  Preventing them here makes them behave like other operations involving scalars and ExtVectors.

llvm-svn: 247643
2015-09-15 00:21:56 +00:00
Rachel Craik 022bdc7d73 C11 _Bool bitfield diagnostic
Summary: Implement DR262 (for C). This patch will mainly affect bitfields of type _Bool

Reviewers: fraggamuffin, rsmith

Subscribers: hubert.reinterpretcast, cfe-commits

Differential Revision: http://reviews.llvm.org/D10018

llvm-svn: 247618
2015-09-14 21:27:36 +00:00
Hal Finkel 0e2b975eb6 Don't crash on a self-alias declaration
We were crashing in CodeGen given input like this:

  int self_alias(void) __attribute__((weak, alias("self_alias")));

such a self-alias is invalid, but instead of diagnosing the situation, we'd
proceed to produce IR for both the function declaration and the alias. Because
we already had a function named 'self_alias', the alias could not be named the
same thing, and so LLVM would pick a different name ('self_alias1' for example)
for that value. When we later called CodeGenModule::checkAliases, we'd look up
the IR value corresponding to the alias name, find the function declaration
instead, and then assert in a cast to llvm::GlobalAlias. The easiest way to prevent
this is simply to avoid creating the wrongly-named alias value in the first
place and issue the diagnostic there (instead of in checkAliases). We detect a
related cycle case in CodeGenModule::EmitAliasDefinition already, so this just
adds a second such check.

Even though the other test cases for this 'alias definition is part of a cycle'
diagnostic are in test/Sema/attr-alias-elf.c, I've added a separate regression
test for this case. This is because I can't add this check to
test/Sema/attr-alias-elf.c without disturbing the other test cases in that
file. In order to avoid construction of the bad IR values, this diagnostic
is emitted from within CodeGenModule::EmitAliasDefinition (and the relevant
declaration is not added to the Aliases vector). The other cycle checks are
done within the CodeGenModule::checkAliases function based on the Aliases
vector, called from CodeGenModule::Release.  However, if there have been errors
earlier, HandleTranslationUnit does not call Release, and so checkAliases is
never called, and so none of the other diagnostics would be produced.

Fixes PR23509.

llvm-svn: 246882
2015-09-04 21:49:21 +00:00
Hans Wennborg 5427a69545 Don't allow dllexport/import on static local variables
They might technically have external linkage, but it still doesn't make sense
for the user to try and export such variables. This matches MSVC's and MinGW's
behaviour.

llvm-svn: 246864
2015-09-04 19:59:39 +00:00
Vedant Kumar 2ea5393ca1 [Sema] Avoid crash on tag-type mismatch (Fixes PR24610)
Differential Revision: http://reviews.llvm.org/D12444

llvm-svn: 246618
2015-09-02 03:27:15 +00:00
David Majnemer c378ca5043 [AST] Don't crash when comparing incomplete object
We cannot tell if an object is past-the-end if its type is incomplete.
Zero sized objects satisfy past-the-end criteria and our object might
turn out to be such an object.

This fixes PR24622.

llvm-svn: 246359
2015-08-29 08:32:55 +00:00
Charles Li 430db1e717 [Tests] Modified Lit Tests to be C++11 compatibile
This 2nd patch should not change the test results, but it is useful if clang's
default C++ language is ever changed from gnu++98.

llvm-svn: 246183
2015-08-27 18:49:15 +00:00
Ahmed Bougacha 5946ca4fc4 [ARM] Mark mcr/mrc builtin operands as required-immediate.
An early error message is better than the "cannot select" alternative.

llvm-svn: 246094
2015-08-26 22:21:07 +00:00
Olivier Goffart 66be61ad4f Fix crash with two typos in the arguments of a function
The problem is that the arguments are of TheCall are reset later
to the ones in Args, making TypoExpr put back. Some TypoExpr that have
already  been diagnosed and will assert later in Sema::getTypoExprState

llvm-svn: 245560
2015-08-20 13:11:14 +00:00
John McCall 0d461693b6 Fix the layout of bitfields in ms_struct unions: their
alignment is ignored, and they always allocate a complete
storage unit.

Also, change the dumping of AST record layouts: use the more
readable C++-style dumping even in C, include bitfield offset
information in the dump, and don't print sizeof/alignof
information for fields of record type, since we don't do so
for bases or other kinds of field.

rdar://22275433

llvm-svn: 245514
2015-08-19 22:42:36 +00:00
Richard Trieu 1cd076eb34 Fix -Wlogical-not-parentheses to work better with C code.
Remove the assumption of a Boolean type by checking if an expression is known
to have a boolean value.  Disable warning in two other tests.

llvm-svn: 245507
2015-08-19 21:33:54 +00:00
George Burgess IV bdb5b2687a Make __builtin_object_size always answer correctly
__builtin_object_size would return incorrect answers for many uses where
type=3. This fixes the inaccuracy by making us emit 0 instead of LLVM's
objectsize intrinsic.

Additionally, there are many cases where we would emit suboptimal (but
correct) answers, such as when arrays are involved. This patch fixes
some of these cases (please see new tests in test/CodeGen/object-size.c
for specifics on which cases are improved)

Resubmit of r245323 with PR24493 fixed.
Patch mostly by Richard Smith.
Differential Revision: http://reviews.llvm.org/D12000
This fixes PR15212.

llvm-svn: 245403
2015-08-19 02:19:07 +00:00
Nico Weber 19999b4816 Revert r245323, it caused PR24493.
llvm-svn: 245342
2015-08-18 20:32:55 +00:00
George Burgess IV 232c76213d Make __builtin_object_size always answer correctly
__builtin_object_size would return incorrect answers for many uses where
type=3. This fixes the inaccuracy by making us emit 0 instead of LLVM's
objectsize intrinsic.

Additionally, there are many cases where we would emit suboptimal (but
correct) answers, such as when arrays are involved. This patch fixes
some of these cases (please see new tests in test/CodeGen/object-size.c
for specifics on which cases are improved)

Patch mostly by Richard Smith.
Differential Revision: http://reviews.llvm.org/D12000
This fixes PR15212.

llvm-svn: 245323
2015-08-18 18:18:27 +00:00
Davide Italiano 32cbff7809 [Sema] Be consistent about diagnostic wording: always use "cannot".
Discussed with Richard Smith.

llvm-svn: 245162
2015-08-15 15:23:14 +00:00
Davide Italiano da8a3b903b [Sema] main can't be declared as global variable, in C++.
So, we now reject that. We also warn for any external-linkage global
variable named main in C, because it results in undefined behavior.

PR:	  24309
Differential Revision:	http://reviews.llvm.org/D11658
Reviewed by:	rsmith

llvm-svn: 245051
2015-08-14 14:13:29 +00:00
Andrey Bokhanko d9eab9cc13 Additional fix for PR14269: Crash on vector elements / global register vars in inline assembler.
Compiler crashed when vector elements / global register vars were used in inline assembler with "m" restriction. This patch fixes this.

Differential Revision: http://reviews.llvm.org/D10476

llvm-svn: 243870
2015-08-03 10:38:10 +00:00