aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex
AgeCommit message (Collapse)AuthorFilesLines
2016-03-06[Modules] Don't swallow errors when parsing optional attributes.Davide Italiano1-3/+8
Differential Revision: http://reviews.llvm.org/D17787 llvm-svn: 262789
2016-03-04Update diagnostics now that hexadecimal literals look likely to be part of ↵Richard Smith2-6/+13
C++17. llvm-svn: 262753
2016-02-26SemaCXX: Support templates in availability attributesDuncan P. N. Exon Smith1-0/+1
If the availability context is `FunctionTemplateDecl`, we should look through it to the `FunctionDecl`. This prevents a diagnostic in the following case: class C __attribute__((unavailable)); template <class T> void foo(C&) __attribute__((unavailable)); This adds tests for availability in templates in many other cases, but that was the only case that failed before this patch. I added a feature `__has_feature(attribute_availability_in_templates)` so users can test for this. rdar://problem/24561029 llvm-svn: 262050
2016-02-24Revert "Don't convert a char to a const char *"David Majnemer1-1/+1
This reverts commit r261780. It turns out the original code was just fine. An overload for ltrim which takes char was added but the Doxygen docs haven't seemed to pick it up. llvm-svn: 261784
2016-02-24Don't convert a char to a const char *David Majnemer1-1/+1
This fixes PR26728. llvm-svn: 261780
2016-02-23PR24667: fix quadratic runtime if textually-included modular headers define ↵Richard Smith2-22/+52
large numbers of macros. llvm-svn: 261705
2016-02-23Lex: Return "" when HeaderMap::lookupFilename failsDuncan P. N. Exon Smith1-13/+24
Change getString() to return Optional<StringRef>, and change lookupFilename() to return an empty string if either one of the prefix and suffix can't be found. This is a more robust follow-up to r261461, but it's still not entirely satisfactory. Ideally we'd report that the header map is corrupt; perhaps something for a follow-up. llvm-svn: 261596
2016-02-22Lex: Check for 0 buckets on header map constructionDuncan P. N. Exon Smith1-5/+5
Switch to using `isPowerOf2_32()` to check whether the buckets are a power of two, and as a side benefit reject loading a header map with no buckets. This is a follow-up to r261448. llvm-svn: 261585
2016-02-22Add has_feature attribute_availability_with_strict.Manman Ren1-0/+1
rdar://23791325 llvm-svn: 261548
2016-02-21Lex: Never overflow the file in HeaderMap::lookupFilename()Duncan P. N. Exon Smith1-5/+11
If a header map file is corrupt, the strings in the string table may not be null-terminated. The logic here previously relied on `MemoryBuffer` always being null-terminated, but this isn't actually guaranteed by the class AFAICT. Moreover, we're seeing a lot of crash traces at calls to `strlen()` inside of `lookupFilename()`, so something is going wrong there. Instead, use `strnlen()` to get the length, and check for corruption. Also remove code paths that could call `StringRef(nullptr)`. r261459 made these rather obvious (although they'd been there all along). llvm-svn: 261461
2016-02-20Lex: Change HeaderMapImpl::getString() to return StringRef, NFCDuncan P. N. Exon Smith1-4/+4
llvm-svn: 261459
2016-02-20Lex: Use dbgs() instead of fprintf() in HeaderMap::dump()Duncan P. N. Exon Smith1-5/+5
This way it's easy to change HeaderMapImpl::getString() to return a StringRef. There's a slight change here, because I used `errs()` instead of `dbgs()`. But `dbgs()` is more appropriate for a dump method. llvm-svn: 261456
2016-02-20Lex: Check whether the header map buffer has space for the bucketsDuncan P. N. Exon Smith1-10/+10
Check up front whether the header map buffer has space for all of its declared buckets. There was already a check in `getBucket()`, but it had UB (comparing pointers that were outside of objects in the error path) and was insufficient (only checking for a single byte of the relevant bucket). I fixed the check, moved it to `checkHeader()`, and left a fixed version behind as an assertion. llvm-svn: 261449
2016-02-20Lex: Check buckets on header map constructionDuncan P. N. Exon Smith1-4/+12
If the number of buckets is not a power of two, immediately recognize the header map as corrupt, rather than waiting for the first lookup. I converted the later check to an assert. llvm-svn: 261448
2016-02-20Lex: Add some unit tests for corrupt header mapsDuncan P. N. Exon Smith1-48/+28
Split the implementation of `HeaderMap` into `HeaderMapImpl` so that we can write unit tests that don't depend on the `FileManager`, and then write a few tests that cover the types of corrupt header maps already detected. This also moves type and constant definitions from HeaderMap.cpp to HeaderMapTypes.h so that the test can access them. llvm-svn: 261446
2016-02-19[modules] Do less scanning of macro definition chains when computing the set ofRichard Smith1-5/+20
exported module macros outside local submodule visibility mode. Related to PR24667. llvm-svn: 261373
2016-02-19[modules] Flatten -fmodule-name= and -fmodule-implementation-of= into a singleRichard Smith4-41/+32
option. Previously these options could both be used to specify that you were compiling the implementation file of a module, with a different set of minor bugs in each case. This change removes -fmodule-implementation-of, and instead tracks a flag to determine whether we're currently building a module. -fmodule-name now behaves the same way that -fmodule-implementation-of previously did. llvm-svn: 261372
2016-02-18Remove use of builtin comma operator.Richard Trieu2-3/+7
Cleanup for upcoming Clang warning -Wcomma. No functionality change intended. llvm-svn: 261271
2016-02-17[OpenCL] Added half type literal with suffix h.Anastasia Stulova1-2/+12
OpenCL Extension v1.2 s9.5 allows half precision floating point type literals with suffices h or H when cl_khr_fp16 is enabled. Example: half x = 1.0h; Patch by Liu Yaxun (Sam)! Differential Revision: http://reviews.llvm.org/D16865 llvm-svn: 261084
2016-02-16Simplify users of StringRef::{l,r}trim (clang) (NFC)Vedant Kumar1-1/+1
r260925 introduced a version of the *trim methods which is preferable when trimming a single kind of character. Update all users in clang. llvm-svn: 260927
2016-02-13Fix use after free.Benjamin Kramer1-1/+1
Found by asan. llvm-svn: 260814
2016-02-13Accept "-Weverything" in clang diagnistic pragmasSunil Srivastava1-4/+13
Differential Revision: http://reviews.llvm.org/D15095 llvm-svn: 260788
2016-02-12Fix remaining Clang-tidy readability-redundant-control-flow warnings; other ↵Eugene Zelenko2-17/+4
minor fixes. Differential revision: http://reviews.llvm.org/D17218 llvm-svn: 260757
2016-02-09PR26349: correctly check whether a digit sequence is empty in the presence ↵Richard Smith1-6/+8
of digit separators. llvm-svn: 260307
2016-02-09Simplify EnterTokenStream API to make it more robust for memory managementDavid Blaikie3-16/+15
While this won't help fix things like the bug that r260219 addressed, it seems like good tidy up to have anyway. (it might be nice if "makeArrayRef" always produced a MutableArrayRef & let it decay to an ArrayRef when needed - then I'd use that for the MutableArrayRefs in this patch) If we had std::dynarray I'd use that instead of unique_ptr+size_t, ideally (but then it'd have to be threaded down through the Preprocessor all the way - no idea how painful that would be) llvm-svn: 260246
2016-02-03[OpenCL] Adding reserved operator logical xor for OpenCLAnastasia Stulova1-0/+3
This patch adds the reserved operator ^^ when compiling for OpenCL (spec v1.1 s6.3.g), which results in a more meaningful error message. Patch by Neil Hickey! Review: http://reviews.llvm.org/D13280 M test/SemaOpenCL/unsupported.cl M include/clang/Basic/TokenKinds.def M include/clang/Basic/DiagnosticParseKinds.td M lib/Basic/OperatorPrecedence.cpp M lib/Lex/Lexer.cpp M lib/Parse/ParseExpr.cpp llvm-svn: 259651
2016-02-01Move LocInfoType from Sema to AST.Benjamin Kramer1-1/+0
While transient and only used during parsing, LocInfoTypes are still used from ASTDumper and are part of the AST. llvm-svn: 259376
2016-01-31[Parser] Update CachedTokens while parsing ObjectiveC template argument listBruno Cardoso Lopes1-0/+26
Consider the following ObjC++ snippet: -- @protocol PA; @protocol PB; @class NSArray<ObjectType>; typedef int some_t; id<PA> FA(NSArray<id<PB>> *h, some_t group); -- This would hit an assertion in the parser after generating an annotation token while trying to update the token cache: Assertion failed: (CachedTokens[CachedLexPos-1].getLastLoc() == Tok.getAnnotationEndLoc() && "The annotation should be until the most recent cached token") ... 7 clang::Preprocessor::AnnotatePreviousCachedTokens(clang::Token const&) + 494 8 clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool, bool, clang::CXXScopeSpec&, bool) + 1163 9 clang::Parser::TryAnnotateTypeOrScopeToken(bool, bool) + 361 10 clang::Parser::isCXXDeclarationSpecifier(clang::Parser::TPResult, bool*) + 598 ... The cached preprocessor token in this case is: greatergreater '>>' Loc=<testcase.mm:7:24> while the annotation ("NSArray<id<PB>>") ends at "testcase.mm:7:25", hence the assertion. Properly update the CachedTokens during template parsing to contain two greater tokens instead of a greatergreater. Differential Revision: http://reviews.llvm.org/D15173 rdar://problem/23494277 llvm-svn: 259311
2016-01-29Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith ↵Yaron Keren3-4/+4
r259192 post commit comment. llvm-svn: 259232
2016-01-28[Lex] Share some common code between decimal and octal parsing in ↵Craig Topper1-61/+47
NumericLiteralParser. There were a couple slight variations between the two copies that I don't believe were intentional. For example, only one of the paths checked for digit separations proceeding a '.', but I think the lexer itself splits the token if a digit separator proceeds a period. llvm-svn: 259022
2016-01-26Remove autoconf supportChris Bieneman1-24/+0
Summary: This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html "This is the way [autoconf] ends Not with a bang but a whimper." -T.S. Eliot Reviewers: chandlerc, grosbach, bob.wilson, echristo Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D16472 llvm-svn: 258862
2016-01-26Fix -Wnull-conversion for long macros.Richard Trieu1-0/+25
Move the function to get a macro name from DiagnosticRenderer.cpp to Lexer.cpp so that other files can use it. Lexer now has two functions to get the immediate macro name, the newly added one is better for diagnostic purposes. Make -Wnull-conversion use this function for better NULL macro detection. llvm-svn: 258778
2016-01-22[MSVC Compat] Accept elided commas in macro function argumentsEhsan Akhgari2-7/+17
Summary: This fixes PR25875. When the trailing comma in a macro argument list is elided, we need to treat it similarly to the case where a variadic macro misses one actual argument. Reviewers: rnk, rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D15670 llvm-svn: 258530
2016-01-19Add -Wexpansion-to-undefined: warn when using `defined` in a macro definition.Nico Weber1-2/+47
[cpp.cond]p4: Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for those macro names modified by the 'defined' unary operator), just as in normal text. If the token 'defined' is generated as a result of this replacement process or use of the 'defined' unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined. This isn't an idle threat, consider this program: #define FOO #define BAR defined(FOO) #if BAR ... #else ... #endif clang and gcc will pick the #if branch while Visual Studio will take the #else branch. Emit a warning about this undefined behavior. One problem is that this also applies to function-like macros. While the example above can be written like #if defined(FOO) && defined(BAR) #defined HAVE_FOO 1 #else #define HAVE_FOO 0 #endif there is no easy way to rewrite a function-like macro like `#define FOO(x) (defined __foo_##x && __foo_##x)`. Function-like macros like this are used in practice, and compilers seem to not have differing behavior in that case. So this a default-on warning only for object-like macros. For function-like macros, it is an extension warning that only shows up with `-pedantic`. (But it's undefined behavior in both cases.) llvm-svn: 258128
2016-01-15When copying whitespace flags from the token naming a macro argument onto theRichard Smith1-0/+1
first token of the expansion, don't forget to copy the "is at the start of a line" token (which is always false, as newlines cannot appear within a macro body); otherwise, stringizing the result can insert spurious whitespace. llvm-svn: 257863
2016-01-12Improve AST dumping:Richard Smith1-1/+18
1) When dumping a declaration that declares a name for a type, also dump the named type. 2) Add a #pragma clang __debug dump X, that dumps the lookup results for X in the current context. llvm-svn: 257529
2016-01-12Module debugging: Make the module format part of the module hash insteadAdrian Prantl1-2/+1
of the file name. This is consistent with how other HeaderSearchOptions are handled. Due to the other inputs of the module hash (revision number) this is not really testable in a meaningful way. llvm-svn: 257520
2016-01-07Properly track that a character literal is UTF-8, and pretty print the ↵Aaron Ballman1-0/+1
prefix properly. llvm-svn: 257097
2015-12-29Emit a -Wmicrosoft warning when treating ^Z as EOF in MS mode.Nico Weber1-1/+4
llvm-svn: 256596
2015-12-29Emit a -Wmicrosoft warning when pasting /##/ into a comment token in MS mode.Nico Weber2-8/+10
llvm-svn: 256595
2015-12-28Refactor: Simplify boolean conditional return statements in lib/LexAlexander Kornienko2-10/+4
Summary: Use clang-tidy to simplify boolean conditional return statements Reviewers: dblaikie Subscribers: dblaikie, cfe-commits Patch by Richard Thomson! Differential Revision: http://reviews.llvm.org/D10017 llvm-svn: 256499
2015-12-18Replace SM.getFileEntryForID(Lexer->getFileID()) with Lexer->getFileEntry().Yaron Keren2-7/+4
llvm-svn: 255993
2015-12-10In Objective-C, ignore attempts to redefine the ARC/GC qualifier macros.John McCall1-0/+24
This works around existing system headers which unconditionally redefine these macros. This is reasonably safe to do because we used to warn about it anyway (outside of system headers). Continue to warn if the redefinition would have changed the expansion. Still permit redefinition if the macro is explicitly #undef'ed first. rdar://23788307 llvm-svn: 255311
2015-11-20[clang] Disable Unicode in asm filesVinicius Tinti1-2/+6
Clang should not convert tokens to Unicode when preprocessing assembly files. Fixes PR25558. llvm-svn: 253738
2015-11-14Use %select to merge similar diagnostics. NFCCraig Topper3-14/+14
llvm-svn: 253119
2015-11-13Fix auto-link for text-based dynamic library SDKs.Juergen Ributzka1-3/+12
When linking against text-based dynamic library SDKs the library name of a framework has now more than one possible filename extensions. This fix tests for both possible extensions (none, and .tbd). This fixes rdar://problem/20609975 llvm-svn: 253060
2015-11-12Use %select to merge two diagnostics that only differ in one word and are ↵Craig Topper1-3/+2
emitted in the same place. NFC llvm-svn: 252861
2015-11-07Remove spaces in empty line, NFC.Yaron Keren1-1/+1
llvm-svn: 252405
2015-11-05Improve macro dumping to preserve semantically-relevant spelling information.Richard Smith1-5/+9
llvm-svn: 252206
2015-11-05Allow use of private headers in different sub-modules.Manuel Klimek1-10/+3
llvm-svn: 252170