Commit Graph

11906 Commits

Author SHA1 Message Date
Sebastian Redl a74948d347 Correctly parse braced member initializers (even in delayed parsing) and correctly pass
the information on to Sema. There's still an incorrectness in the way template instantiation
works now, but that is due to a far larger underlying representational problem.
Also add a test case for various list initialization cases of scalars, which test this
commit as well as the previous one.

llvm-svn: 140460
2011-09-24 17:48:25 +00:00
Sebastian Redl 12757ab4cb Treat list-initialization of scalars as a first-class citizen in C++11.
Allow empty initializer lists for scalars, which mean value-initialization.
Constant evaluation for single-element and empty initializer lists for scalars.
Codegen for empty initializer lists for scalars.
Test case comes in next commit.

llvm-svn: 140459
2011-09-24 17:48:14 +00:00
Sebastian Redl 46975ea682 Fix the expected error for narrowing conversions in generalized-initializers.cpp to
match what the actual implementation of the error looks like.

llvm-svn: 140458
2011-09-24 17:48:06 +00:00
Francois Pichet d8e4e41301 [microsoft] In Microsoft mode, if we are inside a template class member function and we can't resolve an identifier then assume the identifier is type dependent. The goal is to postpone name lookup to instantiation time to be able to search into type dependent base classes.
This fixes a few errors when parsing MFC code with clang.
BTW clang trunk is now about 5 patches away to be able the parse the default wizard-generated MFC project.

llvm-svn: 140452
2011-09-24 10:38:05 +00:00
Fariborz Jahanian 11ee283e2a objc - redeclaration of property in extension class
must match property type declaration in its
primary class. // rdar://10142679

llvm-svn: 140438
2011-09-24 00:56:59 +00:00
Fariborz Jahanian 44653709fd objc - fixes a crash when undefined typed property
followed by it implementation crashes when attempt
is made to access the synthesized ivar. 
// rdar://10177744

llvm-svn: 140432
2011-09-23 23:11:38 +00:00
Matt Beaumont-Gay d0457924e3 Fix a crash-on-invalid.
The token stream was not getting properly reset when leaving
ParseLexedMethodDef in some error cases. In the testcase, that caused later
accesses to the token stream to touch memory which had been freed as we
finished parsing the class definition. Major hat-tip to AddressSanitizer for
helping pinpoint the use-after-free, including the allocation and deallocation
points:

==21510== ERROR: AddressSanitizer heap-use-after-free on address 0x7feb3de87848 at pc 0x249f4e2 bp 0x7fff15a89df0 sp 0x7fff15a89ce0
READ of size 1 at 0x7feb3de87848 thread T0
  #0 0x249f4e2 clang::TokenLexer::Lex()
  #1 0x1c834a0 clang::Parser::ConsumeToken()
  #2 0x1c7dc0f clang::Parser::ParseDeclarationOrFunctionDefinition()
  #3 0x1c7e16b clang::Parser::ParseDeclarationOrFunctionDefinition()
<snip>
0x7feb3de87848 is located 1992 bytes inside of 3816-byte region [0x7feb3de87080,0x7feb3de87f68)
freed by thread T0 here:
  #0 0x3a22c19 free
  #1 0x1d136a1 clang::Parser::LexedMethod::~LexedMethod()
  #2 0x1cef528 clang::Parser::DeallocateParsedClasses()
  #3 0x1cef676 clang::Parser::PopParsingClass()
  #4 0x1cea094 clang::Parser::ParseCXXMemberSpecification()
  #5 0x1ce7ae5 clang::Parser::ParseClassSpecifier()
  #6 0x1cfe588 clang::Parser::ParseDeclarationSpecifiers()
  #7 0x1c7dbe8 clang::Parser::ParseDeclarationOrFunctionDefinition()
  #8 0x1c7e16b clang::Parser::ParseDeclarationOrFunctionDefinition()
<snip>
previously allocated by thread T0 here:
  #0 0x3a2302d realloc
  #1 0x39d7c97 llvm::SmallVectorBase::grow_pod()
  #2 0x1ac588e llvm::SmallVectorImpl<>::push_back()
  #3 0x1d12d8b clang::Parser::ConsumeAndStoreUntil()
  #4 0x1c9c24d clang::Parser::ConsumeAndStoreUntil()
  #5 0x1d12c1e clang::Parser::ConsumeAndStoreUntil()
  #6 0x1c9c24d clang::Parser::ConsumeAndStoreUntil()
  #7 0x1d10042 clang::Parser::ParseCXXInlineMethodDef()
  #8 0x1cec51a clang::Parser::ParseCXXClassMemberDeclaration()
  #9 0x1ce9de5 clang::Parser::ParseCXXMemberSpecification()
  #10 0x1ce7ae5 clang::Parser::ParseClassSpecifier()
  #11 0x1cfe588 clang::Parser::ParseDeclarationSpecifiers()
  #12 0x1c7dbe8 clang::Parser::ParseDeclarationOrFunctionDefinition()
  #13 0x1c7e16b clang::Parser::ParseDeclarationOrFunctionDefinition()
<snip>

llvm-svn: 140427
2011-09-23 22:39:23 +00:00
Matt Beaumont-Gay c9229a71ac Add DiagGroups to a couple of warnings.
llvm-svn: 140411
2011-09-23 20:56:58 +00:00
Daniel Dunbar db086f93dd Driver: Test case that was supposed to go with previous commit.
llvm-svn: 140410
2011-09-23 20:35:31 +00:00
Douglas Gregor 83dea558bc Add a test triple. Who knew that all the world wasn't darwin?
llvm-svn: 140408
2011-09-23 20:28:32 +00:00
Douglas Gregor b1fa148837 Don't propagate the 'availability' attribute through declaration
merging for overrides. One might want to make a method's availability
in a superclass different from that of its subclass. Fixes
<rdar://problem/10166223>.

llvm-svn: 140406
2011-09-23 20:23:42 +00:00
Richard Trieu 021baa373f Add a new warning to -Wliteral-conversion to catch cases where a string literal
is cast to a boolean.  An exception has been made for string literals in
logical expressions to allow the common case of use in assert statements.

bool x;
x = "hi";  // Warn here
void foo(bool x);
foo("hi");  // Warn here
assert(0 && "error");
assert("error);  // Warn here

llvm-svn: 140405
2011-09-23 20:10:00 +00:00
Douglas Gregor 0c254a00c1 Clean up parsing the category names in interfaces slightly, using
MatchRHSPunctuation appropriately and giving a useful source location
for the complaint about attributes being added to a category.

llvm-svn: 140404
2011-09-23 19:19:41 +00:00
Douglas Gregor 34bc6e5ee4 When checking for weak vtables, check whether the actual definition of
the key function is inline, rather than the original
declaration. Perhaps FunctionDecl::isInlined() is poorly named. Fixes
<rdar://problem/9979458>. 

llvm-svn: 140400
2011-09-23 19:04:03 +00:00
Fariborz Jahanian c367b8f8cc objc-gc: Fix a corner case where clang fails to generate GC
write barrier with captured pointer to object. // rdar://10150823

llvm-svn: 140399
2011-09-23 18:57:30 +00:00
Benjamin Kramer 559865c89d Reenable -cxx-isystem for Objective C++, until I come up with a better solution
llvm-svn: 140365
2011-09-23 02:25:14 +00:00
Douglas Gregor 5223529b27 Don't finalize checking of base and member initializers for a
constructor template. Fixes PR10457.

llvm-svn: 140350
2011-09-22 23:04:35 +00:00
Francois Pichet 8134518331 [microsoft] Fix a bug in -fdelayed-template-parsing mode where we were not reentering the delayed function context correctly. The problem was that all template params were reintroduced inside the same scope. So if we had a situation where we had 2 template params with the same name at different scope then clang would generate an error about ambiguous name.
The solution is to create a new ParseScope(Scope::TemplateParamScope) for each template scope that we want to reenter. (from the outmost to the innermost scope)

This fixes some errors when parsing MFC code with clang.

llvm-svn: 140344
2011-09-22 22:14:56 +00:00
Benjamin Kramer dcae044a10 Don't test unix path seperators, that will fail on windows.
llvm-svn: 140343
2011-09-22 22:14:48 +00:00
Benjamin Kramer e3faaaba79 See if going through env pacifies the windows buildbots.
llvm-svn: 140342
2011-09-22 22:08:09 +00:00
Benjamin Kramer 8404eb0bad Add support for CPATH and friends.
This moves the existing code for CPATH into the driver and adds the environment lookup and path splitting there.
The paths are then passed down to cc1 with -I options (CPATH), added after the normal user-specified include dirs.
Language specific paths are passed via -LANG-isystem and the actual filtering is performed in the frontend.

I tried to match GCC's behavior as close as possible

Fixes PR8971.

llvm-svn: 140341
2011-09-22 21:41:16 +00:00
Ted Kremenek 34a1d37ba3 Place diagnostic warn_ivar_use_hidden under the flag -Wshadow-ivar.
llvm-svn: 140329
2011-09-22 19:24:22 +00:00
Douglas Gregor 4ea5dec0e5 Don't allow template argument deduction to deduce a placeholder type,
ever. Fixes PR10939.

llvm-svn: 140304
2011-09-22 15:57:07 +00:00
Douglas Gregor 8a556ce512 Explicitly-defaulted copy/move constructors are not "implicit", but
they still need the logic to cope with array member
initialization. Fixes PR10720.

llvm-svn: 140302
2011-09-22 15:15:51 +00:00
Tobias Grosser 766bcc27dc In OpenCL, conversions between different vector types are disallowed
OpenCL 6.2.1 says: "Implicit conversions between built-in vector data types are
disallowed."  OpenCL 6.2.2 says: "Explicit casts between vector types are not
legal."  For example:

uint4 u = (uint4)(1);
int4 i = u; // invalid implicit conversion
int4 e = (int4)u; // invalid explicit conversion

Fixes PR10967. Submitted by: Anton Lokhmotov <Anton.lokhmotov@gmail.com>

llvm-svn: 140300
2011-09-22 13:03:14 +00:00
Tobias Grosser 0a3a22fe66 In the OpenCL mode, the AltiVec mode must be off and checks must be strict
OpenCL is different from AltiVec in the way it supports vector literals.  OpenCL
is strict with regards to semantic checks.  For example, implicit conversions
and explicit casts between vectors of different types are disallowed.

Fixes PR10975. Submitted by: Anton Lokhmotov <Anton.lokhmotov@gmail.com>

llvm-svn: 140270
2011-09-21 18:28:29 +00:00
Douglas Gregor 7c26c04ba9 Diagnose attempts to write a templated data member, from Stepan
Dyatkovskiy! Fixes PR10896.

llvm-svn: 140250
2011-09-21 14:40:46 +00:00
John McCall 30909031a7 Enforce access control for conversion operators used in contextual
conversions (rather than just call-arguments).

llvm-svn: 140244
2011-09-21 08:36:56 +00:00
John McCall 9cb88ec8d1 I had meant to locally revert this test.
llvm-svn: 140243
2011-09-21 08:34:49 +00:00
John McCall cbc038a6c3 ANSI C requires that a call to an unprototyped function type succeed
if the definition has a non-variadic prototype with compatible
parameters.  Therefore, the default rule for such calls must be to
use a non-variadic convention.  Achieve this by casting the callee to
the function type with which it is required to be compatible, unless
the target specifically opts out and insists that unprototyped calls
should use the variadic rules.  The only case of that I'm aware of is
the x86-64 convention, which passes arguments the same way in both
cases but also sets a small amount of extra information;  here we seek
to maintain compatibility with GCC, which does set this when calling
an unprototyped function.

Addresses PR10810 and PR10713.

llvm-svn: 140241
2011-09-21 08:08:30 +00:00
Francois Pichet 3b4de99158 [microsoft] Move missing typename warning from -fms-extensions to -fms-compatibility. Also allow the missing typename warning at function scope.
llvm-svn: 140240
2011-09-21 07:59:49 +00:00
Anna Zaks 15ca5e7a21 [analyzer] Fix a bug where PathDiagnosticLocation did not generate a valid range and add asserts to check validity of locations early on. Ignore invalid ranges in PathDiagnosticPiece (they could be added by checker writers).
Addresses radar://10124836 and radar://radar10102244.

llvm-svn: 140218
2011-09-21 00:35:58 +00:00
Argyrios Kyrtzidis 712512bb36 [ARC] Allow forming 'id*' in an unevaluated context. Fixes rdar://10148540.
llvm-svn: 140212
2011-09-20 23:49:22 +00:00
Argyrios Kyrtzidis 45e8cf5732 [libclang] When pointing at a macro expansion inside a macro argument,
return a cursor for the inner macro.

llvm-svn: 140207
2011-09-20 23:27:33 +00:00
Francois Pichet b3642c2c7a Move Microsoft access specifier bug emulation from -fms-extensions to -fm-compatibility.
llvm-svn: 140189
2011-09-20 22:08:26 +00:00
Richard Trieu 02e25db543 Fix a problem in digraph handling where "[:" might be treated as "<::" and
erronously trigger the digraph correction fix-it.  Include a new test to catch
this in the future.

llvm-svn: 140175
2011-09-20 20:03:50 +00:00
Eric Christopher 5507159245 Remove __WCHAR_UNSIGNED__ and anything that used it.
llvm-svn: 140155
2011-09-20 18:05:01 +00:00
John McCall a62a666273 Fix a crash-on-invalid with bad CV-qualification on 'this' in the
presence of an implicit move assignment operator.  I think the implicit
copy assignment operator case was also wrong, but just in a "displaying
the wrong diagnostic" way.

llvm-svn: 140139
2011-09-20 06:21:28 +00:00
Chandler Carruth 9a797578dc Fix a pretty nasty bug in noreturn destructors that cascaded into lots
of false positive warnings that depend on noreturn destructors pruning
the CFGs, but only in C++0x mode!

This was really surprising as the debugger quickly reveals that the
attributes are parsed correctly (and using the same code) in both modes.
The warning fires in the same way in both modes. But between parsing and
building the destructor declaration with the noreturn attribute and the
warning, it magically disappears. The key? The 'noexcept' appears!

When we were rebuilding the destructor type with the computed implicit
noexcept we completely dropped the old type on the floor. This almost
makes sense (as the arguments and return type to a destructor aren't
exactly unpredictable), but lost any function type attributes as well.
The fix is simple, we build the new type off of the old one rather than
starting fresh.

Testing this is a bit awkward. I've done it by running the
noreturn-sensitive tests in both modes, which previous failed and now
passes, but if anyone has ideas about how to more specifically and
thoroughly test that the extended info on a destructor is preserved when
adding noexcept, I'm all ears.

llvm-svn: 140138
2011-09-20 04:55:26 +00:00
Eli Friedman 6b9c41ea68 Add list initialization for complex numbers in C. Essentially, this allows "_Complex float x = {1.0f, 2.0f};". See changes to docs/LanguageExtensions.html for a longer description.
<rdar://problem/9397672>.

llvm-svn: 140090
2011-09-19 23:17:44 +00:00
Peter Collingbourne 2dbb708b8a OpenCL: introduce support for function scope __local variables
llvm-svn: 140068
2011-09-19 21:14:35 +00:00
Argyrios Kyrtzidis 7c06d8666b [libclang] When getting a source location from a file:line:col triplet
check whether the requested location points inside the precompiled preamble,
in which case the returned source location will be a "loaded" one.

llvm-svn: 140060
2011-09-19 20:40:35 +00:00
Argyrios Kyrtzidis b4199b659b For SourceManager::isBeforeInTranslationUnit, a location pointing
inside a macro argument should be regarded as coming before
the location of the expanded tokens.

llvm-svn: 140053
2011-09-19 20:39:57 +00:00
Bill Wendling f0724e8e06 Throw the switch to convert clang to the new exception handling model!
This model uses the 'landingpad' instruction, which is pinned to the top of the
landing pad. (A landing pad is defined as the destination of the unwind branch
of an invoke instruction.) All of the information needed to generate the correct
exception handling metadata during code generation is encoded into the
landingpad instruction.

The new 'resume' instruction takes the place of the llvm.eh.resume intrinsic
call. It's lowered in much the same way as the intrinsic is.

llvm-svn: 140049
2011-09-19 20:31:14 +00:00
Richard Trieu 01fc001062 Changes to the name lookup have caused a regression in the digraph fix-it hint.
For instance:

template <class T> void E() {};
class F {};

void test() {
 ::E<::F>();
 E<::F>();
}

Gives the following error messages:

error: found '<::' after a template name which forms the
     digraph '<:' (aka '[') and a ':', did you mean '< ::'?
 ::E<::F>();
    ^~~
    < ::
error: expected expression
 E<::F>();
    ^
error: expected ']'
note: to match this '['
 E<::F>();

This patch adds the digraph fix-it check right before the name lookup,
moves the shared checking code to a new function, and adds new
tests to catch future regressions.

llvm-svn: 140039
2011-09-19 19:01:00 +00:00
Devang Patel 5a54065c4f Tighten check to match an ivar with corresponding property by using ObjCImplementationDecl.
Radar 10139522 - Part 1.

llvm-svn: 140038
2011-09-19 18:54:16 +00:00
Matt Beaumont-Gay dcaacaa190 Fix a QoI bug with overloaded operators inside macros.
We were failing to set source locations and ranges in isUnusedResultAWarning
for CXXOperatorCallExprs, leading to an "expression result unused" warning
with absolutely no context if the expression was inside a macro.

llvm-svn: 140036
2011-09-19 18:51:20 +00:00
John McCall 28a5b326e1 In apple-kext mode, use external linkage for explicit template instantiations
instead of internal linkage.

llvm-svn: 140030
2011-09-19 18:05:26 +00:00
Richard Smith c94ec84a3d In constructors, don't generate implicit initializers for members of anonymous structs contained within anonymous unions.
llvm-svn: 140015
2011-09-19 13:34:43 +00:00
Francois Pichet 39cba5343d Move the "jump bypasses variable initialization" error -> warning downgrade from -fms-extensions to -fms-compatibility.
llvm-svn: 140008
2011-09-18 21:48:27 +00:00