Re: [PATCH] D22567: [include-fixer] Add mising qualifiers to all instances of an unidentified symbol.
hokein added inline comments. Comment at: include-fixer/tool/ClangIncludeFixer.cpp:365 @@ +364,3 @@ + for (const auto : Context.getQuerySymbolInfos()) { +Replacements->insert({FilePath, Info.Range.getOffset(), + Info.Range.getLength(), ioeric wrote: > Now that we insert namespace qualifiers, we might want to do a > `formatReplacements` before applying them. Good point! So that we won't break the current code style. The line probably exceeds 80 characters after adding qualifiers. https://reviews.llvm.org/D22567 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D22567: [include-fixer] Add mising qualifiers to all instances of an unidentified symbol.
hokein updated this revision to Diff 64848. hokein marked 3 inline comments as done. hokein added a comment. Address review comments. https://reviews.llvm.org/D22567 Files: include-fixer/IncludeFixer.cpp include-fixer/IncludeFixer.h include-fixer/IncludeFixerContext.cpp include-fixer/IncludeFixerContext.h include-fixer/tool/ClangIncludeFixer.cpp include-fixer/tool/clang-include-fixer.py test/include-fixer/commandline_options.cpp unittests/include-fixer/IncludeFixerTest.cpp Index: unittests/include-fixer/IncludeFixerTest.cpp === --- unittests/include-fixer/IncludeFixerTest.cpp +++ unittests/include-fixer/IncludeFixerTest.cpp @@ -89,17 +89,14 @@ runOnCode(, Code, FakeFileName, ExtraArgs); if (FixerContext.getHeaderInfos().empty()) return Code; - auto Replaces = clang::include_fixer::createInsertHeaderReplacements( - Code, FakeFileName, FixerContext.getHeaderInfos().front().Header); + auto Replaces = clang::include_fixer::createIncludeFixerReplacements( + Code, FakeFileName, FixerContext); EXPECT_TRUE(static_cast(Replaces)) << llvm::toString(Replaces.takeError()) << "\n"; if (!Replaces) return ""; clang::RewriterTestContext Context; clang::FileID ID = Context.createInMemoryFile(FakeFileName, Code); - Replaces->insert({FakeFileName, FixerContext.getSymbolRange().getOffset(), -FixerContext.getSymbolRange().getLength(), -FixerContext.getHeaderInfos().front().QualifiedName}); clang::tooling::applyAllReplacements(*Replaces, Context.Rewrite); return Context.getRewrittenText(ID); } @@ -211,12 +208,12 @@ std::string Code = "#include \"a.h\"\n" "#include \"foo.h\"\n" "\n" - "namespace a { b::bar b; }"; + "namespace a {\nb::bar b;\n}\n"; std::string Expected = "#include \"a.h\"\n" "#include \"bar.h\"\n" "#include \"foo.h\"\n" "\n" - "namespace a { b::bar b; }"; + "namespace a {\nb::bar b;\n}\n"; EXPECT_EQ(Expected, runIncludeFixer(Code)); } @@ -275,6 +272,69 @@ runIncludeFixer("namespace a {\n::a::b::bar b;\n}\n")); } +TEST(IncludeFixer, FixNamespaceQualifiersForAllInstances) { + const char TestCode[] = R"( +namespace a { +bar b; +int func1() { + bar a; + bar *p = new bar(); + return 0; +} +} // namespace a + +namespace a { +bar func2() { + bar f; + return f; +} +} // namespace a + +// Non-fixed cases: +void f() { + bar b; +} + +namespace a { +namespace c { + bar b; +} // namespace c +} // namespace a +)"; + + const char ExpectedCode[] = R"( +#include "bar.h" +namespace a { +b::bar b; +int func1() { + b::bar a; + b::bar *p = new b::bar(); + return 0; +} +} // namespace a + +namespace a { +b::bar func2() { + b::bar f; + return f; +} +} // namespace a + +// Non-fixed cases: +void f() { + bar b; +} + +namespace a { +namespace c { + bar b; +} // namespace c +} // namespace a +)"; + + EXPECT_EQ(ExpectedCode, runIncludeFixer(TestCode)); +} + } // namespace } // namespace include_fixer } // namespace clang Index: test/include-fixer/commandline_options.cpp === --- test/include-fixer/commandline_options.cpp +++ test/include-fixer/commandline_options.cpp @@ -1,9 +1,9 @@ // REQUIRES: shell // RUN: echo "foo f;" > %t.cpp // RUN: clang-include-fixer -db=fixed -input='foo= "foo.h","bar.h"' -output-headers %t.cpp -- | FileCheck %s -// RUN: cat %t.cpp | clang-include-fixer -stdin -insert-header='{QuerySymbolInfo: {RawIdentifier: foo, Range: {Offset: 0, Length: 3}}, HeaderInfos: [{Header: "\"foo.h\"", QualifiedName: "foo"}]}' %t.cpp | FileCheck %s -check-prefix=CHECK-CODE -// RUN: cat %t.cpp | not clang-include-fixer -stdin -insert-header='{QuerySymbolInfo: {RawIdentifier: foo, Range: {Offset: 0, Length: 3}}, HeaderInfos: [{Header: "\"foo.h\"", QualifiedName: "foo"},{Header: "\"foo2.h\"", QualifiedName: "foo"}]}' %t.cpp -// RUN: cat %t.cpp | clang-include-fixer -stdin -insert-header='{QuerySymbolInfo: {RawIdentifier: foo, Range: {Offset: 0, Length: 3}}, HeaderInfos: [{Header: "\"foo.h\"", QualifiedName: "a:foo"},{Header: "\"foo.h\"", QualifiedName: "b:foo"}]}' %t.cpp +// RUN: cat %t.cpp | clang-include-fixer -stdin -insert-header='{QuerySymbolInfos: [{RawIdentifier: foo, Range: {Offset: 0, Length: 3}}], HeaderInfos: [{Header: "\"foo.h\"", QualifiedName: "foo"}]}' %t.cpp | FileCheck %s -check-prefix=CHECK-CODE +// RUN: cat %t.cpp | not clang-include-fixer -stdin -insert-header='{QuerySymbolInfos: [{RawIdentifier: foo, Range: {Offset: 0, Length: 3}}], HeaderInfos: [{Header: "\"foo.h\"", QualifiedName: "foo"},{Header: "\"foo2.h\"", QualifiedName: "foo"}]}' %t.cpp +// RUN: cat %t.cpp |
Re: [PATCH] D22465: [clang-rename] introduce better symbol finding and add few more tests
omtcyfz updated this revision to Diff 64844. https://reviews.llvm.org/D22465 Files: clang-rename/RenamingAction.cpp clang-rename/USRFinder.cpp clang-rename/USRFinder.h clang-rename/USRLocFinder.cpp test/clang-rename/ClassNameInFunctionDefenition.cpp test/clang-rename/ComplicatedClassType.cpp test/clang-rename/ComplicatedClassTypeInCustomNamespace.cpp test/clang-rename/FindNameSpaceInNestedNameSpec.cpp test/clang-rename/NestedNamespace.cpp test/clang-rename/TemplateTypename.cpp test/clang-rename/UserDefinedConversion.cpp test/clang-rename/UserDefinedConversionFindByConversion.cpp test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp Index: test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp === --- test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp +++ test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp @@ -1,7 +1,6 @@ -// Currently unsupported test. // RUN: cat %s > %t.cpp -// FIXME: while renaming class/struct clang-rename should be able to change -// this type name corresponding user-defined conversions, too. +// RUN: clang-rename -offset=136 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s class Foo { // CHECK: class Bar { //^ offset must be here @@ -22,3 +21,6 @@ Foo foo = static_cast(boo); // CHECK: Bar foo = static_cast(boo); return 0; } + +// Use grep -FUbo 'Foo' to get the correct offset of Cla when changing +// this file. Index: test/clang-rename/UserDefinedConversionFindByConversion.cpp === --- /dev/null +++ test/clang-rename/UserDefinedConversionFindByConversion.cpp @@ -0,0 +1,29 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=441 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +// FIXME: clang-rename removes "operator " while renaming user-defined +// conversion only if offset points to the conversion for some reason. +// XFAIL: * + +class Foo { // CHECK: class Bar { +public: + Foo() {} // CHECK: Bar() {} +}; + +class Baz { +public: + operator Foo() const {// CHECK: operator Bar() const { +Foo foo;// CHECK: Bar foo; +return foo; + } +}; + +int main() { + Baz boo; + Foo foo = static_cast(boo); // CHECK: Bar foo = static_cast(boo); + return 0; +} + +// Use grep -FUbo 'Foo' to get the correct offset of Cla when changing +// this file. Index: test/clang-rename/UserDefinedConversion.cpp === --- test/clang-rename/UserDefinedConversion.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// Currently unsupported test. -// RUN: cat %s > %t.cpp -// FIXME: clang-rename should handle conversions from a class type to another -// type. - -class Foo {}; // CHECK: class Bar {}; - -class Baz { // CHECK: class Bar { - operator Foo() const { // CHECK: operator Bar() const { -Foo foo; // CHECK: Bar foo; -return foo; - } -}; Index: test/clang-rename/TemplateTypename.cpp === --- test/clang-rename/TemplateTypename.cpp +++ test/clang-rename/TemplateTypename.cpp @@ -1,12 +1,20 @@ -// Currently unsupported test. // RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=270 -new-name=U %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +// Currently unsupported test. // FIXME: clang-rename should be able to rename template parameters correctly. +// XFAIL: * -template -T foo(T arg, T& ref, T* ptr) { - T value; +template // CHECK: template +class Foo { +T foo(T arg, T& ref, T* ptr) {// CHECK: U foo(U arg, U& ref, U* ptr) { + T value;// CHECK: U value; int number = 42; - value = (T)number; - value = static_cast(number); + value = (T)number; // CHECK: value = (U)number; + value = static_cast(number); // CHECK: value = static_cast(number); return value; } + +T member; // CHECK: U member; +}; Index: test/clang-rename/NestedNamespace.cpp === --- /dev/null +++ test/clang-rename/NestedNamespace.cpp @@ -0,0 +1,38 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=156 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +namespace Baz { +namespace Foo { // CHECK: namespace Bar { +class A { +public: + static int aFunction() { return 0; } +}; +int FooFunction() { return 0; } +namespace Qux { +class B { +public: + static int bFunction() { return 0; } +}; +int QuxFunction() { return 0; } +} // namespace Qux +} // namespace Foo +} // namespace Baz + +int main() { + + // Variable type tests. + Baz::Foo::A a; // CHECK: Baz::Bar::A
Re: [PATCH] D22465: [clang-rename] introduce better symbol finding and add few more tests
omtcyfz updated this revision to Diff 64841. omtcyfz added a comment. add one more XFAIL test https://reviews.llvm.org/D22465 Files: clang-rename/RenamingAction.cpp clang-rename/USRFinder.cpp clang-rename/USRFinder.h clang-rename/USRLocFinder.cpp test/clang-rename/ClassNameInFunctionDefenition.cpp test/clang-rename/ComplicatedClassType.cpp test/clang-rename/ComplicatedClassTypeInCustomNamespace.cpp test/clang-rename/FindNameSpaceInNestedNameSpec.cpp test/clang-rename/NestedNamespace.cpp test/clang-rename/TemplateTypename.cpp test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp Index: test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp === --- test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp +++ test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp @@ -1,7 +1,6 @@ -// Currently unsupported test. // RUN: cat %s > %t.cpp -// FIXME: while renaming class/struct clang-rename should be able to change -// this type name corresponding user-defined conversions, too. +// RUN: clang-rename -offset=136 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s class Foo { // CHECK: class Bar { //^ offset must be here Index: test/clang-rename/TemplateTypename.cpp === --- test/clang-rename/TemplateTypename.cpp +++ test/clang-rename/TemplateTypename.cpp @@ -1,12 +1,20 @@ -// Currently unsupported test. // RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=270 -new-name=U %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +// Currently unsupported test. // FIXME: clang-rename should be able to rename template parameters correctly. +// XFAIL: * -template -T foo(T arg, T& ref, T* ptr) { - T value; +template // CHECK: template +class Foo { +T foo(T arg, T& ref, T* ptr) {// CHECK: U foo(U arg, U& ref, U* ptr) { + T value;// CHECK: U value; int number = 42; - value = (T)number; - value = static_cast(number); + value = (T)number; // CHECK: value = (U)number; + value = static_cast(number); // CHECK: value = static_cast(number); return value; } + +T member; // CHECK: U member; +}; Index: test/clang-rename/NestedNamespace.cpp === --- /dev/null +++ test/clang-rename/NestedNamespace.cpp @@ -0,0 +1,38 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=156 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +namespace Baz { +namespace Foo { // CHECK: namespace Bar { +class A { +public: + static int aFunction() { return 0; } +}; +int FooFunction() { return 0; } +namespace Qux { +class B { +public: + static int bFunction() { return 0; } +}; +int QuxFunction() { return 0; } +} // namespace Qux +} // namespace Foo +} // namespace Baz + +int main() { + + // Variable type tests. + Baz::Foo::A a; // CHECK: Baz::Bar::A a; + Baz::Foo::Qux::B b; // CHECK: Baz::Bar::Qux::B b; + unsigned i = 42; + for (Baz::Foo::A c; i < 100; i++); // CHECK: for (Baz::Bar::A c; i < 100; i++); + for (Baz::Foo::Qux::B d; i < 200; i++); // CHECK: for (Baz::Bar::Qux::B d; i < 200; i++); + + // Function tests. + int x = Baz::Foo::A::aFunction(); // CHECK: int x = Baz::Bar::A::aFunction(); + x = Baz::Foo::FooFunction();// CHECK: x = Baz::Bar::FooFunction(); + x = Baz::Foo::Qux::B::bFunction(); // CHECK: x = Baz::Bar::Qux::B::bFunction(); + x = Baz::Foo::Qux::QuxFunction(); // CHECK: x = Baz::Bar::Qux::QuxFunction(); + + return 0; +} Index: test/clang-rename/FindNameSpaceInNestedNameSpec.cpp === --- /dev/null +++ test/clang-rename/FindNameSpaceInNestedNameSpec.cpp @@ -0,0 +1,37 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=583 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +namespace Baz { +namespace Foo { // CHECK: namespace Bar { +class A { +public: + static int aFunction() { return 0; } +}; +int FooFunction() { return 0; } +namespace Qux { +class B { +public: + static int bFunction() { return 0; } +}; +int QuxFunction() { return 0; } +} // namespace Qux +} // namespace Foo +} // namespace Baz + +int main() { + // Variable type tests. + Baz::Foo::A a; // CHECK: Baz::Bar::A a; + Baz::Foo::Qux::B b; // CHECK: Baz::Bar::Qux::B b; + unsigned i = 42; + for (Baz::Foo::A c; i < 100; i++); // CHECK: for (Baz::Bar::A c; i < 100; i++); + for (Baz::Foo::Qux::B d; i < 200; i++); // CHECK: for (Baz::Bar::Qux::B d; i < 200; i++); + + // Function tests. + int x = Baz::Foo::A::aFunction(); // CHECK: int x = Baz::Bar::A::aFunction();
Re: [PATCH] D22465: [clang-rename] introduce better symbol finding and add few more tests
omtcyfz updated this revision to Diff 64839. omtcyfz added a comment. fix previously unsupported test https://reviews.llvm.org/D22465 Files: clang-rename/RenamingAction.cpp clang-rename/USRFinder.cpp clang-rename/USRFinder.h clang-rename/USRLocFinder.cpp test/clang-rename/ClassNameInFunctionDefenition.cpp test/clang-rename/ComplicatedClassType.cpp test/clang-rename/ComplicatedClassTypeInCustomNamespace.cpp test/clang-rename/FindNameSpaceInNestedNameSpec.cpp test/clang-rename/NestedNamespace.cpp test/clang-rename/TemplateTypename.cpp test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp Index: test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp === --- test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp +++ test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp @@ -1,7 +1,6 @@ -// Currently unsupported test. // RUN: cat %s > %t.cpp -// FIXME: while renaming class/struct clang-rename should be able to change -// this type name corresponding user-defined conversions, too. +// RUN: clang-rename -offset=136 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s class Foo { // CHECK: class Bar { //^ offset must be here Index: test/clang-rename/TemplateTypename.cpp === --- test/clang-rename/TemplateTypename.cpp +++ test/clang-rename/TemplateTypename.cpp @@ -1,12 +1,20 @@ -// Currently unsupported test. // RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=270 -new-name=U %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +// Currently unsupported test. // FIXME: clang-rename should be able to rename template parameters correctly. +// XFAIL: * -template -T foo(T arg, T& ref, T* ptr) { - T value; +template // CHECK: template +class Foo { +T foo(T arg, T& ref, T* ptr) {// CHECK: U foo(U arg, U& ref, U* ptr) { + T value;// CHECK: U value; int number = 42; - value = (T)number; - value = static_cast(number); + value = (T)number; // CHECK: value = (U)number; + value = static_cast(number); // CHECK: value = static_cast(number); return value; } + +T member; // CHECK: U member; +}; Index: test/clang-rename/NestedNamespace.cpp === --- /dev/null +++ test/clang-rename/NestedNamespace.cpp @@ -0,0 +1,38 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=156 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +namespace Baz { +namespace Foo { // CHECK: namespace Bar { +class A { +public: + static int aFunction() { return 0; } +}; +int FooFunction() { return 0; } +namespace Qux { +class B { +public: + static int bFunction() { return 0; } +}; +int QuxFunction() { return 0; } +} // namespace Qux +} // namespace Foo +} // namespace Baz + +int main() { + + // Variable type tests. + Baz::Foo::A a; // CHECK: Baz::Bar::A a; + Baz::Foo::Qux::B b; // CHECK: Baz::Bar::Qux::B b; + unsigned i = 42; + for (Baz::Foo::A c; i < 100; i++); // CHECK: for (Baz::Bar::A c; i < 100; i++); + for (Baz::Foo::Qux::B d; i < 200; i++); // CHECK: for (Baz::Bar::Qux::B d; i < 200; i++); + + // Function tests. + int x = Baz::Foo::A::aFunction(); // CHECK: int x = Baz::Bar::A::aFunction(); + x = Baz::Foo::FooFunction();// CHECK: x = Baz::Bar::FooFunction(); + x = Baz::Foo::Qux::B::bFunction(); // CHECK: x = Baz::Bar::Qux::B::bFunction(); + x = Baz::Foo::Qux::QuxFunction(); // CHECK: x = Baz::Bar::Qux::QuxFunction(); + + return 0; +} Index: test/clang-rename/FindNameSpaceInNestedNameSpec.cpp === --- /dev/null +++ test/clang-rename/FindNameSpaceInNestedNameSpec.cpp @@ -0,0 +1,37 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=583 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +namespace Baz { +namespace Foo { // CHECK: namespace Bar { +class A { +public: + static int aFunction() { return 0; } +}; +int FooFunction() { return 0; } +namespace Qux { +class B { +public: + static int bFunction() { return 0; } +}; +int QuxFunction() { return 0; } +} // namespace Qux +} // namespace Foo +} // namespace Baz + +int main() { + // Variable type tests. + Baz::Foo::A a; // CHECK: Baz::Bar::A a; + Baz::Foo::Qux::B b; // CHECK: Baz::Bar::Qux::B b; + unsigned i = 42; + for (Baz::Foo::A c; i < 100; i++); // CHECK: for (Baz::Bar::A c; i < 100; i++); + for (Baz::Foo::Qux::B d; i < 200; i++); // CHECK: for (Baz::Bar::Qux::B d; i < 200; i++); + + // Function tests. + int x = Baz::Foo::A::aFunction(); // CHECK: int x =
Re: [PATCH] D22465: [clang-rename] introduce better symbol finding and add few more tests
omtcyfz updated this revision to Diff 64838. omtcyfz added a comment. few fixes https://reviews.llvm.org/D22465 Files: clang-rename/RenamingAction.cpp clang-rename/USRFinder.cpp clang-rename/USRFinder.h clang-rename/USRLocFinder.cpp test/clang-rename/ClassNameInFunctionDefenition.cpp test/clang-rename/ComplicatedClassType.cpp test/clang-rename/ComplicatedClassTypeInCustomNamespace.cpp test/clang-rename/FindNameSpaceInNestedNameSpec.cpp test/clang-rename/NestedNamespace.cpp test/clang-rename/TemplateTypename.cpp test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp Index: test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp === --- test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp +++ test/clang-rename/UserDefinedConversionFindByTypeDeclaration.cpp @@ -1,7 +1,6 @@ -// Currently unsupported test. // RUN: cat %s > %t.cpp -// FIXME: while renaming class/struct clang-rename should be able to change -// this type name corresponding user-defined conversions, too. +// RUN: clang-rename -offset=136 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s class Foo { // CHECK: class Bar { //^ offset must be here Index: test/clang-rename/TemplateTypename.cpp === --- test/clang-rename/TemplateTypename.cpp +++ test/clang-rename/TemplateTypename.cpp @@ -1,12 +1,20 @@ -// Currently unsupported test. // RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=270 -new-name=U %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +// Currently unsupported test. // FIXME: clang-rename should be able to rename template parameters correctly. +// XFAIL: * -template -T foo(T arg, T& ref, T* ptr) { - T value; +template // CHECK: template +class Foo { +T foo(T arg, T& ref, T* ptr) {// CHECK: U foo(U arg, U& ref, U* ptr) { + T value;// CHECK: U value; int number = 42; - value = (T)number; - value = static_cast(number); + value = (T)number; // CHECK: value = (U)number; + value = static_cast(number); // CHECK: value = static_cast(number); return value; } + +T member; // CHECK: U member; +}; Index: test/clang-rename/NestedNamespace.cpp === --- /dev/null +++ test/clang-rename/NestedNamespace.cpp @@ -0,0 +1,38 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=156 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +namespace Baz { +namespace Foo { // CHECK: namespace Bar { +class A { +public: + static int aFunction() { return 0; } +}; +int FooFunction() { return 0; } +namespace Qux { +class B { +public: + static int bFunction() { return 0; } +}; +int QuxFunction() { return 0; } +} // namespace Qux +} // namespace Foo +} // namespace Baz + +int main() { + + // Variable type tests. + Baz::Foo::A a; // CHECK: Baz::Bar::A a; + Baz::Foo::Qux::B b; // CHECK: Baz::Bar::Qux::B b; + unsigned i = 42; + for (Baz::Foo::A c; i < 100; i++); // CHECK: for (Baz::Bar::A c; i < 100; i++); + for (Baz::Foo::Qux::B d; i < 200; i++); // CHECK: for (Baz::Bar::Qux::B d; i < 200; i++); + + // Function tests. + int x = Baz::Foo::A::aFunction(); // CHECK: int x = Baz::Bar::A::aFunction(); + x = Baz::Foo::FooFunction();// CHECK: x = Baz::Bar::FooFunction(); + x = Baz::Foo::Qux::B::bFunction(); // CHECK: x = Baz::Bar::Qux::B::bFunction(); + x = Baz::Foo::Qux::QuxFunction(); // CHECK: x = Baz::Bar::Qux::QuxFunction(); + + return 0; +} Index: test/clang-rename/FindNameSpaceInNestedNameSpec.cpp === --- /dev/null +++ test/clang-rename/FindNameSpaceInNestedNameSpec.cpp @@ -0,0 +1,37 @@ +// RUN: cat %s > %t.cpp +// RUN: clang-rename -offset=583 -new-name=Bar %t.cpp -i -- +// RUN: sed 's,//.*,,' %t.cpp | FileCheck %s + +namespace Baz { +namespace Foo { // CHECK: namespace Bar { +class A { +public: + static int aFunction() { return 0; } +}; +int FooFunction() { return 0; } +namespace Qux { +class B { +public: + static int bFunction() { return 0; } +}; +int QuxFunction() { return 0; } +} // namespace Qux +} // namespace Foo +} // namespace Baz + +int main() { + // Variable type tests. + Baz::Foo::A a; // CHECK: Baz::Bar::A a; + Baz::Foo::Qux::B b; // CHECK: Baz::Bar::Qux::B b; + unsigned i = 42; + for (Baz::Foo::A c; i < 100; i++); // CHECK: for (Baz::Bar::A c; i < 100; i++); + for (Baz::Foo::Qux::B d; i < 200; i++); // CHECK: for (Baz::Bar::Qux::B d; i < 200; i++); + + // Function tests. + int x = Baz::Foo::A::aFunction(); // CHECK: int x = Baz::Bar::A::aFunction(); + x =
Re: [PATCH] D22465: [clang-rename] introduce better symbol finding and add few more tests
omtcyfz added a comment. ping https://reviews.llvm.org/D22465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21814: clang-rename: split existing options into two new subcommands
omtcyfz added a comment. The patch looks fine to me (though I'm not sure if there are no new tests; if they are interface changes should be applied). If everyone seems to be in favor of such changes, I'm OK with it, but in general I think it makes things more complicated and I'm not sure if it's necessary at the moment; I expressed my ideas about it in comments to the other patch. But if that's what the common use-case is... So, //TL;DR// I personally don't see why one would want to rename multiple things at once while we still can't rename a single symbol correctly in too many cases... P.S. it seems logical to me to support `-offset` option in `-rename-all`, too. And introducing `-rename-all` without actually supporting multiple renaming actions "at once" seems weird to me, too. Comment at: clang-rename/tool/ClangRename.cpp:226 @@ +225,3 @@ + if (argc > 1) { +typedef int (*MainFunction)(int, const char *[]); +MainFunction Func = StringSwitch(argv[1]) use `std::function` here? https://reviews.llvm.org/D21814 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21814: clang-rename: split existing options into two new subcommands
klimek added a comment. Kirill, you happy with this approach? https://reviews.llvm.org/D21814 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21459: Implement http://wg21.link/P0254R1: "Integrating std::string_view and std::string"
kimgr added a subscriber: kimgr. kimgr added a comment. Inline question on ctor+nullptr Comment at: include/string_view:216 @@ +215,3 @@ + basic_string_view(const _CharT* __s) + : __data(__s), __size(_Traits::length(__s)) {} + I'm working from the paper at https://isocpp.org/files/papers/N3762.html, and I find it a little sketchy on the policy for nullptrs. Since the ctor above accepts nullptr as long as the length is zero, would it make sense to do that here too? That is, only call _Traits::length for non-nullptr __s args? https://reviews.llvm.org/D21459 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r276252 - Provide __GLIBCXX_TYPE_INT_N_0 and __GLIBCXX_BITSIZE_INT_N_0 when in C++ gnu language extensions.
Author: yrnkrn Date: Thu Jul 21 02:44:41 2016 New Revision: 276252 URL: http://llvm.org/viewvc/llvm-project?rev=276252=rev Log: Provide __GLIBCXX_TYPE_INT_N_0 and __GLIBCXX_BITSIZE_INT_N_0 when in C++ gnu language extensions. These are used by libstdc++ for is_integral<__int128>. Addresses http://llvm.org/pr23156. Added: cfe/trunk/test/Frontend/int128.cpp Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=276252=276251=276252=diff == --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original) +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Thu Jul 21 02:44:41 2016 @@ -961,6 +961,11 @@ static void InitializePredefinedMacros(c #include "clang/Basic/OpenCLExtensions.def" } + if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) { +Builder.defineMacro("__GLIBCXX_TYPE_INT_N_0", "__int128"); +Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128"); + } + // Get other target #defines. TI.getTargetDefines(LangOpts, Builder); } Added: cfe/trunk/test/Frontend/int128.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/int128.cpp?rev=276252=auto == --- cfe/trunk/test/Frontend/int128.cpp (added) +++ cfe/trunk/test/Frontend/int128.cpp Thu Jul 21 02:44:41 2016 @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -x c -std=gnu99 -dM -E -triple x86_64-pc-linux %s | FileCheck -check-prefix=NO %s +// RUN: %clang_cc1 -x c++ -std=c++11 -dM -E -triple x86_64-pc-linux %s | FileCheck -check-prefix=NO %s +// RUN: %clang_cc1 -x c++ -std=gnu++11 -dM -E -triple i686-pc-linux %s | FileCheck -check-prefix=NO %s +// RUN: %clang_cc1 -x c++ -std=gnu++11 -dM -E -triple x86_64-pc-linux %s | FileCheck -check-prefix=YES %s +// RUN: %clang_cc1 -x c++ -std=gnu++1y -dM -E -triple x86_64-pc-linux %s | FileCheck -check-prefix=YES %s +// PR23156 + +// NO-NOT: __GLIBCXX_TYPE_INT_N_0 +// NO-NOT: __GLIBCXX_BITSIZE_INT_N_0 +// YES-DAG: __GLIBCXX_TYPE_INT_N_0 +// YES-DAG: __GLIBCXX_BITSIZE_INT_N_0 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21814: clang-rename: split existing options into two new subcommands
vmiklos added a comment. Is there anything I can help with to get this reviewed, please? As far as I see it still applies cleanly on top of current trunk. https://reviews.llvm.org/D21814 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r276249 - [X86] Add missing __x86_64__ qualifiers on a bunch of intrinsics that assume 64-bit GPRs are available.
Author: ctopper Date: Thu Jul 21 02:38:39 2016 New Revision: 276249 URL: http://llvm.org/viewvc/llvm-project?rev=276249=rev Log: [X86] Add missing __x86_64__ qualifiers on a bunch of intrinsics that assume 64-bit GPRs are available. Usages of these intrinsics in a 32-bit build results in assertions in the backend. Modified: cfe/trunk/lib/Headers/avx512bwintrin.h cfe/trunk/lib/Headers/avx512fintrin.h cfe/trunk/lib/Headers/avx512vlbwintrin.h cfe/trunk/lib/Headers/avx512vlintrin.h cfe/trunk/lib/Headers/fxsrintrin.h cfe/trunk/lib/Headers/xmmintrin.h cfe/trunk/test/CodeGen/avx512f-builtins.c cfe/trunk/test/CodeGen/avx512vl-builtins.c Modified: cfe/trunk/lib/Headers/avx512bwintrin.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=276249=276248=276249=diff == --- cfe/trunk/lib/Headers/avx512bwintrin.h (original) +++ cfe/trunk/lib/Headers/avx512bwintrin.h Thu Jul 21 02:38:39 2016 @@ -2099,6 +2099,7 @@ _mm512_maskz_mov_epi8 (__mmask64 __U, __ (__v64qi) _mm512_setzero_hi ()); } +#ifdef __x86_64__ static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_mask_set1_epi8 (__m512i __O, __mmask64 __M, char __A) { @@ -2115,6 +2116,7 @@ _mm512_maskz_set1_epi8 (__mmask64 __M, c _mm512_setzero_qi(), __M); } +#endif static __inline__ __mmask64 __DEFAULT_FN_ATTRS _mm512_kunpackd (__mmask64 __A, __mmask64 __B) Modified: cfe/trunk/lib/Headers/avx512fintrin.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512fintrin.h?rev=276249=276248=276249=diff == --- cfe/trunk/lib/Headers/avx512fintrin.h (original) +++ cfe/trunk/lib/Headers/avx512fintrin.h Thu Jul 21 02:38:39 2016 @@ -5911,8 +5911,10 @@ _mm512_kmov (__mmask16 __A) (int)__builtin_ia32_vcomiss((__v4sf)(__m128)(A), (__v4sf)(__m128)(B), \ (int)(P), (int)(R)); }) +#ifdef __x86_64__ #define _mm_cvt_roundsd_si64(A, R) __extension__ ({ \ (long long)__builtin_ia32_vcvtsd2si64((__v2df)(__m128d)(A), (int)(R)); }) +#endif static __inline__ __m512i __DEFAULT_FN_ATTRS _mm512_mask2_permutex2var_epi32 (__m512i __A, __m512i __I, @@ -6309,8 +6311,10 @@ _mm512_maskz_srlv_epi64 (__mmask8 __U, _ (__v8di)(__m512i)(C), (int)(imm), \ (__mmask8)(U)); }) +#ifdef __x86_64__ #define _mm_cvt_roundsd_i64(A, R) __extension__ ({ \ (long long)__builtin_ia32_vcvtsd2si64((__v2df)(__m128d)(A), (int)(R)); }) +#endif #define _mm_cvt_roundsd_si32(A, R) __extension__ ({ \ (int)__builtin_ia32_vcvtsd2si32((__v2df)(__m128d)(A), (int)(R)); }) @@ -6328,6 +6332,7 @@ _mm_cvtsd_u32 (__m128d __A) _MM_FROUND_CUR_DIRECTION); } +#ifdef __x86_64__ #define _mm_cvt_roundsd_u64(A, R) __extension__ ({ \ (unsigned long long)__builtin_ia32_vcvtsd2usi64((__v2df)(__m128d)(A), \ (int)(R)); }) @@ -6339,6 +6344,7 @@ _mm_cvtsd_u64 (__m128d __A) __A, _MM_FROUND_CUR_DIRECTION); } +#endif #define _mm_cvt_roundss_si32(A, R) __extension__ ({ \ (int)__builtin_ia32_vcvtss2si32((__v4sf)(__m128)(A), (int)(R)); }) @@ -6346,11 +6352,13 @@ _mm_cvtsd_u64 (__m128d __A) #define _mm_cvt_roundss_i32(A, R) __extension__ ({ \ (int)__builtin_ia32_vcvtss2si32((__v4sf)(__m128)(A), (int)(R)); }) +#ifdef __x86_64__ #define _mm_cvt_roundss_si64(A, R) __extension__ ({ \ (long long)__builtin_ia32_vcvtss2si64((__v4sf)(__m128)(A), (int)(R)); }) #define _mm_cvt_roundss_i64(A, R) __extension__ ({ \ (long long)__builtin_ia32_vcvtss2si64((__v4sf)(__m128)(A), (int)(R)); }) +#endif #define _mm_cvt_roundss_u32(A, R) __extension__ ({ \ (unsigned int)__builtin_ia32_vcvtss2usi32((__v4sf)(__m128)(A), (int)(R)); }) @@ -6362,6 +6370,7 @@ _mm_cvtss_u32 (__m128 __A) _MM_FROUND_CUR_DIRECTION); } +#ifdef __x86_64__ #define _mm_cvt_roundss_u64(A, R) __extension__ ({ \ (unsigned long long)__builtin_ia32_vcvtss2usi64((__v4sf)(__m128)(A), \ (int)(R)); }) @@ -6373,6 +6382,7 @@ _mm_cvtss_u64 (__m128 __A) __A, _MM_FROUND_CUR_DIRECTION); } +#endif #define _mm_cvtt_roundsd_i32(A, R) __extension__ ({ \ (int)__builtin_ia32_vcvttsd2si32((__v2df)(__m128d)(A), (int)(R)); }) @@ -6387,6 +6397,7 @@ _mm_cvttsd_i32 (__m128d __A) _MM_FROUND_CUR_DIRECTION); } +#ifdef __x86_64__ #define _mm_cvtt_roundsd_si64(A, R) __extension__ ({ \ (long long)__builtin_ia32_vcvttsd2si64((__v2df)(__m128d)(A), (int)(R)); }) @@ -6399,6 +6410,7 @@ _mm_cvttsd_i64 (__m128d __A) return (long long) __builtin_ia32_vcvttsd2si64 ((__v2df) __A, _MM_FROUND_CUR_DIRECTION); } +#endif #define
r276250 - [Sema, X86] Add explicit check to ensure that builtins that require x86-64 target throw an error if used on 32-bit target.
Author: ctopper Date: Thu Jul 21 02:38:43 2016 New Revision: 276250 URL: http://llvm.org/viewvc/llvm-project?rev=276250=rev Log: [Sema,X86] Add explicit check to ensure that builtins that require x86-64 target throw an error if used on 32-bit target. If these builtins are allowed to go through on a 32-bit target they will fire assertions in the backend. Fixes PR28635. Added: cfe/trunk/test/CodeGen/builtins-x86-disabled.c Modified: cfe/trunk/lib/Sema/SemaChecking.cpp Modified: cfe/trunk/lib/Sema/SemaChecking.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=276250=276249=276250=diff == --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) +++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Jul 21 02:38:43 2016 @@ -1597,6 +1597,56 @@ bool Sema::CheckX86BuiltinFunctionCall(u return SemaBuiltinCpuSupports(*this, TheCall); case X86::BI__builtin_ms_va_start: return SemaBuiltinMSVAStart(TheCall); + case X86::BI__builtin_ia32_addcarryx_u64: + case X86::BI__builtin_ia32_addcarry_u64: + case X86::BI__builtin_ia32_subborrow_u64: + case X86::BI__builtin_ia32_readeflags_u64: + case X86::BI__builtin_ia32_writeeflags_u64: + case X86::BI__builtin_ia32_bextr_u64: + case X86::BI__builtin_ia32_bextri_u64: + case X86::BI__builtin_ia32_bzhi_di: + case X86::BI__builtin_ia32_pdep_di: + case X86::BI__builtin_ia32_pext_di: + case X86::BI__builtin_ia32_crc32di: + case X86::BI__builtin_ia32_fxsave64: + case X86::BI__builtin_ia32_fxrstor64: + case X86::BI__builtin_ia32_xsave64: + case X86::BI__builtin_ia32_xrstor64: + case X86::BI__builtin_ia32_xsaveopt64: + case X86::BI__builtin_ia32_xrstors64: + case X86::BI__builtin_ia32_xsavec64: + case X86::BI__builtin_ia32_xsaves64: + case X86::BI__builtin_ia32_rdfsbase64: + case X86::BI__builtin_ia32_rdgsbase64: + case X86::BI__builtin_ia32_wrfsbase64: + case X86::BI__builtin_ia32_wrgsbase64: + case X86::BI__builtin_ia32_pbroadcastb512_gpr_mask: + case X86::BI__builtin_ia32_pbroadcastb256_gpr_mask: + case X86::BI__builtin_ia32_pbroadcastb128_gpr_mask: + case X86::BI__builtin_ia32_vcvtsd2si64: + case X86::BI__builtin_ia32_vcvtsd2usi64: + case X86::BI__builtin_ia32_vcvtss2si64: + case X86::BI__builtin_ia32_vcvtss2usi64: + case X86::BI__builtin_ia32_vcvttsd2si64: + case X86::BI__builtin_ia32_vcvttsd2usi64: + case X86::BI__builtin_ia32_vcvttss2si64: + case X86::BI__builtin_ia32_vcvttss2usi64: + case X86::BI__builtin_ia32_cvtss2si64: + case X86::BI__builtin_ia32_cvttss2si64: + case X86::BI__builtin_ia32_cvtsd2si64: + case X86::BI__builtin_ia32_cvttsd2si64: + case X86::BI__builtin_ia32_cvtsi2sd64: + case X86::BI__builtin_ia32_cvtsi2ss64: + case X86::BI__builtin_ia32_cvtusi2sd64: + case X86::BI__builtin_ia32_cvtusi2ss64: + case X86::BI__builtin_ia32_rdseed64_step: { +// These builtins only work on x86-64 targets. +const llvm::Triple = Context.getTargetInfo().getTriple(); +if (TT.getArch() != llvm::Triple::x86_64) + return Diag(TheCall->getCallee()->getLocStart(), + diag::err_x86_builtin_32_bit_tgt); +return false; + } case X86::BI__builtin_ia32_extractf64x4_mask: case X86::BI__builtin_ia32_extracti64x4_mask: case X86::BI__builtin_ia32_extractf32x8_mask: Added: cfe/trunk/test/CodeGen/builtins-x86-disabled.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-x86-disabled.c?rev=276250=auto == --- cfe/trunk/test/CodeGen/builtins-x86-disabled.c (added) +++ cfe/trunk/test/CodeGen/builtins-x86-disabled.c Thu Jul 21 02:38:43 2016 @@ -0,0 +1,22 @@ +// REQUIRES: x86-registered-target +// RUN: not %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - 2>&1 | FileCheck %s + +void call_x86_64_builtins(void) +{ + unsigned long long a = __builtin_ia32_crc32di(0, 0); + unsigned long long b; + unsigned int c = __builtin_ia32_rdseed64_step (); + unsigned long long d = __builtin_ia32_bextr_u64 (0, 0); + unsigned long long e = __builtin_ia32_pdep_di(0, 0); + unsigned long long f = __builtin_ia32_pext_di(0, 0); + unsigned long long g = __builtin_ia32_bzhi_di(0, 0); + unsigned long long h; + unsigned long long i = __builtin_ia32_addcarryx_u64(0, 0, 0, ); + unsigned long long j; + unsigned long long k = __builtin_ia32_addcarry_u64(0, 0, 0, ); + unsigned long long l; + unsigned long long m = __builtin_ia32_subborrow_u64(0, 0, 0, ); +} + +// CHECK: error: this builtin is only available on x86-64 targets +// CHECK: __builtin_ia32_crc32di ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D19311: [analyzer] Self Assignment Checker
xazax.hun added inline comments. Comment at: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:1738 @@ +1737,3 @@ + + const auto Msg = "Assuming " + Met->getParamDecl(0)->getName() + + ((Param == This) ? " == " : " != ") + "*this"; getName will return a StringRef here. Contatenating const char * and StringRef will give you a Twine. So Msg will be a twine which refers to temporary objects. This will result in a use after free. You shoud convert the result of the concatenation (the Twine) to a std::string, to copy the data and avoid use after free. Repository: rL LLVM https://reviews.llvm.org/D19311 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r276242 - [CodeGen] Handle recursion in LLVMIRGeneration Timer.
Author: davide Date: Thu Jul 21 01:28:48 2016 New Revision: 276242 URL: http://llvm.org/viewvc/llvm-project?rev=276242=rev Log: [CodeGen] Handle recursion in LLVMIRGeneration Timer. This can happen when emitting a local decl, which triggers loading a decl imported from an AST file, which we then hand to the AST consumer. Timer is not allowed to recurse so an assertion fire. Keep a reference counter to avoid this problem. LGTM'd by Richard Smith on IRC. Differential Revision: https://reviews.llvm.org/D20748 Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp Modified: cfe/trunk/lib/CodeGen/CodeGenAction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenAction.cpp?rev=276242=276241=276242=diff == --- cfe/trunk/lib/CodeGen/CodeGenAction.cpp (original) +++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp Thu Jul 21 01:28:48 2016 @@ -49,6 +49,7 @@ namespace clang { ASTContext *Context; Timer LLVMIRGeneration; +unsigned LLVMIRGenerationRefCount; std::unique_ptr Gen; @@ -73,6 +74,7 @@ namespace clang { TargetOpts(TargetOpts), LangOpts(LangOpts), AsmOutStream(std::move(OS)), Context(nullptr), LLVMIRGeneration("LLVM IR Generation Time"), + LLVMIRGenerationRefCount(0), Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, CodeGenOpts, C, CoverageInfo)) { llvm::TimePassesIsEnabled = TimePasses; @@ -112,13 +114,20 @@ namespace clang { Context->getSourceManager(), "LLVM IR generation of declaration"); - if (llvm::TimePassesIsEnabled) -LLVMIRGeneration.startTimer(); + // Recurse. + if (llvm::TimePassesIsEnabled) { +LLVMIRGenerationRefCount += 1; +if (LLVMIRGenerationRefCount == 1) + LLVMIRGeneration.startTimer(); + } Gen->HandleTopLevelDecl(D); - if (llvm::TimePassesIsEnabled) -LLVMIRGeneration.stopTimer(); + if (llvm::TimePassesIsEnabled) { +LLVMIRGenerationRefCount -= 1; +if (LLVMIRGenerationRefCount == 0) + LLVMIRGeneration.stopTimer(); + } return true; } @@ -139,13 +148,19 @@ namespace clang { void HandleTranslationUnit(ASTContext ) override { { PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); -if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.startTimer(); +if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount += 1; + if (LLVMIRGenerationRefCount == 1) +LLVMIRGeneration.startTimer(); +} Gen->HandleTranslationUnit(C); -if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.stopTimer(); +if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount -= 1; + if (LLVMIRGenerationRefCount == 0) +LLVMIRGeneration.stopTimer(); +} } // Silently ignore if we weren't initialized for some reason. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D20748: Handle recursion in LLVMIRGeneration Timer
This revision was automatically updated to reflect the committed changes. Closed by commit rL276242: [CodeGen] Handle recursion in LLVMIRGeneration Timer. (authored by davide). Changed prior to commit: https://reviews.llvm.org/D20748?vs=58833=64826#toc Repository: rL LLVM https://reviews.llvm.org/D20748 Files: cfe/trunk/lib/CodeGen/CodeGenAction.cpp Index: cfe/trunk/lib/CodeGen/CodeGenAction.cpp === --- cfe/trunk/lib/CodeGen/CodeGenAction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp @@ -49,6 +49,7 @@ ASTContext *Context; Timer LLVMIRGeneration; +unsigned LLVMIRGenerationRefCount; std::unique_ptr Gen; @@ -73,6 +74,7 @@ TargetOpts(TargetOpts), LangOpts(LangOpts), AsmOutStream(std::move(OS)), Context(nullptr), LLVMIRGeneration("LLVM IR Generation Time"), + LLVMIRGenerationRefCount(0), Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, CodeGenOpts, C, CoverageInfo)) { llvm::TimePassesIsEnabled = TimePasses; @@ -112,13 +114,20 @@ Context->getSourceManager(), "LLVM IR generation of declaration"); - if (llvm::TimePassesIsEnabled) -LLVMIRGeneration.startTimer(); + // Recurse. + if (llvm::TimePassesIsEnabled) { +LLVMIRGenerationRefCount += 1; +if (LLVMIRGenerationRefCount == 1) + LLVMIRGeneration.startTimer(); + } Gen->HandleTopLevelDecl(D); - if (llvm::TimePassesIsEnabled) -LLVMIRGeneration.stopTimer(); + if (llvm::TimePassesIsEnabled) { +LLVMIRGenerationRefCount -= 1; +if (LLVMIRGenerationRefCount == 0) + LLVMIRGeneration.stopTimer(); + } return true; } @@ -139,13 +148,19 @@ void HandleTranslationUnit(ASTContext ) override { { PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); -if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.startTimer(); +if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount += 1; + if (LLVMIRGenerationRefCount == 1) +LLVMIRGeneration.startTimer(); +} Gen->HandleTranslationUnit(C); -if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.stopTimer(); +if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount -= 1; + if (LLVMIRGenerationRefCount == 0) +LLVMIRGeneration.stopTimer(); +} } // Silently ignore if we weren't initialized for some reason. Index: cfe/trunk/lib/CodeGen/CodeGenAction.cpp === --- cfe/trunk/lib/CodeGen/CodeGenAction.cpp +++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp @@ -49,6 +49,7 @@ ASTContext *Context; Timer LLVMIRGeneration; +unsigned LLVMIRGenerationRefCount; std::unique_ptr Gen; @@ -73,6 +74,7 @@ TargetOpts(TargetOpts), LangOpts(LangOpts), AsmOutStream(std::move(OS)), Context(nullptr), LLVMIRGeneration("LLVM IR Generation Time"), + LLVMIRGenerationRefCount(0), Gen(CreateLLVMCodeGen(Diags, InFile, HeaderSearchOpts, PPOpts, CodeGenOpts, C, CoverageInfo)) { llvm::TimePassesIsEnabled = TimePasses; @@ -112,13 +114,20 @@ Context->getSourceManager(), "LLVM IR generation of declaration"); - if (llvm::TimePassesIsEnabled) -LLVMIRGeneration.startTimer(); + // Recurse. + if (llvm::TimePassesIsEnabled) { +LLVMIRGenerationRefCount += 1; +if (LLVMIRGenerationRefCount == 1) + LLVMIRGeneration.startTimer(); + } Gen->HandleTopLevelDecl(D); - if (llvm::TimePassesIsEnabled) -LLVMIRGeneration.stopTimer(); + if (llvm::TimePassesIsEnabled) { +LLVMIRGenerationRefCount -= 1; +if (LLVMIRGenerationRefCount == 0) + LLVMIRGeneration.stopTimer(); + } return true; } @@ -139,13 +148,19 @@ void HandleTranslationUnit(ASTContext ) override { { PrettyStackTraceString CrashInfo("Per-file LLVM IR generation"); -if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.startTimer(); +if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount += 1; + if (LLVMIRGenerationRefCount == 1) +LLVMIRGeneration.startTimer(); +} Gen->HandleTranslationUnit(C); -if (llvm::TimePassesIsEnabled) - LLVMIRGeneration.stopTimer(); +if (llvm::TimePassesIsEnabled) { + LLVMIRGenerationRefCount -= 1; + if (LLVMIRGenerationRefCount == 0) +LLVMIRGeneration.stopTimer(); +} } // Silently ignore
Re: [PATCH] D19311: [analyzer] Self Assignment Checker
baloghadamsoftware added a comment. Thx, I checked the output, but I do not understand why a simple string concatenation fails in your test environment. It works on our build server (Linux) with the latest master trunk. Repository: rL LLVM https://reviews.llvm.org/D19311 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] r276241 - Fix some string_view tests that were failing when exceptions were disabled. Also comment out a _LIBCPP_ASSERT that gcc4.9 was complaining about. Will revisit that later.
Author: marshall Date: Thu Jul 21 01:24:04 2016 New Revision: 276241 URL: http://llvm.org/viewvc/llvm-project?rev=276241=rev Log: Fix some string_view tests that were failing when exceptions were disabled. Also comment out a _LIBCPP_ASSERT that gcc4.9 was complaining about. Will revisit that later. Modified: libcxx/trunk/include/string_view libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv.pass.cpp libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv_size_size.pass.cpp libcxx/trunk/test/std/strings/string.view/string.view.ops/substr.pass.cpp Modified: libcxx/trunk/include/string_view URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string_view?rev=276241=276240=276241=diff == --- libcxx/trunk/include/string_view (original) +++ libcxx/trunk/include/string_view Thu Jul 21 01:24:04 2016 @@ -206,9 +206,9 @@ public: basic_string_view(const _CharT* __s, size_type __len) : __data(__s), __size(__len) { -#if _LIBCPP_STD_VER > 11 -_LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); -#endif +// #if _LIBCPP_STD_VER > 11 +// _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); +// #endif } _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY Modified: libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp?rev=276241=276240=276241=diff == --- libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp (original) +++ libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.pointer_size.pass.cpp Thu Jul 21 01:24:04 2016 @@ -22,6 +22,10 @@ int sign ( int x ) { return x > 0 ? 1 : template void test1 ( std::basic_string_view sv1, size_t pos1, size_t n1, const CharT *s, int expected ) { +#ifdef TEST_HAS_NO_EXCEPTIONS +if (pos1 <= sv1.size()) +assert(sign(sv1.compare(pos1, n1, s)) == sign(expected)); +#else try { assert(sign(sv1.compare(pos1, n1, s)) == sign(expected)); assert(pos1 <= sv1.size()); @@ -29,6 +33,7 @@ void test1 ( std::basic_string_view sv1.size()); } +#endif } template Modified: libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv.pass.cpp?rev=276241=276240=276241=diff == --- libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv.pass.cpp (original) +++ libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv.pass.cpp Thu Jul 21 01:24:04 2016 @@ -22,6 +22,10 @@ int sign ( int x ) { return x > 0 ? 1 : template void test1 ( std::basic_string_view sv1, size_t pos1, size_t n1, std::basic_string_view sv2, int expected ) { +#ifdef TEST_HAS_NO_EXCEPTIONS +if (pos1 <= sv1.size()) +assert(sign( sv1.compare(pos1, n1, sv2)) == sign(expected)); +#else try { assert(sign( sv1.compare(pos1, n1, sv2)) == sign(expected)); assert(pos1 <= sv1.size()); @@ -29,6 +33,7 @@ void test1 ( std::basic_string_view sv1.size()); } +#endif } Modified: libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp?rev=276241=276240=276241=diff == --- libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp (original) +++ libcxx/trunk/test/std/strings/string.view/string.view.ops/compare.size_size_sv_pointer_size.pass.cpp Thu Jul 21 01:24:04 2016 @@ -23,6 +23,10 @@ int sign ( int x ) { return x > 0 ? 1 : template void test1 ( std::basic_string_view sv1, size_t pos1, size_t n1, const CharT *s2, size_t n2, int expected ) { +#ifdef TEST_HAS_NO_EXCEPTIONS +if (pos1 <= sv1.size()) +assert(sign(sv1.compare(pos1, n1, s2, n2)) == sign(expected)); +#else try { assert(sign(sv1.compare(pos1, n1, s2, n2)) == sign(expected)); assert(pos1 <= sv1.size()); @@ -30,6 +34,7 @@ void test1 (