[PATCH] D42273: Add hasTrailingReturn AST matcher
lebedev.ri added inline comments. Comment at: include/clang/ASTMatchers/ASTMatchers.h:5904 +return F->hasTrailingReturn(); + return false; +} juliehockett wrote: > lebedev.ri wrote: > > There are no negative tests in the unittest that cover this false path. > Is there a test case you would recommend? I'm not entirely sure what would be > appropriate -- the tests compile in C++, yes? So `void f();` would just be a > normal function declaration (with a prototype, please correct me if I'm > wrong). I'd start by checking what @aaron.ballman has suggested: ``` EXPECT_TRUE(notMatches("void f();")); ``` https://reviews.llvm.org/D42273 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42300: [Analyzer] Add PreStmt and PostStmt callbacks for OffsetOfExpr
MTC updated this revision to Diff 130753. MTC added a comment. - Use C++11 range-based for loop to traverse ExplodedNodeSet. - Define the macro `offsetof` in `system-header-simulator.h`. Repository: rC Clang https://reviews.llvm.org/D42300 Files: lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp lib/StaticAnalyzer/Core/ExprEngine.cpp test/Analysis/Inputs/system-header-simulator.h test/Analysis/offsetofexpr-callback.c Index: test/Analysis/offsetofexpr-callback.c === --- /dev/null +++ test/Analysis/offsetofexpr-callback.c @@ -0,0 +1,13 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=debug.AnalysisOrder -analyzer-config debug.AnalysisOrder:PreStmtOffsetOfExpr=true,debug.AnalysisOrder:PostStmtOffsetOfExpr=true %s 2>&1 | FileCheck %s +#include "Inputs/system-header-simulator.h" + +struct S { +char c; +}; + +void test() { + offsetof(struct S, c); +} + +// CHECK: PreStmt +// CHECK-NEXT: PostStmt Index: test/Analysis/Inputs/system-header-simulator.h === --- test/Analysis/Inputs/system-header-simulator.h +++ test/Analysis/Inputs/system-header-simulator.h @@ -109,4 +109,6 @@ #ifndef NULL #define __DARWIN_NULL 0 #define NULL __DARWIN_NULL -#endif \ No newline at end of file +#endif + +#define offsetof(t, d) __builtin_offsetof(t, d) Index: lib/StaticAnalyzer/Core/ExprEngine.cpp === --- lib/StaticAnalyzer/Core/ExprEngine.cpp +++ lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1488,12 +1488,19 @@ Bldr.addNodes(Dst); break; -case Stmt::OffsetOfExprClass: +case Stmt::OffsetOfExprClass: { Bldr.takeNodes(Pred); - VisitOffsetOfExpr(cast(S), Pred, Dst); + ExplodedNodeSet PreVisit; + getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this); + + ExplodedNodeSet PostVisit; + for (ExplodedNode *Node : PreVisit) +VisitOffsetOfExpr(cast(S), Node, PostVisit); + + getCheckerManager().runCheckersForPostStmt(Dst, PostVisit, S, *this); Bldr.addNodes(Dst); break; - +} case Stmt::UnaryExprOrTypeTraitExprClass: Bldr.takeNodes(Pred); VisitUnaryExprOrTypeTraitExpr(cast(S), Index: lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp === --- lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp +++ lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp @@ -33,6 +33,8 @@ check::PostStmt, check::PreStmt, check::PostStmt, + check::PreStmt, + check::PostStmt, check::PreCall, check::PostCall, check::NewAllocator, @@ -89,6 +91,16 @@ llvm::errs() << "PostStmt\n"; } + void checkPreStmt(const OffsetOfExpr *OOE, CheckerContext &C) const { +if (isCallbackEnabled(C, "PreStmtOffsetOfExpr")) + llvm::errs() << "PreStmt\n"; + } + + void checkPostStmt(const OffsetOfExpr *OOE, CheckerContext &C) const { +if (isCallbackEnabled(C, "PostStmtOffsetOfExpr")) + llvm::errs() << "PostStmt\n"; + } + void checkPreCall(const CallEvent &Call, CheckerContext &C) const { if (isCallbackEnabled(C, "PreCall")) { llvm::errs() << "PreCall"; Index: test/Analysis/offsetofexpr-callback.c === --- /dev/null +++ test/Analysis/offsetofexpr-callback.c @@ -0,0 +1,13 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=debug.AnalysisOrder -analyzer-config debug.AnalysisOrder:PreStmtOffsetOfExpr=true,debug.AnalysisOrder:PostStmtOffsetOfExpr=true %s 2>&1 | FileCheck %s +#include "Inputs/system-header-simulator.h" + +struct S { +char c; +}; + +void test() { + offsetof(struct S, c); +} + +// CHECK: PreStmt +// CHECK-NEXT: PostStmt Index: test/Analysis/Inputs/system-header-simulator.h === --- test/Analysis/Inputs/system-header-simulator.h +++ test/Analysis/Inputs/system-header-simulator.h @@ -109,4 +109,6 @@ #ifndef NULL #define __DARWIN_NULL 0 #define NULL __DARWIN_NULL -#endif \ No newline at end of file +#endif + +#define offsetof(t, d) __builtin_offsetof(t, d) Index: lib/StaticAnalyzer/Core/ExprEngine.cpp === --- lib/StaticAnalyzer/Core/ExprEngine.cpp +++ lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -1488,12 +1488,19 @@ Bldr.addNodes(Dst); break; -case Stmt::OffsetOfExprClass: +case Stmt::OffsetOfExprClass: { Bldr.takeNodes(Pred); - VisitOffsetOfExpr(cast(S), Pred, Dst); + ExplodedNodeSet PreVisit; + getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this); + + ExplodedNodeSet PostVisit; + for (ExplodedNode *Node : PreVisit) +
[PATCH] D42300: [Analyzer] Add PreStmt and PostStmt callbacks for OffsetOfExpr
MTC added a comment. In https://reviews.llvm.org/D42300#982187, @NoQ wrote: > My intuition suggests that this checker shouldn't be path-sensitive; our > path-sensitive analysis does very little to help you with this particular > checker, and you might end up with a much easier and more reliable checker if > you turn it into a simple AST visitor or an AST matcher. Just a heads up. This is a very useful suggestion, many thanks, Noq! Path-sensitive is really a bit too heavy for this checker. Repository: rC Clang https://reviews.llvm.org/D42300 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42272: [X86] Add rdpid command line option and intrinsics.
RKSimon accepted this revision. RKSimon added a comment. This revision is now accepted and ready to land. LGTM https://reviews.llvm.org/D42272 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42213: [ASTMatchers] [NFC] Fix code examples
aaron.ballman added a comment. Great, all that remains is for you to regenerate the documentation file and upload that with the next patch. Repository: rC Clang https://reviews.llvm.org/D42213 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42273: Add hasTrailingReturn AST matcher
aaron.ballman added inline comments. Comment at: include/clang/ASTMatchers/ASTMatchers.h:5904 +return F->hasTrailingReturn(); + return false; +} lebedev.ri wrote: > juliehockett wrote: > > lebedev.ri wrote: > > > There are no negative tests in the unittest that cover this false path. > > Is there a test case you would recommend? I'm not entirely sure what would > > be appropriate -- the tests compile in C++, yes? So `void f();` would just > > be a normal function declaration (with a prototype, please correct me if > > I'm wrong). > I'd start by checking what @aaron.ballman has suggested: > ``` > EXPECT_TRUE(notMatches("void f();")); > ``` > You'll need to use `notMatchesC()` to test that case (so you get a C input file instead of a C++ input file). https://reviews.llvm.org/D42273 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] r323040 - Assume the shared library path variable is LD_LIBRARY_PATH on systems
Author: dim Date: Sat Jan 20 06:34:33 2018 New Revision: 323040 URL: http://llvm.org/viewvc/llvm-project?rev=323040&view=rev Log: Assume the shared library path variable is LD_LIBRARY_PATH on systems except Darwin and Windows. This prevents inserting an environment variable with an empty name (which is illegal and leads to a Python exception) on any of the BSDs. Modified: clang-tools-extra/trunk/test/Unit/lit.cfg Modified: clang-tools-extra/trunk/test/Unit/lit.cfg URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/Unit/lit.cfg?rev=323040&r1=323039&r2=323040&view=diff == --- clang-tools-extra/trunk/test/Unit/lit.cfg (original) +++ clang-tools-extra/trunk/test/Unit/lit.cfg Sat Jan 20 06:34:33 2018 @@ -19,13 +19,12 @@ config.test_exec_root = config.test_sour # ;-separated list of subdirectories). config.test_format = lit.formats.GoogleTest('.', 'Tests') -shlibpath_var = '' -if platform.system() == 'Linux': -shlibpath_var = 'LD_LIBRARY_PATH' -elif platform.system() == 'Darwin': +if platform.system() == 'Darwin': shlibpath_var = 'DYLD_LIBRARY_PATH' elif platform.system() == 'Windows': shlibpath_var = 'PATH' +else: +shlibpath_var = 'LD_LIBRARY_PATH' # Point the dynamic loader at dynamic libraries in 'lib'. shlibpath = os.path.pathsep.join((config.shlibdir, config.llvm_libs_dir, ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42273: Add hasTrailingReturn AST matcher
lebedev.ri added inline comments. Comment at: include/clang/ASTMatchers/ASTMatchers.h:5904 +return F->hasTrailingReturn(); + return false; +} aaron.ballman wrote: > lebedev.ri wrote: > > juliehockett wrote: > > > lebedev.ri wrote: > > > > There are no negative tests in the unittest that cover this false path. > > > Is there a test case you would recommend? I'm not entirely sure what > > > would be appropriate -- the tests compile in C++, yes? So `void f();` > > > would just be a normal function declaration (with a prototype, please > > > correct me if I'm wrong). > > I'd start by checking what @aaron.ballman has suggested: > > ``` > > EXPECT_TRUE(notMatches("void f();")); > > ``` > > > You'll need to use `notMatchesC()` to test that case (so you get a C input > file instead of a C++ input file). Oh, sorry, indeed. I did mean `notMatchesC()`, the trailing `C` was lost during copy-paste. https://reviews.llvm.org/D42273 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D38845: [ASTImporter] Support importing UnresolvedMemberExpr, DependentNameType, DependentScopeDeclRefExpr
xazax.hun added a comment. This should be rebased to latest master. https://reviews.llvm.org/D38845 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D41946: [clangd] Add support for different file URI schemas.
ioeric updated this revision to Diff 130766. ioeric marked 16 inline comments as done. ioeric added a comment. - Addressed review comments. - Check windows vs unit paths in tests. - Properly check absolute paths. Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D41946 Files: clangd/CMakeLists.txt clangd/URI.cpp clangd/URI.h unittests/clangd/CMakeLists.txt unittests/clangd/URITests.cpp Index: unittests/clangd/URITests.cpp === --- /dev/null +++ unittests/clangd/URITests.cpp @@ -0,0 +1,190 @@ +//===-- URITests.cpp -*- C++ -*---===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===--===// + +#include "URI.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace clang { +namespace clangd { +namespace { + +using ::testing::AllOf; + +MATCHER_P(Scheme, S, "") { return arg.scheme() == S; } +MATCHER_P(Authority, A, "") { return arg.authority() == A; } +MATCHER_P(Body, B, "") { return arg.body() == B; } + +TEST(PercentEncodingTest, Encode) { + EXPECT_EQ(percentEncode("a/b/c"), "a/b/c"); + EXPECT_EQ(percentEncode("a!b;c~"), "a%21b%3bc~"); +} + +TEST(PercentEncodingTest, Decode) { + EXPECT_EQ(percentDecode("a/b/c"), "a/b/c"); + EXPECT_EQ(percentDecode("%3a%3"), ":%3"); + EXPECT_EQ(percentDecode("a%21b%3ac~"), "a!b:c~"); + EXPECT_EQ(percentDecode("a%21b%3ac~"), "a!b:c~"); +} + +// Assume all files in the schema have a "test-root/" root directory, and the +// schema path is the relative path to the root directory. +// So the schema of "/some-dir/test-root/x/y/z" is "test:x/y/z". +class TestScheme : public URIScheme { +public: + static const char *Scheme; + + static const char *TestRoot; + + llvm::Expected + getAbsolutePath(llvm::StringRef /*Authority*/, llvm::StringRef Body, + llvm::StringRef HintPath) const override { +auto Pos = HintPath.find(TestRoot); +assert(Pos != llvm::StringRef::npos); +return (HintPath.substr(0, Pos + llvm::StringRef(TestRoot).size()) + Body) +.str(); + } + + llvm::Expected + uriFromAbsolutePath(llvm::StringRef AbsolutePath) const override { +auto Pos = AbsolutePath.find(TestRoot); +assert(Pos != llvm::StringRef::npos); +return (llvm::Twine(Scheme) + ":" + +AbsolutePath.substr(Pos + Pos + llvm::StringRef(TestRoot).size())) +.str(); + } +}; + +const char *TestScheme::Scheme = "test"; +const char *TestScheme::TestRoot = "/test-root/"; + +static URISchemeRegistry::Add X(TestScheme::Scheme, "Test schema"); + +std::string createOrDie(llvm::StringRef AbsolutePath, +llvm::StringRef Scheme = "file") { + auto Uri = FileURI::create(AbsolutePath, Scheme); + if (!Uri) +llvm_unreachable(llvm::toString(Uri.takeError()).c_str()); + return *Uri; +} + +FileURI parseOrDie(llvm::StringRef Uri) { + auto U = FileURI::parse(Uri); + if (!U) +llvm_unreachable(llvm::toString(U.takeError()).c_str()); + return *U; +} + +std::string resolveOrDie(const FileURI &U, llvm::StringRef HintPath = "") { + auto Path = FileURI::resolve(U, HintPath); + if (!Path) +llvm_unreachable(llvm::toString(Path.takeError()).c_str()); + return *Path; +} + +TEST(URITest, Create) { +#ifdef LLVM_ON_WIN32 + EXPECT_THAT(createOrDie("c:\\x\\y\\z"), "file:///c:/x/y/z"); +#else + EXPECT_THAT(createOrDie("/x/y/z"), "file:///x/y/z"); + EXPECT_THAT(createOrDie("/(x)/y/\\ z"), "file:///%28x%29/y/%5c%20z"); +#endif +} + +TEST(URITest, FailedCreate) { + auto Uri = FileURI::create("/x/y/z", "no"); + EXPECT_FALSE(static_cast(Uri)); + llvm::consumeError(Uri.takeError()); + + // Path has to be absolute. + Uri = FileURI::create("x/y/z"); + EXPECT_FALSE(static_cast(Uri)); + llvm::consumeError(Uri.takeError()); +} + +TEST(URITest, Parse) { + EXPECT_THAT(parseOrDie("file://auth/x/y/z"), + AllOf(Scheme("file"), Authority("auth"), Body("/x/y/z"))); + + EXPECT_THAT(parseOrDie("file://au%3dth/%28x%29/y/%5c%20z"), + AllOf(Scheme("file"), Authority("au=th"), Body("/(x)/y/\\ z"))); + + EXPECT_THAT(parseOrDie("file:///%28x%29/y/%5c%20z"), + AllOf(Scheme("file"), Authority(""), Body("/(x)/y/\\ z"))); + EXPECT_THAT(parseOrDie("file:///x/y/z"), + AllOf(Scheme("file"), Authority(""), Body("/x/y/z"))); + EXPECT_THAT(parseOrDie("file:"), + AllOf(Scheme("file"), Authority(""), Body(""))); + EXPECT_THAT(parseOrDie("file:///x/y/z%2"), + AllOf(Scheme("file"), Authority(""), Body("/x/y/z%2"))); + EXPECT_THAT(parseOrDie("http://llvm.org";), + AllOf(Scheme("http"), Authority("llvm.org"), Body(""))); + EXPECT_THAT(parseOrDie("http://llvm.org/";), + AllOf(Scheme("http"), Authority("llvm.org"), B
[PATCH] D41946: [clangd] Add support for different file URI schemas.
ioeric added inline comments. Comment at: clangd/URI.cpp:57 + Body = "/"; +Body += path::convert_to_slash(AbsolutePath, path::Style::posix); +return (llvm::Twine(Scheme) + ":" + percentEncode(Body)).str(); sammccall wrote: > ioeric wrote: > > sammccall wrote: > > > conversely, here you want native (which is the default) > > Don't we still need to convert \ to / on windows? > yes. `convert_to_slash(path, style)` assumes that `path` is in `style`. > > `convert_to_slash("c:\\foo.txt", windows)` --> "c:/foo.txt" > `convert_to_slash("c:\\foo.txt", posix)` --> "c:\\foo.txt" (because that's a > perfectly valid filename on a posix system! well, apart from the colon) > `convert_to_slash("c:\\foo.txt", native)` --> "c:/foo.txt" if the host is > windows, "c:\\foo.txt" if the host is windows (this is what you want) > I see. Thanks for the clarification! Comment at: clangd/URI.cpp:138 + + auto Pos = Uri.find(':'); + if (Pos == llvm::StringRef::npos) sammccall wrote: > consider StringRef::split which avoids some index arithmetic: > > pair SchemeSplit = Uri.split(':'); > if (SchemeSplit.second == "") > return error > U.Scheme = percentDecode(SchemeSplit.first); > // then SchemeSplit.second contains the rest `split` is neat. But here we want to distinguish between `http:` vs `http` while it's not trivial wth `split`. Similar for `/` following the authority if we want to keep body '/', say, in `http://llvm.org/`. Comment at: clangd/URI.cpp:155 + return Decoded.takeError(); +if (Decoded->empty()) + return make_string_error( sammccall wrote: > this is e.g. `file:///foo/bar`, which is definitely valid! > scheme = 'file', authority = '', path = '/foo/bar' > > (we should have a test for this one!) Right! Realized `file:foo/bar` was weird while preparing the previous diff ;) Repository: rCTE Clang Tools Extra https://reviews.llvm.org/D41946 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42335: [ASTImporter] Supporting CXXOperatorCallExpr, SizeOfPackExpr, DependentTemplateSpecializationType, DependentSizedArray importing.
xazax.hun created this revision. xazax.hun added reviewers: a.sidorin, szepet. Herald added subscribers: dkrupp, rnkovacs. Also fix a problem with CXXTemporaryObjectExpr. Repository: rC Clang https://reviews.llvm.org/D42335 Files: lib/AST/ASTImporter.cpp unittests/AST/ASTImporterTest.cpp Index: unittests/AST/ASTImporterTest.cpp === --- unittests/AST/ASTImporterTest.cpp +++ unittests/AST/ASTImporterTest.cpp @@ -480,6 +480,16 @@ vaArgExpr(; } +TEST(ImportExpr, CXXTemporaryObjectExpr) { + MatchVerifier Verifier; + testImport("struct C {};" + "void declToImport() { C c = C(); }", + Lang_CXX, "", Lang_CXX, Verifier, + functionDecl(hasBody(compoundStmt(has( + declStmt(has(varDecl(has(exprWithCleanups(has(cxxConstructExpr( + has(materializeTemporaryExpr(has(implicitCastExpr( + has(cxxTemporaryObjectExpr()); +} TEST(ImportType, ImportAtomicType) { MatchVerifier Verifier; @@ -564,6 +574,50 @@ declRefExpr()); } +const internal::VariadicDynCastAllOfMatcher +dependentTemplateSpecializationType; + +TEST(ImportType, ImportDependentTemplateSpecialization) { + MatchVerifier Verifier; + testImport("template" + "struct A;" + "template" + "struct declToImport {" + " typename A::template B a;" + "};", + Lang_CXX, "", Lang_CXX, Verifier, + classTemplateDecl(has(cxxRecordDecl(has( + fieldDecl(hasType(dependentTemplateSpecializationType(; +} + +const internal::VariadicDynCastAllOfMatcher +sizeOfPackExpr; + +TEST(ImportExpr, ImportSizeOfPackExpr) { + MatchVerifier Verifier; + testImport("template " + "void declToImport() {" + " const int i = sizeof...(Ts);" + "};" + "void g() { declToImport(); }", + Lang_CXX11, "", Lang_CXX11, Verifier, + functionTemplateDecl(has(functionDecl( + hasBody(compoundStmt(has(declStmt(has(varDecl(hasInitializer( + implicitCastExpr(has(sizeOfPackExpr()); + testImport( + "template " + "using X = int[sizeof...(Ts)];" + "template " + "struct Y {" + " X f;" + "};" + "Y declToImport;", + Lang_CXX11, "", Lang_CXX11, Verifier, + varDecl(hasType(classTemplateSpecializationDecl(has(fieldDecl(hasType( + hasUnqualifiedDesugaredType(constantArrayType(hasSize(7)); +} + /// \brief Matches __builtin_types_compatible_p: /// GNU extension to check equivalent types /// Given @@ -691,5 +745,25 @@ binaryOperator(has(cxxUnresolvedConstructExpr()); } +TEST(ImportExpr, CXXOperatorCallExpr) { + MatchVerifier Verifier; + testImport("class declToImport {" + " void f() { *this = declToImport(); }" + "};", + Lang_CXX, "", Lang_CXX, Verifier, + cxxRecordDecl(has(cxxMethodDecl(hasBody(compoundStmt( + has(exprWithCleanups(has(cxxOperatorCallExpr()); +} + +TEST(ImportExpr, DependentSizedArrayType) { + MatchVerifier Verifier; + testImport("template class declToImport {" + " T data[Size];" + "};", + Lang_CXX, "", Lang_CXX, Verifier, + classTemplateDecl(has(cxxRecordDecl( + has(fieldDecl(hasType(dependentSizedArrayType(; +} + } // end namespace ast_matchers } // end namespace clang Index: lib/AST/ASTImporter.cpp === --- lib/AST/ASTImporter.cpp +++ lib/AST/ASTImporter.cpp @@ -52,7 +52,7 @@ QualType VisitConstantArrayType(const ConstantArrayType *T); QualType VisitIncompleteArrayType(const IncompleteArrayType *T); QualType VisitVariableArrayType(const VariableArrayType *T); -// FIXME: DependentSizedArrayType +QualType VisitDependentSizedArrayType(const DependentSizedArrayType *T); // FIXME: DependentSizedExtVectorType QualType VisitVectorType(const VectorType *T); QualType VisitExtVectorType(const ExtVectorType *T); @@ -78,7 +78,8 @@ QualType VisitElaboratedType(const ElaboratedType *T); // FIXME: DependentNameType QualType VisitPackExpansionType(const PackExpansionType *T); -// FIXME: DependentTemplateSpecializationType +QualType VisitDependentTemplateSpecializationType( +const DependentTemplateSpecializationType *T); QualType VisitObjCInterfaceType(const ObjCInterfaceType *T); QualType VisitObjCObjectType(const ObjCObjectType *T); QualType VisitObjCObjectPointerType(const ObjCObjectPointerType *T); @@ -282,10 +283,12 @@ Expr *VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *CE); Expr *VisitMaterializeTemporaryExpr(MaterializeTempo
r323046 - [X86] Put the code that defines __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 for the preprocessor with the other __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* defines. NFC
Author: ctopper Date: Sat Jan 20 10:36:06 2018 New Revision: 323046 URL: http://llvm.org/viewvc/llvm-project?rev=323046&view=rev Log: [X86] Put the code that defines __GCC_HAVE_SYNC_COMPARE_AND_SWAP_16 for the preprocessor with the other __GCC_HAVE_SYNC_COMPARE_AND_SWAP_* defines. NFC Modified: cfe/trunk/lib/Basic/Targets/X86.cpp Modified: cfe/trunk/lib/Basic/Targets/X86.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=323046&r1=323045&r2=323046&view=diff == --- cfe/trunk/lib/Basic/Targets/X86.cpp (original) +++ cfe/trunk/lib/Basic/Targets/X86.cpp Sat Jan 20 10:36:06 2018 @@ -1109,8 +1109,6 @@ void X86TargetInfo::getTargetDefines(con Builder.defineMacro("__XSAVES__"); if (HasPKU) Builder.defineMacro("__PKU__"); - if (HasCX16) -Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16"); if (HasCLFLUSHOPT) Builder.defineMacro("__CLFLUSHOPT__"); if (HasCLWB) @@ -1204,6 +1202,8 @@ void X86TargetInfo::getTargetDefines(con } if (CPU >= CK_i586) Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8"); + if (HasCX16) +Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16"); if (HasFloat128) Builder.defineMacro("__SIZEOF_FLOAT128__", "16"); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r323047 - [X86] Add rdpid command line option and intrinsics.
Author: ctopper Date: Sat Jan 20 10:36:52 2018 New Revision: 323047 URL: http://llvm.org/viewvc/llvm-project?rev=323047&view=rev Log: [X86] Add rdpid command line option and intrinsics. Summary: This patch adds -mrdpid/-mno-rdpid and the rdpid intrinsic. The corresponding LLVM commit has already been made. Reviewers: RKSimon, spatel, zvi, AndreiGrischenko Reviewed By: RKSimon Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D42272 Added: cfe/trunk/test/CodeGen/rdpid-builtins.c Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def cfe/trunk/include/clang/Driver/Options.td cfe/trunk/lib/Basic/Targets/X86.cpp cfe/trunk/lib/Basic/Targets/X86.h cfe/trunk/lib/Headers/immintrin.h cfe/trunk/test/Driver/x86-target-features.c cfe/trunk/test/Preprocessor/predefined-arch-macros.c cfe/trunk/test/Preprocessor/x86_target_features.c Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=323047&r1=323046&r2=323047&view=diff == --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original) +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Sat Jan 20 10:36:52 2018 @@ -894,6 +894,9 @@ BUILTIN(__builtin_ia32_rdpmc, "ULLii", " BUILTIN(__builtin_ia32_rdtsc, "ULLi", "") BUILTIN(__rdtsc, "ULLi", "") BUILTIN(__builtin_ia32_rdtscp, "ULLiUi*", "") + +TARGET_BUILTIN(__builtin_ia32_rdpid, "Ui", "", "rdpid") + // PKU TARGET_BUILTIN(__builtin_ia32_rdpkru, "Ui", "", "pku") TARGET_BUILTIN(__builtin_ia32_wrpkru, "vUi", "", "pku") Modified: cfe/trunk/include/clang/Driver/Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=323047&r1=323046&r2=323047&view=diff == --- cfe/trunk/include/clang/Driver/Options.td (original) +++ cfe/trunk/include/clang/Driver/Options.td Sat Jan 20 10:36:52 2018 @@ -2562,6 +2562,8 @@ def mprefetchwt1 : Flag<["-"], "mprefetc def mno_prefetchwt1 : Flag<["-"], "mno-prefetchwt1">, Group; def mprfchw : Flag<["-"], "mprfchw">, Group; def mno_prfchw : Flag<["-"], "mno-prfchw">, Group; +def mrdpid : Flag<["-"], "mrdpid">, Group; +def mno_rdpid : Flag<["-"], "mno-rdpid">, Group; def mrdrnd : Flag<["-"], "mrdrnd">, Group; def mno_rdrnd : Flag<["-"], "mno-rdrnd">, Group; def mrtm : Flag<["-"], "mrtm">, Group; Modified: cfe/trunk/lib/Basic/Targets/X86.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.cpp?rev=323047&r1=323046&r2=323047&view=diff == --- cfe/trunk/lib/Basic/Targets/X86.cpp (original) +++ cfe/trunk/lib/Basic/Targets/X86.cpp Sat Jan 20 10:36:52 2018 @@ -160,6 +160,7 @@ bool X86TargetInfo::initFeatureMap( setFeatureEnabledImpl(Features, "avx512vnni", true); setFeatureEnabledImpl(Features, "avx512vbmi2", true); setFeatureEnabledImpl(Features, "avx512vpopcntdq", true); +setFeatureEnabledImpl(Features, "rdpid", true); LLVM_FALLTHROUGH; case CK_Cannonlake: setFeatureEnabledImpl(Features, "avx512ifma", true); @@ -784,6 +785,8 @@ bool X86TargetInfo::handleTargetFeatures HasPREFETCHWT1 = true; } else if (Feature == "+clzero") { HasCLZERO = true; +} else if (Feature == "+rdpid") { + HasRDPID = true; } X86SSEEnum Level = llvm::StringSwitch(Feature) @@ -1123,6 +1126,8 @@ void X86TargetInfo::getTargetDefines(con Builder.defineMacro("__PREFETCHWT1__"); if (HasCLZERO) Builder.defineMacro("__CLZERO__"); + if (HasRDPID) +Builder.defineMacro("__RDPID__"); // Each case falls through to the previous one here. switch (SSELevel) { @@ -1253,6 +1258,7 @@ bool X86TargetInfo::isValidFeatureName(S .Case("popcnt", true) .Case("prefetchwt1", true) .Case("prfchw", true) + .Case("rdpid", true) .Case("rdrnd", true) .Case("rdseed", true) .Case("rtm", true) @@ -1324,6 +1330,7 @@ bool X86TargetInfo::hasFeature(StringRef .Case("popcnt", HasPOPCNT) .Case("prefetchwt1", HasPREFETCHWT1) .Case("prfchw", HasPRFCHW) + .Case("rdpid", HasRDPID) .Case("rdrnd", HasRDRND) .Case("rdseed", HasRDSEED) .Case("rtm", HasRTM) Modified: cfe/trunk/lib/Basic/Targets/X86.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/X86.h?rev=323047&r1=323046&r2=323047&view=diff == --- cfe/trunk/lib/Basic/Targets/X86.h (original) +++ cfe/trunk/lib/Basic/Targets/X86.h Sat Jan 20 10:36:52 2018 @@ -96,6 +96,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetI bool HasCLWB = false; bool HasMOVBE = false; bool HasPREFETCHWT1 = false; + bool HasRDPID = false; /// \brief Enumeration of all of the X86 CPUs supported by Clang.
[PATCH] D42272: [X86] Add rdpid command line option and intrinsics.
This revision was automatically updated to reflect the committed changes. Closed by commit rL323047: [X86] Add rdpid command line option and intrinsics. (authored by ctopper, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D42272?vs=130670&id=130770#toc Repository: rL LLVM https://reviews.llvm.org/D42272 Files: cfe/trunk/include/clang/Basic/BuiltinsX86.def cfe/trunk/include/clang/Driver/Options.td cfe/trunk/lib/Basic/Targets/X86.cpp cfe/trunk/lib/Basic/Targets/X86.h cfe/trunk/lib/Headers/immintrin.h cfe/trunk/test/CodeGen/rdpid-builtins.c cfe/trunk/test/Driver/x86-target-features.c cfe/trunk/test/Preprocessor/predefined-arch-macros.c cfe/trunk/test/Preprocessor/x86_target_features.c Index: cfe/trunk/include/clang/Basic/BuiltinsX86.def === --- cfe/trunk/include/clang/Basic/BuiltinsX86.def +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def @@ -894,6 +894,9 @@ BUILTIN(__builtin_ia32_rdtsc, "ULLi", "") BUILTIN(__rdtsc, "ULLi", "") BUILTIN(__builtin_ia32_rdtscp, "ULLiUi*", "") + +TARGET_BUILTIN(__builtin_ia32_rdpid, "Ui", "", "rdpid") + // PKU TARGET_BUILTIN(__builtin_ia32_rdpkru, "Ui", "", "pku") TARGET_BUILTIN(__builtin_ia32_wrpkru, "vUi", "", "pku") Index: cfe/trunk/include/clang/Driver/Options.td === --- cfe/trunk/include/clang/Driver/Options.td +++ cfe/trunk/include/clang/Driver/Options.td @@ -2562,6 +2562,8 @@ def mno_prefetchwt1 : Flag<["-"], "mno-prefetchwt1">, Group; def mprfchw : Flag<["-"], "mprfchw">, Group; def mno_prfchw : Flag<["-"], "mno-prfchw">, Group; +def mrdpid : Flag<["-"], "mrdpid">, Group; +def mno_rdpid : Flag<["-"], "mno-rdpid">, Group; def mrdrnd : Flag<["-"], "mrdrnd">, Group; def mno_rdrnd : Flag<["-"], "mno-rdrnd">, Group; def mrtm : Flag<["-"], "mrtm">, Group; Index: cfe/trunk/test/Driver/x86-target-features.c === --- cfe/trunk/test/Driver/x86-target-features.c +++ cfe/trunk/test/Driver/x86-target-features.c @@ -125,3 +125,7 @@ // VBMI2: "-target-feature" "+avx512vbmi2" // NO-VBMI2: "-target-feature" "-avx512vbmi2" +// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mrdpid %s -### -o %t.o 2>&1 | FileCheck -check-prefix=RDPID %s +// RUN: %clang -target i386-unknown-linux-gnu -march=i386 -mno-rdpid %s -### -o %t.o 2>&1 | FileCheck -check-prefix=NO-RDPID %s +// RDPID: "-target-feature" "+rdpid" +// NO-RDPID: "-target-feature" "-rdpid" Index: cfe/trunk/test/CodeGen/rdpid-builtins.c === --- cfe/trunk/test/CodeGen/rdpid-builtins.c +++ cfe/trunk/test/CodeGen/rdpid-builtins.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -target-feature +rdpid -emit-llvm -o - %s | FileCheck %s + + +#include + +unsigned int test_rdpid_u32(void) { +// CHECK-LABEL: @test_rdpid_u32 +// CHECK: call i32 @llvm.x86.rdpid + return _rdpid_u32(); +} Index: cfe/trunk/test/Preprocessor/predefined-arch-macros.c === --- cfe/trunk/test/Preprocessor/predefined-arch-macros.c +++ cfe/trunk/test/Preprocessor/predefined-arch-macros.c @@ -1086,6 +1086,7 @@ // CHECK_ICL_M32: #define __PKU__ 1 // CHECK_ICL_M32: #define __POPCNT__ 1 // CHECK_ICL_M32: #define __PRFCHW__ 1 +// CHECK_ICL_M32: #define __RDPID__ 1 // CHECK_ICL_M32: #define __RDRND__ 1 // CHECK_ICL_M32: #define __RDSEED__ 1 // CHECK_ICL_M32: #define __RTM__ 1 @@ -1141,6 +1142,7 @@ // CHECK_ICL_M64: #define __PKU__ 1 // CHECK_ICL_M64: #define __POPCNT__ 1 // CHECK_ICL_M64: #define __PRFCHW__ 1 +// CHECK_ICL_M64: #define __RDPID__ 1 // CHECK_ICL_M64: #define __RDRND__ 1 // CHECK_ICL_M64: #define __RDSEED__ 1 // CHECK_ICL_M64: #define __RTM__ 1 Index: cfe/trunk/test/Preprocessor/x86_target_features.c === --- cfe/trunk/test/Preprocessor/x86_target_features.c +++ cfe/trunk/test/Preprocessor/x86_target_features.c @@ -436,3 +436,6 @@ // VPCLMULQDQNOPCLMUL-NOT: #define __PCLMUL__ 1 // VPCLMULQDQNOPCLMUL-NOT: #define __VPCLMULQDQ__ 1 +// RUN: %clang -target i386-unknown-unknown -march=atom -mrdpid -x c -E -dM -o - %s | FileCheck -match-full-lines --check-prefix=RDPID %s + +// RDPID: #define __RDPID__ 1 Index: cfe/trunk/lib/Basic/Targets/X86.h === --- cfe/trunk/lib/Basic/Targets/X86.h +++ cfe/trunk/lib/Basic/Targets/X86.h @@ -96,6 +96,7 @@ bool HasCLWB = false; bool HasMOVBE = false; bool HasPREFETCHWT1 = false; + bool HasRDPID = false; /// \brief Enumeration of all of the X86 CPUs supported by Clang. /// Index: cfe/trunk/lib/Basic/Targets/X86.cpp === --- cfe/trunk/lib/Basic/Targets/X86.cpp +++ cf
[libcxx] r323050 - More P0202 constexpr work. This commit adds fill/fill_n/generate/generate_n/unique/unique_copy. I removed a specialization of fill_n that recognized when we were dealing with raw po
Author: marshall Date: Sat Jan 20 12:14:32 2018 New Revision: 323050 URL: http://llvm.org/viewvc/llvm-project?rev=323050&view=rev Log: More P0202 constexpr work. This commit adds fill/fill_n/generate/generate_n/unique/unique_copy. I removed a specialization of fill_n that recognized when we were dealing with raw pointers and 1 byte trivially-assignable types and did a memset, because the compiler will do that optimization for us. Modified: libcxx/trunk/include/algorithm libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.fill/fill.pass.cpp libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.fill/fill_n.pass.cpp libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.generate/generate.pass.cpp libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.unique/unique.pass.cpp libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy.pass.cpp libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.unique/unique_copy_pred.pass.cpp libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.unique/unique_pred.pass.cpp Modified: libcxx/trunk/include/algorithm URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=323050&r1=323049&r2=323050&view=diff == --- libcxx/trunk/include/algorithm (original) +++ libcxx/trunk/include/algorithm Sat Jan 20 12:14:32 2018 @@ -219,19 +219,19 @@ template -void +constexpr void // constexpr in C++20 fill(ForwardIterator first, ForwardIterator last, const T& value); template -OutputIterator +constexpr OutputIterator // constexpr in C++20 fill_n(OutputIterator first, Size n, const T& value); template -void +constexpr void // constexpr in C++20 generate(ForwardIterator first, ForwardIterator last, Generator gen); template -OutputIterator +constexpr OutputIterator // constexpr in C++20 generate_n(OutputIterator first, Size n, Generator gen); template @@ -2025,7 +2025,7 @@ replace_copy_if(_InputIterator __first, // fill_n template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) { @@ -2034,24 +2034,8 @@ __fill_n(_OutputIterator __first, _Size return __first; } -template -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< -is_integral<_Tp>::value && sizeof(_Tp) == 1 && -!is_same<_Tp, bool>::value && -is_integral<_Up>::value && sizeof(_Up) == 1, -_Tp* ->::type -__fill_n(_Tp* __first, _Size __n,_Up __value_) -{ -if (__n > 0) -_VSTD::memset(__first, (unsigned char)__value_, (size_t)(__n)); -return __first + __n; -} - template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) { @@ -2061,7 +2045,7 @@ fill_n(_OutputIterator __first, _Size __ // fill template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag) { @@ -2070,7 +2054,7 @@ __fill(_ForwardIterator __first, _Forwar } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void __fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag) { @@ -2078,7 +2062,7 @@ __fill(_RandomAccessIterator __first, _R } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) { @@ -2088,7 +2072,7 @@ fill(_ForwardIterator __first, _ForwardI // generate template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 void generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) { @@ -2099,7 +2083,7 @@ generate(_ForwardIterator __first, _Forw // generate_n template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen) { @@ -2194,7 +2178,7 @@ remove_copy_if(_InputIterator __first, _ // unique template -_ForwardIterator +_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) { __first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type> @@ -2213,7 +2197,7 @@ unique(_ForwardIterator __first, _Forwar } template -inline
[PATCH] D41976: Low-hanging fruit optimization in string::__move_assign().
tvanslyke updated this revision to Diff 130775. tvanslyke added a comment. Since `__clear_and_shrink()` is private the test covers copy and move assignment. I also ran the libcxx/strings/basic.string and std/strings tests with a hard-coded `assert(__invariants());` at the end of `__clear_and_shrink()` and saw no failures. I don't have commit access myself so I've added the test to the diff. https://reviews.llvm.org/D41976 Files: include/string test/libcxx/strings/basic.string/string.modifiers/copy_assign_move_assign_db1.pass.cpp Index: test/libcxx/strings/basic.string/string.modifiers/copy_assign_move_assign_db1.pass.cpp === --- test/libcxx/strings/basic.string/string.modifiers/copy_assign_move_assign_db1.pass.cpp +++ test/libcxx/strings/basic.string/string.modifiers/copy_assign_move_assign_db1.pass.cpp @@ -0,0 +1,66 @@ +//===--===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===--===// + +// + +// Call __clear_and_shrink() and ensure string invariants hold + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include + +int main() +{ +std::string l = "Long string so that allocation definitely, for sure, absolutely happens. Probably."; +std::string l2 = l; +std::string s = "short"; +std::string s2 = s; +std::string empty = ""; + +assert(l.__invariants()); +assert(s.__invariants()); +assert(l2.__invariants()); +assert(s2.__invariants()); +assert(empty.__invariants()); + + +s2 = empty; +assert(s2.__invariants()); +assert(s2.size() == 0); +assert(empty.__invariants()); +s2 = empty; +assert(s2.__invariants()); +assert(s2.size() == 0); +assert(empty.__invariants()); + +{ +std::string::size_type cap = l.capacity(); +l = empty; +assert(l.__invariants()); +assert(l.size() == 0); +assert(empty.__invariants()); +cap = l2.capacity(); +l2 = std::move(empty); +assert(l2.capacity() < cap); +assert(l2.__invariants()); +assert(l2.size() == 0); +assert(empty.__invariants()); +} +} + +#else + +int main() +{ +} + +#endif Index: include/string === --- include/string +++ include/string @@ -1407,24 +1407,34 @@ __alloc_traits::propagate_on_container_copy_assignment::value>());} _LIBCPP_INLINE_VISIBILITY +void __clear_and_shrink() +{ +clear(); +if(__is_long()) +{ +__alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1); +__set_long_cap(0); +__set_short_size(0); +} +} + +_LIBCPP_INLINE_VISIBILITY void __copy_assign_alloc(const basic_string& __str, true_type) { if (__alloc() == __str.__alloc()) __alloc() = __str.__alloc(); else { if (!__str.__is_long()) { -clear(); -shrink_to_fit(); +__clear_and_shrink(); __alloc() = __str.__alloc(); } else { allocator_type __a = __str.__alloc(); pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap()); -clear(); -shrink_to_fit(); +__clear_and_shrink(); __alloc() = _VSTD::move(__a); __set_long_pointer(__p); __set_long_cap(__str.__get_long_cap()); @@ -2102,8 +2112,7 @@ _NOEXCEPT_(is_nothrow_move_assignable::value) #endif { -clear(); -shrink_to_fit(); +__clear_and_shrink(); __r_.first() = __str.__r_.first(); __move_assign_alloc(__str); __str.__zero(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r323051 - [cmake] Use CLANG_BINARY_DIR to determine the build directory.
Author: vvassilev Date: Sat Jan 20 13:43:35 2018 New Revision: 323051 URL: http://llvm.org/viewvc/llvm-project?rev=323051&view=rev Log: [cmake] Use CLANG_BINARY_DIR to determine the build directory. The patch puts the ClangConfig.cmake in the expected location when clang is embedded into a framework. Modified: cfe/trunk/cmake/modules/CMakeLists.txt Modified: cfe/trunk/cmake/modules/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/modules/CMakeLists.txt?rev=323051&r1=323050&r2=323051&view=diff == --- cfe/trunk/cmake/modules/CMakeLists.txt (original) +++ cfe/trunk/cmake/modules/CMakeLists.txt Sat Jan 20 13:43:35 2018 @@ -2,7 +2,7 @@ # link against them. LLVM calls its version of this file LLVMExports.cmake, but # the usual CMake convention seems to be ${Project}Targets.cmake. set(CLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/clang) -set(clang_cmake_builddir "${CMAKE_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}") +set(clang_cmake_builddir "${CLANG_BINARY_DIR}/${CLANG_INSTALL_PACKAGE_DIR}") # Keep this in sync with llvm/cmake/CMakeLists.txt! set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
r323052 - [analyzer] Provide a check name when MallocChecker enables CStringChecker
Author: dcoughlin Date: Sat Jan 20 15:11:17 2018 New Revision: 323052 URL: http://llvm.org/viewvc/llvm-project?rev=323052&view=rev Log: [analyzer] Provide a check name when MallocChecker enables CStringChecker Fix an assertion failure caused by a missing CheckName. The malloc checker enables "basic" support in the CStringChecker, which causes some CString bounds checks to be enabled. In this case, make sure that we have a valid CheckName for the BugType. Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp cfe/trunk/test/Analysis/Inputs/system-header-simulator.h cfe/trunk/test/Analysis/malloc.c Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp?rev=323052&r1=323051&r2=323052&view=diff == --- cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (original) +++ cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp Sat Jan 20 15:11:17 2018 @@ -309,9 +309,19 @@ ProgramStateRef CStringChecker::CheckLoc if (!N) return nullptr; +CheckName Name; +// These checks are either enabled by the CString out-of-bounds checker +// explicitly or the "basic" CStringNullArg checker support that Malloc +// checker enables. +assert(Filter.CheckCStringOutOfBounds || Filter.CheckCStringNullArg); +if (Filter.CheckCStringOutOfBounds) + Name = Filter.CheckNameCStringOutOfBounds; +else + Name = Filter.CheckNameCStringNullArg; + if (!BT_Bounds) { BT_Bounds.reset(new BuiltinBug( - Filter.CheckNameCStringOutOfBounds, "Out-of-bound array access", + Name, "Out-of-bound array access", "Byte string function accesses out-of-bound array element")); } BuiltinBug *BT = static_cast(BT_Bounds.get()); Modified: cfe/trunk/test/Analysis/Inputs/system-header-simulator.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/Inputs/system-header-simulator.h?rev=323052&r1=323051&r2=323052&view=diff == --- cfe/trunk/test/Analysis/Inputs/system-header-simulator.h (original) +++ cfe/trunk/test/Analysis/Inputs/system-header-simulator.h Sat Jan 20 15:11:17 2018 @@ -32,6 +32,7 @@ typedef __typeof(sizeof(int)) size_t; size_t strlen(const char *); char *strcpy(char *restrict, const char *restrict); +char *strncpy(char *dst, const char *src, size_t n); void *memcpy(void *dst, const void *src, size_t n); typedef unsigned long __darwin_pthread_key_t; Modified: cfe/trunk/test/Analysis/malloc.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.c?rev=323052&r1=323051&r2=323052&view=diff == --- cfe/trunk/test/Analysis/malloc.c (original) +++ cfe/trunk/test/Analysis/malloc.c Sat Jan 20 15:11:17 2018 @@ -1777,6 +1777,15 @@ void freeFunctionPtr() { free((void *)fnptr); // expected-warning {{Argument to free() is a function pointer}} } +// Enabling the malloc checker enables some of the buffer-checking portions +// of the C-string checker. +void cstringchecker_bounds_nocrash() { + char *p = malloc(2); + strncpy(p, "AAA", sizeof("AAA")); // expected-warning {{Size argument is greater than the length of the destination buffer}} + + free(p); +} + // // False negatives. ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42343: [coroutines] Fix application of NRVO to Coroutine "Gro" or return object.
EricWF created this revision. EricWF added reviewers: rsmith, GorNishanov, nicholas. Fix NRVO for Gro variable. Previously, we only marked the GRO declaration as an NRVO variable when its QualType and the function return's QualType matched exactly (using operator==). However, this was incorrect for two reasons: 1. We were marking non-class types, such as ints, as being NRVO variables. This was incorrect. 2. We failed to handle cases where the canonical types were the same, but the actual `QualType` objects were different. For example, if one was represented by a typedef. (Example: https://godbolt.org/g/3UFgsL) This patch fixes these bugs by marking the Gro variable as supporting NRVO only when `Sema::isCopyElisionCandidate` is true. https://reviews.llvm.org/D42343 Files: lib/Sema/SemaCoroutine.cpp test/CodeGenCoroutines/coro-alloc.cpp test/CodeGenCoroutines/coro-gro-nrvo.cpp Index: test/CodeGenCoroutines/coro-gro-nrvo.cpp === --- /dev/null +++ test/CodeGenCoroutines/coro-gro-nrvo.cpp @@ -0,0 +1,81 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fcoroutines-ts -std=c++14 -emit-llvm %s -o - -disable-llvm-passes | FileCheck %s + +#include "Inputs/coroutine.h" + +using namespace std::experimental; + +namespace std { + +struct nothrow_t {}; +constexpr nothrow_t nothrow = {}; + +} // end namespace std + +// Required when get_return_object_on_allocation_failure() is defined by +// the promise. +using SizeT = decltype(sizeof(int)); +void* operator new(SizeT __sz, const std::nothrow_t&) noexcept; +void operator delete(void* __p, const std::nothrow_t&) noexcept; + + +template +struct promise_type { +RetObject get_return_object(); +suspend_always initial_suspend(); +suspend_never final_suspend(); +void return_void(); +static void unhandled_exception(); +}; + +struct coro { + using promise_type = promise_type; + coro(coro const&); + struct Impl; + Impl *impl; +}; + +// Verify that the NRVO is applied to the Gro object. +// CHECK-LABEL: define void @_Z1fi(%struct.coro* noalias sret %agg.result, i32) +coro f(int) { +// CHECK: coro.init: +// CHECK: store i1 false, i1* %gro.active +// CHECK-NEXT: call void @{{.*get_return_objectEv}}(%struct.coro* sret %agg.result +// CHECK-NEXT: store i1 true, i1* %gro.active + co_return; +} + + +template +struct promise_type_with_on_alloc_failure { +static RetObject get_return_object_on_allocation_failure(); +RetObject get_return_object(); +suspend_always initial_suspend(); +suspend_never final_suspend(); +void return_void(); +static void unhandled_exception(); +}; + +struct coro_two { + using promise_type = promise_type_with_on_alloc_failure; + coro_two(coro_two const&); + struct Impl; + Impl *impl; +}; + +// Verify that the NRVO is applied to the Gro object. +// CHECK-LABEL: define void @_Z1hi(%struct.coro_two* noalias sret %agg.result, i32) + coro_two h(int) { + +// CHECK: coro.ret.on.failure: +// CHECK-NEXT: call void @{{.*get_return_object_on_allocation_failureEv}}(%struct.coro_two* sret %agg.result +// CHECK-NEXT: br label %[[RetLabel:.*]] + +// CHECK: coro.init: +// CHECK: store i1 false, i1* %gro.active +// CHECK-NEXT: call void @{{.*get_return_objectEv}}(%struct.coro_two* sret %agg.result +// CHECK-NEXT: store i1 true, i1* %gro.active + +// CHECK: [[RetLabel]]: +// CHECK-NEXT: ret void + co_return; +} Index: test/CodeGenCoroutines/coro-alloc.cpp === --- test/CodeGenCoroutines/coro-alloc.cpp +++ test/CodeGenCoroutines/coro-alloc.cpp @@ -173,6 +173,7 @@ // CHECK-LABEL: f4( extern "C" int f4(promise_on_alloc_failure_tag) { // CHECK: %[[RetVal:.+]] = alloca i32 + // CHECK: %[[Gro:.+]] = alloca i32 // CHECK: %[[ID:.+]] = call token @llvm.coro.id(i32 16 // CHECK: %[[SIZE:.+]] = call i64 @llvm.coro.size.i64() // CHECK: %[[MEM:.+]] = call i8* @_ZnwmRKSt9nothrow_t(i64 %[[SIZE]], %"struct.std::nothrow_t"* dereferenceable(1) @_ZStL7nothrow) @@ -186,7 +187,12 @@ // CHECK: [[OKBB]]: // CHECK: %[[OkRet:.+]] = call i32 @_ZNSt12experimental16coroutine_traitsIJi28promise_on_alloc_failure_tagEE12promise_type17get_return_objectEv( - // CHECK: store i32 %[[OkRet]], i32* %[[RetVal]] + // CHECK: store i32 %[[OkRet]], i32* %[[Gro]] + + // CHECK: coro.ret: + // CHECK: %[[Tmp1:.*]] = load i32, i32* %[[Gro]] + // CHECK-NEXT: store i32 %[[Tmp1]], i32* %[[RetVal]] + // CHECK-NEXT: br label %[[RetBB]] // CHECK: [[RetBB]]: // CHECK: %[[LoadRet:.+]] = load i32, i32* %[[RetVal]], align 4 Index: lib/Sema/SemaCoroutine.cpp === --- lib/Sema/SemaCoroutine.cpp +++ lib/Sema/SemaCoroutine.cpp @@ -1256,9 +1256,8 @@ if (Res.isInvalid()) return false; - if (GroType == FnRetType) { + if (S.isCopyElisionCandidate(FnRetType, GroDecl, false)) GroDecl->setNRVOVariable(true); - }
[PATCH] D42344: [libc++] Use multi-key tree search for {map, set}::{count, equal_range}
ng created this revision. ng added a reviewer: mclow.lists. Herald added a reviewer: EricWF. As described in http://bugs.llvm.org/show_bug.cgi?id=30959, the current implementation of std::{map, key}::{count, equal_range} in libcxx is non-conforming. Quoting ISO/IEC 14882:2014 section 23.2.4: > The phrase “equivalence of keys” means the equivalence relation imposed by > the comparison and not the > operator== on keys. That is, two keys k1 and k2 are considered to be > equivalent if for the comparison > object comp, comp(k1, k2) == false && comp(k2, k1) == false. In the same section, the requirements table states the following: > a.equal_range(k) equivalent to make_pair(a.lower_bound(k), a.upper_bound(k)) > a.count(k) returns the number of elements with key equivalent to k The behaviour of libstdc++ seems to conform to the standard here. Repository: rCXX libc++ https://reviews.llvm.org/D42344 Files: include/map include/set Index: include/map === --- include/map +++ include/map @@ -1223,12 +1223,12 @@ _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const -{return __tree_.__count_unique(__k);} +{return __tree_.__count_multi(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type -count(const _K2& __k) const {return __tree_.__count_unique(__k);} +count(const _K2& __k) const {return __tree_.__count_multi(__k);} #endif _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) @@ -1267,19 +1267,19 @@ _LIBCPP_INLINE_VISIBILITY pair equal_range(const key_type& __k) -{return __tree_.__equal_range_unique(__k);} +{return __tree_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY pair equal_range(const key_type& __k) const -{return __tree_.__equal_range_unique(__k);} +{return __tree_.__equal_range_multi(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,pair>::type -equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);} +equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,pair>::type -equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);} +equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} #endif private: Index: include/set === --- include/set +++ include/set @@ -663,12 +663,12 @@ _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const -{return __tree_.__count_unique(__k);} +{return __tree_.__count_multi(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type -count(const _K2& __k) const{return __tree_.__count_unique(__k);} +count(const _K2& __k) const{return __tree_.__count_multi(__k);} #endif _LIBCPP_INLINE_VISIBILITY iterator lower_bound(const key_type& __k) @@ -707,19 +707,19 @@ _LIBCPP_INLINE_VISIBILITY pair equal_range(const key_type& __k) -{return __tree_.__equal_range_unique(__k);} +{return __tree_.__equal_range_multi(__k);} _LIBCPP_INLINE_VISIBILITY pair equal_range(const key_type& __k) const -{return __tree_.__equal_range_unique(__k);} +{return __tree_.__equal_range_multi(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,pair>::type -equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);} +equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);} template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,pair>::type -equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);} +equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);} #endif }; Index: include/map === --- include/map +++ include/map @@ -1223,12 +1223,12 @@ _LIBCPP_INLINE_VISIBILITY size_type count(const key_type& __k) const -{return __tree_.__count_unique(__k);} +{return __tree_.__count_multi(__k);} #if _LIBCPP_STD_VER > 11 template _LIBCPP_INLINE_VISIBILITY typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type -count(const _K2& __k) const {return __tree_.__count_unique(__k);} +
[PATCH] D42343: [coroutines] Fix application of NRVO to Coroutine "Gro" or return object.
majnemer added inline comments. Comment at: test/CodeGenCoroutines/coro-gro-nrvo.cpp:17 +using SizeT = decltype(sizeof(int)); +void* operator new(SizeT __sz, const std::nothrow_t&) noexcept; +void operator delete(void* __p, const std::nothrow_t&) noexcept; `SizeT` -> `__SIZE_TYPE__` ? https://reviews.llvm.org/D42343 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42344: [libc++] Use multi-key tree search for {map, set}::{count, equal_range}
EricWF added a comment. Could you provide tests that demonstrate the previously incorrect behavior? Repository: rCXX libc++ https://reviews.llvm.org/D42344 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42344: [libc++] Use multi-key tree search for {map, set}::{count, equal_range}
rsmith added a comment. Shouldn't we be changing only the heterogeneous functions here? Repository: rCXX libc++ https://reviews.llvm.org/D42344 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D42344: [libc++] Use multi-key tree search for {map, set}::{count, equal_range}
EricWF added a comment. @rsmith Yes. I agree this should only be applied in that case Repository: rCXX libc++ https://reviews.llvm.org/D42344 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits