Commit Graph

496 Commits

Author SHA1 Message Date
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
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
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
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
Douglas Gregor 86325ad2b5 Allow C99 hexfloats in C++0x mode. This change resolves the standards
collision between C99 hexfloats and C++0x user-defined literals by
giving C99 hexfloats precedence. Also, warning about user-defined
literals that conflict with hexfloats and those that have names that
are reserved by the implementation. Fixes <rdar://problem/9940194>.

llvm-svn: 138839
2011-08-30 22:40:35 +00:00
Francois Pichet f2fb411d4a Add support for Microsoft __ptr32 keyword.
Patch by Chris Cudmore!

llvm-svn: 138533
2011-08-25 00:36:46 +00:00
Chandler Carruth 2b949c2b4b Remove the last FIXMEs on -Wunused-comparison since it got moved to
entirely use the existing -Wunused-value infrastructure. This also fixes
a few missed cases for -Wunused in general.

llvm-svn: 137916
2011-08-18 02:04:29 +00:00
Douglas Gregor db0b9f1264 Parsing of C++0x lambda expressions, from John Freeman with help from
David Blaikie!

llvm-svn: 136876
2011-08-04 15:30:47 +00:00
Douglas Gregor 5e6fcb108f This patch makes the string/character literal tests run in C,
C++98/03, and C++0x mode, from Craig Topper!

llvm-svn: 136443
2011-07-29 01:08:54 +00:00
Douglas Gregor fb65e592e0 Add support for C++0x unicode string and character literals, from Craig Topper!
llvm-svn: 136210
2011-07-27 05:40:30 +00:00
Joerg Sonnenberger 869f0b70d4 PR10392: "#pragma GCC visibility" must not expand macros in its
arguments.

llvm-svn: 135552
2011-07-20 01:03:50 +00:00
Francois Pichet 4ad2a27065 Change __debugbreak signature to void __debugbreak(void); MSVC compatibility.
llvm-svn: 134869
2011-07-10 14:15:07 +00:00
Argyrios Kyrtzidis 41fb2d95a3 Make the Preprocessor more memory efficient and improve macro instantiation diagnostics.
When a macro instantiation occurs, reserve a SLocEntry chunk with length the
full length of the macro definition source. Set the spelling location of this chunk
to point to the start of the macro definition and any tokens that are lexed directly
from the macro definition will get a location from this chunk with the appropriate offset.

For any tokens that come from argument expansion, '##' paste operator, etc. have their
instantiation location point at the appropriate place in the instantiated macro definition
(the argument identifier and the '##' token respectively).
This improves macro instantiation diagnostics:

Before:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

After:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:3:20: note: instantiated from:
\#define M(op) (foo op 3);
                ~~~ ^  ~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

The memory savings for a candidate boost library that abuses the preprocessor are:

- 32% less SLocEntries (37M -> 25M)
- 30% reduction in PCH file size (900M -> 635M)
- 50% reduction in memory usage for the SLocEntry table (1.6G -> 800M)

llvm-svn: 134587
2011-07-07 03:40:34 +00:00
Richard Trieu 94942b32a3 For code such as:
int f(int x) {
  if (int foo = f(bar)) {}
  return 0;
}

Clang produces the following error messages:

paren_imbalance.cc:2:19: error: use of undeclared identifier 'bar'
  if (int foo = f(bar)) {}
                  ^
paren_imbalance.cc:2:26: error: expected ')'
  if (int foo = f(bar)) {}
                        ^
paren_imbalance.cc:2:6: note: to match this '('
  if (int foo = f(bar)) {}
     ^

The second error is incorrect.  This patch will stop Clang from producing an error on parenthesis imbalance during error recovery when there isn't one.

llvm-svn: 134258
2011-07-01 20:54:02 +00:00
Argyrios Kyrtzidis 2cfce18645 Allow Lexer::getLocForEndOfToken to return the location just passed the macro instantiation
if the location given points at the last token of the macro instantiation.

Fixes rdar://9045701.

llvm-svn: 133804
2011-06-24 17:58:59 +00:00
David Majnemer 0ac67fa22f Improve the diagnostics generated for switch statements missing expressions
- Move the diagnostic to the case statement instead of at the end of the switch
- Add a fix-it hint as to how to fix the compilation error

llvm-svn: 132903
2011-06-13 05:50:12 +00:00
Richard Smith 938f40b5aa Implement support for C++11 in-class initialization of non-static data members.
llvm-svn: 132878
2011-06-11 17:19:42 +00:00
Peter Collingbourne 23f1bee3c0 Modify a diagnostic introduced in r132612 to emit QualTypes directly
This fixes a memory error on FreeBSD (and is the right thing to do
in any case).

llvm-svn: 132750
2011-06-08 15:15:17 +00:00
Tanya Lattner 55808c1026 Add support for builtin astype:
__builtin_astype(): Used to reinterpreted as another data type of the same size using for both scalar and vector data types.
Added test case.

llvm-svn: 132612
2011-06-04 00:47:47 +00:00
Richard Trieu 61384cb8bd Add a fix-it and better error recovery for improperly nested namespaces. This will give a better error message for cases such as "namespace foo::bar::baz {}" and a suggested fix-it of "namespace foo { namespace bar { namespace baz {} } }"
llvm-svn: 132138
2011-05-26 20:11:09 +00:00
Francois Pichet 8f981d5964 Add support for Microsoft __if_exists, __if_not_exists extension at class scope.
Example:

typedef int TYPE;
class C {
  __if_exists(TYPE) {
     TYPE a;
  }
  __if_not_exists(TYPE) {
     this will never be parsed.
  }
};

llvm-svn: 132052
2011-05-25 10:19:49 +00:00
Alexis Hunt 94f9cbf998 Implement a few basic tests for defaulted and deleted functions.
More comprehensive testing once copy {constructors,assignment operators}
can be defaulted.

llvm-svn: 131275
2011-05-13 01:01:05 +00:00
Francois Pichet 3abc9b8b79 In Microsoft mode, allow pure specifier (=0) on inline functions declared at class scope.
This removes 2 errors when parsing MFC code with clang

Example:
class A {
    virtual void f() = 0 { }
}

llvm-svn: 131175
2011-05-11 02:14:46 +00:00
Douglas Gregor 932aac6492 Tweak the diagnostics for the C++0x extensions to friend types to note
that they are C++0x extensions, and put them in the appropriate
group. We already support most of the semantics. Addresses
<rdar://problem/9407525>.

llvm-svn: 131153
2011-05-10 21:23:31 +00:00
Francois Pichet 2f019ed2e6 Add a __uuidof test where the uuid attribute is on the second declaration.
Also some -fdelayed-template-parsing test refactoring.

llvm-svn: 131113
2011-05-10 00:08:32 +00:00
Francois Pichet 61d818c058 Temporary preprocessor hack to get around the Microsoft __identifier(x) extension.
http://msdn.microsoft.com/en-us/library/hzc8ytsz(v=VS.100).aspx

Microsoft doc claims this is a C++/CLI feature but it is really always enabled.
This removes 2 error when parsing MFC code with clang.

llvm-svn: 131051
2011-05-07 17:47:38 +00:00
Francois Pichet a5b3fcbc02 Add support for _if_exists and __if_not_exists at namespace/global scope.
llvm-svn: 131050
2011-05-07 17:30:27 +00:00
Francois Pichet 4a7de3eb2c Add support for Microsoft __if_exists and __if_not_exists construct inside function definition.
Allow to include or exclude code depending on if a symbol exists or not. Just like a #ifdef but for C/C++ symbols.

More doc: http://msdn.microsoft.com/en-us/library/x7wy9xh3(v=VS.100).aspx

Support at class and namespace scopes will be added later.

llvm-svn: 131014
2011-05-06 20:48:22 +00:00
Francois Pichet c867975776 r130381 follow up: accept __uuidof expression for template argument reference.
llvm-svn: 130491
2011-04-29 09:08:14 +00:00
Francois Pichet a1c1352a36 Support &__uuidof(type) as a non type template argument.
This idiom is used everywhere in MFC/COM code and as such this patch removes hundreds of errors when parsing MFC code with clang.

Example: 
template <class T, const GUID* g = &__uuidof(T)>
class ComTemplate  { };

typedef ComTemplate<struct_with_uuid, &__uuidof(struct_with_uuid)> COM_TYPE;

Of course this is just parsing support. Trying to use this in CodeGen will generate:
error: cannot yet mangle expression type CXXUuidofExpr

llvm-svn: 130381
2011-04-28 04:39:50 +00:00
Francois Pichet 84133e41be Upgrade Microsoft's __int8, __int16, __int32 and __int64 types from builtin defines to real types.
Otherwise statements like:
  __int64 var = __int64(0);

would be expanded to:
  long long var = long long(0);

and fail to compile.

llvm-svn: 130369
2011-04-28 01:59:37 +00:00
Francois Pichet 33477fdfd5 Add support for Microsoft __interface keyword. An __interface class is basically a normal class containing just pure virtual functions. No urgency to enforce that restriction in clang for now, so make __interface an "class" alias.
llvm-svn: 130290
2011-04-27 05:07:51 +00:00
Chandler Carruth bc0f9aeac3 Remove some more hard CR-LF lines. These were particularly weird as they were
only a few lines of the file. Also set their properties to have explicitly
native eol sytle.

llvm-svn: 130124
2011-04-25 07:09:43 +00:00
Chandler Carruth 03b77b37d6 Remove hard coded dos line endings, let subversion translate them on
update.

Despite the diff, nothing but line endings changed here.

llvm-svn: 130121
2011-04-25 06:34:35 +00:00
Francois Pichet dd876125df Downgrade unnecessary "typename" from error to warning in Microsoft mode.
This fixes 1 error when parsing MSVC 2008 headers with clang. 

Must "return true;" even if it is a warning because the rest of the code path assumes that SS is set to something. The parser will get back on its feet and continue parsing the rest of the declaration correctly so it is not a problem.

llvm-svn: 130088
2011-04-24 11:24:13 +00:00
Francois Pichet dcb3ebeb2c Correctly emit a diagnostic for multiple templated function definitions in -flate-template-parsing mode.
llvm-svn: 130030
2011-04-22 23:20:44 +00:00
Francois Pichet 1c229c0472 Add -fdelayed-template-parsing option. Using this option all templated function definitions are parsed at the end of the translation unit only if it is required by an actual instantiation. As such all the symbols of the TU are available during name lookup.
Using this flag is necessary for compatibility with Microsoft template code.
This also provides some parsing speed improvement.

llvm-svn: 130022
2011-04-22 22:18:13 +00:00
Fariborz Jahanian c057794adb Fixes an instance method meta-data generation bug in
ObjC NeXt runtime where method pointer registered in
metadata belongs to an unrelated method. Ast part of this fix,
I turned at @end missing warning (for class
implementations) into an error as we can never
be sure that meta-data being generated is correct.
// rdar://9072317

llvm-svn: 130019
2011-04-22 22:02:28 +00:00
Richard Trieu 2c850c0980 Add a fixit suggest for missing case keywords inside a switch scope. For instance, in the following code, 'case ' will be suggested before the '1:'
switch (x) {
  1: return 0;
  default: return 1;
}

llvm-svn: 129943
2011-04-21 21:44:26 +00:00
Fariborz Jahanian 2b059998f7 Avoid superfluous warning after an error is detcted and reported.
// rdar://9132143

llvm-svn: 129822
2011-04-19 21:42:37 +00:00
Peter Collingbourne 9114759641 C1X: implement generic selections
As an extension, generic selection support has been added for all
supported languages.  The syntax is the same as for C1X.

llvm-svn: 129554
2011-04-15 00:35:48 +00:00
Douglas Gregor 6ca6410e3a If the declaration of a C++ member function with an inline definition
is so broken that Sema can't form a declaration for it, don't bother
trying to parse the definition later. Fixes <rdar://problem/9221993>.

llvm-svn: 129547
2011-04-14 23:19:27 +00:00
Richard Smith 55858499e2 Detect when the string "<::" is found in code after a cast or template name and is interpreted as "[:" because of the digraph "<:". When found, give an error with a fix-it to add whitespace between the "<" and "::".
Patch by Richard Trieu! Plus a small tweak from me to deal with one of the tokens coming from a macro.

llvm-svn: 129540
2011-04-14 21:45:45 +00:00
Douglas Gregor 23c8476748 Parse an '@' in an Objective-C++ class member specification,
diagnosing it as an error rather than looping infinitely. Also,
explicitly disallow @defs in Objective-C++. Fixes <rdar://problem/9260136>.

llvm-svn: 129521
2011-04-14 17:21:19 +00:00
John McCall c5e6b97523 Diagnose a missing ')' on what looks like a statement expression.
A situation where we can get an invalid ExprResult without an error.
Fixes PR8394.  Patch by Justin Bogner!

llvm-svn: 128979
2011-04-06 02:35:25 +00:00
Francois Pichet 4e7a2c09b2 Improve recovery (error + fix-it) when parsing type dependent template name without the "template" keyword.
For example:
   typename C1<T>:: /*template*/ Iterator<0> pos; 

Also the error is downgraded to an ExtWarn in Microsoft mode.

llvm-svn: 128387
2011-03-27 19:41:34 +00:00
Chris Lattner 85222c6b2f fix the second part of rdar://8366474 - clang fails to parse ObjC selectors with '::', when :: isn't the first part of the selector.
llvm-svn: 128344
2011-03-26 18:11:38 +00:00
Douglas Gregor 7bf3fbe6e1 Add a __has_feature check for the 'availability' attribute
llvm-svn: 128337
2011-03-26 12:16:15 +00:00
Douglas Gregor 7ab142b55a Extend the new 'availability' attribute with support for an
'unavailable' argument, which specifies that the declaration to which
the attribute appertains is unavailable on that platform.

llvm-svn: 128329
2011-03-26 03:35:55 +00:00
John McCall 405988b97c Fix the recovery from missing semis on @property declarations to not consume
the following '@'.  Conceivably, we could skip tokens until something that
can validly start an @interface declaration here, but it's not clear that
it matters.

llvm-svn: 128325
2011-03-26 01:53:26 +00:00