[PATCH] D44075: [analyzer] CStringChecker.cpp: Remove the duplicated check about null dereference on dest-buffer or src-buffer.
MTC created this revision. MTC added reviewers: dcoughlin, NoQ, xazax.hun, cfe-commits. Herald added subscribers: a.sidorin, rnkovacs, szepet. Herald added a reviewer: george.karpenkov. `CheckBufferAccess()` calls `CheckNonNull()`, so there are some calls to `CheckNonNull()` that are useless. Repository: rC Clang https://reviews.llvm.org/D44075 Files: lib/StaticAnalyzer/Checkers/CStringChecker.cpp Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp === --- lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -1033,21 +1033,6 @@ if (stateNonZeroSize) { state = stateNonZeroSize; -// Ensure the destination is not null. If it is NULL there will be a -// NULL pointer dereference. -state = checkNonNull(C, state, Dest, destVal); -if (!state) - return; - -// Get the value of the Src. -SVal srcVal = state->getSVal(Source, LCtx); - -// Ensure the source is not null. If it is NULL there will be a -// NULL pointer dereference. -state = checkNonNull(C, state, Source, srcVal); -if (!state) - return; - // Ensure the accesses are valid and that the buffers do not overlap. const char * const writeWarning = "Memory copy function overflows destination buffer"; @@ -2033,12 +2018,6 @@ return; } - // Ensure the memory area is not null. - // If it is NULL there will be a NULL pointer dereference. - State = checkNonNull(C, StateNonZeroSize, Mem, MemVal); - if (!State) -return; - State = CheckBufferAccess(C, State, Size, Mem); if (!State) return; Index: lib/StaticAnalyzer/Checkers/CStringChecker.cpp === --- lib/StaticAnalyzer/Checkers/CStringChecker.cpp +++ lib/StaticAnalyzer/Checkers/CStringChecker.cpp @@ -1033,21 +1033,6 @@ if (stateNonZeroSize) { state = stateNonZeroSize; -// Ensure the destination is not null. If it is NULL there will be a -// NULL pointer dereference. -state = checkNonNull(C, state, Dest, destVal); -if (!state) - return; - -// Get the value of the Src. -SVal srcVal = state->getSVal(Source, LCtx); - -// Ensure the source is not null. If it is NULL there will be a -// NULL pointer dereference. -state = checkNonNull(C, state, Source, srcVal); -if (!state) - return; - // Ensure the accesses are valid and that the buffers do not overlap. const char * const writeWarning = "Memory copy function overflows destination buffer"; @@ -2033,12 +2018,6 @@ return; } - // Ensure the memory area is not null. - // If it is NULL there will be a NULL pointer dereference. - State = checkNonNull(C, StateNonZeroSize, Mem, MemVal); - if (!State) -return; - State = CheckBufferAccess(C, State, Size, Mem); if (!State) return; ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r326675 - Replace the custom handling for several attributes; NFC.
Author: aaronballman Date: Sun Mar 4 07:32:01 2018 New Revision: 326675 URL: http://llvm.org/viewvc/llvm-project?rev=326675&view=rev Log: Replace the custom handling for several attributes; NFC. These attributes were only customized because of the need to check for attribute mutual exclusion, but we now have the handleSimpleAttributeWithExclusions() helper function to handle these scenarios. Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=326675&r1=326674&r2=326675&view=diff == --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sun Mar 4 07:32:01 2018 @@ -1842,22 +1842,6 @@ static void handleAliasAttr(Sema &S, Dec AL.getAttributeSpellingListIndex())); } -static void handleColdAttr(Sema &S, Decl *D, const AttributeList &AL) { - if (checkAttrMutualExclusion(S, D, AL.getRange(), AL.getName())) -return; - - D->addAttr(::new (S.Context) ColdAttr(AL.getRange(), S.Context, -AL.getAttributeSpellingListIndex())); -} - -static void handleHotAttr(Sema &S, Decl *D, const AttributeList &AL) { - if (checkAttrMutualExclusion(S, D, AL.getRange(), AL.getName())) -return; - - D->addAttr(::new (S.Context) HotAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); -} - static void handleTLSModelAttr(Sema &S, Decl *D, const AttributeList &AL) { StringRef Model; @@ -2066,26 +2050,6 @@ static void handleDependencyAttr(Sema &S AL.getAttributeSpellingListIndex())); } -static void handleNotTailCalledAttr(Sema &S, Decl *D, -const AttributeList &AL) { - if (checkAttrMutualExclusion(S, D, AL.getRange(), - AL.getName())) -return; - - D->addAttr(::new (S.Context) NotTailCalledAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); -} - -static void handleDisableTailCallsAttr(Sema &S, Decl *D, - const AttributeList &AL) { - if (checkAttrMutualExclusion(S, D, AL.getRange(), - AL.getName())) -return; - - D->addAttr(::new (S.Context) DisableTailCallsAttr( - AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); -} - static void handleUnusedAttr(Sema &S, Decl *D, const AttributeList &AL) { bool IsCXX17Attr = AL.isCXX11Attribute() && !AL.getScopeName(); @@ -4807,28 +4771,6 @@ static void handleObjCRequiresSuperAttr( Attrs.getRange(), S.Context, Attrs.getAttributeSpellingListIndex())); } -static void handleCFAuditedTransferAttr(Sema &S, Decl *D, -const AttributeList &AL) { - if (checkAttrMutualExclusion(S, D, AL.getRange(), - AL.getName())) -return; - - D->addAttr(::new (S.Context) - CFAuditedTransferAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); -} - -static void handleCFUnknownTransferAttr(Sema &S, Decl *D, -const AttributeList &AL) { - if (checkAttrMutualExclusion(S, D, AL.getRange(), - AL.getName())) -return; - - D->addAttr(::new (S.Context) - CFUnknownTransferAttr(AL.getRange(), S.Context, - AL.getAttributeSpellingListIndex())); -} - static void handleObjCBridgeAttr(Sema &S, Decl *D, const AttributeList &AL) { IdentifierLoc *Parm = AL.isArgIdent(0) ? AL.getArgAsIdent(0) : nullptr; @@ -6100,10 +6042,10 @@ static void ProcessDeclAttribute(Sema &S handleOwnershipAttr(S, D, AL); break; case AttributeList::AT_Cold: -handleColdAttr(S, D, AL); +handleSimpleAttributeWithExclusions(S, D, AL); break; case AttributeList::AT_Hot: -handleHotAttr(S, D, AL); +handleSimpleAttributeWithExclusions(S, D, AL); break; case AttributeList::AT_Naked: handleNakedAttr(S, D, AL); @@ -6154,10 +6096,12 @@ static void ProcessDeclAttribute(Sema &S handleObjCBoxable(S, D, AL); break; case AttributeList::AT_CFAuditedTransfer: -handleCFAuditedTransferAttr(S, D, AL); +handleSimpleAttributeWithExclusions(S, D, AL); break; case AttributeList::AT_CFUnknownTransfer: -handleCFUnknownTransferAttr(S, D, AL); +handleSimpleAttributeWithExclusions(S, D, AL); break; case AttributeList::AT_CFConsumed: case AttributeList::AT_NSConsumed: @@ -6225,10 +6169,12 @@ static void ProcessDeclAttribute(Sema &S handleSimpleAttribute(S, D, AL); break; case AttributeList::AT_NotTailCalled: -handleNotTa
r326676 - Amend r326665 to print out the `used` attribute subjects in a different order.
Author: aaronballman Date: Sun Mar 4 08:24:10 2018 New Revision: 326676 URL: http://llvm.org/viewvc/llvm-project?rev=326676&view=rev Log: Amend r326665 to print out the `used` attribute subjects in a different order. Modified: cfe/trunk/include/clang/Basic/Attr.td cfe/trunk/test/Sema/attr-used.c Modified: cfe/trunk/include/clang/Basic/Attr.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326676&r1=326675&r2=326676&view=diff == --- cfe/trunk/include/clang/Basic/Attr.td (original) +++ cfe/trunk/include/clang/Basic/Attr.td Sun Mar 4 08:24:10 2018 @@ -2010,7 +2010,7 @@ def Unused : InheritableAttr { def Used : InheritableAttr { let Spellings = [GCC<"used">]; - let Subjects = SubjectList<[Function, ObjCMethod, NonLocalVar]>; + let Subjects = SubjectList<[NonLocalVar, Function, ObjCMethod]>; let Documentation = [Undocumented]; } Modified: cfe/trunk/test/Sema/attr-used.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-used.c?rev=326676&r1=326675&r2=326676&view=diff == --- cfe/trunk/test/Sema/attr-used.c (original) +++ cfe/trunk/test/Sema/attr-used.c Sun Mar 4 08:24:10 2018 @@ -3,7 +3,7 @@ extern int l0 __attribute__((used)); // expected-warning {{'used' attribute ignored}} __private_extern__ int l1 __attribute__((used)); // expected-warning {{'used' attribute ignored}} -struct __attribute__((used)) s { // expected-warning {{'used' attribute only applies to functions, Objective-C methods, and variables with non-local storage}} +struct __attribute__((used)) s { // expected-warning {{'used' attribute only applies to variables with non-local storage, functions, and Objective-C methods}} int x; }; @@ -14,7 +14,7 @@ static void __attribute__((used)) f0(voi void f1() { static int a __attribute__((used)); - int b __attribute__((used)); // expected-warning {{'used' attribute only applies to functions, Objective-C methods, and variables with non-local storage}} + int b __attribute__((used)); // expected-warning {{'used' attribute only applies to variables with non-local storage, functions, and Objective-C methods}} } static void __attribute__((used)) f0(void); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: r326665 - Create a subject list for the `used` attribute rather than use custom checking logic.
Good suggestion -- I've switched the order in r326676. ~Aaron On Sat, Mar 3, 2018 at 6:16 PM, Nico Weber wrote: > Is it easy to mention variables first in the diag? That's probably the most > common subject for this attribute. (If it's not easy, nevermind -- > definitely a polish thing.) > > On Sat, Mar 3, 2018, 4:04 PM Aaron Ballman via cfe-commits > wrote: >> >> Author: aaronballman >> Date: Sat Mar 3 13:02:09 2018 >> New Revision: 326665 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=326665&view=rev >> Log: >> Create a subject list for the `used` attribute rather than use custom >> checking logic. >> >> This changes the diagnostic wording somewhat, but otherwise intends no >> functional change to the attribute. >> >> Modified: >> cfe/trunk/include/clang/Basic/Attr.td >> cfe/trunk/lib/Sema/SemaDeclAttr.cpp >> cfe/trunk/test/Sema/attr-used.c >> >> Modified: cfe/trunk/include/clang/Basic/Attr.td >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326665&r1=326664&r2=326665&view=diff >> >> == >> --- cfe/trunk/include/clang/Basic/Attr.td (original) >> +++ cfe/trunk/include/clang/Basic/Attr.td Sat Mar 3 13:02:09 2018 >> @@ -83,6 +83,9 @@ def LocalVar : SubsetSubject> def NonParmVar : SubsetSubject> [{S->getKind() != Decl::ParmVar}], >> "variables">; >> +def NonLocalVar : SubsetSubject> +[{!S->hasLocalStorage()}], >> +"variables with non-local storage">; >> def NonBitField : SubsetSubject> [{!S->isBitField()}], >> "non-bit-field non-static data members">; >> @@ -2007,6 +2010,7 @@ def Unused : InheritableAttr { >> >> def Used : InheritableAttr { >>let Spellings = [GCC<"used">]; >> + let Subjects = SubjectList<[Function, ObjCMethod, NonLocalVar]>; >>let Documentation = [Undocumented]; >> } >> >> >> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=326665&r1=326664&r2=326665&view=diff >> >> == >> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original) >> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sat Mar 3 13:02:09 2018 >> @@ -2086,23 +2086,6 @@ static void handleDisableTailCallsAttr(S >>AL.getRange(), S.Context, AL.getAttributeSpellingListIndex())); >> } >> >> -static void handleUsedAttr(Sema &S, Decl *D, const AttributeList &AL) { >> - if (const auto *VD = dyn_cast(D)) { >> -if (VD->hasLocalStorage()) { >> - S.Diag(AL.getLoc(), diag::warn_attribute_ignored) << AL.getName(); >> - return; >> -} >> - } else if (!isFunctionOrMethod(D)) { >> -S.Diag(AL.getLoc(), diag::warn_attribute_wrong_decl_type) >> - << AL.getName() << ExpectedVariableOrFunction; >> -return; >> - } >> - >> - D->addAttr(::new (S.Context) >> - UsedAttr(AL.getRange(), S.Context, >> - AL.getAttributeSpellingListIndex())); >> -} >> - >> static void handleUnusedAttr(Sema &S, Decl *D, const AttributeList &AL) { >>bool IsCXX17Attr = AL.isCXX11Attribute() && !AL.getScopeName(); >> >> @@ -6248,7 +6231,7 @@ static void ProcessDeclAttribute(Sema &S >> handleDisableTailCallsAttr(S, D, AL); >> break; >>case AttributeList::AT_Used: >> -handleUsedAttr(S, D, AL); >> +handleSimpleAttribute(S, D, AL); >> break; >>case AttributeList::AT_Visibility: >> handleVisibilityAttr(S, D, AL, false); >> >> Modified: cfe/trunk/test/Sema/attr-used.c >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-used.c?rev=326665&r1=326664&r2=326665&view=diff >> >> == >> --- cfe/trunk/test/Sema/attr-used.c (original) >> +++ cfe/trunk/test/Sema/attr-used.c Sat Mar 3 13:02:09 2018 >> @@ -3,7 +3,7 @@ >> extern int l0 __attribute__((used)); // expected-warning {{'used' >> attribute ignored}} >> __private_extern__ int l1 __attribute__((used)); // expected-warning >> {{'used' attribute ignored}} >> >> -struct __attribute__((used)) s { // expected-warning {{'used' attribute >> only applies to variables and functions}} >> +struct __attribute__((used)) s { // expected-warning {{'used' attribute >> only applies to functions, Objective-C methods, and variables with non-local >> storage}} >>int x; >> }; >> >> @@ -14,7 +14,7 @@ static void __attribute__((used)) f0(voi >> >> void f1() { >>static int a __attribute__((used)); >> - int b __attribute__((used)); // expected-warning {{'used' attribute >> ignored}} >> + int b __attribute__((used)); // expected-warning {{'used' attribute >> only applies to functions, Objective-C methods, and variables with non-local >> storage}} >> } >> >> static voi
[PATCH] D43764: [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting.
jdemeule added inline comments. Comment at: clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp:207 + llvm::DenseMap> + GroupedReplacements; + ioeric wrote: > jdemeule wrote: > > ioeric wrote: > > > I don't think we need to do the deduplication here anymore. AtomicChange > > > handles duplicates for you. I think all you need to do here is to group > > > replacements by files and later convert replacements to atomic changes. > > I think I wrongly use AtomicChange somewhere because it doesn't deduplicate > > same replacement automatically. > > For exemple, in the test suite, basic test defines 2 time the same > > replacement (adding 'override ' at offset 148) and I do not manage to avoid > > AtomicChange to add 'override override '. This is why I have kept the > > deduplicate step. > `AtomicChange` does deduplicate identical replacements but not insertions, > because it wouldn't know whether users really want the insertions to be > deduplicated or not (e.g. imagine a tool wants to insert two `)` at the same > location). So it doesn't support that test case intentionally. In general, > users (i.e. tools generating changes) are responsible for ensuring changes > are deduplicated/applied in the expected way by using the correct interface > (e.g. `replace`, `insert` etc). I think it would probably make more sense to > change the test to deduplicate identical non-insertion replacements. It would > also make sense to add another test case where identical insertions are both > applied. > > For more semantics of conflicting/duplicated replacements, see > https://github.com/llvm-mirror/clang/blob/master/include/clang/Tooling/Core/Replacement.h#L217 > That's make sense indeed. My confusion comes from I do not want to break existing tests. I will update them the way you describe. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D43764 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D44079: [ASTImporter] Allow testing of import sequences; fix import of typedefs for anonymous decls
a.sidorin created this revision. a.sidorin added reviewers: r.stahl, xazax.hun, jingham, szepet. Herald added subscribers: martong, rnkovacs. This patch introduces the ability to test an arbitrary sequence of imports between a given set of virtual source files. This should finally allow us to write simple tests and fix annoying issues inside ASTImporter that cause failures in CSA CTU. This is done by refactoring ASTImporterTest functions and introducing `testImportSequence` facility. As a side effect, `testImport` facility was generalized a bit more. It should now allow import of non-decl AST nodes; however, there is still no test using this ability. As a "test for test", there is also a fix for import anonymous TagDecls referred by typedef. Before this patch, the setting of typedef for anonymous structure was delayed; however, this approach misses the corner case if an enum constant is imported directly. In this patch, typedefs for anonymous declarations are imported right after the anonymous declaration is imported, without any delay. Repository: rC Clang https://reviews.llvm.org/D44079 Files: include/clang/AST/ASTImporter.h lib/AST/ASTImporter.cpp unittests/AST/ASTImporterTest.cpp Index: unittests/AST/ASTImporterTest.cpp === --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -18,10 +18,15 @@ #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Tooling/Tooling.h" #include "gtest/gtest.h" +#include "llvm/ADT/StringMap.h" namespace clang { namespace ast_matchers { +using internal::Matcher; +using internal::BindableMatcher; +using llvm::StringMap; + typedef std::vector ArgVector; typedef std::vector RunOptions; @@ -61,11 +66,48 @@ return {BasicArgs}; } -template +template +NodeType importNode(ASTUnit *From, ASTUnit *To, ASTImporter &Importer, +NodeType Node) { + ASTContext &ToCtx = To->getASTContext(); + + // Add 'From' file to virtual file system so importer can 'find' it + // while importing SourceLocations. It is safe to add same file multiple + // times - it just isn't replaced. + vfs::OverlayFileSystem *OFS = static_cast( + ToCtx.getSourceManager().getFileManager().getVirtualFileSystem().get()); + vfs::InMemoryFileSystem *MFS = + static_cast(OFS->overlays_begin()->get()); + + StringRef FromFileName = From->getMainFileName(); + MFS->addFile(FromFileName, 0, From->getBufferForFile(FromFileName)); + + auto Imported = Importer.Import(Node); + + // This should dump source locations and assert if some source locations + // were not imported. + SmallString<1024> ImportChecker; + llvm::raw_svector_ostream ToNothing(ImportChecker); + ToCtx.getTranslationUnitDecl()->print(ToNothing); + + // This traverses the AST to catch certain bugs like poorly or not + // implemented subtrees. + Imported->dump(ToNothing); + + return Imported; +} + + +const StringRef DeclToImportID = "declToImport"; +const StringRef DeclToVerifyID = "declToVerify"; + +template testing::AssertionResult testImport(const std::string &FromCode, const ArgVector &FromArgs, const std::string &ToCode, const ArgVector &ToArgs, - MatchVerifier &Verifier, const MatcherType &AMatcher) { + MatchVerifier &Verifier, + const BindableMatcher &SearchMatcher, + const BindableMatcher &VerificationMatcher) { const char *const InputFileName = "input.cc"; const char *const OutputFileName = "output.cc"; @@ -77,50 +119,47 @@ ASTContext &FromCtx = FromAST->getASTContext(), &ToCtx = ToAST->getASTContext(); - // Add input.cc to virtual file system so importer can 'find' it - // while importing SourceLocations. - vfs::OverlayFileSystem *OFS = static_cast( -ToCtx.getSourceManager().getFileManager().getVirtualFileSystem().get()); - vfs::InMemoryFileSystem *MFS = static_cast( -OFS->overlays_begin()->get()); - MFS->addFile(InputFileName, 0, llvm::MemoryBuffer::getMemBuffer(FromCode)); - ASTImporter Importer(ToCtx, ToAST->getFileManager(), FromCtx, FromAST->getFileManager(), false); - IdentifierInfo *ImportedII = &FromCtx.Idents.get("declToImport"); - assert(ImportedII && "Declaration with 'declToImport' name" - "should be specified in test!"); - DeclarationName ImportDeclName(ImportedII); - SmallVector FoundDecls; - FromCtx.getTranslationUnitDecl()->localUncachedLookup( -ImportDeclName, FoundDecls); + auto FoundNodes = match(SearchMatcher, FromCtx); + if (FoundNodes.size() != 1) +return testing::AssertionFailure() + << "Multiple potential nodes were found!"; - if (FoundDecls.size() != 1) -return testing::AssertionFailure() << "Multiple declarations were found!"; + auto ToImport = selectFirst(DeclToImportID, FoundNodes); + if (!ToImport) +return testing::AssertionFailure() << "Node ty
Re: r326676 - Amend r326665 to print out the `used` attribute subjects in a different order.
Awesome, thanks! On Sun, Mar 4, 2018, 11:26 AM Aaron Ballman via cfe-commits < cfe-commits@lists.llvm.org> wrote: > Author: aaronballman > Date: Sun Mar 4 08:24:10 2018 > New Revision: 326676 > > URL: http://llvm.org/viewvc/llvm-project?rev=326676&view=rev > Log: > Amend r326665 to print out the `used` attribute subjects in a different > order. > > Modified: > cfe/trunk/include/clang/Basic/Attr.td > cfe/trunk/test/Sema/attr-used.c > > Modified: cfe/trunk/include/clang/Basic/Attr.td > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=326676&r1=326675&r2=326676&view=diff > > == > --- cfe/trunk/include/clang/Basic/Attr.td (original) > +++ cfe/trunk/include/clang/Basic/Attr.td Sun Mar 4 08:24:10 2018 > @@ -2010,7 +2010,7 @@ def Unused : InheritableAttr { > > def Used : InheritableAttr { >let Spellings = [GCC<"used">]; > - let Subjects = SubjectList<[Function, ObjCMethod, NonLocalVar]>; > + let Subjects = SubjectList<[NonLocalVar, Function, ObjCMethod]>; >let Documentation = [Undocumented]; > } > > > Modified: cfe/trunk/test/Sema/attr-used.c > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-used.c?rev=326676&r1=326675&r2=326676&view=diff > > == > --- cfe/trunk/test/Sema/attr-used.c (original) > +++ cfe/trunk/test/Sema/attr-used.c Sun Mar 4 08:24:10 2018 > @@ -3,7 +3,7 @@ > extern int l0 __attribute__((used)); // expected-warning {{'used' > attribute ignored}} > __private_extern__ int l1 __attribute__((used)); // expected-warning > {{'used' attribute ignored}} > > -struct __attribute__((used)) s { // expected-warning {{'used' attribute > only applies to functions, Objective-C methods, and variables with > non-local storage}} > +struct __attribute__((used)) s { // expected-warning {{'used' attribute > only applies to variables with non-local storage, functions, and > Objective-C methods}} >int x; > }; > > @@ -14,7 +14,7 @@ static void __attribute__((used)) f0(voi > > void f1() { >static int a __attribute__((used)); > - int b __attribute__((used)); // expected-warning {{'used' attribute > only applies to functions, Objective-C methods, and variables with > non-local storage}} > + int b __attribute__((used)); // expected-warning {{'used' attribute > only applies to variables with non-local storage, functions, and > Objective-C methods}} > } > > static void __attribute__((used)) f0(void); > > > ___ > 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
[PATCH] D43764: [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting.
jdemeule updated this revision to Diff 136944. jdemeule added a comment. Update patch after reviewer comments. https://reviews.llvm.org/D43764 Files: clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp clang-apply-replacements/tool/CMakeLists.txt clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp test/clang-apply-replacements/Inputs/basic/basic.h test/clang-apply-replacements/Inputs/basic/file1.yaml test/clang-apply-replacements/Inputs/basic/file2.yaml test/clang-apply-replacements/Inputs/conflict/expected.txt unittests/clang-apply-replacements/ApplyReplacementsTest.cpp unittests/clang-apply-replacements/CMakeLists.txt unittests/clang-apply-replacements/ReformattingTest.cpp Index: unittests/clang-apply-replacements/ReformattingTest.cpp === --- unittests/clang-apply-replacements/ReformattingTest.cpp +++ /dev/null @@ -1,67 +0,0 @@ -//===- clang-apply-replacements/ReformattingTest.cpp --===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===--===// - -#include "clang-apply-replacements/Tooling/ApplyReplacements.h" -#include "common/VirtualFileHelper.h" -#include "clang/Format/Format.h" -#include "clang/Tooling/Refactoring.h" -#include "gtest/gtest.h" - -using namespace clang; -using namespace clang::tooling; -using namespace clang::replace; - -typedef std::vector ReplacementsVec; - -static Replacement makeReplacement(unsigned Offset, unsigned Length, - unsigned ReplacementLength, - llvm::StringRef FilePath = "") { - return Replacement(FilePath, Offset, Length, - std::string(ReplacementLength, '~')); -} - -// generate a set of replacements containing one element -static ReplacementsVec makeReplacements(unsigned Offset, unsigned Length, -unsigned ReplacementLength, -llvm::StringRef FilePath = "~") { - ReplacementsVec Replaces; - Replaces.push_back( - makeReplacement(Offset, Length, ReplacementLength, FilePath)); - return Replaces; -} - -// Put these functions in the clang::tooling namespace so arg-dependent name -// lookup finds these functions for the EXPECT_EQ macros below. -namespace clang { -namespace tooling { - -std::ostream &operator<<(std::ostream &os, const Range &R) { - return os << "Range(" << R.getOffset() << ", " << R.getLength() << ")"; -} - -} // namespace tooling -} // namespace clang - -// Ensure zero-length ranges are produced. Even lines where things are deleted -// need reformatting. -TEST(CalculateChangedRangesTest, producesZeroLengthRange) { - RangeVector Changes = calculateChangedRanges(makeReplacements(0, 4, 0)); - EXPECT_EQ(Range(0, 0), Changes.front()); -} - -// Basic test to ensure replacements turn into ranges properly. -TEST(CalculateChangedRangesTest, calculatesRanges) { - ReplacementsVec R; - R.push_back(makeReplacement(2, 0, 3)); - R.push_back(makeReplacement(5, 2, 4)); - RangeVector Changes = calculateChangedRanges(R); - - Range ExpectedRanges[] = { Range(2, 3), Range(8, 4) }; - EXPECT_TRUE(std::equal(Changes.begin(), Changes.end(), ExpectedRanges)); -} Index: unittests/clang-apply-replacements/CMakeLists.txt === --- unittests/clang-apply-replacements/CMakeLists.txt +++ unittests/clang-apply-replacements/CMakeLists.txt @@ -9,12 +9,12 @@ add_extra_unittest(ClangApplyReplacementsTests ApplyReplacementsTest.cpp - ReformattingTest.cpp ) target_link_libraries(ClangApplyReplacementsTests PRIVATE clangApplyReplacements clangBasic clangToolingCore + clangToolingRefactor ) Index: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp === --- unittests/clang-apply-replacements/ApplyReplacementsTest.cpp +++ unittests/clang-apply-replacements/ApplyReplacementsTest.cpp @@ -9,6 +9,7 @@ //===--===// #include "clang-apply-replacements/Tooling/ApplyReplacements.h" +#include "clang/Format/Format.h" #include "gtest/gtest.h" using namespace clang::replace; @@ -41,11 +42,12 @@ IntrusiveRefCntPtr(new DiagnosticIDs()), DiagOpts.get()); FileManager Files((FileSystemOptions())); SourceManager SM(Diagnostics, Files); + TUReplacements TURs; TUDiagnostics TUs = makeTUDiagnostics("path/to/source.cpp", "diagnostic", {}, {}, "path/to"); - FileToReplacementsMap ReplacementsMap; + FileToChangesMap ReplacementsMap; - EXPECT_TRUE(mergeAndDeduplicate(T