[llvm-branch-commits] [clang] 85ce339 - [cmake] Fix build of attribute plugin example on Windows
Author: Kristina Bessonova Date: 2020-11-11T23:13:58-05:00 New Revision: 85ce339f1bd4af075aeb08f59a5a1da00993ce40 URL: https://github.com/llvm/llvm-project/commit/85ce339f1bd4af075aeb08f59a5a1da00993ce40 DIFF: https://github.com/llvm/llvm-project/commit/85ce339f1bd4af075aeb08f59a5a1da00993ce40.diff LOG: [cmake] Fix build of attribute plugin example on Windows Seems '${cmake_2_8_12_PRIVATE}' was removed a long time ago, so it should be just PRIVATE keyword here. Reviewed By: john.brawn Differential Revision: https://reviews.llvm.org/D86091 (cherry picked from commit 04ea680a8ccc4f9a4d7333cd712333960348c35b) Added: Modified: clang/examples/Attribute/CMakeLists.txt Removed: diff --git a/clang/examples/Attribute/CMakeLists.txt b/clang/examples/Attribute/CMakeLists.txt index ed02f5e5992f..42f04f5039bc 100644 --- a/clang/examples/Attribute/CMakeLists.txt +++ b/clang/examples/Attribute/CMakeLists.txt @@ -1,7 +1,7 @@ add_llvm_library(Attribute MODULE Attribute.cpp PLUGIN_TOOL clang) if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) - target_link_libraries(Attribute ${cmake_2_8_12_PRIVATE} + target_link_libraries(Attribute PRIVATE clangAST clangBasic clangFrontend ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 02004c9 - [ADT] Fix for ImmutableMapRef
Author: Adam Balogh Date: 2020-11-11T23:18:59-05:00 New Revision: 02004c9e7c9668465585a35a33c6580cc4e3056f URL: https://github.com/llvm/llvm-project/commit/02004c9e7c9668465585a35a33c6580cc4e3056f DIFF: https://github.com/llvm/llvm-project/commit/02004c9e7c9668465585a35a33c6580cc4e3056f.diff LOG: [ADT] Fix for ImmutableMapRef The `Root` member of `ImmutableMapRef` was changed recently from a plain pointer to `IntrusiveRefCntPtr`. However, the `Profile` member function was not adjusted. This results in comilation error whenever the `Profile` method is used on an `ImmutableMapRef`. This patch fixes this issue and also adds unit tests for `ImmutableMapRef`. Differential Revision: https://reviews.llvm.org/D89486 (cherry picked from commit 184eb4fa4f1cc871692fa390261df8c25ddcc7ec) Added: Modified: llvm/include/llvm/ADT/ImmutableMap.h llvm/unittests/ADT/ImmutableMapTest.cpp Removed: diff --git a/llvm/include/llvm/ADT/ImmutableMap.h b/llvm/include/llvm/ADT/ImmutableMap.h index 30689d2274a8..81b21a7319a7 100644 --- a/llvm/include/llvm/ADT/ImmutableMap.h +++ b/llvm/include/llvm/ADT/ImmutableMap.h @@ -355,7 +355,7 @@ class ImmutableMapRef { unsigned getHeight() const { return Root ? Root->getHeight() : 0; } static inline void Profile(FoldingSetNodeID &ID, const ImmutableMapRef &M) { -ID.AddPointer(M.Root); +ID.AddPointer(M.Root.get()); } inline void Profile(FoldingSetNodeID &ID) const { return Profile(ID, *this); } diff --git a/llvm/unittests/ADT/ImmutableMapTest.cpp b/llvm/unittests/ADT/ImmutableMapTest.cpp index fa61816d213c..1217718826f7 100644 --- a/llvm/unittests/ADT/ImmutableMapTest.cpp +++ b/llvm/unittests/ADT/ImmutableMapTest.cpp @@ -46,4 +46,45 @@ TEST(ImmutableMapTest, MultiElemIntMapTest) { EXPECT_EQ(3U, S2.getHeight()); } +TEST(ImmutableMapTest, EmptyIntMapRefTest) { + using int_int_map = ImmutableMapRef; + ImmutableMapRef::FactoryTy f; + + EXPECT_TRUE(int_int_map::getEmptyMap(&f) == int_int_map::getEmptyMap(&f)); + EXPECT_FALSE(int_int_map::getEmptyMap(&f) != int_int_map::getEmptyMap(&f)); + EXPECT_TRUE(int_int_map::getEmptyMap(&f).isEmpty()); + + int_int_map S = int_int_map::getEmptyMap(&f); + EXPECT_EQ(0u, S.getHeight()); + EXPECT_TRUE(S.begin() == S.end()); + EXPECT_FALSE(S.begin() != S.end()); +} + +TEST(ImmutableMapTest, MultiElemIntMapRefTest) { + ImmutableMapRef::FactoryTy f; + + ImmutableMapRef S = ImmutableMapRef::getEmptyMap(&f); + + ImmutableMapRef S2 = S.add(3, 10).add(4, 11).add(5, 12); + + EXPECT_TRUE(S.isEmpty()); + EXPECT_FALSE(S2.isEmpty()); + + EXPECT_EQ(nullptr, S.lookup(3)); + EXPECT_EQ(nullptr, S.lookup(9)); + + EXPECT_EQ(10, *S2.lookup(3)); + EXPECT_EQ(11, *S2.lookup(4)); + EXPECT_EQ(12, *S2.lookup(5)); + + EXPECT_EQ(5, S2.getMaxElement()->first); + EXPECT_EQ(3U, S2.getHeight()); +} + + TEST(ImmutableMapTest, MapOfMapRefsTest) { + ImmutableMap>::Factory f; + + EXPECT_TRUE(f.getEmptyMap() == f.getEmptyMap()); + } + } ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] 0874e7e - Allow init_priority values <= 100 and > 65535 within system headers.
Author: Aaron Ballman Date: 2020-11-11T23:29:37-05:00 New Revision: 0874e7ef66cc82a795fb19e8662e09a10eabaa01 URL: https://github.com/llvm/llvm-project/commit/0874e7ef66cc82a795fb19e8662e09a10eabaa01 DIFF: https://github.com/llvm/llvm-project/commit/0874e7ef66cc82a795fb19e8662e09a10eabaa01.diff LOG: Allow init_priority values <= 100 and > 65535 within system headers. This also adds some bare-bones documentation for the attribute rather than leaving it undocumented. (cherry picked from commit af1d3e655991e5f0c86df372b8583a60d20268e0) Added: Modified: clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/lib/Sema/SemaDeclAttr.cpp clang/test/SemaCXX/init-priority-attr.cpp Removed: diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index bc4a380545afe..19eccf7ceadf8 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -2115,7 +2115,7 @@ def InitPriority : InheritableAttr { let Spellings = [GCC<"init_priority", /*AllowInC*/0>]; let Args = [UnsignedArgument<"Priority">]; let Subjects = SubjectList<[Var], ErrorDiag>; - let Documentation = [Undocumented]; + let Documentation = [InitPriorityDocs]; } def Section : InheritableAttr { diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 3cba3a3d96f96..833127ed44eb3 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -57,6 +57,32 @@ global variable or function should be in after translation. let Heading = "section, __declspec(allocate)"; } +def InitPriorityDocs : Documentation { + let Category = DocCatVariable; + let Content = [{ +In C++, the order in which global variables are initialized across translation +units is unspecified, unlike the ordering within a single translation unit. The +``init_priority`` attribute allows you to specify a relative ordering for the +initialization of objects declared at namespace scope in C++. The priority is +given as an integer constant expression between 101 and 65535 (inclusive). +Priorities outside of that range are reserved for use by the implementation. A +lower value indicates a higher priority of initialization. Note that only the +relative ordering of values is important. For example: + +.. code-block:: c++ + + struct SomeType { SomeType(); }; + __attribute__((init_priority(200))) SomeType Obj1; + __attribute__((init_priority(101))) SomeType Obj2; + +``Obj1`` will be initialized *before* ``Obj2`` despite the usual order of +initialization being the opposite. + +This attribute is only supported for C++ and Objective-C++ and is ignored in +other language modes. + }]; +} + def InitSegDocs : Documentation { let Category = DocCatVariable; let Content = [{ diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 1a0594512a606..a9a2a19b47978 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3301,7 +3301,11 @@ static void handleInitPriorityAttr(Sema &S, Decl *D, const ParsedAttr &AL) { return; } - if (prioritynum < 101 || prioritynum > 65535) { + // Only perform the priority check if the attribute is outside of a system + // header. Values <= 100 are reserved for the implementation, and libc++ + // benefits from being able to specify values in that range. + if ((prioritynum < 101 || prioritynum > 65535) && + !S.getSourceManager().isInSystemHeader(AL.getLoc())) { S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_range) << E->getSourceRange() << AL << 101 << 65535; AL.setInvalid(); diff --git a/clang/test/SemaCXX/init-priority-attr.cpp b/clang/test/SemaCXX/init-priority-attr.cpp index 8f31e2fd62d00..5b5e3b9eb940e 100644 --- a/clang/test/SemaCXX/init-priority-attr.cpp +++ b/clang/test/SemaCXX/init-priority-attr.cpp @@ -1,4 +1,9 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s +// RUN: %clang_cc1 -fsyntax-only -DSYSTEM -verify %s + +#if defined(SYSTEM) +#5 "init-priority-attr.cpp" 3 // system header +#endif class Two { private: @@ -21,7 +26,15 @@ Two foo __attribute__((init_priority(101))) ( 5, 6 ); Two goo __attribute__((init_priority(2,3))) ( 5, 6 ); // expected-error {{'init_priority' attribute takes one argument}} -Two coo[2] __attribute__((init_priority(3))); // expected-error {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} +Two coo[2] __attribute__((init_priority(100))); +#if !defined(SYSTEM) +// expected-error@-2 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} +#endif + +Two boo[2] __attribute__((init_priority(65536))); +#if !defined(SYSTEM) +// expected-error@-2 {{'init_priority' attribute requires integer constant between 101 and 65535 inclusive}} +#endif Two koo[4] __attribute__((