Re: [PATCH] D13765: clang-format: [JS] Handle string literals spanning character classes.
djasper accepted this revision. djasper added a comment. This revision is now accepted and ready to land. Looks good. http://reviews.llvm.org/D13765 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r250648 - clang-format: [JS] Handle string literals spanning character classes.
Author: djasper Date: Sun Oct 18 02:02:28 2015 New Revision: 250648 URL: http://llvm.org/viewvc/llvm-project?rev=250648&view=rev Log: clang-format: [JS] Handle string literals spanning character classes. If a RegExp contains a character group with a quote (/["]/), the trailing end of it is first tokenized as a string literal, which leads to the merging code seeing an unbalanced bracket. This change parses regex literals from the left hand side. That simplifies the parsing code and also allows correctly handling escapes and character classes, hopefully correctly parsing all regex literals. Patch by Martin Probst, thank you. Review: http://reviews.llvm.org/D13765 Modified: cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/FormatTestJS.cpp Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=250648&r1=250647&r2=250648&view=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Sun Oct 18 02:02:28 2015 @@ -732,6 +732,8 @@ public: assert(FirstInLineIndex == 0); do { Tokens.push_back(getNextToken()); + if (Style.Language == FormatStyle::LK_JavaScript) +tryParseJSRegexLiteral(); tryMergePreviousTokens(); if (Tokens.back()->NewlinesBefore > 0 || Tokens.back()->IsMultiline) FirstInLineIndex = Tokens.size() - 1; @@ -751,10 +753,6 @@ private: return; if (Style.Language == FormatStyle::LK_JavaScript) { - if (tryMergeJSRegexLiteral()) -return; - if (tryMergeEscapeSequence()) -return; if (tryMergeTemplateString()) return; @@ -826,107 +824,97 @@ private: return true; } - // Tries to merge an escape sequence, i.e. a "\\" and the following - // character. Use e.g. inside JavaScript regex literals. - bool tryMergeEscapeSequence() { -if (Tokens.size() < 2) - return false; -FormatToken *Previous = Tokens[Tokens.size() - 2]; -if (Previous->isNot(tok::unknown) || Previous->TokenText != "\\") - return false; -++Previous->ColumnWidth; -StringRef Text = Previous->TokenText; -Previous->TokenText = StringRef(Text.data(), Text.size() + 1); -resetLexer(SourceMgr.getFileOffset(Tokens.back()->Tok.getLocation()) + 1); -Tokens.resize(Tokens.size() - 1); -Column = Previous->OriginalColumn + Previous->ColumnWidth; + // Returns \c true if \p Tok can only be followed by an operand in JavaScript. + bool precedesOperand(FormatToken *Tok) { +// NB: This is not entirely correct, as an r_paren can introduce an operand +// location in e.g. `if (foo) /bar/.exec(...);`. That is a rare enough +// corner case to not matter in practice, though. +return Tok->isOneOf(tok::period, tok::l_paren, tok::comma, tok::l_brace, +tok::r_brace, tok::l_square, tok::semi, tok::exclaim, +tok::colon, tok::question, tok::tilde) || + Tok->isOneOf(tok::kw_return, tok::kw_do, tok::kw_case, tok::kw_throw, +tok::kw_else, tok::kw_new, tok::kw_delete, tok::kw_void, +tok::kw_typeof, Keywords.kw_instanceof, +Keywords.kw_in) || + Tok->isBinaryOperator(); + } + + bool canPrecedeRegexLiteral(FormatToken *Prev) { +if (!Prev) + return true; + +// Regex literals can only follow after prefix unary operators, not after +// postfix unary operators. If the '++' is followed by a non-operand +// introducing token, the slash here is the operand and not the start of a +// regex. +if (Prev->isOneOf(tok::plusplus, tok::minusminus)) + return (Tokens.size() < 3 || precedesOperand(Tokens[Tokens.size() - 3])); + +// The previous token must introduce an operand location where regex +// literals can occur. +if (!precedesOperand(Prev)) + return false; + return true; } - // Try to determine whether the current token ends a JavaScript regex literal. - // We heuristically assume that this is a regex literal if we find two - // unescaped slashes on a line and the token before the first slash is one of - // "(;,{}![:?", a binary operator or 'return', as those cannot be followed by - // a division. - bool tryMergeJSRegexLiteral() { -if (Tokens.size() < 2) - return false; - -// If this is a string literal with a slash inside, compute the slash's -// offset and try to find the beginning of the regex literal. -// Also look at tok::unknown, as it can be an unterminated char literal. -size_t SlashInStringPos = StringRef::npos; -if (Tokens.back()->isOneOf(tok::string_literal, tok::char_constant, - tok::unknown)) { - // Start search from position 1 as otherwise, this is an unknown token - // for an unterminated /*-comment which is handled elsewhere. -
Re: [PATCH] D13765: clang-format: [JS] Handle string literals spanning character classes.
djasper closed this revision. djasper added a comment. Submitted as r250648. http://reviews.llvm.org/D13765 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13811: [clang-format] AllowShortFunctionsOnASingleLine: true/Empty didn't work with BreakBeforeBraces: Linux/Allman.
djasper added inline comments. Comment at: lib/Format/UnwrappedLineFormatter.cpp:193 @@ -192,3 +192,3 @@ (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty && - I[1]->First->is(tok::r_brace)) || + I[1]->First->isOneOf(tok::l_brace, tok::r_brace)) || (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline && From a first look, this doesn't make sense. We specifically check that the next line is a closing brace to ensure that this is an empty function. Now, this seems to work with the existing tests, but because of very intricate reasons: * If we are not wrapping with Allman/Linux style, the first token of I[1] is unlikely to be an open brace. It can actually be one: void f() { { DoSomething(); } }, but in this case there are too many unwrapped lines to merge anything. * There aren't any other tests with Allman/Linux style *and* AllowShortFunctionsOnASingleLine set to "Empty". If there were, they'd show, that this code now also merges non-empty functinos. Instead, pull out an additional variable: bool EmptyFunction = (Style.BraceWrapping.AfterFunction ? I[2] : I[1])->First->is(tok::r_brace); and then use that. Please also add a test showing that non-empty functions do not get merged. Comment at: unittests/Format/FormatTest.cpp:6523 @@ -6522,1 +6522,3 @@ +TEST_F(FormatTest, PullEmptyFunctionDefinitionsIntoSingleLineLinux) { + FormatStyle MergeEmptyLinux = getLLVMStyle(); Just extend PullInlineFunctionDefinitionsIntoSingleLine instead. Repository: rL LLVM http://reviews.llvm.org/D13811 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r250657 - Support linking against OpenMP runtime on FreeBSD.
Author: dim Date: Sun Oct 18 08:32:20 2015 New Revision: 250657 URL: http://llvm.org/viewvc/llvm-project?rev=250657&view=rev Log: Support linking against OpenMP runtime on FreeBSD. Summary: Similar to rL248426 (which was a followup to rL248379 and rL248424), add the required libraries for OpenMP on the linker command line, and update the test case. Reviewers: emaste, theraven, joerg Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13822 Modified: cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/test/Driver/fopenmp.c Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=250657&r1=250656&r2=250657&view=diff == --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Sun Oct 18 08:32:20 2015 @@ -7612,6 +7612,7 @@ void freebsd::Linker::ConstructJob(Compi if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_nodefaultlibs)) { +addOpenMPRuntime(CmdArgs, ToolChain, Args); if (D.CCCIsCXX()) { ToolChain.AddCXXStdlibLibArgs(Args, CmdArgs); if (Args.hasArg(options::OPT_pg)) Modified: cfe/trunk/test/Driver/fopenmp.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fopenmp.c?rev=250657&r1=250656&r2=250657&view=diff == --- cfe/trunk/test/Driver/fopenmp.c (original) +++ cfe/trunk/test/Driver/fopenmp.c Sun Oct 18 08:32:20 2015 @@ -4,6 +4,9 @@ // RUN: %clang -target x86_64-apple-darwin -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP // RUN: %clang -target x86_64-apple-darwin -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP // RUN: %clang -target x86_64-apple-darwin -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP +// RUN: %clang -target x86_64-freebsd -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP +// RUN: %clang -target x86_64-freebsd -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP +// RUN: %clang -target x86_64-freebsd -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP // RUN: %clang -target x86_64-netbsd -fopenmp=libomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP // RUN: %clang -target x86_64-netbsd -fopenmp=libgomp -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-NO-OPENMP // RUN: %clang -target x86_64-netbsd -fopenmp=libiomp5 -c %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-CC1-OPENMP @@ -34,6 +37,10 @@ // RUN: %clang -target x86_64-netbsd -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-GOMP // RUN: %clang -target x86_64-netbsd -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-IOMP5 // +// RUN: %clang -nostdlib -target x86_64-freebsd -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP +// RUN: %clang -nostdlib -target x86_64-freebsd -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP +// RUN: %clang -nostdlib -target x86_64-freebsd -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5 +// // RUN: %clang -nostdlib -target x86_64-netbsd -fopenmp=libomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-OMP // RUN: %clang -nostdlib -target x86_64-netbsd -fopenmp=libgomp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-GOMP // RUN: %clang -nostdlib -target x86_64-netbsd -fopenmp=libiomp5 %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-IOMP5 @@ -64,6 +71,7 @@ // // RUN: %clang -target x86_64-linux-gnu -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY // RUN: %clang -target x86_64-darwin -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY +// RUN: %clang -target x86_64-freebsd -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY // RUN: %clang -target x86_64-netbsd -fopenmp %s -o %t -### 2>&1 | FileCheck %s --check-prefix=CHECK-LD-ANY // // CHECK-LD-ANY: "{{.*}}ld{{(.exe)?}}" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D12761: MPI-Checker patch for Clang Static Analyzer
Alexander_Droste added inline comments. Comment at: tools/clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPITypes.h:67 @@ +66,3 @@ + // Every time a request is 'set' a new 'RequestId' gets created. + // Therefore, the 'UserKind' does not need to be profiled. + const int RequestId{RequestIdCount++}; Alexander_Droste wrote: > zaks.anna wrote: > > Alexander_Droste wrote: > > > zaks.anna wrote: > > > > Still it looks like you have several pieces of information in the state > > > > that are redundant.. Looks like you've added more now. > > > > > > > > For example, why do we need RequestId? Each report will only talk about > > > > a single request, is this not the case? > > > > > > > > Do you absolutely need to store LastUser and VariableName? > > > > > > > > Note that storing in the state is very expensive; on the other hand, we > > > > can afford to perform costly analysis on post-processing of an error > > > > report. This is why all other checkers store minimal information in the > > > > state, usually just a single enum and determine all the other > > > > information during the walk over the error path in BugReporterVisitor. > > > > The visitor will visit all nodes that you visited while reporting this > > > > bug, so it should have access to all the information you need. > > > > > > > I need the RequestID to distinct function calls of the same type > > > and location using the request multiple times along the path. > > > Like in a loop: > > > ``` > > > for int i ... > > >nonblocking(.., request) // double nonblocking > > > ``` > > > > > > > Do you absolutely need to store LastUser and VariableName? > > > Absolutely not. :D I will remove the string member. > > > The variable name retrieval can be delayed to the point where the report > > > is created. > > > > > > I can also remove the enum, as the state of the request can be derived > > > from the LastUser. > > > The reason why I added the enum member, is that I was concerned about > > > that the CallEventRef > > > can be invalid to reference again if the call is inlined from an > > > implementation defined in a header. > > > As this seems not to be the case, I can remove the redundancy. > > > > > > > This is why all other checkers store minimal information in the state, > > > > usually just a single enum and determine all the other information > > > > during the walk over the error path in BugReporterVisitor. > > > > > > Ah, I get it. Until now that seemed a bit overly complicated to me. > > I suspect the only thing you need in Request is the enum; everything else > > can be determined while visiting the path. > > > > This should be in ento namespace not in the clang namespace. > I think you're right that the enum is sufficient. > Thus for better diagnostics the source range > of the CallEventRef (LastUser) > should be obtained by the BugReportVisitor. > Is it possible to obtain a CallEventRef based on > a memory region? So conceptually this would mean > to find the last function call (before the error node) using > a specific region. > I'll give this pattern a try: ``` const Stmt *S = nullptr; ProgramPoint ProgLoc = N->getLocation(); if (Optional SP = ProgLoc.getAs()) { S = SP->getStmt(); } // if S then S->getSourceRange ``` Looks like it could work. http://reviews.llvm.org/D12761 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r250470 - Fix the subtarget features required by some x86 builtins.
Interestingly, gcc doesn't get this right either *test.cpp:7:64:* *error: *‘*__builtin_ia32_xorpd256_mask*’ needs isa option -m32 -mavx512dq -mavx512vl I'm not even sure why it bothered to list -m32. If you then give it -mavx512dq without -mavx512vl it proceeds to throw internal compiler errors. *test.cpp:8:1:* *error: *unrecognizable insn: } * ^* (insn 15 14 18 2 (set (reg:V4DF 89 [ D.22466 ]) (vec_merge:V4DF (xor:V4DF (reg:V4DF 92) (mem/c:V4DF (plus:DI (reg/f:DI 82 virtual-stack-vars) (const_int -96 [0xffa0])) [0 __A+0 S32 A256])) (reg:V4DF 93) (subreg:QI (reg:SI 94) 0))) test.cpp:7 -1 (nil)) *test.cpp:8:1:* *internal compiler error: *in extract_insn, at recog.c:2343 *test.cpp:8:1:* *internal compiler error: *Abort trap: 6 *g++:* *internal compiler error: *Abort trap: 6 (program cc1plus) On Fri, Oct 16, 2015 at 6:50 PM, Eric Christopher wrote: > Sure, but if someone is planning on doing this for ARM there's some work > in the ARM TargetInfo that needs to be done :) > > -eric > > On Fri, Oct 16, 2015 at 3:24 PM Justin Bogner > wrote: > >> Looks like we'll need "and" for ARM's builtins as well - several require >> things like neon+fp16 or neon+vfp4. >> >> Eric Christopher writes: >> > Right. My current direction is going to be: >> > >> > "foo+bar" we can represent as "and" >> > "foo,bar" we'll continue to represent as "or" >> > >> > this will lead to things like (possibly): >> > >> > "foo+bar, baz" - "either foo and bar, or baz." >> > >> > -eric >> > >> > On Fri, Oct 16, 2015 at 11:41 AM Justin Bogner >> > wrote: >> > >> >> Hm. Well, supporting both "and" and "or" combinations here sounds like >> >> an unpleasant path to go down. I guess the question is, which is >> >> weirder? >> >> >> >> - With fma, we have fma4 which is basically a synonym as far as >> >> intrinsics go - some chips have 3-argument versions and some have 4, >> >> but I don't think any of the intrinsics reflect that. >> >> >> >> - With avx512, we have combinations of features which introduce new >> >> intrinsics, since the supported elements and supported vector types >> >> are more or less orthogonal. >> >> >> >> I guess the fma situation is easier to special case if we want to avoid >> >> having to parse expressions here. Ie, we could have some kind of >> >> meta-feature that expands to "fma or fma4". Of course, the obvious name >> >> for that is "fma", which means fma3 today... >> >> >> >> Eric Christopher via cfe-commits writes: >> >> > Lovely. Cc'ing Justin here. We'll need to figure out some change for >> >> these >> >> > builtins here if we need to have and as well as or. >> >> > >> >> > (Why on earth are these builtins subject to two separate features? >> *sigh* >> >> > It's ridiculous.) >> >> > >> >> > -eric >> >> > >> >> > On Thu, Oct 15, 2015 at 11:59 PM Craig Topper < >> craig.top...@gmail.com> >> >> > wrote: >> >> > >> >> >> Correct you avx512vl means it support 128 and 256-bit vectors. >> avx512bw >> >> >> means it supports byte and word elements. So you actually need both. >> >> >> >> >> >> On Thu, Oct 15, 2015 at 11:57 PM, Eric Christopher < >> echri...@gmail.com> >> >> >> wrote: >> >> >> >> >> >>> The comma separated list is currently represented as "one of >> these". I >> >> >>> couldn't parse your first sentence, for the avx512 ones are you >> saying >> >> that >> >> >>> it requires both and not just one of the options? >> >> >>> >> >> >>> -eric >> >> >>> >> >> >>> On Thu, Oct 15, 2015 at 11:55 PM Craig Topper < >> craig.top...@gmail.com> >> >> >>> wrote: >> >> >>> >> >> So for the AVX512 ones that list 2 features those features are >> both >> >> required, but for FMA you need either one of the features but not >> >> both. >> >> What is the comma separated list currently implemented as? >> >> >> >> On Thu, Oct 15, 2015 at 3:46 PM, Eric Christopher via cfe-commits >> < >> >> cfe-commits@lists.llvm.org> wrote: >> >> >> >> > Author: echristo >> >> > Date: Thu Oct 15 17:46:02 2015 >> >> > New Revision: 250470 >> >> > >> >> > URL: http://llvm.org/viewvc/llvm-project?rev=250470&view=rev >> >> > Log: >> >> > Fix the subtarget features required by some x86 builtins. >> >> > >> >> > Update the fma builtins to be fma/fma4 until some we can find >> some >> >> > documentation either way. >> >> > >> >> > Update a couple of the avx intrinsics because they were in the >> wrong >> >> > category. >> >> > >> >> > Modified: >> >> > cfe/trunk/include/clang/Basic/BuiltinsX86.def >> >> > >> >> > Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def >> >> > URL: >> >> > >> >> >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=250470&r1=250469&r2=250470&view=diff >> >> > >> >> > >> >> >> ==
Re: [Diffusion] rL248426: Support linking against OpenMP runtime on NetBSD.
dim added a subscriber: dim. dim added auditors: 3.7-release, cfe-commits, tstellarAMD, joerg. dim added a comment. Should be merged together with http://reviews.llvm.org/rL248379, http://reviews.llvm.org/rL248424, and http://reviews.llvm.org/rL250657. Together, these add support for linking against OpenMP on FreeBSD and NetBSD. Users: joerg (Author, Auditor) 3.7-release (Auditor) cfe-commits (Auditor) tstellarAMD (Auditor) http://reviews.llvm.org/rL248426 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [Diffusion] rL248424: Push OpenMP linker flags after linker input on Darwin. Don't add any
dim added a subscriber: dim. dim added auditors: 3.7-release, cfe-commits, tstellarAMD, joerg. dim added a comment. Should be merged together with http://reviews.llvm.org/rL248379, http://reviews.llvm.org/rL248426, and http://reviews.llvm.org/rL250657. Together, these add support for linking against OpenMP on FreeBSD and NetBSD. Users: joerg (Author, Auditor) 3.7-release (Auditor) cfe-commits (Auditor) tstellarAMD (Auditor) http://reviews.llvm.org/rL248424 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [Diffusion] rL248379: Refactor library decision for -fopenmp support from Darwin into a
dim added a subscriber: dim. dim added auditors: 3.7-release, cfe-commits, tstellarAMD, joerg. dim added a comment. Should be merged together with http://reviews.llvm.org/rL248424, http://reviews.llvm.org/rL248426, and http://reviews.llvm.org/rL250657. Together, these add support for linking against OpenMP on FreeBSD and NetBSD. Users: joerg (Author, Auditor) 3.7-release (Auditor) cfe-commits (Auditor) tstellarAMD (Auditor) http://reviews.llvm.org/rL248379 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [Diffusion] rL250657: Support linking against OpenMP runtime on FreeBSD.
dim added auditors: 3.7-release, cfe-commits, tstellarAMD, joerg. dim added a comment. Should be merged together with http://reviews.llvm.org/rL248379, http://reviews.llvm.org/rL248424, and http://reviews.llvm.org/rL248426. Together, these add support for linking against OpenMP on FreeBSD and NetBSD. Users: dim (Author) 3.7-release (Auditor) cfe-commits (Auditor) tstellarAMD (Auditor) joerg (Auditor) http://reviews.llvm.org/rL250657 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r250665 - CodeGen: simplify TargetOptions setup
Author: compnerd Date: Sun Oct 18 15:24:53 2015 New Revision: 250665 URL: http://llvm.org/viewvc/llvm-project?rev=250665&view=rev Log: CodeGen: simplify TargetOptions setup Do direct assignment of boolean values and regroup. Use StringSwitch instead of custom cases. NFC. Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=250665&r1=250664&r2=250665&view=diff == --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original) +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Sun Oct 18 15:24:53 2015 @@ -488,24 +488,16 @@ TargetMachine *EmitAssemblyHelper::Creat .Case("posix", llvm::ThreadModel::POSIX) .Case("single", llvm::ThreadModel::Single); - if (CodeGenOpts.DisableIntegratedAS) -Options.DisableIntegratedAS = true; - - if (CodeGenOpts.CompressDebugSections) -Options.CompressDebugSections = true; - - if (CodeGenOpts.UseInitArray) -Options.UseInitArray = true; - // Set float ABI type. - if (CodeGenOpts.FloatABI == "soft" || CodeGenOpts.FloatABI == "softfp") -Options.FloatABIType = llvm::FloatABI::Soft; - else if (CodeGenOpts.FloatABI == "hard") -Options.FloatABIType = llvm::FloatABI::Hard; - else { -assert(CodeGenOpts.FloatABI.empty() && "Invalid float abi!"); -Options.FloatABIType = llvm::FloatABI::Default; - } + assert((CodeGenOpts.FloatABI == "soft" || CodeGenOpts.FloatABI == "softfp" || + CodeGenOpts.FloatABI == "hard" || CodeGenOpts.FloatABI.empty()) && + "Invalid Floating Point ABI!"); + Options.FloatABIType = + llvm::StringSwitch(CodeGenOpts.FloatABI) + .Case("soft", llvm::FloatABI::Soft) + .Case("softfp", llvm::FloatABI::Soft) + .Case("hard", llvm::FloatABI::Hard) + .Default(llvm::FloatABI::Default); // Set FP fusion mode. switch (CodeGenOpts.getFPContractMode()) { @@ -520,6 +512,9 @@ TargetMachine *EmitAssemblyHelper::Creat break; } + Options.UseInitArray = CodeGenOpts.UseInitArray; + Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS; + Options.CompressDebugSections = CodeGenOpts.CompressDebugSections; Options.LessPreciseFPMADOption = CodeGenOpts.LessPreciseFPMAD; Options.NoInfsFPMath = CodeGenOpts.NoInfsFPMath; Options.NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r250666 - No functionality change, just fix whitespace, a typo and remove an unnecessary
Author: nicholas Date: Sun Oct 18 15:32:12 2015 New Revision: 250666 URL: http://llvm.org/viewvc/llvm-project?rev=250666&view=rev Log: No functionality change, just fix whitespace, a typo and remove an unnecessary emacs mode marker. (Changes left behind from another patch that ended up not working out.) Modified: cfe/trunk/lib/AST/DeclBase.cpp cfe/trunk/lib/Sema/SemaLookup.cpp cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Modified: cfe/trunk/lib/AST/DeclBase.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=250666&r1=250665&r2=250666&view=diff == --- cfe/trunk/lib/AST/DeclBase.cpp (original) +++ cfe/trunk/lib/AST/DeclBase.cpp Sun Oct 18 15:32:12 2015 @@ -1233,7 +1233,7 @@ void DeclContext::addHiddenDecl(Decl *D) } // Notify a C++ record declaration that we've added a member, so it can - // update it's class-specific state. + // update its class-specific state. if (CXXRecordDecl *Record = dyn_cast(this)) Record->addedMember(D); Modified: cfe/trunk/lib/Sema/SemaLookup.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=250666&r1=250665&r2=250666&view=diff == --- cfe/trunk/lib/Sema/SemaLookup.cpp (original) +++ cfe/trunk/lib/Sema/SemaLookup.cpp Sun Oct 18 15:32:12 2015 @@ -1,4 +1,4 @@ -//===- SemaLookup.cpp - Name Lookup *- C++ -*-===// +//===- SemaLookup.cpp - Name Lookup --===// // // The LLVM Compiler Infrastructure // @@ -154,7 +154,7 @@ namespace { // by its using directives, transitively) as if they appeared in // the given effective context. void addUsingDirectives(DeclContext *DC, DeclContext *EffectiveDC) { - SmallVector queue; + SmallVector queue; while (true) { for (auto UD : DC->using_directives()) { DeclContext *NS = UD->getNominatedNamespace(); @@ -2189,7 +2189,7 @@ void Sema::DiagnoseAmbiguousLookup(Looku case LookupResult::AmbiguousTagHiding: { Diag(NameLoc, diag::err_ambiguous_tag_hiding) << Name << LookupRange; -llvm::SmallPtrSet TagDecls; +llvm::SmallPtrSet TagDecls; for (auto *D : Result) if (TagDecl *TD = dyn_cast(D)) { Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=250666&r1=250665&r2=250666&view=diff == --- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original) +++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Sun Oct 18 15:32:12 2015 @@ -260,7 +260,7 @@ void ASTDeclWriter::Visit(Decl *D) { // Source locations require array (variable-length) abbreviations. The // abbreviation infrastructure requires that arrays are encoded last, so // we handle it here in the case of those classes derived from DeclaratorDecl - if (DeclaratorDecl *DD = dyn_cast(D)){ + if (DeclaratorDecl *DD = dyn_cast(D)) { Writer.AddTypeSourceInfo(DD->getTypeSourceInfo(), Record); } @@ -2101,7 +2101,7 @@ void ASTWriter::WriteDecl(ASTContext &Co if (IDR == 0) IDR = NextDeclID++; -ID= IDR; +ID = IDR; } bool isReplacingADecl = ID < FirstDeclID; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r250473 - Add an error when calling a builtin that requires features that don't
Eric Christopher writes: > I'm reasonably certain you forgot to rebuild or ran make test in the wrong > directory. You're right, I did something funny there. Sorry for the noise. > Two reasons: > > a) This is pretty much my first patch. I mean, identical and I tried that. > b) I actually tried this one and got: > > Testing Time: 217.41s > > Failing Tests (68): > Clang :: CodeGen/3dnow-builtins.c > Clang :: CodeGen/adc-builtins.c > Clang :: CodeGen/adx-builtins.c > Clang :: CodeGen/attr-target-x86-mmx.c > Clang :: CodeGen/avx-builtins.c > Clang :: CodeGen/avx-cmp-builtins.c > Clang :: CodeGen/avx-shuffle-builtins.c > Clang :: CodeGen/avx2-builtins.c > Clang :: CodeGen/avx512bw-builtins.c > Clang :: CodeGen/avx512cdintrin.c > Clang :: CodeGen/avx512dq-builtins.c > Clang :: CodeGen/avx512er-builtins.c > Clang :: CodeGen/avx512f-builtins.c > Clang :: CodeGen/avx512vl-builtins.c > Clang :: CodeGen/avx512vlbw-builtins.c > Clang :: CodeGen/avx512vldq-builtins.c > Clang :: CodeGen/bmi-builtins.c > Clang :: CodeGen/bmi2-builtins.c > Clang :: CodeGen/builtins-x86.c > Clang :: CodeGen/f16c-builtins.c > Clang :: CodeGen/fma-builtins.c > Clang :: CodeGen/fma4-builtins.c > Clang :: CodeGen/fsgsbase-builtins.c > Clang :: CodeGen/lzcnt-builtins.c > Clang :: CodeGen/mmx-builtins.c > Clang :: CodeGen/mmx-inline-asm.c > Clang :: CodeGen/mmx-shift-with-immediate.c > Clang :: CodeGen/ms-intrinsics.c > Clang :: CodeGen/ms-mm-align.c > Clang :: CodeGen/palignr.c > Clang :: CodeGen/pclmul-builtins.c > Clang :: CodeGen/popcnt-builtins.c > Clang :: CodeGen/prefetchw-builtins.c > Clang :: CodeGen/rdrand-builtins.c > Clang :: CodeGen/rtm-builtins.c > Clang :: CodeGen/sha-builtins.c > Clang :: CodeGen/sse-builtins-dbg.c > Clang :: CodeGen/sse-builtins.c > Clang :: CodeGen/sse.c > Clang :: CodeGen/sse3-builtins.c > Clang :: CodeGen/sse41-builtins.c > Clang :: CodeGen/sse42-builtins.c > Clang :: CodeGen/sse4a-builtins.c > Clang :: CodeGen/ssse3-builtins.c > Clang :: CodeGen/target-builtin-error-2.c > Clang :: CodeGen/target-builtin-error.c > Clang :: CodeGen/target-builtin-noerror.c > Clang :: CodeGen/tbm-builtins.c > Clang :: CodeGen/vector.c > Clang :: CodeGen/x86_32-xsave.c > Clang :: CodeGen/x86_64-xsave.c > Clang :: CodeGen/xop-builtins.c > Clang :: CodeGenCXX/mangle-ms-vector-types.cpp > Clang :: Headers/c89.c > Clang :: Headers/ms-intrin.cpp > Clang :: Headers/pmmintrin.c > Clang :: Headers/wmmintrin.c > Clang :: Headers/x86-intrinsics-headers.c > Clang :: Headers/x86intrin-2.c > Clang :: Headers/x86intrin.c > Clang :: Headers/xmmintrin.c > Clang :: Integration/carbon.c > Clang :: Integration/cocoa-pch.m > Clang :: Integration/cocoa.m > Clang :: Modules/compiler_builtins.m > Clang :: Sema/builtins-x86.c > Clang :: Sema/warn-shadow-intrinsics.c > Clang :: Sema/x86-builtin-palignr.c > > Expected Passes: 8545 > Expected Failures : 15 > Unsupported Tests : 15 > Unexpected Failures: 68 > > with lots of failures that look like: > > In file included from > /Users/echristo/builds/build-llvm/Debug+Asserts/bin/../lib/clang/3.8.0/include/immintrin.h:143: > /Users/echristo/builds/build-llvm/Debug+Asserts/bin/../lib/clang/3.8.0/include/shaintrin.h:40:19: > error: '__builtin_ia32_sha1nexte' needs target feature sha > return (__m128i)__builtin_ia32_sha1nexte((__v4si)__X, (__v4si)__Y); > ^ > > for files that include more headers than they need (think x86intrin.h being > the only header included), but not calling any of the functions and so not > using a command line option that enables every feature for the x86 target. > > -eric > > On Sat, Oct 17, 2015 at 2:11 AM Justin Bogner wrote: > >> Eric Christopher writes: >> > Can't be. We don't know we're going to make the call until we code gen. >> :) >> >> Okay... but then why don't any tests fail with the attached? It looks >> like it does the right thing in a very cursory test, as well. >> >> >> > On Fri, Oct 16, 2015, 7:50 PM Justin Bogner >> wrote: >> > >> >> Eric Christopher via cfe-commits writes: >> >> > Author: echristo >> >> > Date: Thu Oct 15 18:47:11 2015 >> >> > New Revision: 250473 >> >> > >> >> > URL: http://llvm.org/viewvc/llvm-project?rev=250473&view=rev >> >> > Log: >> >> > Add an error when calling a builtin that requires features that don't >> >> > match the feature set of the function that they're being called from. >> >> > >> >> > This ensures that we can effectively diagnose some[1] code that would >> >> > instead ICE in the backend with a failure to select message. >> >> > >> >> > Example: >> >> > >> >> > __m128d foo(__m128d a, __m128d b) { >> >> > return __builtin_ia32_addsubps(b, a); >> >> > } >> >> > >> >> > compiled for normal x86_64 via: >> >>
[PATCH] D13852: clang-format: Use pipes instead of temporary files for most lit tests.
thakis created this revision. thakis added a reviewer: djasper. thakis added a subscriber: cfe-commits. Herald added a subscriber: klimek. This makes the format tests look more like most other FileCheck tests in clang. The multiple-inputs tests still use temp files, to make sure that the file input code in clang-format stays tested. Stop stripping out the comment lines in style-on-command-line.cpp as they don't get in the way and it makes the test simpler. Also remove 2>&1s on the tests in that file that don't need it. http://reviews.llvm.org/D13852 Files: test/Format/basic.cpp test/Format/cursor.cpp test/Format/disable-format.cpp test/Format/incomplete.cpp test/Format/language-detection.cpp test/Format/line-ranges.cpp test/Format/ranges.cpp test/Format/style-on-command-line.cpp test/Format/xmloutput.cpp Index: test/Format/xmloutput.cpp === --- test/Format/xmloutput.cpp +++ test/Format/xmloutput.cpp @@ -1,5 +1,4 @@ -// RUN: clang-format -output-replacements-xml -sort-includes %s > %t.xml -// RUN: FileCheck -strict-whitespace -input-file=%t.xml %s +// RUN: clang-format -output-replacements-xml -sort-includes %s | FileCheck -strict-whitespace %s // CHECK: %t.cpp -// RUN: clang-format -style="{BasedOnStyle: Google, IndentWidth: 8}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK1 %s -// RUN: clang-format -style="{BasedOnStyle: LLVM, IndentWidth: 7}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK2 %s -// RUN: clang-format -style="{BasedOnStyle: invalid, IndentWidth: 7}" -fallback-style=LLVM %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK3 %s -// RUN: clang-format -style="{lsjd}" %t.cpp -fallback-style=LLVM 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK4 %s +// RUN: clang-format -style="{BasedOnStyle: Google, IndentWidth: 8}" %s | FileCheck -strict-whitespace -check-prefix=CHECK1 %s +// RUN: clang-format -style="{BasedOnStyle: LLVM, IndentWidth: 7}" %s | FileCheck -strict-whitespace -check-prefix=CHECK2 %s +// RUN: clang-format -style="{BasedOnStyle: invalid, IndentWidth: 7}" -fallback-style=LLVM %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK3 %s +// RUN: clang-format -style="{lsjd}" %s -fallback-style=LLVM 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK4 %s // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %T/.clang-format -// RUN: clang-format -style=file %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK5 %s +// RUN: clang-format -style=file -assume-filename=%T/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK5 %s // RUN: printf "\n" > %T/.clang-format -// RUN: clang-format -style=file -fallback-style=webkit %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK6 %s +// RUN: clang-format -style=file -fallback-style=webkit -assume-filename=%T/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK6 %s // RUN: rm %T/.clang-format // RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %T/_clang-format -// RUN: clang-format -style=file %t.cpp 2>&1 | FileCheck -strict-whitespace -check-prefix=CHECK7 %s -// RUN: clang-format -style="{BasedOnStyle: LLVM, PointerBindsToType: true}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK8 %s -// RUN: clang-format -style="{BasedOnStyle: WebKit, PointerBindsToType: false}" %t.cpp | FileCheck -strict-whitespace -check-prefix=CHECK9 %s +// RUN: clang-format -style=file -assume-filename=%T/foo.cpp < %s | FileCheck -strict-whitespace -check-prefix=CHECK7 %s +// RUN: clang-format -style="{BasedOnStyle: LLVM, PointerBindsToType: true}" %s | FileCheck -strict-whitespace -check-prefix=CHECK8 %s +// RUN: clang-format -style="{BasedOnStyle: WebKit, PointerBindsToType: false}" %s | FileCheck -strict-whitespace -check-prefix=CHECK9 %s void f() { // CHECK1: {{^int\* i;$}} // CHECK2: {{^ int \*i;$}} Index: test/Format/ranges.cpp === --- test/Format/ranges.cpp +++ test/Format/ranges.cpp @@ -1,6 +1,4 @@ -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: clang-format -style=LLVM -offset=2 -length=0 -offset=28 -length=0 -i %t.cpp -// RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s +// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style=LLVM -offset=2 -length=0 -offset=28 -length=0 | FileCheck -strict-whitespace %s // CHECK: {{^int\ \*i;$}} int*i; Index: test/Format/line-ranges.cpp === --- test/Format/line-ranges.cpp +++ test/Format/line-ranges.cpp @@ -1,6 +1,4 @@ -// RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp -// RUN: clang-format -style=LLVM -lines=1:1 -lines=5:5 -i %t.cpp -// RUN: FileCheck -strict-whitespace -input-file=%t.cpp %s +// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style=LLVM -lines=1:1 -lines=5:5 | FileCheck -strict-whitespace %s // CHECK: {{^int\ \*i;$}} int*i; Index: test/Format/l
r250671 - Update list of languages advertised in OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
Author: nico Date: Sun Oct 18 20:03:19 2015 New Revision: 250671 URL: http://llvm.org/viewvc/llvm-project?rev=250671&view=rev Log: Update list of languages advertised in OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code. If no arguments are specified, it formats the code from standard input and writes the result to the standard output. If s are given, it reformats the files. If -i is specified together with s, the files are edited in-place. Otherwise, the result is written to the standard output. USAGE: clang-format [options] [ ...] OPTIONS: -assume-filename= - When reading from stdin, clang-format assumes this filename to look for a style config file (with -style=file) and to determine the language. -cursor=- The position of the cursor when invoking clang-format from an editor integration -dump-config - Dump configuration options to stdout and exit. Can be used with -style option. -fallback-style= - The name of the predefined style used as a fallback in case clang-format is invoked with -style=file, but can not find the .clang-format file to use. Use -fallback-style=none to skip formatting. -help - Display available options (-help-hidden for more) -i- Inplace edit s, if specified. -length=- Format a range of this length (in bytes). Multiple ranges can be formatted by specifying several -offset and -length pairs. When only a single -offset is specified without -length, clang-format will format up to the end of the file. Can only be used with one input file. -lines= - : - format a range of lines (both 1-based). Multiple ranges can be formatted by specifying several -lines arguments. Can't be used with -offset and -length. Can only be used with one input file. -offset=- Format a range starting at this byte offset. Multiple ranges can be formatted by specifying several -offset and -length pairs. Can only be used with one input file. -output-replacements-xml - Output replacements as XML. -sort-includes- Sort touched include lines -style= - Coding style, currently supports: LLVM, Google, Chromium, Mozilla, WebKit. Use -style=file to load style configuration from .clang-format file located in one of the parent directories of the source file (or current directory for stdin). Use -style="{key: value, ...}" to set specific parameters, e.g.: -style="{BasedOnStyle: llvm, IndentWidth: 8}" -version - Display the version of this program output. Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=250671&r1=250670&r2=250671&view=diff == --- cfe/trunk/tools/clang-format/ClangFormat.cpp (original) +++ cfe/trunk/tools/clang-format/ClangFormat.cpp Sun Oct 18 20:03:19 2015 @@ -324,7 +324,7 @@ int main(int argc, const char **argv) { cl::SetVersionPrinter(PrintVersion); cl::ParseCommandLineOptions( argc, argv, - "A tool to format C/C++/Obj-C code.\n\n" + "A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code.\n\n" "If no arguments are specified, it formats the code from standard input\n" "and writes the result to the standard output.\n" "If s are given, it reformats the files. If -i is specified\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r250672 - Update `clang-format -help` output in clang-format docs.
Author: nico Date: Sun Oct 18 20:08:30 2015 New Revision: 250672 URL: http://llvm.org/viewvc/llvm-project?rev=250672&view=rev Log: Update `clang-format -help` output in clang-format docs. -assume-filename, -fallback-style, and -sort-includes are new. (They're also longer than the previous options, so all descriptions shift over by some amount, making this diff look larger than it is.) It looks like someone renamed "General options" to "Generic Options" too. Modified: cfe/trunk/docs/ClangFormat.rst Modified: cfe/trunk/docs/ClangFormat.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=250672&r1=250671&r2=250672&view=diff == --- cfe/trunk/docs/ClangFormat.rst (original) +++ cfe/trunk/docs/ClangFormat.rst Sun Oct 18 20:08:30 2015 @@ -16,7 +16,7 @@ to format C/C++/Obj-C code. .. code-block:: console $ clang-format -help - OVERVIEW: A tool to format C/C++/Obj-C code. + OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code. If no arguments are specified, it formats the code from standard input and writes the result to the standard output. @@ -30,44 +30,53 @@ to format C/C++/Obj-C code. Clang-format options: --cursor= - The position of the cursor when invoking - clang-format from an editor integration --dump-config - Dump configuration options to stdout and exit. - Can be used with -style option. --i - Inplace edit s, if specified. --length= - Format a range of this length (in bytes). - Multiple ranges can be formatted by specifying - several -offset and -length pairs. - When only a single -offset is specified without - -length, clang-format will format up to the end - of the file. - Can only be used with one input file. --lines= - : - format a range of - lines (both 1-based). - Multiple ranges can be formatted by specifying - several -lines arguments. - Can't be used with -offset and -length. - Can only be used with one input file. --offset= - Format a range starting at this byte offset. - Multiple ranges can be formatted by specifying - several -offset and -length pairs. - Can only be used with one input file. --output-replacements-xml - Output replacements as XML. --style= - Coding style, currently supports: - LLVM, Google, Chromium, Mozilla, WebKit. - Use -style=file to load style configuration from - .clang-format file located in one of the parent - directories of the source file (or current - directory for stdin). - Use -style="{key: value, ...}" to set specific - parameters, e.g.: - -style="{BasedOnStyle: llvm, IndentWidth: 8}" - - General options: - --help- Display available options (-help-hidden for more) --help-list - Display list of available options (-help-list-hidden for more) --version - Display the version of this program +-assume-filename= - When reading from stdin, clang-format assumes this +filename to look for a style config file (with +-style=file) and to determine the language. +-cursor=- The position of the cursor when invoking +clang-format from an editor integration +-dump-config - Dump configuration options to stdout and exit. +Can be used with -style option. +-fallback-style= - The name of the predefined style used as a +fallback in case clang-format is invoked with +-style=file, but can not find the .clang-format +file to use. +Use -fallback-style=none to skip formatting. +-i- Inplace edit s, if specified. +-length=- Format a range of this length (in bytes). +Multiple ranges can be formatted by specifying +several -offset and -length pairs. +When only a single -offset is specified without +
Re: r250671 - Update list of languages advertised in OVERVIEW: A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf code.
I had committed this with svn commit tools/clang-format -m "Update list of languages advertised in `clang-format -h` output." and since I used "" and not '' the shell executed the `clang-format -h` bit and made the commit message look funny. Apologies. On Sun, Oct 18, 2015 at 6:03 PM, Nico Weber via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: nico > Date: Sun Oct 18 20:03:19 2015 > New Revision: 250671 > > URL: http://llvm.org/viewvc/llvm-project?rev=250671&view=rev > Log: > Update list of languages advertised in OVERVIEW: A tool to format > C/C++/Java/JavaScript/Objective-C/Protobuf code. > > If no arguments are specified, it formats the code from standard input > and writes the result to the standard output. > If s are given, it reformats the files. If -i is specified > together with s, the files are edited in-place. Otherwise, the > result is written to the standard output. > > USAGE: clang-format [options] [ ...] > > OPTIONS: > -assume-filename= - When reading from stdin, clang-format > assumes this > filename to look for a style config file > (with > -style=file) and to determine the language. > -cursor=- The position of the cursor when invoking > clang-format from an editor integration > -dump-config - Dump configuration options to stdout and > exit. > Can be used with -style option. > -fallback-style= - The name of the predefined style used as a > fallback in case clang-format is invoked with > -style=file, but can not find the > .clang-format > file to use. > Use -fallback-style=none to skip formatting. > -help - Display available options (-help-hidden for > more) > -i- Inplace edit s, if specified. > -length=- Format a range of this length (in bytes). > Multiple ranges can be formatted by > specifying > several -offset and -length pairs. > When only a single -offset is specified > without > -length, clang-format will format up to the > end > of the file. > Can only be used with one input file. > -lines= - : - format a range of > lines (both 1-based). > Multiple ranges can be formatted by > specifying > several -lines arguments. > Can't be used with -offset and -length. > Can only be used with one input file. > -offset=- Format a range starting at this byte offset. > Multiple ranges can be formatted by > specifying > several -offset and -length pairs. > Can only be used with one input file. > -output-replacements-xml - Output replacements as XML. > -sort-includes- Sort touched include lines > -style= - Coding style, currently supports: > LLVM, Google, Chromium, Mozilla, WebKit. > Use -style=file to load style configuration > from > .clang-format file located in one of the > parent > directories of the source file (or current > directory for stdin). > Use -style="{key: value, ...}" to set > specific > parameters, e.g.: > -style="{BasedOnStyle: llvm, IndentWidth: > 8}" > -version - Display the version of this program output. > > Modified: > cfe/trunk/tools/clang-format/ClangFormat.cpp > > Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=250671&r1=250670&r2=250671&view=diff > > == > --- cfe/trunk/tools/clang-format/ClangFormat.cpp (original) > +++ cfe/trunk/tools/clang-format/ClangFormat.cpp Sun Oct 18 20:03:19 2015 > @@ -324,7 +324,7 @@ int main(int argc, const char **argv) { >cl::SetVersionPrinter(PrintVersion); >cl::ParseCommandLineOptions( >argc, argv, > - "A tool to format C/C++/Obj-C code.\n\n" > + "A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf > code.\n\n" >"If no arguments are specified, it formats the code from standard > input\n" >"and writes the result to the standard output.\n" >"If s are given, it reformats the files. If -i is specified\n" > > > __
r250674 - docs: remote stale refs
Author: compnerd Date: Sun Oct 18 20:24:08 2015 New Revision: 250674 URL: http://llvm.org/viewvc/llvm-project?rev=250674&view=rev Log: docs: remote stale refs Since the attribute documentation is now auto-generated, the previous references are no longer valid. This prevented the docs build from completing successfully. Modified: cfe/trunk/docs/AddressSanitizer.rst cfe/trunk/docs/MemorySanitizer.rst cfe/trunk/docs/ThreadSanitizer.rst Modified: cfe/trunk/docs/AddressSanitizer.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/AddressSanitizer.rst?rev=250674&r1=250673&r2=250674&view=diff == --- cfe/trunk/docs/AddressSanitizer.rst (original) +++ cfe/trunk/docs/AddressSanitizer.rst Sun Oct 18 20:24:08 2015 @@ -196,12 +196,11 @@ Disabling Instrumentation with ``__attri -- Some code should not be instrumented by AddressSanitizer. One may use the -function attribute ``__attribute__((no_sanitize("address")))`` -(which has deprecated synonyms -:ref:`no_sanitize_address ` and -`no_address_safety_analysis`) to disable instrumentation of a particular -function. This attribute may not be supported by other compilers, so we suggest -to use it together with ``__has_feature(address_sanitizer)``. +function attribute ``__attribute__((no_sanitize("address")))`` (which has +deprecated synonyms `no_sanitize_address` and `no_address_safety_analysis`) to +disable instrumentation of a particular function. This attribute may not be +supported by other compilers, so we suggest to use it together with +``__has_feature(address_sanitizer)``. Suppressing Errors in Recompiled Code (Blacklist) - Modified: cfe/trunk/docs/MemorySanitizer.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/MemorySanitizer.rst?rev=250674&r1=250673&r2=250674&view=diff == --- cfe/trunk/docs/MemorySanitizer.rst (original) +++ cfe/trunk/docs/MemorySanitizer.rst Sun Oct 18 20:24:08 2015 @@ -80,14 +80,11 @@ whether MemorySanitizer is enabled. :ref ``__attribute__((no_sanitize_memory))`` --- -Some code should not be checked by MemorySanitizer. -One may use the function attribute -:ref:`no_sanitize_memory ` -to disable uninitialized checks in a particular function. -MemorySanitizer may still instrument such functions to avoid false positives. -This attribute may not be -supported by other compilers, so we suggest to use it together with -``__has_feature(memory_sanitizer)``. +Some code should not be checked by MemorySanitizer. One may use the function +attribute `no_sanitize_memory` to disable uninitialized checks in a particular +function. MemorySanitizer may still instrument such functions to avoid false +positives. This attribute may not be supported by other compilers, so we +suggest to use it together with ``__has_feature(memory_sanitizer)``. Blacklist - Modified: cfe/trunk/docs/ThreadSanitizer.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ThreadSanitizer.rst?rev=250674&r1=250673&r2=250674&view=diff == --- cfe/trunk/docs/ThreadSanitizer.rst (original) +++ cfe/trunk/docs/ThreadSanitizer.rst Sun Oct 18 20:24:08 2015 @@ -86,25 +86,22 @@ this purpose. ``__attribute__((no_sanitize_thread))`` --- -Some code should not be instrumented by ThreadSanitizer. -One may use the function attribute -:ref:`no_sanitize_thread ` -to disable instrumentation of plain (non-atomic) loads/stores in a particular function. -ThreadSanitizer still instruments such functions to avoid false positives and -provide meaningful stack traces. -This attribute may not be -supported by other compilers, so we suggest to use it together with -``__has_feature(thread_sanitizer)``. +Some code should not be instrumented by ThreadSanitizer. One may use the +function attribute `no_sanitize_thread` to disable instrumentation of plain +(non-atomic) loads/stores in a particular function. ThreadSanitizer still +instruments such functions to avoid false positives and provide meaningful stack +traces. This attribute may not be supported by other compilers, so we suggest +to use it together with ``__has_feature(thread_sanitizer)``. Blacklist - ThreadSanitizer supports ``src`` and ``fun`` entity types in -:doc:`SanitizerSpecialCaseList`, that can be used to suppress data race reports in -the specified source files or functions. Unlike functions marked with -:ref:`no_sanitize_thread ` attribute, -blacklisted functions are not instrumented at all. This can lead to false positives -due to missed synchronization via atomic operations and missed stack frames in reports. +:doc:`SanitizerSp
r250675 - clang-format: Extend main header include sorting heuristic to Objective-C files.
Author: nico Date: Sun Oct 18 20:36:09 2015 New Revision: 250675 URL: http://llvm.org/viewvc/llvm-project?rev=250675&view=rev Log: clang-format: Extend main header include sorting heuristic to Objective-C files. Modified: cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/SortIncludesTest.cpp Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=250675&r1=250674&r2=250675&view=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Sun Oct 18 20:36:09 2015 @@ -1747,7 +1747,9 @@ tooling::Replacements sortIncludes(const FileName.endswith(".cc") || FileName.endswith(".cpp")|| FileName.endswith(".c++")|| - FileName.endswith(".cxx"); + FileName.endswith(".cxx") || + FileName.endswith(".m")|| + FileName.endswith(".mm"); // Create pre-compiled regular expressions for the #include categories. SmallVector CategoryRegexs; Modified: cfe/trunk/unittests/Format/SortIncludesTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortIncludesTest.cpp?rev=250675&r1=250674&r2=250675&view=diff == --- cfe/trunk/unittests/Format/SortIncludesTest.cpp (original) +++ cfe/trunk/unittests/Format/SortIncludesTest.cpp Sun Oct 18 20:36:09 2015 @@ -122,6 +122,13 @@ TEST_F(SortIncludesTest, LeavesMainHeade sort("#include \"llvm/a.h\"\n" "#include \"c.h\"\n" "#include \"b.h\"\n")); + EXPECT_EQ("#include \"llvm/a.h\"\n" +"#include \"b.h\"\n" +"#include \"c.h\"\n", +sort("#include \"llvm/a.h\"\n" + "#include \"c.h\"\n" + "#include \"b.h\"\n", + "input.mm")); // Don't do this in headers. EXPECT_EQ("#include \"b.h\"\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r248782 - clang-format: Extend #include sorting functionality
On Tue, Sep 29, 2015 at 12:53 AM, Daniel Jasper via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: djasper > Date: Tue Sep 29 02:53:08 2015 > New Revision: 248782 > > URL: http://llvm.org/viewvc/llvm-project?rev=248782&view=rev > Log: > clang-format: Extend #include sorting functionality > > Recognize the main module header as well as different #include categories. > This should now mimic the behavior of llvm/utils/sort_includes.py as > well as clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp very > closely. > > Modified: > cfe/trunk/include/clang/Format/Format.h > cfe/trunk/lib/Format/Format.cpp > cfe/trunk/tools/clang-format/ClangFormat.cpp > cfe/trunk/unittests/Format/SortIncludesTest.cpp > > Modified: cfe/trunk/include/clang/Format/Format.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=248782&r1=248781&r2=248782&view=diff > > == > --- cfe/trunk/include/clang/Format/Format.h (original) > +++ cfe/trunk/include/clang/Format/Format.h Tue Sep 29 02:53:08 2015 > @@ -259,6 +259,21 @@ struct FormatStyle { >/// For example: BOOST_FOREACH. >std::vector ForEachMacros; > > + /// \brief Regular expressions denoting the different #include > categories used > + /// for ordering #includes. > + /// > + /// These regular expressions are matched against the filename of an > include > + /// (including the <> or "") in order. The value belonging to the first > + /// matching regular expression is assigned and #includes are sorted > first > + /// according to increasing category number and then alphabetically > within > + /// each category. > + /// > + /// If none of the regular expressions match, UINT_MAX is assigned as > + /// category. The main header for a source file automatically gets > category 0, > + /// so that it is kept at the beginning of the #includes > + /// (http://llvm.org/docs/CodingStandards.html#include-style). > + std::vector> IncludeCategories; > + >/// \brief Indent case labels one level from the switch statement. >/// >/// When \c false, use the same indentation level as for the switch > statement. > > Modified: cfe/trunk/lib/Format/Format.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=248782&r1=248781&r2=248782&view=diff > > == > --- cfe/trunk/lib/Format/Format.cpp (original) > +++ cfe/trunk/lib/Format/Format.cpp Tue Sep 29 02:53:08 2015 > @@ -13,6 +13,7 @@ > /// > > > //===--===// > > +#include "clang/Format/Format.h" > #include "ContinuationIndenter.h" > #include "TokenAnnotator.h" > #include "UnwrappedLineFormatter.h" > @@ -21,7 +22,6 @@ > #include "clang/Basic/Diagnostic.h" > #include "clang/Basic/DiagnosticOptions.h" > #include "clang/Basic/SourceManager.h" > -#include "clang/Format/Format.h" > #include "clang/Lex/Lexer.h" > #include "llvm/ADT/STLExtras.h" > #include "llvm/Support/Allocator.h" > @@ -375,6 +375,9 @@ FormatStyle getLLVMStyle() { >LLVMStyle.ForEachMacros.push_back("foreach"); >LLVMStyle.ForEachMacros.push_back("Q_FOREACH"); >LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH"); > + LLVMStyle.IncludeCategories = {{"^\"(llvm|llvm-c|clang|clang-c)/", 2}, > + {"^(<|\"(gtest|isl|json)/)", 3}, > + {".*", 1}}; >LLVMStyle.IndentCaseLabels = false; >LLVMStyle.IndentWrappedFunctionNames = false; >LLVMStyle.IndentWidth = 2; > @@ -423,6 +426,7 @@ FormatStyle getGoogleStyle(FormatStyle:: >GoogleStyle.AlwaysBreakTemplateDeclarations = true; >GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true; >GoogleStyle.DerivePointerAlignment = true; > + GoogleStyle.IncludeCategories = {{"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", > 3}}; >GoogleStyle.IndentCaseLabels = true; >GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false; >GoogleStyle.ObjCSpaceAfterProperty = false; > @@ -1575,7 +1579,7 @@ struct IncludeDirective { >StringRef Filename; >StringRef Text; >unsigned Offset; > - bool IsAngled; > + unsigned Category; > }; > > } // end anonymous namespace > @@ -1605,7 +1609,8 @@ static void sortIncludes(const FormatSty >for (unsigned i = 0, e = Includes.size(); i != e; ++i) > Indices.push_back(i); >std::sort(Indices.begin(), Indices.end(), [&](unsigned LHSI, unsigned > RHSI) { > -return Includes[LHSI].Filename < Includes[RHSI].Filename; > +return std::tie(Includes[LHSI].Category, Includes[LHSI].Filename) < > + std::tie(Includes[RHSI].Category, Includes[RHSI].Filename); >}); > >// If the #includes are out of order, we generate a single replacement > fixing > @@ -1642,22 +1647,49 @@ tooling::Replacements sortIncludes(const >tooling::Replacements Replaces; >
[PATCH] D13853: clang-format: Treat --sort-includes that #include and #import mean the same thing.
thakis created this revision. thakis added a reviewer: djasper. thakis added a subscriber: cfe-commits. Herald added a subscriber: klimek. clang accepts both #include and #import for includes (the latter having an implicit header guard). Let clang-format interleave both types if --sort-includes is passed. #import is used frequently in Objective-C code. http://reviews.llvm.org/D13853 Files: lib/Format/Format.cpp unittests/Format/SortIncludesTest.cpp Index: unittests/Format/SortIncludesTest.cpp === --- unittests/Format/SortIncludesTest.cpp +++ unittests/Format/SortIncludesTest.cpp @@ -40,6 +40,16 @@ "#include \"b.h\"\n")); } +TEST_F(SortIncludesTest, MixIncludeAndImport) { + EXPECT_EQ("#include \"a.h\"\n" +"#import \"b.h\"\n" +"#include \"c.h\"\n", +sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#import \"b.h\"\n")); +} + + TEST_F(SortIncludesTest, FixTrailingComments) { EXPECT_EQ("#include \"a.h\" // comment\n" "#include \"bb.h\" // comment\n" Index: lib/Format/Format.cpp === --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -1732,7 +1732,7 @@ unsigned Prev = 0; unsigned SearchFrom = 0; llvm::Regex IncludeRegex( - R"(^[\t\ ]*#[\t\ ]*include[^"<]*(["<][^">]*[">]))"); + R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))"); SmallVector Matches; SmallVector IncludesInBlock; @@ -1762,20 +1762,21 @@ Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev); if (!Line.endswith("\\")) { if (IncludeRegex.match(Line, &Matches)) { +StringRef IncludeName = Matches[2]; unsigned Category; -if (LookForMainHeader && !Matches[1].startswith("<")) { +if (LookForMainHeader && !IncludeName.startswith("<")) { Category = 0; } else { Category = UINT_MAX; for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i) { -if (CategoryRegexs[i].match(Matches[1])) { +if (CategoryRegexs[i].match(IncludeName)) { Category = Style.IncludeCategories[i].Priority; break; } } } LookForMainHeader = false; -IncludesInBlock.push_back({Matches[1], Line, Prev, Category}); +IncludesInBlock.push_back({IncludeName, Line, Prev, Category}); } else if (!IncludesInBlock.empty()) { sortIncludes(Style, IncludesInBlock, Ranges, FileName, Replaces); IncludesInBlock.clear(); Index: unittests/Format/SortIncludesTest.cpp === --- unittests/Format/SortIncludesTest.cpp +++ unittests/Format/SortIncludesTest.cpp @@ -40,6 +40,16 @@ "#include \"b.h\"\n")); } +TEST_F(SortIncludesTest, MixIncludeAndImport) { + EXPECT_EQ("#include \"a.h\"\n" +"#import \"b.h\"\n" +"#include \"c.h\"\n", +sort("#include \"a.h\"\n" + "#include \"c.h\"\n" + "#import \"b.h\"\n")); +} + + TEST_F(SortIncludesTest, FixTrailingComments) { EXPECT_EQ("#include \"a.h\" // comment\n" "#include \"bb.h\" // comment\n" Index: lib/Format/Format.cpp === --- lib/Format/Format.cpp +++ lib/Format/Format.cpp @@ -1732,7 +1732,7 @@ unsigned Prev = 0; unsigned SearchFrom = 0; llvm::Regex IncludeRegex( - R"(^[\t\ ]*#[\t\ ]*include[^"<]*(["<][^">]*[">]))"); + R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))"); SmallVector Matches; SmallVector IncludesInBlock; @@ -1762,20 +1762,21 @@ Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev); if (!Line.endswith("\\")) { if (IncludeRegex.match(Line, &Matches)) { +StringRef IncludeName = Matches[2]; unsigned Category; -if (LookForMainHeader && !Matches[1].startswith("<")) { +if (LookForMainHeader && !IncludeName.startswith("<")) { Category = 0; } else { Category = UINT_MAX; for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i) { -if (CategoryRegexs[i].match(Matches[1])) { +if (CategoryRegexs[i].match(IncludeName)) { Category = Style.IncludeCategories[i].Priority; break; } } } LookForMainHeader = false; -IncludesInBlock.push_back({Matches[1], Line, Prev, Category}); +IncludesInBlock.push_back({IncludeName, Line, Prev, Category}); } else if (!IncludesInBlock.empty()) { sortIncludes(Style, IncludesInBlock, Ranges, FileName, Replaces); IncludesInBlock.clear(); ___ cfe-commits mailing list
Re: [PATCH] D13853: clang-format: Treat --sort-includes that #include and #import mean the same thing.
thakis added inline comments. Comment at: lib/Format/Format.cpp:1735 @@ -1734,3 +1734,3 @@ llvm::Regex IncludeRegex( - R"(^[\t\ ]*#[\t\ ]*include[^"<]*(["<][^">]*[">]))"); + R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))"); SmallVector Matches; llvm's Regex class doesn't support non-capturing groups (`(?:foo|bar)`) as far as I can tell, so I changed Matches[1] to Matches[2] below. http://reviews.llvm.org/D13853 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r250676 - Return an ArrayRef instead of having two out parameters of a pointer and length. NFC
Author: ctopper Date: Sun Oct 18 22:05:12 2015 New Revision: 250676 URL: http://llvm.org/viewvc/llvm-project?rev=250676&view=rev Log: Return an ArrayRef instead of having two out parameters of a pointer and length. NFC Modified: cfe/trunk/include/clang/Basic/TargetInfo.h cfe/trunk/lib/Basic/TargetInfo.cpp cfe/trunk/lib/Basic/Targets.cpp Modified: cfe/trunk/include/clang/Basic/TargetInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=250676&r1=250675&r2=250676&view=diff == --- cfe/trunk/include/clang/Basic/TargetInfo.h (original) +++ cfe/trunk/include/clang/Basic/TargetInfo.h Sun Oct 18 22:05:12 2015 @@ -930,14 +930,10 @@ protected: virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { return PtrDiffType; } - virtual void getGCCRegNames(const char * const *&Names, - unsigned &NumNames) const = 0; - virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, -unsigned &NumAliases) const = 0; - virtual void getGCCAddlRegNames(const AddlRegName *&Addl, - unsigned &NumAddl) const { -Addl = nullptr; -NumAddl = 0; + virtual ArrayRef getGCCRegNames() const = 0; + virtual ArrayRef getGCCRegAliases() const = 0; + virtual ArrayRef getGCCAddlRegNames() const { +return None; } }; Modified: cfe/trunk/lib/Basic/TargetInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=250676&r1=250675&r2=250676&view=diff == --- cfe/trunk/lib/Basic/TargetInfo.cpp (original) +++ cfe/trunk/lib/Basic/TargetInfo.cpp Sun Oct 18 22:05:12 2015 @@ -349,49 +349,41 @@ bool TargetInfo::isValidGCCRegisterName( if (Name.empty()) return false; - const char * const *Names; - unsigned NumNames; - // Get rid of any register prefix. Name = removeGCCRegisterPrefix(Name); if (Name.empty()) return false; - getGCCRegNames(Names, NumNames); + ArrayRef Names = getGCCRegNames(); // If we have a number it maps to an entry in the register name array. if (isDigit(Name[0])) { int n; if (!Name.getAsInteger(0, n)) - return n >= 0 && (unsigned)n < NumNames; + return n >= 0 && (unsigned)n < Names.size(); } // Check register names. - for (unsigned i = 0; i < NumNames; i++) { + for (unsigned i = 0; i < Names.size(); i++) { if (Name == Names[i]) return true; } // Check any additional names that we have. - const AddlRegName *AddlNames; - unsigned NumAddlNames; - getGCCAddlRegNames(AddlNames, NumAddlNames); - for (unsigned i = 0; i < NumAddlNames; i++) + ArrayRef AddlNames = getGCCAddlRegNames(); + for (unsigned i = 0; i < AddlNames.size(); i++) for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) { if (!AddlNames[i].Names[j]) break; // Make sure the register that the additional name is for is within // the bounds of the register names from above. - if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames) + if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < Names.size()) return true; } // Now check aliases. - const GCCRegAlias *Aliases; - unsigned NumAliases; - - getGCCRegAliases(Aliases, NumAliases); - for (unsigned i = 0; i < NumAliases; i++) { + ArrayRef Aliases = getGCCRegAliases(); + for (unsigned i = 0; i < Aliases.size(); i++) { for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) { if (!Aliases[i].Aliases[j]) break; @@ -410,41 +402,33 @@ TargetInfo::getNormalizedGCCRegisterName // Get rid of any register prefix. Name = removeGCCRegisterPrefix(Name); - const char * const *Names; - unsigned NumNames; - - getGCCRegNames(Names, NumNames); + ArrayRef Names = getGCCRegNames(); // First, check if we have a number. if (isDigit(Name[0])) { int n; if (!Name.getAsInteger(0, n)) { - assert(n >= 0 && (unsigned)n < NumNames && + assert(n >= 0 && (unsigned)n < Names.size() && "Out of bounds register number!"); return Names[n]; } } // Check any additional names that we have. - const AddlRegName *AddlNames; - unsigned NumAddlNames; - getGCCAddlRegNames(AddlNames, NumAddlNames); - for (unsigned i = 0; i < NumAddlNames; i++) + ArrayRef AddlNames = getGCCAddlRegNames(); + for (unsigned i = 0; i < AddlNames.size(); i++) for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) { if (!AddlNames[i].Names[j]) break; // Make sure the register that the additional name is for is within // the bounds of the register names from above. - if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames) + if (AddlNames[i].Names[j] == Nam
Re: r250473 - Add an error when calling a builtin that requires features that don't
No worries! :) On Sun, Oct 18, 2015, 5:42 PM Justin Bogner wrote: > Eric Christopher writes: > > I'm reasonably certain you forgot to rebuild or ran make test in the > wrong > > directory. > > You're right, I did something funny there. Sorry for the noise. > > > Two reasons: > > > > a) This is pretty much my first patch. I mean, identical and I tried > that. > > b) I actually tried this one and got: > > > > Testing Time: 217.41s > > > > Failing Tests (68): > > Clang :: CodeGen/3dnow-builtins.c > > Clang :: CodeGen/adc-builtins.c > > Clang :: CodeGen/adx-builtins.c > > Clang :: CodeGen/attr-target-x86-mmx.c > > Clang :: CodeGen/avx-builtins.c > > Clang :: CodeGen/avx-cmp-builtins.c > > Clang :: CodeGen/avx-shuffle-builtins.c > > Clang :: CodeGen/avx2-builtins.c > > Clang :: CodeGen/avx512bw-builtins.c > > Clang :: CodeGen/avx512cdintrin.c > > Clang :: CodeGen/avx512dq-builtins.c > > Clang :: CodeGen/avx512er-builtins.c > > Clang :: CodeGen/avx512f-builtins.c > > Clang :: CodeGen/avx512vl-builtins.c > > Clang :: CodeGen/avx512vlbw-builtins.c > > Clang :: CodeGen/avx512vldq-builtins.c > > Clang :: CodeGen/bmi-builtins.c > > Clang :: CodeGen/bmi2-builtins.c > > Clang :: CodeGen/builtins-x86.c > > Clang :: CodeGen/f16c-builtins.c > > Clang :: CodeGen/fma-builtins.c > > Clang :: CodeGen/fma4-builtins.c > > Clang :: CodeGen/fsgsbase-builtins.c > > Clang :: CodeGen/lzcnt-builtins.c > > Clang :: CodeGen/mmx-builtins.c > > Clang :: CodeGen/mmx-inline-asm.c > > Clang :: CodeGen/mmx-shift-with-immediate.c > > Clang :: CodeGen/ms-intrinsics.c > > Clang :: CodeGen/ms-mm-align.c > > Clang :: CodeGen/palignr.c > > Clang :: CodeGen/pclmul-builtins.c > > Clang :: CodeGen/popcnt-builtins.c > > Clang :: CodeGen/prefetchw-builtins.c > > Clang :: CodeGen/rdrand-builtins.c > > Clang :: CodeGen/rtm-builtins.c > > Clang :: CodeGen/sha-builtins.c > > Clang :: CodeGen/sse-builtins-dbg.c > > Clang :: CodeGen/sse-builtins.c > > Clang :: CodeGen/sse.c > > Clang :: CodeGen/sse3-builtins.c > > Clang :: CodeGen/sse41-builtins.c > > Clang :: CodeGen/sse42-builtins.c > > Clang :: CodeGen/sse4a-builtins.c > > Clang :: CodeGen/ssse3-builtins.c > > Clang :: CodeGen/target-builtin-error-2.c > > Clang :: CodeGen/target-builtin-error.c > > Clang :: CodeGen/target-builtin-noerror.c > > Clang :: CodeGen/tbm-builtins.c > > Clang :: CodeGen/vector.c > > Clang :: CodeGen/x86_32-xsave.c > > Clang :: CodeGen/x86_64-xsave.c > > Clang :: CodeGen/xop-builtins.c > > Clang :: CodeGenCXX/mangle-ms-vector-types.cpp > > Clang :: Headers/c89.c > > Clang :: Headers/ms-intrin.cpp > > Clang :: Headers/pmmintrin.c > > Clang :: Headers/wmmintrin.c > > Clang :: Headers/x86-intrinsics-headers.c > > Clang :: Headers/x86intrin-2.c > > Clang :: Headers/x86intrin.c > > Clang :: Headers/xmmintrin.c > > Clang :: Integration/carbon.c > > Clang :: Integration/cocoa-pch.m > > Clang :: Integration/cocoa.m > > Clang :: Modules/compiler_builtins.m > > Clang :: Sema/builtins-x86.c > > Clang :: Sema/warn-shadow-intrinsics.c > > Clang :: Sema/x86-builtin-palignr.c > > > > Expected Passes: 8545 > > Expected Failures : 15 > > Unsupported Tests : 15 > > Unexpected Failures: 68 > > > > with lots of failures that look like: > > > > In file included from > > > /Users/echristo/builds/build-llvm/Debug+Asserts/bin/../lib/clang/3.8.0/include/immintrin.h:143: > > > /Users/echristo/builds/build-llvm/Debug+Asserts/bin/../lib/clang/3.8.0/include/shaintrin.h:40:19: > > error: '__builtin_ia32_sha1nexte' needs target feature sha > > return (__m128i)__builtin_ia32_sha1nexte((__v4si)__X, (__v4si)__Y); > > ^ > > > > for files that include more headers than they need (think x86intrin.h > being > > the only header included), but not calling any of the functions and so > not > > using a command line option that enables every feature for the x86 > target. > > > > -eric > > > > On Sat, Oct 17, 2015 at 2:11 AM Justin Bogner > wrote: > > > >> Eric Christopher writes: > >> > Can't be. We don't know we're going to make the call until we code > gen. > >> :) > >> > >> Okay... but then why don't any tests fail with the attached? It looks > >> like it does the right thing in a very cursory test, as well. > >> > >> > >> > On Fri, Oct 16, 2015, 7:50 PM Justin Bogner > >> wrote: > >> > > >> >> Eric Christopher via cfe-commits > writes: > >> >> > Author: echristo > >> >> > Date: Thu Oct 15 18:47:11 2015 > >> >> > New Revision: 250473 > >> >> > > >> >> > URL: http://llvm.org/viewvc/llvm-project?rev=250473&view=rev > >> >> > Log: > >> >> > Add an error when calling a builtin that requires features that > don't > >> >> > match the feature set of the function that they're being called > from. >
r250677 - Revert r250676 "Return an ArrayRef instead of having two out parameters of a pointer and length. NFC"
Author: ctopper Date: Sun Oct 18 22:17:00 2015 New Revision: 250677 URL: http://llvm.org/viewvc/llvm-project?rev=250677&view=rev Log: Revert r250676 "Return an ArrayRef instead of having two out parameters of a pointer and length. NFC" Modified: cfe/trunk/include/clang/Basic/TargetInfo.h cfe/trunk/lib/Basic/TargetInfo.cpp cfe/trunk/lib/Basic/Targets.cpp Modified: cfe/trunk/include/clang/Basic/TargetInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=250677&r1=250676&r2=250677&view=diff == --- cfe/trunk/include/clang/Basic/TargetInfo.h (original) +++ cfe/trunk/include/clang/Basic/TargetInfo.h Sun Oct 18 22:17:00 2015 @@ -930,10 +930,14 @@ protected: virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { return PtrDiffType; } - virtual ArrayRef getGCCRegNames() const = 0; - virtual ArrayRef getGCCRegAliases() const = 0; - virtual ArrayRef getGCCAddlRegNames() const { -return None; + virtual void getGCCRegNames(const char * const *&Names, + unsigned &NumNames) const = 0; + virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, +unsigned &NumAliases) const = 0; + virtual void getGCCAddlRegNames(const AddlRegName *&Addl, + unsigned &NumAddl) const { +Addl = nullptr; +NumAddl = 0; } }; Modified: cfe/trunk/lib/Basic/TargetInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=250677&r1=250676&r2=250677&view=diff == --- cfe/trunk/lib/Basic/TargetInfo.cpp (original) +++ cfe/trunk/lib/Basic/TargetInfo.cpp Sun Oct 18 22:17:00 2015 @@ -349,41 +349,49 @@ bool TargetInfo::isValidGCCRegisterName( if (Name.empty()) return false; + const char * const *Names; + unsigned NumNames; + // Get rid of any register prefix. Name = removeGCCRegisterPrefix(Name); if (Name.empty()) return false; - ArrayRef Names = getGCCRegNames(); + getGCCRegNames(Names, NumNames); // If we have a number it maps to an entry in the register name array. if (isDigit(Name[0])) { int n; if (!Name.getAsInteger(0, n)) - return n >= 0 && (unsigned)n < Names.size(); + return n >= 0 && (unsigned)n < NumNames; } // Check register names. - for (unsigned i = 0; i < Names.size(); i++) { + for (unsigned i = 0; i < NumNames; i++) { if (Name == Names[i]) return true; } // Check any additional names that we have. - ArrayRef AddlNames = getGCCAddlRegNames(); - for (unsigned i = 0; i < AddlNames.size(); i++) + const AddlRegName *AddlNames; + unsigned NumAddlNames; + getGCCAddlRegNames(AddlNames, NumAddlNames); + for (unsigned i = 0; i < NumAddlNames; i++) for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) { if (!AddlNames[i].Names[j]) break; // Make sure the register that the additional name is for is within // the bounds of the register names from above. - if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < Names.size()) + if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames) return true; } // Now check aliases. - ArrayRef Aliases = getGCCRegAliases(); - for (unsigned i = 0; i < Aliases.size(); i++) { + const GCCRegAlias *Aliases; + unsigned NumAliases; + + getGCCRegAliases(Aliases, NumAliases); + for (unsigned i = 0; i < NumAliases; i++) { for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) { if (!Aliases[i].Aliases[j]) break; @@ -402,33 +410,41 @@ TargetInfo::getNormalizedGCCRegisterName // Get rid of any register prefix. Name = removeGCCRegisterPrefix(Name); - ArrayRef Names = getGCCRegNames(); + const char * const *Names; + unsigned NumNames; + + getGCCRegNames(Names, NumNames); // First, check if we have a number. if (isDigit(Name[0])) { int n; if (!Name.getAsInteger(0, n)) { - assert(n >= 0 && (unsigned)n < Names.size() && + assert(n >= 0 && (unsigned)n < NumNames && "Out of bounds register number!"); return Names[n]; } } // Check any additional names that we have. - ArrayRef AddlNames = getGCCAddlRegNames(); - for (unsigned i = 0; i < AddlNames.size(); i++) + const AddlRegName *AddlNames; + unsigned NumAddlNames; + getGCCAddlRegNames(AddlNames, NumAddlNames); + for (unsigned i = 0; i < NumAddlNames; i++) for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) { if (!AddlNames[i].Names[j]) break; // Make sure the register that the additional name is for is within // the bounds of the register names from above. - if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < Names.size()) + if (AddlNam
[PATCH] D13854: Template class: emit better diagnostic in case of missing template argument list
davide created this revision. davide added a reviewer: rsmith. davide added a subscriber: cfe-commits. davide set the repository for this revision to rL LLVM. Richard, this implements what you proposed in https://llvm.org/bugs/show_bug.cgi?id=25223 , hopefully in the correct way. This is what we emit now: template.cpp:7:3: error: missing template argument list for class template 'X' T X::foo(void) ^ X template.cpp:2:7: note: 'X' declared here class X { ^ 1 error generated. I will tackle the case where we emit a terrible diagnostic for ambigous lookup separately. Repository: rL LLVM http://reviews.llvm.org/D13854 Files: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaCXXScopeSpec.cpp test/SemaTemplate/temp_arg_lookup.cpp Index: test/SemaTemplate/temp_arg_lookup.cpp === --- test/SemaTemplate/temp_arg_lookup.cpp +++ test/SemaTemplate/temp_arg_lookup.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template +class X { // expected-note{{declared here}} + T foo(void); +}; + +template +T X::foo(void) // expected-error{{missing template argument list for class template}}} +{ + return 0; +} Index: lib/Sema/SemaCXXScopeSpec.cpp === --- lib/Sema/SemaCXXScopeSpec.cpp +++ lib/Sema/SemaCXXScopeSpec.cpp @@ -771,9 +771,29 @@ } if (!Found.empty()) { -if (TypeDecl *TD = Found.getAsSingle()) +if (ClassTemplateDecl *CTD = Found.getAsSingle()) { + TemplateParameterList *TPL = CTD->getTemplateParameters(); + assert(TPL && "NULL template parameter list"); + std::string FixString = Identifier.getName(); + FixString += "<"; + bool FirstArg = true; + for (NamedDecl *TemplArg : *TPL) { +if (FirstArg) + FirstArg = false; +else + FixString += ", "; +FixString += TemplArg->getName(); + } + FixString += ">"; + Diag(IdentifierLoc, diag::err_missing_argument_list) << &Identifier + << FixItHint::CreateReplacement(IdentifierLoc, FixString); + if (NamedDecl *ND = Found.getAsSingle()) +Diag(ND->getLocation(), diag::note_entity_declared_at) << &Identifier; +} +else if (TypeDecl *TD = Found.getAsSingle()) { Diag(IdentifierLoc, diag::err_expected_class_or_namespace) << QualType(TD->getTypeForDecl(), 0) << getLangOpts().CPlusPlus; +} else { Diag(IdentifierLoc, diag::err_expected_class_or_namespace) << &Identifier << getLangOpts().CPlusPlus; Index: include/clang/Basic/DiagnosticSemaKinds.td === --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -5831,6 +5831,8 @@ def err_expected_class_or_namespace : Error<"%0 is not a class" "%select{ or namespace|, namespace, or enumeration}1">; +def err_missing_argument_list : Error<"missing template argument list for " + "class template %0">; def err_invalid_declarator_scope : Error<"cannot define or redeclare %0 here " "because namespace %1 does not enclose namespace %2">; def err_invalid_declarator_global_scope : Error< Index: test/SemaTemplate/temp_arg_lookup.cpp === --- test/SemaTemplate/temp_arg_lookup.cpp +++ test/SemaTemplate/temp_arg_lookup.cpp @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +template +class X { // expected-note{{declared here}} + T foo(void); +}; + +template +T X::foo(void) // expected-error{{missing template argument list for class template}}} +{ + return 0; +} Index: lib/Sema/SemaCXXScopeSpec.cpp === --- lib/Sema/SemaCXXScopeSpec.cpp +++ lib/Sema/SemaCXXScopeSpec.cpp @@ -771,9 +771,29 @@ } if (!Found.empty()) { -if (TypeDecl *TD = Found.getAsSingle()) +if (ClassTemplateDecl *CTD = Found.getAsSingle()) { + TemplateParameterList *TPL = CTD->getTemplateParameters(); + assert(TPL && "NULL template parameter list"); + std::string FixString = Identifier.getName(); + FixString += "<"; + bool FirstArg = true; + for (NamedDecl *TemplArg : *TPL) { +if (FirstArg) + FirstArg = false; +else + FixString += ", "; +FixString += TemplArg->getName(); + } + FixString += ">"; + Diag(IdentifierLoc, diag::err_missing_argument_list) << &Identifier + << FixItHint::CreateReplacement(IdentifierLoc, FixString); + if (NamedDecl *ND = Found.getAsSingle()) +Diag(ND->getLocation(), diag::note_entity_declared_at) << &Identifier; +} +else if (TypeDecl *TD = Found.getAsSingle()) { Diag(IdentifierLoc, diag::err_expected_class_or_namespace) << QualType(TD->getTypeForDecl(), 0) << getLangOpts().CPlusPlus; +} else { Diag(Identi
r250678 - Recommit "Return an ArrayRef instead of having two out parameters of a pointer and length. NFC". Hopefully this time the bots will be happy.
Author: ctopper Date: Sun Oct 18 22:52:27 2015 New Revision: 250678 URL: http://llvm.org/viewvc/llvm-project?rev=250678&view=rev Log: Recommit "Return an ArrayRef instead of having two out parameters of a pointer and length. NFC". Hopefully this time the bots will be happy. Modified: cfe/trunk/include/clang/Basic/TargetInfo.h cfe/trunk/lib/Basic/TargetInfo.cpp cfe/trunk/lib/Basic/Targets.cpp Modified: cfe/trunk/include/clang/Basic/TargetInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=250678&r1=250677&r2=250678&view=diff == --- cfe/trunk/include/clang/Basic/TargetInfo.h (original) +++ cfe/trunk/include/clang/Basic/TargetInfo.h Sun Oct 18 22:52:27 2015 @@ -930,14 +930,10 @@ protected: virtual enum IntType getPtrDiffTypeV(unsigned AddrSpace) const { return PtrDiffType; } - virtual void getGCCRegNames(const char * const *&Names, - unsigned &NumNames) const = 0; - virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, -unsigned &NumAliases) const = 0; - virtual void getGCCAddlRegNames(const AddlRegName *&Addl, - unsigned &NumAddl) const { -Addl = nullptr; -NumAddl = 0; + virtual ArrayRef getGCCRegNames() const = 0; + virtual ArrayRef getGCCRegAliases() const = 0; + virtual ArrayRef getGCCAddlRegNames() const { +return None; } }; Modified: cfe/trunk/lib/Basic/TargetInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=250678&r1=250677&r2=250678&view=diff == --- cfe/trunk/lib/Basic/TargetInfo.cpp (original) +++ cfe/trunk/lib/Basic/TargetInfo.cpp Sun Oct 18 22:52:27 2015 @@ -349,49 +349,41 @@ bool TargetInfo::isValidGCCRegisterName( if (Name.empty()) return false; - const char * const *Names; - unsigned NumNames; - // Get rid of any register prefix. Name = removeGCCRegisterPrefix(Name); if (Name.empty()) return false; - getGCCRegNames(Names, NumNames); + ArrayRef Names = getGCCRegNames(); // If we have a number it maps to an entry in the register name array. if (isDigit(Name[0])) { int n; if (!Name.getAsInteger(0, n)) - return n >= 0 && (unsigned)n < NumNames; + return n >= 0 && (unsigned)n < Names.size(); } // Check register names. - for (unsigned i = 0; i < NumNames; i++) { + for (unsigned i = 0; i < Names.size(); i++) { if (Name == Names[i]) return true; } // Check any additional names that we have. - const AddlRegName *AddlNames; - unsigned NumAddlNames; - getGCCAddlRegNames(AddlNames, NumAddlNames); - for (unsigned i = 0; i < NumAddlNames; i++) + ArrayRef AddlNames = getGCCAddlRegNames(); + for (unsigned i = 0; i < AddlNames.size(); i++) for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) { if (!AddlNames[i].Names[j]) break; // Make sure the register that the additional name is for is within // the bounds of the register names from above. - if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames) + if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < Names.size()) return true; } // Now check aliases. - const GCCRegAlias *Aliases; - unsigned NumAliases; - - getGCCRegAliases(Aliases, NumAliases); - for (unsigned i = 0; i < NumAliases; i++) { + ArrayRef Aliases = getGCCRegAliases(); + for (unsigned i = 0; i < Aliases.size(); i++) { for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) { if (!Aliases[i].Aliases[j]) break; @@ -410,41 +402,33 @@ TargetInfo::getNormalizedGCCRegisterName // Get rid of any register prefix. Name = removeGCCRegisterPrefix(Name); - const char * const *Names; - unsigned NumNames; - - getGCCRegNames(Names, NumNames); + ArrayRef Names = getGCCRegNames(); // First, check if we have a number. if (isDigit(Name[0])) { int n; if (!Name.getAsInteger(0, n)) { - assert(n >= 0 && (unsigned)n < NumNames && + assert(n >= 0 && (unsigned)n < Names.size() && "Out of bounds register number!"); return Names[n]; } } // Check any additional names that we have. - const AddlRegName *AddlNames; - unsigned NumAddlNames; - getGCCAddlRegNames(AddlNames, NumAddlNames); - for (unsigned i = 0; i < NumAddlNames; i++) + ArrayRef AddlNames = getGCCAddlRegNames(); + for (unsigned i = 0; i < AddlNames.size(); i++) for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) { if (!AddlNames[i].Names[j]) break; // Make sure the register that the additional name is for is within // the bounds of the register names from above. - if (AddlNames[i].Names[j] == Name && AddlNames[i].Re
r250681 - Make getTargetBuiltins return an ArrayRef instead of having two out parameters of a pointer and length. NFC
Author: ctopper Date: Sun Oct 18 23:51:35 2015 New Revision: 250681 URL: http://llvm.org/viewvc/llvm-project?rev=250681&view=rev Log: Make getTargetBuiltins return an ArrayRef instead of having two out parameters of a pointer and length. NFC Modified: cfe/trunk/include/clang/Basic/Builtins.h cfe/trunk/include/clang/Basic/TargetInfo.h cfe/trunk/lib/Basic/Builtins.cpp cfe/trunk/lib/Basic/Targets.cpp Modified: cfe/trunk/include/clang/Basic/Builtins.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.h?rev=250681&r1=250680&r2=250681&view=diff == --- cfe/trunk/include/clang/Basic/Builtins.h (original) +++ cfe/trunk/include/clang/Basic/Builtins.h Sun Oct 18 23:51:35 2015 @@ -16,6 +16,7 @@ #ifndef LLVM_CLANG_BASIC_BUILTINS_H #define LLVM_CLANG_BASIC_BUILTINS_H +#include "llvm/ADT/ArrayRef.h" #include // VC++ defines 'alloca' as an object-like macro, which interferes with our @@ -58,16 +59,14 @@ struct Info { /// target-specific builtins, allowing easy queries by clients. /// /// Builtins from an optional auxiliary target are stored in -/// AuxTSRecords. Their IDs are shifted up by NumTSRecords and need to +/// AuxTSRecords. Their IDs are shifted up by TSRecords.size() and need to /// be translated back with getAuxBuiltinID() before use. class Context { - const Info *TSRecords; - const Info *AuxTSRecords; - unsigned NumTSRecords; - unsigned NumAuxTSRecords; + llvm::ArrayRef TSRecords; + llvm::ArrayRef AuxTSRecords; public: - Context(); + Context() {} /// \brief Perform target-specific initialization /// \param AuxTarget Target info to incorporate builtins from. May be nullptr. @@ -186,12 +185,12 @@ public: /// \brief Return true if builtin ID belongs to AuxTarget. bool isAuxBuiltinID(unsigned ID) const { -return ID >= (Builtin::FirstTSBuiltin + NumTSRecords); +return ID >= (Builtin::FirstTSBuiltin + TSRecords.size()); } /// Return real buitin ID (i.e. ID it would have furing compilation /// for AuxTarget). - unsigned getAuxBuiltinID(unsigned ID) const { return ID - NumTSRecords; } + unsigned getAuxBuiltinID(unsigned ID) const { return ID - TSRecords.size(); } private: const Info &getRecord(unsigned ID) const; Modified: cfe/trunk/include/clang/Basic/TargetInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=250681&r1=250680&r2=250681&view=diff == --- cfe/trunk/include/clang/Basic/TargetInfo.h (original) +++ cfe/trunk/include/clang/Basic/TargetInfo.h Sun Oct 18 23:51:35 2015 @@ -516,8 +516,7 @@ public: /// Return information about target-specific builtins for /// the current primary target, and info about which builtins are non-portable /// across the current set of primary and secondary targets. - virtual void getTargetBuiltins(const Builtin::Info *&Records, - unsigned &NumRecords) const = 0; + virtual ArrayRef getTargetBuiltins() const = 0; /// The __builtin_clz* and __builtin_ctz* built-in /// functions are specified to have undefined results for zero inputs, but Modified: cfe/trunk/lib/Basic/Builtins.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Builtins.cpp?rev=250681&r1=250680&r2=250681&view=diff == --- cfe/trunk/lib/Basic/Builtins.cpp (original) +++ cfe/trunk/lib/Basic/Builtins.cpp Sun Oct 18 23:51:35 2015 @@ -32,27 +32,20 @@ static const Builtin::Info BuiltinInfo[] const Builtin::Info &Builtin::Context::getRecord(unsigned ID) const { if (ID < Builtin::FirstTSBuiltin) return BuiltinInfo[ID]; - assert(ID - Builtin::FirstTSBuiltin < (NumTSRecords + NumAuxTSRecords) && + assert(((ID - Builtin::FirstTSBuiltin) < + (TSRecords.size() + AuxTSRecords.size())) && "Invalid builtin ID!"); if (isAuxBuiltinID(ID)) return AuxTSRecords[getAuxBuiltinID(ID) - Builtin::FirstTSBuiltin]; return TSRecords[ID - Builtin::FirstTSBuiltin]; } -Builtin::Context::Context() { - // Get the target specific builtins from the target. - TSRecords = nullptr; - AuxTSRecords = nullptr; - NumTSRecords = 0; - NumAuxTSRecords = 0; -} - void Builtin::Context::InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget) { - assert(NumTSRecords == 0 && "Already initialized target?"); - Target.getTargetBuiltins(TSRecords, NumTSRecords); + assert(TSRecords.empty() && "Already initialized target?"); + TSRecords = Target.getTargetBuiltins(); if (AuxTarget) -AuxTarget->getTargetBuiltins(AuxTSRecords, NumAuxTSRecords); +AuxTSRecords = AuxTarget->getTargetBuiltins(); } bool Builtin::Context::builtinIsSupported(const Builtin::Info &BuiltinInfo, @@ -82,14 +75,14 @@ void Builtin::Contex
Re: [PATCH] D7639: Add readability-redundant-void-arg check to clang-tidy
LegalizeAdulthood updated this revision to Diff 37717. http://reviews.llvm.org/D7639 Files: clang-tidy/readability/CMakeLists.txt clang-tidy/readability/ReadabilityTidyModule.cpp clang-tidy/readability/RedundantVoidArgCheck.cpp clang-tidy/readability/RedundantVoidArgCheck.h test/clang-tidy/readability-redundant-void-arg.c test/clang-tidy/readability-redundant-void-arg.cpp Index: test/clang-tidy/readability-redundant-void-arg.cpp === --- /dev/null +++ test/clang-tidy/readability-redundant-void-arg.cpp @@ -0,0 +1,419 @@ +// RUN: %python %S/check_clang_tidy.py %s readability-redundant-void-arg %t + +#include + +int foo(); + +void bar(); + +void bar2(); + +extern "C" void ecfoo(void); + +extern "C" void ecfoo(void) { +} + +extern int i; + +int j = 1; + +int foo(void) { +// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: redundant void argument list in function definition [readability-redundant-void-arg] +// CHECK-FIXES: {{^}}int foo() {{{$}} +return 0; +} + +typedef unsigned int my_uint; + +typedef void my_void; + +// A function taking void and returning a pointer to function taking void +// and returning int. +int (*returns_fn_void_int(void))(void); +// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} in function declaration +// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in function declaration +// CHECK-FIXES: {{^}}int (*returns_fn_void_int())();{{$}} + +typedef int (*returns_fn_void_int_t(void))(void); +// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: {{.*}} in typedef +// CHECK-MESSAGES: :[[@LINE-2]]:44: warning: {{.*}} in typedef +// CHECK-FIXES: {{^}}typedef int (*returns_fn_void_int_t())();{{$}} + +int (*returns_fn_void_int(void))(void) { +// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}} in function definition +// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: {{.*}} in function definition +// CHECK-FIXES: {{^}}int (*returns_fn_void_int())() {{{$}} + return nullptr; +} + +// A function taking void and returning a pointer to a function taking void +// and returning a pointer to a function taking void and returning void. +void (*(*returns_fn_returns_fn_void_void(void))(void))(void); +// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: {{.*}} in function declaration +// CHECK-MESSAGES: :[[@LINE-2]]:49: warning: {{.*}} in function declaration +// CHECK-MESSAGES: :[[@LINE-3]]:56: warning: {{.*}} in function declaration +// CHECK-FIXES: {{^}}void (*(*returns_fn_returns_fn_void_void())())();{{$}} + +typedef void (*(*returns_fn_returns_fn_void_void_t(void))(void))(void); +// CHECK-MESSAGES: :[[@LINE-1]]:52: warning: {{.*}} in typedef +// CHECK-MESSAGES: :[[@LINE-2]]:59: warning: {{.*}} in typedef +// CHECK-MESSAGES: :[[@LINE-3]]:66: warning: {{.*}} in typedef +// CHECK-FIXES: {{^}}typedef void (*(*returns_fn_returns_fn_void_void_t())())();{{$}} + +void (*(*returns_fn_returns_fn_void_void(void))(void))(void) { +// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: {{.*}} in function definition +// CHECK-MESSAGES: :[[@LINE-2]]:49: warning: {{.*}} in function definition +// CHECK-MESSAGES: :[[@LINE-3]]:56: warning: {{.*}} in function definition +// CHECK-FIXES: {{^}}void (*(*returns_fn_returns_fn_void_void())())() {{{$}} +return nullptr; +} + +void bar(void) { +// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: {{.*}} in function definition +// CHECK-FIXES: {{^}}void bar() {{{$}} +} + +void op_fn(int i) { +} + +class gronk { +public: + gronk(); + ~gronk(); + +void foo(); +void bar(); +void bar2 +(); +void operation(int i) { } + +private: +int m_i; +int *m_pi; +float m_f; +float *m_pf; +double m_d; +double *m_pd; + +void (*f1)(void); +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}} in field declaration +// CHECK-FIXES: {{^}}void (*f1)();{{$}} + + void (*op)(int i); + + void (gronk::*p1)(void); + // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}} in field declaration + // CHECK-FIXES: {{^ }}void (gronk::*p1)();{{$}} + + int (gronk::*p_mi); + + void (gronk::*p2)(int); + + void (*(*returns_fn_returns_fn_void_void(void))(void))(void); + // CHECK-MESSAGES: :[[@LINE-1]]:44: warning: {{.*}} in function declaration + // CHECK-MESSAGES: :[[@LINE-2]]:51: warning: {{.*}} in function declaration + // CHECK-MESSAGES: :[[@LINE-3]]:58: warning: {{.*}} in function declaration + // CHECK-FIXES: {{^}} void (*(*returns_fn_returns_fn_void_void())())();{{$}} + + void (*(*(gronk::*returns_fn_returns_fn_void_void_mem)(void))(void))(void); + // CHECK-MESSAGES: :[[@LINE-1]]:58: warning: {{.*}} in field declaration + // CHECK-MESSAGES: :[[@LINE-2]]:65: warning: {{.*}} in field declaration + // CHECK-MESSAGES: :[[@LINE-3]]:72: warning: {{.*}} in field declaration + // CHECK-FIXES: {{^}} void (*(*(gronk::*returns_fn_returns_fn_void_void_mem)())())();{{$}} +}; + +int i; +int *pi; +void *pv = (void *) pi; +float f; +float *fi; +double d; +double *pd; + +void (*f1)(void); +// CHECK-MESSAGES: :[[@LI
Re: [PATCH] D7639: Add readability-redundant-void-arg check to clang-tidy
LegalizeAdulthood added a comment. In http://reviews.llvm.org/D7639#266332, @Eugene.Zelenko wrote: > What is preventing to add this check to Clang-tidy? Just found another piece > of fresh C++ code in LLDB with (void) as argument list... To be honest, I don't know. This review had taken SO long to get approved. At this point, the code is correct and I'd really like to get it committed and available for use instead of fussing with it any longer. http://reviews.llvm.org/D7639 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D13643: [Sema] Warn on ternary comparison
mgrabovsky added a comment. In http://reviews.llvm.org/D13643#266926, @aaron.ballman wrote: > I would spend some time digging into how GCC handles those cases, and use > that as a baseline that we can then improve upon. I like the fact that GCC > basically says "use parens to clarify your intent", as that solves all of the > cases regarding equality and inequality. > > I would imagine type == type == bool should behave the same as bool == bool > == bool; it can be valid code that just needs parens to clarify intent. As > for C90 behavior, I'm not too worried about what we do there. I'm back. The warning is emitted in `gcc/c-family/c-common.c` L11488–11503; GCC only does this for what LLVM calls 'relational' operators (i.e., comparisons except == and !=) and for integral types. http://reviews.llvm.org/D13643 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r250684 - [OPENMP] Fix for http://llvm.org/PR25221: Infinite loop while parsing OpenMP directive
Author: abataev Date: Mon Oct 19 01:40:17 2015 New Revision: 250684 URL: http://llvm.org/viewvc/llvm-project?rev=250684&view=rev Log: [OPENMP] Fix for http://llvm.org/PR25221: Infinite loop while parsing OpenMP directive Clang skipped annot_pragma_openmp token, while it should be considered as a stop token while skipping tokens. Added: cfe/trunk/test/OpenMP/openmp_check.cpp (with props) Modified: cfe/trunk/lib/Parse/Parser.cpp Modified: cfe/trunk/lib/Parse/Parser.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/Parser.cpp?rev=250684&r1=250683&r2=250684&view=diff == --- cfe/trunk/lib/Parse/Parser.cpp (original) +++ cfe/trunk/lib/Parse/Parser.cpp Mon Oct 19 01:40:17 2015 @@ -282,6 +282,7 @@ bool Parser::SkipUntil(ArrayRefhttp://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/openmp_check.cpp?rev=250684&view=auto == --- cfe/trunk/test/OpenMP/openmp_check.cpp (added) +++ cfe/trunk/test/OpenMP/openmp_check.cpp Mon Oct 19 01:40:17 2015 @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s +int nested(int a) { +#pragma omp parallel + ++a; + + auto F = [&]() { // expected-error {{expected expression}} expected-error {{expected ';' at end of declaration}} expected-warning {{'auto' type specifier is a C++11 extension}} +#pragma omp parallel +{ +#pragma omp target + ++a; +} + }; + F(); // expected-error {{C++ requires a type specifier for all declarations}} + return a; // expected-error {{expected unqualified-id}} +}// expected-error {{extraneous closing brace ('}')}} Propchange: cfe/trunk/test/OpenMP/openmp_check.cpp -- svn:eol-style = native Propchange: cfe/trunk/test/OpenMP/openmp_check.cpp -- svn:keywords = Author Date Id Rev URL Propchange: cfe/trunk/test/OpenMP/openmp_check.cpp -- svn:mime-type = text/plain ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits