Re: [PATCH] D15914: [OpenCL] Pipe builtin functions
pekka.jaaskelainen added a comment. I wonder could we squeeze this in before the next week's LLVM 3.8 branching? It would be great. Comment at: lib/CodeGen/CGBuiltin.cpp:2033 @@ +2032,3 @@ +else if (BuiltinID == Builtin::BIwork_group_reserve_write_pipe) + Name = "_Z29work_group_reserve_write_pipePU3AS110ocl_pipe_tji"; +else if (BuiltinID == Builtin::BIsub_group_reserve_read_pipe) Anastasia wrote: > I am still not convinced we need to mangle here at all. It seems we mainly > have only one prototype for those functions apart from read/write_pipe in > which case we can generate two versions of that function: > > read_pipe_2(...) - for two parameters case > read_pipe_4(...) - for four parameters case > > Having a mangler would complicate the implementation. And if used it would be > better to adhere to conventional scheme (i.e. calling getMangledName()). But > that won't work here as we are generating parameters different from > originally specified. I don't see any need or benefit in mangling at the > moment since the function signatures are all known here. > > Regarding the packet size, I prefer to pass it in. This way we can allow > simple BIF implementation without using any metadata magic. Usage of metadata > often implies adding non-conventional compilation mechanisms somewhere that > are best to avoid. We just need to remember that passing the packet size as an argument means touching all the user functions having pipes as arguments too. I'm still in the understanding that the compile time packet size info is needed only for optimization purposes, and thus could be a metadata which your implementation can just ignore for starters, or convert to a parameter before code emission? Touching the initial function finger prints for optimization reasons sounds a bit too intrusive. I'd rather leave the decision what to do with it to consumer of the Clang's output. Comment at: lib/CodeGen/CGOpenCLRuntime.h:55 @@ -50,3 +54,3 @@ }; } > Additionally how would definitions of builtin with user defined types appear > in the BIF libraries? This is a good question. read_pipe should just work for any type of any size, thus we cannot just generate a new function for all possible sizes in advance, thus what Anastasia suggests here makes sense to me: > One approach would be to just generate calls that would always use generic > types If now there was an additional parameter (always a constant) that stores the type's size it would not help much as one would need to generate a big switch...case that optimizes the access based on the packet size in case of a software pipe or a compiler pass that looks into that argument and generates (a call to) an optimized version? I think combining the Anastasia proposed generic read/write_pipe with the metadata (that points to the packet's inner type or its size?) would be the best solution (so far). http://reviews.llvm.org/D15914 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15914: [OpenCL] Pipe builtin functions
pxli168 added inline comments. Comment at: include/clang/Basic/Builtins.def:1260 @@ +1259,3 @@ + +LANGBUILTIN(reserve_read_pipe, "i.", "tn", OCLC_LANG) +LANGBUILTIN(reserve_write_pipe, "i.", "tn", OCLC_LANG) Anastasia wrote: > That's right! I am just saying that we don't have to make it variadic, so you > can change "v." -> "v" and "i." -> "i" If that means there is no arguments, and may be misleading. Comment at: lib/CodeGen/CGBuiltin.cpp:2033 @@ +2032,3 @@ +else if (BuiltinID == Builtin::BIwork_group_reserve_write_pipe) + Name = "_Z29work_group_reserve_write_pipePU3AS110ocl_pipe_tji"; +else if (BuiltinID == Builtin::BIsub_group_reserve_read_pipe) pekka.jaaskelainen wrote: > Anastasia wrote: > > I am still not convinced we need to mangle here at all. It seems we mainly > > have only one prototype for those functions apart from read/write_pipe in > > which case we can generate two versions of that function: > > > > read_pipe_2(...) - for two parameters case > > read_pipe_4(...) - for four parameters case > > > > Having a mangler would complicate the implementation. And if used it would > > be better to adhere to conventional scheme (i.e. calling > > getMangledName()). But that won't work here as we are generating parameters > > different from originally specified. I don't see any need or benefit in > > mangling at the moment since the function signatures are all known here. > > > > Regarding the packet size, I prefer to pass it in. This way we can allow > > simple BIF implementation without using any metadata magic. Usage of > > metadata often implies adding non-conventional compilation mechanisms > > somewhere that are best to avoid. > We just need to remember that passing the packet size as an argument means > touching all the user functions having pipes as arguments too. > > I'm still in the understanding that the compile time packet size info is > needed only for optimization purposes, and thus could be a metadata which > your implementation can just ignore for starters, or convert to a parameter > before code emission? Touching the initial function finger prints for > optimization reasons sounds a bit too intrusive. I'd rather leave the > decision what to do with it to consumer of the Clang's output. That could be fine I think, the function name do not need mangle if we use generic type. Comment at: lib/Sema/SemaChecking.cpp:268 @@ +267,3 @@ +static OpenCLImageAccessAttr *getOpenCLImageAcces(const Decl *D) { + if (D->hasAttr()) +return D->getAttr(); Anastasia wrote: > Let's rename this new function in this commit and I agree with renaming an > attribute later on. May be leaving TODO explaining that would be good. OK, it will make the function more easy to understand. And I will add a FIXME or TODO here to explain the misleading imageaccess. And how do you think about the access check for the work_group functions? The specification does not say clearly, but it seems they should also obey the same rule with read/write_pipe. http://reviews.llvm.org/D15914 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15914: [OpenCL] Pipe builtin functions
pxli168 added a comment. Then maybe I should hurry up to see if I can finish the Semacheck and this patch in time. By the way, I just got the access to the llvm svn, can I just commit the pipe type patch directly as I see you all accepted it. Or I should send it to the cfe-commit first? Comment at: lib/CodeGen/CGOpenCLRuntime.h:55 @@ -50,3 +54,3 @@ }; } pekka.jaaskelainen wrote: > > Additionally how would definitions of builtin with user defined types > > appear in the BIF libraries? > > This is a good question. read_pipe should just work for any type of any size, > thus we cannot just generate a new function for all possible sizes in > advance, thus what Anastasia suggests here makes sense to me: > > > One approach would be to just generate calls that would always use generic > > types > > If now there was an additional parameter (always a constant) that stores the > type's size it would not help much as one would need to generate a big > switch...case that optimizes the access based on the packet size in case of a > software pipe or a compiler pass that looks into that argument and generates > (a call to) an optimized version? > > I think combining the Anastasia proposed generic read/write_pipe with the > metadata (that points to the packet's inner type or its size?) would be the > best solution (so far). Ok, I will send a patch in the best way so far. http://reviews.llvm.org/D15914 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15914: [OpenCL] Pipe builtin functions
pekka.jaaskelainen added a comment. In http://reviews.llvm.org/D15914#322917, @pxli168 wrote: > By the way, I just got the access to the llvm svn, can I just commit the pipe > type patch directly as I see you all accepted it. Or I should send it to the > cfe-commit first? I'm afraid we won't get more reviews from cfe-commit so IMO just commit it in case it was accepted. http://reviews.llvm.org/D15914 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r257254 - [OpenCL] Pipe type support
Author: pxl Date: Sat Jan 9 06:53:17 2016 New Revision: 257254 URL: http://llvm.org/viewvc/llvm-project?rev=257254&view=rev Log: [OpenCL] Pipe type support Summary: Support for OpenCL 2.0 pipe type. This is a bug-fix version for bader's patch reviews.llvm.org/D14441 Reviewers: pekka.jaaskelainen, Anastasia Subscribers: bader, Anastasia, cfe-commits Differential Revision: http://reviews.llvm.org/D15603 Added: cfe/trunk/test/CodeGenOpenCL/pipe_types.cl cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl cfe/trunk/test/SemaOpenCL/pipes-1.2-negative.cl Modified: cfe/trunk/include/clang/AST/ASTContext.h cfe/trunk/include/clang/AST/RecursiveASTVisitor.h cfe/trunk/include/clang/AST/Type.h cfe/trunk/include/clang/AST/TypeLoc.h cfe/trunk/include/clang/AST/TypeNodes.def cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td cfe/trunk/include/clang/Basic/Specifiers.h cfe/trunk/include/clang/Basic/TokenKinds.def cfe/trunk/include/clang/Sema/DeclSpec.h cfe/trunk/include/clang/Sema/Sema.h cfe/trunk/include/clang/Serialization/ASTBitCodes.h cfe/trunk/lib/AST/ASTContext.cpp cfe/trunk/lib/AST/ASTImporter.cpp cfe/trunk/lib/AST/ItaniumMangle.cpp cfe/trunk/lib/AST/MicrosoftMangle.cpp cfe/trunk/lib/AST/Type.cpp cfe/trunk/lib/AST/TypePrinter.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp cfe/trunk/lib/CodeGen/CGOpenCLRuntime.h cfe/trunk/lib/CodeGen/CodeGenFunction.cpp cfe/trunk/lib/CodeGen/CodeGenTypes.cpp cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp cfe/trunk/lib/Parse/ParseDecl.cpp cfe/trunk/lib/Sema/DeclSpec.cpp cfe/trunk/lib/Sema/SemaDecl.cpp cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/lib/Sema/SemaLookup.cpp cfe/trunk/lib/Sema/SemaTemplate.cpp cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp cfe/trunk/lib/Sema/SemaType.cpp cfe/trunk/lib/Sema/TreeTransform.h cfe/trunk/lib/Serialization/ASTReader.cpp cfe/trunk/lib/Serialization/ASTWriter.cpp cfe/trunk/test/PCH/ocl_types.cl cfe/trunk/test/PCH/ocl_types.h cfe/trunk/tools/libclang/CIndex.cpp Modified: cfe/trunk/include/clang/AST/ASTContext.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=257254&r1=257253&r2=257254&view=diff == --- cfe/trunk/include/clang/AST/ASTContext.h (original) +++ cfe/trunk/include/clang/AST/ASTContext.h Sat Jan 9 06:53:17 2016 @@ -131,6 +131,7 @@ class ASTContext : public RefCountedBase mutable llvm::FoldingSet AutoTypes; mutable llvm::FoldingSet AtomicTypes; llvm::FoldingSet AttributedTypes; + mutable llvm::FoldingSet PipeTypes; mutable llvm::FoldingSet QualifiedTemplateNames; mutable llvm::FoldingSet DependentTemplateNames; @@ -1079,6 +1080,9 @@ public: /// blocks. QualType getBlockDescriptorType() const; + /// \brief Return pipe type for the specified type. + QualType getPipeType(QualType T) const; + /// Gets the struct used to keep track of the extended descriptor for /// pointer to blocks. QualType getBlockDescriptorExtendedType() const; Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=257254&r1=257253&r2=257254&view=diff == --- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original) +++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Sat Jan 9 06:53:17 2016 @@ -978,6 +978,8 @@ DEF_TRAVERSE_TYPE(ObjCObjectPointerType, DEF_TRAVERSE_TYPE(AtomicType, { TRY_TO(TraverseType(T->getValueType())); }) +DEF_TRAVERSE_TYPE(PipeType, { TRY_TO(TraverseType(T->getElementType())); }) + #undef DEF_TRAVERSE_TYPE // - TypeLoc traversal - @@ -1206,6 +1208,8 @@ DEF_TRAVERSE_TYPELOC(ObjCObjectPointerTy DEF_TRAVERSE_TYPELOC(AtomicType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); }) +DEF_TRAVERSE_TYPELOC(PipeType, { TRY_TO(TraverseTypeLoc(TL.getValueLoc())); }) + #undef DEF_TRAVERSE_TYPELOC // - Decl traversal - Modified: cfe/trunk/include/clang/AST/Type.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=257254&r1=257253&r2=257254&view=diff == --- cfe/trunk/include/clang/AST/Type.h (original) +++ cfe/trunk/include/clang/AST/Type.h Sat Jan 9 06:53:17 2016 @@ -1721,6 +1721,7 @@ public: bool isNDRangeT() const; // OpenCL ndrange_t bool isReserveIDT() const;// OpenCL reserve_id_t + bool isPipeType() const; // OpenCL pipe type bool isOpenCLSpecificType() const;
Re: [PATCH] D15914: [OpenCL] Pipe builtin functions
pxli168 updated the summary for this revision. pxli168 updated this revision to Diff 44404. pxli168 added a comment. 1. Add tests for builtin function CodeGen and Semacheck 2. Add TODO for what we need to do about access qualifier 3. Fix some bugs found in writing Hope we cans squeeze these patch into llvm 3.8 http://reviews.llvm.org/D15914 Files: include/clang/Basic/Builtins.def include/clang/Basic/Builtins.h include/clang/Basic/DiagnosticSemaKinds.td lib/Basic/Builtins.cpp lib/CodeGen/CGBuiltin.cpp lib/Sema/SemaChecking.cpp test/CodeGenOpenCL/pipe_builtin.cl test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl Index: test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl === --- /dev/null +++ test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 + +void test(read_only pipe int p, global int* ptr){ + int tmp; + read_pipe(tmp, p);// expected-error {{first argument to read_pipe must be a pipe type}} + read_pipe(p); // expected-error {{invalid number of arguments to function: read_pipe}} + read_pipe(p,tmp); // expected-error {{invalid argument type to function read_pipe (expecting: 'int *')}} + write_pipe(p,ptr);// expected-error {{invalid pipe access modifier (expecting write_only)}} +} Index: test/CodeGenOpenCL/pipe_builtin.cl === --- /dev/null +++ test/CodeGenOpenCL/pipe_builtin.cl @@ -0,0 +1,61 @@ +// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s + +// CHECK: %opencl.pipe_t = type opaque +// CHECK: %opencl.reserve_id_t = type opaque + +void test1(read_only pipe int p, global int *ptr) { + // CHECK: call i32 @read_pipe_2(%opencl.pipe_t* %{{.*}}, i8 addrspace(4)* %{{.*}}) + read_pipe(p, ptr); + // CHECK: call %opencl.reserve_id_t* @reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}) + reserve_id_t rid = reserve_read_pipe(p, 2); + // CHECK: call i32 @read_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8 addrspace(4)* %{{.*}}) + read_pipe(p, rid, 2, ptr); + // CHECK: call void @commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}) + commit_read_pipe(p, rid); +} + +void test2(write_only pipe int p, global int *ptr) { + // CHECK: call i32 @write_pipe_2(%opencl.pipe_t* %{{.*}}, i8 addrspace(4)* %{{.*}}) + write_pipe(p, ptr); + // CHECK: call %opencl.reserve_id_t* @reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}) + reserve_id_t rid = reserve_write_pipe(p, 2); + // CHECK: call i32 @write_pipe_4(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}, i32 {{.*}}, i8 addrspace(4)* %{{.*}}) + write_pipe(p, rid, 2, ptr); + // CHECK: call void @commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}) + commit_write_pipe(p, rid); +} + +void test3(read_only pipe int p, global int *ptr) { + // CHECK: call %opencl.reserve_id_t* @work_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}) + reserve_id_t rid = work_group_reserve_read_pipe(p, 2); + // CHECK: call void @work_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}) + work_group_commit_read_pipe(p, rid); +} + +void test4(write_only pipe int p, global int *ptr) { + // CHECK: call %opencl.reserve_id_t* @work_group_reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}) + reserve_id_t rid = work_group_reserve_write_pipe(p, 2); + // CHECK: call void @work_group_commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}) + work_group_commit_write_pipe(p, rid); +} + +void test5(read_only pipe int p, global int *ptr) { + // CHECK: call %opencl.reserve_id_t* @sub_group_reserve_read_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}) + reserve_id_t rid = sub_group_reserve_read_pipe(p, 2); + // CHECK: call void @sub_group_commit_read_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}) + sub_group_commit_read_pipe(p, rid); +} + +void test6(write_only pipe int p, global int *ptr) { + // CHECK: call %opencl.reserve_id_t* @sub_group_reserve_write_pipe(%opencl.pipe_t* %{{.*}}, i32 {{.*}}) + reserve_id_t rid = sub_group_reserve_write_pipe(p, 2); + // CHECK: call void @sub_group_commit_write_pipe(%opencl.pipe_t* %{{.*}}, %opencl.reserve_id_t* %{{.*}}) + sub_group_commit_write_pipe(p, rid); +} + +void test7(write_only pipe int p, global int *ptr) { + // CHECK: call i32 @get_pipe_num_packets(%opencl.pipe_t* %{{.*}}) + *ptr = get_pipe_num_packets(p); + // CHECK: call i32 @get_pipe_max_packets(%opencl.pipe_t* %{{.*}}) + *ptr = get_pipe_max_packets(p); +} Index: lib/Sema/SemaChecking.cpp === --- lib/Sema/SemaChecking.cpp +++ lib/Sema/SemaChecking.cpp @@ -258,6 +258,193 @@ return false; } +/// Returns readable name for a call. +static StringRef getFunctionName(CallExpr *Call) { + return cast(Call->getCalleeDecl())->getNa
r257255 - clang-format: [JS] Support semicolons in TypeScript's TypeMemberLists.
Author: djasper Date: Sat Jan 9 09:56:28 2016 New Revision: 257255 URL: http://llvm.org/viewvc/llvm-project?rev=257255&view=rev Log: clang-format: [JS] Support semicolons in TypeScript's TypeMemberLists. Before: var x: { a: string; b: number; } = {}; After: var x: {a: string; b: number;} = {}; Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp cfe/trunk/lib/Format/UnwrappedLineParser.h cfe/trunk/unittests/Format/FormatTestJS.cpp Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=257255&r1=257254&r2=257255&view=diff == --- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original) +++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sat Jan 9 09:56:28 2016 @@ -315,6 +315,7 @@ void UnwrappedLineParser::calculateBrace // definitions, too. unsigned StoredPosition = Tokens->getPosition(); FormatToken *Tok = FormatTok; + const FormatToken *PrevTok = getPreviousToken(); // Keep a stack of positions of lbrace tokens. We will // update information about whether an lbrace starts a // braced init list or a different block during the loop. @@ -331,47 +332,53 @@ void UnwrappedLineParser::calculateBrace switch (Tok->Tok.getKind()) { case tok::l_brace: - Tok->BlockKind = BK_Unknown; + if (Style.Language == FormatStyle::LK_JavaScript && PrevTok && + PrevTok->is(tok::colon)) +// In TypeScript's TypeMemberLists, there can be semicolons between the +// individual members. +Tok->BlockKind = BK_BracedInit; + else +Tok->BlockKind = BK_Unknown; LBraceStack.push_back(Tok); break; case tok::r_brace: - if (!LBraceStack.empty()) { -if (LBraceStack.back()->BlockKind == BK_Unknown) { - bool ProbablyBracedList = false; - if (Style.Language == FormatStyle::LK_Proto) { -ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square); - } else { -// Using OriginalColumn to distinguish between ObjC methods and -// binary operators is a bit hacky. -bool NextIsObjCMethod = NextTok->isOneOf(tok::plus, tok::minus) && -NextTok->OriginalColumn == 0; - -// If there is a comma, semicolon or right paren after the closing -// brace, we assume this is a braced initializer list. Note that -// regardless how we mark inner braces here, we will overwrite the -// BlockKind later if we parse a braced list (where all blocks -// inside are by default braced lists), or when we explicitly detect -// blocks (for example while parsing lambdas). -// -// We exclude + and - as they can be ObjC visibility modifiers. -ProbablyBracedList = -NextTok->isOneOf(tok::comma, tok::period, tok::colon, - tok::r_paren, tok::r_square, tok::l_brace, - tok::l_square, tok::l_paren, tok::ellipsis) || -(NextTok->is(tok::semi) && - (!ExpectClassBody || LBraceStack.size() != 1)) || -(NextTok->isBinaryOperator() && !NextIsObjCMethod); - } - if (ProbablyBracedList) { -Tok->BlockKind = BK_BracedInit; -LBraceStack.back()->BlockKind = BK_BracedInit; - } else { -Tok->BlockKind = BK_Block; -LBraceStack.back()->BlockKind = BK_Block; - } + if (LBraceStack.empty()) +break; + if (LBraceStack.back()->BlockKind == BK_Unknown) { +bool ProbablyBracedList = false; +if (Style.Language == FormatStyle::LK_Proto) { + ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square); +} else { + // Using OriginalColumn to distinguish between ObjC methods and + // binary operators is a bit hacky. + bool NextIsObjCMethod = NextTok->isOneOf(tok::plus, tok::minus) && + NextTok->OriginalColumn == 0; + + // If there is a comma, semicolon or right paren after the closing + // brace, we assume this is a braced initializer list. Note that + // regardless how we mark inner braces here, we will overwrite the + // BlockKind later if we parse a braced list (where all blocks + // inside are by default braced lists), or when we explicitly detect + // blocks (for example while parsing lambdas). + // + // We exclude + and - as they can be ObjC visibility modifiers. + ProbablyBracedList = + NextTok->isOneOf(tok::comma, tok::period, tok::colon, + tok::r_paren, tok::r_square, tok::l_brace, + tok::l_square, tok::l_paren, tok:
r257256 - clang-format: Support definitions/declarations of operator, .
Author: djasper Date: Sat Jan 9 09:56:40 2016 New Revision: 257256 URL: http://llvm.org/viewvc/llvm-project?rev=257256&view=rev Log: clang-format: Support definitions/declarations of operator,. Before: bool operator, (); After: bool operator,(); Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp cfe/trunk/lib/Format/TokenAnnotator.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=257256&r1=257255&r2=257256&view=diff == --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original) +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sat Jan 9 09:56:40 2016 @@ -383,7 +383,8 @@ void ContinuationIndenter::addTokenOnCur State.Stack.back().LastSpace = State.Column; State.Stack.back().NestedBlockIndent = State.Column; } else if (!Current.isOneOf(tok::comment, tok::caret) && - (Previous.is(tok::comma) || + ((Previous.is(tok::comma) && + !Previous.is(TT_OverloadedOperator)) || (Previous.is(tok::colon) && Previous.is(TT_ObjCMethodExpr { State.Stack.back().LastSpace = State.Column; } else if ((Previous.isOneOf(TT_BinaryOperator, TT_ConditionalExpr, Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=257256&r1=257255&r2=257256&view=diff == --- cfe/trunk/lib/Format/TokenAnnotator.cpp (original) +++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Jan 9 09:56:40 2016 @@ -580,7 +580,8 @@ private: if (CurrentToken->isOneOf(tok::star, tok::amp)) CurrentToken->Type = TT_PointerOrReference; consumeToken(); -if (CurrentToken && CurrentToken->Previous->is(TT_BinaryOperator)) +if (CurrentToken && +CurrentToken->Previous->isOneOf(TT_BinaryOperator, tok::comma)) CurrentToken->Previous->Type = TT_OverloadedOperator; } if (CurrentToken) { @@ -2070,14 +2071,14 @@ bool TokenAnnotator::spaceRequiredBefore if (Right.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow) || Left.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow)) return true; + if (Right.is(TT_OverloadedOperatorLParen)) +return Style.SpaceBeforeParens == FormatStyle::SBPO_Always; if (Left.is(tok::comma)) return true; if (Right.is(tok::comma)) return false; if (Right.isOneOf(TT_CtorInitializerColon, TT_ObjCBlockLParen)) return true; - if (Right.is(TT_OverloadedOperatorLParen)) -return Style.SpaceBeforeParens == FormatStyle::SBPO_Always; if (Right.is(tok::colon)) { if (Line.First->isOneOf(tok::kw_case, tok::kw_default) || !Right.getNextNonComment() || Right.getNextNonComment()->is(tok::semi)) Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=257256&r1=257255&r2=257256&view=diff == --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Jan 9 09:56:40 2016 @@ -5458,6 +5458,7 @@ TEST_F(FormatTest, UnderstandsOverloaded verifyFormat("bool operator!=();"); verifyFormat("int operator+();"); verifyFormat("int operator++();"); + verifyFormat("bool operator,();"); verifyFormat("bool operator();"); verifyFormat("bool operator()();"); verifyFormat("bool operator[]();"); @@ -5473,6 +5474,8 @@ TEST_F(FormatTest, UnderstandsOverloaded verifyFormat("void operator delete[](void *ptr);"); verifyFormat("template \n" "AAA operator/(const AAA &a, BBB &b);"); + verifyFormat("aa operator,(\n" + "a) const;"); verifyFormat( "ostream &operator<<(ostream &OutputStream,\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r257258 - clang-format: Improve selective comment formatting.
Author: djasper Date: Sat Jan 9 09:56:53 2016 New Revision: 257258 URL: http://llvm.org/viewvc/llvm-project?rev=257258&view=rev Log: clang-format: Improve selective comment formatting. Starting here: int x; // Format this line only. int xx; // int x; // Before: int x; // Format this line only. int xx; // int x; // After: int x; // Format this line only. int xx; // int x; // Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp cfe/trunk/unittests/Format/FormatTestSelective.cpp Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=257258&r1=257257&r2=257258&view=diff == --- cfe/trunk/lib/Format/WhitespaceManager.cpp (original) +++ cfe/trunk/lib/Format/WhitespaceManager.cpp Sat Jan 9 09:56:53 2016 @@ -55,8 +55,9 @@ void WhitespaceManager::replaceWhitespac return; Tok.Decision = (Newlines > 0) ? FD_Break : FD_Continue; Changes.push_back( - Change(true, Tok.WhitespaceRange, IndentLevel, Spaces, StartOfTokenColumn, - Newlines, "", "", Tok.Tok.getKind(), InPPDirective && !Tok.IsFirst, + Change(/*CreateReplacement=*/true, Tok.WhitespaceRange, IndentLevel, + Spaces, StartOfTokenColumn, Newlines, "", "", Tok.Tok.getKind(), + InPPDirective && !Tok.IsFirst, Tok.is(TT_StartOfName) || Tok.is(TT_FunctionDeclarationName))); } @@ -64,11 +65,11 @@ void WhitespaceManager::addUntouchableTo bool InPPDirective) { if (Tok.Finalized) return; - Changes.push_back( - Change(false, Tok.WhitespaceRange, /*IndentLevel=*/0, - /*Spaces=*/0, Tok.OriginalColumn, Tok.NewlinesBefore, "", "", - Tok.Tok.getKind(), InPPDirective && !Tok.IsFirst, - Tok.is(TT_StartOfName) || Tok.is(TT_FunctionDeclarationName))); + Changes.push_back(Change( + /*CreateReplacement=*/false, Tok.WhitespaceRange, /*IndentLevel=*/0, + /*Spaces=*/0, Tok.OriginalColumn, Tok.NewlinesBefore, "", "", + Tok.Tok.getKind(), InPPDirective && !Tok.IsFirst, + Tok.is(TT_StartOfName) || Tok.is(TT_FunctionDeclarationName))); } void WhitespaceManager::replaceWhitespaceInToken( @@ -342,6 +343,12 @@ void WhitespaceManager::alignTrailingCom unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn; unsigned ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength; + +// If we don't create a replacement for this change, we have to consider +// it to be immovable. +if (!Changes[i].CreateReplacement) + ChangeMaxColumn = ChangeMinColumn; + if (i + 1 != e && Changes[i + 1].ContinuesPPDirective) ChangeMaxColumn -= 2; // If this comment follows an } in column 0, it probably documents the Modified: cfe/trunk/unittests/Format/FormatTestSelective.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestSelective.cpp?rev=257258&r1=257257&r2=257258&view=diff == --- cfe/trunk/unittests/Format/FormatTestSelective.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestSelective.cpp Sat Jan 9 09:56:53 2016 @@ -162,6 +162,13 @@ TEST_F(FormatTestSelective, FormatsComme "// This is\n" "// not formatted. ", 0, 0)); + EXPECT_EQ("int x; // Format this line.\n" +"int xx; //\n" +"int x; //", +format("int x; // Format this line.\n" + "int xx; //\n" + "int x; //", + 0, 0)); } TEST_F(FormatTestSelective, IndividualStatementsOfNestedBlocks) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r257257 - clang-format: Fix incorrect line break in certain configurations.
Author: djasper Date: Sat Jan 9 09:56:47 2016 New Revision: 257257 URL: http://llvm.org/viewvc/llvm-project?rev=257257&view=rev Log: clang-format: Fix incorrect line break in certain configurations. Before: void aa(, vector bbb); After: void aa(, vector bbb); Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=257257&r1=257256&r2=257257&view=diff == --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original) +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sat Jan 9 09:56:47 2016 @@ -150,7 +150,8 @@ bool ContinuationIndenter::mustBreak(con if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection) return true; if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) || - (Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName)) || + (Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) && +Previous.NestingLevel == 1) || (Style.BreakBeforeTernaryOperators && Current.is(TT_ConditionalExpr) && Previous.isNot(tok::question)) || (!Style.BreakBeforeTernaryOperators && Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=257257&r1=257256&r2=257257&view=diff == --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Jan 9 09:56:47 2016 @@ -4062,6 +4062,10 @@ TEST_F(FormatTest, FormatsDeclarationsOn " int ,\n" " int aaa) {}", NoBinPacking); + NoBinPacking.AllowAllParametersOfDeclarationOnNextLine = false; + verifyFormat("void aa(,\n" + "vector bbb);", + NoBinPacking); } TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r257259 - Make clang::format::reformat work with non 0-terminated strings.
Author: djasper Date: Sat Jan 9 09:56:57 2016 New Revision: 257259 URL: http://llvm.org/viewvc/llvm-project?rev=257259&view=rev Log: Make clang::format::reformat work with non 0-terminated strings. Modified: cfe/trunk/lib/Format/Format.cpp Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=257259&r1=257258&r2=257259&view=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Sat Jan 9 09:56:57 2016 @@ -1902,8 +1902,9 @@ tooling::Replacements reformat(const For IntrusiveRefCntPtr(new DiagnosticIDs), new DiagnosticOptions); SourceManager SourceMgr(Diagnostics, Files); - InMemoryFileSystem->addFile(FileName, 0, - llvm::MemoryBuffer::getMemBuffer(Code, FileName)); + InMemoryFileSystem->addFile( + FileName, 0, llvm::MemoryBuffer::getMemBuffer( + Code, FileName, /*RequiresNullTerminator=*/false)); FileID ID = SourceMgr.createFileID(Files.getFile(FileName), SourceLocation(), clang::SrcMgr::C_User); SourceLocation StartOfFile = SourceMgr.getLocForStartOfFile(ID); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r257259 - Make clang::format::reformat work with non 0-terminated strings.
On Sat, Jan 9, 2016 at 4:56 PM, Daniel Jasper via cfe-commits wrote: > Author: djasper > Date: Sat Jan 9 09:56:57 2016 > New Revision: 257259 > > URL: http://llvm.org/viewvc/llvm-project?rev=257259&view=rev > Log: > Make clang::format::reformat work with non 0-terminated strings. > > Modified: > cfe/trunk/lib/Format/Format.cpp > > Modified: cfe/trunk/lib/Format/Format.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=257259&r1=257258&r2=257259&view=diff > == > --- cfe/trunk/lib/Format/Format.cpp (original) > +++ cfe/trunk/lib/Format/Format.cpp Sat Jan 9 09:56:57 2016 > @@ -1902,8 +1902,9 @@ tooling::Replacements reformat(const For >IntrusiveRefCntPtr(new DiagnosticIDs), >new DiagnosticOptions); >SourceManager SourceMgr(Diagnostics, Files); > - InMemoryFileSystem->addFile(FileName, 0, > - llvm::MemoryBuffer::getMemBuffer(Code, > FileName)); > + InMemoryFileSystem->addFile( > + FileName, 0, llvm::MemoryBuffer::getMemBuffer( > + Code, FileName, /*RequiresNullTerminator=*/false)); Hmm, Clang's Lexer depends on the null terminator at EOF. I'd expect this change to create invalid memory reads (asan) for cases like formatting "// foo" without a trailing newline. - Ben >FileID ID = SourceMgr.createFileID(Files.getFile(FileName), > SourceLocation(), > clang::SrcMgr::C_User); >SourceLocation StartOfFile = SourceMgr.getLocForStartOfFile(ID); > > > ___ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r257260 - [vfs] Normalize working directory if requested.
Author: d0k Date: Sat Jan 9 10:33:16 2016 New Revision: 257260 URL: http://llvm.org/viewvc/llvm-project?rev=257260&view=rev Log: [vfs] Normalize working directory if requested. FixedCompilationDatabase sets the working dir to "." by default. For chdir(".") this is a noop but this lead to InMemoryFileSystem to create bogus paths. Fixes PR25327. Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h cfe/trunk/lib/Basic/VirtualFileSystem.cpp cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=257260&r1=257259&r2=257260&view=diff == --- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original) +++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Sat Jan 9 10:33:16 2016 @@ -299,10 +299,7 @@ public: llvm::ErrorOr getCurrentWorkingDirectory() const override { return WorkingDirectory; } - std::error_code setCurrentWorkingDirectory(const Twine &Path) override { -WorkingDirectory = Path.str(); -return std::error_code(); - } + std::error_code setCurrentWorkingDirectory(const Twine &Path) override; }; /// \brief Get a globally unique ID for a virtual file or directory. Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=257260&r1=257259&r2=257260&view=diff == --- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original) +++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Sat Jan 9 10:33:16 2016 @@ -658,6 +658,23 @@ directory_iterator InMemoryFileSystem::d EC = make_error_code(llvm::errc::not_a_directory); return directory_iterator(std::make_shared()); } + +std::error_code InMemoryFileSystem::setCurrentWorkingDirectory(const Twine &P) { + SmallString<128> Path; + P.toVector(Path); + + // Fix up relative paths. This just prepends the current working directory. + std::error_code EC = makeAbsolute(Path); + assert(!EC); + (void)EC; + + if (useNormalizedPaths()) +llvm::sys::path::remove_dots(Path, /*remove_dot_dot=*/true); + + if (!Path.empty()) +WorkingDirectory = Path.str(); + return std::error_code(); +} } } Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=257260&r1=257259&r2=257260&view=diff == --- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original) +++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Sat Jan 9 10:33:16 2016 @@ -657,6 +657,12 @@ TEST_F(InMemoryFileSystemTest, WorkingDi Stat = FS.status("c"); ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString(); + + NormalizedFS.setCurrentWorkingDirectory("/b/c"); + NormalizedFS.setCurrentWorkingDirectory("."); + ASSERT_EQ("/b/c", NormalizedFS.getCurrentWorkingDirectory().get()); + NormalizedFS.setCurrentWorkingDirectory(".."); + ASSERT_EQ("/b", NormalizedFS.getCurrentWorkingDirectory().get()); } // NOTE: in the tests below, we use '//root/' as our root directory, since it is ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r257267 - clang-format: Fix the counting of leading whitespace in tok::unknown tokens
Author: djasper Date: Sat Jan 9 15:12:45 2016 New Revision: 257267 URL: http://llvm.org/viewvc/llvm-project?rev=257267&view=rev Log: clang-format: Fix the counting of leading whitespace in tok::unknown tokens Previously, all whitespace characters would increase the starting column, which doesn't make sense. This fixes a problem, e.g. with the length calculation in JS template strings. 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=257267&r1=257266&r2=257267&view=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Sat Jan 9 15:12:45 2016 @@ -1239,6 +1239,8 @@ private: FormatTok->Type = TT_ImplicitStringLiteral; break; } +if (FormatTok->Type == TT_ImplicitStringLiteral) + break; } if (FormatTok->is(TT_ImplicitStringLiteral)) Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=257267&r1=257266&r2=257267&view=diff == --- cfe/trunk/unittests/Format/FormatTestJS.cpp (original) +++ cfe/trunk/unittests/Format/FormatTestJS.cpp Sat Jan 9 15:12:45 2016 @@ -956,6 +956,9 @@ TEST_F(FormatTestJS, TemplateStrings) { "var y;"); verifyFormat("var x = `\"`; // comment with matching quote \"\n" "var y;"); + EXPECT_EQ("it(`'aaa `, a);", +format("it(`'aaa `, a) ;", + getGoogleJSStyleWithColumns(40))); // Backticks in a comment - not a template string. EXPECT_EQ("var x = 1 // `/*a`;\n" ";", ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D10833: Retrieve BinaryOperator::getOpcode and BinaryOperator::getOpcodeStr via libclang and its python interface
RedX2501 added a comment. Ping http://reviews.llvm.org/D10833 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15097: [Sema] Issue a warning for integer overflow in struct initializer
ahatanak added a comment. OK, thank you for the review. I'll commit this patch in a day or two unless someone comes up with a better solution. http://reviews.llvm.org/D15097 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D15443: Fix getLocEnd for function declarations with exception specification.
adek05 added a comment. I think this won't work. If there is a problem with the expression inside `throw` or `noexcept` specifier, it will be highlighted inside the parens, never trying to actually access the end location of the function declaration. It would be enough if there is a warning/error which would highlight the whole function declaration, because we could check whether it points at `;` or the character in front of it, but I don't know about such warning and I don't know how to smartly look for it. http://reviews.llvm.org/D15443 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r257260 - [vfs] Normalize working directory if requested.
Hi, > + NormalizedFS.setCurrentWorkingDirectory("/b/c"); > + NormalizedFS.setCurrentWorkingDirectory("."); > + ASSERT_EQ("/b/c", NormalizedFS.getCurrentWorkingDirectory().get()); > + NormalizedFS.setCurrentWorkingDirectory(".."); > + ASSERT_EQ("/b", NormalizedFS.getCurrentWorkingDirectory().get()); > } This test fails on Windows (MSVC 2015 x64): TEST 'Clang-Unit :: Basic/BasicTests.exe/InMemoryFileSystemTest.WorkingDirectory' FAILED Note: Google Test filter = InMemoryFileSystemTest.WorkingDirectory [==] Running 1 test from 1 test case. [--] Global test environment set-up. [--] 1 test from InMemoryFileSystemTest [ RUN ] InMemoryFileSystemTest.WorkingDirectory ..\tools\clang\unittests\Basic\VirtualFileSystemTest.cpp(663): error: Value of: NormalizedFS.getCurrentWorkingDirectory().get( ) Actual: "/b\\c" Expected: "/b/c" [ FAILED ] InMemoryFileSystemTest.WorkingDirectory (0 ms) [--] 1 test from InMemoryFileSystemTest (0 ms total) [--] Global test environment tear-down [==] 1 test from 1 test case ran. (0 ms total) [ PASSED ] 0 tests. [ FAILED ] 1 test, listed below: [ FAILED ] InMemoryFileSystemTest.WorkingDirectory 1 FAILED TEST ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits