[PATCH] D125875: [RISCV] Add vread_csr and vwrite_csr to riscv_vector.h

2022-06-01 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead added a comment.

Gentle ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125875

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


[PATCH] D125862: [clang][driver] Add gcc-toolset/devtoolset 12 to prefixes

2022-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D125862#3552465 , @tbaeder wrote:

> Ping. @MaskRay Can you take a quick look and check if this is what you had in 
> mind?

LG




Comment at: clang/unittests/Driver/ToolChainTest.cpp:615
+TEST(ToolChainTest, Toolsets) {
+
+  // Ignore this test on Windows hosts.

delete blank line



Comment at: clang/unittests/Driver/ToolChainTest.cpp:623
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+

delete `public`.

Can you avoid using a derived DiagnosticConsumer?



Comment at: clang/unittests/Driver/ToolChainTest.cpp:698
+}
+if (is_style_windows(llvm::sys::path::Style::native))
+  std::replace(S.begin(), S.end(), '\\', '/');

This should be removed if we exclude Windows.


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

https://reviews.llvm.org/D125862

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


[PATCH] D126855: [clang-tidy] check_clang_tidy.py: Print output nicely in Python 3.

2022-06-01 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

In Python 3, `encode()` produces a `bytes`. The way this is printed makes it
very hard to read the clang-tidy output because everything gets jammed onto one
line (newlines are printed as `\n`).

The `encode()` was introduced here:

https://github.com/llvm/llvm-project/commit/a35efc4dcb70658ebd704c28dfeed4cc2bac095b

It seems that this was done to print non-ASCII characters correctly in Python 2,
and this seems worth preserving (though anyone still on Python 2 should really
be migrating).

For the time being, I've simply introduced a version distinction. I'm not sure
if there's a more idiomatic way to do this that works in both Python 2 and
Python 3 -- input welcome!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126855

Files:
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -173,7 +173,10 @@
 print('Running ' + repr(args) + '...')
 clang_tidy_output = try_run(args)
 print(' clang-tidy output ---')
-print(clang_tidy_output.encode())
+if sys.version_info.major >= 3:
+  print(clang_tidy_output);
+else:
+  print(clang_tidy_output.encode())
 
print('\n--')
 
 diff_output = try_run(['diff', '-u', self.original_file_name, 
self.temp_file_name], False)


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -173,7 +173,10 @@
 print('Running ' + repr(args) + '...')
 clang_tidy_output = try_run(args)
 print(' clang-tidy output ---')
-print(clang_tidy_output.encode())
+if sys.version_info.major >= 3:
+  print(clang_tidy_output);
+else:
+  print(clang_tidy_output.encode())
 print('\n--')
 
 diff_output = try_run(['diff', '-u', self.original_file_name, self.temp_file_name], False)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126198: [analyzer][NFCi] Annotate major nonnull returning functions

2022-06-01 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

@steakhal : Thanks for the quick fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126198

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


[PATCH] D125862: [clang][driver] Add gcc-toolset/devtoolset 12 to prefixes

2022-06-01 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping. @MaskRay Can you take a quick look and check if this is what you had in 
mind?


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

https://reviews.llvm.org/D125862

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


[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added a comment.

> OK, as I mentioned. I think we need an attorney to review this change and 
> confirm that it actually accomplishes this goal.

Can you add an attorney as a reviewer of this change so that we can proceed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[PATCH] D126495: [clang-tidy] Organize test docs into subdirectories by module (NFC)

2022-06-01 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

I know this is a rather huge diff, but the part that needs to be reviewed is 
the python script changes.

I've rebuilt the HTML docs with sphinx and tested all the manually modified 
links to verify that they still go to the correct page.

The existing Release Notes have been rebased as well.


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

https://reviews.llvm.org/D126495

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


[PATCH] D125095: [Clang][AIX] Add .ref in frontend for AIX XCOFF to support `-bcdtors:csect` linker option

2022-06-01 Thread ChenZheng via Phabricator via cfe-commits
shchenz added a comment.

Thanks for doing this. I am not familiar with the frontend, so I may be 
wrong/stupid in the follow comments : )
Hope other experts like @hubert.reinterpretcast can give more meaningful 
comments.

I tested on AIX, seems for static variable `static int x = foo();` in global 
scope, even compile with `-bcdtors:csect`, the init function also will not be 
eliminated. Could you please give an example to show why we need the new 
associated metadata for this case? Thanks.

And we may need to update the docs for `associated` metadata too in 
`docs/LangRef.rst`




Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:542
+  if (getTriple().isOSAIX())
+VFInitTermAssoc.push_back(std::make_pair(D, Fn));
+

Should we use `addVarTermAssoc`?



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:688
+updateAssociatedFunc(VFInitTermAssoc, LocalCXXGlobalInits, GetElem, 
Fn);
+updateAssociatedFunc(FFDtorTermAssoc, LocalCXXGlobalInits, GetElem, 
Fn);
+  }

`FFDtorTermAssoc` should store the mapping between dtor and term functions? So 
why we need to update this container when we generate wrapper function for init 
function? I think in the init function there should only be ctors related 
functions?

And why we don't need to update for `VarsWithInitTerm`, in that container there 
should be some static variables reply on the wrapper init function?



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:4799
+if (getTriple().isOSAIX())
+  addVarWithInitTerm(D, GV);
+  }

Why do we need to add mapping between a variable and its address? We already 
map the global and its init function in above `EmitCXXGlobalVarDeclInitFunc`?



Comment at: clang/lib/CodeGen/CodeGenModule.h:465
+  /// between dtor and term functions.
+  llvm::SmallVector, 8>
+  VFInitTermAssoc;

Is there any reason why we need `vector` here instead of `map`? Can you give an 
example that shows one global variable will be connected with more than one 
init functions?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125095

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


[PATCH] D125622: [clang-tidy] Reject invalid enum initializers in C files

2022-06-01 Thread Richard 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 rGb418ef5cb90b: [clang-tidy] Reject invalid enum initializers 
in C files (authored by LegalizeAdulthood).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125622

Files:
  clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
  clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.c
  clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
  clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp
@@ -36,177 +36,241 @@
   return Tokens;
 }
 
-static bool matchText(const char *Text) {
+static bool matchText(const char *Text, bool AllowComma) {
   std::vector Tokens{tokenify(Text)};
-  modernize::IntegralLiteralExpressionMatcher Matcher(Tokens);
+  modernize::IntegralLiteralExpressionMatcher Matcher(Tokens, AllowComma);
 
   return Matcher.match();
 }
 
+static modernize::LiteralSize sizeText(const char *Text) {
+  std::vector Tokens{tokenify(Text)};
+  modernize::IntegralLiteralExpressionMatcher Matcher(Tokens, true);
+  if (Matcher.match())
+return Matcher.largestLiteralSize();
+  return modernize::LiteralSize::Unknown;
+}
+
+static const char *toString(modernize::LiteralSize Value) {
+  switch (Value) {
+  case modernize::LiteralSize::Int:
+return "Int";
+  case modernize::LiteralSize::UnsignedInt:
+return "UnsignedInt";
+  case modernize::LiteralSize::Long:
+return "Long";
+  case modernize::LiteralSize::UnsignedLong:
+return "UnsignedLong";
+  case modernize::LiteralSize::LongLong:
+return "LongLong";
+  case modernize::LiteralSize::UnsignedLongLong:
+return "UnsignedLongLong";
+  default:
+return "Unknown";
+  }
+}
+
 namespace {
 
-struct Param {
+struct MatchParam {
+  bool AllowComma;
   bool Matched;
   const char *Text;
 
-  friend std::ostream <<(std::ostream , const Param ) {
-return Str << "Matched: " << std::boolalpha << Value.Matched << ", Text: '"
-   << Value.Text << "'";
+  friend std::ostream <<(std::ostream , const MatchParam ) {
+return Str << "Allow operator,: " << std::boolalpha << Value.AllowComma
+   << ", Matched: " << std::boolalpha << Value.Matched
+   << ", Text: '" << Value.Text << '\'';
   }
 };
 
-class MatcherTest : public ::testing::TestWithParam {};
+struct SizeParam {
+  modernize::LiteralSize Size;
+  const char *Text;
+
+  friend std::ostream <<(std::ostream , const SizeParam ) {
+return Str << "Size: " << toString(Value.Size) << ", Text: '" << Value.Text << '\'';
+  }
+};
+
+class MatcherTest : public ::testing::TestWithParam {};
+
+class SizeTest : public ::testing::TestWithParam {};
 
 } // namespace
 
-static const Param Params[] = {
+static const MatchParam MatchParams[] = {
 // Accept integral literals.
-{true, "1"},
-{true, "0177"},
-{true, "0xdeadbeef"},
-{true, "0b1011"},
-{true, "'c'"},
+{true, true, "1"},
+{true, true, "0177"},
+{true, true, "0xdeadbeef"},
+{true, true, "0b1011"},
+{true, true, "'c'"},
 // Reject non-integral literals.
-{false, "1.23"},
-{false, "0x1p3"},
-{false, R"("string")"},
-{false, "1i"},
+{true, false, "1.23"},
+{true, false, "0x1p3"},
+{true, false, R"("string")"},
+{true, false, "1i"},
 
 // Accept literals with these unary operators.
-{true, "-1"},
-{true, "+1"},
-{true, "~1"},
-{true, "!1"},
+{true, true, "-1"},
+{true, true, "+1"},
+{true, true, "~1"},
+{true, true, "!1"},
 // Reject invalid unary operators.
-{false, "1-"},
-{false, "1+"},
-{false, "1~"},
-{false, "1!"},
+{true, false, "1-"},
+{true, false, "1+"},
+{true, false, "1~"},
+{true, false, "1!"},
 
 // Accept valid binary operators.
-{true, "1+1"},
-{true, "1-1"},
-{true, "1*1"},
-{true, "1/1"},
-{true, "1%2"},
-{true, "1<<1"},
-{true, "1>>1"},
-{true, "1<=>1"},
-{true, "1<1"},
-{true, "1>1"},
-{true, "1<=1"},
-{true, "1>=1"},
-{true, "1==1"},
-{true, "1!=1"},
-{true, "1&1"},
-{true, "1^1"},
-{true, "1|1"},
-{true, "1&&1"},
-{true, "1||1"},
-{true, "1+ +1"}, // A space is needed to avoid being tokenized as ++ or --.
-{true, "1- -1"},
-{true, "1,1"},
+{true, true, "1+1"},
+{true, true, "1-1"},
+{true, true, "1*1"},
+{true, true, "1/1"},
+{true, 

[clang-tools-extra] b418ef5 - [clang-tidy] Reject invalid enum initializers in C files

2022-06-01 Thread via cfe-commits

Author: Richard
Date: 2022-06-01T22:25:39-06:00
New Revision: b418ef5cb90b32657dee46b068ac367787a8d2d6

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

LOG: [clang-tidy] Reject invalid enum initializers in C files

C requires that enum values fit into an int.  Scan the macro tokens
present in an initializing expression and reject macros that contain
tokens that have suffixes making them larger than int.

C forbids the comma operator in enum initializing expressions, so
optionally reject comma operator.

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

Fixes #55467

Added: 
clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.c

Modified: 
clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h
clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp 
b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
index 91a10f8956e62..ca0e99fc787a1 100644
--- 
a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
+++ 
b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
@@ -8,6 +8,7 @@
 
 #include "IntegralLiteralExpressionMatcher.h"
 
+#include 
 #include 
 #include 
 
@@ -81,6 +82,50 @@ bool IntegralLiteralExpressionMatcher::unaryOperator() {
   return true;
 }
 
+static LiteralSize literalTokenSize(const Token ) {
+  unsigned int Length = Tok.getLength();
+  if (Length <= 1)
+return LiteralSize::Int;
+
+  bool SeenUnsigned = false;
+  bool SeenLong = false;
+  bool SeenLongLong = false;
+  const char *Text = Tok.getLiteralData();
+  for (unsigned int End = Length - 1; End > 0; --End) {
+if (std::isdigit(Text[End]))
+  break;
+
+if (std::toupper(Text[End]) == 'U')
+  SeenUnsigned = true;
+else if (std::toupper(Text[End]) == 'L') {
+  if (SeenLong)
+SeenLongLong = true;
+  SeenLong = true;
+}
+  }
+
+  if (SeenLongLong) {
+if (SeenUnsigned)
+  return LiteralSize::UnsignedLongLong;
+
+return LiteralSize::LongLong;
+  }
+  if (SeenLong) {
+if (SeenUnsigned)
+  return LiteralSize::UnsignedLong;
+
+return LiteralSize::Long;
+  }
+  if (SeenUnsigned)
+return LiteralSize::UnsignedInt;
+
+  return LiteralSize::Int;
+}
+
+static bool operator<(LiteralSize LHS, LiteralSize RHS) {
+  return static_cast(LHS) < static_cast(RHS);
+}
+
 bool IntegralLiteralExpressionMatcher::unaryExpr() {
   if (!unaryOperator())
 return false;
@@ -102,7 +147,10 @@ bool IntegralLiteralExpressionMatcher::unaryExpr() {
   !isIntegralConstant(*Current)) {
 return false;
   }
+
+  LargestSize = std::max(LargestSize, literalTokenSize(*Current));
   ++Current;
+
   return true;
 }
 
@@ -217,14 +265,24 @@ bool IntegralLiteralExpressionMatcher::conditionalExpr() {
 }
 
 bool IntegralLiteralExpressionMatcher::commaExpr() {
-  return nonTerminalChainedExpr(
-  ::conditionalExpr);
+  auto Pred = CommaAllowed
+  ? std::function(
+[](Token Tok) { return Tok.is(tok::TokenKind::comma); 
})
+  : std::function([](Token) { return false; });
+  return nonTerminalChainedExpr(
+  ::conditionalExpr, Pred);
 }
 
 bool IntegralLiteralExpressionMatcher::expr() { return commaExpr(); }
 
 bool IntegralLiteralExpressionMatcher::match() {
-  return expr() && Current == End;
+  // Top-level allowed expression is conditionalExpr(), not expr(), because
+  // comma operators are only valid initializers when used inside parentheses.
+  return conditionalExpr() && Current == End;
+}
+
+LiteralSize IntegralLiteralExpressionMatcher::largestLiteralSize() const {
+  return LargestSize;
 }
 
 } // namespace modernize

diff  --git 
a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h 
b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h
index 9202cc1ed4574..4499ef983ea4e 100644
--- a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h
+++ b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h
@@ -16,15 +16,27 @@ namespace clang {
 namespace tidy {
 namespace modernize {
 
+enum class LiteralSize {
+  Unknown = 0,
+  Int,
+  UnsignedInt,
+  Long,
+  UnsignedLong,
+  LongLong,
+  UnsignedLongLong
+};
+
 // Parses an array of tokens and returns true if they conform to the rules of
 // C++ for whole expressions involving integral literals.  Follows the operator
-// precedence rules of 

[PATCH] D126853: [clang-tidy] `bugprone-use-after-move`: Don't warn on self-moves.

2022-06-01 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126853

Files:
  clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -152,6 +152,13 @@
   // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
 }
 
+// Don't flag a move-to-self.
+void selfMove() {
+  A a;
+  a = std::move(a);
+  a.foo();
+}
+
 // A warning should only be emitted for one use-after-move.
 void onlyFlagOneUseAfterMove() {
   A a;
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -158,9 +158,12 @@
 
   // Ignore all reinitializations where the move potentially comes after the
   // reinit.
+  // If `Reinit` is identical to `MovingCall`, we're looking at a move-to-self
+  // (e.g. `a = std::move(a)`). Count these as reinitializations.
   llvm::SmallVector ReinitsToDelete;
   for (const Stmt *Reinit : Reinits) {
-if (MovingCall && Sequence->potentiallyAfter(MovingCall, Reinit))
+if (MovingCall && Reinit != MovingCall &&
+Sequence->potentiallyAfter(MovingCall, Reinit))
   ReinitsToDelete.push_back(Reinit);
   }
   for (const Stmt *Reinit : ReinitsToDelete) {


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-use-after-move.cpp
@@ -152,6 +152,13 @@
   // CHECK-NOTES: [[@LINE-3]]:15: note: move occurred here
 }
 
+// Don't flag a move-to-self.
+void selfMove() {
+  A a;
+  a = std::move(a);
+  a.foo();
+}
+
 // A warning should only be emitted for one use-after-move.
 void onlyFlagOneUseAfterMove() {
   A a;
Index: clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -158,9 +158,12 @@
 
   // Ignore all reinitializations where the move potentially comes after the
   // reinit.
+  // If `Reinit` is identical to `MovingCall`, we're looking at a move-to-self
+  // (e.g. `a = std::move(a)`). Count these as reinitializations.
   llvm::SmallVector ReinitsToDelete;
   for (const Stmt *Reinit : Reinits) {
-if (MovingCall && Sequence->potentiallyAfter(MovingCall, Reinit))
+if (MovingCall && Reinit != MovingCall &&
+Sequence->potentiallyAfter(MovingCall, Reinit))
   ReinitsToDelete.push_back(Reinit);
   }
   for (const Stmt *Reinit : ReinitsToDelete) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125622: [clang-tidy] Reject invalid enum initializers in C files

2022-06-01 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood updated this revision to Diff 433648.
LegalizeAdulthood added a comment.

Update from review comments


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

https://reviews.llvm.org/D125622

Files:
  clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
  clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.h
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.c
  clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.cpp
  clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ModernizeModuleTest.cpp
@@ -36,177 +36,241 @@
   return Tokens;
 }
 
-static bool matchText(const char *Text) {
+static bool matchText(const char *Text, bool AllowComma) {
   std::vector Tokens{tokenify(Text)};
-  modernize::IntegralLiteralExpressionMatcher Matcher(Tokens);
+  modernize::IntegralLiteralExpressionMatcher Matcher(Tokens, AllowComma);
 
   return Matcher.match();
 }
 
+static modernize::LiteralSize sizeText(const char *Text) {
+  std::vector Tokens{tokenify(Text)};
+  modernize::IntegralLiteralExpressionMatcher Matcher(Tokens, true);
+  if (Matcher.match())
+return Matcher.largestLiteralSize();
+  return modernize::LiteralSize::Unknown;
+}
+
+static const char *toString(modernize::LiteralSize Value) {
+  switch (Value) {
+  case modernize::LiteralSize::Int:
+return "Int";
+  case modernize::LiteralSize::UnsignedInt:
+return "UnsignedInt";
+  case modernize::LiteralSize::Long:
+return "Long";
+  case modernize::LiteralSize::UnsignedLong:
+return "UnsignedLong";
+  case modernize::LiteralSize::LongLong:
+return "LongLong";
+  case modernize::LiteralSize::UnsignedLongLong:
+return "UnsignedLongLong";
+  default:
+return "Unknown";
+  }
+}
+
 namespace {
 
-struct Param {
+struct MatchParam {
+  bool AllowComma;
   bool Matched;
   const char *Text;
 
-  friend std::ostream <<(std::ostream , const Param ) {
-return Str << "Matched: " << std::boolalpha << Value.Matched << ", Text: '"
-   << Value.Text << "'";
+  friend std::ostream <<(std::ostream , const MatchParam ) {
+return Str << "Allow operator,: " << std::boolalpha << Value.AllowComma
+   << ", Matched: " << std::boolalpha << Value.Matched
+   << ", Text: '" << Value.Text << '\'';
   }
 };
 
-class MatcherTest : public ::testing::TestWithParam {};
+struct SizeParam {
+  modernize::LiteralSize Size;
+  const char *Text;
+
+  friend std::ostream <<(std::ostream , const SizeParam ) {
+return Str << "Size: " << toString(Value.Size) << ", Text: '" << Value.Text << '\'';
+  }
+};
+
+class MatcherTest : public ::testing::TestWithParam {};
+
+class SizeTest : public ::testing::TestWithParam {};
 
 } // namespace
 
-static const Param Params[] = {
+static const MatchParam MatchParams[] = {
 // Accept integral literals.
-{true, "1"},
-{true, "0177"},
-{true, "0xdeadbeef"},
-{true, "0b1011"},
-{true, "'c'"},
+{true, true, "1"},
+{true, true, "0177"},
+{true, true, "0xdeadbeef"},
+{true, true, "0b1011"},
+{true, true, "'c'"},
 // Reject non-integral literals.
-{false, "1.23"},
-{false, "0x1p3"},
-{false, R"("string")"},
-{false, "1i"},
+{true, false, "1.23"},
+{true, false, "0x1p3"},
+{true, false, R"("string")"},
+{true, false, "1i"},
 
 // Accept literals with these unary operators.
-{true, "-1"},
-{true, "+1"},
-{true, "~1"},
-{true, "!1"},
+{true, true, "-1"},
+{true, true, "+1"},
+{true, true, "~1"},
+{true, true, "!1"},
 // Reject invalid unary operators.
-{false, "1-"},
-{false, "1+"},
-{false, "1~"},
-{false, "1!"},
+{true, false, "1-"},
+{true, false, "1+"},
+{true, false, "1~"},
+{true, false, "1!"},
 
 // Accept valid binary operators.
-{true, "1+1"},
-{true, "1-1"},
-{true, "1*1"},
-{true, "1/1"},
-{true, "1%2"},
-{true, "1<<1"},
-{true, "1>>1"},
-{true, "1<=>1"},
-{true, "1<1"},
-{true, "1>1"},
-{true, "1<=1"},
-{true, "1>=1"},
-{true, "1==1"},
-{true, "1!=1"},
-{true, "1&1"},
-{true, "1^1"},
-{true, "1|1"},
-{true, "1&&1"},
-{true, "1||1"},
-{true, "1+ +1"}, // A space is needed to avoid being tokenized as ++ or --.
-{true, "1- -1"},
-{true, "1,1"},
+{true, true, "1+1"},
+{true, true, "1-1"},
+{true, true, "1*1"},
+{true, true, "1/1"},
+{true, true, "1%2"},
+{true, true, "1<<1"},
+{true, true, "1>>1"},
+{true, true, "1<=>1"},
+{true, true, "1<1"},
+{true, true, "1>1"},
+{true, true, 

[PATCH] D125622: [clang-tidy] Reject invalid enum initializers in C files

2022-06-01 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood marked 2 inline comments as done.
LegalizeAdulthood added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-macro-to-enum.c:3-7
+// C requires enum values to fit into an int.
+#define TOO_BIG1 1L
+#define TOO_BIG2 1UL
+#define TOO_BIG3 1LL
+#define TOO_BIG4 1ULL

aaron.ballman wrote:
> LegalizeAdulthood wrote:
> > aaron.ballman wrote:
> > > How do we want to handle the fact that Clang has an extension to allow 
> > > this? Perhaps we want a config option for pedantic vs non-pedantic fixes?
> > I was trying to find a way to make it fail on gcc/clang on compiler 
> > explorer and I couldn't get it to fail in either compiler
> > 
> > Where is the extension documented?  It appears to be on by default in both 
> > compilers.
> I don't think we have any documentation for it (we basically don't bother to 
> document our implementation-defined behavior, which drives me mildly nuts -- 
> we fall back on "the source code is the definitive documentation", which is 
> not user-friendly at all).
> 
> That's why I was wondering if we wanted a pedantic vs non-pedantic option 
> here. Pedantically, the behavior you have today is correct. However, because 
> this is a super common extension to compilers, we might want to allow it to 
> be transformed despite being pedantically an extension.
> 
> We can handle that as a follow-up though.
Is there a way to force it to fail with some compiler flag?  If you could show 
me on compiler explorer, that would be great.


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

https://reviews.llvm.org/D125622

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


[PATCH] D125847: LTO: Add option to initialize with opaque/non-opaque pointer types

2022-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Your commit message seems to use the original summary.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

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


[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added a comment.

In D125624#3552284 , @khchen wrote:

> IMO, maybe we could keep the DLLVM_BINUTILS_INCDIR option support but default 
> is using the Plugin.h?

We can, but I wonder what is the motivation of doing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Zakk Chen via Phabricator via cfe-commits
khchen added a comment.

IMO, maybe we could keep the DLLVM_BINUTILS_INCDIR option support but default 
is using the Plugin.h?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[libunwind] 13b8bfc - [libunwind] Add more information to eh_frame_hdr version error

2022-06-01 Thread Florian Mayer via cfe-commits

Author: Florian Mayer
Date: 2022-06-01T19:48:19-07:00
New Revision: 13b8bfc51451fcfc00f3e3480abaf64b337a43d4

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

LOG: [libunwind] Add more information to eh_frame_hdr version error

This makes it easier to find the offending ELF file.

Reviewed By: #libunwind, MaskRay

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

Added: 


Modified: 
libunwind/src/EHHeaderParser.hpp

Removed: 




diff  --git a/libunwind/src/EHHeaderParser.hpp 
b/libunwind/src/EHHeaderParser.hpp
index 9a38070faba9b..ed4317c89055c 100644
--- a/libunwind/src/EHHeaderParser.hpp
+++ b/libunwind/src/EHHeaderParser.hpp
@@ -57,7 +57,8 @@ bool EHHeaderParser::decodeEHHdr(A , pint_t 
ehHdrStart,
   pint_t p = ehHdrStart;
   uint8_t version = addressSpace.get8(p++);
   if (version != 1) {
-_LIBUNWIND_LOG0("Unsupported .eh_frame_hdr version");
+_LIBUNWIND_LOG("unsupported .eh_frame_hdr version: %" PRIu8 " at %" PRIx64,
+   version, static_cast(ehHdrStart));
 return false;
   }
 



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


[PATCH] D125323: [RISCV] Add the passthru operand for RVV unmasked segment load IR intrinsics.

2022-06-01 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead added a comment.

In D125323#3550307 , @khchen wrote:

> In D125323#3549794 , @pcwang-thead 
> wrote:
>
>> Is there an easy way to update tests? Or we need to add passthru operands 
>> manually? I will appreciate it if you can tell me. :-)
>
> use sed to do replacement.
> ex.
>
>   #!/bin/bash
>   set -x
>   
>   for var in "$@"
>   do
> sed -i 's/declare {\([^,]\+\),[^,]\+} \(.*\)(\([0-9a-z*]\+\)/declare 
> {\1,\1} \2(\1,\1, \3/g' $var
> sed -i 's/declare {\([^,]\+\),[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/declare {\1,\1,\1} \2(\1,\1,\1, \3/g' $var
> sed -i 's/declare {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/declare {\1,\1,\1,\1} \2(\1,\1,\1,\1, \3/g' $var
> sed -i 's/declare {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/declare {\1,\1,\1,\1,\1} \2(\1,\1,\1,\1,\1, \3/g' $var
> sed -i 's/declare {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/declare {\1,\1,\1,\1,\1,\1} \2(\1,\1,\1,\1,\1,\1, 
> \3/g' $var
> sed -i 's/declare {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/declare {\1,\1,\1,\1,\1,\1,\1} 
> \2(\1,\1,\1,\1,\1,\1,\1, \3/g' $var
> sed -i 's/declare 
> {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/declare {\1,\1,\1,\1,\1,\1,\1,\1} 
> \2(\1,\1,\1,\1,\1,\1,\1,\1, \3/g' $var
> sed -i 's/call {\([^,]\+\),[^,]\+} \(.*\)(\([0-9a-z*]\+\)/call {\1,\1} 
> \2(\1 undef, \1 undef, \3/g' $var
> sed -i 's/call {\([^,]\+\),[^,]\+,[^,]\+} \(.*\)(\([0-9a-z*]\+\)/call 
> {\1,\1,\1} \2(\1 undef, \1 undef, \1 undef, \3/g' $var
> sed -i 's/call {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/call {\1,\1,\1,\1} \2(\1 undef, \1 undef, \1 undef, \1 
> undef, \3/g' $var
> sed -i 's/call {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/call {\1,\1,\1,\1,\1} \2(\1 undef, \1 undef, \1 undef, 
> \1 undef, \1 undef, \3/g' $var
> sed -i 's/call {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/call {\1,\1,\1,\1,\1,\1} \2(\1 undef, \1 undef, \1 
> undef, \1 undef, \1 undef, \1 undef, \3/g' $var
> sed -i 's/call {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/call {\1,\1,\1,\1,\1,\1,\1} \2(\1 undef, \1 undef, \1 
> undef, \1 undef, \1 undef, \1 undef, \1 undef, \3/g' $var
> sed -i 's/call 
> {\([^,]\+\),[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+,[^,]\+} 
> \(.*\)(\([0-9a-z*]\+\)/call {\1,\1,\1,\1,\1,\1,\1,\1} \2(\1 undef, \1 undef 
> ,\1 undef ,\1 undef, \1 undef ,\1 undef, \1 undef, \1 undef, \
>   3/g' $var
>   done

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125323

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


[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added a comment.

> So what happens if LLVMgold.so  uses one of the new structs or constants and 
> then is built and run on system where binutils is old enough to not have 
> these new structs  and constants?

The same thing can happen with GCC and binutils. Imagine that you install a 
newer version of GCC binary to your system and use it with an older version of 
binutils ld which doesn't know anything about new structs and constants. The 
plugin should still work, as changes to this file must be made in such a way 
that that don't break ABI. The whole point of this interface is decoupling 
compiler versions from linker versions. So it's backward compatible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[clang] 4463bd0 - unbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV after 8c8a2679a20f

2022-06-01 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-06-01T22:33:36-04:00
New Revision: 4463bd0f89181234e0cef982e21de2e96038f873

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

LOG: unbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV after 
8c8a2679a20f

See revision b8b7a9dcdcbc for prior art.

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 1ed234e644e79..0ea8b9002a974 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -41,7 +41,7 @@ namespace serialization {
 /// Version 4 of AST files also requires that the version control branch and
 /// revision match exactly, since there is no backward compatibility of
 /// AST files at this time.
-const unsigned VERSION_MAJOR = 19;
+const unsigned VERSION_MAJOR = 20;
 
 /// AST file minor version number supported by this version of
 /// Clang.



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


[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

In D125624#3552238 , @ruiu wrote:

> The motivation of doing this is to be able to build LLVMgold.so without 
> binutils' source files and make it clear that LLVMgold.so does not include 
> any GPL code.

OK, as I mentioned.  I think we need an attorney to review this change and 
confirm that it actually accomplishes this goal.

> The header file defines the public interface between linker plugins and 
> compilers (and other tools such as `ar` which has to read symbol table of LTO 
> object files). New structs or constants may be added to this header, but the 
> existing ones will never be deleted or altered in such a way that that breaks 
> compatibility. So, the declarations in this file aren't different from other 
> structs and types that are defined the same as they are in GNU systems. We 
> already have lots of such structs and types in llvm/include, no?

So what happens if LLVMgold.so  uses one of the new structs or constants and 
then is built and run on system where binutils is old enough to not have these 
new structs  and constants?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added a comment.

The motivation of doing this is to be able to build LLVMgold.so without 
binutils' source files and make it clear that LLVMgold.so does not include any 
GPL code.

The header file defines the public interface between linker plugins and 
compilers (and other tools such as `ar` which has to read symbol table of LTO 
object files). New structs or constants may be added to this header, but the 
existing ones will never be deleted or altered in such a way that that breaks 
compatibility. So, the declarations in this file aren't different from other 
structs and types that are defined the same as they are in GNU systems. We 
already have lots of such structs and types in llvm/include, no?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[PATCH] D124748: [clang-format] Fix whitespace counting stuff

2022-06-01 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 433626.
sstwcw added a comment.

- add comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124748

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h

Index: clang/lib/Format/FormatTokenLexer.h
===
--- clang/lib/Format/FormatTokenLexer.h
+++ clang/lib/Format/FormatTokenLexer.h
@@ -92,6 +92,8 @@
 
   bool tryMergeConflictMarkers();
 
+  void truncateToken(size_t NewLen);
+
   FormatToken *getStashedToken();
 
   FormatToken *getNextToken();
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -840,6 +840,56 @@
   return FormatTok;
 }
 
+/// Truncate the current token to the new length and make the lexer continue
+/// from the end of the truncated token. Used for other languages that have
+/// different token boundaries, like JavaScript in which a comment ends at a
+/// line break regardless of whether the line break follows a backslash. Also
+/// used to set the lexer to the end of whitespace if the lexer regards
+/// whitespace and an unrecognized symbol as one token.
+void FormatTokenLexer::truncateToken(size_t NewLen) {
+  assert(NewLen <= FormatTok->TokenText.size());
+  resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(
+  Lex->getBufferLocation() - FormatTok->TokenText.size() + NewLen)));
+  FormatTok->TokenText = FormatTok->TokenText.substr(0, NewLen);
+  FormatTok->ColumnWidth = encoding::columnWidthWithTabs(
+  FormatTok->TokenText, FormatTok->OriginalColumn, Style.TabWidth,
+  Encoding);
+  FormatTok->Tok.setLength(NewLen);
+}
+
+/// Count the length of leading whitespace in a token.
+static size_t countLeadingWhitespace(StringRef Text) {
+  // Basically counting the length matched by this regex.
+  // "^([\n\r\f\v \t]|(|\\?\\?/)[\n\r])+"
+  // Directly using the regex turned out to be slow. With the regex
+  // version formatting all files in this directory took about 1.25
+  // seconds. This version took about 0.5 seconds.
+  const char *Cur = Text.begin();
+  while (Cur < Text.end()) {
+if (isspace(Cur[0])) {
+  ++Cur;
+} else if (Cur[0] == '\\' && (Cur[1] == '\n' || Cur[1] == '\r')) {
+  // A '\' followed by a newline always escapes the newline, regardless
+  // of whether there is another '\' before it.
+  // The source has a null byte at the end. So the end of the entire input
+  // isn't reached yet. Also the lexer doesn't break apart an escaped
+  // newline.
+  assert(Text.end() - Cur >= 2);
+  Cur += 2;
+} else if (Cur[0] == '?' && Cur[1] == '?' && Cur[2] == '/' &&
+   (Cur[3] == '\n' || Cur[3] == '\r')) {
+  // Newlines can also be escaped by a '?' '?' '/' trigraph. By the way, the
+  // characters are quoted individually in this comment because if we write
+  // them together some compilers warn that we have a trigraph in the code.
+  assert(Text.end() - Cur >= 4);
+  Cur += 4;
+} else {
+  break;
+}
+  }
+  return Cur - Text.begin();
+}
+
 FormatToken *FormatTokenLexer::getNextToken() {
   if (StateStack.top() == LexerState::TOKEN_STASHED) {
 StateStack.pop();
@@ -854,34 +904,33 @@
   IsFirstToken = false;
 
   // Consume and record whitespace until we find a significant token.
+  // Some tok::unknown tokens are not just whitespace, e.g. whitespace
+  // followed by a symbol such as backtick. Those symbols may be
+  // significant in other languages.
   unsigned WhitespaceLength = TrailingWhitespace;
-  while (FormatTok->is(tok::unknown)) {
+  while (FormatTok->isNot(tok::eof)) {
+auto LeadingWhitespace = countLeadingWhitespace(FormatTok->TokenText);
+if (LeadingWhitespace == 0)
+  break;
+if (LeadingWhitespace < FormatTok->TokenText.size())
+  truncateToken(LeadingWhitespace);
 StringRef Text = FormatTok->TokenText;
-auto EscapesNewline = [&](int pos) {
-  // A '\r' here is just part of '\r\n'. Skip it.
-  if (pos >= 0 && Text[pos] == '\r')
---pos;
-  // See whether there is an odd number of '\' before this.
-  // FIXME: This is wrong. A '\' followed by a newline is always removed,
-  // regardless of whether there is another '\' before it.
-  // FIXME: Newlines can also be escaped by a '?' '?' '/' trigraph.
-  unsigned count = 0;
-  for (; pos >= 0; --pos, ++count)
-if (Text[pos] != '\\')
-  break;
-  return count & 1;
-};
-// FIXME: This miscounts tok:unknown tokens that are not just
-// whitespace, e.g. a '`' character.
+bool InEscape = false;
 for (int i = 0, e = Text.size(); i != e; ++i) {
   switch (Text[i]) {
+  case '\r':
+// If this is a CRLF sequence, break here and the LF 

[PATCH] D126781: [CodeGen] Correctly handle weak symbols in the codegen

2022-06-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 433624.
junaire added a comment.

Forget to use helpers again...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -248,4 +248,22 @@
   EXPECT_EQ(42, fn(NewA));
 }
 
+TEST(InterpreterTest, InlineDecls) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  auto R1 = Interp->Parse("inline int foo() { return 42;}");
+  EXPECT_TRUE(!!R1);
+
+  auto R2 = Interp->Parse("int x = foo()");
+  EXPECT_TRUE(!!R2);
+}
+
 } // end anonymous namespace
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,8 +133,38 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext ) {
   assert(!M && "Replacing existing Module?");
+
+  std::unique_ptr OldBuilder;
+  OldBuilder.swap(Builder);
+
+  assert(OldBuilder->getEmittedDeferredDecls().empty() &&
+ "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
   Initialize(*Ctx);
+
+  assert(OldBuilder->getDeferredDeclsToEmit().empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(Builder->getDeferredDecls().empty() &&
+ "Newly created module should not have deferred decls");
+
+  Builder->getDeferredDecls().swap(OldBuilder->getDeferredDecls());
+
+  assert(Builder->getDeferredVTables().empty() &&
+ "Newly created module should not have deferred vtables");
+
+  Builder->getDeferredVTables().swap(OldBuilder->getDeferredVTables());
+
+  assert(Builder->getMangledDeclNames().empty() &&
+ "Newly created module should not have mangled decl names");
+  assert(Builder->getManglings().empty() &&
+ "Newly created module should not have manglings");
+
+  Builder->getManglings() = std::move(OldBuilder->getManglings());
+
+  assert(OldBuilder->getWeakRefReferences().empty() &&
+ "Not all WeakRefRefs have been applied");
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -339,11 +339,30 @@
   /// yet.
   llvm::DenseMap DeferredDecls;
 
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+bool IsAFunction = isa(GD.getDecl());
+const VarDecl *VD = IsAFunction ? nullptr : dyn_cast(GD.getDecl());
+assert((IsAFunction || VD) && "Unexpected Decl type!");
+llvm::GlobalValue::LinkageTypes L =
+IsAFunction
+? getFunctionLinkage(GD)
+: getLLVMLinkageVarDefinition(
+  VD, isTypeConstant(VD->getType(), /*ExcludeCtor=*/false));
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
+  }
+
   /// This is a list of deferred decls which we have seen that *are* actually
   /// referenced. These get code generated when the module is done.
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1477,6 +1496,34 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream ,
const Decl *D) const;
 
+  llvm::SmallPtrSetImpl () {
+return EmittedModuleInitializers;
+  }
+
+  llvm::DenseMap () {
+return DeferredDecls;
+  }
+
+  std::vector () {
+return DeferredDeclsToEmit;
+  }
+
+  std::vector () {
+return DeferredVTables;
+  }
+
+  llvm::MapVector () {
+return MangledDeclNames;
+  }
+
+  llvm::StringMap () {
+return Manglings;
+  }
+
+  llvm::SmallPtrSetImpl () {
+return WeakRefReferences;
+  }
+
 private:
   llvm::Constant 

[PATCH] D126781: [CodeGen] Correctly handle weak symbols in the codegen

2022-06-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 433623.
junaire added a comment.

Fix the build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -248,4 +248,22 @@
   EXPECT_EQ(42, fn(NewA));
 }
 
+TEST(InterpreterTest, InlineDecls) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  auto R1 = Interp->Parse("inline int foo() { return 42;}");
+  EXPECT_TRUE(!!R1);
+
+  auto R2 = Interp->Parse("int x = foo()");
+  EXPECT_TRUE(!!R2);
+}
+
 } // end anonymous namespace
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,8 +133,38 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext ) {
   assert(!M && "Replacing existing Module?");
+
+  std::unique_ptr OldBuilder;
+  OldBuilder.swap(Builder);
+
+  assert(OldBuilder->EmittedDeferredDecls.empty() &&
+ "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
   Initialize(*Ctx);
+
+  assert(OldBuilder->getDeferredDeclsToEmit().empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(Builder->getDeferredDecls().empty() &&
+ "Newly created module should not have deferred decls");
+
+  Builder->getDeferredDecls().swap(OldBuilder->getDeferredDecls());
+
+  assert(Builder->getDeferredVTables().empty() &&
+ "Newly created module should not have deferred vtables");
+
+  Builder->getDeferredVTables().swap(OldBuilder->getDeferredVTables());
+
+  assert(Builder->getMangledDeclNames().empty() &&
+ "Newly created module should not have mangled decl names");
+  assert(Builder->getManglings().empty() &&
+ "Newly created module should not have manglings");
+
+  Builder->getManglings() = std::move(OldBuilder->getManglings());
+
+  assert(OldBuilder->getWeakRefReferences().empty() &&
+ "Not all WeakRefRefs have been applied");
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -339,11 +339,30 @@
   /// yet.
   llvm::DenseMap DeferredDecls;
 
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+bool IsAFunction = isa(GD.getDecl());
+const VarDecl *VD = IsAFunction ? nullptr : dyn_cast(GD.getDecl());
+assert((IsAFunction || VD) && "Unexpected Decl type!");
+llvm::GlobalValue::LinkageTypes L =
+IsAFunction
+? getFunctionLinkage(GD)
+: getLLVMLinkageVarDefinition(
+  VD, isTypeConstant(VD->getType(), /*ExcludeCtor=*/false));
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
+  }
+
   /// This is a list of deferred decls which we have seen that *are* actually
   /// referenced. These get code generated when the module is done.
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1477,6 +1496,34 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream ,
const Decl *D) const;
 
+  llvm::SmallPtrSetImpl () {
+return EmittedModuleInitializers;
+  }
+
+  llvm::DenseMap () {
+return DeferredDecls;
+  }
+
+  std::vector () {
+return DeferredDeclsToEmit;
+  }
+
+  std::vector () {
+return DeferredVTables;
+  }
+
+  llvm::MapVector () {
+return MangledDeclNames;
+  }
+
+  llvm::StringMap () {
+return Manglings;
+  }
+
+  llvm::SmallPtrSetImpl () {
+return WeakRefReferences;
+  }
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   

[PATCH] D126845: [clang-format] Handle Verilog numbers and operators

2022-06-01 Thread sstwcw via Phabricator via cfe-commits
sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126845

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -45,6 +45,27 @@
   }
 };
 
+TEST_F(FormatTestVerilog, BasedLiteral) {
+  verifyFormat("x = '0;");
+  verifyFormat("x = '1;");
+  verifyFormat("x = 'X;");
+  verifyFormat("x = 'x;");
+  verifyFormat("x = 'Z;");
+  verifyFormat("x = 'z;");
+  verifyFormat("x = 659;");
+  verifyFormat("x = 'h837ff;");
+  verifyFormat("x = 'o7460;");
+  verifyFormat("x = 4'b1001;");
+  verifyFormat("x = 5'D3;");
+  verifyFormat("x = 3'b01x;");
+  verifyFormat("x = 12'hx;");
+  verifyFormat("x = 16'hz;");
+  verifyFormat("x = -8'd6;");
+  verifyFormat("x = 4'shf;");
+  verifyFormat("x = -4'sd15;");
+  verifyFormat("x = 16'sd?;");
+}
+
 TEST_F(FormatTestVerilog, Delay) {
   // Delay by the default unit.
   verifyFormat("#0;");
@@ -139,6 +160,64 @@
"  {x} = {x};");
 }
 
+TEST_F(FormatTestVerilog, Operators) {
+  // Test that unary operators are not followed by space.
+  verifyFormat("x = +x;");
+  verifyFormat("x = -x;");
+  verifyFormat("x = !x;");
+  verifyFormat("x = ~x;");
+  verifyFormat("x = ");
+  verifyFormat("x = ~");
+  verifyFormat("x = |x;");
+  verifyFormat("x = ~|x;");
+  verifyFormat("x = ^x;");
+  verifyFormat("x = ~^x;");
+  verifyFormat("x = ^~x;");
+  verifyFormat("x = ++x;");
+  verifyFormat("x = --x;");
+
+  // Test that operators don't get split.
+  verifyFormat("x = x++;");
+  verifyFormat("x = x--;");
+  verifyFormat("x = x ** x;");
+  verifyFormat("x = x << x;");
+  verifyFormat("x = x >> x;");
+  verifyFormat("x = x <<< x;");
+  verifyFormat("x = x >>> x;");
+  verifyFormat("x = x <= x;");
+  verifyFormat("x = x >= x;");
+  verifyFormat("x = x == x;");
+  verifyFormat("x = x != x;");
+  verifyFormat("x = x === x;");
+  verifyFormat("x = x !== x;");
+  verifyFormat("x = x ==? x;");
+  verifyFormat("x = x !=? x;");
+  verifyFormat("x = x ~^ x;");
+  verifyFormat("x = x ^~ x;");
+  verifyFormat("x = x && x;");
+  verifyFormat("x = x || x;");
+  verifyFormat("x = x->x;");
+  verifyFormat("x = x <-> x;");
+  verifyFormat("x += x;");
+  verifyFormat("x -= x;");
+  verifyFormat("x *= x;");
+  verifyFormat("x /= x;");
+  verifyFormat("x %= x;");
+  verifyFormat("x &= x;");
+  verifyFormat("x ^= x;");
+  verifyFormat("x |= x;");
+  verifyFormat("x <<= x;");
+  verifyFormat("x >>= x;");
+  verifyFormat("x <<<= x;");
+  verifyFormat("x >>>= x;");
+  verifyFormat("x <= x;");
+
+  // Test that space is added between operators.
+  EXPECT_EQ("x = x < -x;", format("x=x<-x;"));
+  EXPECT_EQ("x = x << -x;", format("x=x<<-x;"));
+  EXPECT_EQ("x = x <<< -x;", format("x=x<<<-x;"));
+}
+
 TEST_F(FormatTestVerilog, Preprocessor) {
   auto Style = getLLVMStyle(FormatStyle::LK_Verilog);
   Style.ColumnLimit = 20;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1841,7 +1841,8 @@
   Current,
   Contexts.back().CanBeExpression && Contexts.back().IsExpression,
   Contexts.back().ContextType == Context::TemplateArgument));
-} else if (Current.isOneOf(tok::minus, tok::plus, tok::caret)) {
+} else if (Current.isOneOf(tok::minus, tok::plus, tok::caret) ||
+   (Style.isVerilog() && Current.is(tok::pipe))) {
   Current.setType(determinePlusMinusCaretUsage(Current));
   if (Current.is(TT_UnaryOperator) && Current.is(tok::caret))
 Contexts.back().CaretFound = true;
@@ -3954,6 +3955,21 @@
  (Left.is(tok::r_paren) && Left.MatchingParen &&
   Left.MatchingParen->endsSequence(tok::l_paren, tok::at
   return true;
+// Don't add embedded spaces in a number literal like `16'h1?ax` or an array
+// literal like `'{}`.
+if (Left.is(Keywords.quote) ||
+(Left.is(TT_VerilogNumberBase) && Right.is(tok::numeric_constant)))
+  return false;
+// Don't add spaces between a casting type and the quote or repetition count
+// and the brace.
+if ((Right.is(Keywords.quote) ||
+ (Right.is(BK_BracedInit) && Right.is(tok::l_brace))) &&
+!(Left.isOneOf(Keywords.kw_assign, Keywords.kw_unique) ||
+  Keywords.isVerilogWordOperator(Left)) &&
+(Left.isOneOf(tok::r_square, tok::r_paren, tok::r_brace,
+  

[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Tom Stellard via Phabricator via cfe-commits
tstellar requested changes to this revision.
tstellar added a comment.
This revision now requires changes to proceed.

What is the motivation for this change?  I really don't like bundling external 
headers like this, because it can lead to subtle hard to catch bugs.  It also 
makes it harder to distribute LLVM on operating systems with different versions 
of binutils.

Even if this change is accepted, we would need to have an attorney review 
whether or not this changes the license for LLVMgold.so before it can be 
committed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[PATCH] D124749: [clang-format] Handle Verilog preprocessor directives

2022-06-01 Thread sstwcw via Phabricator via cfe-commits
sstwcw updated this revision to Diff 433614.
sstwcw added a comment.

- use raw string for regex
- use default style in test
- remove parentheses
- use seek now that skipOver no longer exists


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124749

Files:
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenLexer.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestVerilog.cpp

Index: clang/unittests/Format/FormatTestVerilog.cpp
===
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -30,7 +30,9 @@
 return *Result;
   }
 
-  static std::string format(llvm::StringRef Code, const FormatStyle ) {
+  static std::string
+  format(llvm::StringRef Code,
+ const FormatStyle  = getLLVMStyle(FormatStyle::LK_Verilog)) {
 return format(Code, 0, Code.size(), Style);
   }
 
@@ -43,6 +45,29 @@
   }
 };
 
+TEST_F(FormatTestVerilog, Delay) {
+  // Delay by the default unit.
+  verifyFormat("#0;");
+  verifyFormat("#1;");
+  verifyFormat("#10;");
+  verifyFormat("#1.5;");
+  // Explicit unit.
+  verifyFormat("#1fs;");
+  verifyFormat("#1.5fs;");
+  verifyFormat("#1ns;");
+  verifyFormat("#1.5ns;");
+  verifyFormat("#1us;");
+  verifyFormat("#1.5us;");
+  verifyFormat("#1ms;");
+  verifyFormat("#1.5ms;");
+  verifyFormat("#1s;");
+  verifyFormat("#1.5s;");
+  // The following expression should be on the same line.
+  verifyFormat("#1 x = x;");
+  EXPECT_EQ("#1 x = x;", format("#1\n"
+"x = x;"));
+}
+
 TEST_F(FormatTestVerilog, If) {
   verifyFormat("if (x)\n"
"  x = x;");
@@ -114,5 +139,113 @@
"  {x} = {x};");
 }
 
+TEST_F(FormatTestVerilog, Preprocessor) {
+  auto Style = getLLVMStyle(FormatStyle::LK_Verilog);
+  Style.ColumnLimit = 20;
+
+  // Macro definitions.
+  EXPECT_EQ("`define X  \\\n"
+"  if (x)   \\\n"
+"x = x;",
+format("`define X if(x)x=x;", Style));
+  EXPECT_EQ("`define X(x)   \\\n"
+"  if (x)   \\\n"
+"x = x;",
+format("`define X(x) if(x)x=x;", Style));
+  EXPECT_EQ("`define X  \\\n"
+"  x = x;   \\\n"
+"  x = x;",
+format("`define X x=x;x=x;", Style));
+  // Macro definitions with invocations inside.
+  EXPECT_EQ("`define LIST   \\\n"
+"  `ENTRY   \\\n"
+"  `ENTRY",
+format("`define LIST \\\n"
+   "`ENTRY \\\n"
+   "`ENTRY",
+   Style));
+  EXPECT_EQ("`define LIST   \\\n"
+"  `x = `x; \\\n"
+"  `x = `x;",
+format("`define LIST \\\n"
+   "`x = `x; \\\n"
+   "`x = `x;",
+   Style));
+  EXPECT_EQ("`define LIST   \\\n"
+"  `x = `x; \\\n"
+"  `x = `x;",
+format("`define LIST `x=`x;`x=`x;", Style));
+  // Macro invocations.
+  verifyFormat("`x = (`x1 + `x2 + x);");
+  // Lines starting with a preprocessor directive should not be indented.
+  std::string Directives[] = {
+  "begin_keywords",
+  "celldefine",
+  "default_nettype",
+  "define",
+  "else",
+  "elsif",
+  "end_keywords",
+  "endcelldefine",
+  "endif",
+  "ifdef",
+  "ifndef",
+  "include",
+  "line",
+  "nounconnected_drive",
+  "pragma",
+  "resetall",
+  "timescale",
+  "unconnected_drive",
+  "undef",
+  "undefineall",
+  };
+  for (auto  : Directives) {
+EXPECT_EQ("if (x)\n"
+  "`" +
+  Name +
+  "\n"
+  "  ;",
+  format("if (x)\n"
+ "`" +
+ Name +
+ "\n"
+ ";",
+ Style));
+  }
+  // Lines starting with a regular macro invocation should be indented as a
+  // normal line.
+  EXPECT_EQ("if (x)\n"
+"  `x = `x;\n"
+"`timescale 1ns / 1ps",
+format("if (x)\n"
+   "`x = `x;\n"
+   "`timescale 1ns / 1ps",
+   Style));
+  EXPECT_EQ("if (x)\n"
+"`timescale 1ns / 1ps\n"
+"  `x = `x;",
+format("if (x)\n"
+   "`timescale 1ns / 1ps\n"
+   "`x = `x;",
+   Style));
+  std::string NonDirectives[] = {
+  // For `__FILE__` and `__LINE__`, although the standard classifies them as
+  // preprocessor directives, they are used like regular macros.
+  "__FILE__", "__LINE__", "elif", "foo", "x",
+  };
+  for (auto  : NonDirectives) {
+EXPECT_EQ("if 

[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added a comment.

I'm not sure if my credential is still valid. Do you mind if I ask you to 
submit this for me?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[PATCH] D108189: [RISCV] Support experimental 'P' extension 0.96

2022-06-01 Thread Jim Lin via Phabricator via cfe-commits
Jim updated this revision to Diff 433612.
Jim added a comment.
Herald added subscribers: sunshaoce, StephenFan, arichardson.
Herald added a project: All.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108189

Files:
  clang/test/Driver/riscv-arch.c
  clang/test/Preprocessor/riscv-target-features.c
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/test/MC/RISCV/attribute-arch.s

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -178,3 +178,12 @@
 
 .attribute arch, "rv32if_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
 # CHECK: attribute  5, "rv32i2p0_f2p0_zkt1p0_zve32f1p0_zve32x1p0_zvl32b1p0"
+
+.attribute arch, "rv32ip0p96"
+# CHECK: attribute  5, "rv32i2p0_p0p96_zpn0p96_zpsfoperand0p96"
+
+.attribute arch, "rv32izpn0p96"
+# CHECK: attribute  5, "rv32i2p0_zpn0p96"
+
+.attribute arch, "rv32izpsfoperand0p96"
+# CHECK: attribute  5, "rv32i2p0_zpsfoperand0p96"
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -105,6 +105,10 @@
 {"zbr", RISCVExtensionVersion{0, 93}},
 {"zbt", RISCVExtensionVersion{0, 93}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
+
+{"p", RISCVExtensionVersion{0, 96}},
+{"zpn", RISCVExtensionVersion{0, 96}},
+{"zpsfoperand", RISCVExtensionVersion{0, 96}},
 };
 
 static bool stripExperimentalPrefix(StringRef ) {
@@ -595,7 +599,7 @@
 // The order is OK, then push it into features.
 // TODO: Use version number when setting target features
 // Currently LLVM supports only "mafdcbv".
-StringRef SupportedStandardExtension = "mafdcbv";
+StringRef SupportedStandardExtension = "mafdcbpv";
 if (!SupportedStandardExtension.contains(C))
   return createStringError(errc::invalid_argument,
"unsupported standard user-level extension '%c'",
@@ -769,6 +773,7 @@
 static const char *ImpliedExtsZkn[] = {"zbkb", "zbkc", "zbkx", "zkne", "zknd", "zknh"};
 static const char *ImpliedExtsZks[] = {"zbkb", "zbkc", "zbkx", "zksed", "zksh"};
 static const char *ImpliedExtsZvfh[] = {"zve32f"};
+static const char *ImpliedExtsP[] = {"zpn", "zpsfoperand"};
 
 struct ImpliedExtsEntry {
   StringLiteral Name;
@@ -783,6 +788,7 @@
 
 // Note: The table needs to be sorted by name.
 static constexpr ImpliedExtsEntry ImpliedExts[] = {
+{{"p"}, {ImpliedExtsP}},
 {{"v"}, {ImpliedExtsV}},
 {{"zdinx"}, {ImpliedExtsZdinx}},
 {{"zfh"}, {ImpliedExtsZfh}},
Index: clang/test/Preprocessor/riscv-target-features.c
===
--- clang/test/Preprocessor/riscv-target-features.c
+++ clang/test/Preprocessor/riscv-target-features.c
@@ -222,6 +222,34 @@
 // CHECK-ZBT-NOT: __riscv_b
 // CHECK-ZBT-EXT: __riscv_zbt 93000{{$}}
 
+// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv32ip0p96 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-P-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv64ip0p96 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-P-EXT %s
+// CHECK-P-EXT: __riscv_p 96000{{$}}
+// CHECK-P-EXT: __riscv_zpn 96000{{$}}
+// CHECK-P-EXT: __riscv_zpsfoperand 96000{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv32izpn0p96 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZPN-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv64izpn0p96 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZPN-EXT %s
+// CHECK-ZPN-NOT: __riscv_p
+// CHECK-ZPN-EXT: __riscv_zpn 96000{{$}}
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv32izpsfoperand0p96 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZPSFOPERAND-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -menable-experimental-extensions \
+// RUN: -march=rv64izpsfoperand0p96 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZPSFOPERAND-EXT %s
+// CHECK-ZPSFOPERAND-NOT: __riscv_p
+// CHECK-ZPSFOPERAND-EXT: __riscv_zpsfoperand 96000{{$}}
+
 // RUN: %clang -target riscv32-unknown-linux-gnu \
 // RUN: -march=rv32iv1p0 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-V-EXT %s
Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -452,6 +452,63 @@
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ZBA %s
 // RV32-ZBA: "-target-feature" "+zba"
 
+// RUN: %clang -target 

[PATCH] D124749: [clang-format] Handle Verilog preprocessor directives

2022-06-01 Thread sstwcw via Phabricator via cfe-commits
sstwcw marked 5 inline comments as done.
sstwcw added inline comments.



Comment at: clang/unittests/Format/FormatTestVerilog.cpp:179
+  verifyFormat("`x = (`x1 + `x2 + x);");
+  // Lines starting with a preprocessor directive should not be indented.
+  std::string Directives[] = {

>>>! In D124749#3490834, @MyDeveloperDay wrote:
>> You add significant number of keywords here but I don't see any of them 
>> being tested? can you add a unit tests to cover what you are adding
> 
> I think this is still open?
The keywords added in this revision are tested here. Most of those added in 
D123450 don't have tests, but I haven't added stuff to handle them yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124749

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


[PATCH] D126781: [CodeGen] Correctly handle weak symbols in the codegen

2022-06-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 433610.
junaire added a comment.

Only use heplers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -248,4 +248,22 @@
   EXPECT_EQ(42, fn(NewA));
 }
 
+TEST(InterpreterTest, InlineDecls) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  auto R1 = Interp->Parse("inline int foo() { return 42;}");
+  EXPECT_TRUE(!!R1);
+
+  auto R2 = Interp->Parse("int x = foo()");
+  EXPECT_TRUE(!!R2);
+}
+
 } // end anonymous namespace
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,8 +133,38 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext ) {
   assert(!M && "Replacing existing Module?");
+
+  assert(OldBuilder->EmittedDeferredDecls.empty() &&
+ "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
+  std::unique_ptr OldBuilder;
+  OldBuilder.swap(Builder);
+
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
   Initialize(*Ctx);
+
+  assert(OldBuilder->getDeferredDeclsToEmit().empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(Builder->getDeferredDecls().empty() &&
+ "Newly created module should not have deferred decls");
+
+  Builder->getDeferredDecls().swap(OldBuilder->getDeferredDecls());
+
+  assert(Builder->getDeferredVTables().empty() &&
+ "Newly created module should not have deferred vtables");
+
+  Builder->getDeferredVTables().swap(OldBuilder->getDeferredVTables());
+
+  assert(Builder->getMangledDeclNames().empty() &&
+ "Newly created module should not have mangled decl names");
+  assert(Builder->getManglings().empty() &&
+ "Newly created module should not have manglings");
+
+  Builder->getManglings() = std::move(OldBuilder->getManglings());
+
+  assert(OldBuilder->getWeakRefReferences().empty() &&
+ "Not all WeakRefRefs have been applied");
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -339,11 +339,30 @@
   /// yet.
   llvm::DenseMap DeferredDecls;
 
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+bool IsAFunction = isa(GD.getDecl());
+const VarDecl *VD = IsAFunction ? nullptr : dyn_cast(GD.getDecl());
+assert((IsAFunction || VD) && "Unexpected Decl type!");
+llvm::GlobalValue::LinkageTypes L =
+IsAFunction
+? getFunctionLinkage(GD)
+: getLLVMLinkageVarDefinition(
+  VD, isTypeConstant(VD->getType(), /*ExcludeCtor=*/false));
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
+  }
+
   /// This is a list of deferred decls which we have seen that *are* actually
   /// referenced. These get code generated when the module is done.
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1477,6 +1496,34 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream ,
const Decl *D) const;
 
+  llvm::SmallPtrSetImpl () {
+return EmittedModuleInitializers;
+  }
+
+  llvm::DenseMap () {
+return DeferredDecls;
+  }
+
+  std::vector () {
+return DeferredDeclsToEmit;
+  }
+
+  std::vector () {
+return DeferredVTables;
+  }
+
+  llvm::MapVector () {
+return MangledDeclNames;
+  }
+
+  llvm::StringMap () {
+return Manglings;
+  }
+
+  llvm::SmallPtrSetImpl () {
+return WeakRefReferences;
+  }
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   

[PATCH] D126781: [CodeGen] Correctly handle weak symbols in the codegen

2022-06-01 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 433607.
junaire added a comment.

Fix the broken build


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ModuleBuilder.cpp
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -248,4 +248,22 @@
   EXPECT_EQ(42, fn(NewA));
 }
 
+TEST(InterpreterTest, InlineDecls) {
+  Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"};
+
+  // Create the diagnostic engine with unowned consumer.
+  std::string DiagnosticOutput;
+  llvm::raw_string_ostream DiagnosticsOS(DiagnosticOutput);
+  auto DiagPrinter = std::make_unique(
+  DiagnosticsOS, new DiagnosticOptions());
+
+  auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
+
+  auto R1 = Interp->Parse("inline int foo() { return 42;}");
+  EXPECT_TRUE(!!R1);
+
+  auto R2 = Interp->Parse("int x = foo()");
+  EXPECT_TRUE(!!R2);
+}
+
 } // end anonymous namespace
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -133,8 +133,38 @@
 llvm::Module *StartModule(llvm::StringRef ModuleName,
   llvm::LLVMContext ) {
   assert(!M && "Replacing existing Module?");
+
+  assert(OldBuilder->EmittedDeferredDecls.empty() &&
+ "Still have (unmerged) EmittedDeferredDecls deferred decls");
+
+  std::unique_ptr OldBuilder;
+  OldBuilder.swap(Builder);
+
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
   Initialize(*Ctx);
+
+  assert(OldBuilder->getDeferredDeclsToEmit().empty() &&
+ "Should have emitted all decls deferred to emit.");
+  assert(Builder->DeferredDecls.empty() &&
+ "Newly created module should not have deferred decls");
+
+  Builder->getDeferredDecls().swap(OldBuilder->getDeferredDecls());
+
+  assert(Builder->getDeferredVTables().empty() &&
+ "Newly created module should not have deferred vtables");
+
+  Builder->getDeferredVTables().swap(OldBuilder->getDeferredVTables());
+
+  assert(Builder->getMangledDeclNames().empty() &&
+ "Newly created module should not have mangled decl names");
+  assert(Builder->getManglings().empty() &&
+ "Newly created module should not have manglings");
+
+  Builder->getManglings() = std::move(OldBuilder->getManglings());
+
+  assert(OldBuilder->getWeakRefReferences().empty() &&
+ "Not all WeakRefRefs have been applied");
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -339,11 +339,30 @@
   /// yet.
   llvm::DenseMap DeferredDecls;
 
+  /// Decls that were DeferredDecls and have now been emitted.
+  llvm::DenseMap EmittedDeferredDecls;
+
+  void addEmittedDeferredDecl(GlobalDecl GD) {
+bool IsAFunction = isa(GD.getDecl());
+const VarDecl *VD = IsAFunction ? nullptr : dyn_cast(GD.getDecl());
+assert((IsAFunction || VD) && "Unexpected Decl type!");
+llvm::GlobalValue::LinkageTypes L =
+IsAFunction
+? getFunctionLinkage(GD)
+: getLLVMLinkageVarDefinition(
+  VD, isTypeConstant(VD->getType(), /*ExcludeCtor=*/false));
+if (llvm::GlobalValue::isLinkOnceLinkage(L) ||
+llvm::GlobalValue::isWeakLinkage(L)) {
+  EmittedDeferredDecls[getMangledName(GD)] = GD;
+}
+  }
+
   /// This is a list of deferred decls which we have seen that *are* actually
   /// referenced. These get code generated when the module is done.
   std::vector DeferredDeclsToEmit;
   void addDeferredDeclToEmit(GlobalDecl GD) {
 DeferredDeclsToEmit.emplace_back(GD);
+addEmittedDeferredDecl(GD);
   }
 
   /// List of alias we have emitted. Used to make sure that what they point to
@@ -1477,6 +1496,34 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream ,
const Decl *D) const;
 
+  llvm::SmallPtrSetImpl () {
+return EmittedModuleInitializers;
+  }
+
+  llvm::DenseMap () {
+return DeferredDecls;
+  }
+
+  std::vector () {
+return DeferredDeclsToEmit;
+  }
+
+  std::vector () {
+return DeferredVTables;
+  }
+
+  llvm::MapVector () {
+return MangledDeclNames;
+  }
+
+  llvm::StringMap () {
+return Manglings;
+  }
+
+  llvm::SmallPtrSetImpl () {
+return WeakRefReferences;
+  }
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   

[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added a comment.

Does it? What is your test command?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[PATCH] D125847: LTO: Add option to initialize with opaque/non-opaque pointer types

2022-06-01 Thread Matthias Braun 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 rG850d53a197f9: LTO: Decide upfront whether to use 
opaque/non-opaque pointer types (authored by MatzeB).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/thinlto-inline-asm2.c
  clang/test/Driver/arm-float-abi-lto.c
  clang/test/Driver/lto-no-opaque-pointers.c
  clang/test/Driver/lto-opaque-pointers.c
  clang/test/Driver/memtag_lto.c
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/discard-value-names.ll
  lld/test/ELF/lto/ltopasses-basic.ll
  lld/test/ELF/lto/type-merge.ll
  lld/test/ELF/lto/type-merge2.ll
  lld/test/ELF/lto/wrap-unreferenced-before-codegen.test
  llvm/docs/OpaquePointers.rst
  llvm/include/llvm/LTO/Config.h
  llvm/test/Analysis/StackSafetyAnalysis/ipa-alias.ll
  llvm/test/Analysis/StackSafetyAnalysis/ipa.ll
  llvm/test/LTO/Resolution/X86/alias-alias.ll
  llvm/test/LTO/Resolution/X86/comdat.ll
  llvm/test/LTO/Resolution/X86/ifunc2.ll
  llvm/test/LTO/Resolution/X86/local-def-dllimport.ll
  llvm/test/LTO/X86/Inputs/opaque-pointers.ll
  llvm/test/LTO/X86/cfi_jt_aliases.ll
  llvm/test/LTO/X86/mix-opaque-typed.ll
  llvm/test/LTO/X86/type-mapping-bug4.ll
  llvm/test/ThinLTO/X86/Inputs/import-constant.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/cfi-unsat.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_check.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-unknown.ll
  llvm/test/ThinLTO/X86/globals-import-blockaddr.ll
  llvm/test/ThinLTO/X86/import-constant.ll
  llvm/test/ThinLTO/X86/import-dsolocal.ll
  llvm/test/ThinLTO/X86/index-const-prop-gvref-pie.ll
  llvm/test/ThinLTO/X86/index-const-prop-gvref.ll
  llvm/test/ThinLTO/X86/index-const-prop-linkage.ll
  llvm/test/ThinLTO/X86/reference_non_importable.ll
  llvm/test/ThinLTO/X86/weak_externals.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -143,6 +143,10 @@
  cl::desc("Run PGO context sensitive IR instrumentation"),
  cl::init(false), cl::Hidden);
 
+static cl::opt LtoOpaquePointers("lto-opaque-pointers",
+   cl::desc("Enable opaque pointer types"),
+   cl::init(true), cl::Hidden);
+
 static cl::opt
 DebugPassManager("debug-pass-manager", cl::init(false), cl::Hidden,
  cl::desc("Print pass management debugging information"));
@@ -291,6 +295,7 @@
   Conf.StatsFile = StatsFile;
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
   Conf.PTO.SLPVectorization = Conf.OptLevel > 1;
+  Conf.OpaquePointers = LtoOpaquePointers;
 
   ThinBackend Backend;
   if (ThinLTODistributedIndexes)
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -208,6 +208,8 @@
   static std::string stats_file;
   // Asserts that LTO link has whole program visibility
   static bool whole_program_visibility = false;
+  // Use opaque pointer types.
+  static bool opaque_pointers = true;
 
   // Optimization remarks filename, accepted passes and hotness options
   static std::string RemarksFilename;
@@ -308,6 +310,10 @@
   RemarksFormat = std::string(opt);
 } else if (opt.consume_front("stats-file=")) {
   stats_file = std::string(opt);
+} else if (opt == "opaque-pointers") {
+  opaque_pointers = true;
+} else if (opt == "no-opaque-pointers") {
+  opaque_pointers = false;
 } else {
   // Save this option to pass to the code generator.
   // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
@@ -957,6 +963,8 @@
 
   Conf.HasWholeProgramVisibility = options::whole_program_visibility;
 
+  Conf.OpaquePointers = options.opaque_pointers;
+
   Conf.StatsFile = options::stats_file;
   return std::make_unique(std::move(Conf), Backend,
 options::ParallelCodeGenParallelismLevel);
Index: llvm/test/ThinLTO/X86/weak_externals.ll
===
--- llvm/test/ThinLTO/X86/weak_externals.ll
+++ llvm/test/ThinLTO/X86/weak_externals.ll
@@ -10,9 +10,9 @@
 ; RUN: llvm-dis %t.out.1.2.internalize.bc -o - | FileCheck %s --check-prefix=INTERNALIZE
 
 ; CHECK: @_ZZN9SingletonI1SE11getInstanceEvE8instance = available_externally dso_local global %struct.S zeroinitializer
-; 

[clang] 850d53a - LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-06-01 Thread Matthias Braun via cfe-commits

Author: Matthias Braun
Date: 2022-06-01T18:05:53-07:00
New Revision: 850d53a197f9ffbf5708b7bd795056335e81e9b7

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

LOG: LTO: Decide upfront whether to use opaque/non-opaque pointer types

LTO code may end up mixing bitcode files from various sources varying in
their use of opaque pointer types. The current strategy to decide
between opaque / typed pointers upon the first bitcode file loaded does
not work here, since we could be loading a non-opaque bitcode file first
and would then be unable to load any files with opaque pointer types
later.

So for LTO this:
- Adds an `lto::Config::OpaquePointer` option and enforces an upfront
  decision between the two modes.
- Adds `-opaque-pointers`/`-no-opaque-pointers` options to the gold
  plugin; disabled by default.
- `--opaque-pointers`/`--no-opaque-pointers` options with
  `-plugin-opt=-opaque-pointers`/`-plugin-opt=-no-opaque-pointers`
  aliases to lld; disabled by default.
- Adds an `-lto-opaque-pointers` option to the `llvm-lto2` tool.
- Changes the clang driver to pass `-plugin-opt=-opaque-pointers` to
  the linker in LTO modes when clang was configured with opaque
  pointers enabled by default.

This fixes https://github.com/llvm/llvm-project/issues/55377

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

Added: 
clang/test/Driver/lto-no-opaque-pointers.c
clang/test/Driver/lto-opaque-pointers.c
llvm/test/LTO/X86/Inputs/opaque-pointers.ll
llvm/test/LTO/X86/mix-opaque-typed.ll

Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/CodeGen/thinlto-inline-asm2.c
clang/test/Driver/arm-float-abi-lto.c
clang/test/Driver/memtag_lto.c
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/LTO.cpp
lld/ELF/Options.td
lld/test/ELF/lto/discard-value-names.ll
lld/test/ELF/lto/ltopasses-basic.ll
lld/test/ELF/lto/type-merge.ll
lld/test/ELF/lto/type-merge2.ll
lld/test/ELF/lto/wrap-unreferenced-before-codegen.test
llvm/docs/OpaquePointers.rst
llvm/include/llvm/LTO/Config.h
llvm/test/Analysis/StackSafetyAnalysis/ipa-alias.ll
llvm/test/Analysis/StackSafetyAnalysis/ipa.ll
llvm/test/LTO/Resolution/X86/alias-alias.ll
llvm/test/LTO/Resolution/X86/comdat.ll
llvm/test/LTO/Resolution/X86/ifunc2.ll
llvm/test/LTO/Resolution/X86/local-def-dllimport.ll
llvm/test/LTO/X86/cfi_jt_aliases.ll
llvm/test/LTO/X86/type-mapping-bug4.ll
llvm/test/ThinLTO/X86/Inputs/import-constant.ll
llvm/test/ThinLTO/X86/cfi-devirt.ll
llvm/test/ThinLTO/X86/cfi-unsat.ll
llvm/test/ThinLTO/X86/devirt-after-icp.ll
llvm/test/ThinLTO/X86/devirt2.ll
llvm/test/ThinLTO/X86/devirt_check.ll
llvm/test/ThinLTO/X86/devirt_promote.ll
llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
llvm/test/ThinLTO/X86/funcattrs-prop-unknown.ll
llvm/test/ThinLTO/X86/globals-import-blockaddr.ll
llvm/test/ThinLTO/X86/import-constant.ll
llvm/test/ThinLTO/X86/import-dsolocal.ll
llvm/test/ThinLTO/X86/index-const-prop-gvref-pie.ll
llvm/test/ThinLTO/X86/index-const-prop-gvref.ll
llvm/test/ThinLTO/X86/index-const-prop-linkage.ll
llvm/test/ThinLTO/X86/reference_non_importable.ll
llvm/test/ThinLTO/X86/weak_externals.ll
llvm/tools/gold/gold-plugin.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 7a22ac4afa7e8..7e9fa055b0bc2 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -559,6 +559,9 @@ void tools::addLTOOptions(const ToolChain , const 
ArgList ,
 CmdArgs.push_back(
 Args.MakeArgString("-plugin-opt=jobs=" + Twine(Parallelism)));
 
+  if (!CLANG_ENABLE_OPAQUE_POINTERS_INTERNAL)
+CmdArgs.push_back(Args.MakeArgString("-plugin-opt=no-opaque-pointers"));
+
   // If an explicit debugger tuning argument appeared, pass it along.
   if (Arg *A = Args.getLastArg(options::OPT_gTune_Group,
options::OPT_ggdbN_Group)) {

diff  --git a/clang/test/CodeGen/thinlto-inline-asm2.c 
b/clang/test/CodeGen/thinlto-inline-asm2.c
index 5d7bbc097de7c..7606b27deac87 100644
--- a/clang/test/CodeGen/thinlto-inline-asm2.c
+++ b/clang/test/CodeGen/thinlto-inline-asm2.c
@@ -5,7 +5,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -flto=thin -emit-llvm-bc 
%t/b.c -o %t/b.bc
 // RUN: llvm-nm %t/a.bc | FileCheck %s --check-prefix=NM
 
-// RUN: llvm-lto2 run %t/a.bc %t/b.bc -o %t/out -save-temps -r=%t/a.bc,ref,plx 
-r=%t/b.bc,ff_h264_cabac_tables,pl
+// RUN: llvm-lto2 run -lto-opaque-pointers %t/a.bc %t/b.bc -o %t/out 
-save-temps -r=%t/a.bc,ref,plx -r=%t/b.bc,ff_h264_cabac_tables,pl
 // RUN: llvm-dis < 

[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

It's better to remove LLVM_BINUTILS_INCDIR for test directories in another 
patch. This change may expose some failures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[PATCH] D125624: [gold] Remove an external dependency to GNU binutils' header file

2022-06-01 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.
Herald added a subscriber: Enna1.



Comment at: llvm/tools/gold/gold-plugin.cpp:44-52
 // FIXME: remove this declaration when we stop maintaining Ubuntu Quantal and
 // Precise and Debian Wheezy (binutils 2.23 is required)
 #define LDPO_PIE 3
 
 #define LDPT_GET_SYMBOLS_V3 28
 
 // FIXME: Remove when binutils 2.31 (containing gold 1.16) is the minimum

pcc wrote:
> Can we remove this stuff now?
I believe so, but I'll do that in another patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125624

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


[PATCH] D125802: Fix std::has_unique_object_representations for _BitInt types with padding bits

2022-06-01 Thread Andrew via Phabricator via cfe-commits
browneee added a comment.

It looks like the leak is rooted at the allocation here:
https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp#L3857

The VarTemplateSpecializationDecl is allocated using placement new which uses 
the AST structure for ownership: 
https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/lib/AST/DeclBase.cpp#L99

The problem is the TemplateArgumentListInfo inside 
https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/DeclTemplate.h#L2721
This object contains a vector which does not use placement new: 
https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/TemplateBase.h#L564

Apparently ASTTemplateArgumentListInfo 

 should be used instead 
https://github.com/llvm/llvm-project/blob/1a155ee7de3b62a2fabee86fb470a1554fadc54d/clang/include/clang/AST/TemplateBase.h#L575


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125802

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


[PATCH] D126812: [Binary] Promote OffloadBinary to inherit from Binary

2022-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/lib/Object/OffloadBinary.cpp:18
-
-namespace llvm {
 

tra wrote:
> tra wrote:
> > Nit: `using namespace` seems a bit too heavy-handed when you only need one 
> > enum
> > `using object_error = llvm::object::object_error;` would probably do.
> > TBH, the use of fully qualified enum in only two instances also looked OK 
> > to me.
> Nit: Offload binary is declared within `llvm` namespace. Removing namespace 
> here and relying on `using namespace llvm;` works, but makes things a bit 
> less obvious. I'd keep the namespace around. Maybe, even remove `using 
> namespace llvm` above, too as it should not be needed if the code is within 
> the actual namespace.
> 
> 
`using namespace llvm;` is actually the preferred style. See other files in 
lib/Object/ and various other components.

I fixed the style in 2108f7a243a5018b4ffc09bcbc2a8bdbe3c9a4d1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126812

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


[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-01 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D126796#3551834 , @tschuett wrote:

> In D126796#3551781 , @cjdb wrote:
>
>> In D126796#3551312 , @tschuett 
>> wrote:
>>
>>> Would a JSON dump help you for your tools?
>>
>> Do you think a JSON dump would be more appropriate? I was just going for 
>> something not unlike `--help` here.
>
> I thought that you need this for your diagnostics campaign.

Ah, gotcha. The idea for this feature came about while @aaron.ballman was 
reviewing a draft of that RFC, but it's orthogonal to that. I can't immediately 
see how users would benefit from this outputting JSON, but open to ideas.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D120007: [OMPIRBuilder] Add the support for compare capture

2022-06-01 Thread Shilei Tian via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGeb673be5ac85: [OMPIRBuilder] Add the support for compare 
capture (authored by tianshilei1992).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120007

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -3475,18 +3475,21 @@
 
   OpenMPIRBuilder::AtomicOpValue XSigned = {XVal, Int32, true, false};
   OpenMPIRBuilder::AtomicOpValue XUnsigned = {XVal, Int32, false, false};
+  // V and R are not used in atomic compare
+  OpenMPIRBuilder::AtomicOpValue V = {nullptr, nullptr, false, false};
+  OpenMPIRBuilder::AtomicOpValue R = {nullptr, nullptr, false, false};
   AtomicOrdering AO = AtomicOrdering::Monotonic;
   ConstantInt *Expr = ConstantInt::get(Type::getInt32Ty(Ctx), 1U);
   ConstantInt *D = ConstantInt::get(Type::getInt32Ty(Ctx), 1U);
   OMPAtomicCompareOp OpMax = OMPAtomicCompareOp::MAX;
   OMPAtomicCompareOp OpEQ = OMPAtomicCompareOp::EQ;
 
-  Builder.restoreIP(OMPBuilder.createAtomicCompare(Builder, XSigned, Expr,
-   nullptr, AO, OpMax, true));
-  Builder.restoreIP(OMPBuilder.createAtomicCompare(Builder, XUnsigned, Expr,
-   nullptr, AO, OpMax, false));
-  Builder.restoreIP(OMPBuilder.createAtomicCompare(Builder, XSigned, Expr, D,
-   AO, OpEQ, true));
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, XSigned, V, R, Expr, nullptr, AO, OpMax, true, false, false));
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, XUnsigned, V, R, Expr, nullptr, AO, OpMax, false, false, false));
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, XSigned, V, R, Expr, D, AO, OpEQ, true, false, false));
 
   BasicBlock *EntryBB = BB;
   EXPECT_EQ(EntryBB->getParent()->size(), 1U);
@@ -3515,6 +3518,257 @@
   EXPECT_FALSE(verifyModule(*M, ()));
 }
 
+TEST_F(OpenMPIRBuilderTest, OMPAtomicCompareCapture) {
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+  F->setName("func");
+  IRBuilder<> Builder(BB);
+
+  OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
+
+  LLVMContext  = M->getContext();
+  IntegerType *Int32 = Type::getInt32Ty(Ctx);
+  AllocaInst *XVal = Builder.CreateAlloca(Int32);
+  XVal->setName("x");
+  AllocaInst *VVal = Builder.CreateAlloca(Int32);
+  VVal->setName("v");
+  AllocaInst *RVal = Builder.CreateAlloca(Int32);
+  RVal->setName("r");
+
+  StoreInst *Init =
+  Builder.CreateStore(ConstantInt::get(Type::getInt32Ty(Ctx), 0U), XVal);
+
+  OpenMPIRBuilder::AtomicOpValue X = {XVal, Int32, true, false};
+  OpenMPIRBuilder::AtomicOpValue V = {VVal, Int32, false, false};
+  OpenMPIRBuilder::AtomicOpValue NoV = {nullptr, nullptr, false, false};
+  OpenMPIRBuilder::AtomicOpValue R = {RVal, Int32, false, false};
+  OpenMPIRBuilder::AtomicOpValue NoR = {nullptr, nullptr, false, false};
+
+  AtomicOrdering AO = AtomicOrdering::Monotonic;
+  ConstantInt *Expr = ConstantInt::get(Type::getInt32Ty(Ctx), 1U);
+  ConstantInt *D = ConstantInt::get(Type::getInt32Ty(Ctx), 1U);
+  OMPAtomicCompareOp OpMax = OMPAtomicCompareOp::MAX;
+  OMPAtomicCompareOp OpEQ = OMPAtomicCompareOp::EQ;
+
+  // { cond-update-stmt v = x; }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, NoR, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ false,
+  /* IsFailOnly */ false));
+  // { v = x; cond-update-stmt }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, NoR, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ true,
+  /* IsFailOnly */ false));
+  // if(x == e) { x = d; } else { v = x; }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, NoR, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ false,
+  /* IsFailOnly */ true));
+  // { r = x == e; if(r) { x = d; } }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, NoV, R, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ false,
+  /* IsFailOnly */ false));
+  // { r = x == e; if(r) { x = d; } else { v = x; } }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, R, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ false,
+  /* IsFailOnly */ true));
+
+  // { v = x; cond-update-stmt }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, NoR, Expr, nullptr, 

[clang] eb673be - [OMPIRBuilder] Add the support for compare capture

2022-06-01 Thread Shilei Tian via cfe-commits

Author: Shilei Tian
Date: 2022-06-01T19:53:43-04:00
New Revision: eb673be5ac8510646692f82a606a1f2c10f24828

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

LOG: [OMPIRBuilder] Add the support for compare capture

This patch adds the support for `compare capture` in `OMPIRBuilder`.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index f78443fd20bc..b22b278202dc 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6190,9 +6190,11 @@ static void emitOMPAtomicCompareExpr(CodeGenFunction 
,
   XAddr.getPointer(), XAddr.getElementType(),
   X->getType()->hasSignedIntegerRepresentation(),
   X->getType().isVolatileQualified()};
+  llvm::OpenMPIRBuilder::AtomicOpValue VOpVal, ROpVal;
 
   CGF.Builder.restoreIP(OMPBuilder.createAtomicCompare(
-  CGF.Builder, XOpVal, EVal, DVal, AO, Op, IsXBinopExpr));
+  CGF.Builder, XOpVal, VOpVal, ROpVal, EVal, DVal, AO, Op, IsXBinopExpr,
+  /* IsPostfixUpdate */ false, /* IsFailOnly */ false));
 }
 
 static void emitOMPAtomicExpr(CodeGenFunction , OpenMPClauseKind Kind,

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 93b1297a7930..c0f3020201d5 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1462,7 +1462,7 @@ class OpenMPIRBuilder {
   bool IsPostfixUpdate, bool IsXBinopExpr);
 
   /// Emit atomic compare for constructs: --- Only scalar data types
-  /// cond-update-atomic:
+  /// cond-expr-stmt:
   /// x = x ordop expr ? expr : x;
   /// x = expr ordop x ? expr : x;
   /// x = x == e ? d : x;
@@ -1472,9 +1472,21 @@ class OpenMPIRBuilder {
   /// if (expr ordop x) { x = expr; }
   /// if (x == e) { x = d; }
   /// if (e == x) { x = d; } (this one is not in the spec)
+  /// conditional-update-capture-atomic:
+  /// v = x; cond-update-stmt; (IsPostfixUpdate=true, IsFailOnly=false)
+  /// cond-update-stmt; v = x; (IsPostfixUpdate=false, IsFailOnly=false)
+  /// if (x == e) { x = d; } else { v = x; } (IsPostfixUpdate=false,
+  /// IsFailOnly=true)
+  /// r = x == e; if (r) { x = d; } (IsPostfixUpdate=false, IsFailOnly=false)
+  /// r = x == e; if (r) { x = d; } else { v = x; } (IsPostfixUpdate=false,
+  ///IsFailOnly=true)
   ///
   /// \param Loc  The insert and source location description.
   /// \param XThe target atomic pointer to be updated.
+  /// \param VMemory address where to store captured value (for
+  /// compare capture only).
+  /// \param RMemory address where to store comparison result
+  /// (for compare capture with '==' only).
   /// \param EThe expected value ('e') for forms that use an
   /// equality comparison or an expression ('expr') for
   /// forms that use 'ordop' (logically an atomic maximum 
or
@@ -1486,13 +1498,19 @@ class OpenMPIRBuilder {
   /// \param Op   Atomic compare operation. It can only be ==, <, or >.
   /// \param IsXBinopExpr True if the conditional statement is in the form 
where
   /// x is on LHS. It only matters for < or >.
+  /// \param IsPostfixUpdate  True if original value of 'x' must be stored in
+  /// 'v', not an updated one (for compare capture
+  /// only).
+  /// \param IsFailOnly   True if the original value of 'x' is stored to 'v'
+  /// only when the comparison fails. This is only valid 
for
+  /// the case the comparison is '=='.
   ///
   /// \return Insertion point after generated atomic capture IR.
-  InsertPointTy createAtomicCompare(const LocationDescription ,
-AtomicOpValue , Value *E, Value *D,
-AtomicOrdering AO,
-omp::OMPAtomicCompareOp Op,
-bool IsXBinopExpr);
+  InsertPointTy
+  createAtomicCompare(const LocationDescription , AtomicOpValue ,
+  AtomicOpValue , AtomicOpValue , Value *E, Value *D,
+  AtomicOrdering AO, omp::OMPAtomicCompareOp Op,
+  bool IsXBinopExpr, bool 

[PATCH] D125847: LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-06-01 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB added a comment.

In D125847#3551972 , @MaskRay wrote:

> In D125847#3551841 , @MatzeB wrote:
>
>> address review feedback. I assume this is accepted and good to push when the 
>> buildkit builds look reasonable.
>
> (I changed myself to a blocking review to check the component I mostly care 
> about. I promise I'll perform a quick check.)

Of course, I won't push then. I wasn't sure since the accept came after the set 
to block.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

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


[PATCH] D125847: LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/tools/gold/gold-plugin.cpp:966
 
+  Config.OpaquePointers = options.opaque_pointers;
+

MatzeB wrote:
> MaskRay wrote:
> > `Conf`?
> > 
> > 
> Ouch, good catch. Guess we have no form of direct testing of the gold plugin 
> in LLVM...
Sanitizers have bots using `-DLLVM_BINUTILS_INCDIR=/usr/include`, but otherwise 
using this option is uncommon among build bots.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

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


[PATCH] D126757: Fix clang RecursiveASTVisitor for definition of XXXTemplateSpecializationDecl

2022-06-01 Thread Qingyuan Zheng via Phabricator via cfe-commits
daiyousei-qz updated this revision to Diff 433590.
daiyousei-qz added a comment.
Herald added a subscriber: arphaman.
Herald added a project: clang-tools-extra.

added unit test
moved redundant visit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126757

Files:
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
  clang/include/clang/AST/RecursiveASTVisitor.h


Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2034,12 +2034,13 @@
 if (TypeSourceInfo *TSI = D->getTypeAsWritten())   
\
   TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));  
\

\
-TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));  
\
 if (getDerived().shouldVisitTemplateInstantiations() ||
\
 D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) {
\
   /* Traverse base definition for explicit specializations */  
\
   TRY_TO(Traverse##DECLKIND##Helper(D));   
\
 } else {   
\
+  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));
\
+   
\
   /* Returning from here skips traversing the  
\
  declaration context of the *TemplateSpecializationDecl
\
  (embedded in the DEF_TRAVERSE_DECL() macro)   
\
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -807,6 +807,19 @@
 $Function_deprecated[[Foo]]($Parameter[[x]]); 
 $Function_deprecated[[Foo]]($Parameter[[x]]); 
 }
+  )cpp",
+  // Template specialization
+  R"cpp(
+struct $Class_decl[[Base]]{};
+template 
+struct $Class_decl[[S]] : public $Class[[Base]] {};
+template <> 
+struct $Class_decl[[S]] : public $Class[[Base]] {};
+
+template 
+$TemplateParameter[[T]] $Variable_decl[[x]] = {};
+template <>
+int $Variable_decl[[x]] = (int)sizeof($Class[[Base]]);
   )cpp"};
   for (const auto  : TestCases)
 // Mask off scope modifiers to keep the tests manageable.


Index: clang/include/clang/AST/RecursiveASTVisitor.h
===
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2034,12 +2034,13 @@
 if (TypeSourceInfo *TSI = D->getTypeAsWritten())   \
   TRY_TO(TraverseTypeLoc(TSI->getTypeLoc()));  \
\
-TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));  \
 if (getDerived().shouldVisitTemplateInstantiations() ||\
 D->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) {\
   /* Traverse base definition for explicit specializations */  \
   TRY_TO(Traverse##DECLKIND##Helper(D));   \
 } else {   \
+  TRY_TO(TraverseNestedNameSpecifierLoc(D->getQualifierLoc()));\
+   \
   /* Returning from here skips traversing the  \
  declaration context of the *TemplateSpecializationDecl\
  (embedded in the DEF_TRAVERSE_DECL() macro)   \
Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -807,6 +807,19 @@
 $Function_deprecated[[Foo]]($Parameter[[x]]); 
 $Function_deprecated[[Foo]]($Parameter[[x]]); 
 }
+  )cpp",
+  // Template specialization
+  R"cpp(
+struct $Class_decl[[Base]]{};
+template 
+struct $Class_decl[[S]] : public $Class[[Base]] {};
+template <> 
+struct $Class_decl[[S]] : public $Class[[Base]] {};
+
+template 
+$TemplateParameter[[T]] 

[PATCH] D125847: LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-06-01 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB updated this revision to Diff 433591.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/thinlto-inline-asm2.c
  clang/test/Driver/arm-float-abi-lto.c
  clang/test/Driver/lto-no-opaque-pointers.c
  clang/test/Driver/lto-opaque-pointers.c
  clang/test/Driver/memtag_lto.c
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/discard-value-names.ll
  lld/test/ELF/lto/ltopasses-basic.ll
  lld/test/ELF/lto/type-merge.ll
  lld/test/ELF/lto/type-merge2.ll
  lld/test/ELF/lto/wrap-unreferenced-before-codegen.test
  llvm/docs/OpaquePointers.rst
  llvm/include/llvm/LTO/Config.h
  llvm/test/Analysis/StackSafetyAnalysis/ipa-alias.ll
  llvm/test/Analysis/StackSafetyAnalysis/ipa.ll
  llvm/test/LTO/Resolution/X86/alias-alias.ll
  llvm/test/LTO/Resolution/X86/comdat.ll
  llvm/test/LTO/Resolution/X86/ifunc2.ll
  llvm/test/LTO/Resolution/X86/local-def-dllimport.ll
  llvm/test/LTO/X86/Inputs/opaque-pointers.ll
  llvm/test/LTO/X86/cfi_jt_aliases.ll
  llvm/test/LTO/X86/mix-opaque-typed.ll
  llvm/test/LTO/X86/type-mapping-bug4.ll
  llvm/test/ThinLTO/X86/Inputs/import-constant.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/cfi-unsat.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_check.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-unknown.ll
  llvm/test/ThinLTO/X86/globals-import-blockaddr.ll
  llvm/test/ThinLTO/X86/import-constant.ll
  llvm/test/ThinLTO/X86/import-dsolocal.ll
  llvm/test/ThinLTO/X86/index-const-prop-gvref-pie.ll
  llvm/test/ThinLTO/X86/index-const-prop-gvref.ll
  llvm/test/ThinLTO/X86/index-const-prop-linkage.ll
  llvm/test/ThinLTO/X86/reference_non_importable.ll
  llvm/test/ThinLTO/X86/weak_externals.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -143,6 +143,10 @@
  cl::desc("Run PGO context sensitive IR instrumentation"),
  cl::init(false), cl::Hidden);
 
+static cl::opt LtoOpaquePointers("lto-opaque-pointers",
+   cl::desc("Enable opaque pointer types"),
+   cl::init(true), cl::Hidden);
+
 static cl::opt
 DebugPassManager("debug-pass-manager", cl::init(false), cl::Hidden,
  cl::desc("Print pass management debugging information"));
@@ -291,6 +295,7 @@
   Conf.StatsFile = StatsFile;
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
   Conf.PTO.SLPVectorization = Conf.OptLevel > 1;
+  Conf.OpaquePointers = LtoOpaquePointers;
 
   ThinBackend Backend;
   if (ThinLTODistributedIndexes)
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -208,6 +208,8 @@
   static std::string stats_file;
   // Asserts that LTO link has whole program visibility
   static bool whole_program_visibility = false;
+  // Use opaque pointer types.
+  static bool opaque_pointers = true;
 
   // Optimization remarks filename, accepted passes and hotness options
   static std::string RemarksFilename;
@@ -308,6 +310,10 @@
   RemarksFormat = std::string(opt);
 } else if (opt.consume_front("stats-file=")) {
   stats_file = std::string(opt);
+} else if (opt == "opaque-pointers") {
+  opaque_pointers = true;
+} else if (opt == "no-opaque-pointers") {
+  opaque_pointers = false;
 } else {
   // Save this option to pass to the code generator.
   // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
@@ -957,6 +963,8 @@
 
   Conf.HasWholeProgramVisibility = options::whole_program_visibility;
 
+  Conf.OpaquePointers = options.opaque_pointers;
+
   Conf.StatsFile = options::stats_file;
   return std::make_unique(std::move(Conf), Backend,
 options::ParallelCodeGenParallelismLevel);
Index: llvm/test/ThinLTO/X86/weak_externals.ll
===
--- llvm/test/ThinLTO/X86/weak_externals.ll
+++ llvm/test/ThinLTO/X86/weak_externals.ll
@@ -10,9 +10,9 @@
 ; RUN: llvm-dis %t.out.1.2.internalize.bc -o - | FileCheck %s --check-prefix=INTERNALIZE
 
 ; CHECK: @_ZZN9SingletonI1SE11getInstanceEvE8instance = available_externally dso_local global %struct.S zeroinitializer
-; CHECK: @_ZZN9SingletonI1SE11getInstanceEvE13instance_weak = available_externally dso_local global %struct.S* null, align 8
-; CHECK: define linkonce_odr dso_local dereferenceable(16) %struct.S* 

[PATCH] D125847: LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D125847#3551841 , @MatzeB wrote:

> address review feedback. I assume this is accepted and good to push when the 
> buildkit builds look reasonable.

(I changed myself to a blocking review to check the component I mostly care 
about. I promise I'll perform a quick check.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

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


[PATCH] D125847: LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-06-01 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB added inline comments.



Comment at: llvm/tools/gold/gold-plugin.cpp:966
 
+  Config.OpaquePointers = options.opaque_pointers;
+

MaskRay wrote:
> `Conf`?
> 
> 
Ouch, good catch. Guess we have no form of direct testing of the gold plugin in 
LLVM...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

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


[PATCH] D125847: LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/tools/gold/gold-plugin.cpp:966
 
+  Config.OpaquePointers = options.opaque_pointers;
+

`Conf`?




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

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


[PATCH] D125847: LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

> LTO: Decide upfront whether to use opaque/non-opaque pointer types

This may need to mention "add options" to decide <...>


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

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


[PATCH] D126172: [clang] Fix comparison of TemplateArgument when they are of template kind

2022-06-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a reviewer: mizvekov.
mizvekov added inline comments.



Comment at: clang/lib/AST/TemplateBase.cpp:373-374
   case TemplateExpansion:
-return TemplateArg.Name == Other.TemplateArg.Name &&
+return getAsTemplateOrTemplatePattern().getAsTemplateDecl() ==
+   Other.getAsTemplateOrTemplatePattern().getAsTemplateDecl() &&
TemplateArg.NumExpansions == Other.TemplateArg.NumExpansions;

I believe this change is not correct, as here we want to compare these two 
template arguments to see if they are identical (structural equality), not just 
that they refer to the same thing.



Comment at: clang/test/CXX/dcl/dcl.fct/p17.cpp:261-279
+  template  struct S3 {};
+  // expected-note@-1 {{'S3' declared here}}
+  // expected-note@-2 {{template is declared here}}
+  // clang-format off
+  void f23(C2<::S3> auto);
+  // expected-error@-1 {{no template named 'S3' in the global namespace; did 
you mean simply 'S3'?}}
+  // expected-error@-2 {{use of class template '::S3' requires template 
arguments}}

So I think that the patch is just papering over the bug with another one of no 
consequence in these tests.

If you look at this code in ASTContext.cpp around line 5695 on 
getAutoTypeInternal:
```
  bool AnyNonCanonArgs =
  ::getCanonicalTemplateArguments(*this, TypeConstraintArgs, CanonArgs);
  if (AnyNonCanonArgs) {
Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
TypeConstraintConcept, CanonArgs, true);
// Find the insert position again.
AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
  }
```
Your patch makes AnyNonCanonArgs be false when it should be true, as structural 
comparison of the argument to the canonical argument should indicate that the 
argument is not canonical.

What is happening here on the real case, where `AnyNonCanonArgs = true`, is 
that we end up outputting a NULL InsertPos on that "// Find the insert position 
again." part, clearly because that `FindNodeOrInsertPos` actually found the 
node.

But that should be impossible, because we clearly looked for it earlier and 
would have returned before if so.

So that means that the call to create the canonical autotype somehow created 
the same type as we want to create for the non-canonical one, which again is 
bananas because the arguments are clearly not structurally identical as we 
established.

So I think the only possibility here is that this is a profiling bug, we are 
somehow not profiling template arguments correctly.

A quick look at `TemplateArgument::Profile` shows some things that look clearly 
long, for example in the template case where we profile the canonical template 
name instead of the as-written one. This is probably the bug that is hitting 
these test cases.

There is also a problem in the Declaration case as well, where we are taking 
the canonical declaration, this should presumably also cause a similar bug.

If that does fix it, can you also add tests which would have caught the bug 
that this current patch would have introduced?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126172

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


[PATCH] D126812: [Binary] Promote OffloadBinary to inherit from Binary

2022-06-01 Thread Joseph Huber 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 rGafd2f7e99197: [Binary] Promote OffloadBinary to inherit from 
Binary (authored by jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D126812?vs=433534=433578#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126812

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm-c/Object.h
  llvm/include/llvm/BinaryFormat/Magic.h
  llvm/include/llvm/Object/Binary.h
  llvm/include/llvm/Object/OffloadBinary.h
  llvm/lib/BinaryFormat/Magic.cpp
  llvm/lib/Object/Binary.cpp
  llvm/lib/Object/Object.cpp
  llvm/lib/Object/ObjectFile.cpp
  llvm/lib/Object/OffloadBinary.cpp
  llvm/unittests/Object/OffloadingTest.cpp

Index: llvm/unittests/Object/OffloadingTest.cpp
===
--- llvm/unittests/Object/OffloadingTest.cpp
+++ llvm/unittests/Object/OffloadingTest.cpp
@@ -4,6 +4,9 @@
 #include "gtest/gtest.h"
 #include 
 
+using namespace llvm;
+using namespace llvm::object;
+
 TEST(OffloadingTest, checkOffloadingBinary) {
   // Create random data to fill the image.
   std::mt19937 Rng(std::random_device{}());
@@ -27,23 +30,22 @@
   }
 
   // Create the image.
-  llvm::StringMap StringData;
+  StringMap StringData;
   for (auto  : Strings)
 StringData[KeyAndValue.first] = KeyAndValue.second;
-  std::unique_ptr ImageData =
-  llvm::MemoryBuffer::getMemBuffer(
-  {reinterpret_cast(Image.data()), Image.size()}, "", false);
+  std::unique_ptr ImageData = MemoryBuffer::getMemBuffer(
+  {reinterpret_cast(Image.data()), Image.size()}, "", false);
 
-  llvm::OffloadBinary::OffloadingImage Data;
-  Data.TheImageKind = static_cast(KindDist(Rng));
-  Data.TheOffloadKind = static_cast(KindDist(Rng));
+  OffloadBinary::OffloadingImage Data;
+  Data.TheImageKind = static_cast(KindDist(Rng));
+  Data.TheOffloadKind = static_cast(KindDist(Rng));
   Data.Flags = KindDist(Rng);
   Data.StringData = StringData;
   Data.Image = *ImageData;
 
-  auto BinaryBuffer = llvm::OffloadBinary::write(Data);
+  auto BinaryBuffer = OffloadBinary::write(Data);
 
-  auto BinaryOrErr = llvm::OffloadBinary::create(*BinaryBuffer);
+  auto BinaryOrErr = OffloadBinary::create(*BinaryBuffer);
   if (!BinaryOrErr)
 FAIL();
 
@@ -60,6 +62,6 @@
   EXPECT_TRUE(Data.Image.getBuffer() == Binary.getImage());
 
   // Ensure the size and alignment of the data is correct.
-  EXPECT_TRUE(Binary.getSize() % llvm::OffloadBinary::getAlignment() == 0);
+  EXPECT_TRUE(Binary.getSize() % OffloadBinary::getAlignment() == 0);
   EXPECT_TRUE(Binary.getSize() == BinaryBuffer->getBuffer().size());
 }
Index: llvm/lib/Object/OffloadBinary.cpp
===
--- llvm/lib/Object/OffloadBinary.cpp
+++ llvm/lib/Object/OffloadBinary.cpp
@@ -9,22 +9,23 @@
 #include "llvm/Object/OffloadBinary.h"
 
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/BinaryFormat/Magic.h"
 #include "llvm/MC/StringTableBuilder.h"
 #include "llvm/Object/Error.h"
 #include "llvm/Support/FileOutputBuffer.h"
 
-using namespace llvm;
-
 namespace llvm {
 
+namespace object {
+
 Expected>
 OffloadBinary::create(MemoryBufferRef Buf) {
   if (Buf.getBufferSize() < sizeof(Header) + sizeof(Entry))
-return errorCodeToError(llvm::object::object_error::parse_failed);
+return errorCodeToError(object_error::parse_failed);
 
   // Check for 0x10FF1OAD magic bytes.
-  if (!Buf.getBuffer().startswith("\x10\xFF\x10\xAD"))
-return errorCodeToError(llvm::object::object_error::parse_failed);
+  if (identify_magic(Buf.getBuffer()) != file_magic::offload_binary)
+return errorCodeToError(object_error::parse_failed);
 
   const char *Start = Buf.getBufferStart();
   const Header *TheHeader = reinterpret_cast(Start);
@@ -32,7 +33,7 @@
   reinterpret_cast([TheHeader->EntryOffset]);
 
   return std::unique_ptr(
-  new OffloadBinary(Buf.getBufferStart(), TheHeader, TheEntry));
+  new OffloadBinary(Buf, TheHeader, TheEntry));
 }
 
 std::unique_ptr
@@ -141,4 +142,6 @@
   }
 }
 
+} // namespace object
+
 } // namespace llvm
Index: llvm/lib/Object/ObjectFile.cpp
===
--- llvm/lib/Object/ObjectFile.cpp
+++ llvm/lib/Object/ObjectFile.cpp
@@ -147,6 +147,7 @@
   case file_magic::minidump:
   case file_magic::goff_object:
   case file_magic::cuda_fatbinary:
+  case file_magic::offload_binary:
   case file_magic::dxcontainer_object:
 return errorCodeToError(object_error::invalid_file_type);
   case file_magic::tapi_file:
Index: llvm/lib/Object/Object.cpp
===
--- llvm/lib/Object/Object.cpp
+++ llvm/lib/Object/Object.cpp
@@ -120,6 +120,8 @@
 return LLVMBinaryTypeMachO64L;
   case ID_MachO64B:
 return 

[PATCH] D125847: LTO: Decide upfront whether to use opaque/non-opaque pointer types

2022-06-01 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB updated this revision to Diff 433577.
MatzeB added a comment.

address review feedback. I assume this is accepted and good to push when the 
buildkit builds look reasonable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125847

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/CodeGen/thinlto-inline-asm2.c
  clang/test/Driver/arm-float-abi-lto.c
  clang/test/Driver/lto-no-opaque-pointers.c
  clang/test/Driver/lto-opaque-pointers.c
  clang/test/Driver/memtag_lto.c
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/discard-value-names.ll
  lld/test/ELF/lto/ltopasses-basic.ll
  lld/test/ELF/lto/type-merge.ll
  lld/test/ELF/lto/type-merge2.ll
  lld/test/ELF/lto/wrap-unreferenced-before-codegen.test
  llvm/docs/OpaquePointers.rst
  llvm/include/llvm/LTO/Config.h
  llvm/test/Analysis/StackSafetyAnalysis/ipa-alias.ll
  llvm/test/Analysis/StackSafetyAnalysis/ipa.ll
  llvm/test/LTO/Resolution/X86/alias-alias.ll
  llvm/test/LTO/Resolution/X86/comdat.ll
  llvm/test/LTO/Resolution/X86/ifunc2.ll
  llvm/test/LTO/Resolution/X86/local-def-dllimport.ll
  llvm/test/LTO/X86/Inputs/opaque-pointers.ll
  llvm/test/LTO/X86/cfi_jt_aliases.ll
  llvm/test/LTO/X86/mix-opaque-typed.ll
  llvm/test/LTO/X86/type-mapping-bug4.ll
  llvm/test/ThinLTO/X86/Inputs/import-constant.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/cfi-unsat.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_check.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/funcattrs-prop-unknown.ll
  llvm/test/ThinLTO/X86/globals-import-blockaddr.ll
  llvm/test/ThinLTO/X86/import-constant.ll
  llvm/test/ThinLTO/X86/import-dsolocal.ll
  llvm/test/ThinLTO/X86/index-const-prop-gvref-pie.ll
  llvm/test/ThinLTO/X86/index-const-prop-gvref.ll
  llvm/test/ThinLTO/X86/index-const-prop-linkage.ll
  llvm/test/ThinLTO/X86/reference_non_importable.ll
  llvm/test/ThinLTO/X86/weak_externals.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/llvm-lto2/llvm-lto2.cpp

Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -143,6 +143,10 @@
  cl::desc("Run PGO context sensitive IR instrumentation"),
  cl::init(false), cl::Hidden);
 
+static cl::opt LtoOpaquePointers("lto-opaque-pointers",
+   cl::desc("Enable opaque pointer types"),
+   cl::init(true), cl::Hidden);
+
 static cl::opt
 DebugPassManager("debug-pass-manager", cl::init(false), cl::Hidden,
  cl::desc("Print pass management debugging information"));
@@ -291,6 +295,7 @@
   Conf.StatsFile = StatsFile;
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
   Conf.PTO.SLPVectorization = Conf.OptLevel > 1;
+  Conf.OpaquePointers = LtoOpaquePointers;
 
   ThinBackend Backend;
   if (ThinLTODistributedIndexes)
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llvm/tools/gold/gold-plugin.cpp
@@ -208,6 +208,8 @@
   static std::string stats_file;
   // Asserts that LTO link has whole program visibility
   static bool whole_program_visibility = false;
+  // Use opaque pointer types.
+  static bool opaque_pointers = true;
 
   // Optimization remarks filename, accepted passes and hotness options
   static std::string RemarksFilename;
@@ -308,6 +310,10 @@
   RemarksFormat = std::string(opt);
 } else if (opt.consume_front("stats-file=")) {
   stats_file = std::string(opt);
+} else if (opt == "opaque-pointers") {
+  opaque_pointers = true;
+} else if (opt == "no-opaque-pointers") {
+  opaque_pointers = false;
 } else {
   // Save this option to pass to the code generator.
   // ParseCommandLineOptions() expects argv[0] to be program name. Lazily
@@ -957,6 +963,8 @@
 
   Conf.HasWholeProgramVisibility = options::whole_program_visibility;
 
+  Config.OpaquePointers = options.opaque_pointers;
+
   Conf.StatsFile = options::stats_file;
   return std::make_unique(std::move(Conf), Backend,
 options::ParallelCodeGenParallelismLevel);
Index: llvm/test/ThinLTO/X86/weak_externals.ll
===
--- llvm/test/ThinLTO/X86/weak_externals.ll
+++ llvm/test/ThinLTO/X86/weak_externals.ll
@@ -10,9 +10,9 @@
 ; RUN: llvm-dis %t.out.1.2.internalize.bc -o - | FileCheck %s --check-prefix=INTERNALIZE
 
 ; CHECK: @_ZZN9SingletonI1SE11getInstanceEvE8instance = available_externally dso_local global %struct.S zeroinitializer
-; CHECK: @_ZZN9SingletonI1SE11getInstanceEvE13instance_weak = 

[clang] afd2f7e - [Binary] Promote OffloadBinary to inherit from Binary

2022-06-01 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-06-01T18:40:57-04:00
New Revision: afd2f7e9919737e30f9fae2d3cff892189301a55

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

LOG: [Binary] Promote OffloadBinary to inherit from Binary

We use the `OffloadBinary` to create binary images of offloading files
and their corresonding metadata. This patch changes this to inherit from
the base `Binary` class. This allows us to create and insepect these
more generically. This patch includes all the necessary glue to
implement this as a new binary format, along with added the magic bytes
we use to distinguish the offloading binary to the `file_magic`
implementation.

Reviewed By: tra

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

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm-c/Object.h
llvm/include/llvm/BinaryFormat/Magic.h
llvm/include/llvm/Object/Binary.h
llvm/include/llvm/Object/OffloadBinary.h
llvm/lib/BinaryFormat/Magic.cpp
llvm/lib/Object/Binary.cpp
llvm/lib/Object/Object.cpp
llvm/lib/Object/ObjectFile.cpp
llvm/lib/Object/OffloadBinary.cpp
llvm/unittests/Object/OffloadingTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 94808e8a625e6..0de15b1e48078 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1221,6 +1221,6 @@ void clang::EmbedObject(llvm::Module *M, const 
CodeGenOptions ,
 }
 
 llvm::embedBufferInModule(*M, **ObjectOrErr, ".llvm.offloading",
-  Align(OffloadBinary::getAlignment()));
+  Align(object::OffloadBinary::getAlignment()));
   }
 }

diff  --git a/llvm/include/llvm-c/Object.h b/llvm/include/llvm-c/Object.h
index 9a9596aaa08cd..f422c1ad224d2 100644
--- a/llvm/include/llvm-c/Object.h
+++ b/llvm/include/llvm-c/Object.h
@@ -38,21 +38,23 @@ typedef struct LLVMOpaqueSymbolIterator 
*LLVMSymbolIteratorRef;
 typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;
 
 typedef enum {
-  LLVMBinaryTypeArchive,/**< Archive file. */
-  LLVMBinaryTypeMachOUniversalBinary,   /**< Mach-O Universal Binary file. */
-  LLVMBinaryTypeCOFFImportFile, /**< COFF Import file. */
-  LLVMBinaryTypeIR, /**< LLVM IR. */
-  LLVMBinaryTypeWinRes, /**< Windows resource (.res) file. */
-  LLVMBinaryTypeCOFF,   /**< COFF Object file. */
-  LLVMBinaryTypeELF32L, /**< ELF 32-bit, little endian. */
-  LLVMBinaryTypeELF32B, /**< ELF 32-bit, big endian. */
-  LLVMBinaryTypeELF64L, /**< ELF 64-bit, little endian. */
-  LLVMBinaryTypeELF64B, /**< ELF 64-bit, big endian. */
-  LLVMBinaryTypeMachO32L,   /**< MachO 32-bit, little endian. */
-  LLVMBinaryTypeMachO32B,   /**< MachO 32-bit, big endian. */
-  LLVMBinaryTypeMachO64L,   /**< MachO 64-bit, little endian. */
-  LLVMBinaryTypeMachO64B,   /**< MachO 64-bit, big endian. */
-  LLVMBinaryTypeWasm,   /**< Web Assembly. */
+  LLVMBinaryTypeArchive,  /**< Archive file. */
+  LLVMBinaryTypeMachOUniversalBinary, /**< Mach-O Universal Binary file. */
+  LLVMBinaryTypeCOFFImportFile,   /**< COFF Import file. */
+  LLVMBinaryTypeIR,   /**< LLVM IR. */
+  LLVMBinaryTypeWinRes,   /**< Windows resource (.res) file. */
+  LLVMBinaryTypeCOFF, /**< COFF Object file. */
+  LLVMBinaryTypeELF32L,   /**< ELF 32-bit, little endian. */
+  LLVMBinaryTypeELF32B,   /**< ELF 32-bit, big endian. */
+  LLVMBinaryTypeELF64L,   /**< ELF 64-bit, little endian. */
+  LLVMBinaryTypeELF64B,   /**< ELF 64-bit, big endian. */
+  LLVMBinaryTypeMachO32L, /**< MachO 32-bit, little endian. */
+  LLVMBinaryTypeMachO32B, /**< MachO 32-bit, big endian. */
+  LLVMBinaryTypeMachO64L, /**< MachO 64-bit, little endian. */
+  LLVMBinaryTypeMachO64B, /**< MachO 64-bit, big endian. */
+  LLVMBinaryTypeWasm, /**< Web Assembly. */
+  LLVMBinaryTypeOffload,  /**< Offloading fatbinary. */
+
 } LLVMBinaryType;
 
 /**

diff  --git a/llvm/include/llvm/BinaryFormat/Magic.h 
b/llvm/include/llvm/BinaryFormat/Magic.h
index b6bc4e9b2a7a3..c8e0dad42b0bc 100644
--- a/llvm/include/llvm/BinaryFormat/Magic.h
+++ b/llvm/include/llvm/BinaryFormat/Magic.h
@@ -52,6 +52,7 @@ struct file_magic {
 pdb, ///< Windows PDB debug info file
 tapi_file,   ///< Text-based Dynamic Library Stub file
 cuda_fatbinary,  ///< CUDA Fatbinary object file
+offload_binary,  

[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-01 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

In D126796#3551781 , @cjdb wrote:

> In D126796#3551312 , @tschuett 
> wrote:
>
>> Would a JSON dump help you for your tools?
>
> Do you think a JSON dump would be more appropriate? I was just going for 
> something not unlike `--help` here.

I thought that you need this for your diagnostics campaign.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D126758: [clang-format] Handle do-while loops for RemoveBracesLLVM

2022-06-01 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.h:118-119
   TokenType NextLBracesType = TT_Unknown,
+  bool *HasDoWhile = nullptr,
   bool *HasLabel = nullptr);
   bool tryToParseBracedList();

HazardyKnusperkeks wrote:
> Should we merge that to something like `KeepBraces`? Or do we use `HasLabel` 
> and `HasDoWhile` differently?
We will use them differently. There will be no configuration for labels but 
some configurations for do-while loops eventually.


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

https://reviews.llvm.org/D126758

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


[PATCH] D126084: [Sema] Reject list-initialization of a scoped enum variable from an element of a different scoped enum type

2022-06-01 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:4506
 !S.Context.hasSameUnqualifiedType(E->getType(), DestType) &&
-(E->getType()->isIntegralOrEnumerationType() ||
+(E->getType()->isIntegralOrUnscopedEnumerationType() ||
  E->getType()->isFloatingType())) {

aaron.ballman wrote:
> ahatanak wrote:
> > ahatanak wrote:
> > > aaron.ballman wrote:
> > > > ahatanak wrote:
> > > > > ahatanak wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > ahatanak wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > This doesn't match the comments immediately above here and I 
> > > > > > > > > don't think is the correct fix.
> > > > > > > > > 
> > > > > > > > > We're handling this case: 
> > > > > > > > > http://eel.is/c++draft/dcl.init.list#3.8
> > > > > > > > > 
> > > > > > > > > A scoped enumeration has a fixed underlying type 
> > > > > > > > > (https://eel.is/c++draft/dcl.enum#5.sentence-5). The 
> > > > > > > > > initializer list has a single element and that element can be 
> > > > > > > > > implicitly converted to the underlying type (`int` in all of 
> > > > > > > > > the test cases changed in this patch). And this is a direct 
> > > > > > > > > initialization case, so I think we should be performing the 
> > > > > > > > > conversion here rather than skipping to the next bullet.
> > > > > > > > Can scoped enums be implicitly converted to integer types? 
> > > > > > > > Unscoped enums can be converted to an integer type, but I don't 
> > > > > > > > see any mention of scoped enums here: 
> > > > > > > > https://eel.is/c++draft/conv.integral
> > > > > > > > 
> > > > > > > > It seems that the original paper was trying to change the rules 
> > > > > > > > about conversions from the underlying type to a scoped enum. It 
> > > > > > > > doesn't look like it's allowing conversion from a scope enum to 
> > > > > > > > another scope enum.
> > > > > > > > 
> > > > > > > > https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0138r2.pdf
> > > > > > > > Can scoped enums be implicitly converted to integer types? 
> > > > > > > > Unscoped enums can be converted to an integer type, but I don't 
> > > > > > > > see any mention of scoped enums here: 
> > > > > > > > https://eel.is/c++draft/conv.integral
> > > > > > > 
> > > > > > > Correct, they cannot be implicitly converted to an integer.
> > > > > > > 
> > > > > > > > It seems that the original paper was trying to change the rules 
> > > > > > > > about conversions from the underlying type to a scoped enum. It 
> > > > > > > > doesn't look like it's allowing conversion from a scope enum to 
> > > > > > > > another scope enum.
> > > > > > > 
> > > > > > > Agreed, however, I think where we want this to fail is below in 
> > > > > > > the attempt at conversion. "v can be implicitly converted to U" 
> > > > > > > is the part that should be failing here, and we're now skipping 
> > > > > > > over the bit of code that's checking whether the implicit 
> > > > > > > conversion is valid.
> > > > > > Is the code below checking whether the implicit conversion is 
> > > > > > valid? It looks like it's assuming the implicit conversion is valid 
> > > > > > and adding an implicit conversion sequence based on that 
> > > > > > assumption. If the source is an integer, unscoped enum, or floating 
> > > > > > type, the implicit conversion that is performed later should 
> > > > > > succeed except when there is narrowing.
> > > > > > 
> > > > > > Or are you suggesting we should add a check to 
> > > > > > `Sema::PerformImplicitConversion` that rejects conversions from 
> > > > > > scoped enums to other types? It seems to me that it's better to 
> > > > > > detect the error earlier.
> > > > > Alternatively, we can emit a diagnostic in the code below that 
> > > > > specifically calls out conversion from scoped enums to integer types.
> > > > > Is the code below checking whether the implicit conversion is valid? 
> > > > 
> > > > It's forming the conversion sequence as-if it must be valid, but that 
> > > > causes us to get the right diagnostics. We do the same for narrowing 
> > > > float conversions: 
> > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaInit.cpp#L4521
> > > >  and I would expect us to then need changes so we get to here: 
> > > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaInit.cpp#L8478
> > > But a conversion from a scoped enum to another scoped enum or its 
> > > underlying type isn't a narrowing conversion unless the conversion from 
> > > the underlying type is narrowing. I guess the current code is forming the 
> > > conversion sequence as if it is valid when the source type is a floating 
> > > type just to call `DiagnoseNarrowingInInitList`. @rsmith, any comments?
> > > 
> > > If we want to detect the invalid conversion while performing conversion, 
> > > shouldn't the call to `PerformImplicitConversion`, which is called before 

[PATCH] D126832: [clang][tablegen] adds human documentation to `WarningOption`

2022-06-01 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added a reviewer: aaron.ballman.
Herald added subscribers: usaxena95, arphaman.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Building on D126796 , this commit adds the 
infrastructure for being able
to print out descriptions of what each warning does.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126832

Files:
  clang/include/clang/Basic/DiagnosticCategories.h
  clang/include/clang/Basic/DiagnosticIDs.h
  clang/lib/Basic/DiagnosticIDs.cpp
  clang/tools/diagtool/DiagnosticNames.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Index: clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
===
--- clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
+++ clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
@@ -1534,14 +1534,24 @@
 const bool hasSubGroups =
 !SubGroups.empty() || (IsPedantic && !GroupsInPedantic.empty());
 if (hasSubGroups) {
-  OS << "/* DiagSubGroup" << I.second.IDNo << " */ " << SubGroupIndex;
+  OS << "/* DiagSubGroup" << I.second.IDNo << " */ " << SubGroupIndex
+ << ", ";
   if (IsPedantic)
 SubGroupIndex += GroupsInPedantic.size();
   SubGroupIndex += SubGroups.size() + 1;
 } else {
-  OS << "0";
+  OS << "0, ";
 }
 
+std::string Documentation = I.second.Defs.back()
+->getValue("Documentation")
+->getValue()
+->getAsUnquotedString();
+if (!Documentation.empty())
+  OS << "R\"(" << StringRef(Documentation).trim() << ")\"";
+else
+  OS << R"("")";
+
 OS << ")\n";
   }
   OS << "#endif // DIAG_ENTRY\n\n";
Index: clang/tools/diagtool/DiagnosticNames.cpp
===
--- clang/tools/diagtool/DiagnosticNames.cpp
+++ clang/tools/diagtool/DiagnosticNames.cpp
@@ -66,7 +66,7 @@
 
 // Second the table of options, sorted by name for fast binary lookup.
 static const GroupRecord OptionTable[] = {
-#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups)  \
+#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups, Docs)\
   {FlagNameOffset, Members, SubGroups},
 #include "clang/Basic/DiagnosticGroups.inc"
 #undef DIAG_ENTRY
Index: clang/lib/Basic/DiagnosticIDs.cpp
===
--- clang/lib/Basic/DiagnosticIDs.cpp
+++ clang/lib/Basic/DiagnosticIDs.cpp
@@ -607,6 +607,7 @@
 uint16_t NameOffset;
 uint16_t Members;
 uint16_t SubGroups;
+StringRef Documentation;
 
 // String is stored with a pascal-style length byte.
 StringRef getName() const {
@@ -618,12 +619,17 @@
 
 // Second the table of options, sorted by name for fast binary lookup.
 static const WarningOption OptionTable[] = {
-#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups)  \
-  {FlagNameOffset, Members, SubGroups},
+#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups, Docs)\
+  {FlagNameOffset, Members, SubGroups, Docs},
 #include "clang/Basic/DiagnosticGroups.inc"
 #undef DIAG_ENTRY
 };
 
+/// getDocumentation Given a diagnostic group ID, return its documentation.
+StringRef DiagnosticIDs::getWarningOptionDocumentation(diag::Group Group) {
+  return OptionTable[static_cast(Group)].Documentation;
+}
+
 StringRef DiagnosticIDs::getWarningOptionForGroup(diag::Group Group) {
   return OptionTable[static_cast(Group)].getName();
 }
Index: clang/include/clang/Basic/DiagnosticIDs.h
===
--- clang/include/clang/Basic/DiagnosticIDs.h
+++ clang/include/clang/Basic/DiagnosticIDs.h
@@ -231,6 +231,9 @@
   /// "deprecated-declarations".
   static StringRef getWarningOptionForGroup(diag::Group);
 
+  /// Given a diagnostic group ID, return its documentation.
+  static StringRef getWarningOptionDocumentation(diag::Group GroupID);
+
   /// Given a group ID, returns the flag that toggles the group.
   /// For example, for "deprecated-declarations", returns
   /// Group::DeprecatedDeclarations.
Index: clang/include/clang/Basic/DiagnosticCategories.h
===
--- clang/include/clang/Basic/DiagnosticCategories.h
+++ clang/include/clang/Basic/DiagnosticCategories.h
@@ -21,7 +21,8 @@
 };
 
 enum class Group {
-#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups) GroupName,
+#define DIAG_ENTRY(GroupName, FlagNameOffset, Members, SubGroups, Docs)\
+  GroupName,
 #include "clang/Basic/DiagnosticGroups.inc"
 #undef CATEGORY
 #undef DIAG_ENTRY
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-01 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D126796#3551312 , @tschuett wrote:

> Would a JSON dump help you for your tools?

Do you think a JSON dump would be more appropriate? I was just going for 
something not unlike `--help` here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D126340: [clang][AIX] add option -mdefault-visibility-export-mapping

2022-06-01 Thread David Tenty via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8c8a2679a20f: [clang][AIX] add option 
mdefault-visibility-export-mapping (authored by daltenty).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126340

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/mdefault-visibility-export-mapping.c
  clang/test/CodeGenCXX/mdefault-visibility-export-mapping-alias.cpp
  clang/test/CodeGenCXX/mdefault-visibility-export-mapping-rtti.cpp
  clang/test/CodeGenCXX/mdefault-visibility-export-mapping.cpp

Index: clang/test/CodeGenCXX/mdefault-visibility-export-mapping.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/mdefault-visibility-export-mapping.cpp
@@ -0,0 +1,119 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -S -emit-llvm -o - | \
+// RUN:   FileCheck -check-prefixes=CHECK,UNSPECIFIED-DEF,EXPLICIT-DEF %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -mdefault-visibility-export-mapping=none -S -emit-llvm -o - | \
+// RUN:   FileCheck -check-prefixes=CHECK,UNSPECIFIED-DEF,EXPLICIT-DEF %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -mdefault-visibility-export-mapping=explicit -S -emit-llvm -o - | \
+// RUN:   FileCheck -check-prefixes=CHECK,UNSPECIFIED-DEF,EXPLICIT-EXP %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix %s -mdefault-visibility-export-mapping=all -S -emit-llvm -o - | \
+// RUN:   FileCheck -check-prefixes=CHECK,UNSPECIFIED-EXP,EXPLICIT-EXP %s
+
+struct A {};
+
+template 
+class B {
+public:
+  T x;
+  B(T _x) : x(_x) {}
+  ~B() {}
+  void func(T x) {}
+};
+
+template 
+class __attribute__((visibility("default"))) C {
+public:
+  T x;
+  C(T _x) : x(_x) {}
+  ~C() {}
+  void func(T x) {}
+};
+
+class D {
+public:
+  ~D();
+};
+
+D::~D() {}
+
+extern template class B;
+extern template class C;
+
+void func() {
+  B x({});
+  C y({});
+  x.func({});
+  y.func({});
+  B xi(0);
+  C yi(0);
+  xi.func(0);
+  yi.func(0);
+  D z;
+}
+
+// D::~D() (base object destructor)
+// UNSPECIFIED-DEF:  define void @_ZN1DD2Ev(
+// UNSPECIFIED-EXP:  define dllexport void @_ZN1DD2Ev(
+
+// D::~D() (complete object destructor)
+// UNSPECIFIED-DEF:  define void @_ZN1DD1Ev(
+// UNSPECIFIED-EXP:  define dllexport void @_ZN1DD1Ev(
+
+// UNSPECIFIED-DEF: define void @_Z4funcv(
+// UNSPECIFIED-EXP: define dllexport void @_Z4funcv(
+
+// B::B(A) (complete object constructor)
+// UNSPECIFIED-DEF: define linkonce_odr void @_ZN1BI1AEC1ES0_(
+// UNSPECIFIED-EXP: define linkonce_odr dllexport void @_ZN1BI1AEC1ES0_(
+
+// C::C(A) (complete object constructor)
+// EXPLICIT-DEF: define linkonce_odr void @_ZN1CI1AEC1ES0_(
+// EXPLICIT-EXP: define linkonce_odr dllexport void @_ZN1CI1AEC1ES0_(
+
+// B::func(A)
+// UNSPECIFIED-DEF: define linkonce_odr void @_ZN1BI1AE4funcES0_(
+// UNSPECIFIED-EXP: define linkonce_odr dllexport void @_ZN1BI1AE4funcES0_(
+
+// C::func(A)
+// EXPLICIT-DEF: define linkonce_odr void @_ZN1CI1AE4funcES0_(
+// EXPLICIT-EXP: define linkonce_odr dllexport void @_ZN1CI1AE4funcES0_(
+
+// B::B(int) (complete object constructor)
+// CHECK: declare void @_ZN1BIiEC1Ei
+
+// C::C(int) (complete object constructor)
+// CHECK: declare void @_ZN1CIiEC1Ei
+
+// B::func(int)
+// CHECK: declare void @_ZN1BIiE4funcEi
+
+// C::func(int)
+// CHECK: declare void @_ZN1CIiE4funcEi
+
+// C::~C() (complete object destructor)
+// CHECK: declare void @_ZN1CIiED1Ev
+
+// B::~B() (complete object destructor)
+// CHECK: declare void @_ZN1BIiED1Ev
+
+// C::~c() (complete object destructor)
+// EXPLICIT-DEF: define linkonce_odr void @_ZN1CI1AED1Ev(
+// EXPLICIT-EXP: define linkonce_odr dllexport void @_ZN1CI1AED1Ev(
+
+// B::~B() (complete object destructor)
+// UNSPECIFIED-DEF: define linkonce_odr void @_ZN1BI1AED1Ev(
+// UNSPECIFIED-EXP: define linkonce_odr dllexport void @_ZN1BI1AED1Ev(
+
+// B::B(A) (base object constructor)
+// UNSPECIFIED-DEF: define linkonce_odr void @_ZN1BI1AEC2ES0_(
+// UNSPECIFIED-EXP: define linkonce_odr dllexport void @_ZN1BI1AEC2ES0_(
+
+// B::~B() (base object destructor)
+// UNSPECIFIED-DEF: define linkonce_odr void @_ZN1BI1AED2Ev(
+// UNSPECIFIED-EXP: define linkonce_odr dllexport void @_ZN1BI1AED2Ev(
+
+// C::C(A) (base object constructor)
+// EXPLICIT-DEF: define linkonce_odr void @_ZN1CI1AEC2ES0_(
+// EXPLICIT-EXP: define linkonce_odr dllexport void @_ZN1CI1AEC2ES0_(
+
+// C::~C() (base object destructor)
+// EXPLICIT-DEF: define linkonce_odr void @_ZN1CI1AED2Ev(
+// EXPLICIT-EXP: define linkonce_odr dllexport void @_ZN1CI1AED2Ev(

[clang] 8c8a267 - [clang][AIX] add option mdefault-visibility-export-mapping

2022-06-01 Thread David Tenty via cfe-commits

Author: David Tenty
Date: 2022-06-01T18:07:17-04:00
New Revision: 8c8a2679a20f621994fa904bcfc68775e7345edc

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

LOG: [clang][AIX] add option mdefault-visibility-export-mapping

The option mdefault-visibility-export-mapping is created to allow
mapping default visibility to an explicit shared library export
(e.g. dllexport). Exactly how and if this is manifested is target
dependent (since it depends on how they map dllexport in the IR).

Three values are provided for the option:

* none: the default and behavior without the option, no additional export 
linkage information is created.
* explicit: add the export for entities with explict default visibility from 
the source, including RTTI
* all: add the export for all entities with default visibility

This option is useful for targets which do not export symbols as part of
their usual default linkage behaviour (e.g. AIX), such targets
traditionally specified such information in external files (e.g. export
lists), but this mapping allows them to use the visibility information
typically used for this purpose on other (e.g. ELF) platforms.

Reviewed By: MaskRay

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

Added: 
clang/test/CodeGen/mdefault-visibility-export-mapping.c
clang/test/CodeGenCXX/mdefault-visibility-export-mapping-alias.cpp
clang/test/CodeGenCXX/mdefault-visibility-export-mapping-rtti.cpp
clang/test/CodeGenCXX/mdefault-visibility-export-mapping.cpp

Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenModule.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index b8c468333a67b..e12dc72407b13 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3626,6 +3626,23 @@ Clang expects the GCC executable "gcc.exe" compiled for
 `Some tests might fail `_ on
 ``x86_64-w64-mingw32``.
 
+AIX
+^^^
+
+The ``-mdefault-visibility-export-mapping=`` option can be used to control
+mapping of default visibility to an explicit shared object export
+(i.e. XCOFF exported visibility). Three values are provided for the option:
+
+* ``-mdefault-visibility-export-mapping=none``: no additional export
+  information is created for entities with default visibility.
+* ``-mdefault-visibility-export-mapping=explicit``: mark entities for export
+  if they have explict (e.g. via an attribute) default visibility from the
+  source, including RTTI.
+* ``-mdefault-visibility-export-mapping=all``: set XCOFF exported visibility
+  for all entities with default visibility from any source. This gives a
+  export behavior similar to ELF platforms where all entities with default
+  visibility are exported.
+
 .. _spir-v:
 
 SPIR-V support

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 6e1a01c6c9767..4a52a65847bbb 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -289,6 +289,7 @@ BENIGN_LANGOPT(DumpRecordLayoutsComplete , 1, 0, "dumping 
the AST layout of all
 BENIGN_LANGOPT(DumpVTableLayouts , 1, 0, "dumping the layouts of emitted 
vtables")
 LANGOPT(NoConstantCFStrings , 1, 0, "no constant CoreFoundation strings")
 BENIGN_LANGOPT(InlineVisibilityHidden , 1, 0, "hidden visibility for inline 
C++ methods")
+BENIGN_ENUM_LANGOPT(DefaultVisibilityExportMapping, 
DefaultVisiblityExportMapping, 2, DefaultVisiblityExportMapping::None, 
"controls mapping of default visibility to dllexport")
 BENIGN_LANGOPT(IgnoreXCOFFVisibility, 1, 0, "All the visibility attributes 
that are specified in the source code are ignored in aix XCOFF.")
 BENIGN_LANGOPT(VisibilityInlinesHiddenStaticLocalVar, 1, 0,
"hidden visibility for static local variables in inline C++ "

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index 6e7763a4a2b47..575fa5a920cbf 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -350,6 +350,14 @@ class LangOptions : public LangOptionsBase {
 PerThread,
   };
 
+  enum class DefaultVisiblityExportMapping {
+None,
+/// map only explicit default visibilities to exported
+Explicit,
+/// map all default visibilities to exported
+All,
+  };
+
 public:
   /// The used language standard.
   LangStandard::Kind LangStd;
@@ -581,6 +589,16 @@ class 

[PATCH] D120007: [OMPIRBuilder] Add the support for compare capture

2022-06-01 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 433558.
tianshilei1992 added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120007

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -3475,18 +3475,21 @@
 
   OpenMPIRBuilder::AtomicOpValue XSigned = {XVal, Int32, true, false};
   OpenMPIRBuilder::AtomicOpValue XUnsigned = {XVal, Int32, false, false};
+  // V and R are not used in atomic compare
+  OpenMPIRBuilder::AtomicOpValue V = {nullptr, nullptr, false, false};
+  OpenMPIRBuilder::AtomicOpValue R = {nullptr, nullptr, false, false};
   AtomicOrdering AO = AtomicOrdering::Monotonic;
   ConstantInt *Expr = ConstantInt::get(Type::getInt32Ty(Ctx), 1U);
   ConstantInt *D = ConstantInt::get(Type::getInt32Ty(Ctx), 1U);
   OMPAtomicCompareOp OpMax = OMPAtomicCompareOp::MAX;
   OMPAtomicCompareOp OpEQ = OMPAtomicCompareOp::EQ;
 
-  Builder.restoreIP(OMPBuilder.createAtomicCompare(Builder, XSigned, Expr,
-   nullptr, AO, OpMax, true));
-  Builder.restoreIP(OMPBuilder.createAtomicCompare(Builder, XUnsigned, Expr,
-   nullptr, AO, OpMax, false));
-  Builder.restoreIP(OMPBuilder.createAtomicCompare(Builder, XSigned, Expr, D,
-   AO, OpEQ, true));
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, XSigned, V, R, Expr, nullptr, AO, OpMax, true, false, false));
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, XUnsigned, V, R, Expr, nullptr, AO, OpMax, false, false, false));
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, XSigned, V, R, Expr, D, AO, OpEQ, true, false, false));
 
   BasicBlock *EntryBB = BB;
   EXPECT_EQ(EntryBB->getParent()->size(), 1U);
@@ -3515,6 +3518,257 @@
   EXPECT_FALSE(verifyModule(*M, ()));
 }
 
+TEST_F(OpenMPIRBuilderTest, OMPAtomicCompareCapture) {
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+  F->setName("func");
+  IRBuilder<> Builder(BB);
+
+  OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
+
+  LLVMContext  = M->getContext();
+  IntegerType *Int32 = Type::getInt32Ty(Ctx);
+  AllocaInst *XVal = Builder.CreateAlloca(Int32);
+  XVal->setName("x");
+  AllocaInst *VVal = Builder.CreateAlloca(Int32);
+  VVal->setName("v");
+  AllocaInst *RVal = Builder.CreateAlloca(Int32);
+  RVal->setName("r");
+
+  StoreInst *Init =
+  Builder.CreateStore(ConstantInt::get(Type::getInt32Ty(Ctx), 0U), XVal);
+
+  OpenMPIRBuilder::AtomicOpValue X = {XVal, Int32, true, false};
+  OpenMPIRBuilder::AtomicOpValue V = {VVal, Int32, false, false};
+  OpenMPIRBuilder::AtomicOpValue NoV = {nullptr, nullptr, false, false};
+  OpenMPIRBuilder::AtomicOpValue R = {RVal, Int32, false, false};
+  OpenMPIRBuilder::AtomicOpValue NoR = {nullptr, nullptr, false, false};
+
+  AtomicOrdering AO = AtomicOrdering::Monotonic;
+  ConstantInt *Expr = ConstantInt::get(Type::getInt32Ty(Ctx), 1U);
+  ConstantInt *D = ConstantInt::get(Type::getInt32Ty(Ctx), 1U);
+  OMPAtomicCompareOp OpMax = OMPAtomicCompareOp::MAX;
+  OMPAtomicCompareOp OpEQ = OMPAtomicCompareOp::EQ;
+
+  // { cond-update-stmt v = x; }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, NoR, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ false,
+  /* IsFailOnly */ false));
+  // { v = x; cond-update-stmt }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, NoR, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ true,
+  /* IsFailOnly */ false));
+  // if(x == e) { x = d; } else { v = x; }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, NoR, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ false,
+  /* IsFailOnly */ true));
+  // { r = x == e; if(r) { x = d; } }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, NoV, R, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ false,
+  /* IsFailOnly */ false));
+  // { r = x == e; if(r) { x = d; } else { v = x; } }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, R, Expr, D, AO, OpEQ, /* IsXBinopExpr */ true,
+  /* IsPostfixUpdate */ false,
+  /* IsFailOnly */ true));
+
+  // { v = x; cond-update-stmt }
+  Builder.restoreIP(OMPBuilder.createAtomicCompare(
+  Builder, X, V, NoR, Expr, nullptr, AO, OpMax, /* IsXBinopExpr 

[PATCH] D124699: [DeadArgElim] Set unused arguments for internal functions

2022-06-01 Thread Quentin Colombet via Phabricator via cfe-commits
qcolombet added a comment.

> But that's not a problem of this patch, and we will address that later if 
> needed.

Thanks for looking into it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124699

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


[PATCH] D126602: [Clang][OpenMP] Replace IgnoreImpCasts with IgnoreImplicitAsWritten in atomic compare

2022-06-01 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 added a comment.

In D126602#3548997 , @ABataev wrote:

> Can you add the test?

I don't have a good test off the top of my head.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126602

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


[PATCH] D126812: [Binary] Promote OffloadBinary to inherit from Binary

2022-06-01 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/lib/Object/OffloadBinary.cpp:28
+  if (identify_magic(Buf.getBuffer()) != file_magic::offload_binary)
 return errorCodeToError(llvm::object::object_error::parse_failed);
 

It could be just `object_error::parse_failed` now. Applies to the return above, 
too.



Comment at: llvm/unittests/Object/OffloadingTest.cpp:8
+using namespace llvm;
+using namespace object;
+

Nit: `using namespace llvm::object;` 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126812

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


[PATCH] D126816: Only issue warning for subtraction involving null pointers on live code paths

2022-06-01 Thread Andres Freund via Phabricator via cfe-commits
anarazel added a comment.

So far the tests in pointer-subtraction.c are mirrored in 
pointer-subtraction.cpp - worth continuing to do?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126816

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


[PATCH] D126812: [Binary] Promote OffloadBinary to inherit from Binary

2022-06-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 433534.
jhuber6 added a comment.

Addressing comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126812

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm-c/Object.h
  llvm/include/llvm/BinaryFormat/Magic.h
  llvm/include/llvm/Object/Binary.h
  llvm/include/llvm/Object/OffloadBinary.h
  llvm/lib/BinaryFormat/Magic.cpp
  llvm/lib/Object/Binary.cpp
  llvm/lib/Object/Object.cpp
  llvm/lib/Object/ObjectFile.cpp
  llvm/lib/Object/OffloadBinary.cpp
  llvm/unittests/Object/OffloadingTest.cpp

Index: llvm/unittests/Object/OffloadingTest.cpp
===
--- llvm/unittests/Object/OffloadingTest.cpp
+++ llvm/unittests/Object/OffloadingTest.cpp
@@ -4,6 +4,9 @@
 #include "gtest/gtest.h"
 #include 
 
+using namespace llvm;
+using namespace object;
+
 TEST(OffloadingTest, checkOffloadingBinary) {
   // Create random data to fill the image.
   std::mt19937 Rng(std::random_device{}());
@@ -27,23 +30,22 @@
   }
 
   // Create the image.
-  llvm::StringMap StringData;
+  StringMap StringData;
   for (auto  : Strings)
 StringData[KeyAndValue.first] = KeyAndValue.second;
-  std::unique_ptr ImageData =
-  llvm::MemoryBuffer::getMemBuffer(
-  {reinterpret_cast(Image.data()), Image.size()}, "", false);
+  std::unique_ptr ImageData = MemoryBuffer::getMemBuffer(
+  {reinterpret_cast(Image.data()), Image.size()}, "", false);
 
-  llvm::OffloadBinary::OffloadingImage Data;
-  Data.TheImageKind = static_cast(KindDist(Rng));
-  Data.TheOffloadKind = static_cast(KindDist(Rng));
+  OffloadBinary::OffloadingImage Data;
+  Data.TheImageKind = static_cast(KindDist(Rng));
+  Data.TheOffloadKind = static_cast(KindDist(Rng));
   Data.Flags = KindDist(Rng);
   Data.StringData = StringData;
   Data.Image = *ImageData;
 
-  auto BinaryBuffer = llvm::OffloadBinary::write(Data);
+  auto BinaryBuffer = OffloadBinary::write(Data);
 
-  auto BinaryOrErr = llvm::OffloadBinary::create(*BinaryBuffer);
+  auto BinaryOrErr = OffloadBinary::create(*BinaryBuffer);
   if (!BinaryOrErr)
 FAIL();
 
@@ -60,6 +62,6 @@
   EXPECT_TRUE(Data.Image.getBuffer() == Binary.getImage());
 
   // Ensure the size and alignment of the data is correct.
-  EXPECT_TRUE(Binary.getSize() % llvm::OffloadBinary::getAlignment() == 0);
+  EXPECT_TRUE(Binary.getSize() % OffloadBinary::getAlignment() == 0);
   EXPECT_TRUE(Binary.getSize() == BinaryBuffer->getBuffer().size());
 }
Index: llvm/lib/Object/OffloadBinary.cpp
===
--- llvm/lib/Object/OffloadBinary.cpp
+++ llvm/lib/Object/OffloadBinary.cpp
@@ -9,21 +9,22 @@
 #include "llvm/Object/OffloadBinary.h"
 
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/BinaryFormat/Magic.h"
 #include "llvm/MC/StringTableBuilder.h"
 #include "llvm/Object/Error.h"
 #include "llvm/Support/FileOutputBuffer.h"
 
-using namespace llvm;
-
 namespace llvm {
 
+namespace object {
+
 Expected>
 OffloadBinary::create(MemoryBufferRef Buf) {
   if (Buf.getBufferSize() < sizeof(Header) + sizeof(Entry))
 return errorCodeToError(llvm::object::object_error::parse_failed);
 
   // Check for 0x10FF1OAD magic bytes.
-  if (!Buf.getBuffer().startswith("\x10\xFF\x10\xAD"))
+  if (identify_magic(Buf.getBuffer()) != file_magic::offload_binary)
 return errorCodeToError(llvm::object::object_error::parse_failed);
 
   const char *Start = Buf.getBufferStart();
@@ -32,7 +33,7 @@
   reinterpret_cast([TheHeader->EntryOffset]);
 
   return std::unique_ptr(
-  new OffloadBinary(Buf.getBufferStart(), TheHeader, TheEntry));
+  new OffloadBinary(Buf, TheHeader, TheEntry));
 }
 
 std::unique_ptr
@@ -141,4 +142,6 @@
   }
 }
 
+} // namespace object
+
 } // namespace llvm
Index: llvm/lib/Object/ObjectFile.cpp
===
--- llvm/lib/Object/ObjectFile.cpp
+++ llvm/lib/Object/ObjectFile.cpp
@@ -147,6 +147,7 @@
   case file_magic::minidump:
   case file_magic::goff_object:
   case file_magic::cuda_fatbinary:
+  case file_magic::offload_binary:
   case file_magic::dxcontainer_object:
 return errorCodeToError(object_error::invalid_file_type);
   case file_magic::tapi_file:
Index: llvm/lib/Object/Object.cpp
===
--- llvm/lib/Object/Object.cpp
+++ llvm/lib/Object/Object.cpp
@@ -120,6 +120,8 @@
 return LLVMBinaryTypeMachO64L;
   case ID_MachO64B:
 return LLVMBinaryTypeMachO64B;
+  case ID_Offload:
+return LLVMBinaryTypeOffload;
   case ID_Wasm:
 return LLVMBinaryTypeWasm;
   case ID_StartObjects:
Index: llvm/lib/Object/Binary.cpp
===
--- llvm/lib/Object/Binary.cpp
+++ llvm/lib/Object/Binary.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Object/MachOUniversal.h"
 

[PATCH] D126172: [clang] Fix comparison of TemplateArgument when they are of template kind

2022-06-01 Thread Robert Esclapez via Phabricator via cfe-commits
roberteg16 added a comment.

@rsmith polite ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126172

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


[PATCH] D126812: [Binary] Promote OffloadBinary to inherit from Binary

2022-06-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

Thanks for the comments, I'll address them real quick.




Comment at: llvm/include/llvm/Object/OffloadBinary.h:121
 const Entry *TheEntry)
-  : Buffer(Buffer), TheHeader(TheHeader), TheEntry(TheEntry) {
-
+  : Binary(Binary::ID_Offload, Source), Buffer(Source.getBufferStart()),
+TheHeader(TheHeader), TheEntry(TheEntry) {

tra wrote:
> We're losing information by passing only the start of the buffer.
> I'd change the type of `Buffer` field to `MemoryBufferRef` instead.
Forgot to remove this one. I just put this here for convenience's sake since I 
need to index the `MemoryBufferRef` directly as a char array. The underlying 
`Binary` type already contains the buffer ref so we're not losing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126812

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


[PATCH] D126804: [scan-build-py] Change scripts to explicitly require python3

2022-06-01 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126804

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


[PATCH] D126818: Itanium ABI: Implement mangling for constrained friends

2022-06-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a subscriber: rsmith.
erichkeane added a comment.

Note this was mentioned as a 'must also do' in my discussion on deferred 
constraints with @rsmith, however as this already fails, I don't see this as a 
prerequisite.  However, I think this is easy enough to just do.

THAT SAID: The proposal on the itanium-abi github wasn't particularly clear as 
to which of the following three options were the 'right' answer.  I'm hoping 
@rjmccall can decide whether this is acceptable:

Option 1: Change the mangling of ALL friend functions.  I determined this is 
likely an ABI break on otherwise 'settled' code, and figured we wouldn't want 
to do this.

Option 2: Change the mangling for ALL constrained friend functions.  This 
seemed easy enough to do, AND changes the mangling for things only covered by 
'experimental' concepts support.  So I think changing the ABI for current 
things is OK here.

Option 3: Change the mangling for constrained friend functions that fall under 
temp.friend p9.  The only difference between this and Option2 is that this 
would need to check the 'template friend function depends on containing scope'. 
 I don't believe this is necessary so long as we are consistent with it.  
Presumably this could end up with multiple symbols for functions that are the 
'same declaration' by rule in separate translation units, such as:

  struct Base{};
  template
  struct S {
template
friend void func(Base&) requires(U::value) {}
  };
  void uses() {
S<1> s;
S<2> s2; // This is an error during Sema, since 'func' is a duplicate here.
func(s); // all Ss SHOULD end up with the same declaration, but in 
different TUs they might end up with different copies here?
  }

In typing this comment up, I believe I got the 'option' wrong here.  Should I 
have gone with #3 above?   I'm going to think about it overnight (and hope you 
reviewer folks can chime in!) and get to it in the morning.


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

https://reviews.llvm.org/D126818

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


[clang] 5d005d8 - Refactor PS4OSTargetInfo into a base class and PS4 subclass; prep for PS5

2022-06-01 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-06-01T13:30:29-07:00
New Revision: 5d005d8256ecd7d57c72e24e7169c4e3d40a773a

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

LOG: Refactor PS4OSTargetInfo into a base class and PS4 subclass; prep for PS5

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index e9832977c7fe8..cf317f58540e3 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -541,8 +541,9 @@ class LLVM_LIBRARY_VISIBILITY PS3PPUTargetInfo : public 
OSTargetInfo {
   }
 };
 
+// Common base class for PS4/PS5 targets.
 template 
-class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public OSTargetInfo {
+class LLVM_LIBRARY_VISIBILITY PSOSTargetInfo : public OSTargetInfo {
 protected:
   void getOSDefines(const LangOptions , const llvm::Triple ,
 MacroBuilder ) const override {
@@ -552,36 +553,49 @@ class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public 
OSTargetInfo {
 DefineStd(Builder, "unix", Opts);
 Builder.defineMacro("__ELF__");
 Builder.defineMacro("__SCE__");
-Builder.defineMacro("__ORBIS__");
   }
 
 public:
-  PS4OSTargetInfo(const llvm::Triple , const TargetOptions )
+  PSOSTargetInfo(const llvm::Triple , const TargetOptions )
   : OSTargetInfo(Triple, Opts) {
 this->WCharType = TargetInfo::UnsignedShort;
 
-// On PS4, TLS variable cannot be aligned to more than 32 bytes (256 bits).
+// On PS4/PS5, TLS variable cannot be aligned to more than 32 bytes (256
+// bits).
 this->MaxTLSAlign = 256;
 
-// On PS4, do not honor explicit bit field alignment,
+// On PS4/PS5, do not honor explicit bit field alignment,
 // as in "__attribute__((aligned(2))) int b : 1;".
 this->UseExplicitBitFieldAlignment = false;
 
-switch (Triple.getArch()) {
-default:
-case llvm::Triple::x86_64:
-  this->MCountName = ".mcount";
-  this->NewAlign = 256;
-  this->SuitableAlign = 256;
-  break;
-}
+this->MCountName = ".mcount";
+this->NewAlign = 256;
+this->SuitableAlign = 256;
   }
+
   TargetInfo::CallingConvCheckResult
   checkCallingConvention(CallingConv CC) const override {
 return (CC == CC_C) ? TargetInfo::CCCR_OK : TargetInfo::CCCR_Error;
   }
 };
 
+// PS4 Target
+template 
+class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public PSOSTargetInfo {
+protected:
+  void getOSDefines(const LangOptions , const llvm::Triple ,
+MacroBuilder ) const override {
+// Start with base class defines.
+PSOSTargetInfo::getOSDefines(Opts, Triple, Builder);
+
+Builder.defineMacro("__ORBIS__");
+  }
+
+public:
+  PS4OSTargetInfo(const llvm::Triple , const TargetOptions )
+  : PSOSTargetInfo(Triple, Opts) {}
+};
+
 // RTEMS Target
 template 
 class LLVM_LIBRARY_VISIBILITY RTEMSTargetInfo : public OSTargetInfo {



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


[clang] 8869ba3 - [PS5] Add PS5OSTargetInfo class, update affected tests

2022-06-01 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-06-01T13:30:29-07:00
New Revision: 8869ba366268c644200784b15c4e6b8efe891397

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

LOG: [PS5] Add PS5OSTargetInfo class, update affected tests

Added: 


Modified: 
clang/lib/Basic/LangStandards.cpp
clang/lib/Basic/Targets.cpp
clang/lib/Basic/Targets/OSTargets.h
clang/test/Preprocessor/init.c
clang/test/Sema/wchar.c
clang/unittests/Tooling/RecursiveASTVisitorTests/LambdaExpr.cpp

Removed: 




diff  --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index a21898dd3c627..5bacc3b164960 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -61,8 +61,8 @@ LangStandard::Kind 
clang::getDefaultLanguageStandard(clang::Language Lang,
 if (CLANG_DEFAULT_STD_C != LangStandard::lang_unspecified)
   return CLANG_DEFAULT_STD_C;
 
-// The PS4 uses C99 as the default C standard.
-if (T.isPS4())
+// The PS4 and PS5 use C99 as the default C standard.
+if (T.isPS())
   return LangStandard::lang_gnu99;
 return LangStandard::lang_gnu17;
   case Language::ObjC:

diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 85c73abde1826..2d6ef998485ae 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -592,6 +592,8 @@ TargetInfo *AllocateTarget(const llvm::Triple ,
   return new NaClTargetInfo(Triple, Opts);
 case llvm::Triple::PS4:
   return new PS4OSTargetInfo(Triple, Opts);
+case llvm::Triple::PS5:
+  return new PS5OSTargetInfo(Triple, Opts);
 default:
   return new X86_64TargetInfo(Triple, Opts);
 }

diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index cf317f58540e3..a814f681b1468 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -596,6 +596,23 @@ class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public 
PSOSTargetInfo {
   : PSOSTargetInfo(Triple, Opts) {}
 };
 
+// PS5 Target
+template 
+class LLVM_LIBRARY_VISIBILITY PS5OSTargetInfo : public PSOSTargetInfo {
+protected:
+  void getOSDefines(const LangOptions , const llvm::Triple ,
+MacroBuilder ) const override {
+// Start with base class defines.
+PSOSTargetInfo::getOSDefines(Opts, Triple, Builder);
+
+Builder.defineMacro("__PROSPERO__");
+  }
+
+public:
+  PS5OSTargetInfo(const llvm::Triple , const TargetOptions )
+  : PSOSTargetInfo(Triple, Opts) {}
+};
+
 // RTEMS Target
 template 
 class LLVM_LIBRARY_VISIBILITY RTEMSTargetInfo : public OSTargetInfo {

diff  --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 07b5fb86c45c2..61324fd5e43d8 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1241,7 +1241,8 @@
 // TCE:#define __tce__ 1
 // TCE:#define tce 1
 //
-// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 
-triple=x86_64-scei-ps4 < /dev/null | FileCheck -match-full-lines -check-prefix 
PS4 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-scei-ps4 < /dev/null | 
FileCheck --match-full-lines --check-prefixes=PS4,PS4ONLY %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=x86_64-sie-ps5 < /dev/null | 
FileCheck --match-full-lines --check-prefixes=PS4,PS5ONLY %s
 //
 // PS4:#define _LP64 1
 // PS4:#define __BIGGEST_ALIGNMENT__ 32
@@ -1311,8 +1312,9 @@
 // PS4:#define __LP64__ 1
 // PS4:#define __MMX__ 1
 // PS4:#define __NO_MATH_INLINES 1
-// PS4:#define __ORBIS__ 1
+// PS4ONLY:#define __ORBIS__ 1
 // PS4:#define __POINTER_WIDTH__ 64
+// PS5ONLY:#define __PROSPERO__ 1
 // PS4:#define __PTRDIFF_MAX__ 9223372036854775807L
 // PS4:#define __PTRDIFF_TYPE__ long int
 // PS4:#define __PTRDIFF_WIDTH__ 64
@@ -1357,7 +1359,8 @@
 // PS4:#define __x86_64__ 1
 // PS4:#define unix 1
 //
-// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=x86_64-scei-ps4 < 
/dev/null | FileCheck -match-full-lines -check-prefix PS4-CXX %s
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=x86_64-scei-ps4 < 
/dev/null | FileCheck --match-full-lines --check-prefix PS4-CXX %s
+// RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=x86_64-sie-ps5 < 
/dev/null | FileCheck --match-full-lines --check-prefix PS4-CXX %s
 // PS4-CXX:#define __STDCPP_DEFAULT_NEW_ALIGNMENT__ 32UL
 //
 // RUN: %clang_cc1 -E -dM -triple=x86_64-pc-mingw32 < /dev/null | FileCheck 
-match-full-lines -check-prefix X86-64-DECLSPEC %s

diff  --git a/clang/test/Sema/wchar.c b/clang/test/Sema/wchar.c
index 5566207e50d7f..fa32ae6512fce 100644
--- a/clang/test/Sema/wchar.c
+++ b/clang/test/Sema/wchar.c
@@ -4,8 +4,8 @@
 typedef __WCHAR_TYPE__ wchar_t;
 
 #if defined(_WIN32) || defined(_M_IX86) || defined(__CYGWIN__) \
- || 

[PATCH] D126816: Only issue warning for subtraction involving null pointers on live code paths

2022-06-01 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126816

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


[PATCH] D126812: [Binary] Promote OffloadBinary to inherit from Binary

2022-06-01 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

LGTM in principle, with new nits.




Comment at: llvm/include/llvm/Object/OffloadBinary.h:121
 const Entry *TheEntry)
-  : Buffer(Buffer), TheHeader(TheHeader), TheEntry(TheEntry) {
-
+  : Binary(Binary::ID_Offload, Source), Buffer(Source.getBufferStart()),
+TheHeader(TheHeader), TheEntry(TheEntry) {

We're losing information by passing only the start of the buffer.
I'd change the type of `Buffer` field to `MemoryBufferRef` instead.



Comment at: llvm/lib/Object/OffloadBinary.cpp:18
 using namespace llvm;
-
-namespace llvm {
+using namespace object;
 

Nit: `using namespace` seems a bit too heavy-handed when you only need one enum
`using object_error = llvm::object::object_error;` would probably do.
TBH, the use of fully qualified enum in only two instances also looked OK to me.



Comment at: llvm/lib/Object/OffloadBinary.cpp:18
-
-namespace llvm {
 

tra wrote:
> Nit: `using namespace` seems a bit too heavy-handed when you only need one 
> enum
> `using object_error = llvm::object::object_error;` would probably do.
> TBH, the use of fully qualified enum in only two instances also looked OK to 
> me.
Nit: Offload binary is declared within `llvm` namespace. Removing namespace 
here and relying on `using namespace llvm;` works, but makes things a bit less 
obvious. I'd keep the namespace around. Maybe, even remove `using namespace 
llvm` above, too as it should not be needed if the code is within the actual 
namespace.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126812

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


[PATCH] D126818: Itanium ABI: Implement mangling for constrained friends

2022-06-01 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: rjmccall, clang-language-wg.
Herald added a project: All.
erichkeane requested review of this revision.

Thanks to concepts, C++ can now have friends that differ by their
containing function.  Because of this, we need to differentiate ones
from different instantiations.  This patch implements itanium-cxx-abi
issue #24 (https://github.com/itanium-cxx-abi/cxx-abi/issues/24).

In addition to mangling the containing scope, this ALSO adds the 'F'
differentiator as proposed.


https://reviews.llvm.org/D126818

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/test/CodeGenCXX/friend-concepts.cpp

Index: clang/test/CodeGenCXX/friend-concepts.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/friend-concepts.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++20 -emit-llvm -o - %s | FileCheck %s
+
+// See US115 from P2103R0 and 
+// https://github.com/itanium-cxx-abi/cxx-abi/issues/24.
+// Friends that have concept constraints (which makes them required to be a
+// definition) must mangle their containing type.
+struct Base {};
+
+template 
+struct S : public Base {
+  friend int func(Base &)
+requires(N == 1)
+  { return 1; }
+  friend int func(Base &)
+requires(N == 2)
+  { return 3; }
+  // Without the 'F' mangling addition, this is in conflict with the above.
+  int func(Base &) { return 5; }
+
+  template
+  friend int templ_func(Base &)
+requires(N == 1 || N == 2)
+  { return 10; }
+
+  template
+  int templ_func(Base &)
+  { return 15; }
+};
+
+int main() {
+  S<1> s1{};
+  S<2> s2{};
+  auto const func1 = func(s1);
+  // CHECK: call noundef i32 @_ZN1SILi1EEF4funcER4Base
+  auto const func2 = func(s2);
+  // CHECK: call noundef i32 @_ZN1SILi2EEF4funcER4Base
+
+  // These have the same signature, so we need to make sure they have a
+  // different mangling (or more correctly, that the friend functions do not
+  // conflict). Note that these are the same as above, with the exception of the
+  // missing 'F' before the unqualified name.
+  auto const func3 = s1.func(s1);
+  // CHECK: call noundef i32 @_ZN1SILi1EE4funcER4Base
+  auto const func4 = s2.func(s2);
+  // CHECK: call noundef i32 @_ZN1SILi2EE4funcER4Base
+
+  auto const templ1 = templ_func(s1);
+  // CHECK: call noundef i32 @_ZN1SILi1EEF10templ_funcIiEEiR4Base
+  auto const templ2 = templ_func(s2);
+  // CHECK: call noundef i32 @_ZN1SILi2EEF10templ_funcIiEEiR4Base
+  auto const templ3 = s1.templ_func(s1);
+  // CHECK: call noundef i32 @_ZN1SILi1EE10templ_funcIiEEiR4Base
+  auto const templ4 = s2.templ_func(s2);
+  // CHECK: call noundef i32 @_ZN1SILi2EE10templ_funcIiEEiR4Base
+}
Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -658,10 +658,25 @@
 if (VD->isExternC())
   return getASTContext().getTranslationUnitDecl();
 
-  if (const auto *FD = dyn_cast(D))
+  if (const auto *FD = dyn_cast(D)) {
 if (FD->isExternC())
   return getASTContext().getTranslationUnitDecl();
 
+// If this is a friend, and has constraints, mangle it in the decl context
+// of its lexical context, since in different scopes, they are considered
+// different functions.  See [temp.friend]p9.
+if (FD->isConstrainedFriend())
+return FD->getLexicalDeclContext();
+  }
+
+  // If this is a friend, and has constraints, mangle it in the decl context
+  // of its lexical context, since in different scopes, they are considered
+  // different functions.  See [temp.friend]p9.
+  // For template friends, we just use the templated decl version here.
+  if (const auto *FTD = dyn_cast(D))
+if (FTD->getTemplatedDecl()->isConstrainedFriend())
+  return FTD->getLexicalDeclContext();
+
   return DC->getRedeclContext();
 }
 
@@ -1697,13 +1712,26 @@
   Out << II->getLength() << II->getName();
 }
 
+// See if the 'F' between the prefix of a nested name or nested template is
+// necessary.  That is, is this a friend with a constraint.
+static void mangleConstrainedFriendness(llvm::raw_ostream , GlobalDecl GD) {
+  if (const auto *FD = dyn_cast(GD.getDecl()))
+if (FD->isConstrainedFriend())
+  Out << 'F';
+
+  if (const auto *FTD = dyn_cast(GD.getDecl()))
+if (FTD->getTemplatedDecl()->isConstrainedFriend())
+  Out << 'F';
+}
+
 void CXXNameMangler::mangleNestedName(GlobalDecl GD,
   const DeclContext *DC,
   const AbiTagList *AdditionalAbiTags,
   bool NoFunction) {
   const NamedDecl *ND = cast(GD.getDecl());
   // 
-  //   ::= N [] []   E
+  //   ::= N [] []  [F} 
+  //E
   //   ::= N [] [] 
   //E
 
@@ -1724,6 +1752,7 @@
 mangleTemplateArgs(asTemplateName(TD), 

[PATCH] D126816: Only issue warning for subtraction involving null pointers on live code paths

2022-06-01 Thread Jamie Schmeiser via Phabricator via cfe-commits
jamieschmeiser created this revision.
jamieschmeiser added reviewers: anarazel, efriedma.
Herald added a project: All.
jamieschmeiser requested review of this revision.
Herald added a project: clang.

Change the warning produced for subtraction from (or with) a null pointer
to only be produced when the code path is live.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126816

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/pointer-subtraction.c


Index: clang/test/Sema/pointer-subtraction.c
===
--- clang/test/Sema/pointer-subtraction.c
+++ clang/test/Sema/pointer-subtraction.c
@@ -11,6 +11,16 @@
   f = (char *)(f - (char *)0); // expected-warning {{performing 
pointer subtraction with a null pointer has undefined behavior}}
   f = (char *)((char *)0 - (char *)0); // expected-warning {{performing 
pointer subtraction with a null pointer has undefined behavior}} 
expected-warning {{performing pointer subtraction with a null pointer has 
undefined behavior}}
 
+  if (1)
+f = (char *)((char *)0 - f); // expected-warning {{performing 
pointer subtraction with a null pointer has undefined behavior}}
+  else
+f = (char *)((char *)0 - f);
+
+  if (0)
+f = (char *)((char *)0 - f);
+  else
+f = (char *)((char *)0 - f); // expected-warning {{performing 
pointer subtraction with a null pointer has undefined behavior}}
+
 #ifndef SYSTEM_WARNINGS
   SYSTEM_MACRO(f);
 #else
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10845,8 +10845,10 @@
   if (S.Diags.getSuppressSystemWarnings() && S.SourceMgr.isInSystemMacro(Loc))
 return;
 
-  S.Diag(Loc, diag::warn_pointer_sub_null_ptr)
-  << S.getLangOpts().CPlusPlus << Pointer->getSourceRange();
+  S.DiagRuntimeBehavior(Loc, Pointer,
+S.PDiag(diag::warn_pointer_sub_null_ptr)
+<< S.getLangOpts().CPlusPlus
+<< Pointer->getSourceRange());
 }
 
 /// Diagnose invalid arithmetic on two function pointers.


Index: clang/test/Sema/pointer-subtraction.c
===
--- clang/test/Sema/pointer-subtraction.c
+++ clang/test/Sema/pointer-subtraction.c
@@ -11,6 +11,16 @@
   f = (char *)(f - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
   f = (char *)((char *)0 - (char *)0); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}} expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
 
+  if (1)
+f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+  else
+f = (char *)((char *)0 - f);
+
+  if (0)
+f = (char *)((char *)0 - f);
+  else
+f = (char *)((char *)0 - f); // expected-warning {{performing pointer subtraction with a null pointer has undefined behavior}}
+
 #ifndef SYSTEM_WARNINGS
   SYSTEM_MACRO(f);
 #else
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10845,8 +10845,10 @@
   if (S.Diags.getSuppressSystemWarnings() && S.SourceMgr.isInSystemMacro(Loc))
 return;
 
-  S.Diag(Loc, diag::warn_pointer_sub_null_ptr)
-  << S.getLangOpts().CPlusPlus << Pointer->getSourceRange();
+  S.DiagRuntimeBehavior(Loc, Pointer,
+S.PDiag(diag::warn_pointer_sub_null_ptr)
+<< S.getLangOpts().CPlusPlus
+<< Pointer->getSourceRange());
 }
 
 /// Diagnose invalid arithmetic on two function pointers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126759: [clang][dataflow] Model calls returning optionals

2022-06-01 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added inline comments.



Comment at: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp:161
 
+auto possiblyAliasedOptionalType() {
+  return hasUnqualifiedDesugaredType(

Does alias refers to a type alias in this case? I first parsed this as if this 
has something to do with pointers being aliased. I wonder if 
`possiblyOptionalAliasType` would read better (considering the optional type 
its own alias). Feel free to ignore. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126759

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


[PATCH] D125802: Fix std::has_unique_object_representations for _BitInt types with padding bits

2022-06-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/SemaCXX/has_unique_object_reps_bitint.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify 
-std=c++17 -Wno-bitfield-width %s
+//  expected-no-diagnostics

browneee wrote:
> This unit test appears to trigger a memory leak:
> 
> https://lab.llvm.org/buildbot/#/builders/5/builds/24359/steps/15/logs/stdio
> 
> ```
> FAIL: Clang :: SemaCXX/has_unique_object_reps_bitint.cpp (13615 of 66177)
>  TEST 'Clang :: 
> SemaCXX/has_unique_object_reps_bitint.cpp' FAILED 
> Script:
> --
> : 'RUN: at line 1';   
> /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -cc1 
> -internal-isystem 
> /b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/lib/clang/15.0.0/include 
> -nostdsysteminc -triple x86_64-unknown-unknown -fsyntax-only -verify 
> -std=c++17 -Wno-bitfield-width 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/SemaCXX/has_unique_object_reps_bitint.cpp
> --
> Exit Code: 1
> Command Output (stderr):
> --
> =
> ==22556==ERROR: LeakSanitizer: detected memory leaks
> Direct leak of 1632 byte(s) in 3 object(s) allocated from:
> #0 0x55cc84e8d6be in malloc 
> /b/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/asan/asan_malloc_linux.cpp:69:3
> #1 0x55cc8c0a417c in safe_malloc 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/Support/MemAlloc.h:26:18
> #2 0x55cc8c0a417c in llvm::SmallVectorBase::grow_pod(void*, 
> unsigned long, unsigned long) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Support/SmallVector.cpp:126:15
> #3 0x55cc94342e34 in grow_pod 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:120:11
> #4 0x55cc94342e34 in grow 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:506:41
> #5 0x55cc94342e34 in 
> reserveForParamAndGetAddressImpl  true> > 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:225:11
> #6 0x55cc94342e34 in reserveForParamAndGetAddress 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:511:12
> #7 0x55cc94342e34 in push_back 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:543:23
> #8 0x55cc94342e34 in addArgument 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/include/clang/AST/TemplateBase.h:604:15
> #9 0x55cc94342e34 in 
> clang::VarTemplateSpecializationDecl::setTemplateArgsInfo(clang::TemplateArgumentListInfo
>  const&) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/AST/DeclTemplate.cpp:1341:22
> #10 0x55cc937d5b66 in 
> clang::TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(clang::VarTemplateDecl*,
>  clang::VarDecl*, clang::TemplateArgumentListInfo const&, 
> llvm::ArrayRef, 
> clang::VarTemplateSpecializationDecl*) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:3860:8
> #11 0x55cc937e1dd4 in 
> clang::Sema::BuildVarTemplateInstantiation(clang::VarTemplateDecl*, 
> clang::VarDecl*, clang::TemplateArgumentList const&, 
> clang::TemplateArgumentListInfo const&, 
> llvm::SmallVectorImpl&, clang::SourceLocation, 
> llvm::SmallVector*, 
> clang::LocalInstantiationScope*) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5135:20
> #12 0x55cc933d777d in 
> clang::Sema::CheckVarTemplateId(clang::VarTemplateDecl*, 
> clang::SourceLocation, clang::SourceLocation, clang::TemplateArgumentListInfo 
> const&) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplate.cpp:4621:41
> #13 0x55cc933daddc in CheckVarTemplateId 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplate.cpp:4657:21
> #14 0x55cc933daddc in 
> clang::Sema::BuildTemplateIdExpr(clang::CXXScopeSpec const&, 
> clang::SourceLocation, clang::LookupResult&, bool, 
> clang::TemplateArgumentListInfo const*) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplate.cpp:4748:22
> #15 0x55cc928ffef3 in clang::Sema::ActOnIdExpression(clang::Scope*, 
> clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, bool, 
> bool, clang::CorrectionCandidateCallback*, bool, clang::Token*) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaExpr.cpp:2728:12
> #16 0x55cc91d0e988 in 
> clang::Parser::tryParseCXXIdExpression(clang::CXXScopeSpec&, bool, 
> clang::Token&) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExprCXX.cpp:610:17
> #17 0x55cc91d124d9 in clang::Parser::ParseCXXIdExpression(bool) 
> /b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExprCXX.cpp:676:7
> #18 0x55cc91cdb510 in 
> 

[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-01 Thread Thorsten via Phabricator via cfe-commits
tschuett added a comment.

Would a JSON dump help you for your tools?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D125802: Fix std::has_unique_object_representations for _BitInt types with padding bits

2022-06-01 Thread Andrew via Phabricator via cfe-commits
browneee added inline comments.



Comment at: clang/test/SemaCXX/has_unique_object_reps_bitint.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fsyntax-only -verify 
-std=c++17 -Wno-bitfield-width %s
+//  expected-no-diagnostics

This unit test appears to trigger a memory leak:

https://lab.llvm.org/buildbot/#/builders/5/builds/24359/steps/15/logs/stdio

```
FAIL: Clang :: SemaCXX/has_unique_object_reps_bitint.cpp (13615 of 66177)
 TEST 'Clang :: SemaCXX/has_unique_object_reps_bitint.cpp' 
FAILED 
Script:
--
: 'RUN: at line 1';   
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/bin/clang -cc1 
-internal-isystem 
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/lib/clang/15.0.0/include 
-nostdsysteminc -triple x86_64-unknown-unknown -fsyntax-only -verify -std=c++17 
-Wno-bitfield-width 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/test/SemaCXX/has_unique_object_reps_bitint.cpp
--
Exit Code: 1
Command Output (stderr):
--
=
==22556==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 1632 byte(s) in 3 object(s) allocated from:
#0 0x55cc84e8d6be in malloc 
/b/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/asan/asan_malloc_linux.cpp:69:3
#1 0x55cc8c0a417c in safe_malloc 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/Support/MemAlloc.h:26:18
#2 0x55cc8c0a417c in llvm::SmallVectorBase::grow_pod(void*, 
unsigned long, unsigned long) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Support/SmallVector.cpp:126:15
#3 0x55cc94342e34 in grow_pod 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:120:11
#4 0x55cc94342e34 in grow 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:506:41
#5 0x55cc94342e34 in 
reserveForParamAndGetAddressImpl > 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:225:11
#6 0x55cc94342e34 in reserveForParamAndGetAddress 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:511:12
#7 0x55cc94342e34 in push_back 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/include/llvm/ADT/SmallVector.h:543:23
#8 0x55cc94342e34 in addArgument 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/include/clang/AST/TemplateBase.h:604:15
#9 0x55cc94342e34 in 
clang::VarTemplateSpecializationDecl::setTemplateArgsInfo(clang::TemplateArgumentListInfo
 const&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/AST/DeclTemplate.cpp:1341:22
#10 0x55cc937d5b66 in 
clang::TemplateDeclInstantiator::VisitVarTemplateSpecializationDecl(clang::VarTemplateDecl*,
 clang::VarDecl*, clang::TemplateArgumentListInfo const&, 
llvm::ArrayRef, clang::VarTemplateSpecializationDecl*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:3860:8
#11 0x55cc937e1dd4 in 
clang::Sema::BuildVarTemplateInstantiation(clang::VarTemplateDecl*, 
clang::VarDecl*, clang::TemplateArgumentList const&, 
clang::TemplateArgumentListInfo const&, 
llvm::SmallVectorImpl&, clang::SourceLocation, 
llvm::SmallVector*, 
clang::LocalInstantiationScope*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5135:20
#12 0x55cc933d777d in 
clang::Sema::CheckVarTemplateId(clang::VarTemplateDecl*, clang::SourceLocation, 
clang::SourceLocation, clang::TemplateArgumentListInfo const&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplate.cpp:4621:41
#13 0x55cc933daddc in CheckVarTemplateId 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplate.cpp:4657:21
#14 0x55cc933daddc in clang::Sema::BuildTemplateIdExpr(clang::CXXScopeSpec 
const&, clang::SourceLocation, clang::LookupResult&, bool, 
clang::TemplateArgumentListInfo const*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaTemplate.cpp:4748:22
#15 0x55cc928ffef3 in clang::Sema::ActOnIdExpression(clang::Scope*, 
clang::CXXScopeSpec&, clang::SourceLocation, clang::UnqualifiedId&, bool, bool, 
clang::CorrectionCandidateCallback*, bool, clang::Token*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Sema/SemaExpr.cpp:2728:12
#16 0x55cc91d0e988 in 
clang::Parser::tryParseCXXIdExpression(clang::CXXScopeSpec&, bool, 
clang::Token&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExprCXX.cpp:610:17
#17 0x55cc91d124d9 in clang::Parser::ParseCXXIdExpression(bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExprCXX.cpp:676:7
#18 0x55cc91cdb510 in 
clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, 
clang::Parser::TypeCastState, bool, bool*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Parse/ParseExpr.cpp:1626:11

[PATCH] D126812: [Binary] Promote OffloadBinary to inherit from Binary

2022-06-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 433504.
jhuber6 added a comment.

Fix test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126812

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm-c/Object.h
  llvm/include/llvm/BinaryFormat/Magic.h
  llvm/include/llvm/Object/Binary.h
  llvm/include/llvm/Object/OffloadBinary.h
  llvm/lib/BinaryFormat/Magic.cpp
  llvm/lib/Object/Binary.cpp
  llvm/lib/Object/Object.cpp
  llvm/lib/Object/ObjectFile.cpp
  llvm/lib/Object/OffloadBinary.cpp
  llvm/unittests/Object/OffloadingTest.cpp

Index: llvm/unittests/Object/OffloadingTest.cpp
===
--- llvm/unittests/Object/OffloadingTest.cpp
+++ llvm/unittests/Object/OffloadingTest.cpp
@@ -4,6 +4,9 @@
 #include "gtest/gtest.h"
 #include 
 
+using namespace llvm;
+using namespace object;
+
 TEST(OffloadingTest, checkOffloadingBinary) {
   // Create random data to fill the image.
   std::mt19937 Rng(std::random_device{}());
@@ -27,23 +30,22 @@
   }
 
   // Create the image.
-  llvm::StringMap StringData;
+  StringMap StringData;
   for (auto  : Strings)
 StringData[KeyAndValue.first] = KeyAndValue.second;
-  std::unique_ptr ImageData =
-  llvm::MemoryBuffer::getMemBuffer(
-  {reinterpret_cast(Image.data()), Image.size()}, "", false);
+  std::unique_ptr ImageData = MemoryBuffer::getMemBuffer(
+  {reinterpret_cast(Image.data()), Image.size()}, "", false);
 
-  llvm::OffloadBinary::OffloadingImage Data;
-  Data.TheImageKind = static_cast(KindDist(Rng));
-  Data.TheOffloadKind = static_cast(KindDist(Rng));
+  OffloadBinary::OffloadingImage Data;
+  Data.TheImageKind = static_cast(KindDist(Rng));
+  Data.TheOffloadKind = static_cast(KindDist(Rng));
   Data.Flags = KindDist(Rng);
   Data.StringData = StringData;
   Data.Image = *ImageData;
 
-  auto BinaryBuffer = llvm::OffloadBinary::write(Data);
+  auto BinaryBuffer = OffloadBinary::write(Data);
 
-  auto BinaryOrErr = llvm::OffloadBinary::create(*BinaryBuffer);
+  auto BinaryOrErr = OffloadBinary::create(*BinaryBuffer);
   if (!BinaryOrErr)
 FAIL();
 
@@ -60,6 +62,6 @@
   EXPECT_TRUE(Data.Image.getBuffer() == Binary.getImage());
 
   // Ensure the size and alignment of the data is correct.
-  EXPECT_TRUE(Binary.getSize() % llvm::OffloadBinary::getAlignment() == 0);
+  EXPECT_TRUE(Binary.getSize() % OffloadBinary::getAlignment() == 0);
   EXPECT_TRUE(Binary.getSize() == BinaryBuffer->getBuffer().size());
 }
Index: llvm/lib/Object/OffloadBinary.cpp
===
--- llvm/lib/Object/OffloadBinary.cpp
+++ llvm/lib/Object/OffloadBinary.cpp
@@ -9,22 +9,22 @@
 #include "llvm/Object/OffloadBinary.h"
 
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/BinaryFormat/Magic.h"
 #include "llvm/MC/StringTableBuilder.h"
 #include "llvm/Object/Error.h"
 #include "llvm/Support/FileOutputBuffer.h"
 
 using namespace llvm;
-
-namespace llvm {
+using namespace object;
 
 Expected>
 OffloadBinary::create(MemoryBufferRef Buf) {
   if (Buf.getBufferSize() < sizeof(Header) + sizeof(Entry))
-return errorCodeToError(llvm::object::object_error::parse_failed);
+return errorCodeToError(object_error::parse_failed);
 
   // Check for 0x10FF1OAD magic bytes.
-  if (!Buf.getBuffer().startswith("\x10\xFF\x10\xAD"))
-return errorCodeToError(llvm::object::object_error::parse_failed);
+  if (identify_magic(Buf.getBuffer()) != file_magic::offload_binary)
+return errorCodeToError(object_error::parse_failed);
 
   const char *Start = Buf.getBufferStart();
   const Header *TheHeader = reinterpret_cast(Start);
@@ -32,7 +32,7 @@
   reinterpret_cast([TheHeader->EntryOffset]);
 
   return std::unique_ptr(
-  new OffloadBinary(Buf.getBufferStart(), TheHeader, TheEntry));
+  new OffloadBinary(Buf, TheHeader, TheEntry));
 }
 
 std::unique_ptr
@@ -93,7 +93,7 @@
   return MemoryBuffer::getMemBufferCopy(OS.str());
 }
 
-OffloadKind getOffloadKind(StringRef Name) {
+OffloadKind llvm::object::getOffloadKind(StringRef Name) {
   return llvm::StringSwitch(Name)
   .Case("openmp", OFK_OpenMP)
   .Case("cuda", OFK_Cuda)
@@ -101,7 +101,7 @@
   .Default(OFK_None);
 }
 
-StringRef getOffloadKindName(OffloadKind Kind) {
+StringRef llvm::object::getOffloadKindName(OffloadKind Kind) {
   switch (Kind) {
   case OFK_OpenMP:
 return "openmp";
@@ -114,7 +114,7 @@
   }
 }
 
-ImageKind getImageKind(StringRef Name) {
+ImageKind llvm::object::getImageKind(StringRef Name) {
   return llvm::StringSwitch(Name)
   .Case("o", IMG_Object)
   .Case("bc", IMG_Bitcode)
@@ -124,7 +124,7 @@
   .Default(IMG_None);
 }
 
-StringRef getImageKindName(ImageKind Kind) {
+StringRef llvm::object::getImageKindName(ImageKind Kind) {
   switch (Kind) {
   case IMG_Object:
 return "o";
@@ -140,5 +140,3 @@
 return "";
   }
 }
-
-} // namespace llvm
Index: 

[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D126796#3551280 , @MaskRay wrote:

> In D126796#3551261 , @cjdb wrote:
>
>> In D126796#3550848 , @MaskRay 
>> wrote:
>>
>>> FYI `diagtool tree` dumps the diagnostics. You can even provide -W options 
>>> and observe the differences.
>>
>> Is `diagtool tree` something that users widely know about?
>
> I think no. But any random new option to clang will have the same 
> discoverability problem.

Yes, but I think there's a pretty wide discoverability gap between "documented 
command line option that shows up in Clang" and "random utility that doesn't 
have any obvious relationship to Clang specifically".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D126719: [clang-cl] Add support for /kernel

2022-06-01 Thread Stephen Long via Phabricator via cfe-commits
steplong updated this revision to Diff 433502.
steplong added a comment.

- Change UnsupportedArches to SupportedArches


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126719

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cl-zc.cpp

Index: clang/test/Driver/cl-zc.cpp
===
--- clang/test/Driver/cl-zc.cpp
+++ clang/test/Driver/cl-zc.cpp
@@ -24,6 +24,28 @@
 // RUN: %clang_cl /c /std:c++17 -### /Zc:alignedNew- -- %s 2>&1 | FileCheck -check-prefix=ALIGNED-NEW-OFF %s
 // ALIGNED-NEW-OFF-NOT: "-faligned-allocation"
 
+// RUN: %clang_cl /c -### /kernel -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-NO-RTTI,KERNEL-NO-EXCEPTIONS %s
+// KERNEL-NO-RTTI: "-fno-rtti"
+// KERNEL-NO-EXCEPTIONS-NOT: "-fcxx-exceptions" "-fexceptions"
+
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:SSE -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-SSE %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:SSE2 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-SSE2 %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:AVX -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-AVX %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:AVX2 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-AVX2 %s
+// RUN: %clang_cl /c -### --target=i686-pc-windows-msvc /kernel /arch:AVX512 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-AVX512 %s
+// KERNEL-SSE: error: invalid argument '/arch:SSE' not allowed with '/kernel'
+// KERNEL-SSE2: error: invalid argument '/arch:SSE2' not allowed with '/kernel'
+// KERNEL-AVX: error: invalid argument '/arch:AVX' not allowed with '/kernel'
+// KERNEL-AVX2: error: invalid argument '/arch:AVX2' not allowed with '/kernel'
+// KERNEL-AVX512: error: invalid argument '/arch:AVX512' not allowed with '/kernel'
+
+// RUN: %clang_cl /c -### --target=x86_64-pc-windows-msvc /kernel /arch:AVX -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-X64-AVX %s
+// RUN: %clang_cl /c -### --target=x86_64-pc-windows-msvc /kernel /arch:AVX2 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-X64-AVX2 %s
+// RUN: %clang_cl /c -### --target=x86_64-pc-windows-msvc /kernel /arch:AVX512 -- %s 2>&1 | FileCheck -check-prefixes=KERNEL-X64-AVX512 %s
+// KERNEL-X64-AVX: error: invalid argument '/arch:AVX' not allowed with '/kernel'
+// KERNEL-X64-AVX2: error: invalid argument '/arch:AVX2' not allowed with '/kernel'
+// KERNEL-X64-AVX512: error: invalid argument '/arch:AVX512' not allowed with '/kernel'
+
 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=STRICTSTRINGS-DEFAULT %s
 // STRICTSTRINGS-DEFAULT-NOT: -Werror=c++11-compat-deprecated-writable-strings
 // RUN: %clang_cl /c -### /Zc:strictStrings -- %s 2>&1 | FileCheck -check-prefix=STRICTSTRINGS-ON %s
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -38,6 +38,7 @@
 #include "clang/Driver/SanitizerArgs.h"
 #include "clang/Driver/Types.h"
 #include "clang/Driver/XRayArgs.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Option/ArgList.h"
@@ -7458,6 +7459,12 @@
 EH.NoUnwindC = true;
   }
 
+  if (Args.hasArg(options::OPT__SLASH_kernel)) {
+EH.Synch = false;
+EH.NoUnwindC = false;
+EH.Asynch = false;
+  }
+
   return EH;
 }
 
@@ -7602,6 +7609,26 @@
CmdArgs.push_back("-fno-wchar");
  }
 
+ if (Args.hasArg(options::OPT__SLASH_kernel)) {
+   llvm::Triple::ArchType Arch = getToolChain().getArch();
+   std::vector Values =
+   Args.getAllArgValues(options::OPT__SLASH_arch);
+   if (!Values.empty()) {
+ llvm::SmallSet SupportedArches;
+ if (Arch == llvm::Triple::x86) {
+   std::vector Arches = {"IA32"};
+   SupportedArches.insert(Arches.begin(), Arches.end());
+ }
+
+ for (auto  : Values)
+   if (!SupportedArches.contains(V))
+ D.Diag(diag::err_drv_argument_not_allowed_with)
+ << std::string("/arch:").append(V) << "/kernel";
+   }
+
+   CmdArgs.push_back("-fno-rtti");
+ }
+
   Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
   Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb);
   if (MostGeneralArg && BestCaseArg)
@@ -7671,6 +7698,9 @@
 CmdArgs.push_back("msvc");
   }
 
+  if (Args.hasArg(options::OPT__SLASH_kernel))
+CmdArgs.push_back("-fms-kernel");
+
   if (Arg *A = Args.getLastArg(options::OPT__SLASH_guard)) {
 StringRef GuardArgs = A->getValue();
 // The only valid options are "cf", "cf,nochecks", "cf-", "ehcont" and
Index: clang/lib/Basic/Targets/OSTargets.cpp

[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D126796#3551261 , @cjdb wrote:

> In D126796#3550848 , @MaskRay wrote:
>
>> FYI `diagtool tree` dumps the diagnostics. You can even provide -W options 
>> and observe the differences.
>
> Is `diagtool tree` something that users widely know about?

Doubtful?

I think I may have been vaguely aware of it, but I thought it was a testing 
utility. Is `diagtool` part of the default install of Clang?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-01 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D126796#3551261 , @cjdb wrote:

> In D126796#3550848 , @MaskRay wrote:
>
>> FYI `diagtool tree` dumps the diagnostics. You can even provide -W options 
>> and observe the differences.
>
> Is `diagtool tree` something that users widely know about?

I think no. But any random new option to clang will have the same 
discoverability problem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D126812: [Binary] Promote OffloadBinary to inherit from Binary

2022-06-01 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tra, JonChesterfield, MaskRay.
Herald added a reviewer: deadalnix.
Herald added subscribers: ormris, StephenFan, hiraditya.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, aheejin.
Herald added projects: clang, LLVM.

We use the `OffloadBinary` to create binary images of offloading files
and their corresonding metadata. This patch changes this to inherit from
the base `Binary` class. This allows us to create and insepect these
more generically. This patch includes all the necessary glue to
implement this as a new binary format, along with added the magic bytes
we use to distinguish the offloading binary to the `file_magic`
implementation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126812

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm-c/Object.h
  llvm/include/llvm/BinaryFormat/Magic.h
  llvm/include/llvm/Object/Binary.h
  llvm/include/llvm/Object/OffloadBinary.h
  llvm/lib/BinaryFormat/Magic.cpp
  llvm/lib/Object/Binary.cpp
  llvm/lib/Object/Object.cpp
  llvm/lib/Object/ObjectFile.cpp
  llvm/lib/Object/OffloadBinary.cpp

Index: llvm/lib/Object/OffloadBinary.cpp
===
--- llvm/lib/Object/OffloadBinary.cpp
+++ llvm/lib/Object/OffloadBinary.cpp
@@ -9,22 +9,22 @@
 #include "llvm/Object/OffloadBinary.h"
 
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/BinaryFormat/Magic.h"
 #include "llvm/MC/StringTableBuilder.h"
 #include "llvm/Object/Error.h"
 #include "llvm/Support/FileOutputBuffer.h"
 
 using namespace llvm;
-
-namespace llvm {
+using namespace object;
 
 Expected>
 OffloadBinary::create(MemoryBufferRef Buf) {
   if (Buf.getBufferSize() < sizeof(Header) + sizeof(Entry))
-return errorCodeToError(llvm::object::object_error::parse_failed);
+return errorCodeToError(object_error::parse_failed);
 
   // Check for 0x10FF1OAD magic bytes.
-  if (!Buf.getBuffer().startswith("\x10\xFF\x10\xAD"))
-return errorCodeToError(llvm::object::object_error::parse_failed);
+  if (identify_magic(Buf.getBuffer()) != file_magic::offload_binary)
+return errorCodeToError(object_error::parse_failed);
 
   const char *Start = Buf.getBufferStart();
   const Header *TheHeader = reinterpret_cast(Start);
@@ -32,7 +32,7 @@
   reinterpret_cast([TheHeader->EntryOffset]);
 
   return std::unique_ptr(
-  new OffloadBinary(Buf.getBufferStart(), TheHeader, TheEntry));
+  new OffloadBinary(Buf, TheHeader, TheEntry));
 }
 
 std::unique_ptr
@@ -93,7 +93,7 @@
   return MemoryBuffer::getMemBufferCopy(OS.str());
 }
 
-OffloadKind getOffloadKind(StringRef Name) {
+OffloadKind llvm::object::getOffloadKind(StringRef Name) {
   return llvm::StringSwitch(Name)
   .Case("openmp", OFK_OpenMP)
   .Case("cuda", OFK_Cuda)
@@ -101,7 +101,7 @@
   .Default(OFK_None);
 }
 
-StringRef getOffloadKindName(OffloadKind Kind) {
+StringRef llvm::object::getOffloadKindName(OffloadKind Kind) {
   switch (Kind) {
   case OFK_OpenMP:
 return "openmp";
@@ -114,7 +114,7 @@
   }
 }
 
-ImageKind getImageKind(StringRef Name) {
+ImageKind llvm::object::getImageKind(StringRef Name) {
   return llvm::StringSwitch(Name)
   .Case("o", IMG_Object)
   .Case("bc", IMG_Bitcode)
@@ -124,7 +124,7 @@
   .Default(IMG_None);
 }
 
-StringRef getImageKindName(ImageKind Kind) {
+StringRef llvm::object::getImageKindName(ImageKind Kind) {
   switch (Kind) {
   case IMG_Object:
 return "o";
@@ -140,5 +140,3 @@
 return "";
   }
 }
-
-} // namespace llvm
Index: llvm/lib/Object/ObjectFile.cpp
===
--- llvm/lib/Object/ObjectFile.cpp
+++ llvm/lib/Object/ObjectFile.cpp
@@ -147,6 +147,7 @@
   case file_magic::minidump:
   case file_magic::goff_object:
   case file_magic::cuda_fatbinary:
+  case file_magic::offload_binary:
   case file_magic::dxcontainer_object:
 return errorCodeToError(object_error::invalid_file_type);
   case file_magic::tapi_file:
Index: llvm/lib/Object/Object.cpp
===
--- llvm/lib/Object/Object.cpp
+++ llvm/lib/Object/Object.cpp
@@ -120,6 +120,8 @@
 return LLVMBinaryTypeMachO64L;
   case ID_MachO64B:
 return LLVMBinaryTypeMachO64B;
+  case ID_Offload:
+return LLVMBinaryTypeOffload;
   case ID_Wasm:
 return LLVMBinaryTypeWasm;
   case ID_StartObjects:
Index: llvm/lib/Object/Binary.cpp
===
--- llvm/lib/Object/Binary.cpp
+++ llvm/lib/Object/Binary.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Object/MachOUniversal.h"
 #include "llvm/Object/Minidump.h"
 #include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/OffloadBinary.h"
 #include "llvm/Object/TapiUniversal.h"
 #include "llvm/Object/WindowsResource.h"
 #include "llvm/Support/Error.h"
@@ -87,6 

[PATCH] D126796: [clang][driver] adds `-print-diagnostics`

2022-06-01 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added a comment.

In D126796#3550848 , @MaskRay wrote:

> FYI `diagtool tree` dumps the diagnostics. You can even provide -W options 
> and observe the differences.

Is `diagtool tree` something that users widely know about?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126796

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


[PATCH] D102122: Support warn_unused_result on typedefs

2022-06-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie marked an inline comment as done.
dblaikie added a comment.

In D102122#3550590 , @aaron.ballman 
wrote:

> In D102122#3544655 , @dblaikie 
> wrote:
>
>> How's this look now, then?
>
> I think it's heading in the right direction.
>
>> One drawback is the built-in attribute warnings that mention which entities 
>> the attribute is valid on will mention typedefs even when the user uses a 
>> spelling that wouldn't be valid there - so the user might try it there, then 
>> get the follow-on warning (totally open to wordsmithing that warning, too - 
>> just placeholder words - also made it part of the same group as the 
>> warn_unused_result warning itself - if you disable that warning, then 
>> presumably you don't care about the warning being in the wrong place either, 
>> to some extent).
>
> Yeah, that is a drawback -- we don't have a spelling-specific set of subjects 
> currently. I had a plan to address that at some point by introducing more 
> data into the subject list so you could do something like:
>
>   def WarnUnusedResult : InheritableAttr {
> let Spellings = [CXX11<"", "nodiscard", 201907>,
>  C2x<"", "nodiscard", 201904>,
>  CXX11<"clang", "warn_unused_result">,
>  GCC<"warn_unused_result">];
> let Subjects = SubjectList<
>  SubjectsFor<[ObjCMethod, Enum, Record, 
> FunctionLike, TypedefName], [GNU<"warn_unused_result">, CXX11<"clang", 
> "warn_unused_result">]>,
>  SubjectsFor<[ObjCMethod, Enum, Record, 
> FunctionLike], [CXX11<"", "nodiscard">, C2x<"", "nodiscard">, CXX11<"gnu", 
> "warn_unused_result">]>,
>>;
> ...
>   }
>
> But that's complicated (as this attribute demonstrates!). This is a case 
> where we want HALF of a spelling to apply to some subjects (the GNU spelling 
> half of the `GCC` spelling) and the other half to apply to other subjects 
> (the C++ spelling half of the `GCC` spelling).
>
> I think for right now, I think it's okay for us to have the slightly degraded 
> diagnostic behavior. If it turns into user confusion in practice, we can 
> improve the diagnostics at that point. WDYT?

Oh, yeah, should've said I'm OK with it if you are. Only meant to point it out 
to get confirmation there. Thanks!




Comment at: clang/include/clang/Basic/Attr.td:2945
C2x<"", "nodiscard", 201904>,
CXX11<"clang", "warn_unused_result">,
GCC<"warn_unused_result">];

aaron.ballman wrote:
> Oops, it looks like we support this spelling in C++ but not in C (not your 
> bug, just an observation): https://godbolt.org/z/1hPq6coba
Oh, so we'd have to put `C2x<"clang", "warn_unused_result">` in here? Fair 
enough, yeah, separate issue.



Comment at: clang/lib/AST/Expr.cpp:1525-1527
+  if (const auto *TD = getCallReturnType(Ctx)->getAs())
+if (const auto *A = TD->getDecl()->getAttr())
+  return A;

aaron.ballman wrote:
> rsmith wrote:
> > This should loop over `TypedefType` sugar; the attribute could be in a 
> > nested typedef.
> I agree with Richard here. I think this is needed for a case like:
> ```
> typedef int foo __attribute__((warn_unused_result));
> typedef foo foob;
> 
> foob func();
> 
> int main() {
>   func(); // Still want to be barked at here
> }
> ```
> But this example brings up an interesting question of expectations. What's 
> your intuition on how this should behave?
> ```
> typedef int foo __attribute__((warn_unused_result));
> typedef foo *foo_ptr;
> 
> foo_ptr func();
> 
> int main() {
>   func(); // Bark? Silence? Other?
> }
> ```
> FWIW, my initial inclination was that this would diagnose the call to 
> `func()` but now I'm second-guessing that, hence the question about type 
> composition in a typedef.
> I agree with Richard here. I think this is needed for a case like:
> ```
> typedef int foo __attribute__((warn_unused_result));
> typedef foo foob;
> 
> foob func();
> 
> int main() {
>  func(); // Still want to be barked at here
> }
> ```

Oh, sorry, I marked this as "done" because I'd done this - but hadn't updated 
the patch. Should be updated now, including a test case 
(warn-unused-result.cpp:unused_typedef_result::indirect).

> But this example brings up an interesting question of expectations. What's 
> your intuition on how this should behave?
> ```
> typedef int foo __attribute__((warn_unused_result));
> typedef foo *foo_ptr;
> 
> foo_ptr func();
> 
> int main() {
>   func(); // Bark? Silence? Other?
> }
> ```
> FWIW, my initial inclination was that this would diagnose the call to func() 
> but now I'm second-guessing that, hence the question about type composition 
> in a typedef.

Yeah, I'm OK with/think that probably shouldn't warn - like instantiating a 
template with a 

[PATCH] D102122: Support warn_unused_result on typedefs

2022-06-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 433499.
dblaikie added a comment.

Fix/update the unsupported syntax warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102122

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/Basic/Attributes.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/c2x-nodiscard.c
  clang/test/Sema/unused-expr.c
  clang/test/SemaCXX/warn-unused-result.cpp

Index: clang/test/SemaCXX/warn-unused-result.cpp
===
--- clang/test/SemaCXX/warn-unused-result.cpp
+++ clang/test/SemaCXX/warn-unused-result.cpp
@@ -254,3 +254,35 @@
 
 void i([[nodiscard]] bool (*fp)()); // expected-warning {{'nodiscard' attribute only applies to functions, classes, or enumerations}}
 }
+
+namespace unused_typedef_result {
+[[clang::warn_unused_result]] typedef void *a;
+typedef a indirect;
+a af1();
+indirect indirectf1();
+void af2() {
+  af1(); // expected-warning {{ignoring return value}}
+  void *(*a1)();
+  a1(); // no warning
+  a (*a2)();
+  a2(); // expected-warning {{ignoring return value}}
+  indirectf1(); // expected-warning {{ignoring return value}}
+}
+[[nodiscard]] typedef void *b1; // expected-warning {{'[[nodiscard]]' attribute ignored when applied to a typedef; consider using '__attribute__((warn_unused_result))' or '[[clang::warn_unused_result]]' instead}}
+[[gnu::warn_unused_result]] typedef void *b2; // expected-warning {{'[[gnu::warn_unused_result]]' attribute ignored when applied to a typedef; consider using '__attribute__((warn_unused_result))' or '[[clang::warn_unused_result]]' instead}}
+b1 b1f1();
+b2 b2f1();
+void bf2() {
+  b1f1(); // no warning
+  b2f1(); // no warning
+}
+__attribute__((warn_unused_result)) typedef void *c;
+c cf1();
+void cf2() {
+  cf1(); // expected-warning {{ignoring return value}}
+  void *(*c1)();
+  c1();
+  c (*c2)();
+  c2(); // expected-warning {{ignoring return value}}
+}
+}
Index: clang/test/Sema/unused-expr.c
===
--- clang/test/Sema/unused-expr.c
+++ clang/test/Sema/unused-expr.c
@@ -96,7 +96,7 @@
   return 0;
 }
 
-int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_result' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}}
+int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_result' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, function pointers, and typedefs}}
 
 // PR4010
 int (*fn4)(void) __attribute__ ((warn_unused_result));
Index: clang/test/Sema/c2x-nodiscard.c
===
--- clang/test/Sema/c2x-nodiscard.c
+++ clang/test/Sema/c2x-nodiscard.c
@@ -15,7 +15,7 @@
 [[nodiscard]] int f1(void);
 enum [[nodiscard]] E1 { One };
 
-[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}}
+[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, function pointers, and typedefs}}
 
 struct [[nodiscard]] S4 {
   int i;
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -185,7 +185,7 @@
 // CHECK-NEXT: VecReturn (SubjectMatchRule_record)
 // CHECK-NEXT: VecTypeHint (SubjectMatchRule_function)
 // CHECK-NEXT: WarnUnused (SubjectMatchRule_record)
-// CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType, SubjectMatchRule_type_alias)
 // CHECK-NEXT: Weak (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: WeakRef (SubjectMatchRule_variable, SubjectMatchRule_function)
 // CHECK-NEXT: WebAssemblyExportName (SubjectMatchRule_function)
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
@@ -7,4 +7,4 @@
 [[nodiscard]] int f();
 enum [[nodiscard]] E {};
 
-namespace 

[PATCH] D126806: Add an overload to ASTUnit::LoadFromASTFile that accepts a virtual file system.

2022-06-01 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

To be clear, I'm fine with the change either way, just want to understand a bit 
better first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126806

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


[PATCH] D126806: Add an overload to ASTUnit::LoadFromASTFile that accepts a virtual file system.

2022-06-01 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

Why add an overload rather than adding it before `UseDebugInfo` and defaulting 
it to `getRealFileSystem()`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126806

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


[PATCH] D102122: Support warn_unused_result on typedefs

2022-06-01 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 433492.
dblaikie marked 4 inline comments as done.
dblaikie added a comment.

Check through multiple typedef layers to find the warn_unused_result attribute
Rephrase unsupported syntax warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D102122

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Expr.cpp
  clang/lib/Basic/Attributes.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/Sema/c2x-nodiscard.c
  clang/test/Sema/unused-expr.c
  clang/test/SemaCXX/warn-unused-result.cpp

Index: clang/test/SemaCXX/warn-unused-result.cpp
===
--- clang/test/SemaCXX/warn-unused-result.cpp
+++ clang/test/SemaCXX/warn-unused-result.cpp
@@ -254,3 +254,32 @@
 
 void i([[nodiscard]] bool (*fp)()); // expected-warning {{'nodiscard' attribute only applies to functions, classes, or enumerations}}
 }
+
+namespace unused_typedef_result {
+[[clang::warn_unused_result]] typedef void *a;
+typedef a indirect;
+a af1();
+indirect indirectf1();
+void af2() {
+  af1(); // expected-warning {{ignoring return value}}
+  void *(*a1)();
+  a1(); // no warning
+  a (*a2)();
+  a2(); // expected-warning {{ignoring return value}}
+  indirectf1(); // expected-warning {{ignoring return value}}
+}
+[[nodiscard]] typedef void *b; // expected-warning {{'[[nodiscard]]' attribute ignored when applied to a typedef; consider using '__attribute__((warn_unused_result))' or '[[clang::warn_unused_result]]' instead}}
+b bf1();
+void bf2() {
+  bf1(); // no warning
+}
+__attribute__((warn_unused_result)) typedef void *c;
+c cf1();
+void cf2() {
+  cf1(); // expected-warning {{ignoring return value}}
+  void *(*c1)();
+  c1();
+  c (*c2)();
+  c2(); // expected-warning {{ignoring return value}}
+}
+}
Index: clang/test/Sema/unused-expr.c
===
--- clang/test/Sema/unused-expr.c
+++ clang/test/Sema/unused-expr.c
@@ -96,7 +96,7 @@
   return 0;
 }
 
-int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_result' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}}
+int t7 __attribute__ ((warn_unused_result)); // expected-warning {{'warn_unused_result' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, function pointers, and typedefs}}
 
 // PR4010
 int (*fn4)(void) __attribute__ ((warn_unused_result));
Index: clang/test/Sema/c2x-nodiscard.c
===
--- clang/test/Sema/c2x-nodiscard.c
+++ clang/test/Sema/c2x-nodiscard.c
@@ -15,7 +15,7 @@
 [[nodiscard]] int f1(void);
 enum [[nodiscard]] E1 { One };
 
-[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}}
+[[nodiscard]] int i; // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, function pointers, and typedefs}}
 
 struct [[nodiscard]] S4 {
   int i;
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -185,7 +185,7 @@
 // CHECK-NEXT: VecReturn (SubjectMatchRule_record)
 // CHECK-NEXT: VecTypeHint (SubjectMatchRule_function)
 // CHECK-NEXT: WarnUnused (SubjectMatchRule_record)
-// CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType)
+// CHECK-NEXT: WarnUnusedResult (SubjectMatchRule_objc_method, SubjectMatchRule_enum, SubjectMatchRule_record, SubjectMatchRule_hasType_functionType, SubjectMatchRule_type_alias)
 // CHECK-NEXT: Weak (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record)
 // CHECK-NEXT: WeakRef (SubjectMatchRule_variable, SubjectMatchRule_function)
 // CHECK-NEXT: WebAssemblyExportName (SubjectMatchRule_function)
Index: clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
===
--- clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
+++ clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.nodiscard/p1.cpp
@@ -7,4 +7,4 @@
 [[nodiscard]] int f();
 enum [[nodiscard]] E {};
 
-namespace [[nodiscard]] N {} // expected-warning {{'nodiscard' attribute only applies to Objective-C methods, enums, structs, unions, classes, functions, and function pointers}}
+namespace 

[PATCH] D126719: [clang-cl] Add support for /kernel

2022-06-01 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7620
+ else if (Arch == llvm::Triple::x86_64)
+   UnsupportedArches = {"AVX", "AVX2", "AVX512"};
+

Making this list opt-in instead of opt-out (ie "SupportedArchs") seems a bit 
more future-proof: We're less likely to forget to update the list when new 
archs are added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126719

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


[PATCH] D120540: [Driver] Enable to use C++20 modules standalone by -fcxx-modules

2022-06-01 Thread Iain Sandoe via Phabricator via cfe-commits
iains added a comment.

I guess Chuanqi's TZ is in sleep mode at the moment, so the revert makes sense.

Please let's not use -fmodules-ts to mean anything - we want to phase it out 
and make it a NOP (we are implementing the standardised modules; I do not see 
anyone putting effort into finishing the ts implementation).

my suggestion is to introduce `-fmodules={cxx20, clang, etc. etc}` where 
`-fmodules` is mapped in the driver to `-fmodules=clang` ... and to introduce 
an enumeration in the options that is visible in the FE so that we can be 
explicit in checking **which** kind of modules we mean at each stage.

unfortunately, right now I cannot volunteer to implement the suggestion ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120540

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


[PATCH] D126806: Add an overload to ASTUnit::LoadFromASTFile that accepts a virtual file system.

2022-06-01 Thread Andy Soffer via Phabricator via cfe-commits
asoffer created this revision.
Herald added a project: All.
asoffer requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126806

Files:
  clang/include/clang/Frontend/ASTUnit.h
  clang/lib/Frontend/ASTUnit.cpp


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -757,6 +757,7 @@
 std::unique_ptr ASTUnit::LoadFromASTFile(
 const std::string , const PCHContainerReader ,
 WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+IntrusiveRefCntPtr VFS,
 const FileSystemOptions , bool UseDebugInfo,
 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
 bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
@@ -775,8 +776,6 @@
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->Diagnostics = Diags;
-  IntrusiveRefCntPtr VFS =
-  llvm::vfs::getRealFileSystem();
   AST->FileMgr = new FileManager(FileSystemOpts, VFS);
   AST->UserFilesAreVolatile = UserFilesAreVolatile;
   AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
@@ -867,6 +866,18 @@
   return AST;
 }
 
+std::unique_ptr ASTUnit::LoadFromASTFile(
+const std::string , const PCHContainerReader ,
+WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+const FileSystemOptions , bool UseDebugInfo,
+bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
+bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
+  return LoadFromASTFile(Filename, PCHContainerRdr, ToLoad, Diags,
+ llvm::vfs::getRealFileSystem(), FileSystemOpts,
+ UseDebugInfo, OnlyLocalDecls, CaptureDiagnostics,
+ AllowASTWithCompilerErrors, UserFilesAreVolatile);
+}
+
 /// Add the given macro to the hash of all top-level entities.
 static void AddDefinedMacroToHash(const Token , unsigned ) {
   Hash = llvm::djbHash(MacroNameTok.getIdentifierInfo()->getName(), Hash);
Index: clang/include/clang/Frontend/ASTUnit.h
===
--- clang/include/clang/Frontend/ASTUnit.h
+++ clang/include/clang/Frontend/ASTUnit.h
@@ -688,17 +688,25 @@
   /// lifetime is expected to extend past that of the returned ASTUnit.
   ///
   /// \returns - The initialized ASTUnit or null if the AST failed to load.
-  static std::unique_ptr
-  LoadFromASTFile(const std::string ,
-  const PCHContainerReader , WhatToLoad ToLoad,
-  IntrusiveRefCntPtr Diags,
-  const FileSystemOptions ,
-  bool UseDebugInfo = false, bool OnlyLocalDecls = false,
-  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
-  bool AllowASTWithCompilerErrors = false,
-  bool UserFilesAreVolatile = false);
+  static std::unique_ptr LoadFromASTFile(
+  const std::string , const PCHContainerReader ,
+  WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+  IntrusiveRefCntPtr VFS,
+  const FileSystemOptions , bool UseDebugInfo = false,
+  bool OnlyLocalDecls = false,
+  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
+  bool AllowASTWithCompilerErrors = false,
+  bool UserFilesAreVolatile = false);
+  static std::unique_ptr LoadFromASTFile(
+  const std::string , const PCHContainerReader ,
+  WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+  const FileSystemOptions , bool UseDebugInfo = false,
+  bool OnlyLocalDecls = false,
+  CaptureDiagsKind CaptureDiagnostics = CaptureDiagsKind::None,
+  bool AllowASTWithCompilerErrors = false,
+  bool UserFilesAreVolatile = false);
 
-private:
+ private:
   /// Helper function for \c LoadFromCompilerInvocation() and
   /// \c LoadFromCommandLine(), which loads an AST from a compiler invocation.
   ///


Index: clang/lib/Frontend/ASTUnit.cpp
===
--- clang/lib/Frontend/ASTUnit.cpp
+++ clang/lib/Frontend/ASTUnit.cpp
@@ -757,6 +757,7 @@
 std::unique_ptr ASTUnit::LoadFromASTFile(
 const std::string , const PCHContainerReader ,
 WhatToLoad ToLoad, IntrusiveRefCntPtr Diags,
+IntrusiveRefCntPtr VFS,
 const FileSystemOptions , bool UseDebugInfo,
 bool OnlyLocalDecls, CaptureDiagsKind CaptureDiagnostics,
 bool AllowASTWithCompilerErrors, bool UserFilesAreVolatile) {
@@ -775,8 +776,6 @@
   AST->OnlyLocalDecls = OnlyLocalDecls;
   AST->CaptureDiagnostics = CaptureDiagnostics;
   AST->Diagnostics = Diags;
-  IntrusiveRefCntPtr VFS =
-  llvm::vfs::getRealFileSystem();
   AST->FileMgr = new FileManager(FileSystemOpts, VFS);
   AST->UserFilesAreVolatile = UserFilesAreVolatile;
   AST->SourceMgr = new SourceManager(AST->getDiagnostics(),
@@ -867,6 +866,18 @@
   return AST;
 }
 
+std::unique_ptr 

[clang-tools-extra] d951ca5 - Revert "[Driver] Enable to use C++20 standalne by -fcxx-modules"

2022-06-01 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2022-06-01T12:11:57-07:00
New Revision: d951ca5439bb8726cfe1ceb2d12e220f29fe5125

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

LOG: Revert "[Driver] Enable to use C++20 standalne by -fcxx-modules"

This reverts commit a544710cd43ba9f7729a613c58729f146e792a8e.

See discussion in D120540.

This breaks C++ Clang modules on Darwin and also more than a dozen
tests in the LLDB testsuite.  I think we need to be more careful to
separate out the enabling of Clang C++ modules and C++20
modules. Either by having -fmodules-ts control the HaveModules flag,
or by adding a way to explicitly turn them off.

Added: 


Modified: 
clang-tools-extra/test/pp-trace/pp-trace-modules.cpp
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/modules.cpp

Removed: 
clang/test/Modules/cxx-modules.cppm



diff  --git a/clang-tools-extra/test/pp-trace/pp-trace-modules.cpp 
b/clang-tools-extra/test/pp-trace/pp-trace-modules.cpp
index 028c967a4e0d8..32d6c48e5d448 100644
--- a/clang-tools-extra/test/pp-trace/pp-trace-modules.cpp
+++ b/clang-tools-extra/test/pp-trace/pp-trace-modules.cpp
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x 
objective-c++ -undef -target x86_64 -std=c++11 -fmodules 
-fmodules-cache-path=%t -I%S -I%S/Input | FileCheck --strict-whitespace %s
+// RUN: pp-trace -callbacks '*,-FileChanged,-MacroDefined' %s -- -x 
objective-c++ -undef -target x86_64 -std=c++11 -fmodules -fcxx-modules 
-fmodules-cache-path=%t -I%S -I%S/Input | FileCheck --strict-whitespace %s
 
 // CHECK: ---
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 074dc56f2aa23..1cef95a0d4efe 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1414,7 +1414,7 @@ defm async_exceptions: BoolFOption<"async-exceptions",
   PosFlag, 
NegFlag>;
 defm cxx_modules : BoolFOption<"cxx-modules",
   LangOpts<"CPlusPlusModules">, Default,
-  NegFlag, PosFlag,
+  NegFlag, PosFlag,
   BothFlags<[NoXarchOption], " modules for C++">>,
   ShouldParseIf;
 def fdebug_pass_arguments : Flag<["-"], "fdebug-pass-arguments">, 
Group;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index f32dfdcdfe4bb..2328e3db1973f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3630,12 +3630,6 @@ static void RenderModulesOptions(Compilation , const 
Driver ,
 HaveModules = true;
   }
 
-  if (Args.hasFlag(options::OPT_fcxx_modules, options::OPT_fno_cxx_modules,
-   false)) {
-CmdArgs.push_back("-fcxx-modules");
-HaveModules = true;
-  }
-
   // -fmodule-maps enables implicit reading of module map files. By default,
   // this is enabled if we are using Clang's flavor of precompiled modules.
   if (Args.hasFlag(options::OPT_fimplicit_module_maps,

diff  --git a/clang/test/Driver/modules.cpp b/clang/test/Driver/modules.cpp
index bac9f715f13a4..87b6cc640cb0d 100644
--- a/clang/test/Driver/modules.cpp
+++ b/clang/test/Driver/modules.cpp
@@ -73,14 +73,3 @@ import "foo.h";
 // CHECK-HEADER-UNIT-USE: BAR;
 FOO;
 #endif
-
-// Check the independent use of -fcxx-modules
-//
-// RUN: %clang++ -fcxx-modules -std=c++17 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX17-MODULES
-// CHECK-CXX17-MODULES: "-fcxx-modules"
-// RUN: %clang++ -fcxx-modules -std=c++14 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX14-MODULES
-// CHECK-CXX14-MODULES: "-fcxx-modules"
-// RUN: %clang++ -fcxx-modules -std=c++11 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX11-MODULES
-// CHECK-CXX11-MODULES: "-fcxx-modules"
-// RUN: %clang++ -fcxx-modules -std=c++03 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX03-MODULES
-// CHECK-CXX03-MODULES: "-fcxx-modules"

diff  --git a/clang/test/Modules/cxx-modules.cppm 
b/clang/test/Modules/cxx-modules.cppm
deleted file mode 100644
index be17f85f8d17d..0
--- a/clang/test/Modules/cxx-modules.cppm
+++ /dev/null
@@ -1,7 +0,0 @@
-// This tests that we could use C++20 modules standalone.
-// RUN: %clang -std=c++03 -fcxx-modules -fsyntax-only -Xclang -verify %s
-// RUN: %clang -std=c++11 -fcxx-modules -fsyntax-only -Xclang -verify %s
-// RUN: %clang -std=c++14 -fcxx-modules -fsyntax-only -Xclang -verify %s
-// RUN: %clang -std=c++17 -fcxx-modules -fsyntax-only -Xclang -verify %s
-// expected-no-diagnostics
-export module M;



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


[clang] c84b9bb - Revert "[NFC] Use %clang instead of %clang++ in tests"

2022-06-01 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2022-06-01T12:11:56-07:00
New Revision: c84b9bbac1ecaafb34daa7618b035f063ef1094e

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

LOG: Revert "[NFC] Use %clang instead of %clang++ in tests"

This reverts commit 738c20e6df01217b6364c3b75d0ced6b6fb6277e as a dependency of 
D120540.

Added: 


Modified: 
clang/test/Driver/modules.cpp

Removed: 




diff  --git a/clang/test/Driver/modules.cpp b/clang/test/Driver/modules.cpp
index 472b07c65799..bac9f715f13a 100644
--- a/clang/test/Driver/modules.cpp
+++ b/clang/test/Driver/modules.cpp
@@ -76,11 +76,11 @@ FOO;
 
 // Check the independent use of -fcxx-modules
 //
-// RUN: %clang -fcxx-modules -std=c++17 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX17-MODULES
+// RUN: %clang++ -fcxx-modules -std=c++17 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX17-MODULES
 // CHECK-CXX17-MODULES: "-fcxx-modules"
-// RUN: %clang -fcxx-modules -std=c++14 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX14-MODULES
+// RUN: %clang++ -fcxx-modules -std=c++14 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX14-MODULES
 // CHECK-CXX14-MODULES: "-fcxx-modules"
-// RUN: %clang -fcxx-modules -std=c++11 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX11-MODULES
+// RUN: %clang++ -fcxx-modules -std=c++11 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX11-MODULES
 // CHECK-CXX11-MODULES: "-fcxx-modules"
-// RUN: %clang -fcxx-modules -std=c++03 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX03-MODULES
+// RUN: %clang++ -fcxx-modules -std=c++03 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX03-MODULES
 // CHECK-CXX03-MODULES: "-fcxx-modules"



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


[clang] 128ffb3 - Revert "[Driver][Modules] Remove dependence on linking support from clang/test/Driver/modules.cpp"

2022-06-01 Thread Adrian Prantl via cfe-commits

Author: Adrian Prantl
Date: 2022-06-01T12:11:56-07:00
New Revision: 128ffb332bca2c3efae82665b2b557f9b481b83f

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

LOG: Revert "[Driver][Modules] Remove dependence on linking support from 
clang/test/Driver/modules.cpp"

This reverts commit 35b1cfc76f08faabf3f27c0bd054acc7c854a6ca as a dependency of 
D120540.

Added: 


Modified: 
clang/test/Driver/modules.cpp

Removed: 




diff  --git a/clang/test/Driver/modules.cpp b/clang/test/Driver/modules.cpp
index f532b5b3c775f..472b07c657992 100644
--- a/clang/test/Driver/modules.cpp
+++ b/clang/test/Driver/modules.cpp
@@ -76,8 +76,11 @@ FOO;
 
 // Check the independent use of -fcxx-modules
 //
-// RUN: %clang -fcxx-modules -std=c++17 -### -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX-MODULES
-// RUN: %clang -fcxx-modules -std=c++14 -### -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX-MODULES
-// RUN: %clang -fcxx-modules -std=c++11 -### -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX-MODULES
-// RUN: %clang -fcxx-modules -std=c++03 -### -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX-MODULES
-// CHECK-CXX-MODULES: "-fcxx-modules"
+// RUN: %clang -fcxx-modules -std=c++17 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX17-MODULES
+// CHECK-CXX17-MODULES: "-fcxx-modules"
+// RUN: %clang -fcxx-modules -std=c++14 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX14-MODULES
+// CHECK-CXX14-MODULES: "-fcxx-modules"
+// RUN: %clang -fcxx-modules -std=c++11 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX11-MODULES
+// CHECK-CXX11-MODULES: "-fcxx-modules"
+// RUN: %clang -fcxx-modules -std=c++03 -### %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-CXX03-MODULES
+// CHECK-CXX03-MODULES: "-fcxx-modules"



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


  1   2   3   >