Commit Graph

2832 Commits

Author SHA1 Message Date
Douglas Gregor f83b4ea8b6 Under -fms-extensions, only inject a friend tag name when we didn't see a tag with that name in an enclosing scope.
r177473 made us correctly consider only those declarations in the
enclosing namespace scope when looking for a friend declaration. Under
ms-extensions mode, where we do some level of friend injection, this
meant that we were introducing a new tag type into a different scope
than what Microsoft actually does. Address this by only doing the
friend injection when we didn't see any tag with that name in any
outer scope. Fixes <rdar://problem/14250378>.

llvm-svn: 185100
2013-06-27 20:42:30 +00:00
Larisse Voufo 64cf3efd47 Fix a conversion to incomplete type bug -- The error message now specifically states that the type is incomplete and points to the forward declaration of the incomplete type.
llvm-svn: 185056
2013-06-27 01:50:25 +00:00
Richard Smith 83e37bee44 PR16467: Teach -Wunsequenced that in C11 (unlike C++11), an assignment's
side-effect is not sequenced before its value computation. Also fix a
mishandling of ?: expressions where the condition is constant that was
exposed by the tests for this.

llvm-svn: 185035
2013-06-26 23:16:51 +00:00
Aaron Ballman 2a6febc0c5 This patch fixes PR16395, when HandleMSProperty returns null due to a declaration with no name.
Patch thanks to Robert Wilhelm.

llvm-svn: 185022
2013-06-26 21:28:44 +00:00
Eli Friedman 2782dacfbc Rewrite record layout for ms_struct structs.
The old implementation of ms_struct in RecordLayoutBuilder was a
complete mess: it depended on complicated conditionals which didn't
really reflect the underlying logic, and placed a burden on users of
the resulting RecordLayout. This commit rips out almost all of the
old code, and replaces it with simple checks in
RecordLayoutBuilder::LayoutBitField.

This commit also fixes <rdar://problem/14252115>, a bug where class
inheritance would cause us to lay out bitfields incorrectly.

llvm-svn: 185018
2013-06-26 20:50:34 +00:00
Nick Lewycky 7a2a4799d6 Don't check for triviality on fields of templated records. We can't know the
answer until after instantiation. Fixes PR16061!

llvm-svn: 184890
2013-06-25 23:22:23 +00:00
David Majnemer 502b0ed264 Implement DR136
Friend declarations that specify a default argument must be a definition
and the only declaration in the translation unit.

llvm-svn: 184889
2013-06-25 23:09:30 +00:00
Matt Beaumont-Gay 35779955b3 Don't try to get the layout of an invalid decl in getDeclAlign.
When the decl that we're getting alignment for is a FieldDecl, and the field's
parent record is invalid, skip the actual field alignment calculation (and
return 1-byte alignment in the general case).

Also, assert in in getASTRecordLayout that the decl is valid. This was
inspired by PR16292; see also r184581 and r184751.

llvm-svn: 184883
2013-06-25 22:19:15 +00:00
Richard Smith e83b1d3e7a More of N3652: don't add an implicit 'const' to 'constexpr' member functions when checking for overloads in C++1y.
llvm-svn: 184865
2013-06-25 18:46:26 +00:00
Reid Kleckner 8a36502a60 [AST] Introduce a new DecayedType sugar node
The goal of this sugar node is to be able to look at an arbitrary
FunctionType and tell if any of the parameters were decayed from an
array or function type.  Ultimately this is necessary to implement
Microsoft's C++ name mangling scheme, which mangles decayed arrays
differently from normal pointers.

Reviewers: rsmith

Differential Revision: http://llvm-reviews.chandlerc.com/D1014

llvm-svn: 184763
2013-06-24 17:51:48 +00:00
Stephen Lin 9354fc5abd Add null check (resolves PR16423)
llvm-svn: 184661
2013-06-23 07:37:13 +00:00
Richard Smith 392497bebe Fix assert if an attempt is made to explicitly instantiate an alias template.
Patch by Ismail Pazarbasi!

llvm-svn: 184650
2013-06-22 22:03:31 +00:00
Richard Trieu 9be9c6804f Extend -Wnon-pod-varargs to check calls made from member pointers.
llvm-svn: 184629
2013-06-22 02:30:38 +00:00
Richard Trieu 41bc0994c3 Extend -Wnon-pod-varargs to more cases, such as function pointers as return
types and function pointer arrays.

llvm-svn: 184616
2013-06-22 00:20:41 +00:00
David Blaikie e5323aa921 Provide suggested no-arg calls for overloaded member functions missing calls
Reviewed by Richard Smith.

llvm-svn: 184612
2013-06-21 23:54:45 +00:00
Reid Kleckner 23f4c4b64f [ms-cxxabi] Destroy temporary record arguments in the callee
Itanium destroys them in the caller at the end of the full expression,
but MSVC destroys them in the callee.  This is further complicated by
the need to emit EH-only destructor cleanups in the caller.

This should help clang compile MSVC's debug iterators more correctly.
There is still an outstanding issue in PR5064 of a memcpy emitted by the
LLVM backend, which is not correct for C++ records.

Fixes PR16226.

Reviewers: rjmccall

Differential Revision: http://llvm-reviews.chandlerc.com/D929

llvm-svn: 184543
2013-06-21 12:45:15 +00:00
Richard Smith 7a5b940952 Fix copy-pasted comment.
llvm-svn: 184494
2013-06-20 23:01:44 +00:00
Eli Friedman 6fc7ad1107 Don't allow __attribute__((common)) in C++. PR16330.
llvm-svn: 184493
2013-06-20 22:55:04 +00:00
Richard Trieu 664c4c678b Extend -Wnon-pod-varargs to check calls made from function pointers.
llvm-svn: 184470
2013-06-20 21:03:13 +00:00
Eli Friedman 600bc24ef0 Clean up warning and add a test.
llvm-svn: 184466
2013-06-20 20:58:02 +00:00
Eli Friedman 97b5f2fafc Add an additional test for dynamic_cast.
llvm-svn: 184454
2013-06-20 18:53:38 +00:00
Enea Zaffanella a86d88c7cd Improved source code fidelity for gcc mode attribute.
llvm-svn: 184417
2013-06-20 12:46:19 +00:00
Richard Smith 51f0317e52 PR16377: Allow evaluation of statement expressions in constant evaluation,
why not. Apparently GCC supports this.

llvm-svn: 184396
2013-06-20 03:00:05 +00:00
Richard Smith f032001b6e Add a workaround for a libstdc++-4.2 <tr1/hashtable> bug. This header uses
return false;

in a function returning a pointer. 'false' was a null pointer constant in C++98
but is not in C++11. Punch a very small hole in the initialization rules in
C++11 mode to allow this specific case in system headers.

llvm-svn: 184395
2013-06-20 02:18:31 +00:00
Eli Friedman 61a511ff5b Add a few more tests for casts.
llvm-svn: 184392
2013-06-20 01:35:13 +00:00
Eli Friedman b2d617de2c Add a testcase which uses an UnresolvedUsingTypenameDecl as the base of an NNS.
llvm-svn: 184386
2013-06-20 00:04:23 +00:00
Eli Friedman d364078a32 Fix r184381 so the test doesn't fail. Sorry for the inconvenience, I thought I had checked it.
llvm-svn: 184382
2013-06-19 23:00:37 +00:00
Eli Friedman 5c85dd93de Extra test for diagnostic in Sema::BuildCXXNestedNameSpecifier.
llvm-svn: 184381
2013-06-19 22:58:30 +00:00
Eli Friedman f26b81b62a Improve diagnostic for redeclaring static member function. Fixes PR16382.
llvm-svn: 184378
2013-06-19 22:43:55 +00:00
Eli Friedman 705a7b4cb7 Add missing test for -Wunneeded-member-functions.
llvm-svn: 184371
2013-06-19 22:01:25 +00:00
Reid Kleckner 0a0c8895ea [Windows] Fix __declspec(property) when the getter returns a ref
This fixes an issue when parsing atlbase.h.

Patch by Will Wilson!

llvm-svn: 184319
2013-06-19 16:37:23 +00:00
Rafael Espindola 45f96f87c3 Fix pr16354.
We now reject things like

struct ABC {
  static double a;
};
register double ABC::a = 1.0;

llvm-svn: 184300
2013-06-19 13:41:54 +00:00
Richard Smith 39b7968ccb DR14, DR101, and part of DR1: fix handling of extern "C" declarations in
namespaces, by treating them just like we treat extern "C" declarations in
function scope.

llvm-svn: 184223
2013-06-18 20:15:12 +00:00
Larisse Voufo 9f380c55ce r184100 Fix -- Updated test cases for contextual conversion
llvm-svn: 184165
2013-06-18 01:27:47 +00:00
Eli Friedman 66b9e9e9fe Fix Expr::Classify to correctly classify ExtVectorElementExprs. PR16204.
llvm-svn: 184123
2013-06-17 21:09:57 +00:00
Rafael Espindola 09ce33ded0 Revert "Updated test cases for contextual conversion"
This reverts commit r184100.

It was faling on some bots:
http://bb.pgr.jp/builders/cmake-clang-i686-mingw32/builds/1973/steps/test_clang/logs/Clang%20%3A%3A%20SemaCXX__cxx1y-contextual-conversion-tweaks.cpp

llvm-svn: 184108
2013-06-17 19:26:19 +00:00
Larisse Voufo 249f9277a4 Updated test cases for contextual conversion
llvm-svn: 184100
2013-06-17 18:41:38 +00:00
Richard Smith f2c9afceef C++11: don't warn about the deprecated 'register' keyword if it's combined with
an asm label.

llvm-svn: 184069
2013-06-17 01:34:01 +00:00
Richard Smith 37ba45a3c5 Add warning group -Wdeprecated-register for C++11 warning on 'register' being
deprecated.

llvm-svn: 184068
2013-06-17 00:01:58 +00:00
Larisse Voufo d1336faf53 Fixed one buildbot-failure-causing bug...
llvm-svn: 184053
2013-06-16 04:34:07 +00:00
Larisse Voufo 0f1394c86e Updated the support for contextual conversion tweaks (n3323) with a previously overlooked part: implicitly converting array sizes to size_t, rather than contextually converting them to some unique type.
llvm-svn: 184048
2013-06-15 20:17:46 +00:00
Faisal Vali d667641542 A quick fix to allow return type deduction on member templates
by ensuring DiagnoseUseOfDecl is called both on the found decl and the
decl being used (i.e the specialization in the case of member templates) whenever they are different.
Per the exchange captured in
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130610/081636.html
a more comprehensive fix that allows both decls to be passed into DiagnoseUseOfDecl is (or should be) forthcoming relatively soon.

llvm-svn: 184043
2013-06-15 11:54:37 +00:00
Richard Smith 82c9b5183f Fix handling of const_cast from prvalue to rvalue reference: such a cast is
only permitted if the source object is of class type, and should materialize a
temporary for the reference to bind to.

llvm-svn: 184017
2013-06-14 22:27:52 +00:00
Richard Smith ab2436ee83 Suppress the c++11 -Wdeprecated warning for 'register' if it is expanded from a
macro defined in a system header. glibc uses it in macros, apparently.

llvm-svn: 184005
2013-06-14 21:05:24 +00:00
Chandler Carruth c41c8b3a4a Fix the warning for divide by zero to be a bit more robust. ;]
Previously, it only ever fired for zeros which formed null pointers.
Now, hilariously, in C++98 this was almost anything. Including tricks
like warning on the divisor in this code:

typedef char c3[3];
size_t f(c3* ptr) {
  return (sizeof(ptr) / sizeof(*ptr)) / (size_t)(!(sizeof(ptr) % sizeof(*ptr)));
}

Why the RHS of the outer divide is a null pointer constant is a sordid
tale of sorrow. Anyways, the committee fixed this for C++11 and onward
as part of core isssue 903, and Richard recently implemented this fix
causing the warning to go away here (and elsewhere).

This patch restores the warning here and adds it for numerous other
somewhat obvious gaffes:

int g(int x) {
  return x / (int)(0.0);
}

The patch is essentially just using the full power of our constant
folding in Clang to produce the warning, but insisting that it must fold
to an *integer* which is zero so that we don't get false positives
anywhere.

llvm-svn: 183970
2013-06-14 08:57:18 +00:00
Richard Smith f24e6e747b Fix some confusing diagnostic wording. s/implicit default/implicit/ if we're
not actually talking about a default constructor.

llvm-svn: 183885
2013-06-13 03:34:55 +00:00
Richard Smith d577fbbd1c C++11: If a class has a user-declared copy operation or destructor, the
implicit definition of a copy operation is deprecated. Add a warning for this
to -Wdeprecated. This warning is disabled by default for now, pending
investigation into how common this situation is.

llvm-svn: 183884
2013-06-13 03:23:42 +00:00
Richard Smith 4055de40ab Implement core issue 903: only integer literals with value 0 and prvalues of
type std::nullptr_t are null pointer constants from C++11 onwards.

llvm-svn: 183883
2013-06-13 02:46:14 +00:00
Richard Smith f026b60099 In C++11, promote access declaration diagnostic from warning to error. There
doesn't seem to be any value in even adding a -W flag for this.

llvm-svn: 183882
2013-06-13 02:12:17 +00:00
Richard Smith 8ca78a16f4 Add -Wdeprecated warnings and fixits for things deprecated in C++11:
- 'register' storage class
 - dynamic exception specifications

Only the former check is enabled by default for now (the latter might be quite noisy).

llvm-svn: 183881
2013-06-13 02:02:51 +00:00
Richard Smith 2eabf78eb6 When copy-initializing a temporary for a reference binding, don't allow use of
explicit constructors.

llvm-svn: 183879
2013-06-13 00:57:57 +00:00
Richard Smith cc1b96d356 PR12086, PR15117
Introduce CXXStdInitializerListExpr node, representing the implicit
construction of a std::initializer_list<T> object from its underlying array.
The AST representation of such an expression goes from an InitListExpr with a
flag set, to a CXXStdInitializerListExpr containing a MaterializeTemporaryExpr
containing an InitListExpr (possibly wrapped in a CXXBindTemporaryExpr).

This more detailed representation has several advantages, the most important of
which is that the new MaterializeTemporaryExpr allows us to directly model
lifetime extension of the underlying temporary array. Using that, this patch
*drastically* simplifies the IR generation of this construct, provides IR
generation support for nested global initializer_list objects, fixes several
bugs where the destructors for the underlying array would accidentally not get
invoked, and provides constant expression evaluation support for
std::initializer_list objects.

llvm-svn: 183872
2013-06-12 22:31:48 +00:00
Richard Smith e3b28bc363 Move detection of reference members binding to temporaries from building of
CXXCtorInitializers to the point where we perform the questionable lifetime
extension. This exposed a selection of false negatives in the warning.

llvm-svn: 183869
2013-06-12 21:51:50 +00:00
Richard Smith 389790a270 Add a testcase for PR7434, which is a bug we no longer appear to have.
llvm-svn: 183787
2013-06-11 20:38:45 +00:00
David Majnemer 55890bfaa6 Implement DR85: Redeclaration of member is forbidden
Disallow the existence of a declaration of a member class that isn't a
forward declaration before it's definition.

llvm-svn: 183722
2013-06-11 03:51:23 +00:00
Richard Trieu bb4b894e0b Add a new warning, -Wlogical-not-parentheses, to -Wparentheses.
This warning triggers on the logical not of a non-boolean expression on the
left hand side of comparison.  Often, the user meant to negate the comparison,
not just the left hand side of the comparison.  Two notes are also emitted,
the first with a fix-it to add parentheses around the comparison, and the other
to put parenthesis around the not expression to silence the warning.

bool not_equal(int x, int y) {
  return !x == y;  // warn here
}

  return !(x == y);  // first fix-it, to negate comparison.

  return (!x) == y;  // second fix-it, to silence warning.

llvm-svn: 183688
2013-06-10 18:52:07 +00:00
Larisse Voufo 236bec24ec reverted test
llvm-svn: 183637
2013-06-10 06:50:24 +00:00
Richard Smith faadef7369 Recursively lifetime-extend into array temporaries. These can get implicitly
created through binding a reference-to-array to an initializer list.

llvm-svn: 183594
2013-06-08 00:02:08 +00:00
Richard Smith 5ed79566d6 PR16273: Weaken a bogus assertion.
llvm-svn: 183550
2013-06-07 20:03:01 +00:00
Eli Friedman c9817fdf16 When we're synthesizing copy/move-assignment, we can't form a reference to an
invalid field; make sure we don't try.  Fixes <rdar://problem/14084171>.

llvm-svn: 183479
2013-06-07 01:48:56 +00:00
Richard Smith de229235b9 Implement DR1270: braces can be elided in all aggregate initialization, not
just copy-list-initialization in a variable declaration. This effectively
reverts r142147.

llvm-svn: 183397
2013-06-06 11:41:05 +00:00
Hans Wennborg 15439bcf79 Disallow reinterpret_cast from pointer to bool on Windows
This became allowed by accident in r131201, but triggers an assert.
That patch added an exception to allow conversion from pointers to
narrow integral types for MSVC compatibility. However, a pointer can
already be converted to bool in a civilized manner; allowing conversion
via reinterpret_cast is a bad idea.

Fixes PR16222.

llvm-svn: 183394
2013-06-06 09:16:36 +00:00
Richard Smith ea4ad5d841 When a static storage duration temporary appears in a constant expression, it
must be initialized by a constant expression (not just a core constant
expression), because we're going to emit it as a global. Core issue for this is
pending.

llvm-svn: 183388
2013-06-06 08:19:16 +00:00
Richard Smith e6c0144208 Model temporary lifetime-extension explicitly in the AST. Use this model to
handle temporaries which have been lifetime-extended to static storage duration
within constant expressions. This correctly handles nested lifetime extension
(through reference members of aggregates in aggregate initializers) but
non-constant-expression emission hasn't yet been updated to do the same.

llvm-svn: 183283
2013-06-05 00:46:14 +00:00
David Blaikie 6df859d859 Bound member function diagnostic - suggest no-args calls and note overload candidates
Still missing cases for templates, but this is a step in the right
direction. Also omits suggestions that would be ambiguous (eg: void
func(int = 0); + void func(float = 0); func;)

llvm-svn: 183173
2013-06-04 00:28:46 +00:00
David Blaikie 778627a010 UnresolvedMemberExpr should have an expr location of the member (not the base)
This matches the behavior of MemberExpr and makes diagnostics such as
"reference to non-static member function must be called" more legible in
the case that the base & member are split over multiple lines (prior to
this change the diagnostic would point to the base, not the member -
making it very unclear in chained multi-line builder-style calls)

llvm-svn: 183149
2013-06-03 19:46:44 +00:00
Richard Smith 844010455d Refactor constant expression evaluation to associate the complete object of a
materialized temporary with the corresponding MaterializeTemporaryExpr. This is
groundwork for providing C++11's guaranteed static initialization for global
references bound to lifetime-extended temporaries (if the initialization is a
constant expression).

In passing, fix a couple of bugs where some evaluation failures didn't trigger
diagnostics, and a rejects-valid where potential constant expression testing
would assume that it knew the dynamic type of *this and would reject programs
which relied on it being some derived type.

llvm-svn: 183093
2013-06-03 05:03:02 +00:00
Richard Smith 2fcb73984a Fix a couple of bugs where jump diagnostics would not notice that a variable
has an initializer.

llvm-svn: 183092
2013-06-03 01:05:37 +00:00
David Majnemer a9d4f77eb9 Allow paren casted throw statements inside of ternary expressions
clang would incorrectly not allow the following:

int x = true ? (throw 1) : 2;

The problem exists because we don't see beyond the parens.
This, in turn, causes us to believe that we are choosing between void
and int which we diagnose as an error.

Instead, allow clang to see the 'throw' inside the parens.

llvm-svn: 183085
2013-06-02 08:40:42 +00:00
David Majnemer 36bc703e03 Put the PR16167 tests together
llvm-svn: 183046
2013-05-31 21:29:50 +00:00
Richard Smith 72752e88ef Fix handling of braced-init-list as reference initializer within aggregate
initialization. Previously we would incorrectly require an extra set of braces
around such initializers.

llvm-svn: 182983
2013-05-31 02:56:17 +00:00
Rafael Espindola 503276be05 Fix PR16060.
The testcase in PR16060 points out that while template arguments can
show that a type is not externally visible, the standards still says
they have external linkage.

In terms of our implementation, it means that we should merge just the
isExternallyVisible bit, not the formal linkage.

llvm-svn: 182962
2013-05-30 21:23:15 +00:00
Aaron Ballman ed0ae1d70b Microsoft has a language extension which allows union members to be
references.  What's more, they use this language extension in their
ATL header files (which come as part of MFC and the Win32 SDK).  This patch implements support for the Microsoft extension, and addresses PR13737.

llvm-svn: 182936
2013-05-30 16:20:00 +00:00
Aaron Ballman 194a79e152 Switching the tests to use size_t instead of unsigned int to hopefully appease the Linux x64 build bot (take 2, forgot this test case).
llvm-svn: 182907
2013-05-30 02:17:14 +00:00
Aaron Ballman 324fbeeba7 Add support to fallback on operator new when a placement operator new[] is called for which there is no valid declaration. This fallback only happens in Microsoft compatibility mode. This patch addresses PR13164, and improves support for the WDK.
llvm-svn: 182905
2013-05-30 01:55:39 +00:00
David Majnemer 970f30e248 Add another test case for r182814.
llvm-svn: 182882
2013-05-29 21:09:52 +00:00
David Majnemer 0ffa331789 Disallow extern decls of type void in C++ mode
C++ and C differ with respect to the handling of extern void
declarations. Enforce the C++ behavior in C++ mode.

llvm-svn: 182814
2013-05-29 00:56:45 +00:00
Rafael Espindola 50df3a02be Fix linkage computation for derived types in inline functions.
John noticed that the fix for pr15930 (r181981) didn't handle indirect
uses of local types. For example, a pointer to local struct, or a
function that returns it.

One way to implement this would be to recursively look for local
types. This would look a lot like the linkage computation itself for
types.

To avoid code duplication and utilize the existing linkage cache, this
patch just makes the computation of "type with no linkage but
externally visible because it is from an inline function"  part of the
linkage computation itself.

llvm-svn: 182711
2013-05-25 17:16:20 +00:00
Rafael Espindola 6f6f3c4e38 Fix printing CXXTemporaryObjectExpr with default args.
Patch by Will Wilson.

llvm-svn: 182651
2013-05-24 16:11:44 +00:00
Richard Smith cd09065ec3 Fix crash-on-invalid if list-initialization works, but we bail out when
building the resulting expression because it invokes a deleted constructor.

llvm-svn: 182624
2013-05-23 23:20:04 +00:00
Richard Smith a23ab514c2 PR14772: Support constant expression evaluation for _Atomic types.
* Treat _Atomic(T) as a literal type if T is a literal type.
 * Evaluate expressions of this type properly.
 * Fix a lurking bug where we built completely bogus ASTs for converting to
   _Atomic types in C++ in some cases, caught by the tests for this change.

llvm-svn: 182541
2013-05-23 00:30:41 +00:00
Richard Smith f9a458047a PR16090: C++1y: treat undeduced 'auto' as a literal type, so that constexpr
function templates can use it as a return type.

llvm-svn: 182433
2013-05-21 22:29:20 +00:00
Richard Smith ccc1181105 Refactor places which perform contextual implicit conversions to go through a
common function. The C++1y contextual implicit conversion rules themselves are
not yet implemented, however.

This also fixes a subtle bug where template instantiation context notes were
dropped for diagnostics coming from conversions for integral constant
expressions -- we were implicitly slicing a SemaDiagnosticBuilder into a
DiagnosticBuilder when producing these diagnostics, and losing their context
notes in the process.

llvm-svn: 182406
2013-05-21 19:05:48 +00:00
Peter Collingbourne b289fe64c1 [ms-cxxabi] Look up operator delete() at every virtual dtor declaration.
While the C++ standard requires that this lookup take place only at the
definition point of a virtual destructor (C++11 [class.dtor]p12), the
Microsoft ABI may require the compiler to emit a deleting destructor
for any virtual destructor declared in the TU, including ones without
a body, requiring an operator delete() lookup for every virtual
destructor declaration.  The result of the lookup should be the same
no matter which declaration is used (except in weird corner cases).

This change will cause us to reject some valid TUs in Microsoft ABI
mode, e.g.:

struct A {
  void operator delete(void *);
};

struct B {
  void operator delete(void *);
};

struct C : A, B {
  virtual ~C();
};

As Richard points out, every virtual function declared in a TU
(including this virtual destructor) is odr-used, so it must be defined
in any program which declares it, or the program is ill formed, no
diagnostic required.  Because we know that any definition of this
destructor will cause the lookup to fail, the compiler can choose to
issue a diagnostic here.

Differential Revision: http://llvm-reviews.chandlerc.com/D822

llvm-svn: 182270
2013-05-20 14:12:25 +00:00
Reid Kleckner b144d36693 Implement __declspec(selectany) under -fms-extensions
selectany only applies to externally visible global variables.  It has
the effect of making the data weak_odr.

The MSDN docs suggest that unused definitions can only be dropped at
linktime, so Clang uses weak instead of linkonce.  MSVC optimizes away
references to constant selectany data, so it must assume that there is
only one definition, hence weak_odr.

Reviewers: espindola

Differential Revision: http://llvm-reviews.chandlerc.com/D814

llvm-svn: 182266
2013-05-20 14:02:37 +00:00
DeLesley Hutchins b682431775 Thread safety analysis: add two new attributes to the thread safety analysis:
assert_exclusive_lock and assert_shared_lock.  These attributes are used to
mark functions that dynamically check (i.e. assert) that a lock is held.

llvm-svn: 182170
2013-05-17 23:02:59 +00:00
Richard Smith 1239d84f77 Use 'c++' not 'cxx' in these diagnostic group names for consistency.
llvm-svn: 182075
2013-05-17 03:11:25 +00:00
Richard Smith 4c163a093f PR15757: When we instantiate an inheriting constructor template, also
instantiate the inherited constructor template and mark that as the constructor
which the instantiated specialization is inheriting. This fixes a
crash-on-valid when trying to compute the exception specification of a
specialization of the inheriting constructor.

llvm-svn: 182072
2013-05-17 02:19:35 +00:00
Richard Smith a3ee78df28 Since we're counting number of steps, switch to turing machines which maximize
#steps not #1s, and use a more traditional step count where the 'halt' step is
not counted.

llvm-svn: 182057
2013-05-16 22:18:32 +00:00
Hans Wennborg 8f62c5ca22 Better diagnostics for string initialization.
This commit improves Clang's diagnostics for string initialization.
Where it would previously say:

  /tmp/a.c:3:9: error: array initializer must be an initializer list
  wchar_t s[] = "Hi";
          ^
  /tmp/a.c:4:6: error: array initializer must be an initializer list or string literal
  char t[] = L"Hi";
       ^

It will now say

  /tmp/a.c:3:9: error: initializing wide char array with non-wide string literal
  wchar_t s[] = "Hi";
          ^
  /tmp/a.c:4:6: error: initializing char array with wide string literal
  char t[] = L"Hi";
       ^

As a bonus, it also fixes the fact that Clang would previously reject
this valid C11 code:

  char16_t s[] = u"hi";
  char32_t t[] = U"hi";

because it would only recognize the built-in types for char16_t and
char32_t, which do not exist in C.

llvm-svn: 181880
2013-05-15 11:03:04 +00:00
David Blaikie 7d17010db5 Use only explicit bool conversion operator
The most common (non-buggy) case are where such objects are used as
return expressions in bool-returning functions or as boolean function
arguments. In those cases I've used (& added if necessary) a named
function to provide the equivalent (or sometimes negative, depending on
convenient wording) test.

DiagnosticBuilder kept its implicit conversion operator owing to the
prevalent use of it in return statements.

One bug was found in ExprConstant.cpp involving a comparison of two
PointerUnions (PointerUnion did not previously have an operator==, so
instead both operands were converted to bool & then compared). A test
is included in test/SemaCXX/constant-expression-cxx1y.cpp for the fix
(adding operator== to PointerUnion in LLVM).

llvm-svn: 181869
2013-05-15 07:37:26 +00:00
Douglas Gregor 230826cc42 Don't mark a type specifier as "owned" if there is no declaration to own.
This simplifies error recovery elsewhere, eliminating the crash in
<rdar://problem/13853540>.

llvm-svn: 181846
2013-05-14 23:22:32 +00:00
Richard Smith 0838f3a1f2 Suppress bogus "use of undefined constexpr function" error if the function body
was erroneous and got discarded.

llvm-svn: 181758
2013-05-14 05:18:44 +00:00
Richard Smith 496ddcfba9 C++1y: support for 'switch' statements in constexpr functions. This is somewhat
inefficient; we perform a linear scan of switch labels to find the one matching
the condition, and then walk the body looking for that label. Both parts should
be straightforward to optimize.

llvm-svn: 181671
2013-05-12 17:32:42 +00:00
Enea Zaffanella 28f36ba693 Avoid patching storage class for block scope thread_local variables.
llvm-svn: 181627
2013-05-10 20:34:44 +00:00
Richard Smith b8a98241fc PR15966: don't get confused by a complex integer -> complex integer conversion
and misclassify it as a complex-real conversion.

llvm-svn: 181626
2013-05-10 20:29:50 +00:00
Hans Wennborg 0d81e01916 Add support for __wchar_t in -fms-extensions mode.
MSVC provides __wchar_t. This is the same as the built-in wchar_t type
from C++, but it is also available with -fno-wchar and in C.

The commit changes ASTContext to have two different types for this:

  - WCharTy is the built-in type used for wchar_t in C++ and __wchar_t.

  - WideCharTy is the type of a wide character literal. In C++ this is
    the same as WCharTy, and in C  it is an integer type compatible with
    the type in <stddef.h>.

This fixes PR15815.

llvm-svn: 181587
2013-05-10 10:08:40 +00:00
Richard Smith 7500ab2464 C++1y auto return type: when a function contains no 'return' statements at all,
substitute 'void' into the return type rather than replacing it with 'void', so
that we maintain the 'auto' type sugar.

llvm-svn: 181584
2013-05-10 04:31:10 +00:00
Richard Smith 220dd33446 Add test forgotten in r181388.
llvm-svn: 181389
2013-05-08 02:38:36 +00:00
Richard Smith 861b5b5aed C++1y constant expression evaluation: compound assignment support for floating-point and pointer types.
llvm-svn: 181376
2013-05-07 23:34:45 +00:00