[PATCH] D87458: [Clang] Clarify __builtin_memcpy_inline documentation

2020-09-11 Thread Clement Courbet via Phabricator via cfe-commits
courbet added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2439
+guarantees not to call any external functions. See LLVM IR `llvm.memcpy.inline
+`_ Intrinsic 
+for more information.

why capitalize ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87458/new/

https://reviews.llvm.org/D87458

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86089: [flang][driver]Add experimental flang driver and frontend with help screen

2020-09-11 Thread Richard Barton via Phabricator via cfe-commits
richard.barton.arm accepted this revision.
richard.barton.arm added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86089/new/

https://reviews.llvm.org/D86089

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87458: [Clang] Clarify __builtin_memcpy_inline documentation

2020-09-11 Thread Guillaume Chatelet via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe38be7091ee3: [Clang] Clarify __builtin_memcpy_inline 
documentation (authored by gchatelet).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87458/new/

https://reviews.llvm.org/D87458

Files:
  clang/docs/LanguageExtensions.rst


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -2408,20 +2408,6 @@
 Memory builtins
 ---
 
- * ``__builtin_memcpy_inline``
-
-.. code-block:: c
-
-  void __builtin_memcpy_inline(void *dst, const void *src, size_t size);
-
-``__builtin_memcpy_inline(dst, src, size)`` is identical to
-``__builtin_memcpy(dst, src, size)`` except that the generated code is
-guaranteed not to call any external functions. See LLVM IR `llvm.memcpy.inline
-`_ Intrinsic 
-for more information.
-
-Note that the `size` argument must be a compile time constant.
-
 Clang provides constant expression evaluation support for builtin forms of the
 following functions from the C standard library headers
  and :
@@ -2439,7 +2425,27 @@
 given size is an exact multiple of the element size that is no greater than
 the number of elements accessible through the source and destination operands.
 
-Constant evaluation support is not yet provided for 
``__builtin_memcpy_inline``.
+Guaranteed inlined copy
+^^^
+
+.. code-block:: c
+
+  void __builtin_memcpy_inline(void *dst, const void *src, size_t size);
+
+
+``__builtin_memcpy_inline`` has been designed as a building block for efficient
+``memcpy`` implementations. It is identical to ``__builtin_memcpy`` but also
+guarantees not to call any external functions. See LLVM IR `llvm.memcpy.inline
+`_ Intrinsic 
+for more information.
+
+This is useful to implement a custom version of ``memcpy``, implemement a
+``libc`` memcpy or work around the absence of a ``libc``.
+
+Note that the `size` argument must be a compile time constant.
+
+Note that this intrinsic cannot yet be called in a ``constexpr`` context.
+
 
 Atomic Min/Max builtins with memory ordering
 


Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -2408,20 +2408,6 @@
 Memory builtins
 ---
 
- * ``__builtin_memcpy_inline``
-
-.. code-block:: c
-
-  void __builtin_memcpy_inline(void *dst, const void *src, size_t size);
-
-``__builtin_memcpy_inline(dst, src, size)`` is identical to
-``__builtin_memcpy(dst, src, size)`` except that the generated code is
-guaranteed not to call any external functions. See LLVM IR `llvm.memcpy.inline
-`_ Intrinsic 
-for more information.
-
-Note that the `size` argument must be a compile time constant.
-
 Clang provides constant expression evaluation support for builtin forms of the
 following functions from the C standard library headers
  and :
@@ -2439,7 +2425,27 @@
 given size is an exact multiple of the element size that is no greater than
 the number of elements accessible through the source and destination operands.
 
-Constant evaluation support is not yet provided for ``__builtin_memcpy_inline``.
+Guaranteed inlined copy
+^^^
+
+.. code-block:: c
+
+  void __builtin_memcpy_inline(void *dst, const void *src, size_t size);
+
+
+``__builtin_memcpy_inline`` has been designed as a building block for efficient
+``memcpy`` implementations. It is identical to ``__builtin_memcpy`` but also
+guarantees not to call any external functions. See LLVM IR `llvm.memcpy.inline
+`_ Intrinsic 
+for more information.
+
+This is useful to implement a custom version of ``memcpy``, implemement a
+``libc`` memcpy or work around the absence of a ``libc``.
+
+Note that the `size` argument must be a compile time constant.
+
+Note that this intrinsic cannot yet be called in a ``constexpr`` context.
+
 
 Atomic Min/Max builtins with memory ordering
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e38be70 - [Clang] Clarify __builtin_memcpy_inline documentation

2020-09-11 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-09-11T07:20:39Z
New Revision: e38be7091ee3d00430652aaa7b66ba3fc8394916

URL: 
https://github.com/llvm/llvm-project/commit/e38be7091ee3d00430652aaa7b66ba3fc8394916
DIFF: 
https://github.com/llvm/llvm-project/commit/e38be7091ee3d00430652aaa7b66ba3fc8394916.diff

LOG: [Clang] Clarify __builtin_memcpy_inline documentation

This patch updates the documentation about `__builtin_memcpy_inline` and 
reorders the sections so it is more consitent and understandable.

Differential Revision: https://reviews.llvm.org/D87458

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 60b3f21b3e50..073d9c86e22f 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2408,20 +2408,6 @@ with ``__has_feature(cxx_constexpr_string_builtins)``.
 Memory builtins
 ---
 
- * ``__builtin_memcpy_inline``
-
-.. code-block:: c
-
-  void __builtin_memcpy_inline(void *dst, const void *src, size_t size);
-
-``__builtin_memcpy_inline(dst, src, size)`` is identical to
-``__builtin_memcpy(dst, src, size)`` except that the generated code is
-guaranteed not to call any external functions. See LLVM IR `llvm.memcpy.inline
-`_ Intrinsic 
-for more information.
-
-Note that the `size` argument must be a compile time constant.
-
 Clang provides constant expression evaluation support for builtin forms of the
 following functions from the C standard library headers
  and :
@@ -2439,7 +2425,27 @@ are pointers to arrays with the same trivially copyable 
element type, and the
 given size is an exact multiple of the element size that is no greater than
 the number of elements accessible through the source and destination operands.
 
-Constant evaluation support is not yet provided for 
``__builtin_memcpy_inline``.
+Guaranteed inlined copy
+^^^
+
+.. code-block:: c
+
+  void __builtin_memcpy_inline(void *dst, const void *src, size_t size);
+
+
+``__builtin_memcpy_inline`` has been designed as a building block for efficient
+``memcpy`` implementations. It is identical to ``__builtin_memcpy`` but also
+guarantees not to call any external functions. See LLVM IR `llvm.memcpy.inline
+`_ Intrinsic 
+for more information.
+
+This is useful to implement a custom version of ``memcpy``, implemement a
+``libc`` memcpy or work around the absence of a ``libc``.
+
+Note that the `size` argument must be a compile time constant.
+
+Note that this intrinsic cannot yet be called in a ``constexpr`` context.
+
 
 Atomic Min/Max builtins with memory ordering
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87495

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -18,27 +18,75 @@
 
 namespace {
 
-INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, SyntaxTreeTest,
+std::string trim(std::string s) { return StringRef(s).trim().str(); }
+
+INSTANTIATE_TEST_CASE_P(SynthesisTest, SyntaxTreeTest,
 ::testing::ValuesIn(allTestClangConfigs()), );
 
 TEST_P(SyntaxTreeTest, Leaf_Punctuation) {
   buildTree("", GetParam());
 
-  auto *C = syntax::createPunctuation(*Arena, tok::comma);
+  auto *C = createPunctuation(*Arena, tok::comma);
+  ASSERT_NE(C, nullptr);
+
+  auto Dump = trim(C->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+',' Detached synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
+}
+
+TEST_P(SyntaxTreeTest, Leaf_Keyword) {
+  buildTree("", GetParam());
+
+  auto *C = createKeyword(*Arena, tok::kw_if);
+  ASSERT_NE(C, nullptr);
+  auto Dump = trim(C->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+'if' Detached synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
+}
+
+TEST_P(SyntaxTreeTest, Leaf_Identifier) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, "a", tok::identifier);
   ASSERT_NE(C, nullptr);
-  EXPECT_EQ(C->token()->kind(), tok::comma);
-  EXPECT_TRUE(C->canModify());
-  EXPECT_FALSE(C->isOriginal());
-  EXPECT_TRUE(C->isDetached());
+  auto Dump = trim(C->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+'a' Detached synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
 }
 
-TEST_P(SyntaxTreeTest, Statement_Empty) {
+TEST_P(SyntaxTreeTest, Leaf_Number) {
   buildTree("", GetParam());
 
-  auto *S = syntax::createEmptyStatement(*Arena);
+  auto *C = createLeaf(*Arena, "1", tok::numeric_constant);
+  ASSERT_NE(C, nullptr);
+  auto Dump = trim(C->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+'1' Detached synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
+}
+
+TEST_P(SyntaxTreeTest, Statement_EmptyStatement) {
+  buildTree("", GetParam());
+
+  auto *S = createEmptyStatement(*Arena);
   ASSERT_NE(S, nullptr);
-  EXPECT_TRUE(S->canModify());
-  EXPECT_FALSE(S->isOriginal());
-  EXPECT_TRUE(S->isDetached());
+  auto Dump = trim(S->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+EmptyStatement Detached synthesized
+`-';' synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
 }
 } // namespace
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -5,7 +5,9 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===--===//
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "llvm/ADT/StringExtras.h"
 
 using namespace clang;
 
@@ -21,24 +23,38 @@
   }
 };
 
-clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
-   clang::tok::TokenKind K) {
-  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
-clang::tok::getPunctuatorSpelling(K)))
-.second;
+namespace {
+syntax::Leaf *createLeafLowLevel(syntax::Arena &A, const char *spelling) {
+  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(spelling)).second;
   assert(Tokens.size() == 1);
-  assert(Tokens.front().kind() == K);
-  auto *L = new (A.allocator()) clang::syntax::Leaf(Tokens.begin());
-  FactoryImpl::setCanModify(L);
+  auto *L = new (A.allocator()) syntax::Leaf(Tokens.begin());
+  clang::syntax::FactoryImpl::setCanModify(L);
   L->assertInvariants();
   return L;
 }
+} // namespace
 
-clang::syntax::EmptyStatement *
-syntax::createEmptyStatement(clang::syntax::Arena &A) {
-  auto *S = new (A.allocator()) clang::syntax::EmptyStatement;
+syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, const char *spelling,
+tok::TokenKind K) {
+  auto *Leaf = createLeafLowLevel(A, spelling);
+  assert(Leaf->token()->kind() == K &&
+ "spelling is not lexed into the expected kind of token");
+  return Leaf;
+}
+
+syntax::Leaf *clang::syntax::createPunctuation(syntax::Arena &A,
+   tok::TokenKind K) {
+  return createLeaf(A, tok::getPunctuatorSpelling(K), K);
+}
+
+syntax::Leaf *clang::syntax::createKeyword(syntax::A

[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 291152.
eduucaldas added a comment.

Remove unused include


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87495/new/

https://reviews.llvm.org/D87495

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -18,27 +18,75 @@
 
 namespace {
 
-INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, SyntaxTreeTest,
+std::string trim(std::string s) { return StringRef(s).trim().str(); }
+
+INSTANTIATE_TEST_CASE_P(SynthesisTest, SyntaxTreeTest,
 ::testing::ValuesIn(allTestClangConfigs()), );
 
 TEST_P(SyntaxTreeTest, Leaf_Punctuation) {
   buildTree("", GetParam());
 
-  auto *C = syntax::createPunctuation(*Arena, tok::comma);
+  auto *C = createPunctuation(*Arena, tok::comma);
+  ASSERT_NE(C, nullptr);
+
+  auto Dump = trim(C->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+',' Detached synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
+}
+
+TEST_P(SyntaxTreeTest, Leaf_Keyword) {
+  buildTree("", GetParam());
+
+  auto *C = createKeyword(*Arena, tok::kw_if);
+  ASSERT_NE(C, nullptr);
+  auto Dump = trim(C->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+'if' Detached synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
+}
+
+TEST_P(SyntaxTreeTest, Leaf_Identifier) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, "a", tok::identifier);
   ASSERT_NE(C, nullptr);
-  EXPECT_EQ(C->token()->kind(), tok::comma);
-  EXPECT_TRUE(C->canModify());
-  EXPECT_FALSE(C->isOriginal());
-  EXPECT_TRUE(C->isDetached());
+  auto Dump = trim(C->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+'a' Detached synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
 }
 
-TEST_P(SyntaxTreeTest, Statement_Empty) {
+TEST_P(SyntaxTreeTest, Leaf_Number) {
   buildTree("", GetParam());
 
-  auto *S = syntax::createEmptyStatement(*Arena);
+  auto *C = createLeaf(*Arena, "1", tok::numeric_constant);
+  ASSERT_NE(C, nullptr);
+  auto Dump = trim(C->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+'1' Detached synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
+}
+
+TEST_P(SyntaxTreeTest, Statement_EmptyStatement) {
+  buildTree("", GetParam());
+
+  auto *S = createEmptyStatement(*Arena);
   ASSERT_NE(S, nullptr);
-  EXPECT_TRUE(S->canModify());
-  EXPECT_FALSE(S->isOriginal());
-  EXPECT_TRUE(S->isDetached());
+  auto Dump = trim(S->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+EmptyStatement Detached synthesized
+`-';' synthesized
+  )txt");
+
+  EXPECT_EQ(Expected, Dump);
 }
 } // namespace
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -5,6 +5,7 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===--===//
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
 
 using namespace clang;
@@ -21,24 +22,38 @@
   }
 };
 
-clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
-   clang::tok::TokenKind K) {
-  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
-clang::tok::getPunctuatorSpelling(K)))
-.second;
+namespace {
+syntax::Leaf *createLeafLowLevel(syntax::Arena &A, const char *spelling) {
+  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(spelling)).second;
   assert(Tokens.size() == 1);
-  assert(Tokens.front().kind() == K);
-  auto *L = new (A.allocator()) clang::syntax::Leaf(Tokens.begin());
-  FactoryImpl::setCanModify(L);
+  auto *L = new (A.allocator()) syntax::Leaf(Tokens.begin());
+  clang::syntax::FactoryImpl::setCanModify(L);
   L->assertInvariants();
   return L;
 }
+} // namespace
 
-clang::syntax::EmptyStatement *
-syntax::createEmptyStatement(clang::syntax::Arena &A) {
-  auto *S = new (A.allocator()) clang::syntax::EmptyStatement;
+syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, const char *spelling,
+tok::TokenKind K) {
+  auto *Leaf = createLeafLowLevel(A, spelling);
+  assert(Leaf->token()->kind() == K &&
+ "spelling is not lexed into the expected kind of token");
+  return Leaf;
+}
+
+syntax::Leaf *clang::syntax::createPunctuation(syntax::Arena &A,
+   tok::TokenKind K) {
+  return createLeaf(A, tok::getPunctuatorSpelling(K), K);
+}
+
+syntax::Leaf *clang::syntax::createKeyword(syntax::Arena &A, tok::TokenKin

[clang] 76e85ae - [clang][Sparc] Default to -mcpu=v9 for Sparc V8 on Solaris

2020-09-11 Thread Rainer Orth via cfe-commits

Author: Rainer Orth
Date: 2020-09-11T09:53:19+02:00
New Revision: 76e85ae268f8e64540703b0d1710d27ef0d36040

URL: 
https://github.com/llvm/llvm-project/commit/76e85ae268f8e64540703b0d1710d27ef0d36040
DIFF: 
https://github.com/llvm/llvm-project/commit/76e85ae268f8e64540703b0d1710d27ef0d36040.diff

LOG: [clang][Sparc] Default to -mcpu=v9 for Sparc V8 on Solaris

As reported in Bug 42535, `clang` doesn't inline atomic ops on 32-bit
Sparc, unlike `gcc` on Solaris.  In a 1-stage build with `gcc`, only two
testcases are affected (currently `XFAIL`ed), while in a 2-stage build more
than 100 tests `FAIL` due to this issue.

The reason for this `gcc`/`clang` difference is that `gcc` on 32-bit
Solaris/SPARC defaults to `-mpcu=v9` where atomic ops are supported, unlike
with `clang`'s default of `-mcpu=v8`.  This patch changes `clang` to use
`-mcpu=v9` on 32-bit Solaris/SPARC, too.

Doing so uncovered two bugs:

`clang -m32 -mcpu=v9` chokes with any Solaris system headers included:

  /usr/include/sys/isa_defs.h:461:2: error: "Both _ILP32 and _LP64 are defined"
  #error "Both _ILP32 and _LP64 are defined"

While `clang` currently defines `__sparcv9` in a 32-bit `-mcpu=v9`
compilation, neither `gcc` nor Studio `cc` do.  In fact, the Studio 12.6
`cc(1)` man page clearly states:

These predefinitions are valid in all modes:
  [...]
   __sparcv8 (SPARC)
   __sparcv9 (SPARC -m64)

At the same time, the patch defines `__GCC_HAVE_SYNC_COMPARE_AND_SWAP_[1248]`
for a 32-bit Sparc compilation with any V9 cpu.  I've also changed
`MaxAtomicInlineWidth` for V9, matching what `gcc` does and the Oracle
Developer Studio 12.6: C User's Guide documents (Ch. 3, Support for Atomic
Types, 3.1 Size and Alignment of Atomic C Types).

The two testcases that had been `XFAIL`ed for Bug 42535 are un-`XFAIL`ed
again.

Tested on `sparcv9-sun-solaris2.11` and `amd64-pc-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D86621

Added: 


Modified: 
clang/lib/Basic/Targets/Sparc.cpp
clang/lib/Basic/Targets/Sparc.h
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Preprocessor/predefined-arch-macros.c
compiler-rt/test/profile/Posix/instrprof-gcov-parallel.test
compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp

Removed: 




diff  --git a/clang/lib/Basic/Targets/Sparc.cpp 
b/clang/lib/Basic/Targets/Sparc.cpp
index 48f36c5ba1c6..5eeb77406c34 100644
--- a/clang/lib/Basic/Targets/Sparc.cpp
+++ b/clang/lib/Basic/Targets/Sparc.cpp
@@ -147,19 +147,20 @@ void SparcTargetInfo::getTargetDefines(const LangOptions 
&Opts,
 void SparcV8TargetInfo::getTargetDefines(const LangOptions &Opts,
  MacroBuilder &Builder) const {
   SparcTargetInfo::getTargetDefines(Opts, Builder);
-  switch (getCPUGeneration(CPU)) {
-  case CG_V8:
+  if (getTriple().getOS() == llvm::Triple::Solaris)
 Builder.defineMacro("__sparcv8");
-if (getTriple().getOS() != llvm::Triple::Solaris)
+  else {
+switch (getCPUGeneration(CPU)) {
+case CG_V8:
+  Builder.defineMacro("__sparcv8");
   Builder.defineMacro("__sparcv8__");
-break;
-  case CG_V9:
-Builder.defineMacro("__sparcv9");
-if (getTriple().getOS() != llvm::Triple::Solaris) {
+  break;
+case CG_V9:
+  Builder.defineMacro("__sparcv9");
   Builder.defineMacro("__sparcv9__");
   Builder.defineMacro("__sparc_v9__");
+  break;
 }
-break;
   }
   if (getTriple().getVendor() == llvm::Triple::Myriad) {
 std::string MyriadArchValue, Myriad2Value;
@@ -227,6 +228,12 @@ void SparcV8TargetInfo::getTargetDefines(const LangOptions 
&Opts,
 Builder.defineMacro("__myriad2__", Myriad2Value);
 Builder.defineMacro("__myriad2", Myriad2Value);
   }
+  if (getCPUGeneration(CPU) == CG_V9) {
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
+Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
+  }
 }
 
 void SparcV9TargetInfo::getTargetDefines(const LangOptions &Opts,

diff  --git a/clang/lib/Basic/Targets/Sparc.h b/clang/lib/Basic/Targets/Sparc.h
index d24cf15d7cd6..07844abafe11 100644
--- a/clang/lib/Basic/Targets/Sparc.h
+++ b/clang/lib/Basic/Targets/Sparc.h
@@ -166,10 +166,15 @@ class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public 
SparcTargetInfo {
   PtrDiffType = SignedLong;
   break;
 }
-// Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
-// on up to 64 bits.
+// Up to 32 bits (V8) or 64 bits (V9) are lock-free atomic, but we're
+// willing to do atomic ops on up to 64 bits.
 MaxAtomicPromoteWidth = 64;
-MaxAtomicInlineWidth = 32;
+if (getCPUGeneration(CPU) == CG_V9)
+  MaxAtomicInlineWidth = 64;
+else
+  // FIXME: This isn't correct for plain 

[PATCH] D86621: [clang][Sparc] Default to -mcpu=v9 for SparcV8 on Solaris

2020-09-11 Thread Rainer Orth via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG76e85ae268f8: [clang][Sparc] Default to -mcpu=v9 for Sparc 
V8 on Solaris (authored by ro).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86621/new/

https://reviews.llvm.org/D86621

Files:
  clang/lib/Basic/Targets/Sparc.cpp
  clang/lib/Basic/Targets/Sparc.h
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/test/profile/Posix/instrprof-gcov-parallel.test
  compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp

Index: compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp
===
--- compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp
+++ compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp
@@ -11,9 +11,6 @@
 // FIXME: not %run %t 8 2>&1 | FileCheck %s --check-prefix=CHECK-8
 // RUN: not %run %t 9 2>&1 | FileCheck %s --check-prefix=CHECK-9
 
-// Bug 42535
-// XFAIL: sparc-target-arch
-
 // This test assumes float and double are IEEE-754 single- and double-precision.
 
 #if defined(__APPLE__)
Index: compiler-rt/test/profile/Posix/instrprof-gcov-parallel.test
===
--- compiler-rt/test/profile/Posix/instrprof-gcov-parallel.test
+++ compiler-rt/test/profile/Posix/instrprof-gcov-parallel.test
@@ -10,9 +10,6 @@
 RUN: llvm-cov gcov instrprof-gcov-parallel.target.gcda
 RUN: FileCheck --input-file instrprof-gcov-parallel.target.c.gcov %s
 
-# Bug 42535
-# XFAIL: sparc-target-arch
-
 # Test if the .gcda file is correctly created from one of child processes
 # and counters of all processes are recorded correctly.
 # 707 = CHILDREN * COUNT
Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -3235,9 +3235,26 @@
 // RUN: -target sparc-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC-V9
 // CHECK_SPARC-V9-NOT: #define __sparcv8 1
+// CHECK_SPARC-V9-NOT: #define __sparcv8__ 1
 // CHECK_SPARC-V9: #define __sparc_v9__ 1
 // CHECK_SPARC-V9: #define __sparcv9 1
-// CHECK_SPARC-V9-NOT: #define __sparcv8 1
+// CHECK_SPARC-V9: #define __sparcv9__ 1
+
+// RUN: %clang -E -dM %s -o - 2>&1 \
+// RUN: -target sparc-sun-solaris \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC_SOLARIS_GCC_ATOMICS
+// CHECK_SPARC_SOLARIS_GCC_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_SPARC_SOLARIS_GCC_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_SPARC_SOLARIS_GCC_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+// CHECK_SPARC_SOLARIS_GCC_ATOMICS: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
+
+// RUN: %clang -mcpu=v8 -E -dM %s -o - 2>&1 \
+// RUN: -target sparc-sun-solaris \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8
+// CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
+// CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
+// CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
+// CHECK_SPARC_SOLARIS_GCC_ATOMICS-V8-NOT: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
 
 // RUN: %clang -E -dM %s -o - 2>&1 \
 // RUN: -target sparcel-unknown-linux \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -347,6 +347,8 @@
   case llvm::Triple::sparcv9:
 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
   return A->getValue();
+if (T.getArch() == llvm::Triple::sparc && T.isOSSolaris())
+  return "v9";
 return "";
 
   case llvm::Triple::x86:
Index: clang/lib/Basic/Targets/Sparc.h
===
--- clang/lib/Basic/Targets/Sparc.h
+++ clang/lib/Basic/Targets/Sparc.h
@@ -166,10 +166,15 @@
   PtrDiffType = SignedLong;
   break;
 }
-// Up to 32 bits are lock-free atomic, but we're willing to do atomic ops
-// on up to 64 bits.
+// Up to 32 bits (V8) or 64 bits (V9) are lock-free atomic, but we're
+// willing to do atomic ops on up to 64 bits.
 MaxAtomicPromoteWidth = 64;
-MaxAtomicInlineWidth = 32;
+if (getCPUGeneration(CPU) == CG_V9)
+  MaxAtomicInlineWidth = 64;
+else
+  // FIXME: This isn't correct for plain V8 which lacks CAS,
+  // only for LEON 3+ and Myriad.
+  MaxAtomicInlineWidth = 32;
   }
 
   void getTargetDefines(const LangOptions &Opts,
Index: clang/lib/Basic/Targets/Sparc.cpp
==

[PATCH] D87458: [Clang] Clarify __builtin_memcpy_inline documentation

2020-09-11 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet marked an inline comment as done.
gchatelet added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2439
+guarantees not to call any external functions. See LLVM IR `llvm.memcpy.inline
+`_ Intrinsic 
+for more information.

courbet wrote:
> why capitalize ?
I somewhat missed this comment, I'll fix this as a separate commit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87458/new/

https://reviews.llvm.org/D87458

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b8ea47a - Uncapitalize word in LanguageExtensions.rst

2020-09-11 Thread via cfe-commits

Author: Guillaume Chatelet
Date: 2020-09-11T10:08:02+02:00
New Revision: b8ea47a38039c57e863e3047c33d8584e21360f0

URL: 
https://github.com/llvm/llvm-project/commit/b8ea47a38039c57e863e3047c33d8584e21360f0
DIFF: 
https://github.com/llvm/llvm-project/commit/b8ea47a38039c57e863e3047c33d8584e21360f0.diff

LOG: Uncapitalize word in LanguageExtensions.rst

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 073d9c86e22f..256f7e12364f 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2436,7 +2436,7 @@ Guaranteed inlined copy
 ``__builtin_memcpy_inline`` has been designed as a building block for efficient
 ``memcpy`` implementations. It is identical to ``__builtin_memcpy`` but also
 guarantees not to call any external functions. See LLVM IR `llvm.memcpy.inline
-`_ Intrinsic 
+`_ intrinsic 
 for more information.
 
 This is useful to implement a custom version of ``memcpy``, implemement a



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87458: [Clang] Clarify __builtin_memcpy_inline documentation

2020-09-11 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet marked an inline comment as done.
gchatelet added inline comments.



Comment at: clang/docs/LanguageExtensions.rst:2439
+guarantees not to call any external functions. See LLVM IR `llvm.memcpy.inline
+`_ Intrinsic 
+for more information.

gchatelet wrote:
> courbet wrote:
> > why capitalize ?
> I somewhat missed this comment, I'll fix this as a separate commit.
Done in rGb8ea47a 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87458/new/

https://reviews.llvm.org/D87458

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85408: Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.

2020-09-11 Thread Rahman Lavaee via Phabricator via cfe-commits
rahmanl updated this revision to Diff 291156.
rahmanl added a comment.

- Remove the complex assembly from the clang test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85408/new/

https://reviews.llvm.org/D85408

Files:
  clang/docs/UsersManual.rst
  clang/test/CodeGen/basic-block-sections.c
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/CodeGen/MachineFunction.h
  llvm/include/llvm/MC/MCObjectFileInfo.h
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/BasicBlockSections.cpp
  llvm/lib/CodeGen/MIRParser/MIRParser.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineFunction.cpp
  llvm/lib/MC/MCObjectFileInfo.cpp
  llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
  llvm/test/CodeGen/X86/basic-block-sections-labels.ll

Index: llvm/test/CodeGen/X86/basic-block-sections-labels.ll
===
--- llvm/test/CodeGen/X86/basic-block-sections-labels.ll
+++ llvm/test/CodeGen/X86/basic-block-sections-labels.ll
@@ -1,23 +1,24 @@
 ; Check the basic block sections labels option
-; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=labels | FileCheck %s -check-prefix=LINUX-LABELS
+; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=labels | FileCheck %s -check-prefix=CHECK
 
-define void @_Z3bazb(i1 zeroext) {
-  %2 = alloca i8, align 1
-  %3 = zext i1 %0 to i8
-  store i8 %3, i8* %2, align 1
-  %4 = load i8, i8* %2, align 1
-  %5 = trunc i8 %4 to i1
-  br i1 %5, label %6, label %8
+define void @_Z3bazb(i1 zeroext) personality i32 (...)* @__gxx_personality_v0 {
+  br i1 %0, label %2, label %7
 
-6:; preds = %1
-  %7 = call i32 @_Z3barv()
-  br label %10
+2:
+  %3 = invoke i32 @_Z3barv()
+  to label %7 unwind label %5
+  br label %9
 
-8:; preds = %1
-  %9 = call i32 @_Z3foov()
-  br label %10
+5:
+  landingpad { i8*, i32 }
+  catch i8* null
+  br label %9
 
-10:   ; preds = %8, %6
+7:
+  %8 = call i32 @_Z3foov()
+  br label %9
+
+9:
   ret void
 }
 
@@ -25,9 +26,31 @@
 
 declare i32 @_Z3foov() #1
 
-; LINUX-LABELS: .section
-; LINUX-LABELS: _Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: r.BB._Z3bazb:
-; LINUX-LABELS-NOT: .section
-; LINUX-LABELS: rr.BB._Z3bazb:
+declare i32 @__gxx_personality_v0(...)
+
+; CHECK-LABEL:	_Z3bazb:
+; CHECK-LABEL:	.Lfunc_begin0:
+; CHECK-LABEL:	.LBB_END0_0:
+; CHECK-LABEL:	.LBB0_1:
+; CHECK-LABEL:	.LBB_END0_1:
+; CHECK-LABEL:	.LBB0_2:
+; CHECK-LABEL:	.LBB_END0_2:
+; CHECK-LABEL:	.LBB0_3:
+; CHECK-LABEL:	.LBB_END0_3:
+; CHECK-LABEL:	.Lfunc_end0:
+
+; CHECK:	.section	.bb_addr_map,"o",@progbits,.text
+; CHECK-NEXT:	.quad	.Lfunc_begin0
+; CHECK-NEXT:	.byte	4
+; CHECK-NEXT:	.uleb128 .Lfunc_begin0-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_0-.Lfunc_begin0
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_1-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_1-.LBB0_1
+; CHECK-NEXT:	.byte	0
+; CHECK-NEXT:	.uleb128 .LBB0_2-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_2-.LBB0_2
+; CHECK-NEXT:	.byte	1
+; CHECK-NEXT:	.uleb128 .LBB0_3-.Lfunc_begin0
+; CHECK-NEXT:	.uleb128 .LBB_END0_3-.LBB0_3
+; CHECK-NEXT:	.byte	5
Index: llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -function-sections -basic-block-sections=labels | FileCheck %s
+
+$_Z4fooTIiET_v = comdat any
+
+define dso_local i32 @_Z3barv() {
+  ret i32 0
+}
+;; Check we add SHF_LINK_ORDER for .bb_addr_map and link it with the corresponding .text sections.
+; CHECK:		.section .text._Z3barv,"ax",@progbits
+; CHECK-LABEL:	_Z3barv:
+; CHECK-NEXT:	[[BAR_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"o",@progbits,.text._Z3barv{{$}}
+; CHECK-NEXT:		.quad [[BAR_BEGIN]]
+
+
+define dso_local i32 @_Z3foov() {
+  %1 = call i32 @_Z4fooTIiET_v()
+  ret i32 %1
+}
+; CHECK:		.section .text._Z3foov,"ax",@progbits
+; CHECK-LABEL:	_Z3foov:
+; CHECK-NEXT:	[[FOO_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section  .bb_addr_map,"o",@progbits,.text._Z3foov{{$}}
+; CHECK-NEXT:		.quad [[FOO_BEGIN]]
+
+
+define linkonce_odr dso_local i32 @_Z4fooTIiET_v() comdat {
+  ret i32 0
+}
+;; Check we add .bb_addr_map section to a COMDAT group with the corresponding .text section if such a COMDAT exists.
+; CHECK:		.section .text._Z4fooTIiET_v,"axG",@progbits,_Z4fooTIiET_v,comdat
+; CHECK-LABEL:	_Z4fooTIiET_v:
+; CHECK-NEXT:	[[FOOCOMDAT_BEGIN:.Lfunc_begin[0-9]+]]:
+; CHECK:		.section .bb_addr_map,"Go",@progbits,_Z4fooTIiET_v,comdat,.text._Z4fooTIiET_v{{$}}
+; CHECK-NEXT:		.quad [[FOOCOMDAT_BEGIN]]
Index: llvm/lib/MC/MCObjectFileInfo.cpp

[PATCH] D85408: Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.

2020-09-11 Thread Rahman Lavaee via Phabricator via cfe-commits
rahmanl added a comment.

In D85408#2266559 , @dblaikie wrote:

> In D85408#2262134 , @rahmanl wrote:
>
>> @efriedma Would you please chime in specially with respect to @MaskRay 's 
>> comment about the clang test involving assembly?
>
> I'll chime in, perhaps @efriedma will/can too: This patch has no changes to 
> Clang's code, so it should have no changes to Clang's tests, generally 
> speaking.
>
> Whatever codepath/behavior is being tested by that Clang test change should 
> be testable (& generally only tested) via LLVM's tools/tests, like llc, I 
> would expect? (I guess that's what the basic-block-sections-labels.ll test is 
> doing? Making the Clang test update redundant)
>
> The only reason I'd expect to see the assembly tested in Clang is if the flag 
> that enables this feature is an MCOptions (or other similar API level 
> feature) member, rather than part of LLVM IR proper. In that case the only 
> way to test that the flag has any effect (since we can't observe the 
> MCOptions struct state directly in a test) is to test for the MCOptions 
> effect on LLVM's output. Depending on the complexity, sometimes such tests 
> are just skipped entirely (leaving the setting of the MCOption untested) - I 
> think I did that for, for example, DWARF type units. Other times, an 
> end-to-end test is used to ensure the flag is working. But that's all the 
> test should do: test the flag is working, with some very basic/rudimentary 
> property of the feature being enabled (so pretty much /any/ change to the way 
> the feature works will still pass the test, but if the feature were turned 
> off entirely (the MCOptions flag stopped being set correctly), the test would 
> fail). Not test all the functionality of the feature that the flag enables - 
> all that testing should be down in LLVM.

Thanks for the clear explanation @dblaikie. In light of your comment,  I 
removed the complex assembly from the clang test, since the LLVM tests are 
already testing those.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85408/new/

https://reviews.llvm.org/D85408

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87449: [clang-tidy] Add new check for SEI CERT rule SIG30-C.

2020-09-11 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 291158.
balazske added a comment.

- Code formatting fixes.
- Updated description.
- Improved CalledFunctionsCollector.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87449/new/

https://reviews.llvm.org/D87449

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/cert/SignalHandlerCheck.h
  clang-tools-extra/docs/clang-tidy/checks/cert-sig30-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
  clang-tools-extra/test/clang-tidy/checkers/cert-sig30-c.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cert-sig30-c.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-sig30-c.cpp
@@ -0,0 +1,72 @@
+// RUN: %check_clang_tidy %s cert-sig30-c %t -- -- -isystem %S/Inputs/Headers
+
+#include "signal.h"
+#include "stdio.h"
+#include "stdlib.h"
+
+void handler_abort(int) {
+  abort();
+}
+
+void handler__Exit(int) {
+  _Exit(0);
+}
+
+void handler_quick_exit(int) {
+  quick_exit(0);
+}
+
+void handler_other(int) {
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Signal handler potentially calls non asynchronous-safe function. This may result in undefined behavior. [cert-sig30-c]
+}
+
+void handler_signal(int) {
+  // FIXME: It is only OK to call signal with the current signal number.
+  signal(0, SIG_DFL);
+}
+
+void f_ok() {
+  abort();
+}
+
+void f_bad() {
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Signal handler potentially calls non asynchronous-safe function. This may result in undefined behavior. [cert-sig30-c]
+}
+
+void f_extern();
+
+void handler_ok(int) {
+  f_ok();
+  f_extern();
+}
+
+void handler_bad(int) {
+  f_bad();
+}
+
+// Function called "signal" that is not to be recognized by the checker.
+typedef void (*callback_t)(int);
+void signal(int, callback_t, int);
+
+void test() {
+  signal(SIGINT, handler_abort);
+  signal(SIGINT, handler__Exit);
+  signal(SIGINT, handler_quick_exit);
+  signal(SIGINT, handler_signal);
+  signal(SIGINT, handler_other);
+
+  signal(SIGINT, handler_ok);
+  signal(SIGINT, handler_bad);
+
+  signal(SIGINT, quick_exit);
+  signal(SIGINT, other_call);
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: Signal handler potentially calls non asynchronous-safe function. This may result in undefined behavior. [cert-sig30-c]
+
+  signal(SIGINT, SIG_IGN);
+  signal(SIGINT, SIG_DFL);
+
+  // Do not find problems here.
+  signal(SIGINT, handler_bad, 1);
+}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
@@ -0,0 +1,18 @@
+//===--- stdio.h - Stub header for tests *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _STDLIB_H_
+#define _STDLIB_H_
+
+void abort(void);
+void _Exit(int __status);
+void quick_exit(int __status);
+
+void other_call(int);
+
+#endif // _STDLIB_H_
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
@@ -0,0 +1,22 @@
+//===--- stdio.h - Stub header for tests *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _SIGNAL_H_
+#define _SIGNAL_H_
+
+void _sig_ign(int);
+void _sig_dfl(int);
+
+#define SIGINT 1
+#define SIG_IGN _sig_ign
+#define SIG_DFL _sig_dfl
+
+typedef void (*sighandler_t)(int);
+sighandler_t signal(int signum, sighandler_t handler);
+
+#endif // _SIGNAL_H_
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -114,6 +114,7 @@
`cert-msc51-cpp `_,
`cert-oop57-cpp `_,
`cert-oop58-cpp `_,
+   `cert-sig30-c `_,
`clang-analyzer-core.DynamicTypePropagation `_,
`clang-analyzer-core.uninitialized.CapturedBlockVariable `_,
`clang-analyzer-cp

[PATCH] D87449: [clang-tidy] Add new check for SEI CERT rule SIG30-C.

2020-09-11 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 4 inline comments as done.
balazske added a comment.

It looks like that the `clang-tidy/add_new_check.py` script does not work 
correctly, at least it "corrupts" the **list.rst** file, and creates files with 
no newline at end.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87449/new/

https://reviews.llvm.org/D87449

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump

2020-09-11 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/BuildTree.h:30-31
+syntax::Leaf *createKeyword(Arena &A, tok::TokenKind K);
+syntax::Leaf *createLeaf(syntax::Arena &A, const char *spelling,
+ tok::TokenKind K);
+





Comment at: clang/include/clang/Tooling/Syntax/BuildTree.h:30-31
+syntax::Leaf *createKeyword(Arena &A, tok::TokenKind K);
+syntax::Leaf *createLeaf(syntax::Arena &A, const char *spelling,
+ tok::TokenKind K);
+

gribozavr2 wrote:
> 
I think putting token kind first might be more readable at the call site -- 
going top-down, first the kind (general), then spelling (specific).



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:26
+namespace {
+syntax::Leaf *createLeafLowLevel(syntax::Arena &A, const char *spelling) {
+  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(spelling)).second;

+`assert(spelling != nullptr);` ?



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:51
+  return createLeaf(A, tok::getKeywordSpelling(K), K);
+}
+

Could we make a combined function that does not require the user to make a 
distinction between punctuation and keywords?

We should also allow creating tokens that have a user-specified spelling, for 
example, identifiers and string literals.

So maybe define two functions:

```
// Uses the provided spelling.
syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K, StringRef 
Spelling);

// Infers spelling if possible.
syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K);
```




Comment at: clang/unittests/Tooling/Syntax/SynthesisTest.cpp:30-37
+  ASSERT_NE(C, nullptr);
+
+  auto Dump = trim(C->dump(Arena->sourceManager()));
+  auto Expected = trim(R"txt(
+',' Detached synthesized
+  )txt");
+

Could you extract the part that I highlighted into a function, and deduplicate 
it across all tests?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87495/new/

https://reviews.llvm.org/D87495

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87498: [SyntaxTree] Rename functions to start with verb

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

According to LLVM coding standards:
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87498

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/ComputeReplacements.cpp
  clang/lib/Tooling/Syntax/Mutations.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp
  clang/unittests/Tooling/Syntax/TreeTestBase.cpp

Index: clang/unittests/Tooling/Syntax/TreeTestBase.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTestBase.cpp
+++ clang/unittests/Tooling/Syntax/TreeTestBase.cpp
@@ -38,10 +38,10 @@
 ArrayRef tokens(syntax::Node *N) {
   assert(N->isOriginal() && "tokens of modified nodes are not well-defined");
   if (auto *L = dyn_cast(N))
-return llvm::makeArrayRef(L->token(), 1);
+return llvm::makeArrayRef(L->getToken(), 1);
   auto *T = cast(N);
-  return llvm::makeArrayRef(T->firstLeaf()->token(),
-T->lastLeaf()->token() + 1);
+  return llvm::makeArrayRef(T->findFirstLeaf()->getToken(),
+T->findLastLeaf()->getToken() + 1);
 }
 } // namespace
 
@@ -170,7 +170,7 @@
   auto *T = dyn_cast(Root);
   if (!T)
 return nullptr;
-  for (auto *C = T->firstChild(); C != nullptr; C = C->nextSibling()) {
+  for (auto *C = T->getFirstChild(); C != nullptr; C = C->getNextSibling()) {
 if (auto *Result = nodeByRange(R, C))
   return Result;
   }
Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -26,7 +26,7 @@
 
   auto *C = syntax::createPunctuation(*Arena, tok::comma);
   ASSERT_NE(C, nullptr);
-  EXPECT_EQ(C->token()->kind(), tok::comma);
+  EXPECT_EQ(C->getToken()->kind(), tok::comma);
   EXPECT_TRUE(C->canModify());
   EXPECT_FALSE(C->isOriginal());
   EXPECT_TRUE(C->isDetached());
Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -28,7 +28,7 @@
  << "Source file has syntax errors, they were printed to the test "
 "log";
 }
-auto Actual = StringRef(Root->dump(Arena->sourceManager())).trim().str();
+auto Actual = StringRef(Root->dump(Arena->getSourceManager())).trim().str();
 // EXPECT_EQ shows the diff between the two strings if they are different.
 EXPECT_EQ(Tree.trim().str(), Actual);
 if (Actual != Tree.trim().str()) {
@@ -63,7 +63,9 @@
   auto *AnnotatedNode = nodeByRange(AnnotatedRanges[i], Root);
   assert(AnnotatedNode);
   auto AnnotatedNodeDump =
-  StringRef(AnnotatedNode->dump(Arena->sourceManager())).trim().str();
+  StringRef(AnnotatedNode->dump(Arena->getSourceManager()))
+  .trim()
+  .str();
   // EXPECT_EQ shows the diff between the two strings if they are different.
   EXPECT_EQ(TreeDumps[i].trim().str(), AnnotatedNodeDump)
   << "Dumps diverged for the code:\n"
Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -19,7 +19,7 @@
 static void traverse(const syntax::Node *N,
  llvm::function_ref Visit) {
   if (auto *T = dyn_cast(N)) {
-for (auto *C = T->firstChild(); C; C = C->nextSibling())
+for (auto *C = T->getFirstChild(); C; C = C->getNextSibling())
   traverse(C, Visit);
   }
   Visit(N);
@@ -36,7 +36,9 @@
  const TokenBuffer &Tokens)
 : SourceMgr(SourceMgr), LangOpts(LangOpts), Tokens(Tokens) {}
 
-const syntax::TokenBuffer &syntax::Arena::tokenBuffer() const { return Tokens; }
+const syntax::TokenBuffer &syntax::Arena::getTokenBuffer() const {
+  return Tokens;
+}
 
 std::pair>
 syntax::Arena::lexBuffer(std::unique_ptr Input) {
@@ -51,7 +53,7 @@
 }
 
 bool syntax::Leaf::classof(const Node *N) {
-  return N->kind() == NodeKind::Leaf;
+  return N->getKind() == NodeKind::Leaf;
 }
 
 syntax::Node::Node(NodeKind Kind)
@@ -60,16 +62,20 @@
   this->setRole(NodeRole::Detached);
 }
 
-bool syntax::Node::isDetached() const { return role() == NodeRole::Detached; }
+bool syntax::Node::isDetached() const {
+  return getRole() == NodeRo

[PATCH] D73425: [PPC] Fix platform definitions when compiling FreeBSD powerpc64 as LE

2020-09-11 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

This is new functionality, so I don't think we should merge it so late in the 
release process.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73425/new/

https://reviews.llvm.org/D73425

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87450: [clangd] Implement hot index reloading for clangd-index-server

2020-09-11 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:71
 
 std::unique_ptr openIndex(llvm::StringRef Index) {
   return loadIndex(Index, /*UseIndex=*/true);

why do we have this extra indirection?



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:86
 
+  clangd::SwapIndex *Index;
+

why not make this private? also keep using `SymbolIndex`. also you can make 
this a reference now.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:224
+// whenever they become available.
+void hotReload(clangd::SwapIndex **Index, llvm::StringRef IndexPath) {
+  llvm::sys::TimePoint<> LastModificationTime =

why is this taking a double pointer? I think you can just use a reference here 
for `Index` (i.e. `clangd::SwapIndex &`



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:226
+  llvm::sys::TimePoint<> LastModificationTime =
+  std::chrono::system_clock::now();
+  for (;; std::this_thread::sleep_for(std::chrono::seconds(90))) {

i think we should rather store the file_status from the original file in here. 
as we want to reload whenever files size/modification_time has changed.
it doesn't have to be moving forward let alone share the same timezone 
restrictions and such provided by system_clock::now.

Also it would be nice to use a VFS in here, that way we can move this logic 
into a helper in the future if other components need similar logic.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:227
+  std::chrono::system_clock::now();
+  for (;; std::this_thread::sleep_for(std::chrono::seconds(90))) {
+llvm::sys::fs::file_status Status;

how's this loop terminated?

I would suggest factoring the loop body into a helper and then having a lambda 
for periodically running it, while looking for an exit signal.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:263
 
+  std::thread HotReloadThread(hotReload, &Service.Index, IndexPath);
+

i think `hotReload` thread creation should also be part of the main.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:266
   Server->Wait();
 }
 

you either need to `join` a thread before its destruction or `detach` it from 
the main thread.



Comment at: clang-tools-extra/clangd/index/remote/server/Server.cpp:313
 
-  std::unique_ptr Index = openIndex(IndexPath);
+  std::unique_ptr Index(
+  new clang::clangd::SwapIndex(openIndex(IndexPath)));

nit: `auto Index = std::make_unique(openIndex...);`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87450/new/

https://reviews.llvm.org/D87450

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] bceca7a - [clangd][NFC] Get rid of an `else after return`

2020-09-11 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-09-11T11:31:16+02:00
New Revision: bceca7a996248aba44c3e4b4752634114650e6ac

URL: 
https://github.com/llvm/llvm-project/commit/bceca7a996248aba44c3e4b4752634114650e6ac
DIFF: 
https://github.com/llvm/llvm-project/commit/bceca7a996248aba44c3e4b4752634114650e6ac.diff

LOG: [clangd][NFC] Get rid of an `else after return`

Added: 


Modified: 
clang-tools-extra/clangd/ClangdLSPServer.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 15ef89cb34fa..6ebb71c3b4d1 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -57,7 +57,7 @@ llvm::Optional decodeVersion(llvm::StringRef 
Encoded) {
   int64_t Result;
   if (llvm::to_integer(Encoded, Result, 10))
 return Result;
-  else if (!Encoded.empty()) // Empty can be e.g. diagnostics on close.
+  if (!Encoded.empty()) // Empty can be e.g. diagnostics on close.
 elog("unexpected non-numeric version {0}", Encoded);
   return llvm::None;
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87501: [clangd] Track tweaks that fail the apply stage

2020-09-11 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: adamcz.
Herald added subscribers: cfe-commits, usaxena95, arphaman, jkorous.
Herald added a project: clang.
kadircet requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87501

Files:
  clang-tools-extra/clangd/ClangdServer.cpp


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -537,9 +537,12 @@
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
   Callback CB) {
-  // Tracks number of times a tweak has been applied.
+  // Tracks number of times a tweak has been attempted.
   static constexpr trace::Metric TweakAttempt(
   "tweak_attempt", trace::Metric::Counter, "tweak_id");
+  // Tracks number of times a tweak has failed to produce edits.
+  static constexpr trace::Metric TweakFailed(
+  "tweak_failed", trace::Metric::Counter, "tweak_id");
   TweakAttempt.record(1, TweakID);
   auto Action = [File = File.str(), Sel, TweakID = TweakID.str(),
  CB = std::move(CB),
@@ -570,6 +573,8 @@
 if (llvm::Error Err = reformatEdit(E, Style))
   elog("Failed to format {0}: {1}", It.first(), std::move(Err));
   }
+} else {
+  TweakFailed.record(1, TweakID);
 }
 return CB(std::move(*Effect));
   };


Index: clang-tools-extra/clangd/ClangdServer.cpp
===
--- clang-tools-extra/clangd/ClangdServer.cpp
+++ clang-tools-extra/clangd/ClangdServer.cpp
@@ -537,9 +537,12 @@
 
 void ClangdServer::applyTweak(PathRef File, Range Sel, StringRef TweakID,
   Callback CB) {
-  // Tracks number of times a tweak has been applied.
+  // Tracks number of times a tweak has been attempted.
   static constexpr trace::Metric TweakAttempt(
   "tweak_attempt", trace::Metric::Counter, "tweak_id");
+  // Tracks number of times a tweak has failed to produce edits.
+  static constexpr trace::Metric TweakFailed(
+  "tweak_failed", trace::Metric::Counter, "tweak_id");
   TweakAttempt.record(1, TweakID);
   auto Action = [File = File.str(), Sel, TweakID = TweakID.str(),
  CB = std::move(CB),
@@ -570,6 +573,8 @@
 if (llvm::Error Err = reformatEdit(E, Style))
   elog("Failed to format {0}: {1}", It.first(), std::move(Err));
   }
+} else {
+  TweakFailed.record(1, TweakID);
 }
 return CB(std::move(*Effect));
   };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87358: [clang][aarch64] Fix ILP32 ABI for arm_sve_vector_bits

2020-09-11 Thread Cullen Rhodes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG002f5ab3b171: [clang][aarch64] Fix ILP32 ABI for 
arm_sve_vector_bits (authored by c-rhodes).

Changed prior to commit:
  https://reviews.llvm.org/D87358?vs=290974&id=291168#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87358/new/

https://reviews.llvm.org/D87358

Files:
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/attr-arm-sve-vector-bits-types.c


Index: clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
===
--- clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
+++ clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -msve-vector-bits=512 -fallow-half-arguments-and-returns 
-S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-512
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -msve-vector-bits=1024 -fallow-half-arguments-and-returns 
-S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-1024
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -msve-vector-bits=2048 -fallow-half-arguments-and-returns 
-S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-2048
+// RUN: %clang_cc1 -triple aarch64_32-unknown-darwin -target-feature +sve 
-target-feature +bf16 -msve-vector-bits=512 -fallow-half-arguments-and-returns 
-S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-ILP32
 
 #include 
 
@@ -579,3 +580,11 @@
 // CHECK-2048-NEXT:  %local_arr_f64 = alloca [3 x <32 x double>], align 16
 // CHECK-2048-NEXT:  %local_arr_bf16 = alloca [3 x <128 x bfloat>], align 16
 // CHECK-2048-NEXT:  %local_arr_bool = alloca [3 x <32 x i8>], align 2
+
+//===--===//
+// ILP32 ABI
+//===--===//
+// CHECK-ILP32: @global_i32 = global <16 x i32> zeroinitializer, align 16
+// CHECK-ILP32: @global_i64 = global <8 x i64> zeroinitializer, align 16
+// CHECK-ILP32: @global_u32 = global <16 x i32> zeroinitializer, align 16
+// CHECK-ILP32: @global_u64 = global <8 x i64> zeroinitializer, align 16
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5627,7 +5627,7 @@
   ResType = llvm::ScalableVectorType::get(
   llvm::Type::getInt64Ty(getVMContext()), 2);
   break;
-case BuiltinType::Float16:
+case BuiltinType::Half:
   ResType = llvm::ScalableVectorType::get(
   llvm::Type::getHalfTy(getVMContext()), 8);
   break;
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2317,38 +2317,13 @@
   assert(isVLSTBuiltinType() && "unsupported type!");
 
   const BuiltinType *BTy = getAs();
-  switch (BTy->getKind()) {
-  default:
-llvm_unreachable("Unknown builtin SVE type!");
-  case BuiltinType::SveInt8:
-return Ctx.SignedCharTy;
-  case BuiltinType::SveUint8:
-  case BuiltinType::SveBool:
+  if (BTy->getKind() == BuiltinType::SveBool)
 // Represent predicates as i8 rather than i1 to avoid any layout issues.
 // The type is bitcasted to a scalable predicate type when casting between
 // scalable and fixed-length vectors.
 return Ctx.UnsignedCharTy;
-  case BuiltinType::SveInt16:
-return Ctx.ShortTy;
-  case BuiltinType::SveUint16:
-return Ctx.UnsignedShortTy;
-  case BuiltinType::SveInt32:
-return Ctx.IntTy;
-  case BuiltinType::SveUint32:
-return Ctx.UnsignedIntTy;
-  case BuiltinType::SveInt64:
-return Ctx.LongTy;
-  case BuiltinType::SveUint64:
-return Ctx.UnsignedLongTy;
-  case BuiltinType::SveFloat16:
-return Ctx.Float16Ty;
-  case BuiltinType::SveBFloat16:
-return Ctx.BFloat16Ty;
-  case BuiltinType::SveFloat32:
-return Ctx.FloatTy;
-  case BuiltinType::SveFloat64:
-return Ctx.DoubleTy;
-  }
+  else
+return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType;
 }
 
 bool QualType::isPODType(const ASTContext &Context) const {
Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -3388,7 +3388,7 @@
   case BuiltinType::ULong:
 TypeName = "__SVUint64_t";
 break;
-  case BuiltinType::Float16:
+  case BuiltinType::Half:
 TypeName = "__SVFloat16_t";
 break;
   case BuiltinType::Float:


Index: clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
===
--- clang/test/CodeGen/attr-arm-sve-vect

[clang] 002f5ab - [clang][aarch64] Fix ILP32 ABI for arm_sve_vector_bits

2020-09-11 Thread Cullen Rhodes via cfe-commits

Author: Cullen Rhodes
Date: 2020-09-11T09:46:35Z
New Revision: 002f5ab3b171c7d9c9ea192b04a5303be78f6e52

URL: 
https://github.com/llvm/llvm-project/commit/002f5ab3b171c7d9c9ea192b04a5303be78f6e52
DIFF: 
https://github.com/llvm/llvm-project/commit/002f5ab3b171c7d9c9ea192b04a5303be78f6e52.diff

LOG: [clang][aarch64] Fix ILP32 ABI for arm_sve_vector_bits

The element types of scalable vectors are defined in terms of stdint
types in the ACLE. This patch fixes the mapping to builtin types for the
ILP32 ABI when creating VLS types with the arm_sve_vector_bits, where
the mapping is as follows:

  int32_t -> LongTy
  int64_t -> LongLongTy
  uint32_t -> UnsignedLongTy
  uint64_t -> UnsignedLongLongTy

This is implemented by leveraging getBuiltinVectorTypeInfo which is
target agnostic since it calls ASTContext::getIntTypeForBitwidth for
integer types. The element type for svfloat16_t is changed from
Float16Ty to HalfTy when creating VLS types since this is what is used
elsewhere.

For more information, see:

https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#types-varying-by-data-model
https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#appendix-support-for-scalable-vectors

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D87358

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/Type.cpp
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/attr-arm-sve-vector-bits-types.c

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index d8ccbdaba9c60..877050c160955 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3388,7 +3388,7 @@ void 
CXXNameMangler::mangleAArch64FixedSveVectorType(const VectorType *T) {
   case BuiltinType::ULong:
 TypeName = "__SVUint64_t";
 break;
-  case BuiltinType::Float16:
+  case BuiltinType::Half:
 TypeName = "__SVFloat16_t";
 break;
   case BuiltinType::Float:

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 801f89a8f1874..ff73a7340091e 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2317,38 +2317,13 @@ QualType Type::getSveEltType(const ASTContext &Ctx) 
const {
   assert(isVLSTBuiltinType() && "unsupported type!");
 
   const BuiltinType *BTy = getAs();
-  switch (BTy->getKind()) {
-  default:
-llvm_unreachable("Unknown builtin SVE type!");
-  case BuiltinType::SveInt8:
-return Ctx.SignedCharTy;
-  case BuiltinType::SveUint8:
-  case BuiltinType::SveBool:
+  if (BTy->getKind() == BuiltinType::SveBool)
 // Represent predicates as i8 rather than i1 to avoid any layout issues.
 // The type is bitcasted to a scalable predicate type when casting between
 // scalable and fixed-length vectors.
 return Ctx.UnsignedCharTy;
-  case BuiltinType::SveInt16:
-return Ctx.ShortTy;
-  case BuiltinType::SveUint16:
-return Ctx.UnsignedShortTy;
-  case BuiltinType::SveInt32:
-return Ctx.IntTy;
-  case BuiltinType::SveUint32:
-return Ctx.UnsignedIntTy;
-  case BuiltinType::SveInt64:
-return Ctx.LongTy;
-  case BuiltinType::SveUint64:
-return Ctx.UnsignedLongTy;
-  case BuiltinType::SveFloat16:
-return Ctx.Float16Ty;
-  case BuiltinType::SveBFloat16:
-return Ctx.BFloat16Ty;
-  case BuiltinType::SveFloat32:
-return Ctx.FloatTy;
-  case BuiltinType::SveFloat64:
-return Ctx.DoubleTy;
-  }
+  else
+return Ctx.getBuiltinVectorTypeInfo(BTy).ElementType;
 }
 
 bool QualType::isPODType(const ASTContext &Context) const {

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index e1ab61f10585d..5ebf432a4cd36 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -5627,7 +5627,7 @@ ABIArgInfo AArch64ABIInfo::coerceIllegalVector(QualType 
Ty) const {
   ResType = llvm::ScalableVectorType::get(
   llvm::Type::getInt64Ty(getVMContext()), 2);
   break;
-case BuiltinType::Float16:
+case BuiltinType::Half:
   ResType = llvm::ScalableVectorType::get(
   llvm::Type::getHalfTy(getVMContext()), 8);
   break;

diff  --git a/clang/test/CodeGen/attr-arm-sve-vector-bits-types.c 
b/clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
index a1cfc514081ea..27366dea3d34d 100644
--- a/clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
+++ b/clang/test/CodeGen/attr-arm-sve-vector-bits-types.c
@@ -4,6 +4,7 @@
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -msve-vector-bits=512 -fallow-half-arguments-and-returns 
-S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-512
 // RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +bf16 -msve-vector-bits=1024 -fallow-half-arguments-and-returns 
-S -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-1024
 // RUN: %clang_cc1 -triple aa

[PATCH] D86089: [flang][driver]Add experimental flang driver and frontend with help screen

2020-09-11 Thread Caroline via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG257b29715bb2: [flang][driver] Add the new flang compiler and 
frontend drivers (authored by CarolineConcatto).

Changed prior to commit:
  https://reviews.llvm.org/D86089?vs=291068&id=291169#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86089/new/

https://reviews.llvm.org/D86089

Files:
  clang/include/clang/Driver/Driver.h
  clang/include/clang/Driver/Options.h
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
  clang/lib/Tooling/Tooling.cpp
  clang/test/Driver/flang/flang.f90
  clang/test/Driver/flang/flang_ucase.F90
  clang/test/Driver/flang/multiple-inputs-mixed.f90
  clang/test/Driver/flang/multiple-inputs.f90
  clang/unittests/Driver/SanitizerArgsTest.cpp
  clang/unittests/Driver/ToolChainTest.cpp
  flang/CMakeLists.txt
  flang/README.md
  flang/include/flang/Frontend/CompilerInstance.h
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/FrontendOptions.h
  flang/include/flang/FrontendTool/Utils.h
  flang/lib/CMakeLists.txt
  flang/lib/Frontend/CMakeLists.txt
  flang/lib/Frontend/CompilerInstance.cpp
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendOptions.cpp
  flang/lib/FrontendTool/CMakeLists.txt
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/CMakeLists.txt
  flang/test/Flang-Driver/driver-error-cc1.c
  flang/test/Flang-Driver/driver-error-cc1.cpp
  flang/test/Flang-Driver/driver-help.f90
  flang/test/Flang-Driver/driver-version.f90
  flang/test/Flang-Driver/emit-obj.f90
  flang/test/Flang-Driver/missing-input.f90
  flang/test/lit.cfg.py
  flang/test/lit.site.cfg.py.in
  flang/tools/CMakeLists.txt
  flang/tools/flang-driver/CMakeLists.txt
  flang/tools/flang-driver/driver.cpp
  flang/tools/flang-driver/fc1_main.cpp
  flang/unittests/CMakeLists.txt
  flang/unittests/Frontend/CMakeLists.txt
  flang/unittests/Frontend/CompilerInstanceTest.cpp
  llvm/include/llvm/Option/OptTable.h

Index: llvm/include/llvm/Option/OptTable.h
===
--- llvm/include/llvm/Option/OptTable.h
+++ llvm/include/llvm/Option/OptTable.h
@@ -50,7 +50,7 @@
 unsigned ID;
 unsigned char Kind;
 unsigned char Param;
-unsigned short Flags;
+unsigned int Flags;
 unsigned short GroupID;
 unsigned short AliasID;
 const char *AliasArgs;
Index: flang/unittests/Frontend/CompilerInstanceTest.cpp
===
--- /dev/null
+++ flang/unittests/Frontend/CompilerInstanceTest.cpp
@@ -0,0 +1,52 @@
+//===- unittests/Frontend/CompilerInstanceTest.cpp - CI tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "flang/Frontend/CompilerInstance.h"
+#include "gtest/gtest.h"
+#include "flang/Frontend/CompilerInvocation.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Driver/Options.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+using namespace llvm;
+using namespace Fortran::frontend;
+
+namespace {
+
+TEST(CompilerInstance, AllowDiagnosticLogWithUnownedDiagnosticConsumer) {
+  // 1. Set-up a basic DiagnosticConsumer
+  std::string diagnosticOutput;
+  llvm::raw_string_ostream diagnosticsOS(diagnosticOutput);
+  auto diagPrinter = std::make_unique(
+  diagnosticsOS, new clang::DiagnosticOptions());
+
+  // 2. Create a CompilerInstance (to manage a DiagnosticEngine)
+  CompilerInstance compInst;
+
+  // 3. Set-up DiagnosticOptions
+  auto diagOpts = new clang::DiagnosticOptions();
+  // Tell the diagnostics engine to emit the diagnostic log to STDERR. This
+  // ensures that a chained diagnostic consumer is created so that the test can
+  // exercise the unowned diagnostic consumer in a chained consumer.
+  diagOpts->DiagnosticLogFile = "-";
+
+  // 4. Create a DiagnosticEngine with an unowned consumer
+  IntrusiveRefCntPtr diags =
+  compInst.CreateDiagnostics(diagOpts, diagPrinter.get(),
+  /*ShouldOwnClient=*/false);
+
+  // 5. Report a diagnostic
+  diags->Report(clang::diag::err_expected) << "no crash";
+
+  // 6. Verify that the reported diagnostic wasn't lost and did end up in the
+  // output stream
+  ASSERT_EQ(diagnosticsOS.str(), "error: expected no crash\n");
+}
+} // namespace
Index: flang/unittests/Frontend/CMakeLists.txt
===
--- /dev/null
+++ flang/unittests/Frontend/CMakeLists.txt
@@ -

[clang] 257b297 - [flang][driver] Add the new flang compiler and frontend drivers

2020-09-11 Thread Caroline Concatto via cfe-commits

Author: Caroline Concatto
Date: 2020-09-11T10:55:54+01:00
New Revision: 257b29715bb27b7d9f6c3c40c481b6a4af0b37e5

URL: 
https://github.com/llvm/llvm-project/commit/257b29715bb27b7d9f6c3c40c481b6a4af0b37e5
DIFF: 
https://github.com/llvm/llvm-project/commit/257b29715bb27b7d9f6c3c40c481b6a4af0b37e5.diff

LOG: [flang][driver] Add the new flang compiler and frontend drivers

Summary:

This is the first patch implementing the new Flang driver as outlined in [1],
[2] & [3]. It creates Flang driver (`flang-new`) and Flang frontend driver
(`flang-new -fc1`). These will be renamed as `flang` and `flang -fc1` once the
current Flang throwaway driver, `flang`, can be replaced with `flang-new`.

Currently only 2 options are supported: `-help` and `--version`.

`flang-new` is implemented in terms of libclangDriver, defaulting the driver
mode to `FlangMode` (added to libclangDriver in [4]). This ensures that the
driver runs in Flang mode regardless of the name of the binary inferred from
argv[0].

The design of the new Flang compiler and frontend drivers is inspired by it
counterparts in Clang [3]. Currently, the new Flang compiler and frontend
drivers re-use Clang libraries: clangBasic, clangDriver and clangFrontend.

To identify Flang options, this patch adds FlangOption/FC1Option enums.
Driver::printHelp is updated so that `flang-new` prints only Flang options.
The new Flang driver is disabled by default. To enable it, set
`-DBUILD_FLANG_NEW_DRIVER=ON` when configuring CMake and add clang to
`LLVM_ENABLE_PROJECTS` (e.g. -DLLVM_ENABLE_PROJECTS=“clang;flang;mlir”).

[1] “RFC: new Flang driver - next steps”
http://lists.llvm.org/pipermail/flang-dev/2020-July/000470.html
[2] “RFC: Adding a fortran mode to the clang driver for flang”
http://lists.llvm.org/pipermail/cfe-dev/2019-June/062669.html
[3] “RFC: refactoring libclangDriver/libclangFrontend to share with Flang”
http://lists.llvm.org/pipermail/cfe-dev/2020-July/066393.html
[4] https://reviews.llvm.org/rG6bf55804924d5a1d902925ad080b1a2b57c5c75c

co-authored-by: Andrzej Warzynski 

Reviewed By: richard.barton.arm, sameeranjoshi

Differential Revision: https://reviews.llvm.org/D86089

Added: 
flang/include/flang/Frontend/CompilerInstance.h
flang/include/flang/Frontend/CompilerInvocation.h
flang/include/flang/Frontend/FrontendOptions.h
flang/include/flang/FrontendTool/Utils.h
flang/lib/Frontend/CMakeLists.txt
flang/lib/Frontend/CompilerInstance.cpp
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendOptions.cpp
flang/lib/FrontendTool/CMakeLists.txt
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Flang-Driver/driver-error-cc1.c
flang/test/Flang-Driver/driver-error-cc1.cpp
flang/test/Flang-Driver/driver-help.f90
flang/test/Flang-Driver/driver-version.f90
flang/test/Flang-Driver/emit-obj.f90
flang/test/Flang-Driver/missing-input.f90
flang/tools/flang-driver/CMakeLists.txt
flang/tools/flang-driver/driver.cpp
flang/tools/flang-driver/fc1_main.cpp
flang/unittests/Frontend/CMakeLists.txt
flang/unittests/Frontend/CompilerInstanceTest.cpp

Modified: 
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Options.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
clang/lib/Tooling/Tooling.cpp
clang/test/Driver/flang/flang.f90
clang/test/Driver/flang/flang_ucase.F90
clang/test/Driver/flang/multiple-inputs-mixed.f90
clang/test/Driver/flang/multiple-inputs.f90
clang/unittests/Driver/SanitizerArgsTest.cpp
clang/unittests/Driver/ToolChainTest.cpp
flang/CMakeLists.txt
flang/README.md
flang/lib/CMakeLists.txt
flang/test/CMakeLists.txt
flang/test/lit.cfg.py
flang/test/lit.site.cfg.py.in
flang/tools/CMakeLists.txt
flang/unittests/CMakeLists.txt
llvm/include/llvm/Option/OptTable.h

Removed: 




diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index dc18f1314f81..7a476199ff7f 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -301,7 +301,7 @@ class Driver {
   StringRef CustomResourceDir = "");
 
   Driver(StringRef ClangExecutable, StringRef TargetTriple,
- DiagnosticsEngine &Diags,
+ DiagnosticsEngine &Diags, std::string Title = "clang LLVM compiler",
  IntrusiveRefCntPtr VFS = nullptr);
 
   /// @name Accessors

diff  --git a/clang/include/clang/Driver/Options.h 
b/clang/include/clang/Driver/Options.h
index 9831efda4e58..06dd3652be94 100644
--- a/clang/include/clang/Driver/Options.h
+++ b/clang/include/clang/Driver/Options.h
@@ -34,7 +34,9 @@ enum ClangFlags {
   CC1AsOption = (1 << 11),
   NoDriverOption = (1 << 12),
   LinkOption = (1 << 13),
-  

[PATCH] D87463: [clang][aarch64] Fix mangling of bfloat16 neon vectors

2020-09-11 Thread Cullen Rhodes via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcabd60c26b5d: [clang][aarch64] Fix mangling of bfloat16 neon 
vectors (authored by c-rhodes).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87463/new/

https://reviews.llvm.org/D87463

Files:
  clang/lib/AST/ItaniumMangle.cpp
  clang/test/CodeGenCXX/mangle-neon-vectors.cpp


Index: clang/test/CodeGenCXX/mangle-neon-vectors.cpp
===
--- clang/test/CodeGenCXX/mangle-neon-vectors.cpp
+++ clang/test/CodeGenCXX/mangle-neon-vectors.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -triple armv7-apple-ios -target-feature +neon  %s 
-emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-apple-ios -target-feature +neon %s -emit-llvm 
-o - | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon %s -emit-llvm 
-o - | FileCheck %s --check-prefix=CHECK-AARCH64
+// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon 
-target-feature +bf16 %s -emit-llvm -o - | FileCheck %s 
--check-prefix=CHECK-AARCH64-BF16
 
 typedef float float32_t;
 typedef double float64_t;
@@ -14,6 +15,10 @@
 #endif
 typedef unsigned __INT64_TYPE__ uint64_t;
 
+#if defined(__ARM_FEATURE_BF16)
+typedef __bf16 bfloat16_t;
+#endif
+
 typedef __attribute__((neon_vector_type(2))) int int32x2_t;
 typedef __attribute__((neon_vector_type(4))) int int32x4_t;
 typedef __attribute__((neon_vector_type(1))) uint64_t uint64x1_t;
@@ -28,6 +33,10 @@
 typedef __attribute__((neon_polyvector_type(16))) poly8_t  poly8x16_t;
 typedef __attribute__((neon_polyvector_type(8)))  poly16_t poly16x8_t;
 
+#if defined(__ARM_FEATURE_BF16)
+typedef __attribute__((neon_vector_type(4))) __bf16 bfloat16x4_t;
+#endif
+
 // CHECK: 16__simd64_int32_t
 // CHECK-AARCH64: 11__Int32x2_t
 void f1(int32x2_t v) { }
@@ -72,3 +81,8 @@
 // CHECK-AARCH64: 13__Float64x2_t
 void f11(float64x2_t v) { }
 #endif
+
+#if defined(__ARM_FEATURE_BF16)
+// CHECK-AARCH64-BF16: 14__Bfloat16x4_t
+void f12(bfloat16x4_t v) {}
+#endif
Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -3275,7 +3275,7 @@
   case BuiltinType::Double:
 return "Float64";
   case BuiltinType::BFloat16:
-return "BFloat16";
+return "Bfloat16";
   default:
 llvm_unreachable("Unexpected vector element base type");
   }


Index: clang/test/CodeGenCXX/mangle-neon-vectors.cpp
===
--- clang/test/CodeGenCXX/mangle-neon-vectors.cpp
+++ clang/test/CodeGenCXX/mangle-neon-vectors.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -triple armv7-apple-ios -target-feature +neon  %s -emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-apple-ios -target-feature +neon %s -emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-AARCH64
+// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon -target-feature +bf16 %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-AARCH64-BF16
 
 typedef float float32_t;
 typedef double float64_t;
@@ -14,6 +15,10 @@
 #endif
 typedef unsigned __INT64_TYPE__ uint64_t;
 
+#if defined(__ARM_FEATURE_BF16)
+typedef __bf16 bfloat16_t;
+#endif
+
 typedef __attribute__((neon_vector_type(2))) int int32x2_t;
 typedef __attribute__((neon_vector_type(4))) int int32x4_t;
 typedef __attribute__((neon_vector_type(1))) uint64_t uint64x1_t;
@@ -28,6 +33,10 @@
 typedef __attribute__((neon_polyvector_type(16))) poly8_t  poly8x16_t;
 typedef __attribute__((neon_polyvector_type(8)))  poly16_t poly16x8_t;
 
+#if defined(__ARM_FEATURE_BF16)
+typedef __attribute__((neon_vector_type(4))) __bf16 bfloat16x4_t;
+#endif
+
 // CHECK: 16__simd64_int32_t
 // CHECK-AARCH64: 11__Int32x2_t
 void f1(int32x2_t v) { }
@@ -72,3 +81,8 @@
 // CHECK-AARCH64: 13__Float64x2_t
 void f11(float64x2_t v) { }
 #endif
+
+#if defined(__ARM_FEATURE_BF16)
+// CHECK-AARCH64-BF16: 14__Bfloat16x4_t
+void f12(bfloat16x4_t v) {}
+#endif
Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -3275,7 +3275,7 @@
   case BuiltinType::Double:
 return "Float64";
   case BuiltinType::BFloat16:
-return "BFloat16";
+return "Bfloat16";
   default:
 llvm_unreachable("Unexpected vector element base type");
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] cabd60c - [clang][aarch64] Fix mangling of bfloat16 neon vectors

2020-09-11 Thread Cullen Rhodes via cfe-commits

Author: Cullen Rhodes
Date: 2020-09-11T10:11:45Z
New Revision: cabd60c26b5df34f096a5a915bde3b1d8ee1

URL: 
https://github.com/llvm/llvm-project/commit/cabd60c26b5df34f096a5a915bde3b1d8ee1
DIFF: 
https://github.com/llvm/llvm-project/commit/cabd60c26b5df34f096a5a915bde3b1d8ee1.diff

LOG: [clang][aarch64] Fix mangling of bfloat16 neon vectors

The AAPCS64 specifies the internal type is used for c++ mangling. For
bfloat16 it was defined as `BFloat16` when it should be `Bfloat16`, i.e.
lowercase 'f'.

For more information, see:

https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#appendix-support-for-advanced-simd-extensions

Reviewed By: stuij

Differential Revision: https://reviews.llvm.org/D87463

Added: 


Modified: 
clang/lib/AST/ItaniumMangle.cpp
clang/test/CodeGenCXX/mangle-neon-vectors.cpp

Removed: 




diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 877050c16095..eb3aa807f63a 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -3275,7 +3275,7 @@ static StringRef mangleAArch64VectorBase(const 
BuiltinType *EltType) {
   case BuiltinType::Double:
 return "Float64";
   case BuiltinType::BFloat16:
-return "BFloat16";
+return "Bfloat16";
   default:
 llvm_unreachable("Unexpected vector element base type");
   }

diff  --git a/clang/test/CodeGenCXX/mangle-neon-vectors.cpp 
b/clang/test/CodeGenCXX/mangle-neon-vectors.cpp
index 6faf6226efd2..cb5e40be6a6d 100644
--- a/clang/test/CodeGenCXX/mangle-neon-vectors.cpp
+++ b/clang/test/CodeGenCXX/mangle-neon-vectors.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -triple armv7-apple-ios -target-feature +neon  %s 
-emit-llvm -o - | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-apple-ios -target-feature +neon %s -emit-llvm 
-o - | FileCheck %s
 // RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon %s -emit-llvm 
-o - | FileCheck %s --check-prefix=CHECK-AARCH64
+// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon 
-target-feature +bf16 %s -emit-llvm -o - | FileCheck %s 
--check-prefix=CHECK-AARCH64-BF16
 
 typedef float float32_t;
 typedef double float64_t;
@@ -14,6 +15,10 @@ typedef short poly16_t;
 #endif
 typedef unsigned __INT64_TYPE__ uint64_t;
 
+#if defined(__ARM_FEATURE_BF16)
+typedef __bf16 bfloat16_t;
+#endif
+
 typedef __attribute__((neon_vector_type(2))) int int32x2_t;
 typedef __attribute__((neon_vector_type(4))) int int32x4_t;
 typedef __attribute__((neon_vector_type(1))) uint64_t uint64x1_t;
@@ -28,6 +33,10 @@ typedef __attribute__((neon_vector_type(2))) float64_t 
float64x2_t;
 typedef __attribute__((neon_polyvector_type(16))) poly8_t  poly8x16_t;
 typedef __attribute__((neon_polyvector_type(8)))  poly16_t poly16x8_t;
 
+#if defined(__ARM_FEATURE_BF16)
+typedef __attribute__((neon_vector_type(4))) __bf16 bfloat16x4_t;
+#endif
+
 // CHECK: 16__simd64_int32_t
 // CHECK-AARCH64: 11__Int32x2_t
 void f1(int32x2_t v) { }
@@ -72,3 +81,8 @@ void f10(poly16x8_t v) {}
 // CHECK-AARCH64: 13__Float64x2_t
 void f11(float64x2_t v) { }
 #endif
+
+#if defined(__ARM_FEATURE_BF16)
+// CHECK-AARCH64-BF16: 14__Bfloat16x4_t
+void f12(bfloat16x4_t v) {}
+#endif



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87358: [clang][aarch64] Fix ILP32 ABI for arm_sve_vector_bits

2020-09-11 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes added inline comments.



Comment at: clang/lib/AST/Type.cpp:2324
 // scalable and fixed-length vectors.
-return Ctx.UnsignedCharTy;
-  case BuiltinType::SveInt16:
-return Ctx.ShortTy;
-  case BuiltinType::SveUint16:
-return Ctx.UnsignedShortTy;
-  case BuiltinType::SveInt32:
-return Ctx.IntTy;
-  case BuiltinType::SveUint32:
-return Ctx.UnsignedIntTy;
-  case BuiltinType::SveInt64:
-return Ctx.LongTy;
-  case BuiltinType::SveUint64:
-return Ctx.UnsignedLongTy;
-  case BuiltinType::SveFloat16:
-return Ctx.Float16Ty;
-  case BuiltinType::SveBFloat16:
-return Ctx.BFloat16Ty;
-  case BuiltinType::SveFloat32:
-return Ctx.FloatTy;
-  case BuiltinType::SveFloat64:
-return Ctx.DoubleTy;
-  }
+return Ctx.getIntTypeForBitwidth(8, /*Signed=*/0);
+  else

efriedma wrote:
> For 8-bit types, not sure you're getting anything by using 
> getIntTypeForBitwidth instead of Ctx.UnsignedCharTy; there isn't actually any 
> possible variation. I don't care much either way, though.
> For 8-bit types, not sure you're getting anything by using 
> getIntTypeForBitwidth instead of Ctx.UnsignedCharTy; there isn't actually any 
> possible variation. I don't care much either way, though.

Yeah you're right, may as well keep `Ctx.UnsignedCharTy`, I changed it before 
pushing. Thanks for reviewing!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87358/new/

https://reviews.llvm.org/D87358

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87463: [clang][aarch64] Fix mangling of bfloat16 neon vectors

2020-09-11 Thread Ties Stuij via Phabricator via cfe-commits
stuij added a comment.

I'm not sure what the procedure is to get patches into LLVM 11, but I think 
there's still time. Could you try to get this in there as well @c-rhodes ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87463/new/

https://reviews.llvm.org/D87463

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85473: [Clang] Add option to allow marking pass-by-value args as noalias.

2020-09-11 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 291176.
fhahn added a comment.

Update code to limit adding noalias to types with `getArgPassingRestrictions() 
== RecordDecl::APK_CanPassInRegs`. This rules out problematic types, like ones 
with non-trivial constructors or ObjC structs with weak pointers. Thanks 
@rjmccall

I also added the escape cases shared on cfe-dev by @rsmith


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85473/new/

https://reviews.llvm.org/D85473

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/pass-by-value-noalias.c
  clang/test/CodeGenCXX/pass-by-value-noalias.cpp
  clang/test/CodeGenObjC/pass-by-value-noalias.m

Index: clang/test/CodeGenObjC/pass-by-value-noalias.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/pass-by-value-noalias.m
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fpass-by-value-is-noalias -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns -fobjc-runtime-has-weak -fobjc-arc -fobjc-dispatch-method=mixed %s -o - 2>&1 | FileCheck --check-prefix=WITH_NOALIAS %s
+// RUN: %clang_cc1 -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns -fobjc-runtime-has-weak -fobjc-arc -fobjc-dispatch-method=mixed %s -o - 2>&1 | FileCheck --check-prefix=NO_NOALIAS %s
+
+@interface Bar
+@property char value;
+@end
+
+// A struct large enough so it is not passed in registers on ARM64, but with a
+// weak reference, so noalias should not be added even with
+// -fpass-by-value-is-noalias.
+struct Foo {
+  int a;
+  int b;
+  int c;
+  int d;
+  int e;
+  Bar *__weak f;
+};
+
+// WITH_NOALIAS: define void @take(%struct.Foo* %arg)
+// NO_NOALIAS: define void @take(%struct.Foo* %arg)
+void take(struct Foo arg) {}
Index: clang/test/CodeGenCXX/pass-by-value-noalias.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pass-by-value-noalias.cpp
@@ -0,0 +1,69 @@
+// RUN: %clang_cc1 -fpass-by-value-is-noalias -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=WITH_NOALIAS %s
+// RUN: %clang_cc1 -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=NO_NOALIAS %s
+
+// A trivial struct large enough so it is not passed in registers on ARM64.
+struct Foo {
+  int a;
+  int b;
+  int c;
+  int d;
+  int e;
+  int f;
+};
+
+// Make sure noalias is added to indirect arguments with trivially copyable types
+// if -fpass-by-value-is-noalias is provided.
+
+// WITH_NOALIAS: define void @_Z4take3Foo(%struct.Foo* noalias %arg)
+// NO_NOALIAS: define void @_Z4take3Foo(%struct.Foo* %arg)
+void take(Foo arg) {}
+
+int G;
+
+// NonTrivial is not trivially-copyable, because it has a non-trivial copy
+// constructor.
+struct NonTrivial {
+  int a;
+  int b;
+  int c;
+  int d;
+  int e;
+  int f;
+
+  NonTrivial(const NonTrivial &Other) {
+a = G + 10 + Other.a;
+  }
+};
+
+// Make sure noalias is not added to indirect arguments that are not trivially
+// copyable even if -fpass-by-value-is-noalias is provided.
+
+// WITH_NOALIAS: define void @_Z4take10NonTrivial(%struct.NonTrivial* %arg)
+// NO_NOALIAS:   define void @_Z4take10NonTrivial(%struct.NonTrivial* %arg)
+void take(NonTrivial arg) {}
+
+// Escape examples. Pointers to the objects passed to take() may escape, depending on whether a temporary copy is created or not (e.g. due to NRVO).
+struct A {
+  A(A **where) : data{"hello world 1"} {
+*where = this; //Escaped pointer 1 (proposed UB?)
+  }
+
+  A() : data{"hello world 2"} {}
+
+  char data[32];
+};
+A *p;
+
+void take(A a);
+
+A CreateA(A **where) {
+  A justlikethis;
+  *where = &justlikethis; //Escaped pointer 2 (should also be UB, then)
+  return justlikethis;
+}
+
+// elsewhere, perhaps compiled by a smarter compiler that doesn't make a copy here
+void test() {
+  take({&p});// 1
+  take(CreateA(&p)); // 2
+}
Index: clang/test/CodeGen/pass-by-value-noalias.c
===
--- /dev/null
+++ clang/test/CodeGen/pass-by-value-noalias.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fpass-by-value-is-noalias -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=WITH_NOALIAS %s
+// RUN: %clang_cc1 -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=NO_NOALIAS %s
+
+// A struct large enough so it is not passed in registers on ARM64.
+struct Foo {
+  int a;
+  int b;
+  int c;
+  int d;
+  int e;
+  int f;
+};
+
+// WITH_NOALIAS: define void @take(%struct.Foo* noalias %arg)
+// NO_NOALIAS: define void @take(%struct.Foo* %arg)
+void take(struct Foo arg) {}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===

[PATCH] D85473: [Clang] Add option to allow marking pass-by-value args as noalias.

2020-09-11 Thread Florian Hahn via Phabricator via cfe-commits
fhahn marked an inline comment as done.
fhahn added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:2198
+// reference to the underlying object. Mark it accordingly.
+Attrs.addAttribute(llvm::Attribute::NoAlias);
+

rjmccall wrote:
> fhahn wrote:
> > rjmccall wrote:
> > > This definitely can't be added unconditionally to all types; you need to 
> > > rule out non-trivial C++ class types, as well as types with ObjC weak 
> > > references.
> > Updated to rule out non trivially-copyable types.
> > 
> > I am not sure how to best handle types with weak references. I did not 
> > manage to find any helpers that traverse a whole type to check if it 
> > contains weak references. 
> > 
> > I added `clang/test/CodeGenObjC/pass-by-value-noalias.m` and IIUC `noalias` 
> > should not be added for that case.
> The restriction should not be by triviality but by whether indirectness is 
> forced semantically.  That may currently only be available on RecordDecl (as 
> `RecordDecl::getArgPassingRestrictions`), but you could definitely add an 
> accessor to `Type` which checked for a RecordType and otherwise returned that 
> there are no passing constraints.  Tagging Akira, who worked on this.
Thanks John, that does indeed exactly what we need I think. I updated the code 
to use `getAsRecordDecl` here. I can also add a helper to Type if it is useful 
beyond here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85473/new/

https://reviews.llvm.org/D85473

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1c08da3 - [analyzer][MacroExpansion] Add a few dumps functions

2020-09-11 Thread Kristóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-09-11T13:29:14+02:00
New Revision: 1c08da38676d15600b5c707cf7522eb4273a5347

URL: 
https://github.com/llvm/llvm-project/commit/1c08da38676d15600b5c707cf7522eb4273a5347
DIFF: 
https://github.com/llvm/llvm-project/commit/1c08da38676d15600b5c707cf7522eb4273a5347.diff

LOG: [analyzer][MacroExpansion] Add a few dumps functions

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index ed62778623a8..c4b66da676aa 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -825,13 +825,31 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
 
 namespace {
 
-using ExpArgTokens = llvm::SmallVector;
+using ExpArgTokensTy = llvm::SmallVector;
 
+} // end of anonymous namespace
+
+LLVM_DUMP_METHOD static void
+dumpExpArgTokensToStream(llvm::raw_ostream &Out, const Preprocessor &PP,
+ const ExpArgTokensTy &Toks);
+
+LLVM_DUMP_METHOD static void dumpExpArgTokens(const Preprocessor &PP,
+  const ExpArgTokensTy &Toks) {
+  dumpExpArgTokensToStream(llvm::errs(), PP, Toks);
+}
+
+namespace {
 /// Maps unexpanded macro arguments to expanded arguments. A macro argument may
 /// need to expanded further when it is nested inside another macro.
-class MacroArgMap : public std::map {
+class MacroArgMap : public std::map {
 public:
   void expandFromPrevMacro(const MacroArgMap &Super);
+  LLVM_DUMP_METHOD void dump(const Preprocessor &PP) const {
+dumpToStream(llvm::errs(), PP);
+  }
+
+  LLVM_DUMP_METHOD void dumpToStream(llvm::raw_ostream &Out,
+ const Preprocessor &PP) const;
 };
 
 struct MacroNameAndArgs {
@@ -1225,7 +1243,7 @@ static const MacroInfo *getMacroInfoForLocation(const 
Preprocessor &PP,
 void MacroArgMap::expandFromPrevMacro(const MacroArgMap &Super) {
 
   for (value_type &Pair : *this) {
-ExpArgTokens &CurrExpArgTokens = Pair.second;
+ExpArgTokensTy &CurrExpArgTokens = Pair.second;
 
 // For each token in the expanded macro argument.
 auto It = CurrExpArgTokens.begin();
@@ -1244,7 +1262,7 @@ void MacroArgMap::expandFromPrevMacro(const MacroArgMap 
&Super) {
 continue;
   }
 
-  const ExpArgTokens &SuperExpArgTokens = Super.at(II);
+  const ExpArgTokensTy &SuperExpArgTokens = Super.at(II);
 
   It = CurrExpArgTokens.insert(
   It, SuperExpArgTokens.begin(), SuperExpArgTokens.end());
@@ -1254,6 +1272,23 @@ void MacroArgMap::expandFromPrevMacro(const MacroArgMap 
&Super) {
   }
 }
 
+void MacroArgMap::dumpToStream(llvm::raw_ostream &Out,
+   const Preprocessor &PP) const {
+  for (const std::pair Pair : *this) {
+Out << Pair.first->getName() << " -> ";
+dumpExpArgTokensToStream(Out, PP, Pair.second);
+Out << '\n';
+  }
+}
+
+static void dumpExpArgTokensToStream(llvm::raw_ostream &Out,
+ const Preprocessor &PP,
+ const ExpArgTokensTy &Toks) {
+  TokenPrinter Printer(Out, PP);
+  for (Token Tok : Toks)
+Printer.printToken(Tok);
+}
+
 void TokenPrinter::printToken(const Token &Tok) {
   // If this is the first token to be printed, don't print space.
   if (PrevTok.isNot(tok::unknown)) {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85473: [Clang] Add option to allow marking pass-by-value args as noalias.

2020-09-11 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 291183.
fhahn marked an inline comment as done.
fhahn added a comment.

Add check lines for escape examples. Note that for return-by-value we already 
add noalias to the pointer unconditionally.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85473/new/

https://reviews.llvm.org/D85473

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/pass-by-value-noalias.c
  clang/test/CodeGenCXX/pass-by-value-noalias.cpp
  clang/test/CodeGenObjC/pass-by-value-noalias.m

Index: clang/test/CodeGenObjC/pass-by-value-noalias.m
===
--- /dev/null
+++ clang/test/CodeGenObjC/pass-by-value-noalias.m
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fpass-by-value-is-noalias -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns -fobjc-runtime-has-weak -fobjc-arc -fobjc-dispatch-method=mixed %s -o - 2>&1 | FileCheck --check-prefix=WITH_NOALIAS %s
+// RUN: %clang_cc1 -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns -fobjc-runtime-has-weak -fobjc-arc -fobjc-dispatch-method=mixed %s -o - 2>&1 | FileCheck --check-prefix=NO_NOALIAS %s
+
+@interface Bar
+@property char value;
+@end
+
+// A struct large enough so it is not passed in registers on ARM64, but with a
+// weak reference, so noalias should not be added even with
+// -fpass-by-value-is-noalias.
+struct Foo {
+  int a;
+  int b;
+  int c;
+  int d;
+  int e;
+  Bar *__weak f;
+};
+
+// WITH_NOALIAS: define void @take(%struct.Foo* %arg)
+// NO_NOALIAS: define void @take(%struct.Foo* %arg)
+void take(struct Foo arg) {}
Index: clang/test/CodeGenCXX/pass-by-value-noalias.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/pass-by-value-noalias.cpp
@@ -0,0 +1,73 @@
+// RUN: %clang_cc1 -fpass-by-value-is-noalias -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=WITH_NOALIAS %s
+// RUN: %clang_cc1 -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=NO_NOALIAS %s
+
+// A trivial struct large enough so it is not passed in registers on ARM64.
+struct Foo {
+  int a;
+  int b;
+  int c;
+  int d;
+  int e;
+  int f;
+};
+
+// Make sure noalias is added to indirect arguments with trivially copyable types
+// if -fpass-by-value-is-noalias is provided.
+
+// WITH_NOALIAS: define void @_Z4take3Foo(%struct.Foo* noalias %arg)
+// NO_NOALIAS: define void @_Z4take3Foo(%struct.Foo* %arg)
+void take(Foo arg) {}
+
+int G;
+
+// NonTrivial is not trivially-copyable, because it has a non-trivial copy
+// constructor.
+struct NonTrivial {
+  int a;
+  int b;
+  int c;
+  int d;
+  int e;
+  int f;
+
+  NonTrivial(const NonTrivial &Other) {
+a = G + 10 + Other.a;
+  }
+};
+
+// Make sure noalias is not added to indirect arguments that are not trivially
+// copyable even if -fpass-by-value-is-noalias is provided.
+
+// WITH_NOALIAS: define void @_Z4take10NonTrivial(%struct.NonTrivial* %arg)
+// NO_NOALIAS:   define void @_Z4take10NonTrivial(%struct.NonTrivial* %arg)
+void take(NonTrivial arg) {}
+
+// Escape examples. Pointers to the objects passed to take() may escape, depending on whether a temporary copy is created or not (e.g. due to NRVO).
+struct A {
+  A(A **where) : data{"hello world 1"} {
+*where = this; //Escaped pointer 1 (proposed UB?)
+  }
+
+  A() : data{"hello world 2"} {}
+
+  char data[32];
+};
+A *p;
+
+// WITH_NOALIAS: define void @_Z4take1A(%struct.A* noalias %arg)
+// NO_NOALIAS: define void @_Z4take1A(%struct.A* %arg)
+void take(A arg) {}
+
+// WITH_NOALIAS: define void @_Z7CreateAPP1A(%struct.A* noalias sret align 1 %agg.result, %struct.A** %where)
+// NO_NOALIAS: define void @_Z7CreateAPP1A(%struct.A* noalias sret align 1 %agg.result, %struct.A** %where)
+A CreateA(A **where) {
+  A justlikethis;
+  *where = &justlikethis; //Escaped pointer 2 (should also be UB, then)
+  return justlikethis;
+}
+
+// elsewhere, perhaps compiled by a smarter compiler that doesn't make a copy here
+void test() {
+  take({&p});// 1
+  take(CreateA(&p)); // 2
+}
Index: clang/test/CodeGen/pass-by-value-noalias.c
===
--- /dev/null
+++ clang/test/CodeGen/pass-by-value-noalias.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fpass-by-value-is-noalias -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=WITH_NOALIAS %s
+// RUN: %clang_cc1 -triple arm64-apple-iphoneos -emit-llvm -disable-llvm-optzns %s -o - 2>&1 | FileCheck --check-prefix=NO_NOALIAS %s
+
+// A struct large enough so it is not passed in registers on ARM64.
+struct Foo {
+  int a;
+  int b;
+  int c;
+  int d;
+  int e;
+  int f;
+};
+
+// WITH_NOALIAS: define void @take(%struct.F

[clang] 26d9a94 - [analyzer][MacroExpansion][NFC] Fix incorrectly calling parameters arguments

2020-09-11 Thread Kristóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-09-11T13:33:02+02:00
New Revision: 26d9a94681056f88bd3e892f8113093268fa0907

URL: 
https://github.com/llvm/llvm-project/commit/26d9a94681056f88bd3e892f8113093268fa0907
DIFF: 
https://github.com/llvm/llvm-project/commit/26d9a94681056f88bd3e892f8113093268fa0907.diff

LOG: [analyzer][MacroExpansion][NFC] Fix incorrectly calling parameters 
arguments

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
index c4b66da676aa..87c9b8479463 100644
--- a/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PlistDiagnostics.cpp
@@ -825,25 +825,26 @@ void PlistDiagnostics::FlushDiagnosticsImpl(
 
 namespace {
 
-using ExpArgTokensTy = llvm::SmallVector;
+using ArgTokensTy = llvm::SmallVector;
 
 } // end of anonymous namespace
 
-LLVM_DUMP_METHOD static void
-dumpExpArgTokensToStream(llvm::raw_ostream &Out, const Preprocessor &PP,
- const ExpArgTokensTy &Toks);
+LLVM_DUMP_METHOD static void dumpArgTokensToStream(llvm::raw_ostream &Out,
+   const Preprocessor &PP,
+   const ArgTokensTy &Toks);
 
-LLVM_DUMP_METHOD static void dumpExpArgTokens(const Preprocessor &PP,
-  const ExpArgTokensTy &Toks) {
-  dumpExpArgTokensToStream(llvm::errs(), PP, Toks);
+LLVM_DUMP_METHOD static void dumpArgTokens(const Preprocessor &PP,
+   const ArgTokensTy &Toks) {
+  dumpArgTokensToStream(llvm::errs(), PP, Toks);
 }
 
 namespace {
-/// Maps unexpanded macro arguments to expanded arguments. A macro argument may
+/// Maps unexpanded macro parameters to expanded arguments. A macro argument 
may
 /// need to expanded further when it is nested inside another macro.
-class MacroArgMap : public std::map {
+class MacroParamMap : public std::map {
 public:
-  void expandFromPrevMacro(const MacroArgMap &Super);
+  void expandFromPrevMacro(const MacroParamMap &Super);
+
   LLVM_DUMP_METHOD void dump(const Preprocessor &PP) const {
 dumpToStream(llvm::errs(), PP);
   }
@@ -852,13 +853,13 @@ class MacroArgMap : public std::map {
  const Preprocessor &PP) const;
 };
 
-struct MacroNameAndArgs {
+struct MacroExpansionInfo {
   std::string Name;
   const MacroInfo *MI = nullptr;
-  MacroArgMap Args;
+  MacroParamMap ParamMap;
 
-  MacroNameAndArgs(std::string N, const MacroInfo *MI, MacroArgMap M)
-: Name(std::move(N)), MI(MI), Args(std::move(M)) {}
+  MacroExpansionInfo(std::string N, const MacroInfo *MI, MacroParamMap M)
+  : Name(std::move(N)), MI(MI), ParamMap(std::move(M)) {}
 };
 
 class TokenPrinter {
@@ -896,7 +897,7 @@ class TokenPrinter {
 ///
 /// As we expand the last line, we'll immediately replace PRINT(str) with
 /// print(x). The information that both 'str' and 'x' refers to the same string
-/// is an information we have to forward, hence the argument \p PrevArgs.
+/// is an information we have to forward, hence the argument \p PrevParamMap.
 ///
 /// To avoid infinite recursion we maintain the already processed tokens in
 /// a set. This is carried as a parameter through the recursive calls. The set
@@ -906,13 +907,11 @@ class TokenPrinter {
 /// #define f(y) x
 /// #define x f(x)
 static std::string getMacroNameAndPrintExpansion(
-TokenPrinter &Printer,
-SourceLocation MacroLoc,
-const Preprocessor &PP,
-const MacroArgMap &PrevArgs,
+TokenPrinter &Printer, SourceLocation MacroLoc, const Preprocessor &PP,
+const MacroParamMap &PrevParamMap,
 llvm::SmallPtrSet &AlreadyProcessedTokens);
 
-/// Retrieves the name of the macro and what it's arguments expand into
+/// Retrieves the name of the macro and what it's parameters expand into
 /// at \p ExpanLoc.
 ///
 /// For example, for the following macro expansion:
@@ -934,8 +933,8 @@ static std::string getMacroNameAndPrintExpansion(
 /// When \p ExpanLoc references "SET_TO_NULL(a)" within the definition of
 /// "NOT_SUSPICOUS", the macro name "SET_TO_NULL" and the MacroArgMap map
 /// { (x, a) } will be returned.
-static MacroNameAndArgs getMacroNameAndArgs(SourceLocation ExpanLoc,
-const Preprocessor &PP);
+static MacroExpansionInfo getMacroExpansionInfo(SourceLocation ExpanLoc,
+const Preprocessor &PP);
 
 /// Retrieves the ')' token that matches '(' \p It points to.
 static MacroInfo::tokens_iterator getMatchingRParen(
@@ -969,21 +968,20 @@ getExpandedMacro(SourceLocation MacroLoc, const 
Preprocessor &PP,
   llvm::SmallPtrSet AlreadyProcessedTokens;
 
   std::string MacroName = getMacroNameAndPrintExpansion(
-  

[PATCH] D86796: [Sema] Address-space sensitive index check for unbounded arrays

2020-09-11 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx updated this revision to Diff 291184.
chrish_ericsson_atx added a comment.

Addressed feedback from Aaron Ballman


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86796/new/

https://reviews.llvm.org/D86796

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/const-eval.c
  clang/test/Sema/unbounded-array-bounds.c
  clang/test/SemaCXX/constant-expression-cxx1y.cpp

Index: clang/test/SemaCXX/constant-expression-cxx1y.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx1y.cpp
+++ clang/test/SemaCXX/constant-expression-cxx1y.cpp
@@ -1018,8 +1018,9 @@
 }
 
 constexpr void PR28739(int n) { // expected-error {{never produces a constant}}
-  int *p = &n;
+  int *p = &n;  // expected-note {{declared here}}
   p += (__int128)(unsigned long)-1; // expected-note {{cannot refer to element 18446744073709551615 of non-array object in a constant expression}}
+  // expected-warning@-1 {{the pointer incremented by 18446744073709551615 refers past the last possible element for an array in 64-bit address space containing 32-bit (4-byte) elements (max possible 4611686018427387904 elements)}}
 }
 
 constexpr void Void(int n) {
Index: clang/test/Sema/unbounded-array-bounds.c
===
--- /dev/null
+++ clang/test/Sema/unbounded-array-bounds.c
@@ -0,0 +1,70 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-X86-ADDR64 %s  \
+// RUN:  --implicit-check-not 'past the last possible element'
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu   -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-I386-ADDR32 %s \
+// RUN:  --implicit-check-not 'past the last possible element'
+// RUN: %clang_cc1 -triple avr-pc-linux-gnu-fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-AVR-ADDR16 %s  \
+// RUN:  --implicit-check-not 'past the last possible element'
+
+struct S {
+  long long a;
+  char b;
+  long long c;
+  short d;
+};
+
+struct S s[];
+
+void f1() {
+  ++s[3].a;
+  ++s[7073650413200313099].b;
+  // CHECK-X86-ADDR64:  :[[@LINE-1]]:5: warning: array index 7073650413200313099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements)
+  // CHECK-I386-ADDR32: :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 178956970 elements)
+  // CHECK-AVR-ADDR16:  :[[@LINE-3]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 3276 elements)
+  ++s[7073650].c;
+  // CHECK-AVR-ADDR16:  :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 3276 elements)
+}
+
+long long ll[];
+
+void f2() {
+  ++ll[3];
+  ++ll[2705843009213693952];
+  // CHECK-X86-ADDR64:  :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 64-bit {{.*}} (max possible 2305843009213693952 elements)
+  // CHECK-I386-ADDR32: :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 536870912 elements)
+  // CHECK-AVR-ADDR16:  :[[@LINE-3]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 8192 elements)
+  ++ll[847073650];
+  // CHECK-I386-ADDR32: :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 536870912 elements)
+  // CHECK-AVR-ADDR16:  :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 8192 elements)
+}
+
+void f3(struct S p[]) {
+  ++p[3].a;
+  ++p[7073650413200313099].b;
+  // CHECK-X86-ADDR64:  :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 64-bit {{.*}} (max possible 576460752303423488 elements)
+  // CHECK-I386-ADDR32: :[[@LINE-2]]:5: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 178956970 elements)
+  // CHECK-AVR-ADDR16:  :[[@LINE-3]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 3276 elements)
+  ++p[7073650].c;
+  // CHECK-AVR-ADDR16:  :[[@LINE-1]]:5: warning: {{.*}} past the last possible element {{.*}} in 16-bit {{.*}} (max possible 3276 elements)
+}
+
+void f4(struct S *p) {
+  p += 3;
+  p += 7073650413200313099;
+  // CHECK-X86-ADDR64:  :[[@LINE-1]]:3: warning: the pointer incremented by 7073650413200313099 refers past the last possible element for an array in 64-bit address space containing 256-bit (32-byte) elements (max possible 576460752303423488 elements)
+  // CHECK-I386-ADDR32: :[[@LINE-2]]:3: warning: {{.*}} past the last possible element {{.*}} in 32-bit {{.*}} (max possible 178956970 elements)
+  // CHECK-AVR-ADDR16:  :[[@LINE-3]]:3: warning: {{.*}} past the last possible el

[PATCH] D86089: [flang][driver]Add experimental flang driver and frontend with help screen

2020-09-11 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

We forgot to update the signature and definition of `OptTable::findByPrefix`: 
https://github.com/llvm/llvm-project/blob/257b29715bb27b7d9f6c3c40c481b6a4af0b37e5/llvm/include/llvm/Option/OptTable.h#L154-L155.
 That's required after updating the definition of `OptTable::Flags`. Not sure 
none of the compilers complained.

Fixed here: 
https://github.com/llvm/llvm-project/commit/4eed800b18abaeba3082bf950fbe5c3020c4b592


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86089/new/

https://reviews.llvm.org/D86089

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86796: [Sema] Address-space sensitive index check for unbounded arrays

2020-09-11 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx marked 11 inline comments as done.
chrish_ericsson_atx added a comment.

Addressed all feedback from Aaron, except for two comments about reachability 
that I don't understand.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86796/new/

https://reviews.llvm.org/D86796

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7527898 - [analyzer][MacroExpansion][NFC] Fix a missing test output check

2020-09-11 Thread Kristóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-09-11T13:48:26+02:00
New Revision: 7527898fef47da929e70c81100a0248c2f445762

URL: 
https://github.com/llvm/llvm-project/commit/7527898fef47da929e70c81100a0248c2f445762
DIFF: 
https://github.com/llvm/llvm-project/commit/7527898fef47da929e70c81100a0248c2f445762.diff

LOG: [analyzer][MacroExpansion][NFC] Fix a missing test output check

Added: 


Modified: 

clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
clang/test/Analysis/plist-macros-with-expansion.cpp

Removed: 




diff  --git 
a/clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
 
b/clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
index 2988f8504fcf..499119c81d25 100644
--- 
a/clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
+++ 
b/clang/test/Analysis/Inputs/expected-plists/plist-macros-with-expansion.cpp.plist
@@ -5645,12 +5645,12 @@
 start
  
   
-   line459
+   line462
col33
file0
   
   
-   line459
+   line462
col33
file0
   
@@ -5658,12 +5658,12 @@
 end
  
   
-   line459
+   line462
col37
file0
   
   
-   line459
+   line462
col39
file0
   
@@ -5675,7 +5675,7 @@
  kindevent
  location
  
-  line459
+  line462
   col37
   file0
  
@@ -5683,12 +5683,12 @@
  

 
- line459
+ line462
  col37
  file0
 
 
- line459
+ line462
  col41
  file0
 
@@ -5704,7 +5704,7 @@
  kindevent
  location
  
-  line458
+  line461
   col1
   file0
  
@@ -5718,7 +5718,7 @@
  kindevent
  location
  
-  line458
+  line461
   col1
   file0
  
@@ -5726,12 +5726,12 @@
  

 
- line458
+ line461
  col1
  file0
 
 
- line458
+ line461
  col16
  file0
 
@@ -5747,7 +5747,7 @@
  kindevent
  location
  
-  line459
+  line462
   col37
   file0
  
@@ -5755,12 +5755,12 @@
  

 
- line459
+ line462
  col37
  file0
 
 
- line459
+ line462
  col41
  file0
 
@@ -5780,12 +5780,12 @@
 start
  
   
-   line459
+   line462
col37
file0
   
   
-   line459
+   line462
col39
file0
   
@@ -5793,12 +5793,12 @@
 end
  
   
-   line459
+   line462
col35
file0
   
   
-   line459
+   line462
col35
file0
   
@@ -5810,7 +5810,7 @@
  kindevent
  location
  
-  line459
+  line462
   col35
   file0
  
@@ -5818,12 +5818,12 @@
  

 
- line459
+ line462
  col33
  file0
 
 
- line459
+ line462
  col41
  file0
 
@@ -5841,7 +5841,7 @@
 
  location
  
-  line458
+  line461
   col1
   file0
  
@@ -5860,7 +5860,7 @@
   issue_hash_function_offset0
   location
   
-   line459
+   line462
col35
file0
   
@@ -5868,8 +5868,8 @@
   
0

-458
-459
+461
+462

   
   
@@ -5884,12 +5884,12 @@
 start
  
   
-   line468
+   line471
col33
file0
   
   
-   line468
+   line471
col33
file0
   
@@ -5897,12 +5897,12 @@
 end
  
   
-   line468
+   line471
col37
file0
   
   
-   line468
+   line471
col39
file0
   
@@ -5914,7 +5914,7 @@
  kindevent
  location
  
-  line468
+  line471
   col37
   file0
  
@@ -5922,12 +5922,12 @@
  

 
- line468
+ line471
  col37
  file0
 
 
- line468
+ line471
  col41
  file0
 
@@ -5943,7 +5943,7 @@
  kindevent
  location
  
-  line467
+  line470
   col1
   file0
  
@@ -5957,7 +5957,7 @@
  kindevent
  location
  
-  line467
+  line470
   col1
   file0
  
@@ -5965,12 +5965,12 @@
  

 
- line467
+ line470
  co

[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 291190.
eduucaldas marked 5 inline comments as done.
eduucaldas added a comment.

Answer inline comments


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87495/new/

https://reviews.llvm.org/D87495

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -12,33 +12,81 @@
 
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "gtest/gtest.h"
 
 using namespace clang;
 using namespace clang::syntax;
 
 namespace {
 
-INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, SyntaxTreeTest,
+class SynthesisTest : public SyntaxTreeTest {
+protected:
+  ::testing::AssertionResult treeDumpEqual(syntax::Node *Root, StringRef Dump) {
+if (!Root)
+  return ::testing::AssertionFailure()
+ << "Root was not built successfully.";
+
+auto Actual = StringRef(Root->dump(Arena->sourceManager())).trim().str();
+auto Expected = Dump.trim().str();
+// EXPECT_EQ shows the diff between the two strings if they are different.
+EXPECT_EQ(Expected, Actual);
+if (Actual != Expected) {
+  return ::testing::AssertionFailure();
+}
+return ::testing::AssertionSuccess();
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(SynthesisTests, SynthesisTest,
 ::testing::ValuesIn(allTestClangConfigs()), );
 
-TEST_P(SyntaxTreeTest, Leaf_Punctuation) {
+TEST_P(SynthesisTest, Leaf_Punctuation) {
+  buildTree("", GetParam());
+
+  auto *C = createPunctuation(*Arena, tok::comma);
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+',' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Keyword) {
+  buildTree("", GetParam());
+
+  auto *C = createKeyword(*Arena, tok::kw_if);
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'if' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Identifier) {
   buildTree("", GetParam());
 
-  auto *C = syntax::createPunctuation(*Arena, tok::comma);
-  ASSERT_NE(C, nullptr);
-  EXPECT_EQ(C->token()->kind(), tok::comma);
-  EXPECT_TRUE(C->canModify());
-  EXPECT_FALSE(C->isOriginal());
-  EXPECT_TRUE(C->isDetached());
+  auto *C = createLeaf(*Arena, tok::identifier, "a");
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'a' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Number) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::numeric_constant, "1");
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'1' Detached synthesized
+  )txt"));
 }
 
-TEST_P(SyntaxTreeTest, Statement_Empty) {
+TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
-  auto *S = syntax::createEmptyStatement(*Arena);
-  ASSERT_NE(S, nullptr);
-  EXPECT_TRUE(S->canModify());
-  EXPECT_FALSE(S->isOriginal());
-  EXPECT_TRUE(S->isDetached());
+  auto *S = createEmptyStatement(*Arena);
+  EXPECT_TRUE(treeDumpEqual(S, R"txt(
+EmptyStatement Detached synthesized
+`-';' synthesized
+  )txt"));
 }
 } // namespace
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -5,6 +5,7 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===--===//
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
 
 using namespace clang;
@@ -21,24 +22,38 @@
   }
 };
 
-clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
-   clang::tok::TokenKind K) {
-  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
-clang::tok::getPunctuatorSpelling(K)))
-.second;
+namespace {
+syntax::Leaf *createLeafLowLevel(syntax::Arena &A, StringRef Spelling) {
+  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(Spelling)).second;
   assert(Tokens.size() == 1);
-  assert(Tokens.front().kind() == K);
-  auto *L = new (A.allocator()) clang::syntax::Leaf(Tokens.begin());
-  FactoryImpl::setCanModify(L);
+  auto *L = new (A.allocator()) syntax::Leaf(Tokens.begin());
+  clang::syntax::FactoryImpl::setCanModify(L);
   L->assertInvariants();
   return L;
 }
+} // namespace
 
-clang::syntax::EmptyStatement *
-syntax::createEmptyStatement(clang::syntax::Arena &A) {
-  auto *S = new (A.allocator()) clang::syntax::EmptyStatement;
+syntax::Leaf *clang::syntax::createLeaf(syntax::Arena &A, tok::TokenKind K,
+StringRef Spelling) {
+  auto *Leaf = createLeafLowLevel(A, Spelling);
+  assert(Leaf->token()->kind() == K &&
+ "spelling is not 

[PATCH] D87409: [libTooling] Fix use of `char` in comparison.

2020-09-11 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa5cefd95cc60: [libTooling] Fix use of `char` in comparison. 
(authored by ymandel).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87409/new/

https://reviews.llvm.org/D87409

Files:
  clang/lib/Tooling/Transformer/Parsing.cpp


Index: clang/lib/Tooling/Transformer/Parsing.cpp
===
--- clang/lib/Tooling/Transformer/Parsing.cpp
+++ clang/lib/Tooling/Transformer/Parsing.cpp
@@ -148,7 +148,7 @@
 }
 
 static StringRef consumeWhitespace(StringRef S) {
-  return S.drop_while([](char c) { return c >= 0 && isWhitespace(c); });
+  return S.drop_while([](char c) { return isASCII(c) && isWhitespace(c); });
 }
 
 // Parses a single expected character \c c from \c State, skipping preceding
@@ -165,7 +165,7 @@
 static ExpectedProgress parseId(ParseState State) {
   State.Input = consumeWhitespace(State.Input);
   auto Id = State.Input.take_while(
-  [](char c) { return c >= 0 && isIdentifierBody(c); });
+  [](char c) { return isASCII(c) && isIdentifierBody(c); });
   if (Id.empty())
 return makeParseError(State, "failed to parse name");
   return makeParseProgress(advance(State, Id.size()), Id.str());


Index: clang/lib/Tooling/Transformer/Parsing.cpp
===
--- clang/lib/Tooling/Transformer/Parsing.cpp
+++ clang/lib/Tooling/Transformer/Parsing.cpp
@@ -148,7 +148,7 @@
 }
 
 static StringRef consumeWhitespace(StringRef S) {
-  return S.drop_while([](char c) { return c >= 0 && isWhitespace(c); });
+  return S.drop_while([](char c) { return isASCII(c) && isWhitespace(c); });
 }
 
 // Parses a single expected character \c c from \c State, skipping preceding
@@ -165,7 +165,7 @@
 static ExpectedProgress parseId(ParseState State) {
   State.Input = consumeWhitespace(State.Input);
   auto Id = State.Input.take_while(
-  [](char c) { return c >= 0 && isIdentifierBody(c); });
+  [](char c) { return isASCII(c) && isIdentifierBody(c); });
   if (Id.empty())
 return makeParseError(State, "failed to parse name");
   return makeParseProgress(advance(State, Id.size()), Id.str());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] a5cefd9 - [libTooling] Fix use of `char` in comparison.

2020-09-11 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2020-09-11T12:24:09Z
New Revision: a5cefd95cc60318fbf8610ee782bd22b492692a2

URL: 
https://github.com/llvm/llvm-project/commit/a5cefd95cc60318fbf8610ee782bd22b492692a2
DIFF: 
https://github.com/llvm/llvm-project/commit/a5cefd95cc60318fbf8610ee782bd22b492692a2.diff

LOG: [libTooling] Fix use of `char` in comparison.

Fixes Transformer's `Range` parser to handle `char` in a platform-independent 
way.

Differential Revision: https://reviews.llvm.org/D87409

Added: 


Modified: 
clang/lib/Tooling/Transformer/Parsing.cpp

Removed: 




diff  --git a/clang/lib/Tooling/Transformer/Parsing.cpp 
b/clang/lib/Tooling/Transformer/Parsing.cpp
index fb5fd4a800bb..66fa04a15594 100644
--- a/clang/lib/Tooling/Transformer/Parsing.cpp
+++ b/clang/lib/Tooling/Transformer/Parsing.cpp
@@ -148,7 +148,7 @@ static ParseState advance(ParseState S, size_t N) {
 }
 
 static StringRef consumeWhitespace(StringRef S) {
-  return S.drop_while([](char c) { return c >= 0 && isWhitespace(c); });
+  return S.drop_while([](char c) { return isASCII(c) && isWhitespace(c); });
 }
 
 // Parses a single expected character \c c from \c State, skipping preceding
@@ -165,7 +165,7 @@ static ExpectedProgress parseChar(char c, 
ParseState State) {
 static ExpectedProgress parseId(ParseState State) {
   State.Input = consumeWhitespace(State.Input);
   auto Id = State.Input.take_while(
-  [](char c) { return c >= 0 && isIdentifierBody(c); });
+  [](char c) { return isASCII(c) && isIdentifierBody(c); });
   if (Id.empty())
 return makeParseError(State, "failed to parse name");
   return makeParseProgress(advance(State, Id.size()), Id.str());



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87463: [clang][aarch64] Fix mangling of bfloat16 neon vectors

2020-09-11 Thread Cullen Rhodes via Phabricator via cfe-commits
c-rhodes added a comment.

In D87463#2267613 , @stuij wrote:

> I'm not sure what the procedure is to get patches into LLVM 11, but I think 
> there's still time. Could you try to get this in there as well @c-rhodes ?

Cherry-picked into LLVM 11, see: https://bugs.llvm.org/show_bug.cgi?id=47490


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87463/new/

https://reviews.llvm.org/D87463

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:51
+  return createLeaf(A, tok::getKeywordSpelling(K), K);
+}
+

gribozavr2 wrote:
> Could we make a combined function that does not require the user to make a 
> distinction between punctuation and keywords?
> 
> We should also allow creating tokens that have a user-specified spelling, for 
> example, identifiers and string literals.
> 
> So maybe define two functions:
> 
> ```
> // Uses the provided spelling.
> syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K, StringRef 
> Spelling);
> 
> // Infers spelling if possible.
> syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K);
> ```
> 
First, thanks for the great comments!

> Could we make a combined function that does not require the user to make a 
> distinction between punctuation and keywords?
We could! 
Bui I wouldn't call it `createLeaf`, as it would work strictly for `Keyword`s 
or `Punctuator`s. 
As an alternative we could unify the `createPunctuator`and `createKeyword` into 
`createPunctuatorOrKeyword` but I would argue that the previous two names are 
more readable. Effectively, we would be unifying those 2 functions because they 
have the same signature.

> We should also allow creating tokens that have a user-specified spelling, for 
> example, identifiers and string literals.
That exists already! It is `createLeaf` as is!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87495/new/

https://reviews.llvm.org/D87495

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump

2020-09-11 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:51
+  return createLeaf(A, tok::getKeywordSpelling(K), K);
+}
+

eduucaldas wrote:
> gribozavr2 wrote:
> > Could we make a combined function that does not require the user to make a 
> > distinction between punctuation and keywords?
> > 
> > We should also allow creating tokens that have a user-specified spelling, 
> > for example, identifiers and string literals.
> > 
> > So maybe define two functions:
> > 
> > ```
> > // Uses the provided spelling.
> > syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K, StringRef 
> > Spelling);
> > 
> > // Infers spelling if possible.
> > syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K);
> > ```
> > 
> First, thanks for the great comments!
> 
> > Could we make a combined function that does not require the user to make a 
> > distinction between punctuation and keywords?
> We could! 
> Bui I wouldn't call it `createLeaf`, as it would work strictly for `Keyword`s 
> or `Punctuator`s. 
> As an alternative we could unify the `createPunctuator`and `createKeyword` 
> into `createPunctuatorOrKeyword` but I would argue that the previous two 
> names are more readable. Effectively, we would be unifying those 2 functions 
> because they have the same signature.
> 
> > We should also allow creating tokens that have a user-specified spelling, 
> > for example, identifiers and string literals.
> That exists already! It is `createLeaf` as is!
> but I would argue that the previous two names are more readable. Effectively, 
> we would be unifying those 2 functions because they have the same signature.

I don't think the user cares very much about whether their token is a keyword 
or a punctuation. Furthermore, most callsites will have the token kind as an 
argument, so saying that it is a keyword or punctuation is redundant:

```
createKeyword(Arena, tok::kw_if); // Yeah, 'if' is a keyword.
```

The semantics of the combined function I'm proposing is "create a token that 
has one fixed spelling". The other function is "create a token where the 
spelling is user-provided".


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87495/new/

https://reviews.llvm.org/D87495

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77491: [Sema] Introduce BuiltinAttr, per-declaration builtin-ness

2020-09-11 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77491/new/

https://reviews.llvm.org/D77491

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r364428 - Make CodeGen depend on ASTMatchers

2020-09-11 Thread Vassil Vassilev via cfe-commits

On 9/11/20 5:13 AM, Michael LIAO wrote:

That change was added long ago to fix the shared library build.
Possibly, there are changes removing that dependency then. Just
verified that removing that dependency is just fine.



  That's great! Would you commit that change or should I?




On Thu, Sep 10, 2020 at 6:48 AM Vassil Vassilev  wrote:

Hello,

IIUC, clang's CodeGen does not immediately depend on ASTMatchers. I
was wondering what is the reason for inserting such a dependency to fix
the shared library builds?

Can you give more details about the failure you are fixing?

Sorry for the late question.

Best, Vassil
On 6/26/19 5:13 PM, Michael Liao via cfe-commits wrote:

Author: hliao
Date: Wed Jun 26 07:13:43 2019
New Revision: 364428

URL: http://llvm.org/viewvc/llvm-project?rev=364428&view=rev
Log:
Make CodeGen depend on ASTMatchers

- Shared library builds are broken due to the missing dependency.

Modified:
  cfe/trunk/lib/CodeGen/CMakeLists.txt

Modified: cfe/trunk/lib/CodeGen/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CMakeLists.txt?rev=364428&r1=364427&r2=364428&view=diff
==
--- cfe/trunk/lib/CodeGen/CMakeLists.txt (original)
+++ cfe/trunk/lib/CodeGen/CMakeLists.txt Wed Jun 26 07:13:43 2019
@@ -101,6 +101,7 @@ add_clang_library(clangCodeGen
 LINK_LIBS
 clangAnalysis
 clangAST
+  clangASTMatchers
 clangBasic
 clangFrontend
 clangLex


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits




___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86736: [analyzer][NFC] Don't bind values to ObjCForCollectionStmt, replace it with a GDM trait

2020-09-11 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 291199.
Szelethus marked 4 inline comments as done.
Szelethus added a comment.

Reinstate the assert removed in rG032b78a0762bee129f33e4255ada6d374aa70c71 
, add a 
test. Enforce that `Environment` only makes an exception for `ReturnStmt` in 
terms of non-expression statements (and hope that isn't going to stay that way 
for long).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86736/new/

https://reviews.llvm.org/D86736

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
  clang/lib/StaticAnalyzer/Core/Environment.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/objc-live-crash.mm

Index: clang/test/Analysis/objc-live-crash.mm
===
--- /dev/null
+++ clang/test/Analysis/objc-live-crash.mm
@@ -0,0 +1,30 @@
+// RUN: %clang --analyze %s -fblocks
+
+// https://reviews.llvm.org/D82598#2171312
+
+@interface Item
+// ...
+@end
+
+@interface Collection
+// ...
+@end
+
+typedef void (^Blk)();
+
+struct RAII {
+  Blk blk;
+
+public:
+  RAII(Blk blk): blk(blk) {}
+  ~RAII() { blk(); }
+};
+
+void foo(Collection *coll) {
+  RAII raii(^{});
+  for (Item *item in coll) {}
+  int i;
+  {
+int j;
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
@@ -14,6 +14,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/StmtObjC.h"
 #include "clang/Analysis/Analyses/LiveVariables.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Basic/LLVM.h"
@@ -494,7 +495,8 @@
 return true;
   }
 
-  // If no statement is provided, everything is this and parent contexts is live.
+  // If no statement is provided, everything in this and parent contexts is
+  // live.
   if (!Loc)
 return true;
 
Index: clang/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
@@ -53,10 +53,8 @@
 ProgramStateRef state = Pred->getState();
 const LocationContext *LCtx = Pred->getLocationContext();
 
-SVal hasElementsV = svalBuilder.makeTruthVal(hasElements);
-
-// FIXME: S is not an expression. We should not be binding values to it.
-ProgramStateRef nextState = state->BindExpr(S, LCtx, hasElementsV);
+ProgramStateRef nextState =
+ExprEngine::setWhetherHasMoreIteration(state, S, LCtx, hasElements);
 
 if (auto MV = elementV.getAs())
   if (const auto *R = dyn_cast(MV->getRegion())) {
@@ -93,10 +91,9 @@
   //  (1) binds the next container value to 'element'.  This creates a new
   //  node in the ExplodedGraph.
   //
-  //  (2) binds the value 0/1 to the ObjCForCollectionStmt* itself, indicating
-  //  whether or not the container has any more elements.  This value
-  //  will be tested in ProcessBranch.  We need to explicitly bind
-  //  this value because a container can contain nil elements.
+  //  (2) note whether the collection has any more elements (or in other words,
+  //  whether the loop has more iterations). This will be tested in
+  //  processBranch.
   //
   // FIXME: Eventually this logic should actually do dispatches to
   //   'countByEnumeratingWithState:objects:count:' (NSFastEnumeration).
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2129,6 +2129,83 @@
   llvm_unreachable("could not resolve condition");
 }
 
+using ObjCForLctxPair =
+std::pair;
+
+REGISTER_MAP_WITH_PROGRAMSTATE(ObjCForHasMoreIterations, ObjCForLctxPair, bool)
+
+ProgramStateRef ExprEngine::setWhetherHasMoreIteration(
+ProgramStateRef State, const ObjCForCollectionStmt *O,
+const LocationContext *LC, bool HasMoreIteraton) {
+  assert(!State->contains({O, LC}));
+  return State->set({O, LC}, HasMoreIteraton);
+}
+
+ProgramStateRef
+ExprEngine::removeIterationState(ProgramStateRef State,
+ const ObjCForCollectionStmt *O,
+ const LocationContext *LC) {
+  assert(State->contains({O, LC}));
+  return State->remove({O, LC});
+}
+
+bool ExprEngine::hasMoreIteration(ProgramStateRef State,
+  const ObjCForCollectionStmt *O,
+  

[PATCH] D86632: [Fixed Point] Add codegen for conversion between fixed-point and floating point.

2020-09-11 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 291203.
ebevhan added a comment.

Using Type::getFloatingPointTy now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86632/new/

https://reviews.llvm.org/D86632

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Frontend/fixed_point_compound.c
  clang/test/Frontend/fixed_point_conversions.c
  clang/test/Frontend/fixed_point_conversions_half.c
  llvm/include/llvm/IR/FixedPointBuilder.h

Index: llvm/include/llvm/IR/FixedPointBuilder.h
===
--- llvm/include/llvm/IR/FixedPointBuilder.h
+++ llvm/include/llvm/IR/FixedPointBuilder.h
@@ -120,6 +120,16 @@
 C.isSigned(), C.isSaturated(), BothPadded);
   }
 
+  /// Given a floating point type and a fixed-point semantic, return a floating
+  /// point type which can accommodate the fixed-point semantic. This is either
+  /// \p Ty, or a floating point type with a larger exponent than Ty.
+  Type *getAccommodatingFloatType(Type *Ty, const FixedPointSemantics &Sema) {
+const fltSemantics *FloatSema = &Ty->getFltSemantics();
+while (!Sema.fitsInFloatSemantics(*FloatSema))
+  FloatSema = APFixedPoint::promoteFloatSemantics(FloatSema);
+return Type::getFloatingPointTy(Ty->getContext(), *FloatSema);
+  }
+
 public:
   FixedPointBuilder(IRBuilderTy &Builder) : B(Builder) {}
 
@@ -159,6 +169,55 @@
DstSema, false);
   }
 
+  Value *CreateFixedToFloating(Value *Src, const FixedPointSemantics &SrcSema,
+   Type *DstTy) {
+Value *Result;
+Type *OpTy = getAccommodatingFloatType(DstTy, SrcSema);
+// Convert the raw fixed-point value directly to floating point. If the
+// value is too large to fit, it will be rounded, not truncated.
+Result = SrcSema.isSigned() ? B.CreateSIToFP(Src, OpTy)
+: B.CreateUIToFP(Src, OpTy);
+// Rescale the integral-in-floating point by the scaling factor. This is
+// lossless, except for overflow to infinity which is unlikely.
+Result = B.CreateFMul(Result,
+ConstantFP::get(OpTy, std::pow(2, -(int)SrcSema.getScale(;
+if (OpTy != DstTy)
+  Result = B.CreateFPTrunc(Result, DstTy);
+return Result;
+  }
+
+  Value *CreateFloatingToFixed(Value *Src, const FixedPointSemantics &DstSema) {
+bool UseSigned = DstSema.isSigned() || DstSema.hasUnsignedPadding();
+Value *Result = Src;
+Type *OpTy = getAccommodatingFloatType(Src->getType(), DstSema);
+if (OpTy != Src->getType())
+  Result = B.CreateFPExt(Result, OpTy);
+// Rescale the floating point value so that its significant bits (for the
+// purposes of the conversion) are in the integral range.
+Result = B.CreateFMul(Result,
+ConstantFP::get(OpTy, std::pow(2, DstSema.getScale(;
+
+Type *ResultTy = B.getIntNTy(DstSema.getWidth());
+if (DstSema.isSaturated()) {
+  Intrinsic::ID IID =
+  UseSigned ? Intrinsic::fptosi_sat : Intrinsic::fptoui_sat;
+  Result = B.CreateIntrinsic(IID, {ResultTy, OpTy}, {Result});
+} else {
+  Result = UseSigned ? B.CreateFPToSI(Result, ResultTy)
+ : B.CreateFPToUI(Result, ResultTy);
+}
+
+// When saturating unsigned-with-padding using signed operations, we may
+// get negative values. Emit an extra clamp to zero.
+if (DstSema.isSaturated() && DstSema.hasUnsignedPadding()) {
+  Constant *Zero = Constant::getNullValue(Result->getType());
+  Result =
+  B.CreateSelect(B.CreateICmpSLT(Result, Zero), Zero, Result, "satmin");
+}
+
+return Result;
+  }
+
   /// Add two fixed-point values and return the result in their common semantic.
   /// \p LHS - The left hand side
   /// \p LHSSema - The semantic of the left hand side
Index: clang/test/Frontend/fixed_point_conversions_half.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_conversions_half.c
@@ -0,0 +1,309 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -ffixed-point -triple arm64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -triple arm64-unknown-linux-gnu -S -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+short _Fract sf;
+long _Fract lf;
+
+short _Accum sa;
+long _Accum la;
+
+unsigned short _Accum usa;
+unsigned long _Accum ula;
+
+_Sat short _Fract sf_sat;
+_Sat long _Fract lf_sat;
+
+_Sat short _Accum sa_sat;
+_Sat long _Accum la_sat;
+
+_Sat unsigned short _Accum usa_sat;
+_Sat unsigned long _Accum ula_sat;
+
+_Float16 h;
+
+
+// CHECK-LABEL: @half_fix1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* @h, align 2
+// CHECK-NEXT:[[TMP1:%.*]] = fmul half [[TMP0]], 0xH5800
+// CHECK-NEXT:[[TMP2:%.*]] = f

[PATCH] D86632: [Fixed Point] Add codegen for conversion between fixed-point and floating point.

2020-09-11 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: llvm/include/llvm/IR/FixedPointBuilder.h:126
+  /// \p Ty, or a floating point type with a larger exponent than Ty.
+  Type *getAccommodatingFloatType(Type *Ty, const FixedPointSemantics &Sema) {
+const fltSemantics *FloatSema = &Ty->getFltSemantics();

rjmccall wrote:
> I like this method name.  Does this have the same problem as I asked about in 
> the other patch about really needing to be about whether the *unscaled* 
> fixed-point type fits in the given type?
It should be the same case here, yes. Both the integral range and the scale 
matter when determining this.



Comment at: llvm/include/llvm/IR/FixedPointBuilder.h:131
+// There's seemingly no way to convert fltSemantics to Type.
+return ConstantFP::get(Ty->getContext(), APFloat(*FloatSema))->getType();
+  }

rjmccall wrote:
> Could you just extract that code out of `llvm::ConstantFP::get` and put it on 
> `llvm::Type`?  Might be better as a separate patch.
> 
> While you're at it, there's also a `TypeToFloatSemantics` function in 
> Constants.cpp that's completely redundant with `llvm::Type::getFltSemantics`.
Done in D87512.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86632/new/

https://reviews.llvm.org/D86632

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b9bca88 - [analyzer][NFC] Don't bind values to ObjCForCollectionStmt, replace it with a GDM trait

2020-09-11 Thread Kristóf Umann via cfe-commits

Author: Kristóf Umann
Date: 2020-09-11T15:58:48+02:00
New Revision: b9bca883c970d36f408db80df21838c713c326db

URL: 
https://github.com/llvm/llvm-project/commit/b9bca883c970d36f408db80df21838c713c326db
DIFF: 
https://github.com/llvm/llvm-project/commit/b9bca883c970d36f408db80df21838c713c326db.diff

LOG: [analyzer][NFC] Don't bind values to ObjCForCollectionStmt, replace it 
with a GDM trait

Based on the discussion in D82598#2171312. Thanks @NoQ!

D82598 is titled "Get rid of statement liveness, because such a thing doesn't
exist", and indeed, expressions express a value, non-expression statements
don't.

if (a && get() || []{ return true; }())
~~ has a value
~ has a value
~~ has a value
   has a value
~~~ doesn't have a value

That is simple enough, so it would only make sense if we only assigned symbolic
values to expressions in the static analyzer. Yet the interface checkers can
access presents, among other strange things, the following two methods:

ProgramState::BindExpr(const Stmt *S, const LocationContext *LCtx, SVal V,
   bool Invalidate=true)
ProgramState::getSVal(const Stmt *S, const LocationContext *LCtx)

So, what gives? Turns out, we make an exception for ReturnStmt (which we'll
leave for another time) and ObjCForCollectionStmt. For any other loops, in order
to know whether we should analyze another iteration, among other things, we
evaluate it's condition. Which is a problem for ObjCForCollectionStmt, because
it simply doesn't have one (CXXForRangeStmt has an implicit one!). In its
absence, we assigned the actual statement with a concrete 1 or 0 to indicate
whether there are any more iterations left. However, this is wildly incorrect,
its just simply not true that the for statement has a value of 1 or 0, we can't
calculate its liveness because that doesn't make any sense either, so this patch
turns it into a GDM trait.

Fixing this allows us to reinstate the assert removed in
https://reviews.llvm.org/rG032b78a0762bee129f33e4255ada6d374aa70c71.

Differential Revision: https://reviews.llvm.org/D86736

Added: 
clang/test/Analysis/objc-live-crash.mm

Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
clang/lib/StaticAnalyzer/Core/Environment.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
clang/lib/StaticAnalyzer/Core/SymbolManager.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
index cdfe986355c5..582a56cbee1e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -869,6 +869,23 @@ class ExprEngine {
   void handleConstructor(const Expr *E, ExplodedNode *Pred,
  ExplodedNodeSet &Dst);
 
+public:
+  /// Note whether this loop has any more iteratios to model. These methods are
+  /// essentially an interface for a GDM trait. Further reading in
+  /// ExprEngine::VisitObjCForCollectionStmt().
+  LLVM_NODISCARD static ProgramStateRef
+  setWhetherHasMoreIteration(ProgramStateRef State,
+ const ObjCForCollectionStmt *O,
+ const LocationContext *LC, bool HasMoreIteraton);
+
+  LLVM_NODISCARD static ProgramStateRef
+  removeIterationState(ProgramStateRef State, const ObjCForCollectionStmt *O,
+   const LocationContext *LC);
+
+  LLVM_NODISCARD static bool hasMoreIteration(ProgramStateRef State,
+  const ObjCForCollectionStmt *O,
+  const LocationContext *LC);
+private:
   /// Store the location of a C++ object corresponding to a statement
   /// until the statement is actually encountered. For example, if a DeclStmt
   /// has CXXConstructExpr as its initializer, the object would be considered

diff  --git a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp 
b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
index 918c6e361381..a86a410ebcbc 100644
--- a/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
@@ -978,8 +978,7 @@ void ObjCLoopChecker::checkPostStmt(const 
ObjCForCollectionStmt *FCS,
   ProgramStateRef State = C.getState();
 
   // Check if this is the branch for the end of the loop.
-  SVal CollectionSentinel = C.getSVal(FCS);
-  if (CollectionSentinel.isZeroConstant()) {
+  if (!ExprEngine::hasMoreIteration(State, FCS, C.getLoca

[PATCH] D86736: [analyzer][NFC] Don't bind values to ObjCForCollectionStmt, replace it with a GDM trait

2020-09-11 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb9bca883c970: [analyzer][NFC] Don't bind values to 
ObjCForCollectionStmt, replace it with a… (authored by Szelethus).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86736/new/

https://reviews.llvm.org/D86736

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  clang/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
  clang/lib/StaticAnalyzer/Core/Environment.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/objc-live-crash.mm

Index: clang/test/Analysis/objc-live-crash.mm
===
--- /dev/null
+++ clang/test/Analysis/objc-live-crash.mm
@@ -0,0 +1,30 @@
+// RUN: %clang --analyze %s -fblocks
+
+// https://reviews.llvm.org/D82598#2171312
+
+@interface Item
+// ...
+@end
+
+@interface Collection
+// ...
+@end
+
+typedef void (^Blk)();
+
+struct RAII {
+  Blk blk;
+
+public:
+  RAII(Blk blk): blk(blk) {}
+  ~RAII() { blk(); }
+};
+
+void foo(Collection *coll) {
+  RAII raii(^{});
+  for (Item *item in coll) {}
+  int i;
+  {
+int j;
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
+++ clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
@@ -14,6 +14,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Expr.h"
+#include "clang/AST/StmtObjC.h"
 #include "clang/Analysis/Analyses/LiveVariables.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Basic/LLVM.h"
@@ -494,7 +495,8 @@
 return true;
   }
 
-  // If no statement is provided, everything is this and parent contexts is live.
+  // If no statement is provided, everything in this and parent contexts is
+  // live.
   if (!Loc)
 return true;
 
Index: clang/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngineObjC.cpp
@@ -53,10 +53,8 @@
 ProgramStateRef state = Pred->getState();
 const LocationContext *LCtx = Pred->getLocationContext();
 
-SVal hasElementsV = svalBuilder.makeTruthVal(hasElements);
-
-// FIXME: S is not an expression. We should not be binding values to it.
-ProgramStateRef nextState = state->BindExpr(S, LCtx, hasElementsV);
+ProgramStateRef nextState =
+ExprEngine::setWhetherHasMoreIteration(state, S, LCtx, hasElements);
 
 if (auto MV = elementV.getAs())
   if (const auto *R = dyn_cast(MV->getRegion())) {
@@ -93,10 +91,9 @@
   //  (1) binds the next container value to 'element'.  This creates a new
   //  node in the ExplodedGraph.
   //
-  //  (2) binds the value 0/1 to the ObjCForCollectionStmt* itself, indicating
-  //  whether or not the container has any more elements.  This value
-  //  will be tested in ProcessBranch.  We need to explicitly bind
-  //  this value because a container can contain nil elements.
+  //  (2) note whether the collection has any more elements (or in other words,
+  //  whether the loop has more iterations). This will be tested in
+  //  processBranch.
   //
   // FIXME: Eventually this logic should actually do dispatches to
   //   'countByEnumeratingWithState:objects:count:' (NSFastEnumeration).
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2129,6 +2129,83 @@
   llvm_unreachable("could not resolve condition");
 }
 
+using ObjCForLctxPair =
+std::pair;
+
+REGISTER_MAP_WITH_PROGRAMSTATE(ObjCForHasMoreIterations, ObjCForLctxPair, bool)
+
+ProgramStateRef ExprEngine::setWhetherHasMoreIteration(
+ProgramStateRef State, const ObjCForCollectionStmt *O,
+const LocationContext *LC, bool HasMoreIteraton) {
+  assert(!State->contains({O, LC}));
+  return State->set({O, LC}, HasMoreIteraton);
+}
+
+ProgramStateRef
+ExprEngine::removeIterationState(ProgramStateRef State,
+ const ObjCForCollectionStmt *O,
+ const LocationContext *LC) {
+  assert(State->contains({O, LC}));
+  return State->remove({O, LC});
+}
+
+bool ExprEngine::hasMoreIteration(ProgramStateRef State,
+  const ObjCForCollectionStmt *O,
+  const LocationContext *LC) {
+  assert(State->contains({O, LC}));
+  return *State->get({O, LC});
+}
+
+/// Split the state on whether there are any more iterati

[PATCH] D83814: [clangd] Add Random Forest runtime for code completion.

2020-09-11 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 291205.
usaxena95 added a comment.

Added README.md for the code completion model.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83814/new/

https://reviews.llvm.org/D83814

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/for-review-only/CompletionModel.cpp
  clang-tools-extra/clangd/for-review-only/CompletionModel.h
  clang-tools-extra/clangd/for-review-only/DecisionForestRuntimeTest.cpp
  clang-tools-extra/clangd/for-review-only/DecisionForestRuntimeTest.h
  clang-tools-extra/clangd/quality/CompletionModel.cmake
  clang-tools-extra/clangd/quality/CompletionModelCodegen.py
  clang-tools-extra/clangd/quality/README.md
  clang-tools-extra/clangd/quality/model/features.json
  clang-tools-extra/clangd/quality/model/forest.json
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang-tools-extra/clangd/unittests/DecisionForestTests.cpp
  clang-tools-extra/clangd/unittests/model/CategoricalFeature.h
  clang-tools-extra/clangd/unittests/model/features.json
  clang-tools-extra/clangd/unittests/model/forest.json

Index: clang-tools-extra/clangd/unittests/model/forest.json
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/model/forest.json
@@ -0,0 +1,52 @@
+[
+{
+"operation": "if_greater",
+"feature": "ANumber",
+"threshold": 200.0,
+"then": {
+"operation": "if_greater",
+"feature": "AFloat",
+"threshold": -1,
+"then": {
+"operation": "boost",
+"score": 10.0
+},
+"else": {
+"operation": "boost",
+"score": -20.0
+}
+},
+"else": {
+"operation": "if_member",
+"feature": "ACategorical",
+"set": [
+"A",
+"C"
+],
+"then": {
+"operation": "boost",
+"score": 3.0
+},
+"else": {
+"operation": "boost",
+"score": -4.0
+}
+}
+},
+{
+"operation": "if_member",
+"feature": "ACategorical",
+"set": [
+"A",
+"B"
+],
+"then": {
+"operation": "boost",
+"score": 5.0
+},
+"else": {
+"operation": "boost",
+"score": -6.0
+}
+}
+]
\ No newline at end of file
Index: clang-tools-extra/clangd/unittests/model/features.json
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/model/features.json
@@ -0,0 +1,16 @@
+[
+{
+"name": "ANumber",
+"type": "NUMBER"
+},
+{
+"name": "AFloat",
+"type": "NUMBER"
+},
+{
+"name": "ACategorical",
+"type": "ENUM",
+"enum": "ns1::ns2::TestEnum",
+"header": "model/CategoricalFeature.h"
+}
+]
\ No newline at end of file
Index: clang-tools-extra/clangd/unittests/model/CategoricalFeature.h
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/model/CategoricalFeature.h
@@ -0,0 +1,5 @@
+namespace ns1 {
+namespace ns2 {
+enum TestEnum { A, B, C, D };
+} // namespace ns2
+} // namespace ns1
Index: clang-tools-extra/clangd/unittests/DecisionForestTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/DecisionForestTests.cpp
@@ -0,0 +1,29 @@
+#include "DecisionForestRuntimeTest.h"
+#include "model/CategoricalFeature.h"
+#include "gtest/gtest.h"
+
+namespace clangd {
+namespace clangd {
+
+TEST(DecisionForestRuntime, Evaluate) {
+  using Example = ::ns1::ns2::test::Example;
+  using Cat = ::ns1::ns2::TestEnum;
+  using ::ns1::ns2::test::Evaluate;
+
+  Example E;
+  E.setANumber(200); // True
+  E.setAFloat(0);// True: +10.0
+  E.setACategorical(Cat::A); // True: +5.0
+  EXPECT_EQ(Evaluate(E), 15.0);
+
+  E.setANumber(200); // True
+  E.setAFloat(-2.5); // False: -20.0
+  E.setACategorical(Cat::B); // True: +5.0
+  EXPECT_EQ(Evaluate(E), -15.0);
+
+  E.setANumber(100); // False
+  E.setACategorical(Cat::C); // True: +3.0, False: -6.0
+  EXPECT_EQ(Evaluate(E), -3.0);
+}
+} // namespace clangd
+} // namespace clangd
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -10,6 +10,7 @@
 #include "ClangdServer.h"
 #include "CodeComplete.h"
 #include "Compiler.h"
+#include "CompletionModel.h"
 #include "Matchers.

[PATCH] D87449: [clang-tidy] Add new check for SEI CERT rule SIG30-C.

2020-09-11 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Release Notes were not updated yet.




Comment at: clang-tools-extra/docs/clang-tidy/checks/cert-sig30-c.rst:10
+The minimal list of asynchronous-safe system functions is:
+``abort()``, ``_Exit()``, ``quick_exit()`` and ``signal()`` (for ``signal`` 
there are additional conditions that are not checked).
+Every other system call is considered as non asynchronous-safe by the checker.

Please make all strings not longer then 80 symbols.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87449/new/

https://reviews.llvm.org/D87449

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86632: [Fixed Point] Add codegen for conversion between fixed-point and floating point.

2020-09-11 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 291211.
ebevhan added a comment.

Fix typo.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86632/new/

https://reviews.llvm.org/D86632

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Frontend/fixed_point_compound.c
  clang/test/Frontend/fixed_point_conversions.c
  clang/test/Frontend/fixed_point_conversions_half.c
  llvm/include/llvm/IR/FixedPointBuilder.h

Index: llvm/include/llvm/IR/FixedPointBuilder.h
===
--- llvm/include/llvm/IR/FixedPointBuilder.h
+++ llvm/include/llvm/IR/FixedPointBuilder.h
@@ -120,6 +120,16 @@
 C.isSigned(), C.isSaturated(), BothPadded);
   }
 
+  /// Given a floating point type and a fixed-point semantic, return a floating
+  /// point type which can accommodate the fixed-point semantic. This is either
+  /// \p Ty, or a floating point type with a larger exponent than Ty.
+  Type *getAccommodatingFloatType(Type *Ty, const FixedPointSemantics &Sema) {
+const fltSemantics *FloatSema = &Ty->getFltSemantics();
+while (!Sema.fitsInFloatSemantics(*FloatSema))
+  FloatSema = APFixedPoint::promoteFloatSemantics(FloatSema);
+return Type::getFloatingPointTy(Ty->getContext(), *FloatSema);
+  }
+
 public:
   FixedPointBuilder(IRBuilderTy &Builder) : B(Builder) {}
 
@@ -159,6 +169,55 @@
DstSema, false);
   }
 
+  Value *CreateFixedToFloating(Value *Src, const FixedPointSemantics &SrcSema,
+   Type *DstTy) {
+Value *Result;
+Type *OpTy = getAccommodatingFloatType(DstTy, SrcSema);
+// Convert the raw fixed-point value directly to floating point. If the
+// value is too large to fit, it will be rounded, not truncated.
+Result = SrcSema.isSigned() ? B.CreateSIToFP(Src, OpTy)
+: B.CreateUIToFP(Src, OpTy);
+// Rescale the integral-in-floating point by the scaling factor. This is
+// lossless, except for overflow to infinity which is unlikely.
+Result = B.CreateFMul(Result,
+ConstantFP::get(OpTy, std::pow(2, -(int)SrcSema.getScale(;
+if (OpTy != DstTy)
+  Result = B.CreateFPTrunc(Result, DstTy);
+return Result;
+  }
+
+  Value *CreateFloatingToFixed(Value *Src, const FixedPointSemantics &DstSema) {
+bool UseSigned = DstSema.isSigned() || DstSema.hasUnsignedPadding();
+Value *Result = Src;
+Type *OpTy = getAccommodatingFloatType(Src->getType(), DstSema);
+if (OpTy != Src->getType())
+  Result = B.CreateFPExt(Result, OpTy);
+// Rescale the floating point value so that its significant bits (for the
+// purposes of the conversion) are in the integral range.
+Result = B.CreateFMul(Result,
+ConstantFP::get(OpTy, std::pow(2, DstSema.getScale(;
+
+Type *ResultTy = B.getIntNTy(DstSema.getWidth());
+if (DstSema.isSaturated()) {
+  Intrinsic::ID IID =
+  UseSigned ? Intrinsic::fptosi_sat : Intrinsic::fptoui_sat;
+  Result = B.CreateIntrinsic(IID, {ResultTy, OpTy}, {Result});
+} else {
+  Result = UseSigned ? B.CreateFPToSI(Result, ResultTy)
+ : B.CreateFPToUI(Result, ResultTy);
+}
+
+// When saturating unsigned-with-padding using signed operations, we may
+// get negative values. Emit an extra clamp to zero.
+if (DstSema.isSaturated() && DstSema.hasUnsignedPadding()) {
+  Constant *Zero = Constant::getNullValue(Result->getType());
+  Result =
+  B.CreateSelect(B.CreateICmpSLT(Result, Zero), Zero, Result, "satmin");
+}
+
+return Result;
+  }
+
   /// Add two fixed-point values and return the result in their common semantic.
   /// \p LHS - The left hand side
   /// \p LHSSema - The semantic of the left hand side
Index: clang/test/Frontend/fixed_point_conversions_half.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_conversions_half.c
@@ -0,0 +1,309 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -ffixed-point -triple arm64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -triple arm64-unknown-linux-gnu -S -emit-llvm %s -o - -fpadding-on-unsigned-fixed-point | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+short _Fract sf;
+long _Fract lf;
+
+short _Accum sa;
+long _Accum la;
+
+unsigned short _Accum usa;
+unsigned long _Accum ula;
+
+_Sat short _Fract sf_sat;
+_Sat long _Fract lf_sat;
+
+_Sat short _Accum sa_sat;
+_Sat long _Accum la_sat;
+
+_Sat unsigned short _Accum usa_sat;
+_Sat unsigned long _Accum ula_sat;
+
+_Float16 h;
+
+
+// CHECK-LABEL: @half_fix1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = load half, half* @h, align 2
+// CHECK-NEXT:[[TMP1:%.*]] = fmul half [[TMP0]], 0xH5800
+// CHECK-NEXT:[[TMP2:%.*]] = fptosi half [[TMP1]] to i8

[PATCH] D87459: [libcxx][test] ostream{,buf}_iterator::difference_type changes in C++20

2020-09-11 Thread Louis Dionne via Phabricator via cfe-commits
ldionne updated this revision to Diff 291213.
ldionne added a comment.

Implement the changes for libc++.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87459/new/

https://reviews.llvm.org/D87459

Files:
  libcxx/include/iterator
  libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
  libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp

Index: libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
===
--- libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
+++ libcxx/test/std/iterators/stream.iterators/ostreambuf.iterator/types.pass.cpp
@@ -19,6 +19,7 @@
 //   typedef basic_ostream   ostream_type;
 //   ...
 
+#include 
 #include 
 #include 
 #include 
@@ -34,7 +35,11 @@
 #else
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
+#if TEST_STD_VER <= 17
 static_assert((std::is_same::value), "");
+#else
+static_assert((std::is_same::value), "");
+#endif
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 #endif
@@ -50,7 +55,11 @@
 #else
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
+#if TEST_STD_VER <= 17
 static_assert((std::is_same::value), "");
+#else
+static_assert((std::is_same::value), "");
+#endif
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 #endif
Index: libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
===
--- libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
+++ libcxx/test/std/iterators/stream.iterators/ostream.iterator/types.pass.cpp
@@ -19,6 +19,7 @@
 // typedef basic_istream istream_type;
 // ...
 
+#include 
 #include 
 #include 
 
@@ -33,7 +34,11 @@
 #else
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
+#if TEST_STD_VER <= 17
 static_assert((std::is_same::value), "");
+#else
+static_assert((std::is_same::value), "");
+#endif
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 #endif
@@ -47,7 +52,11 @@
 #else
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
+#if TEST_STD_VER <= 17
 static_assert((std::is_same::value), "");
+#else
+static_assert((std::is_same::value), "");
+#endif
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 #endif
Index: libcxx/include/iterator
===
--- libcxx/include/iterator
+++ libcxx/include/iterator
@@ -1052,9 +1052,19 @@
 : public iterator
 {
 public:
-typedef _CharT char_type;
-typedef _Traits traits_type;
-typedef basic_ostream<_CharT,_Traits> ostream_type;
+typedef output_iterator_tag iterator_category;
+typedef voidvalue_type;
+#if _LIBCPP_STD_VER > 17
+typedef std::ptrdiff_t  difference_type;
+#else
+typedef voiddifference_type;
+#endif
+typedef voidpointer;
+typedef voidreference;
+typedef _CharT  char_type;
+typedef _Traits traits_type;
+typedef basic_ostream<_CharT, _Traits>  ostream_type;
+
 private:
 ostream_type* __out_stream_;
 const char_type* __delim_;
@@ -1151,10 +1161,20 @@
 : public iterator
 {
 public:
-typedef _CharT  char_type;
-typedef _Traits traits_type;
-typedef basic_streambuf<_CharT,_Traits> streambuf_type;
-typedef basic_ostream<_CharT,_Traits>   ostream_type;
+typedef output_iterator_tag iterator_category;
+typedef voidvalue_type;
+#if _LIBCPP_STD_VER > 17
+typedef std::ptrdiff_t  difference_type;
+#else
+typedef voiddifference_type;
+#endif
+typedef voidpointer;
+typedef voidreference;
+typedef _CharT  char_type;
+typedef _Traits traits_type;
+typedef basic_streambuf<_CharT, _Traits>streambuf_type;
+typedef basic_ostream<_CharT, _Traits>  ostream_type;
+
 private:
 streambuf_type* __sbuf_;
 public:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 48b510c - [NFC] Fix compiler warnings due to integer comparison of different signedness

2020-09-11 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2020-09-11T15:32:03+01:00
New Revision: 48b510c4bc0fe090e635ee0440e46fc176527d7e

URL: 
https://github.com/llvm/llvm-project/commit/48b510c4bc0fe090e635ee0440e46fc176527d7e
DIFF: 
https://github.com/llvm/llvm-project/commit/48b510c4bc0fe090e635ee0440e46fc176527d7e.diff

LOG: [NFC] Fix compiler warnings due to integer comparison of different 
signedness

Fix by directly using INT_MAX and INT32_MAX.

Patch by: @nullptr.cpp (Yang Fan)

Differential Revision: https://reviews.llvm.org/D87347

Added: 


Modified: 
clang/lib/Lex/Pragma.cpp
llvm/lib/Analysis/VectorUtils.cpp
llvm/lib/MC/WasmObjectWriter.cpp
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Removed: 




diff  --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index b512a547de7d..a05df060813e 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -1356,7 +1356,7 @@ struct PragmaWarningHandler : public PragmaHandler {
 while (Tok.is(tok::numeric_constant)) {
   uint64_t Value;
   if (!PP.parseSimpleIntegerLiteral(Tok, Value) || Value == 0 ||
-  Value > std::numeric_limits::max()) {
+  Value > INT_MAX) {
 PP.Diag(Tok, diag::warn_pragma_warning_expected_number);
 return;
   }

diff  --git a/llvm/lib/Analysis/VectorUtils.cpp 
b/llvm/lib/Analysis/VectorUtils.cpp
index 0b10983442e2..34fa0f283b03 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -416,8 +416,7 @@ void llvm::narrowShuffleMaskElts(int Scale, ArrayRef 
Mask,
   ScaledMask.clear();
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
-  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=
- std::numeric_limits::max() &&
+  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <= INT32_MAX &&
  "Overflowed 32-bits");
 }
 for (int SliceElt = 0; SliceElt != Scale; ++SliceElt)

diff  --git a/llvm/lib/MC/WasmObjectWriter.cpp 
b/llvm/lib/MC/WasmObjectWriter.cpp
index af4620361c34..6075423fa0f2 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,8 @@ uint32_t WasmObjectWriter::writeDataSection(const 
MCAsmLayout &Layout) {
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > INT32_MAX ? wasm::WASM_OPCODE_I64_CONST
+  : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index ef56cb77447a..55c6ce6eb783 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,8 +2037,7 @@ static Instruction *foldTruncShuffle(ShuffleVectorInst 
&Shuf,
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * 
TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
-   "Overflowed 32-bits");
+assert(LSBIndex <= INT32_MAX && "Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
   }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87347: [NFC] Fix compiler warnings due to integer comparison of different signedness

2020-09-11 Thread Simon Pilgrim via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG48b510c4bc0f: [NFC] Fix compiler warnings due to integer 
comparison of different signedness (authored by RKSimon).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87347/new/

https://reviews.llvm.org/D87347

Files:
  clang/lib/Lex/Pragma.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/MC/WasmObjectWriter.cpp
  llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,8 +2037,7 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * 
TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
-   "Overflowed 32-bits");
+assert(LSBIndex <= INT32_MAX && "Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
   }
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,8 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > INT32_MAX ? wasm::WASM_OPCODE_I64_CONST
+  : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -416,8 +416,7 @@
   ScaledMask.clear();
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
-  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=
- std::numeric_limits::max() &&
+  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <= INT32_MAX &&
  "Overflowed 32-bits");
 }
 for (int SliceElt = 0; SliceElt != Scale; ++SliceElt)
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -1356,7 +1356,7 @@
 while (Tok.is(tok::numeric_constant)) {
   uint64_t Value;
   if (!PP.parseSimpleIntegerLiteral(Tok, Value) || Value == 0 ||
-  Value > std::numeric_limits::max()) {
+  Value > INT_MAX) {
 PP.Diag(Tok, diag::warn_pragma_warning_expected_number);
 return;
   }


Index: llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -2037,8 +2037,7 @@
 if (Mask[i] == UndefMaskElem)
   continue;
 uint64_t LSBIndex = IsBigEndian ? (i + 1) * TruncRatio - 1 : i * TruncRatio;
-assert(LSBIndex <= std::numeric_limits::max() &&
-   "Overflowed 32-bits");
+assert(LSBIndex <= INT32_MAX && "Overflowed 32-bits");
 if (Mask[i] != (int)LSBIndex)
   return nullptr;
   }
Index: llvm/lib/MC/WasmObjectWriter.cpp
===
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -939,9 +939,8 @@
 if (Segment.InitFlags & wasm::WASM_SEGMENT_HAS_MEMINDEX)
   encodeULEB128(0, W.OS); // memory index
 if ((Segment.InitFlags & wasm::WASM_SEGMENT_IS_PASSIVE) == 0) {
-  W.OS << char(Segment.Offset > std::numeric_limits().max()
- ? wasm::WASM_OPCODE_I64_CONST
- : wasm::WASM_OPCODE_I32_CONST);
+  W.OS << char(Segment.Offset > INT32_MAX ? wasm::WASM_OPCODE_I64_CONST
+  : wasm::WASM_OPCODE_I32_CONST);
   encodeSLEB128(Segment.Offset, W.OS); // offset
   W.OS << char(wasm::WASM_OPCODE_END);
 }
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -416,8 +416,7 @@
   ScaledMask.clear();
   for (int MaskElt : Mask) {
 if (MaskElt >= 0) {
-  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <=
- std::numeric_limits::max() &&
+  assert(((uint64_t)Scale * MaskElt + (Scale - 1)) <= INT32_MAX &&
  "Overflowed 32-bits");
 }
 for (int SliceElt

[PATCH] D87498: [SyntaxTree][NFC] Rename functions to start with verb

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c14ee61b737: [SyntaxTree] Rename functions to start with 
verb (authored by eduucaldas).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87498/new/

https://reviews.llvm.org/D87498

Files:
  clang/include/clang/Tooling/Syntax/Nodes.h
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/ComputeReplacements.cpp
  clang/lib/Tooling/Syntax/Mutations.cpp
  clang/lib/Tooling/Syntax/Nodes.cpp
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/lib/Tooling/Syntax/Tree.cpp
  clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp
  clang/unittests/Tooling/Syntax/TreeTestBase.cpp

Index: clang/unittests/Tooling/Syntax/TreeTestBase.cpp
===
--- clang/unittests/Tooling/Syntax/TreeTestBase.cpp
+++ clang/unittests/Tooling/Syntax/TreeTestBase.cpp
@@ -38,10 +38,10 @@
 ArrayRef tokens(syntax::Node *N) {
   assert(N->isOriginal() && "tokens of modified nodes are not well-defined");
   if (auto *L = dyn_cast(N))
-return llvm::makeArrayRef(L->token(), 1);
+return llvm::makeArrayRef(L->getToken(), 1);
   auto *T = cast(N);
-  return llvm::makeArrayRef(T->firstLeaf()->token(),
-T->lastLeaf()->token() + 1);
+  return llvm::makeArrayRef(T->findFirstLeaf()->getToken(),
+T->findLastLeaf()->getToken() + 1);
 }
 } // namespace
 
@@ -170,7 +170,7 @@
   auto *T = dyn_cast(Root);
   if (!T)
 return nullptr;
-  for (auto *C = T->firstChild(); C != nullptr; C = C->nextSibling()) {
+  for (auto *C = T->getFirstChild(); C != nullptr; C = C->getNextSibling()) {
 if (auto *Result = nodeByRange(R, C))
   return Result;
   }
Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -26,7 +26,7 @@
 
   auto *C = syntax::createPunctuation(*Arena, tok::comma);
   ASSERT_NE(C, nullptr);
-  EXPECT_EQ(C->token()->kind(), tok::comma);
+  EXPECT_EQ(C->getToken()->kind(), tok::comma);
   EXPECT_TRUE(C->canModify());
   EXPECT_FALSE(C->isOriginal());
   EXPECT_TRUE(C->isDetached());
Index: clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
===
--- clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
+++ clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
@@ -28,7 +28,7 @@
  << "Source file has syntax errors, they were printed to the test "
 "log";
 }
-auto Actual = StringRef(Root->dump(Arena->sourceManager())).trim().str();
+auto Actual = StringRef(Root->dump(Arena->getSourceManager())).trim().str();
 // EXPECT_EQ shows the diff between the two strings if they are different.
 EXPECT_EQ(Tree.trim().str(), Actual);
 if (Actual != Tree.trim().str()) {
@@ -63,7 +63,9 @@
   auto *AnnotatedNode = nodeByRange(AnnotatedRanges[i], Root);
   assert(AnnotatedNode);
   auto AnnotatedNodeDump =
-  StringRef(AnnotatedNode->dump(Arena->sourceManager())).trim().str();
+  StringRef(AnnotatedNode->dump(Arena->getSourceManager()))
+  .trim()
+  .str();
   // EXPECT_EQ shows the diff between the two strings if they are different.
   EXPECT_EQ(TreeDumps[i].trim().str(), AnnotatedNodeDump)
   << "Dumps diverged for the code:\n"
Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -19,7 +19,7 @@
 static void traverse(const syntax::Node *N,
  llvm::function_ref Visit) {
   if (auto *T = dyn_cast(N)) {
-for (auto *C = T->firstChild(); C; C = C->nextSibling())
+for (auto *C = T->getFirstChild(); C; C = C->getNextSibling())
   traverse(C, Visit);
   }
   Visit(N);
@@ -36,7 +36,9 @@
  const TokenBuffer &Tokens)
 : SourceMgr(SourceMgr), LangOpts(LangOpts), Tokens(Tokens) {}
 
-const syntax::TokenBuffer &syntax::Arena::tokenBuffer() const { return Tokens; }
+const syntax::TokenBuffer &syntax::Arena::getTokenBuffer() const {
+  return Tokens;
+}
 
 std::pair>
 syntax::Arena::lexBuffer(std::unique_ptr Input) {
@@ -51,7 +53,7 @@
 }
 
 bool syntax::Leaf::classof(const Node *N) {
-  return N->kind() == NodeKind::Leaf;
+  return N->getKind() == NodeKind::Leaf;
 }
 
 syntax::Node::Node(NodeKind Kind)
@@ -60,16 +62,20 @@
   this->setRole(NodeRole::Detached);
 }
 
-bool syntax::Node::isDetached() const { return role() == NodeRole::Detached; }
+bool syntax::Node::isDetached() const {
+  return getRole() == NodeRole::Detached;
+}
 
 void

[clang] 4c14ee6 - [SyntaxTree] Rename functions to start with verb

2020-09-11 Thread Eduardo Caldas via cfe-commits

Author: Eduardo Caldas
Date: 2020-09-11T14:54:18Z
New Revision: 4c14ee61b73746b314d83e7c52e03d6527b78105

URL: 
https://github.com/llvm/llvm-project/commit/4c14ee61b73746b314d83e7c52e03d6527b78105
DIFF: 
https://github.com/llvm/llvm-project/commit/4c14ee61b73746b314d83e7c52e03d6527b78105.diff

LOG: [SyntaxTree] Rename functions to start with verb

According to LLVM coding standards:
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

Differential Revision: https://reviews.llvm.org/D87498

Added: 


Modified: 
clang/include/clang/Tooling/Syntax/Nodes.h
clang/include/clang/Tooling/Syntax/Tree.h
clang/lib/Tooling/Syntax/BuildTree.cpp
clang/lib/Tooling/Syntax/ComputeReplacements.cpp
clang/lib/Tooling/Syntax/Mutations.cpp
clang/lib/Tooling/Syntax/Nodes.cpp
clang/lib/Tooling/Syntax/Synthesis.cpp
clang/lib/Tooling/Syntax/Tree.cpp
clang/unittests/Tooling/Syntax/BuildTreeTest.cpp
clang/unittests/Tooling/Syntax/SynthesisTest.cpp
clang/unittests/Tooling/Syntax/TreeTestBase.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Syntax/Nodes.h 
b/clang/include/clang/Tooling/Syntax/Nodes.h
index a6505c8167ee..8b393c5423b4 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -190,7 +190,7 @@ class TranslationUnit final : public Tree {
 public:
   TranslationUnit() : Tree(NodeKind::TranslationUnit) {}
   static bool classof(const Node *N) {
-return N->kind() == NodeKind::TranslationUnit;
+return N->getKind() == NodeKind::TranslationUnit;
   }
 };
 
@@ -200,8 +200,8 @@ class Expression : public Tree {
 public:
   Expression(NodeKind K) : Tree(K) {}
   static bool classof(const Node *N) {
-return NodeKind::UnknownExpression <= N->kind() &&
-   N->kind() <= NodeKind::UnknownExpression;
+return NodeKind::UnknownExpression <= N->getKind() &&
+   N->getKind() <= NodeKind::UnknownExpression;
   }
 };
 
@@ -211,10 +211,10 @@ class NameSpecifier : public Tree {
 public:
   NameSpecifier(NodeKind K) : Tree(K) {}
   static bool classof(const Node *N) {
-return N->kind() == NodeKind::GlobalNameSpecifier ||
-   N->kind() == NodeKind::DecltypeNameSpecifier ||
-   N->kind() == NodeKind::IdentifierNameSpecifier ||
-   N->kind() == NodeKind::SimpleTemplateNameSpecifier;
+return N->getKind() == NodeKind::GlobalNameSpecifier ||
+   N->getKind() == NodeKind::DecltypeNameSpecifier ||
+   N->getKind() == NodeKind::IdentifierNameSpecifier ||
+   N->getKind() == NodeKind::SimpleTemplateNameSpecifier;
   }
 };
 
@@ -226,7 +226,7 @@ class GlobalNameSpecifier final : public NameSpecifier {
 public:
   GlobalNameSpecifier() : NameSpecifier(NodeKind::GlobalNameSpecifier) {}
   static bool classof(const Node *N) {
-return N->kind() == NodeKind::GlobalNameSpecifier;
+return N->getKind() == NodeKind::GlobalNameSpecifier;
   }
 };
 
@@ -236,7 +236,7 @@ class DecltypeNameSpecifier final : public NameSpecifier {
 public:
   DecltypeNameSpecifier() : NameSpecifier(NodeKind::DecltypeNameSpecifier) {}
   static bool classof(const Node *N) {
-return N->kind() == NodeKind::DecltypeNameSpecifier;
+return N->getKind() == NodeKind::DecltypeNameSpecifier;
   }
 };
 
@@ -247,7 +247,7 @@ class IdentifierNameSpecifier final : public NameSpecifier {
   IdentifierNameSpecifier()
   : NameSpecifier(NodeKind::IdentifierNameSpecifier) {}
   static bool classof(const Node *N) {
-return N->kind() == NodeKind::IdentifierNameSpecifier;
+return N->getKind() == NodeKind::IdentifierNameSpecifier;
   }
 };
 
@@ -259,7 +259,7 @@ class SimpleTemplateNameSpecifier final : public 
NameSpecifier {
   SimpleTemplateNameSpecifier()
   : NameSpecifier(NodeKind::SimpleTemplateNameSpecifier) {}
   static bool classof(const Node *N) {
-return N->kind() == NodeKind::SimpleTemplateNameSpecifier;
+return N->getKind() == NodeKind::SimpleTemplateNameSpecifier;
   }
 };
 
@@ -269,7 +269,7 @@ class NestedNameSpecifier final : public List {
 public:
   NestedNameSpecifier() : List(NodeKind::NestedNameSpecifier) {}
   static bool classof(const Node *N) {
-return N->kind() <= NodeKind::NestedNameSpecifier;
+return N->getKind() <= NodeKind::NestedNameSpecifier;
   }
   std::vector getSpecifiers();
   std::vector>
@@ -282,7 +282,7 @@ class UnqualifiedId final : public Tree {
 public:
   UnqualifiedId() : Tree(NodeKind::UnqualifiedId) {}
   static bool classof(const Node *N) {
-return N->kind() == NodeKind::UnqualifiedId;
+return N->getKind() == NodeKind::UnqualifiedId;
   }
 };
 
@@ -297,7 +297,7 @@ class IdExpression final : public Expression {
 public:
   IdExpression() : Expression(NodeKind::IdExpression) {}
   static bool classof(const Node *N) {
-return N->kind() == NodeKind::IdExpression;
+return N->getKind() =

[PATCH] D87517: [MinGW] Use lib prefix for libraries

2020-09-11 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 created this revision.
mati865 added a reviewer: LLVM.
mati865 added projects: LLVM, clang, LLDB.
Herald added subscribers: llvm-commits, lldb-commits, cfe-commits, 
JDevlieghere, mgorny.
mati865 requested review of this revision.

In MinGW world, UNIX like `lib` prefix is preferred. This patch adjusts CMake 
files to do that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87517

Files:
  clang/tools/libclang/CMakeLists.txt
  lldb/source/API/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake


Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -567,7 +567,7 @@
   endif()
 
   if(ARG_SHARED)
-if(WIN32)
+if(MSVC)
   set_target_properties(${name} PROPERTIES
 PREFIX ""
 )
Index: lldb/source/API/CMakeLists.txt
===
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -182,10 +182,10 @@
   set_target_properties(liblldb_exports PROPERTIES FOLDER "lldb misc")
 endif()
 
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
+if (MSVC)
   # Only MSVC has the ABI compatibility problem and avoids using 
FindPythonLibs,
   # so only it needs to explicitly link against ${Python3_LIBRARIES}
-  if (MSVC AND LLDB_ENABLE_PYTHON)
+  if (LLDB_ENABLE_PYTHON)
 target_link_libraries(liblldb PRIVATE ${Python3_LIBRARIES})
   endif()
 else()
Index: clang/tools/libclang/CMakeLists.txt
===
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -101,7 +101,7 @@
   unset(ENABLE_STATIC)
 endif()
 
-if(WIN32)
+if(MSVC)
   set(output_name "libclang")
 else()
   set(output_name "clang")
@@ -205,4 +205,3 @@
COMPONENT
  libclang-python-bindings)
 endif()
-


Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -567,7 +567,7 @@
   endif()
 
   if(ARG_SHARED)
-if(WIN32)
+if(MSVC)
   set_target_properties(${name} PROPERTIES
 PREFIX ""
 )
Index: lldb/source/API/CMakeLists.txt
===
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -182,10 +182,10 @@
   set_target_properties(liblldb_exports PROPERTIES FOLDER "lldb misc")
 endif()
 
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
+if (MSVC)
   # Only MSVC has the ABI compatibility problem and avoids using FindPythonLibs,
   # so only it needs to explicitly link against ${Python3_LIBRARIES}
-  if (MSVC AND LLDB_ENABLE_PYTHON)
+  if (LLDB_ENABLE_PYTHON)
 target_link_libraries(liblldb PRIVATE ${Python3_LIBRARIES})
   endif()
 else()
Index: clang/tools/libclang/CMakeLists.txt
===
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -101,7 +101,7 @@
   unset(ENABLE_STATIC)
 endif()
 
-if(WIN32)
+if(MSVC)
   set(output_name "libclang")
 else()
   set(output_name "clang")
@@ -205,4 +205,3 @@
COMPONENT
  libclang-python-bindings)
 endif()
-
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86049: RFC: Implement optional exportable wrapper function generation for objc_direct methods.

2020-09-11 Thread Manman Ren via Phabricator via cfe-commits
manmanren added a comment.



In D86049#2255738 , @rjmccall wrote:

> We just talk about it.  I agree with Nathan that we shouldn't just add this 
> as a short-term hack; we should design the ABI right and then do what we want.
>
> I think these are basically all the ABI questions:
>
> - Is there a good reason to preserve signature compatibility with normal ObjC 
> methods, or should we just drop the selector argument on direct methods?
> - Should we do the null test on the caller side or the callee side?
> - In direct class methods, is the caller's responsibility or the callee's to 
> ensure that `self` is initialized?
>
> For the first, I think dropping the argument is fine.

Dropping the argument sounds good to me! We are already passing the argument as 
undefined.

> For the second, I'm less certain.

It feels cleaner to do the null test on the callee side (i.e inside the 
wrapper). It may have binary size advantage compared to checking at each 
callsite.

> For the third, making it the callee's responsibility is generally better for 
> code size but harder to optimize.  But we only have the code-size cost on the 
> caller side when materializing from a global, and that's actually something 
> we can also eliminate as redundant.  So maybe the best approach is to 
> introduce a weak+hidden thunk that we use when making a call to a direct 
> class method on a specific class, and we have that thunk do the entire 
> materialization sequence.

Completely agree. For direct class method, making sure 'self' is initialized on 
the callee side is cleaner and better for code size. But caller has the context 
to know whether the class is already initialized.
Maybe we can start with doing it on callee's side and make an incremental 
improvement by implementing the approach that can get both benefits.

Do we need to support direct methods with variadic arguments for the wrapper 
implementation or are we going with the non-wrapper version? @plotfi

Thanks!
Manman


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86049/new/

https://reviews.llvm.org/D86049

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87517: [MinGW] Use lib prefix for libraries

2020-09-11 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 updated this revision to Diff 291224.
mati865 added a comment.

Also adjusted llvm-config.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87517/new/

https://reviews.llvm.org/D87517

Files:
  clang/tools/libclang/CMakeLists.txt
  lldb/source/API/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/tools/llvm-config/llvm-config.cpp


Index: llvm/tools/llvm-config/llvm-config.cpp
===
--- llvm/tools/llvm-config/llvm-config.cpp
+++ llvm/tools/llvm-config/llvm-config.cpp
@@ -381,6 +381,7 @@
 SharedExt = "dll";
 SharedVersionedExt = LLVM_DYLIB_VERSION ".dll";
 if (HostTriple.isOSCygMing()) {
+  SharedPrefix = "lib";
   StaticExt = "a";
   StaticPrefix = "lib";
 } else {
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -567,7 +567,7 @@
   endif()
 
   if(ARG_SHARED)
-if(WIN32)
+if(MSVC)
   set_target_properties(${name} PROPERTIES
 PREFIX ""
 )
Index: lldb/source/API/CMakeLists.txt
===
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -182,10 +182,10 @@
   set_target_properties(liblldb_exports PROPERTIES FOLDER "lldb misc")
 endif()
 
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
+if (MSVC)
   # Only MSVC has the ABI compatibility problem and avoids using 
FindPythonLibs,
   # so only it needs to explicitly link against ${Python3_LIBRARIES}
-  if (MSVC AND LLDB_ENABLE_PYTHON)
+  if (LLDB_ENABLE_PYTHON)
 target_link_libraries(liblldb PRIVATE ${Python3_LIBRARIES})
   endif()
 else()
Index: clang/tools/libclang/CMakeLists.txt
===
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -101,7 +101,7 @@
   unset(ENABLE_STATIC)
 endif()
 
-if(WIN32)
+if(MSVC)
   set(output_name "libclang")
 else()
   set(output_name "clang")


Index: llvm/tools/llvm-config/llvm-config.cpp
===
--- llvm/tools/llvm-config/llvm-config.cpp
+++ llvm/tools/llvm-config/llvm-config.cpp
@@ -381,6 +381,7 @@
 SharedExt = "dll";
 SharedVersionedExt = LLVM_DYLIB_VERSION ".dll";
 if (HostTriple.isOSCygMing()) {
+  SharedPrefix = "lib";
   StaticExt = "a";
   StaticPrefix = "lib";
 } else {
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -567,7 +567,7 @@
   endif()
 
   if(ARG_SHARED)
-if(WIN32)
+if(MSVC)
   set_target_properties(${name} PROPERTIES
 PREFIX ""
 )
Index: lldb/source/API/CMakeLists.txt
===
--- lldb/source/API/CMakeLists.txt
+++ lldb/source/API/CMakeLists.txt
@@ -182,10 +182,10 @@
   set_target_properties(liblldb_exports PROPERTIES FOLDER "lldb misc")
 endif()
 
-if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
+if (MSVC)
   # Only MSVC has the ABI compatibility problem and avoids using FindPythonLibs,
   # so only it needs to explicitly link against ${Python3_LIBRARIES}
-  if (MSVC AND LLDB_ENABLE_PYTHON)
+  if (LLDB_ENABLE_PYTHON)
 target_link_libraries(liblldb PRIVATE ${Python3_LIBRARIES})
   endif()
 else()
Index: clang/tools/libclang/CMakeLists.txt
===
--- clang/tools/libclang/CMakeLists.txt
+++ clang/tools/libclang/CMakeLists.txt
@@ -101,7 +101,7 @@
   unset(ENABLE_STATIC)
 endif()
 
-if(WIN32)
+if(MSVC)
   set(output_name "libclang")
 else()
   set(output_name "clang")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r364428 - Make CodeGen depend on ASTMatchers

2020-09-11 Thread Michael LIAO via cfe-commits
b22d4504968 was committed last night.

On Fri, Sep 11, 2020 at 9:30 AM Vassil Vassilev  wrote:
>
> On 9/11/20 5:13 AM, Michael LIAO wrote:
> > That change was added long ago to fix the shared library build.
> > Possibly, there are changes removing that dependency then. Just
> > verified that removing that dependency is just fine.
>
>
>That's great! Would you commit that change or should I?
>
>
> >
> > On Thu, Sep 10, 2020 at 6:48 AM Vassil Vassilev  
> > wrote:
> >> Hello,
> >>
> >> IIUC, clang's CodeGen does not immediately depend on ASTMatchers. I
> >> was wondering what is the reason for inserting such a dependency to fix
> >> the shared library builds?
> >>
> >> Can you give more details about the failure you are fixing?
> >>
> >> Sorry for the late question.
> >>
> >> Best, Vassil
> >> On 6/26/19 5:13 PM, Michael Liao via cfe-commits wrote:
> >>> Author: hliao
> >>> Date: Wed Jun 26 07:13:43 2019
> >>> New Revision: 364428
> >>>
> >>> URL: http://llvm.org/viewvc/llvm-project?rev=364428&view=rev
> >>> Log:
> >>> Make CodeGen depend on ASTMatchers
> >>>
> >>> - Shared library builds are broken due to the missing dependency.
> >>>
> >>> Modified:
> >>>   cfe/trunk/lib/CodeGen/CMakeLists.txt
> >>>
> >>> Modified: cfe/trunk/lib/CodeGen/CMakeLists.txt
> >>> URL: 
> >>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CMakeLists.txt?rev=364428&r1=364427&r2=364428&view=diff
> >>> ==
> >>> --- cfe/trunk/lib/CodeGen/CMakeLists.txt (original)
> >>> +++ cfe/trunk/lib/CodeGen/CMakeLists.txt Wed Jun 26 07:13:43 2019
> >>> @@ -101,6 +101,7 @@ add_clang_library(clangCodeGen
> >>>  LINK_LIBS
> >>>  clangAnalysis
> >>>  clangAST
> >>> +  clangASTMatchers
> >>>  clangBasic
> >>>  clangFrontend
> >>>  clangLex
> >>>
> >>>
> >>> ___
> >>> cfe-commits mailing list
> >>> cfe-commits@lists.llvm.org
> >>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> >>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87321: Fix -gz=zlib options for linker

2020-09-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 291227.
yaxunl marked 6 inline comments as done.
yaxunl added a comment.

revised by Fangrui's comments.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87321/new/

https://reviews.llvm.org/D87321

Files:
  clang/lib/Driver/ToolChains/AMDGPU.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/compress.c
  clang/test/Driver/hip-gz-options.hip

Index: clang/test/Driver/hip-gz-options.hip
===
--- /dev/null
+++ clang/test/Driver/hip-gz-options.hip
@@ -0,0 +1,14 @@
+// REQUIRES: clang-driver, x86-registered-target, amdgpu-registered-target
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN:--offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   -ggdb -gz=zlib 2>&1 | FileCheck %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN:   -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   -ggdb -gz=zlib 2>&1 | FileCheck %s
+
+// CHECK: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
+// CHECK-DAG: {{".*lld.*" .* "--compress-debug-sections=zlib"}}
+// CHECK-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
+// CHECK: {{".*ld.*" .* "--compress-debug-sections=zlib"}}
Index: clang/test/Driver/compress.c
===
--- clang/test/Driver/compress.c
+++ clang/test/Driver/compress.c
@@ -18,19 +18,27 @@
 // RUN: %clang -### -fintegrated-as -gz -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ %s
 // CHECK-OPT_GZ: "--compress-debug-sections"
 
-// RUN: %clang -### -fintegrated-as -gz=none -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
-// RUN: %clang -### -fintegrated-as -gz=none -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
-// CHECK-OPT_GZ_EQ_NONE: "--compress-debug-sections=none"
-
-// RUN: %clang -### -fintegrated-as -gz=zlib -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
-// RUN: %clang -### -fintegrated-as -gz=zlib -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
-// CHECK-OPT_GZ_EQ_ZLIB: "--compress-debug-sections=zlib"
-
-// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
-// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
-// CHECK-OPT_GZ_EQ_ZLIB_GNU: "--compress-debug-sections=zlib-gnu"
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -fintegrated-as -gz=none -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -fintegrated-as -gz=none %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -fintegrated-as -gz=none -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -fintegrated-as -gz=none %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
+// CHECK-OPT_GZ_EQ_NONE: {{".*clang.*".* "--compress-debug-sections=none"}}
+// CHECK-OPT_GZ_EQ_NONE: {{".*ld.*".* "--compress-debug-sections=none"}}
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -fintegrated-as -gz=zlib -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -fintegrated-as -gz=zlib %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -fintegrated-as -gz=zlib -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -fintegrated-as -gz=zlib %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
+// CHECK-OPT_GZ_EQ_ZLIB: {{".*clang.*".* "--compress-debug-sections=zlib"}}
+// CHECK-OPT_GZ_EQ_ZLIB: {{".*ld.*".* "--compress-debug-sections=zlib"}}
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -fintegrated-as -gz=zlib-gnu -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -fintegrated-as -gz=zlib-gnu %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -fintegrated-as -gz=zlib-gnu -x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -fintegrated-as -gz=zlib-gnu %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
+// CHECK-OPT_GZ_EQ_ZLIB_GNU: {{".*clang.*".* "--compress-debug-sections=zlib-gnu"}}
+// CHECK-OPT_GZ_EQ_ZLIB_GNU: {{".*ld.*".* "--compress-debug-sections=zlib-gnu"}}
 
 // RUN: %clang -### -fintegrated-as -gz=invalid -x assembler -c %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_INVALID %s
 // RUN: %clang -### -fintegrated-as -gz=invalid -c %s 2>&1 | FileCheck -check-prefix CHEC

[PATCH] D87321: Fix -gz=zlib options for linker

2020-09-11 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/Driver/gz.c:1
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -g -gz=none %s 2>&1 | \
+// RUN:FileCheck -check-prefix=NONE %s

MaskRay wrote:
> This can be merged into `compress.c`
> You may delete some `-c` from compress.c to exercise the linker stage.
done



Comment at: clang/test/Driver/hip-gz-options.hip:1
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target

MaskRay wrote:
> REQUIRES values can be comma separated
merged



Comment at: clang/test/Driver/hip-gz-options.hip:5
+
+// RUN: %clang -### --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN:   -ggdb -gz=zlib 2>&1 | FileCheck %s

MaskRay wrote:
> Is `-target` (or `--target=`)  needed?
yes. added



Comment at: clang/test/Driver/hip-gz-options.hip:15
+// CHECK: {{".*ld.*" .* "--compress-debug-sections=zlib"}}
+

MaskRay wrote:
> Delete trailing empty lines
done


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87321/new/

https://reviews.llvm.org/D87321

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 291229.
eduucaldas marked an inline comment as done.
eduucaldas added a comment.

`createPunctuation`, `createKeyword` -> `createLeaf`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87495/new/

https://reviews.llvm.org/D87495

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -12,33 +12,81 @@
 
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "gtest/gtest.h"
 
 using namespace clang;
 using namespace clang::syntax;
 
 namespace {
 
-INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, SyntaxTreeTest,
+class SynthesisTest : public SyntaxTreeTest {
+protected:
+  ::testing::AssertionResult treeDumpEqual(syntax::Node *Root, StringRef Dump) {
+if (!Root)
+  return ::testing::AssertionFailure()
+ << "Root was not built successfully.";
+
+auto Actual = StringRef(Root->dump(Arena->getSourceManager())).trim().str();
+auto Expected = Dump.trim().str();
+// EXPECT_EQ shows the diff between the two strings if they are different.
+EXPECT_EQ(Expected, Actual);
+if (Actual != Expected) {
+  return ::testing::AssertionFailure();
+}
+return ::testing::AssertionSuccess();
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(SynthesisTests, SynthesisTest,
 ::testing::ValuesIn(allTestClangConfigs()), );
 
-TEST_P(SyntaxTreeTest, Leaf_Punctuation) {
+TEST_P(SynthesisTest, Leaf_Punctuation) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::comma);
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+',' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Keyword) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::kw_if);
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'if' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Identifier) {
   buildTree("", GetParam());
 
-  auto *C = syntax::createPunctuation(*Arena, tok::comma);
-  ASSERT_NE(C, nullptr);
-  EXPECT_EQ(C->getToken()->kind(), tok::comma);
-  EXPECT_TRUE(C->canModify());
-  EXPECT_FALSE(C->isOriginal());
-  EXPECT_TRUE(C->isDetached());
+  auto *C = createLeaf(*Arena, tok::identifier, "a");
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'a' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Number) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::numeric_constant, "1");
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'1' Detached synthesized
+  )txt"));
 }
 
-TEST_P(SyntaxTreeTest, Statement_Empty) {
+TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
-  auto *S = syntax::createEmptyStatement(*Arena);
-  ASSERT_NE(S, nullptr);
-  EXPECT_TRUE(S->canModify());
-  EXPECT_FALSE(S->isOriginal());
-  EXPECT_TRUE(S->isDetached());
+  auto *S = createEmptyStatement(*Arena);
+  EXPECT_TRUE(treeDumpEqual(S, R"txt(
+EmptyStatement Detached synthesized
+`-';' synthesized
+  )txt"));
 }
 } // namespace
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -5,13 +5,14 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===--===//
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
 
 using namespace clang;
 
 /// Exposes private syntax tree APIs required to implement node synthesis.
 /// Should not be used for anything else.
-class syntax::FactoryImpl {
+class clang::syntax::FactoryImpl {
 public:
   static void setCanModify(syntax::Node *N) { N->CanModify = true; }
 
@@ -21,24 +22,38 @@
   }
 };
 
-clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
-   clang::tok::TokenKind K) {
-  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
-clang::tok::getPunctuatorSpelling(K)))
-.second;
+namespace {
+syntax::Leaf *createLeafLowLevel(syntax::Arena &A, StringRef Spelling) {
+  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(Spelling)).second;
   assert(Tokens.size() == 1);
-  assert(Tokens.front().kind() == K);
-  auto *L = new (A.getAllocator()) clang::syntax::Leaf(Tokens.begin());
-  FactoryImpl::setCanModify(L);
+  auto *L = new (A.getAllocator()) syntax::Leaf(Tokens.begin());
+  syntax::FactoryImpl::setCanModify(L);
   L->assertInvariants();
   return L;
 }
+} // namespace
 
-clang::syntax::EmptyStatement *
-syntax::createEmptyStatement(clang::syntax::Arena &A) {
-  auto *S = new (A.getAll

[PATCH] D82598: [analyzer][Liveness][NFC] Get rid of statement liveness, because such a thing doesn't exist

2020-09-11 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus updated this revision to Diff 291231.
Szelethus added a comment.

Rename the live statements checker to live expressions checker. The test file 
added in a revert commit changed rather heavily, but it makes sense that these 
entries are removed IMO. Unless anyone objects, I'll intend to land this as-is.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82598/new/

https://reviews.llvm.org/D82598

Files:
  clang/docs/analyzer/developer-docs/DebugChecks.rst
  clang/include/clang/Analysis/Analyses/LiveVariables.h
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  clang/lib/Analysis/LiveVariables.cpp
  clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
  clang/lib/StaticAnalyzer/Core/Environment.cpp
  clang/lib/StaticAnalyzer/Core/SymbolManager.cpp
  clang/test/Analysis/live-stmts.cpp
  clang/test/Analysis/live-stmts.mm

Index: clang/test/Analysis/live-stmts.mm
===
--- clang/test/Analysis/live-stmts.mm
+++ clang/test/Analysis/live-stmts.mm
@@ -1,5 +1,5 @@
 // RUN: %clang_analyze_cc1 -w -fblocks %s \
-// RUN:   -analyzer-checker=debug.DumpLiveStmts \
+// RUN:   -analyzer-checker=debug.DumpLiveExprs \
 // RUN:   2>&1 | FileCheck %s
 
 @interface Item
@@ -18,25 +18,25 @@
 public:
   RAII(Blk blk): blk(blk) {}
 
-// CHECK: [ B0 (live statements at block exit) ]
+// CHECK: [ B0 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B1 (live statements at block exit) ]
+// CHECK-NEXT: [ B1 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B2 (live statements at block exit) ]
+// CHECK-NEXT: [ B2 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
 
   ~RAII() { blk(); }
 
-// CHECK-NEXT: [ B0 (live statements at block exit) ]
+// CHECK-NEXT: [ B0 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B1 (live statements at block exit) ]
+// CHECK-NEXT: [ B1 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B2 (live statements at block exit) ]
+// CHECK-NEXT: [ B2 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
 };
@@ -45,57 +45,37 @@
   RAII raii(^{});
   for (Item *item in coll) {}
 }
-// CHECK-NEXT: [ B0 (live statements at block exit) ]
+// CHECK-NEXT: [ B0 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B1 (live statements at block exit) ]
+// CHECK-NEXT: [ B1 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B2 (live statements at block exit) ]
-// CHECK-EMPTY:
-// CHECK-NEXT: DeclStmt {{.*}}
-// CHECK-NEXT: `-VarDecl {{.*}}  item 'Item *'
+// CHECK-NEXT: [ B2 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'Collection *' 
 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'Collection *' lvalue ParmVar {{.*}} 'coll' 'Collection *'
 // CHECK-EMPTY:
-// CHECK-NEXT: CompoundStmt {{.*}}
-// CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B3 (live statements at block exit) ]
-// CHECK-EMPTY:
-// CHECK-NEXT: DeclStmt {{.*}}
-// CHECK-NEXT: `-VarDecl {{.*}}  item 'Item *'
+// CHECK-NEXT: [ B3 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'Collection *' 
 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'Collection *' lvalue ParmVar {{.*}} 'coll' 'Collection *'
 // CHECK-EMPTY:
-// CHECK-NEXT: CompoundStmt {{.*}}
-// CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B4 (live statements at block exit) ]
-// CHECK-EMPTY:
-// CHECK-NEXT: DeclStmt {{.*}}
-// CHECK-NEXT: `-VarDecl {{.*}}  item 'Item *'
+// CHECK-NEXT: [ B4 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-NEXT: ImplicitCastExpr {{.*}} 'Collection *' 
 // CHECK-NEXT: `-DeclRefExpr {{.*}} 'Collection *' lvalue ParmVar {{.*}} 'coll' 'Collection *'
 // CHECK-EMPTY:
-// CHECK-NEXT: CompoundStmt {{.*}}
-// CHECK-EMPTY:
-// CHECK-EMPTY:
-// CHECK-NEXT: [ B5 (live statements at block exit) ]
-// CHECK-EMPTY:
-// CHECK-NEXT: DeclStmt {{.*}}
-// CHECK-NEXT: `-VarDecl {{.*}}  item 'Item *'
 // CHECK-EMPTY:
-// CHECK-NEXT: CompoundStmt {{.*}}
+// CHECK-NEXT: [ B5 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B0 (live statements at block exit) ]
+// CHECK-NEXT: [ B0 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
-// CHECK-NEXT: [ B1 (live statements at block exit) ]
+// CHECK-NEXT: [ B1 (live expressions at block exit) ]
 // CHECK-EMPTY:
 // CHECK-EMPTY:
 
Index: clang/test/Analysis/live-stmts.cpp
===
--- clang/test/Analysis/live-stmts.cpp
+++ clang/test/Analysis/live-stmts.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 -w -analyzer-checker=debug.DumpLiveStmts %s 2>&1\
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=debug.DumpLiveExprs %s 2>&1\
 // RUN:   | FileChec

[PATCH] D87449: [clang-tidy] Add new check for SEI CERT rule SIG30-C.

2020-09-11 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 291238.
balazske added a comment.

Added entry to release notes and fixed wrong comment in test headers.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87449/new/

https://reviews.llvm.org/D87449

Files:
  clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp
  clang-tools-extra/clang-tidy/cert/CMakeLists.txt
  clang-tools-extra/clang-tidy/cert/SignalHandlerCheck.cpp
  clang-tools-extra/clang-tidy/cert/SignalHandlerCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/cert-sig30-c.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
  clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
  clang-tools-extra/test/clang-tidy/checkers/cert-sig30-c.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cert-sig30-c.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cert-sig30-c.cpp
@@ -0,0 +1,72 @@
+// RUN: %check_clang_tidy %s cert-sig30-c %t -- -- -isystem %S/Inputs/Headers
+
+#include "signal.h"
+#include "stdio.h"
+#include "stdlib.h"
+
+void handler_abort(int) {
+  abort();
+}
+
+void handler__Exit(int) {
+  _Exit(0);
+}
+
+void handler_quick_exit(int) {
+  quick_exit(0);
+}
+
+void handler_other(int) {
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Signal handler potentially calls non asynchronous-safe function. This may result in undefined behavior. [cert-sig30-c]
+}
+
+void handler_signal(int) {
+  // FIXME: It is only OK to call signal with the current signal number.
+  signal(0, SIG_DFL);
+}
+
+void f_ok() {
+  abort();
+}
+
+void f_bad() {
+  printf("1234");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: Signal handler potentially calls non asynchronous-safe function. This may result in undefined behavior. [cert-sig30-c]
+}
+
+void f_extern();
+
+void handler_ok(int) {
+  f_ok();
+  f_extern();
+}
+
+void handler_bad(int) {
+  f_bad();
+}
+
+// Function called "signal" that is not to be recognized by the checker.
+typedef void (*callback_t)(int);
+void signal(int, callback_t, int);
+
+void test() {
+  signal(SIGINT, handler_abort);
+  signal(SIGINT, handler__Exit);
+  signal(SIGINT, handler_quick_exit);
+  signal(SIGINT, handler_signal);
+  signal(SIGINT, handler_other);
+
+  signal(SIGINT, handler_ok);
+  signal(SIGINT, handler_bad);
+
+  signal(SIGINT, quick_exit);
+  signal(SIGINT, other_call);
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: Signal handler potentially calls non asynchronous-safe function. This may result in undefined behavior. [cert-sig30-c]
+
+  signal(SIGINT, SIG_IGN);
+  signal(SIGINT, SIG_DFL);
+
+  // Do not find problems here.
+  signal(SIGINT, handler_bad, 1);
+}
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/stdlib.h
@@ -0,0 +1,18 @@
+//===--- stdlib.h - Stub header for tests ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _STDLIB_H_
+#define _STDLIB_H_
+
+void abort(void);
+void _Exit(int __status);
+void quick_exit(int __status);
+
+void other_call(int);
+
+#endif // _STDLIB_H_
Index: clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/signal.h
@@ -0,0 +1,22 @@
+//===--- signal.h - Stub header for tests ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _SIGNAL_H_
+#define _SIGNAL_H_
+
+void _sig_ign(int);
+void _sig_dfl(int);
+
+#define SIGINT 1
+#define SIG_IGN _sig_ign
+#define SIG_DFL _sig_dfl
+
+typedef void (*sighandler_t)(int);
+sighandler_t signal(int signum, sighandler_t handler);
+
+#endif // _SIGNAL_H_
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -114,6 +114,7 @@
`cert-msc51-cpp `_,
`cert-oop57-cpp `_,
`cert-oop58-cpp `_,
+   `cert-sig30-c `_,
`clang-analyzer-core.DynamicTypePropagation `_,
`clang-analyzer-core.uninitialized.CapturedBlockVariable

[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas added inline comments.



Comment at: clang/lib/Tooling/Syntax/Synthesis.cpp:51
+  return createLeaf(A, tok::getKeywordSpelling(K), K);
+}
+

gribozavr2 wrote:
> eduucaldas wrote:
> > gribozavr2 wrote:
> > > Could we make a combined function that does not require the user to make 
> > > a distinction between punctuation and keywords?
> > > 
> > > We should also allow creating tokens that have a user-specified spelling, 
> > > for example, identifiers and string literals.
> > > 
> > > So maybe define two functions:
> > > 
> > > ```
> > > // Uses the provided spelling.
> > > syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K, StringRef 
> > > Spelling);
> > > 
> > > // Infers spelling if possible.
> > > syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K);
> > > ```
> > > 
> > First, thanks for the great comments!
> > 
> > > Could we make a combined function that does not require the user to make 
> > > a distinction between punctuation and keywords?
> > We could! 
> > Bui I wouldn't call it `createLeaf`, as it would work strictly for 
> > `Keyword`s or `Punctuator`s. 
> > As an alternative we could unify the `createPunctuator`and `createKeyword` 
> > into `createPunctuatorOrKeyword` but I would argue that the previous two 
> > names are more readable. Effectively, we would be unifying those 2 
> > functions because they have the same signature.
> > 
> > > We should also allow creating tokens that have a user-specified spelling, 
> > > for example, identifiers and string literals.
> > That exists already! It is `createLeaf` as is!
> > but I would argue that the previous two names are more readable. 
> > Effectively, we would be unifying those 2 functions because they have the 
> > same signature.
> 
> I don't think the user cares very much about whether their token is a keyword 
> or a punctuation. Furthermore, most callsites will have the token kind as an 
> argument, so saying that it is a keyword or punctuation is redundant:
> 
> ```
> createKeyword(Arena, tok::kw_if); // Yeah, 'if' is a keyword.
> ```
> 
> The semantics of the combined function I'm proposing is "create a token that 
> has one fixed spelling". The other function is "create a token where the 
> spelling is user-provided".
I think the user cares about whether their token is a keyword.

It's is somewhat redundant yes, but I don't think that hurts, we are still 
specifying that the keyword being used is `if`.

I see your points, and I don't have a strong opinion so I'm updating the patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87495/new/

https://reviews.llvm.org/D87495

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87518: [analyzer][Liveness][NFC] Remove an unneeded pass to collect variables that appear in an assignment

2020-09-11 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: xazax.hun, NoQ, vsavchenko, martong, balazske, 
baloghadamsoftware, steakhal.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, gamesh411, 
dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, whisperity.
Szelethus requested review of this revision.

Suppose you stumble across a `DeclRefExpr` in the AST, that references a 
`VarDecl`. How would you know that that variable is written in the containing 
statement, or not? One trick would be to ascend the AST through 
`Stmt::getParent`, and see whether the variable appears on the left hand side 
of the assignment.

Liveness does something similar, but instead of //ascending// the AST, it 
//descends// into it with a `StmtVisitor`. However, as [1] demonstrates, the 
analysis isn't ran on the AST of an entire function, but rather on CFG, where 
the order of the statements, visited in order, would make it impossible to know 
this information by descending.

  void f() {
int i;
  
i = 5;
  }



  `-FunctionDecl 0x55a6e1b070b8  line:1:6 f 'void ()'
`-CompoundStmt 0x55a6e1b07298 
  |-DeclStmt 0x55a6e1b07220 
  | `-VarDecl 0x55a6e1b071b8  col:7 used i 'int'
  `-BinaryOperator 0x55a6e1b07278  'int' lvalue '='
|-DeclRefExpr 0x55a6e1b07238  'int' lvalue Var 0x55a6e1b071b8 
'i' 'int'
`-IntegerLiteral 0x55a6e1b07258  'int' 5



  void f()
   [B2 (ENTRY)]
 Succs (1): B1
  
   [B1]
 1: int i;
 2: 5
 3: i
 4: [B1.3] = [B1.2]
 Preds (1): B2
 Succs (1): B0
  
   [B0 (EXIT)]
 Preds (1): B1

You can see that the arguments (rightfully so, they need to be evaluated first) 
precede the assignment operator. For this reason, Liveness implemented a pass 
to scan the CFG and note which variables appear in an assignment.

BUT.

This problem only exists if we traverse a CFGBlock in order. And Liveness in 
fact does it reverse order. So a distinct pass is indeed unnecessary, we can 
note the appearance of the assignment by the time we reach the variable.

[1] http://lists.llvm.org/pipermail/cfe-dev/2020-July/066330.html


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87518

Files:
  clang/include/clang/Analysis/CFG.h
  clang/lib/Analysis/LiveVariables.cpp


Index: clang/lib/Analysis/LiveVariables.cpp
===
--- clang/lib/Analysis/LiveVariables.cpp
+++ clang/lib/Analysis/LiveVariables.cpp
@@ -323,6 +323,11 @@
 }
 
 void TransferFunctions::VisitBinaryOperator(BinaryOperator *B) {
+  if (LV.killAtAssign && B->getOpcode() == BO_Assign) {
+if (const auto *DR = dyn_cast(B->getLHS()->IgnoreParens())) {
+  LV.inAssignment[DR] = 1;
+}
+  }
   if (B->isAssignmentOp()) {
 if (!LV.killAtAssign)
   return;
@@ -511,29 +516,8 @@
   llvm::BitVector everAnalyzedBlock(cfg->getNumBlockIDs());
 
   // FIXME: we should enqueue using post order.
-  for (CFG::const_iterator it = cfg->begin(), ei = cfg->end(); it != ei; ++it) 
{
-const CFGBlock *block = *it;
-worklist.enqueueBlock(block);
-
-// FIXME: Scan for DeclRefExprs using in the LHS of an assignment.
-// We need to do this because we lack context in the reverse analysis
-// to determine if a DeclRefExpr appears in such a context, and thus
-// doesn't constitute a "use".
-if (killAtAssign)
-  for (CFGBlock::const_iterator bi = block->begin(), be = block->end();
-   bi != be; ++bi) {
-if (Optional cs = bi->getAs()) {
-  const Stmt* stmt = cs->getStmt();
-  if (const auto *BO = dyn_cast(stmt)) {
-if (BO->getOpcode() == BO_Assign) {
-  if (const auto *DR =
-dyn_cast(BO->getLHS()->IgnoreParens())) {
-LV->inAssignment[DR] = 1;
-  }
-}
-  }
-}
-  }
+  for (const CFGBlock *B : cfg->nodes()) {
+worklist.enqueueBlock(B);
   }
 
   while (const CFGBlock *block = worklist.dequeue()) {
Index: clang/include/clang/Analysis/CFG.h
===
--- clang/include/clang/Analysis/CFG.h
+++ clang/include/clang/Analysis/CFG.h
@@ -1307,6 +1307,10 @@
 
   iterator nodes_begin() { return iterator(Blocks.begin()); }
   iterator nodes_end() { return iterator(Blocks.end()); }
+
+  llvm::iterator_range nodes() { return *this; }
+  llvm::iterator_range const_nodes() const { return *this; }
+
   const_iterator nodes_begin() const { return const_iterator(Blocks.begin()); }
   const_iterator nodes_end() const { return const_iterator(Blocks.end()); }
 
@@ -1315,6 +1319,13 @@
   const_reverse_iteratorrbegin()  const{ return Blocks.rbegin(); }
   const_reverse_iteratorrend()const{ return Blocks.rend(); }
 
+  llvm::iterator_range reverse_nodes() {
+return {rbegin(), rend()};
+  }
+  llvm::iterator_range const_reverse_nodes() const {
+return {rbeg

[PATCH] D87495: [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 291239.
eduucaldas added a comment.

fix clang-tidy warning


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87495/new/

https://reviews.llvm.org/D87495

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -12,33 +12,81 @@
 
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "gtest/gtest.h"
 
 using namespace clang;
 using namespace clang::syntax;
 
 namespace {
 
-INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, SyntaxTreeTest,
+class SynthesisTest : public SyntaxTreeTest {
+protected:
+  ::testing::AssertionResult treeDumpEqual(syntax::Node *Root, StringRef Dump) {
+if (!Root)
+  return ::testing::AssertionFailure()
+ << "Root was not built successfully.";
+
+auto Actual = StringRef(Root->dump(Arena->getSourceManager())).trim().str();
+auto Expected = Dump.trim().str();
+// EXPECT_EQ shows the diff between the two strings if they are different.
+EXPECT_EQ(Expected, Actual);
+if (Actual != Expected) {
+  return ::testing::AssertionFailure();
+}
+return ::testing::AssertionSuccess();
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(SynthesisTests, SynthesisTest,
 ::testing::ValuesIn(allTestClangConfigs()), );
 
-TEST_P(SyntaxTreeTest, Leaf_Punctuation) {
+TEST_P(SynthesisTest, Leaf_Punctuation) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::comma);
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+',' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Keyword) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::kw_if);
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'if' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Identifier) {
   buildTree("", GetParam());
 
-  auto *C = syntax::createPunctuation(*Arena, tok::comma);
-  ASSERT_NE(C, nullptr);
-  EXPECT_EQ(C->getToken()->kind(), tok::comma);
-  EXPECT_TRUE(C->canModify());
-  EXPECT_FALSE(C->isOriginal());
-  EXPECT_TRUE(C->isDetached());
+  auto *C = createLeaf(*Arena, tok::identifier, "a");
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'a' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Number) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::numeric_constant, "1");
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'1' Detached synthesized
+  )txt"));
 }
 
-TEST_P(SyntaxTreeTest, Statement_Empty) {
+TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
-  auto *S = syntax::createEmptyStatement(*Arena);
-  ASSERT_NE(S, nullptr);
-  EXPECT_TRUE(S->canModify());
-  EXPECT_FALSE(S->isOriginal());
-  EXPECT_TRUE(S->isDetached());
+  auto *S = createEmptyStatement(*Arena);
+  EXPECT_TRUE(treeDumpEqual(S, R"txt(
+EmptyStatement Detached synthesized
+`-';' synthesized
+  )txt"));
 }
 } // namespace
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -5,13 +5,14 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===--===//
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
 
 using namespace clang;
 
 /// Exposes private syntax tree APIs required to implement node synthesis.
 /// Should not be used for anything else.
-class syntax::FactoryImpl {
+class clang::syntax::FactoryImpl {
 public:
   static void setCanModify(syntax::Node *N) { N->CanModify = true; }
 
@@ -21,24 +22,38 @@
   }
 };
 
-clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
-   clang::tok::TokenKind K) {
-  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
-clang::tok::getPunctuatorSpelling(K)))
-.second;
+namespace {
+syntax::Leaf *createLeafLowLevel(syntax::Arena &A, StringRef Spelling) {
+  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(Spelling)).second;
   assert(Tokens.size() == 1);
-  assert(Tokens.front().kind() == K);
-  auto *L = new (A.getAllocator()) clang::syntax::Leaf(Tokens.begin());
-  FactoryImpl::setCanModify(L);
+  auto *L = new (A.getAllocator()) syntax::Leaf(Tokens.begin());
+  syntax::FactoryImpl::setCanModify(L);
   L->assertInvariants();
   return L;
 }
+} // namespace
 
-clang::syntax::EmptyStatement *
-syntax::createEmptyStatement(clang::syntax::Arena &A) {
-  auto *S = new (A.getAllocator()) clang::syntax::EmptyStatement;
+syntax::Leaf *clang::syntax::crea

Re: r364428 - Make CodeGen depend on ASTMatchers

2020-09-11 Thread Vassil Vassilev via cfe-commits

Thanks a lot!
On 9/11/20 6:20 PM, Michael LIAO wrote:

b22d4504968 was committed last night.

On Fri, Sep 11, 2020 at 9:30 AM Vassil Vassilev  wrote:

On 9/11/20 5:13 AM, Michael LIAO wrote:

That change was added long ago to fix the shared library build.
Possibly, there are changes removing that dependency then. Just
verified that removing that dependency is just fine.


That's great! Would you commit that change or should I?



On Thu, Sep 10, 2020 at 6:48 AM Vassil Vassilev  wrote:

Hello,

 IIUC, clang's CodeGen does not immediately depend on ASTMatchers. I
was wondering what is the reason for inserting such a dependency to fix
the shared library builds?

 Can you give more details about the failure you are fixing?

 Sorry for the late question.

Best, Vassil
On 6/26/19 5:13 PM, Michael Liao via cfe-commits wrote:

Author: hliao
Date: Wed Jun 26 07:13:43 2019
New Revision: 364428

URL: http://llvm.org/viewvc/llvm-project?rev=364428&view=rev
Log:
Make CodeGen depend on ASTMatchers

- Shared library builds are broken due to the missing dependency.

Modified:
   cfe/trunk/lib/CodeGen/CMakeLists.txt

Modified: cfe/trunk/lib/CodeGen/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CMakeLists.txt?rev=364428&r1=364427&r2=364428&view=diff
==
--- cfe/trunk/lib/CodeGen/CMakeLists.txt (original)
+++ cfe/trunk/lib/CodeGen/CMakeLists.txt Wed Jun 26 07:13:43 2019
@@ -101,6 +101,7 @@ add_clang_library(clangCodeGen
  LINK_LIBS
  clangAnalysis
  clangAST
+  clangASTMatchers
  clangBasic
  clangFrontend
  clangLex


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87449: [clang-tidy] Add new check for SEI CERT rule SIG30-C.

2020-09-11 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:94
+
+- New :doc:`cert-sig30-c
+  ` check.

Please rebase from trunk.  New checks section is above and somehow header is 
missed in your file.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87449/new/

https://reviews.llvm.org/D87449

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87519: [analyzer][Liveness][NFC] Enqueue the CFGBlocks post-order

2020-09-11 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: xazax.hun, NoQ, vsavchenko, balazske, martong, 
baloghadamsoftware, steakhal.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, ASDenysPetrov, Charusso, gamesh411, 
dkrupp, donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, whisperity.
Szelethus requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87519

Files:
  clang/lib/Analysis/LiveVariables.cpp


Index: clang/lib/Analysis/LiveVariables.cpp
===
--- clang/lib/Analysis/LiveVariables.cpp
+++ clang/lib/Analysis/LiveVariables.cpp
@@ -13,6 +13,7 @@
 #include "clang/Analysis/Analyses/LiveVariables.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Analysis/Analyses/PostOrderCFGView.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowWorklist.h"
@@ -502,6 +503,9 @@
   CFG *cfg = AC.getCFG();
   if (!cfg)
 return nullptr;
+  assert(AC.getAnalysis() &&
+ "If the CFG exists, we should be able to create a post order view of "
+ "it!");
 
   // The analysis currently has scalability issues for very large CFGs.
   // Bail out if it looks too large.
@@ -510,13 +514,12 @@
 
   LiveVariablesImpl *LV = new LiveVariablesImpl(AC, killAtAssign);
 
-  // Construct the dataflow worklist.  Enqueue the exit block as the
+  // Construct the dataflow worklist. Enqueue the exit block as the
   // start of the analysis.
   BackwardDataflowWorklist worklist(*cfg, AC);
   llvm::BitVector everAnalyzedBlock(cfg->getNumBlockIDs());
 
-  // FIXME: we should enqueue using post order.
-  for (const CFGBlock *B : cfg->nodes()) {
+  for (const CFGBlock *B : *AC.getAnalysis()) {
 worklist.enqueueBlock(B);
   }
 


Index: clang/lib/Analysis/LiveVariables.cpp
===
--- clang/lib/Analysis/LiveVariables.cpp
+++ clang/lib/Analysis/LiveVariables.cpp
@@ -13,6 +13,7 @@
 #include "clang/Analysis/Analyses/LiveVariables.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Analysis/Analyses/PostOrderCFGView.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowWorklist.h"
@@ -502,6 +503,9 @@
   CFG *cfg = AC.getCFG();
   if (!cfg)
 return nullptr;
+  assert(AC.getAnalysis() &&
+ "If the CFG exists, we should be able to create a post order view of "
+ "it!");
 
   // The analysis currently has scalability issues for very large CFGs.
   // Bail out if it looks too large.
@@ -510,13 +514,12 @@
 
   LiveVariablesImpl *LV = new LiveVariablesImpl(AC, killAtAssign);
 
-  // Construct the dataflow worklist.  Enqueue the exit block as the
+  // Construct the dataflow worklist. Enqueue the exit block as the
   // start of the analysis.
   BackwardDataflowWorklist worklist(*cfg, AC);
   llvm::BitVector everAnalyzedBlock(cfg->getNumBlockIDs());
 
-  // FIXME: we should enqueue using post order.
-  for (const CFGBlock *B : cfg->nodes()) {
+  for (const CFGBlock *B : *AC.getAnalysis()) {
 worklist.enqueueBlock(B);
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87520: [tests][compiler-rt] Implement generic_ldbl{80,128}_test targets

2020-09-11 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko created this revision.
atrosinenko added reviewers: MaskRay, howard.hinnant, samsonov.
Herald added subscribers: Sanitizers, mgorny, dberris.
Herald added a project: Sanitizers.
atrosinenko requested review of this revision.
Herald added a subscriber: aheejin.

This patch introduces two "generic" pseudo targets to simplify testing
the changes to builtins library on a developer machine.

These targets

- ignore any target-specific subdirectories
- use the specified size of `long double` (this may simplify testing of 
QUAD_PRECISION libcall variants when working on a generic implementation on an 
X86 host)
- are intended *for testing only*
- may produce false positives (at least when non-default size of `long double` 
is selected)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87520

Files:
  compiler-rt/cmake/base-config-ix.cmake
  compiler-rt/cmake/builtin-config-ix.cmake
  compiler-rt/lib/builtins/CMakeLists.txt
  compiler-rt/test/builtins/Unit/addtf3_test.c
  compiler-rt/test/builtins/Unit/compiler_rt_logbl_test.c
  compiler-rt/test/builtins/Unit/divtc3_test.c
  compiler-rt/test/builtins/Unit/divxc3_test.c
  compiler-rt/test/builtins/Unit/subtf3_test.c

Index: compiler-rt/test/builtins/Unit/subtf3_test.c
===
--- compiler-rt/test/builtins/Unit/subtf3_test.c
+++ compiler-rt/test/builtins/Unit/subtf3_test.c
@@ -58,6 +58,7 @@
  UINT64_C(0xa44a7bca780a166c)))
 return 1;
 
+#if !defined(GENERIC_TARGET)
 #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \
 defined(i386) || defined(__x86_64__)
 // Rounding mode tests on supported architectures
@@ -87,6 +88,7 @@
  UINT64_C(0x70a3d70a3d70a3d7)))
 return 1;
 #endif
+#endif // !defined(GENERIC_TARGET)
 
 #else
 printf("skipped\n");
Index: compiler-rt/test/builtins/Unit/divxc3_test.c
===
--- compiler-rt/test/builtins/Unit/divxc3_test.c
+++ compiler-rt/test/builtins/Unit/divxc3_test.c
@@ -5,6 +5,10 @@
 // UNSUPPORTED: mips
 // REQUIRES: c99-complex
 
+// `long double` should have its default target-specific size
+// to be `classify()`ed properly.
+// XFAIL: generic_ldbl80-target-arch
+
 #if !_ARCH_PPC
 
 #include "int_lib.h"
Index: compiler-rt/test/builtins/Unit/divtc3_test.c
===
--- compiler-rt/test/builtins/Unit/divtc3_test.c
+++ compiler-rt/test/builtins/Unit/divtc3_test.c
@@ -6,6 +6,11 @@
 // Bug 42493
 // XFAIL: sparc-target-arch
 //
+
+// `long double` should have its default target-specific size
+// to be `classify()`ed properly.
+// XFAIL: generic_ldbl128-target-arch
+
 #include 
 
 #include "int_lib.h"
Index: compiler-rt/test/builtins/Unit/compiler_rt_logbl_test.c
===
--- compiler-rt/test/builtins/Unit/compiler_rt_logbl_test.c
+++ compiler-rt/test/builtins/Unit/compiler_rt_logbl_test.c
@@ -6,7 +6,11 @@
 #include "fp_lib.h"
 #include "int_lib.h"
 
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+// GENERIC_TARGET may have non-default sizeof(long double), so it is useless
+// to compare __compiler_rt_logbl() against native logbl().
+
+#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) && \
+!defined(GENERIC_TARGET)
 
 int test__compiler_rt_logbl(fp_t x) {
   fp_t crt_value = __compiler_rt_logbl(x);
@@ -38,7 +42,8 @@
 #endif
 
 int main() {
-#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT) && \
+!defined(GENERIC_TARGET)
   const unsigned N = sizeof(cases) / sizeof(cases[0]);
   unsigned i;
   for (i = 0; i < N; ++i) {
Index: compiler-rt/test/builtins/Unit/addtf3_test.c
===
--- compiler-rt/test/builtins/Unit/addtf3_test.c
+++ compiler-rt/test/builtins/Unit/addtf3_test.c
@@ -65,6 +65,7 @@
  UINT64_C(0x61e58dd6c51eb77c)))
 return 1;
 
+#if !defined(GENERIC_TARGET)
 #if (defined(__arm__) || defined(__aarch64__)) && defined(__ARM_FP) || \
 defined(i386) || defined(__x86_64__)
 // Rounding mode tests on supported architectures
@@ -95,6 +96,7 @@
  UINT64_C(0x70a3d70a3d70a3d7)))
 return 1;
 #endif
+#endif // !defined(GENERIC_TARGET)
 
 #else
 printf("skipped\n");
Index: compiler-rt/lib/builtins/CMakeLists.txt
===
--- compiler-rt/lib/builtins/CMakeLists.txt
+++ compiler-rt/lib/builtins/CMakeLists.txt
@@ -603,6 +603,16 @@
   ${GENERIC_TF_SOURCES}
   ${GENERIC_SOURCES})
 
+# For local testing only.
+set(generic_ldbl80_SOURCES
+  ${GENERIC_SOURCES}
+  ${x86_80_BIT_SOURCES}
+)
+set(generic_ldbl128_SOURCES
+  ${GENERIC_SOURCES}
+  ${GENERIC_TF_SOURCES}
+)
+
 add_custom_target(builtins)
 set_target_properties(builtins PROPERTIES F

[PATCH] D86694: [scudo] Allow -fsanitize=scudo on Linux and Windows (WIP, don't land as is)

2020-09-11 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop updated this revision to Diff 291235.
russell.gallop edited the summary of this revision.
russell.gallop added a comment.
Herald added subscribers: phosek, hiraditya.

Fixup scudo (sanitizer based) to work on Windows.

This makes use of the CRT alloc hooks from D71786 
.

To build with scudo on Windows use: 
-DLLVM_INTEGRATED_CRT_ALLOC=/stage1/lib/clang/12.0.0/lib/windows/clang_rt.scudo-x86_64.lib
 -DLLVM_USE_CRT_RELEASE=MT 
-DLLVM_USE_SANITIZER=Scudo is supported in this patch, but isn't required. 
@cryptoad on Linux does this do anything other than add libraries when using 
clang to drive the linker?

Limitations:
-Note that this is not using hardware CRC32.
-This just hooks in the C scudo library, not the cxx library

I evaluated this on a 3 stage LLVM build on Windows 10 2004 (in vs2019 16.7.3 
environment) on a 6-core i7-8700k.

- stage1 builds the scudo sanitizer on Windows: requires 
-DLLVM_ENABLE_PROJECTS=clang;lld;compiler-rt
- stage2: built with -DCMAKE_C_COMPILER="/bin/clang-cl.exe" 
-DCMAKE_CXX_COMPILER="/bin/clang-cl.exe" 
-DCMAKE_LINKER="/bin/lld-link.exe" -DLLVM_USE_CRT_RELEASE=MT 
-DCMAKE_BUILD_TYPE=Release
- stage2_scudo: as stage2 plus 
-DLLVM_INTEGRATED_CRT_ALLOC=/lib/clang/12.0.0/lib/windows/clang_rt.scudo-x86_64.lib

Then evaluated linking clang with ThinLTO:

- stage3: -DCMAKE_C_COMPILER="/bin/clang-cl.exe" 
-DCMAKE_CXX_COMPILER="/bin/clang-cl.exe" 
-DCMAKE_LINKER="/bin/lld-link.exe" -DLLVM_USE_CRT_RELEASE=MT 
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_LTO=Thin
- stage3_scudo: -DCMAKE_C_COMPILER="/bin/clang-cl.exe" 
-DCMAKE_CXX_COMPILER="/bin/clang-cl.exe" 
-DCMAKE_LINKER="/bin/lld-link.exe" -DLLVM_USE_CRT_RELEASE=MT 
-DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_LTO=Thin

I set /threads:12 and removed /lldltocache.

Without SCUDO_OPTIONS scudo seems to be about 25% slower.

  >"hyperfine.exe" -m 3 -w 1 "cd stage3\repro && 
f:\git\llvm-project\stage2\bin\lld-link @response.txt" "cd stage3_scudo\repro 
&& f:\git\llvm-project\stage2_scudo\bin\lld-link @response.txt"
  Benchmark #1: cd stage3\repro && f:\git\llvm-project\stage2\bin\lld-link 
@response.txt
Time (mean ± σ): 268.209 s ±  4.966 s[User: 18.1 ms, System: 6.6 ms]
Range (min … max):   263.223 s … 273.155 s3 runs
  
  Benchmark #2: cd stage3_scudo\repro && 
f:\git\llvm-project\stage2_scudo\bin\lld-link @response.txt
Time (mean ± σ): 334.312 s ±  4.002 s[User: 2.4 ms, System: 14.6 ms]
Range (min … max):   329.889 s … 337.683 s3 runs
  
  Summary
'cd stage3\repro && f:\git\llvm-project\stage2\bin\lld-link @response.txt' 
ran
  1.25 ± 0.03 times faster than 'cd stage3_scudo\repro && 
f:\git\llvm-project\stage2_scudo\bin\lld-link @response.txt'

I set scudo options to disable quarantine and mismatch checking and it seems to 
be about 8% slower.

  >set 
SCUDO_OPTIONS=allocator_release_to_os_interval_ms=-1:QuarantineSizeKb=0:ThreadLocalQuarantineSizeKb=0:DeleteSizeMismatch=0:DeallocationTypeMismatch=0
  >"hyperfine.exe" -m 3 -w 1 "cd stage3\repro && 
f:\git\llvm-project\stage2\bin\lld-link @response.txt" "cd stage3_scudo\repro 
&& f:\git\llvm-project\stage2_scudo\bin\lld-link @response.txt"
  Benchmark #1: cd stage3\repro && f:\git\llvm-project\stage2\bin\lld-link 
@response.txt
Time (mean ± σ): 273.772 s ±  3.624 s[User: 1.3 ms, System: 8.6 ms]
Range (min … max):   269.806 s … 276.909 s3 runs
  
  Benchmark #2: cd stage3_scudo\repro && 
f:\git\llvm-project\stage2_scudo\bin\lld-link @response.txt
Time (mean ± σ): 296.593 s ±  2.362 s[User: 1.3 ms, System: 13.9 ms]
Range (min … max):   293.917 s … 298.391 s3 runs
  
  Summary
'cd stage3\repro && f:\git\llvm-project\stage2\bin\lld-link @response.txt' 
ran
  1.08 ± 0.02 times faster than 'cd stage3_scudo\repro && 
f:\git\llvm-project\stage2_scudo\bin\lld-link @response.txt'

It's worth noting that the run without scudo was not using all CPU so still 
hitting some locking issues but was still over 90%. With both scudo runs it was 
pegged at 100% CPU until near the end of the link.  From this it appears that 
the locking behaviour is better than the default allocator and would win out on 
a wide enough processor. The loss in straight line performance is potentially 
due to CRC calculations (not using hardware).

@cryptoad are those the best scudo flags to evaluate for performance?

I'm looking at porting scudo standalone to Windows.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86694/new/

https://reviews.llvm.org/D86694

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
  compiler-rt/lib/scudo/CMakeLists.txt
  compiler-rt/lib/scudo/scudo_allocator.cpp
  compiler-rt/lib/scudo/scudo_crc32.cpp
  compiler-rt/lib/scudo/scudo_new_delete.cpp
  compiler-rt/lib/scudo/scudo_platform.h
  compiler-rt/lib/scudo/scudo_tsd.h
  compiler-rt/lib/scudo/scudo_tsd_shared.cpp
  comp

[PATCH] D87321: Fix -gz=zlib options for linker

2020-09-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/compress.c:21
 
-// RUN: %clang -### -fintegrated-as -gz=none -x assembler -c %s 2>&1 | 
FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
-// RUN: %clang -### -fintegrated-as -gz=none -c %s 2>&1 | FileCheck 
-check-prefix CHECK-OPT_GZ_EQ_NONE %s
-// CHECK-OPT_GZ_EQ_NONE: "--compress-debug-sections=none"
-
-// RUN: %clang -### -fintegrated-as -gz=zlib -x assembler -c %s 2>&1 | 
FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
-// RUN: %clang -### -fintegrated-as -gz=zlib -c %s 2>&1 | FileCheck 
-check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
-// CHECK-OPT_GZ_EQ_ZLIB: "--compress-debug-sections=zlib"
-
-// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -x assembler -c %s 2>&1 | 
FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
-// RUN: %clang -### -fintegrated-as -gz=zlib-gnu -c %s 2>&1 | FileCheck 
-check-prefix CHECK-OPT_GZ_EQ_ZLIB_GNU %s
-// CHECK-OPT_GZ_EQ_ZLIB_GNU: "--compress-debug-sections=zlib-gnu"
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -fintegrated-as -gz=none 
-x assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -fintegrated-as -gz=none 
%s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_NONE %s

You can delete `-fintegrated-as` since it is the default for most targets/OSes.



Comment at: clang/test/Driver/compress.c:26
+// CHECK-OPT_GZ_EQ_NONE: {{".*clang.*".* "--compress-debug-sections=none"}}
+// CHECK-OPT_GZ_EQ_NONE: {{".*ld.*".* "--compress-debug-sections=none"}}
+

If the user sets CLANG_DEFAULT_LINKER to a string not containing "ld", this 
line will not match. Matching a different substring on the linker command line 
can be more robust, e.g. `"-m" "elf_x86_64"`



Comment at: clang/test/Driver/compress.c:30
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -fintegrated-as -gz=zlib 
%s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -fintegrated-as -gz=zlib -x 
assembler %s 2>&1 | FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s
+// RUN: %clang -### -target amdgcn-amd-amdhsa -fintegrated-as -gz=zlib %s 2>&1 
| FileCheck -check-prefix CHECK-OPT_GZ_EQ_ZLIB %s

Delete -fintegrated-as if it is the default on amdgcn-amd-amdhsa


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87321/new/

https://reviews.llvm.org/D87321

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87520: [tests][compiler-rt] Implement generic_ldbl{80,128}_test targets

2020-09-11 Thread Anatoly Trosinenko via Phabricator via cfe-commits
atrosinenko added a comment.

See rG553833958fd 
 as an 
example.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87520/new/

https://reviews.llvm.org/D87520

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86694: [scudo] Allow -fsanitize=scudo on Linux and Windows (WIP, don't land as is)

2020-09-11 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop added a comment.

In D86694#2242559 , @cryptoad wrote:

> In D86694#2242150 , @russell.gallop 
> wrote:
>
>> In D86694#2242140 , @cryptoad wrote:
>>
>>> That's awesome! Is it meant to eventually be committed or only be used for 
>>> comparison purposes?
>>
>> I'd like it to be committed, but can't claim I know the code from 
>> https://reviews.llvm.org/D42519 well enough. The good news is that I can 
>> build LLVM on Windows with this. Is there a good sanity check that it is 
>> actually using Scudo rather than silently using the standard alloc?
>
> Nothing except the tests. Compiling a sizeable application with Scudo as well.

Compiling clang and lld with Scudo and ThinLTO linking clang seems to work.

> The other point that is worth mentioning is that we moved all dev efforts to 
> the "standalone" version of Scudo (eg: the one not depending on 
> sanitizer_common in the standalone/ subdirectory).
> There is enough differences that there could be some significant 
> performance/mem footprint changes between the 2.

Thanks. I'm looking at porting the standalone variant, drawing on D42519 
 and Windows support from sanitizer_common. 
Does that sound like a reasonable approach?

> Also depending on what you want to compare, disabling the Quarantine and 
> other optional security features will make things faster and use less memory.

Would these be good flags to use:

  set 
SCUDO_OPTIONS=allocator_release_to_os_interval_ms=-1:QuarantineSizeKb=0:ThreadLocalQuarantineSizeKb=0:DeleteSizeMismatch=0:DeallocationTypeMismatch=0


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86694/new/

https://reviews.llvm.org/D86694

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D86841: [clang] Add mayprogress and llvm.loop.mustprogress attribute deduction

2020-09-11 Thread Atmn Patel via Phabricator via cfe-commits
atmnpatel updated this revision to Diff 291249.
atmnpatel added a comment.

More tightly follows both the C and C++ standards. `maynotprogress` is only 
added to C functions when compiled with C11 or later.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86841/new/

https://reviews.llvm.org/D86841

Files:
  clang/lib/CodeGen/CGLoopInfo.cpp
  clang/lib/CodeGen/CGLoopInfo.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/attr-noprogress.c
  clang/test/CodeGen/attr-noprogress.cpp
  clang/test/CodeGen/unwind-attr.c
  clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
  clang/test/CodeGenObjC/class-stubs.m
  clang/test/CodeGenObjC/gnu-exceptions.m
  clang/test/OpenMP/simd_metadata.c
  clang/test/Profile/c-unprofiled-blocks.c

Index: clang/test/Profile/c-unprofiled-blocks.c
===
--- clang/test/Profile/c-unprofiled-blocks.c
+++ clang/test/Profile/c-unprofiled-blocks.c
@@ -16,7 +16,7 @@
   // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
   while (--i) {}
 
-  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+  // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}, !llvm.loop [[LOOP1:!.*]]
   do {} while (i++ < 75);
 
   // PGOUSE: switch {{.*}} [
@@ -46,7 +46,7 @@
 // PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
 while (--i) {}
 
-// PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}{{$}}
+// PGOUSE: br i1 %{{[^,]*}}, label %{{[^,]*}}, label %{{[^,]*}}, !llvm.loop [[LOOP2:!.*]]
 do {} while (i++ < 75);
 
 // PGOUSE: switch {{.*}} [
Index: clang/test/OpenMP/simd_metadata.c
===
--- clang/test/OpenMP/simd_metadata.c
+++ clang/test/OpenMP/simd_metadata.c
@@ -137,7 +137,8 @@
 }
 // CHECK: store float {{.+}}, float* {{.+}}, align {{.+}}, !llvm.access.group ![[ACCESS_GROUP_13:[0-9]+]]
   }
-// CHECK: br label %{{.+}}, !llvm.loop [[LOOP_H3_HEADER:![0-9]+]]
+  // CHECK: br label %{{.+}}, !llvm.loop [[LOOP_H3_HEADER_INNER:![0-9]+]]
+  // CHECK: br label %{{.+}}, !llvm.loop [[LOOP_H3_HEADER:![0-9]+]]
 }
 
 // Metadata for h1:
Index: clang/test/CodeGenObjC/gnu-exceptions.m
===
--- clang/test/CodeGenObjC/gnu-exceptions.m
+++ clang/test/CodeGenObjC/gnu-exceptions.m
@@ -32,4 +32,4 @@
   log(1);
 }
 
-// CHECK: attributes [[TF]] = { noinline optnone "{{.*}} }
+// CHECK: attributes [[TF]] = { noinline optnone maynotprogress "{{.*}} }
Index: clang/test/CodeGenObjC/class-stubs.m
===
--- clang/test/CodeGenObjC/class-stubs.m
+++ clang/test/CodeGenObjC/class-stubs.m
@@ -55,7 +55,7 @@
 + (void) anotherClassMethod {
   [super classMethod];
 }
-// CHECK-LABEL: define internal void @"\01+[Derived(MyCategory) anotherClassMethod]"(i8* %self, i8* %_cmd) #0 {
+// CHECK-LABEL: define internal void @"\01+[Derived(MyCategory) anotherClassMethod]"(i8* %self, i8* %_cmd) #3 {
 // CHECK-NEXT: entry:
 // CHECK:[[SUPER:%.*]] = alloca %struct._objc_super, align 8
 // CHECK:[[METACLASS_REF:%.*]] = load %struct._class_t*, %struct._class_t** @"OBJC_CLASSLIST_SUP_REFS_$_", align 8
@@ -68,7 +68,7 @@
 - (void) anotherInstanceMethod {
   [super instanceMethod];
 }
-// CHECK-LABEL: define internal void @"\01-[Derived(MyCategory) anotherInstanceMethod]"(%0* %self, i8* %_cmd) #0 {
+// CHECK-LABEL: define internal void @"\01-[Derived(MyCategory) anotherInstanceMethod]"(%0* %self, i8* %_cmd) #3 {
 // CHECK-NEXT: entry:
 // CHECK:[[SUPER:%.*]] = alloca %struct._objc_super, align 8
 // CHECK:[[CLASS_REF:%.*]] = call %struct._class_t* @objc_loadClassref(i8** @"OBJC_CLASSLIST_SUP_REFS_$_.1")
Index: clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
===
--- clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
+++ clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
@@ -4,7 +4,7 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O3 -disable-llvm-optzns -fno-unroll-loops | FileCheck --check-prefix=UNROLL_DISABLED_MD %s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm -o - %s -O3 -disable-llvm-optzns | FileCheck --check-prefix=NO_UNROLL_MD %s
 
-// NO_UNROLL_MD-NOT: llvm.loop
+// NO_UNROLL_MD-NOT: llvm.loop.unroll.disable
 
 // Verify unroll.disable metadata is added to while loop with -fno-unroll-loops
 // and optlevel > 0.
Index: clang/test/CodeGen/unwind-attr.c
===
--- clang/test/CodeGen/unwind-attr.c
+++ clang/test/CodeGen/unwind-attr.c
@@ -23,7 +23,7 @@
   return 0;
 }
 
-// CHECK: attributes [[TF]] = { noinline optnone "{{.*}} }
+// CHECK: attributes [[TF]] = { noinline optnone maynotprogress "{{.*}} }
 // CHECK

[PATCH] D87522: [SyntaxTree] Add const qualifiers, from [llvm-qualified-auto]

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87522

Files:
  clang/lib/Tooling/Syntax/BuildTree.cpp
  clang/lib/Tooling/Syntax/ComputeReplacements.cpp
  clang/lib/Tooling/Syntax/Tree.cpp


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -19,7 +19,7 @@
 static void traverse(const syntax::Node *N,
  llvm::function_ref Visit) {
   if (auto *T = dyn_cast(N)) {
-for (auto *C = T->getFirstChild(); C; C = C->getNextSibling())
+for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling())
   traverse(C, Visit);
   }
   Visit(N);
@@ -226,7 +226,7 @@
   auto *T = dyn_cast(this);
   if (!T)
 return;
-  for (auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
 if (T->isOriginal())
   assert(C->isOriginal());
 assert(!C->isDetached());
Index: clang/lib/Tooling/Syntax/ComputeReplacements.cpp
===
--- clang/lib/Tooling/Syntax/ComputeReplacements.cpp
+++ clang/lib/Tooling/Syntax/ComputeReplacements.cpp
@@ -32,7 +32,7 @@
   private:
 void process(const syntax::Node *N) {
   if (auto *T = dyn_cast(N)) {
-for (auto *C = T->getFirstChild(); C != nullptr;
+for (const auto *C = T->getFirstChild(); C != nullptr;
  C = C->getNextSibling())
   process(C);
 return;
@@ -64,8 +64,8 @@
 
 syntax::FileRange rangeOfExpanded(const syntax::Arena &A,
   llvm::ArrayRef Expanded) {
-  auto &Buffer = A.getTokenBuffer();
-  auto &SM = A.getSourceManager();
+  const auto &Buffer = A.getTokenBuffer();
+  const auto &SM = A.getSourceManager();
 
   // Check that \p Expanded actually points into expanded tokens.
   assert(Buffer.expandedTokens().begin() <= Expanded.begin());
@@ -85,8 +85,8 @@
 tooling::Replacements
 syntax::computeReplacements(const syntax::Arena &A,
 const syntax::TranslationUnit &TU) {
-  auto &Buffer = A.getTokenBuffer();
-  auto &SM = A.getSourceManager();
+  const auto &Buffer = A.getTokenBuffer();
+  const auto &SM = A.getSourceManager();
 
   tooling::Replacements Replacements;
   // Text inserted by the replacement we are building now.
Index: clang/lib/Tooling/Syntax/BuildTree.cpp
===
--- clang/lib/Tooling/Syntax/BuildTree.cpp
+++ clang/lib/Tooling/Syntax/BuildTree.cpp
@@ -558,7 +558,7 @@
   assert(A.getTokenBuffer().expandedTokens().back().kind() == tok::eof);
   // Create all leaf nodes.
   // Note that we do not have 'eof' in the tree.
-  for (auto &T : A.getTokenBuffer().expandedTokens().drop_back()) {
+  for (const auto &T : A.getTokenBuffer().expandedTokens().drop_back()) {
 auto *L = new (A.getAllocator()) syntax::Leaf(&T);
 L->Original = true;
 L->CanModify = A.getTokenBuffer().spelledForExpanded(T).hasValue();


Index: clang/lib/Tooling/Syntax/Tree.cpp
===
--- clang/lib/Tooling/Syntax/Tree.cpp
+++ clang/lib/Tooling/Syntax/Tree.cpp
@@ -19,7 +19,7 @@
 static void traverse(const syntax::Node *N,
  llvm::function_ref Visit) {
   if (auto *T = dyn_cast(N)) {
-for (auto *C = T->getFirstChild(); C; C = C->getNextSibling())
+for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling())
   traverse(C, Visit);
   }
   Visit(N);
@@ -226,7 +226,7 @@
   auto *T = dyn_cast(this);
   if (!T)
 return;
-  for (auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
+  for (const auto *C = T->getFirstChild(); C; C = C->getNextSibling()) {
 if (T->isOriginal())
   assert(C->isOriginal());
 assert(!C->isDetached());
Index: clang/lib/Tooling/Syntax/ComputeReplacements.cpp
===
--- clang/lib/Tooling/Syntax/ComputeReplacements.cpp
+++ clang/lib/Tooling/Syntax/ComputeReplacements.cpp
@@ -32,7 +32,7 @@
   private:
 void process(const syntax::Node *N) {
   if (auto *T = dyn_cast(N)) {
-for (auto *C = T->getFirstChild(); C != nullptr;
+for (const auto *C = T->getFirstChild(); C != nullptr;
  C = C->getNextSibling())
   process(C);
 return;
@@ -64,8 +64,8 @@
 
 syntax::FileRange rangeOfExpanded(const syntax::Arena &A,
   llvm::ArrayRef Expanded) {
-  auto &Buffer = A.getTokenBuffer();
-  auto &SM = A.getSourceManager();
+  const auto &Buffer = A.getTokenBuffer();
+  const auto &SM = A.getSourceManager();
 
   // Check 

[PATCH] D87223: [FPEnv] [Clang] Enable constrained FP support for PowerPC

2020-09-11 Thread Qiu Chaofan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8ecc8520bc5b: [FPEnv] [Clang] Enable constrained FP support 
for PowerPC (authored by qiucf).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87223/new/

https://reviews.llvm.org/D87223

Files:
  clang/lib/Basic/Targets/PPC.h
  clang/test/CodeGen/builtins-ppc-fpconstrained.c


Index: clang/test/CodeGen/builtins-ppc-fpconstrained.c
===
--- clang/test/CodeGen/builtins-ppc-fpconstrained.c
+++ clang/test/CodeGen/builtins-ppc-fpconstrained.c
@@ -2,14 +2,12 @@
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
 // RUN: -emit-llvm %s -o - | FileCheck --check-prefix=CHECK-UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
-// RUN: -fexperimental-strict-floating-point \
 // RUN:  -ffp-exception-behavior=strict -emit-llvm %s -o - | FileCheck \
 // RUN: --check-prefix=CHECK-CONSTRAINED -vv %s
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
 // RUN: -fallow-half-arguments-and-returns -S -o - %s | \
 // RUN: FileCheck --check-prefix=CHECK-ASM --check-prefix=NOT-FIXME-CHECK  %s
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
-// RUN: -fexperimental-strict-floating-point \
 // RUN: -fallow-half-arguments-and-returns -S -ffp-exception-behavior=strict \
 // RUN: -o - %s | FileCheck --check-prefix=CHECK-ASM \
 // RUN: --check-prefix=FIXME-CHECK  %s
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -82,6 +82,7 @@
 SimdDefaultAlign = 128;
 LongDoubleWidth = LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble();
+HasStrictFP = true;
   }
 
   // Set the language option for altivec based on our value.


Index: clang/test/CodeGen/builtins-ppc-fpconstrained.c
===
--- clang/test/CodeGen/builtins-ppc-fpconstrained.c
+++ clang/test/CodeGen/builtins-ppc-fpconstrained.c
@@ -2,14 +2,12 @@
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
 // RUN: -emit-llvm %s -o - | FileCheck --check-prefix=CHECK-UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
-// RUN: -fexperimental-strict-floating-point \
 // RUN:  -ffp-exception-behavior=strict -emit-llvm %s -o - | FileCheck \
 // RUN: --check-prefix=CHECK-CONSTRAINED -vv %s
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
 // RUN: -fallow-half-arguments-and-returns -S -o - %s | \
 // RUN: FileCheck --check-prefix=CHECK-ASM --check-prefix=NOT-FIXME-CHECK  %s
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
-// RUN: -fexperimental-strict-floating-point \
 // RUN: -fallow-half-arguments-and-returns -S -ffp-exception-behavior=strict \
 // RUN: -o - %s | FileCheck --check-prefix=CHECK-ASM \
 // RUN: --check-prefix=FIXME-CHECK  %s
Index: clang/lib/Basic/Targets/PPC.h
===
--- clang/lib/Basic/Targets/PPC.h
+++ clang/lib/Basic/Targets/PPC.h
@@ -82,6 +82,7 @@
 SimdDefaultAlign = 128;
 LongDoubleWidth = LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble();
+HasStrictFP = true;
   }
 
   // Set the language option for altivec based on our value.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8ecc852 - [FPEnv] [Clang] Enable constrained FP support for PowerPC

2020-09-11 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2020-09-12T00:39:52+08:00
New Revision: 8ecc8520bc5bc20ae00c13e5ae13f8edbb80642e

URL: 
https://github.com/llvm/llvm-project/commit/8ecc8520bc5bc20ae00c13e5ae13f8edbb80642e
DIFF: 
https://github.com/llvm/llvm-project/commit/8ecc8520bc5bc20ae00c13e5ae13f8edbb80642e.diff

LOG: [FPEnv] [Clang] Enable constrained FP support for PowerPC

d4ce862f introduced HasStrictFP to disable generating constrained FP
operations for platforms lacking support. Since work for enabling
constrained FP on PowerPC is almost done, we'd like to enable it.

Reviewed By: kpn, steven.zhang

Differential Revision: https://reviews.llvm.org/D87223

Added: 


Modified: 
clang/lib/Basic/Targets/PPC.h
clang/test/CodeGen/builtins-ppc-fpconstrained.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index bca06a7a802dd..ec067d8811fc6 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -82,6 +82,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
 SimdDefaultAlign = 128;
 LongDoubleWidth = LongDoubleAlign = 128;
 LongDoubleFormat = &llvm::APFloat::PPCDoubleDouble();
+HasStrictFP = true;
   }
 
   // Set the language option for altivec based on our value.

diff  --git a/clang/test/CodeGen/builtins-ppc-fpconstrained.c 
b/clang/test/CodeGen/builtins-ppc-fpconstrained.c
index 7c770845090fc..880c0c339ef33 100644
--- a/clang/test/CodeGen/builtins-ppc-fpconstrained.c
+++ b/clang/test/CodeGen/builtins-ppc-fpconstrained.c
@@ -2,14 +2,12 @@
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
 // RUN: -emit-llvm %s -o - | FileCheck --check-prefix=CHECK-UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
-// RUN: -fexperimental-strict-floating-point \
 // RUN:  -ffp-exception-behavior=strict -emit-llvm %s -o - | FileCheck \
 // RUN: --check-prefix=CHECK-CONSTRAINED -vv %s
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
 // RUN: -fallow-half-arguments-and-returns -S -o - %s | \
 // RUN: FileCheck --check-prefix=CHECK-ASM --check-prefix=NOT-FIXME-CHECK  %s
 // RUN: %clang_cc1 -triple powerpc64le-gnu-linux -target-feature +vsx \
-// RUN: -fexperimental-strict-floating-point \
 // RUN: -fallow-half-arguments-and-returns -S -ffp-exception-behavior=strict \
 // RUN: -o - %s | FileCheck --check-prefix=CHECK-ASM \
 // RUN: --check-prefix=FIXME-CHECK  %s



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87523: [SyntaxTree] Reduce visibility of `Arena::lexBuffer`.

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
eduucaldas added a reviewer: gribozavr2.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87523

Files:
  clang/include/clang/Tooling/Syntax/Tree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp


Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -6,6 +6,7 @@
 //
 
//===--===//
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Tree.h"
 
 using namespace clang;
 
@@ -19,13 +20,19 @@
syntax::NodeRole R) {
 T->prependChildLowLevel(Child, R);
   }
+
+  static std::pair>
+  lexBuffer(syntax::Arena &A, std::unique_ptr Buffer) {
+return A.lexBuffer(std::move(Buffer));
+  }
 };
 
 clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
clang::tok::TokenKind K) {
-  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
-clang::tok::getPunctuatorSpelling(K)))
-.second;
+  auto Tokens =
+  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer(
+clang::tok::getPunctuatorSpelling(K)))
+  .second;
   assert(Tokens.size() == 1);
   assert(Tokens.front().kind() == K);
   auto *L = new (A.getAllocator()) clang::syntax::Leaf(Tokens.begin());
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -47,11 +47,13 @@
   const TokenBuffer &getTokenBuffer() const;
   llvm::BumpPtrAllocator &getAllocator() { return Allocator; }
 
+private:
   /// Add \p Buffer to the underlying source manager, tokenize it and store the
-  /// resulting tokens. Useful when there is a need to materialize tokens that
-  /// were not written in user code.
+  /// resulting tokens. Used exclusively in `FactoryImpl` to materialize tokens
+  /// that were not written in user code.
   std::pair>
   lexBuffer(std::unique_ptr Buffer);
+  friend class FactoryImpl;
 
 private:
   SourceManager &SourceMgr;


Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Tree.h"
 
 using namespace clang;
 
@@ -19,13 +20,19 @@
syntax::NodeRole R) {
 T->prependChildLowLevel(Child, R);
   }
+
+  static std::pair>
+  lexBuffer(syntax::Arena &A, std::unique_ptr Buffer) {
+return A.lexBuffer(std::move(Buffer));
+  }
 };
 
 clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
clang::tok::TokenKind K) {
-  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
-clang::tok::getPunctuatorSpelling(K)))
-.second;
+  auto Tokens =
+  FactoryImpl::lexBuffer(A, llvm::MemoryBuffer::getMemBuffer(
+clang::tok::getPunctuatorSpelling(K)))
+  .second;
   assert(Tokens.size() == 1);
   assert(Tokens.front().kind() == K);
   auto *L = new (A.getAllocator()) clang::syntax::Leaf(Tokens.begin());
Index: clang/include/clang/Tooling/Syntax/Tree.h
===
--- clang/include/clang/Tooling/Syntax/Tree.h
+++ clang/include/clang/Tooling/Syntax/Tree.h
@@ -47,11 +47,13 @@
   const TokenBuffer &getTokenBuffer() const;
   llvm::BumpPtrAllocator &getAllocator() { return Allocator; }
 
+private:
   /// Add \p Buffer to the underlying source manager, tokenize it and store the
-  /// resulting tokens. Useful when there is a need to materialize tokens that
-  /// were not written in user code.
+  /// resulting tokens. Used exclusively in `FactoryImpl` to materialize tokens
+  /// that were not written in user code.
   std::pair>
   lexBuffer(std::unique_ptr Buffer);
+  friend class FactoryImpl;
 
 private:
   SourceManager &SourceMgr;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87470: [Coroutine][Sema] Tighten the lifetime of symmetric transfer returned handle

2020-09-11 Thread Xun Li via Phabricator via cfe-commits
lxfind added a comment.

hmm @rjmccall, I don't think there is a stable way to test this. The code 
generated for symmetric transfer is way too complicated to stably pattern match 
one less item in the frame.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87470/new/

https://reviews.llvm.org/D87470

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87470: [Coroutine][Sema] Tighten the lifetime of symmetric transfer returned handle

2020-09-11 Thread Xun Li via Phabricator via cfe-commits
lxfind updated this revision to Diff 291255.
lxfind added a comment.

Remove unstable test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87470/new/

https://reviews.llvm.org/D87470

Files:
  clang/lib/Sema/SemaCoroutine.cpp


Index: clang/lib/Sema/SemaCoroutine.cpp
===
--- clang/lib/Sema/SemaCoroutine.cpp
+++ clang/lib/Sema/SemaCoroutine.cpp
@@ -398,8 +398,8 @@
diag::warn_coroutine_handle_address_invalid_return_type)
 << JustAddress->getType();
 
-  return buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_resume,
-  JustAddress);
+  return S.MaybeCreateExprWithCleanups(
+  buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_resume, JustAddress));
 }
 
 /// Build calls to await_ready, await_suspend, and await_resume for a co_await


Index: clang/lib/Sema/SemaCoroutine.cpp
===
--- clang/lib/Sema/SemaCoroutine.cpp
+++ clang/lib/Sema/SemaCoroutine.cpp
@@ -398,8 +398,8 @@
diag::warn_coroutine_handle_address_invalid_return_type)
 << JustAddress->getType();
 
-  return buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_resume,
-  JustAddress);
+  return S.MaybeCreateExprWithCleanups(
+  buildBuiltinCall(S, Loc, Builtin::BI__builtin_coro_resume, JustAddress));
 }
 
 /// Build calls to await_ready, await_suspend, and await_resume for a co_await
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87526: [SyntaxTree][Synthesis] Add support for Tree.

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
eduucaldas requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87526

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -80,6 +80,32 @@
   )txt"));
 }
 
+TEST_P(SynthesisTest, Tree_Empty) {
+  buildTree("", GetParam());
+
+  auto *Tree = createEmptyTree(*Arena);
+
+  EXPECT_TRUE(treeDumpEqual(Tree, R"txt(
+UnknownExpression Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Tree_Simple) {
+  buildTree("", GetParam());
+
+  auto *IdA = createLeaf(*Arena, tok::identifier, "a");
+  auto *Comma = createLeaf(*Arena, tok::comma);
+  auto *IdB = createLeaf(*Arena, tok::identifier, "b");
+  auto *Tree = foldChildren(*Arena, {IdA, Comma, IdB});
+
+  EXPECT_TRUE(treeDumpEqual(Tree, R"txt(
+UnknownExpression Detached synthesized
+|-'a' synthesized
+|-',' synthesized
+`-'b' synthesized
+  )txt"));
+}
+
 TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -7,6 +7,7 @@
 //===--===//
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
 
 using namespace clang;
 
@@ -50,6 +51,42 @@
   return createLeaf(A, K, Spelling);
 }
 
+syntax::Tree *clang::syntax::foldChildren(
+syntax::Arena &A,
+std::vector> Children,
+syntax::NodeKind K) {
+  auto *T = new (A.getAllocator()) syntax::Tree(K);
+  FactoryImpl::setCanModify(T);
+  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend();
+   std::advance(ChildIt, 1))
+FactoryImpl::prependChildLowLevel(T, ChildIt->first, ChildIt->second);
+
+  T->assertInvariants();
+  return T;
+}
+
+// For testing purposes
+syntax::Tree *clang::syntax::foldChildren(syntax::Arena &A,
+  std::vector Children,
+  syntax::NodeKind K) {
+  auto *T = new (A.getAllocator()) syntax::Tree(K);
+  FactoryImpl::setCanModify(T);
+  for (auto ChildIt = Children.rbegin(); ChildIt != Children.rend();
+   std::advance(ChildIt, 1))
+FactoryImpl::prependChildLowLevel(T, *ChildIt, NodeRole::Unknown);
+
+  T->assertInvariants();
+  return T;
+}
+
+syntax::Tree *clang::syntax::createEmptyTree(syntax::Arena &A,
+ syntax::NodeKind K) {
+  auto *T = new (A.getAllocator()) syntax::Tree(K);
+  FactoryImpl::setCanModify(T);
+  T->assertInvariants();
+  return T;
+}
+
 syntax::EmptyStatement *clang::syntax::createEmptyStatement(syntax::Arena &A) {
   auto *S = new (A.getAllocator()) syntax::EmptyStatement;
   FactoryImpl::setCanModify(S);
Index: clang/include/clang/Tooling/Syntax/BuildTree.h
===
--- clang/include/clang/Tooling/Syntax/BuildTree.h
+++ clang/include/clang/Tooling/Syntax/BuildTree.h
@@ -34,6 +34,15 @@
 /// this token
 syntax::Leaf *createLeaf(syntax::Arena &A, tok::TokenKind K);
 
+// Synthesis of Trees
+syntax::Tree *
+foldChildren(Arena &A, std::vector>,
+ syntax::NodeKind);
+syntax::Tree *foldChildren(Arena &A, std::vector Children,
+   syntax::NodeKind K = NodeKind::UnknownExpression);
+syntax::Tree *createEmptyTree(Arena &A,
+  syntax::NodeKind K = NodeKind::UnknownExpression);
+
 // Synthesis of Syntax Nodes
 clang::syntax::EmptyStatement *createEmptyStatement(clang::syntax::Arena &A);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87527: [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`

2020-09-11 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added reviewers: klimek, sbenza.
baloghadamsoftware added a project: clang.
Herald added subscribers: martong, gamesh411, Szelethus, dkrupp, rnkovacs.
baloghadamsoftware requested review of this revision.

//AST Matcher// `hasBody` is a polymorphic matcher that behaves differently for 
loop statements and function declarations. The main difference is the for 
functions declarations it does not only call `FunctionDecl::getBody()` but 
first checks whether the declaration in question is that specific declaration 
which has the body by calling `FunctionDecl::doesThisDeclarationHaveABody()`. 
This is achieved by specialization of the template `GetBodyMatcher`. 
Unfortunately template specializations do not catch the descendants of the 
class for which the template is specialized. Therefore it does not work 
correcly for the descendants of `FunctionDecl`, such as `CXXMethodDecl`, 
`CXXConstructorDecl`, `CXXDestructorDecl` etc. This patch fixes this issue by 
using a template metaprogram.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87527

Files:
  clang/include/clang/ASTMatchers/ASTMatchersInternal.h
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1454,10 +1454,30 @@
   doStmt(hasBody(compoundStmt();
   EXPECT_TRUE(matches("void f() { int p[2]; for (auto x : p) {} }",
   cxxForRangeStmt(hasBody(compoundStmt();
+}
+
+TEST(HasBody, FindsBodyOfFunctions) {
   EXPECT_TRUE(matches("void f() {}", functionDecl(hasBody(compoundStmt();
   EXPECT_TRUE(notMatches("void f();", functionDecl(hasBody(compoundStmt();
-  EXPECT_TRUE(matches("void f(); void f() {}",
-  functionDecl(hasBody(compoundStmt();
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "void f(); void f() {}",
+  functionDecl(hasBody(compoundStmt())).bind("func"),
+  std::make_unique>("func", 1)));
+}
+
+TEST(HasBody, FindsBodyOfFunctionChildren) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "class C { void f(); }; void C::f() {}",
+  cxxMethodDecl(hasBody(compoundStmt())).bind("met"),
+  std::make_unique>("met", 1)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "class C { C(); }; C::C() {}",
+  cxxConstructorDecl(hasBody(compoundStmt())).bind("ctr"),
+  std::make_unique>("ctr", 1)));
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "class C { ~C(); }; C::~C() {}",
+  cxxDestructorDecl(hasBody(compoundStmt())).bind("dtr"),
+  std::make_unique>("dtr", 1)));
 }
 
 TEST(HasAnySubstatement, MatchesForTopLevelCompoundStatement) {
Index: clang/include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1835,18 +1835,18 @@
   DynTypedNode Node;
 };
 
+template  struct GetBodyMatcher {
+  static const Stmt *get(const Ty &Node) { return Node.getBody(); }
+};
+
 template 
-struct GetBodyMatcher {
+struct GetBodyMatcher::value>::type> 
{
   static const Stmt *get(const Ty &Node) {
-return Node.getBody();
+return Node.doesThisDeclarationHaveABody() ? Node.getBody() : nullptr;
   }
 };
 
-template <>
-inline const Stmt *GetBodyMatcher::get(const FunctionDecl &Node) 
{
-  return Node.doesThisDeclarationHaveABody() ? Node.getBody() : nullptr;
-}
-
 template 
 struct HasSizeMatcher {
   static bool hasSize(const Ty &Node, unsigned int N) {


Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1454,10 +1454,30 @@
   doStmt(hasBody(compoundStmt();
   EXPECT_TRUE(matches("void f() { int p[2]; for (auto x : p) {} }",
   cxxForRangeStmt(hasBody(compoundStmt();
+}
+
+TEST(HasBody, FindsBodyOfFunctions) {
   EXPECT_TRUE(matches("void f() {}", functionDecl(hasBody(compoundStmt();
   EXPECT_TRUE(notMatches("void f();", functionDecl(hasBody(compoundStmt();
-  EXPECT_TRUE(matches("void f(); void f() {}",
-  functionDecl(hasBody(compoundStmt();
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "void f(); void f() {}",
+  functionDecl(hasBody(compoundStmt())).bind("func"),
+  std::make_unique>("func", 1)));
+}
+
+TEST(HasBody, FindsBodyOfFunctionChildren) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "class C { void f(); }; void C::f() {}",
+  cxxMethodDecl(hasBody(compoundStmt())).bind("met"),
+  std::make_unique>("met", 1)));
+  EXPECT_TRUE(match

[PATCH] D87526: [SyntaxTree][Synthesis] Add support for Tree.

2020-09-11 Thread Eduardo Caldas via Phabricator via cfe-commits
eduucaldas updated this revision to Diff 291261.
eduucaldas added a comment.

add previous patch to allow pre-merge checks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87526/new/

https://reviews.llvm.org/D87526

Files:
  clang/include/clang/Tooling/Syntax/BuildTree.h
  clang/lib/Tooling/Syntax/Synthesis.cpp
  clang/unittests/Tooling/Syntax/SynthesisTest.cpp

Index: clang/unittests/Tooling/Syntax/SynthesisTest.cpp
===
--- clang/unittests/Tooling/Syntax/SynthesisTest.cpp
+++ clang/unittests/Tooling/Syntax/SynthesisTest.cpp
@@ -12,33 +12,107 @@
 
 #include "TreeTestBase.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "gtest/gtest.h"
 
 using namespace clang;
 using namespace clang::syntax;
 
 namespace {
 
-INSTANTIATE_TEST_CASE_P(SyntaxTreeTests, SyntaxTreeTest,
+class SynthesisTest : public SyntaxTreeTest {
+protected:
+  ::testing::AssertionResult treeDumpEqual(syntax::Node *Root, StringRef Dump) {
+if (!Root)
+  return ::testing::AssertionFailure()
+ << "Root was not built successfully.";
+
+auto Actual = StringRef(Root->dump(Arena->getSourceManager())).trim().str();
+auto Expected = Dump.trim().str();
+// EXPECT_EQ shows the diff between the two strings if they are different.
+EXPECT_EQ(Expected, Actual);
+if (Actual != Expected) {
+  return ::testing::AssertionFailure();
+}
+return ::testing::AssertionSuccess();
+  }
+};
+
+INSTANTIATE_TEST_CASE_P(SynthesisTests, SynthesisTest,
 ::testing::ValuesIn(allTestClangConfigs()), );
 
-TEST_P(SyntaxTreeTest, Leaf_Punctuation) {
+TEST_P(SynthesisTest, Leaf_Punctuation) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::comma);
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+',' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Keyword) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::kw_if);
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'if' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Identifier) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::identifier, "a");
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'a' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Leaf_Number) {
+  buildTree("", GetParam());
+
+  auto *C = createLeaf(*Arena, tok::numeric_constant, "1");
+
+  EXPECT_TRUE(treeDumpEqual(C, R"txt(
+'1' Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Tree_Empty) {
   buildTree("", GetParam());
 
-  auto *C = syntax::createPunctuation(*Arena, tok::comma);
-  ASSERT_NE(C, nullptr);
-  EXPECT_EQ(C->getToken()->kind(), tok::comma);
-  EXPECT_TRUE(C->canModify());
-  EXPECT_FALSE(C->isOriginal());
-  EXPECT_TRUE(C->isDetached());
+  auto *Tree = createEmptyTree(*Arena);
+
+  EXPECT_TRUE(treeDumpEqual(Tree, R"txt(
+UnknownExpression Detached synthesized
+  )txt"));
+}
+
+TEST_P(SynthesisTest, Tree_Simple) {
+  buildTree("", GetParam());
+
+  auto *IdA = createLeaf(*Arena, tok::identifier, "a");
+  auto *Comma = createLeaf(*Arena, tok::comma);
+  auto *IdB = createLeaf(*Arena, tok::identifier, "b");
+  auto *Tree = foldChildren(*Arena, {IdA, Comma, IdB});
+
+  EXPECT_TRUE(treeDumpEqual(Tree, R"txt(
+UnknownExpression Detached synthesized
+|-'a' synthesized
+|-',' synthesized
+`-'b' synthesized
+  )txt"));
 }
 
-TEST_P(SyntaxTreeTest, Statement_Empty) {
+TEST_P(SynthesisTest, Statement_EmptyStatement) {
   buildTree("", GetParam());
 
-  auto *S = syntax::createEmptyStatement(*Arena);
-  ASSERT_NE(S, nullptr);
-  EXPECT_TRUE(S->canModify());
-  EXPECT_FALSE(S->isOriginal());
-  EXPECT_TRUE(S->isDetached());
+  auto *S = createEmptyStatement(*Arena);
+  EXPECT_TRUE(treeDumpEqual(S, R"txt(
+EmptyStatement Detached synthesized
+`-';' synthesized
+  )txt"));
 }
 } // namespace
Index: clang/lib/Tooling/Syntax/Synthesis.cpp
===
--- clang/lib/Tooling/Syntax/Synthesis.cpp
+++ clang/lib/Tooling/Syntax/Synthesis.cpp
@@ -5,13 +5,15 @@
 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 //
 //===--===//
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Tooling/Syntax/BuildTree.h"
+#include "clang/Tooling/Syntax/Nodes.h"
 
 using namespace clang;
 
 /// Exposes private syntax tree APIs required to implement node synthesis.
 /// Should not be used for anything else.
-class syntax::FactoryImpl {
+class clang::syntax::FactoryImpl {
 public:
   static void setCanModify(syntax::Node *N) { N->CanModify = true; }
 
@@ -21,24 +23,74 @@
   }
 };
 
-clang::syntax::Leaf *syntax::createPunctuation(clang::syntax::Arena &A,
-   clang::tok::TokenKind K) {
-  auto Tokens = A.lexBuffer(llvm::MemoryBuffer::getMemBuffer(
-clang::tok::getPunctuatorSpelling(K)))
-

[PATCH] D87164: Extending Baremetal toolchain's support for the rtlib option.

2020-09-11 Thread Manuel Carrasco via Phabricator via cfe-commits
mcarrasco updated this revision to Diff 291262.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87164/new/

https://reviews.llvm.org/D87164

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -83,3 +83,7 @@
 // RUN: %clangxx -target arm-none-eabi -mthread-model posix -v 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-THREAD-MODEL-POSIX
 // CHECK-THREAD-MODEL-POSIX: Thread model: posix
+
+// RUN: %clang -### -target arm-none-eabi -rtlib=libgcc -v %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RTLIB-GCC
+// CHECK-RTLIB-GCC: -lgcc
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -156,8 +156,17 @@
 
 void BareMetal::AddLinkRuntimeLib(const ArgList &Args,
   ArgStringList &CmdArgs) const {
-  CmdArgs.push_back(Args.MakeArgString("-lclang_rt.builtins-" +
-   getTriple().getArchName()));
+  ToolChain::RuntimeLibType RLT = GetRuntimeLibType(Args);
+  switch (RLT) {
+  case ToolChain::RLT_CompilerRT:
+CmdArgs.push_back(
+Args.MakeArgString("-lclang_rt.builtins-" + 
getTriple().getArchName()));
+return;
+  case ToolChain::RLT_Libgcc:
+CmdArgs.push_back("-lgcc");
+return;
+  }
+  llvm_unreachable("Unhandled RuntimeLibType.");
 }
 
 void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -83,3 +83,7 @@
 // RUN: %clangxx -target arm-none-eabi -mthread-model posix -v 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-THREAD-MODEL-POSIX
 // CHECK-THREAD-MODEL-POSIX: Thread model: posix
+
+// RUN: %clang -### -target arm-none-eabi -rtlib=libgcc -v %s 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RTLIB-GCC
+// CHECK-RTLIB-GCC: -lgcc
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -156,8 +156,17 @@
 
 void BareMetal::AddLinkRuntimeLib(const ArgList &Args,
   ArgStringList &CmdArgs) const {
-  CmdArgs.push_back(Args.MakeArgString("-lclang_rt.builtins-" +
-   getTriple().getArchName()));
+  ToolChain::RuntimeLibType RLT = GetRuntimeLibType(Args);
+  switch (RLT) {
+  case ToolChain::RLT_CompilerRT:
+CmdArgs.push_back(
+Args.MakeArgString("-lclang_rt.builtins-" + getTriple().getArchName()));
+return;
+  case ToolChain::RLT_Libgcc:
+CmdArgs.push_back("-lgcc");
+return;
+  }
+  llvm_unreachable("Unhandled RuntimeLibType.");
 }
 
 void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87528: Enable '#pragma STDC FENV_ACCESS' in frontend cf. D69272 - Work in Progress

2020-09-11 Thread Melanie Blower via Phabricator via cfe-commits
mibintc created this revision.
mibintc added reviewers: sepavloff, rjmccall.
Herald added a project: clang.
mibintc requested review of this revision.

I rebased https://reviews.llvm.org/D69272 to work on the blocking comment from 
@rsmith 
@sepavloff Is it OK if I continue work on this item?  Not sure about the 
protocol when continuing someone else's patch.

@rsmith asked "I don't see changes to the constant evaluator".  The semantic 
rules for enabling this pragma require that strict or precise semantics be in 
effect., see SemaAttr.cpp  And the floating point constant evaluation doesn't 
occur when strict or precise

One of the test cases in this patch shows 1+2 isn't folded in strict mode.

However, I don't see where is the decision about floating point constant 
folding, can someone tell me where that occurs? . I thought the constant 
folding was in AST/ExprConstant.cpp and indeed constant folding does occur 
there. But sometimes, if the floating point semantics are set to 'strict', even 
tho' folding has occurred successfully in ExprConstant.cpp, when i look at 
emit-llvm, there is arithmetic emitted for the floating point expression;  For 
example if you use the command line option -ffp-exception-behavior=strict and 
you compile this function, it will emit the add instruction; but without the 
option you will see the folded expression 3.0.  Either way (i.e. regardless of 
option) if you put a breakpoint inside ExprConstant.cpp the calculation of the 
floating sum does occur.  The function is float myAdd(void) { return 1.0 + 2.0; 
}


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87528

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CodeGen/fp-floatcontrol-pragma.cpp
  clang/test/CodeGen/pragma-fenv_access.c
  clang/test/Parser/fp-floatcontrol-syntax.cpp
  clang/test/Parser/pragma-fenv_access.c
  clang/test/Preprocessor/pragma_unknown.c

Index: clang/test/Preprocessor/pragma_unknown.c
===
--- clang/test/Preprocessor/pragma_unknown.c
+++ clang/test/Preprocessor/pragma_unknown.c
@@ -16,15 +16,6 @@
 // CHECK: {{^}}#pragma STDC FP_CONTRACT DEFAULT{{$}}
 // CHECK: {{^}}#pragma STDC FP_CONTRACT IN_BETWEEN{{$}}
 
-#pragma STDC FENV_ACCESS ON  // expected-warning {{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
-#pragma STDC FENV_ACCESS OFF
-#pragma STDC FENV_ACCESS DEFAULT
-#pragma STDC FENV_ACCESS IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS ON{{$}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS OFF{{$}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS DEFAULT{{$}}
-// CHECK: {{^}}#pragma STDC FENV_ACCESS IN_BETWEEN{{$}}
-
 #pragma STDC CX_LIMITED_RANGE ON
 #pragma STDC CX_LIMITED_RANGE OFF
 #pragma STDC CX_LIMITED_RANGE DEFAULT 
Index: clang/test/Parser/pragma-fenv_access.c
===
--- /dev/null
+++ clang/test/Parser/pragma-fenv_access.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+#pragma STDC FENV_ACCESS IN_BETWEEN   // expected-warning {{expected 'ON' or 'OFF' or 'DEFAULT' in pragma}}
+
+#pragma STDC FENV_ACCESS OFF
+
+float func_04(int x, float y) {
+  if (x)
+return y + 2;
+  #pragma STDC FENV_ACCESS ON // expected-error{{'#pragma STDC FENV_ACCESS' can only appear at file scope or at the start of a compound statement}}
+  return x + y;
+}
Index: clang/test/Parser/fp-floatcontrol-syntax.cpp
===
--- clang/test/Parser/fp-floatcontrol-syntax.cpp
+++ clang/test/Parser/fp-floatcontrol-syntax.cpp
@@ -26,19 +26,14 @@
 double a = 0.0;
 double b = 1.0;
 
-//FIXME At some point this warning will be removed, until then
-//  document the warning
-#ifdef FAST
-// expected-warning@+1{{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
-#pragma STDC FENV_ACCESS ON
-#else
-#pragma STDC FENV_ACCESS ON // expected-warning{{pragma STDC FENV_ACCESS ON is not supported, ignoring pragma}}
-#endif
 #ifdef STRICT
 #pragma float_control(precise, off) // expected-error {{'#pragma float_control(precise, off)' is illegal when except is enabled}}
 #else
+#ifndef FAST
 // Currently FENV_ACCESS cannot be enabled by pragma, skip error check
-#pragma float_control(precise, off) // not-expected-error {{'#pragma float_control(precise, off)' is illegal when fenv_access is enabled}}
+#pragma STDC FENV_ACCESS ON
+#pragma float_control(precise, off) // expected-error {{'#pragma float_control(precise, off)' is illegal when fenv_access is enabled}}
+#endif
 #endif
 
 #pragma float_control(precise, on)
Index: clang/test/CodeGen/pragma-fenv_access.c

[PATCH] D69272: Enable '#pragma STDC FENV_ACCESS' in frontend

2020-09-11 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

Hello, I rebased this and made a few changes here, 
https://reviews.llvm.org/D87528 ; I added a question about floating point 
constant folding in that review, I'm going to duplicate it here,

My question is about constant folding. I am working on a task to ensure that 
clang is doing floating point constant folding correctly. I thought the 
constant folding was in AST/ExprConstant.cpp and indeed constant folding does 
occur there. But sometimes, if the floating point semantics are set to 
'strict', even tho' folding has occurred successfully in ExprConstant.cpp, when 
i look at emit-llvm, there is arithmetic emitted for the floating point 
expression;  For example if you use the command line option 
-ffp-exception-behavior=strict and you compile this function, it will emit the 
add instruction; but without the option you will see the folded expression.  
Either way, if you put a breakpoint inside ExprConstant.cpp the calculation of 
the floating sum does occur.  The function is float myAdd(void) { return 1.0 + 
2.0; }

So where is the decision made that backs out the fold?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69272/new/

https://reviews.llvm.org/D69272

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71199: [clang-tidy] New check cppcoreguidelines-prefer-member-initializer

2020-09-11 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

It looks like it was not entirely my fault: D87527 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D71199/new/

https://reviews.llvm.org/D71199

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87527: [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`

2020-09-11 Thread Whisperity via Phabricator via cfe-commits
whisperity added a comment.

What about http://clang.llvm.org/doxygen/classclang_1_1CXXConversionDecl.html ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87527/new/

https://reviews.llvm.org/D87527

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87527: [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`

2020-09-11 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware added a comment.

In D87527#2268348 , @whisperity wrote:

> What about http://clang.llvm.org/doxygen/classclang_1_1CXXConversionDecl.html 
> ?

That is part of "etc.". It works for all current and future descendants of 
`FunctionDecl` now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87527/new/

https://reviews.llvm.org/D87527

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87164: Extending Baremetal toolchain's support for the rtlib option.

2020-09-11 Thread Manuel Carrasco via Phabricator via cfe-commits
mcarrasco marked an inline comment as done.
mcarrasco added a comment.

@jroelofs no worries, thanks a lot for your time.

Please tell me if I understood you correctly.

It is acceptable just to append the -lgcc if -rtlib=libgcc is used, although 
the user is responsible to ensure that correct paths are provided so libgcc is 
found.

I also agree with the above, although I just want to know if I got your words 
correctly. In addition, you suggest that the build system should invoke clang 
with a valid value in --resource-dir option in order find libgcc.

Could you point me where I can find more info regarding --resource-dir? So far 
I only found this:

  clang --help-hidden | grep resource-dir
-print-resource-dir Print the resource directory pathname
-resource-dirThe directory which holds the compiler resource 
files

Sincerly, I'm a little bit confused about: -sysroot, -gcc-toolchain and now 
-resource-dir




Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:164
+Args.MakeArgString("-lclang_rt.builtins-" + 
getTriple().getArchName()));
+break;
+  case ToolChain::RLT_Libgcc:

jroelofs wrote:
> If you make these `break`s into `return`s, and put an 
> `llvm_unreachable("unhandled RuntimeLibType");` after the switch, then 
> whoever adds a new entry to that enum will get a nice warning showing them 
> that they need to update this code.
Thanks!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87164/new/

https://reviews.llvm.org/D87164

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87409: [libTooling] Fix use of `char` in comparison.

2020-09-11 Thread Luke Benes via Phabricator via cfe-commits
lbenes added a comment.

I can confirm that this commit fixes the Wtype-limits warning when built on 
Raspbian armhf.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87409/new/

https://reviews.llvm.org/D87409

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85408: Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.

2020-09-11 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: 
llvm/test/CodeGen/X86/basic-block-sections-labels-functions-sections.ll:1
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -function-sections 
-basic-block-sections=labels | FileCheck %s
+

You can drop `-unknown-linux-gnu`. This is a generic ELF feature.



Comment at: llvm/test/CodeGen/X86/basic-block-sections-labels.ll:2
 ; Check the basic block sections labels option
-; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections 
-basic-block-sections=labels | FileCheck %s -check-prefix=LINUX-LABELS
+; RUN: llc < %s -mtriple=x86_64 -function-sections 
-basic-block-sections=labels | FileCheck %s -check-prefix=CHECK
 

Delete `-check-prefix=CHECK`
It is the default


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D85408/new/

https://reviews.llvm.org/D85408

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87331: Sema: add support for `__attribute__((__swift_error__))`

2020-09-11 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

Discussed this with @aaron.ballman offline; he is okay with this since this is 
not going to permit incorrect code through without a diagnostic, even if it is 
not the most clear and the attribute wont be accidentally ignored.  We can add 
more diagnostics as a follow up if it is useful.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87331/new/

https://reviews.llvm.org/D87331

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69272: Enable '#pragma STDC FENV_ACCESS' in frontend

2020-09-11 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added a comment.

Say, in D80952  I added support for disabling 
strictfp support when a target doesn't support it. But it only applies to 
command line arguments.

Is there any chance at all that relevant pragmas can also be disabled with the 
warning in the same cases?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69272/new/

https://reviews.llvm.org/D69272

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >