[clang] 125ccd3 - [ASTMatchers] Add isInAnonymousNamespace narrowing matcher

2022-12-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2022-12-23T07:39:03Z
New Revision: 125ccd3751472a0c709498f83671577ffed394a6

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

LOG: [ASTMatchers] Add isInAnonymousNamespace narrowing matcher

Used in a couple clang-tidy checks so it could be extracted
out as its own matcher.

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/docs/ReleaseNotes.rst
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 61844ffc9de90..f9cb9f2e942bb 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -3962,6 +3962,25 @@ Narrowing Matchers
 cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
 
 
+MatcherDecl>isInAnonymousNamespace
+Matches 
declarations in an anonymous namespace.
+
+Given
+  class vector {};
+  namespace foo {
+class vector {};
+namespace {
+  class vector {}; // #1
+}
+  }
+  namespace {
+class vector {}; // #2
+namespace foo {
+  class vector{}; // #3
+}
+  }
+cxxRecordDecl(hasName("vector"), isInAnonymousNamespace()) will match #1, #2 
and #3.
+
 
 MatcherDecl>isInstantiated
 Matches declarations 
that are template instantiations or are inside

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8c288a98eec99..48ffafafb1bb7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -859,6 +859,7 @@ Build System Changes
 
 AST Matchers
 
+- Add ``isInAnoymousNamespace`` matcher to match declarations in an anonymous 
namespace.
 
 clang-format
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index dfea432c16adb..5d3d458b6409f 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7813,6 +7813,30 @@ AST_MATCHER(NamespaceDecl, isAnonymous) {
 /// cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
 AST_MATCHER(Decl, isInStdNamespace) { return Node.isInStdNamespace(); }
 
+/// Matches declarations in an anonymous namespace.
+///
+/// Given
+/// \code
+///   class vector {};
+///   namespace foo {
+/// class vector {};
+/// namespace {
+///   class vector {}; // #1
+/// }
+///   }
+///   namespace {
+/// class vector {}; // #2
+/// namespace foo {
+///   class vector{}; // #3
+/// }
+///   }
+/// \endcode
+/// cxxRecordDecl(hasName("vector"), isInAnonymousNamespace()) will match
+/// #1, #2 and #3.
+AST_MATCHER(Decl, isInAnonymousNamespace) {
+  return Node.isInAnonymousNamespace();
+}
+
 /// If the given case statement does not use the GNU case range
 /// extension, matches the constant given in the statement.
 ///

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 752a736ae800e..2c8b67f2644fd 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3550,6 +3550,41 @@ TEST_P(ASTMatchersTest, InStdNamespace) {
   cxxRecordDecl(hasName("vector"), isInStdNamespace(;
 }
 
+TEST_P(ASTMatchersTest, InAnonymousNamespace) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+
+  EXPECT_TRUE(
+  notMatches("class vector {};"
+ "namespace foo {"
+ "  class vector {};"
+ "}",
+ cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+
+  EXPECT_TRUE(
+  matches("namespace {"
+  "  class vector {};"
+  "}",
+  cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+
+  EXPECT_TRUE(
+  matches("namespace foo {"
+  "  namespace {"
+  "class vector {};"
+  "  }"
+  "}",
+  cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+
+  EXPECT_TRUE(
+  matches("namespace {"
+  "  namespace foo {"
+  "class vector {};"
+  "  }"
+  "}",
+  cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+}
+
 TEST_P(ASTMatchersTest, InStdNamespace_CXX11) {
   if (!GetParam().isCXX11OrLater()) {
 return;



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.or

[PATCH] D140328: [ASTMatchers] Add isInAnonymousNamespace narrowing matcher

2022-12-23 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG125ccd375147: [ASTMatchers] Add isInAnonymousNamespace 
narrowing matcher (authored by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140328

Files:
  clang/docs/LibASTMatchersReference.html
  clang/docs/ReleaseNotes.rst
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Index: clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3550,6 +3550,41 @@
   cxxRecordDecl(hasName("vector"), isInStdNamespace(;
 }
 
+TEST_P(ASTMatchersTest, InAnonymousNamespace) {
+  if (!GetParam().isCXX()) {
+return;
+  }
+
+  EXPECT_TRUE(
+  notMatches("class vector {};"
+ "namespace foo {"
+ "  class vector {};"
+ "}",
+ cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+
+  EXPECT_TRUE(
+  matches("namespace {"
+  "  class vector {};"
+  "}",
+  cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+
+  EXPECT_TRUE(
+  matches("namespace foo {"
+  "  namespace {"
+  "class vector {};"
+  "  }"
+  "}",
+  cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+
+  EXPECT_TRUE(
+  matches("namespace {"
+  "  namespace foo {"
+  "class vector {};"
+  "  }"
+  "}",
+  cxxRecordDecl(hasName("vector"), isInAnonymousNamespace(;
+}
+
 TEST_P(ASTMatchersTest, InStdNamespace_CXX11) {
   if (!GetParam().isCXX11OrLater()) {
 return;
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7813,6 +7813,30 @@
 /// cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
 AST_MATCHER(Decl, isInStdNamespace) { return Node.isInStdNamespace(); }
 
+/// Matches declarations in an anonymous namespace.
+///
+/// Given
+/// \code
+///   class vector {};
+///   namespace foo {
+/// class vector {};
+/// namespace {
+///   class vector {}; // #1
+/// }
+///   }
+///   namespace {
+/// class vector {}; // #2
+/// namespace foo {
+///   class vector{}; // #3
+/// }
+///   }
+/// \endcode
+/// cxxRecordDecl(hasName("vector"), isInAnonymousNamespace()) will match
+/// #1, #2 and #3.
+AST_MATCHER(Decl, isInAnonymousNamespace) {
+  return Node.isInAnonymousNamespace();
+}
+
 /// If the given case statement does not use the GNU case range
 /// extension, matches the constant given in the statement.
 ///
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -859,6 +859,7 @@
 
 AST Matchers
 
+- Add ``isInAnoymousNamespace`` matcher to match declarations in an anonymous namespace.
 
 clang-format
 
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -3962,6 +3962,25 @@
 cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1.
 
 
+MatcherDecl>isInAnonymousNamespace
+Matches declarations in an anonymous namespace.
+
+Given
+  class vector {};
+  namespace foo {
+class vector {};
+namespace {
+  class vector {}; // #1
+}
+  }
+  namespace {
+class vector {}; // #2
+namespace foo {
+  class vector{}; // #3
+}
+  }
+cxxRecordDecl(hasName("vector"), isInAnonymousNamespace()) will match #1, #2 and #3.
+
 
 MatcherDecl>isInstantiated
 Matches declarations that are template instantiations or are inside
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140587: [clang] Fix a clang crash on invalid code in C++20 mode.

2022-12-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D140587#4014437 , @shafik wrote:

> Thank you for the fix, can you explain the failure case in more detail and 
> why checking that `RD` is defined is the correct fix.

The `RD->isAggregate()` needs to access the member of `data()`, for the code in 
the testcase, data() is null, we ends up with accessing a nullptr. see the 
stack trace:

  lang: llvm-project/clang/include/clang/AST/DeclCXX.h:448: struct 
DefinitionData &clang::CXXRecordDecl::data() const: Assertion `DD && "queried 
property of class with no definition"' failed.
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ 
and include the crash backtrace, preprocessed source, and associated run script.
  Stack dump:
   #0 0x55bef3cd7ff3 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
llvm-project/llvm/lib/Support/Unix/Signals.inc:567:13
   #1 0x55bef3cd6260 llvm::sys::RunSignalHandlers() 
llvm-project/llvm/lib/Support/Signals.cpp:105:18
   #2 0x55bef3cd837a SignalHandler(int) 
llvm-project/llvm/lib/Support/Unix/Signals.inc:412:1
   #3 0x7f024183daa0 (/lib/x86_64-linux-gnu/libc.so.6+0x3daa0)
   #4 0x7f024188957c __pthread_kill_implementation 
./nptl/pthread_kill.c:44:76
   #5 0x7f024183da02 gsignal ./signal/../sysdeps/posix/raise.c:27:6
   #6 0x7f0241828469 abort ./stdlib/abort.c:81:7
   #7 0x7f0241828395 _nl_load_domain ./intl/loadmsgcat.c:1177:9
   #8 0x7f0241836ab2 (/lib/x86_64-linux-gnu/libc.so.6+0x36ab2)
   #9 0x55bef3fd2b78 (./bin/clang+0x38eab78)
  #10 0x55bef5e78f07 clang::CXXRecordDecl::isAggregate() const 
llvm-project/clang/include/clang/AST/DeclCXX.h:1119:37
  #11 0x55bef5e78f07 
clang::InitializationSequence::InitializeFrom(clang::Sema&, 
clang::InitializedEntity const&, clang::InitializationKind const&, 
llvm::MutableArrayRef, bool, bool) 
llvm-project/clang/lib/Sema/SemaInit.cpp:6180:15
  #12 0x55bef5e89a75 clang::InitializedEntity::getKind() const 
llvm-project/clang/include/clang/Sema/Initialization.h:427:39
  #13 0x55bef5e89a75 clang::InitializedEntity::isParameterKind() const 
llvm-project/clang/include/clang/Sema/Initialization.h:461:13
  #14 0x55bef5e89a75 
clang::Sema::PerformCopyInitialization(clang::InitializedEntity const&, 
clang::SourceLocation, clang::ActionResult, bool, bool) 
llvm-project/clang/lib/Sema/SemaInit.cpp:10253:14
  #15 0x55bef5ffecd3 
clang::Sema::PerformMoveOrCopyInitialization(clang::InitializedEntity const&, 
clang::Sema::NamedReturnInfo const&, clang::Expr*, bool) /usr/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140587

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


[clang-tools-extra] e82dd5b - [clang-tidy][NFC] Remove custom isInAnonymousNamespace matchers

2022-12-23 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2022-12-23T08:54:48Z
New Revision: e82dd5b37c7d6ccd67c5118fe7400c6006e67d73

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

LOG: [clang-tidy][NFC] Remove custom isInAnonymousNamespace matchers

Since now the same matcher exists in ASTMatchers.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp

clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
index 211bd3c73e12e..909bf793a9197 100644
--- a/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UseAnonymousNamespaceCheck.cpp
@@ -29,10 +29,6 @@ AST_MATCHER(FunctionDecl, isMemberFunction) {
   return llvm::isa(&Node);
 }
 AST_MATCHER(VarDecl, isStaticDataMember) { return Node.isStaticDataMember(); }
-
-AST_MATCHER(Decl, isInAnonymousNamespace) {
-  return Node.isInAnonymousNamespace();
-}
 } // namespace
 
 UseAnonymousNamespaceCheck::UseAnonymousNamespaceCheck(

diff  --git 
a/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
index b76c1837b8019..ffd1238e421c3 100644
--- 
a/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/StaticDefinitionInAnonymousNamespaceCheck.cpp
@@ -17,10 +17,6 @@ namespace clang {
 namespace tidy {
 namespace readability {
 
-AST_MATCHER(NamedDecl, isInAnonymousNamespace) {
-  return Node.isInAnonymousNamespace();
-}
-
 void StaticDefinitionInAnonymousNamespaceCheck::registerMatchers(
 MatchFinder *Finder) {
   Finder->addMatcher(



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


[PATCH] D139211: [clang-format] Properly handle the C11 _Generic keyword.

2022-12-23 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel updated this revision to Diff 485062.
rymiel marked an inline comment as done.
rymiel retitled this revision from "[WIP][clang-format] Properly handle the C11 
_Generic keyword." to "[clang-format] Properly handle the C11 _Generic 
keyword.".
rymiel added a comment.
This revision is now accepted and ready to land.

Change indenting behaviour

I'm still not sure what I'm doing regarding ContinuationIndenter, since I don't 
fully understand its mechanisms, so I just followed my usual method of "stick a 
very specific check in a random spot that makes the correct fields have the 
correct value", which feels like a hack here. There is probably a much better 
way to do this, perhaps something with fake parens or something, to actually 
treat the "controlling expression" and the actual selectors differently, but 
right now I've just put in a specific check to dedent the selectors to be 
relative to the _Generic keyword, and not aligned to the opening paren.

It is also no surprise that I don't know how to write tests; I included organic 
examples of cases that are semi-realistic use cases of _Generic, but there are 
definitely edge cases I don't have listed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139211

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1136,6 +1136,14 @@
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsC11GenericSelection) {
+  auto Tokens = annotate("_Generic(x, int: 1, default: 0)");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::kw__Generic, TT_Unknown);
+  EXPECT_TOKEN(Tokens[5], tok::colon, TT_GenericSelectionColon);
+  EXPECT_TOKEN(Tokens[9], tok::colon, TT_GenericSelectionColon);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
   auto Annotate = [this](llvm::StringRef Code) {
 return annotate(Code, getLLVMStyle(FormatStyle::LK_Verilog));
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22996,6 +22996,41 @@
   verifyFormat("x = (_Atomic( uint64_t ))&a;", Style);
 }
 
+TEST_F(FormatTest, C11Generic) {
+  verifyFormat("_Generic(x, int: 1, default: 0)");
+  verifyFormat("#define cbrt(X) _Generic((X), float: cbrtf, default: cbrt)(X)");
+  verifyFormat("_Generic(x, const char *: 1, char *const: 16, int: 8);");
+  verifyFormat("_Generic(x, int: f1, const int: f2)();");
+  verifyFormat("_Generic(x, struct A: 1, void (*)(void): 2);");
+
+  verifyFormat("_Generic(x,\n"
+   "float: f,\n"
+   "default: d,\n"
+   "long double: ld,\n"
+   "float _Complex: fc,\n"
+   "double _Complex: dc,\n"
+   "long double _Complex: ldc)");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 40;
+  verifyFormat("#define LIMIT_MAX(T)   \\\n"
+   "  _Generic(((T)0), \\\n"
+   "  unsigned int: UINT_MAX,  \\\n"
+   "  unsigned long: ULONG_MAX,\\\n"
+   "  unsigned long long: ULLONG_MAX)",
+   Style);
+  verifyFormat("_Generic(x,\n"
+   "struct A: 1,\n"
+   "void (*)(void): 2);",
+   Style);
+
+  Style.ContinuationIndentWidth = 2;
+  verifyFormat("_Generic(x,\n"
+   "  struct A: 1,\n"
+   "  void (*)(void): 2);",
+   Style);
+}
+
 TEST_F(FormatTest, AmbersandInLamda) {
   // Test case reported in https://bugs.llvm.org/show_bug.cgi?id=41899
   FormatStyle AlignStyle = getLLVMStyle();
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -323,6 +323,10 @@
   Contexts.back().IsExpression = false;
 } else if (OpeningParen.is(TT_RequiresExpressionLParen)) {
   Contexts.back().IsExpression = false;
+} else if (OpeningParen.Previous &&
+   OpeningParen.Previous->is(tok::kw__Generic)) {
+  Contexts.back().ContextType = Context::C11GenericSelection;
+  Contexts.back().IsExpression = true;
 } else if (Line.InPPDirective &&
(!OpeningParen.Previous ||
 !OpeningParen.Previous->is(tok::identifier))) {
@@ -1028,6 +1032,8 @@
 }
   } else if (Contexts.back().ColonIsForRa

[PATCH] D82087: AMDGPU/clang: Add builtins for llvm.amdgcn.ballot

2022-12-23 Thread Sameer Sahasrabuddhe via Phabricator via cfe-commits
sameerds added inline comments.



Comment at: clang/test/CodeGenOpenCL/amdgpu-features.cl:7
+// RUN: %clang_cc1 -triple amdgcn -S -emit-llvm -o - %s | FileCheck 
--check-prefix=NOCPU %s
+// RUN: %clang_cc1 -triple amdgcn -target-feature +wavefrontsize32 -S 
-emit-llvm -o - %s | FileCheck --check-prefix=NOCPU-WAVE32 %s
+// RUN: %clang_cc1 -triple amdgcn -target-feature +wavefrontsize64 -S 
-emit-llvm -o - %s | FileCheck --check-prefix=NOCPU-WAVE64 %s

yaxunl wrote:
> what happens if both +wavefrontsize32 and +wavefrontsize64 are specified?
Shouldn't this be separately an error in itself? Is it tested elsewhere?


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

https://reviews.llvm.org/D82087

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


[PATCH] D140614: [C++20] Check the dependency of declaration contexts before pumping diagnostics

2022-12-23 Thread Liming Liu via Phabricator via cfe-commits
lime created this revision.
lime added reviewers: cor3ntin, shafik, erichkeane, aaron.ballman, ychen, 
clang-language-wg.
lime added a project: clang.
Herald added a project: All.
lime requested review of this revision.
Herald added a subscriber: cfe-commits.

Unevaluated lambdas can cause the instantiator pumping dependent diagnostics 
from independent declaration contexts, and triggering the assertion in the 
following iteration.

This patch adds the check of the dependency before pumping diagnostics and 
fixes issues:
https://github.com/llvm/llvm-project/issues/57155
https://github.com/llvm/llvm-project/issues/57170


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140614

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaCXX/lambda-unevaluated.cpp


Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -122,6 +122,22 @@
 static_assert(!__is_same(decltype(foo), void));
 } // namespace GH51641
 
+namespace GH57155 {
+auto foo(int t) {
+  int(*f)(int) = [](auto t) -> decltype([=] { return t; } ()) { return t; };
+  return f;
+}
+} // namespace GH57155
+
+namespace GH57170 {
+int(*f)(int) = [](auto t) -> decltype([] {
+return 0;
+  } ()
+){
+  return t;
+};
+} // namespace GH57170
+
 namespace StaticLambdas {
 template  struct Nothing {};
 Nothing<[]() static { return 0; }()> nothing;
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1230,8 +1230,10 @@
 
   // We recreated a local declaration, but not by instantiating it. There
   // may be pending dependent diagnostics to produce.
-  if (auto *DC = dyn_cast(Old))
-SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
+  if (auto *DC = dyn_cast(Old)) {
+if (DC->isDependentContext())
+  SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
+  }
 }
 
 /// Transform the definition of the given declaration by


Index: clang/test/SemaCXX/lambda-unevaluated.cpp
===
--- clang/test/SemaCXX/lambda-unevaluated.cpp
+++ clang/test/SemaCXX/lambda-unevaluated.cpp
@@ -122,6 +122,22 @@
 static_assert(!__is_same(decltype(foo), void));
 } // namespace GH51641
 
+namespace GH57155 {
+auto foo(int t) {
+  int(*f)(int) = [](auto t) -> decltype([=] { return t; } ()) { return t; };
+  return f;
+}
+} // namespace GH57155
+
+namespace GH57170 {
+int(*f)(int) = [](auto t) -> decltype([] {
+return 0;
+  } ()
+){
+  return t;
+};
+} // namespace GH57170
+
 namespace StaticLambdas {
 template  struct Nothing {};
 Nothing<[]() static { return 0; }()> nothing;
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1230,8 +1230,10 @@
 
   // We recreated a local declaration, but not by instantiating it. There
   // may be pending dependent diagnostics to produce.
-  if (auto *DC = dyn_cast(Old))
-SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
+  if (auto *DC = dyn_cast(Old)) {
+if (DC->isDependentContext())
+  SemaRef.PerformDependentDiagnostics(DC, TemplateArgs);
+  }
 }
 
 /// Transform the definition of the given declaration by
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136554: Implement CWG2631

2022-12-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 485067.
cor3ntin added a comment.

I hope we will get there...

It further reduces to

  consteval void immediate(){};
  
  struct h {
int g = 0;
int blah = (immediate(), g);
  };
  struct k {
   h j{};
  }_;

The issue was that nested expressions are all transformed in the context of 
the outermost (k) class and transforming the this pointer pick up 
the current this pointer. 
Because when we do the replacenent we no longer have templates,
we can just skip the transformation of the this pointer.

This is a cleaner way to handke the this pointer than
having a CXXThisScopeRAII on the outer scope, 
so I removed that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136554

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Sema/UsedDeclVisitor.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/AST/ast-dump-records.cpp
  clang/test/CXX/class/class.local/p1-0x.cpp
  clang/test/CXX/drs/dr26xx.cpp
  clang/test/CodeGenCXX/builtin-source-location.cpp
  clang/test/CodeGenCXX/default-arguments-with-immediate.cpp
  clang/test/CodeGenCXX/meminit-initializers-odr.cpp
  clang/test/PCH/default-argument-with-immediate-calls.cpp
  clang/test/SemaCXX/cxx11-default-member-initializers.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/source_location.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -15593,7 +15593,7 @@
 https://wg21.link/cwg2631";>2631
 DR
 Immediate function evaluations in default arguments
-Unknown
+Clang 16
   
   
 https://wg21.link/cwg2632";>2632
Index: clang/test/SemaCXX/source_location.cpp
===
--- clang/test/SemaCXX/source_location.cpp
+++ clang/test/SemaCXX/source_location.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -DUSE_CONSTEVAL -fexceptions -verify %s
 // expected-no-diagnostics
 
 #define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
@@ -8,15 +9,22 @@
 template 
 struct Printer;
 
+#ifdef USE_CONSTEVAL
+#define SOURCE_LOC_EVAL_KIND consteval
+#else
+#define SOURCE_LOC_EVAL_KIND constexpr
+#endif
+
 namespace std {
 class source_location {
   struct __impl;
 
 public:
-  static constexpr source_location current(const __impl *__p = __builtin_source_location()) noexcept {
-source_location __loc;
-__loc.__m_impl = __p;
-return __loc;
+  static SOURCE_LOC_EVAL_KIND source_location
+current(const __impl *__p = __builtin_source_location()) noexcept {
+  source_location __loc;
+  __loc.__m_impl = __p;
+  return __loc;
   }
   constexpr source_location() = default;
   constexpr source_location(source_location const &) = default;
@@ -593,3 +601,73 @@
   }
   static_assert(test());
 }
+
+namespace Lambda {
+#line 8000 "TestLambda.cpp"
+constexpr int nested_lambda(int l = []{
+  return SL::current().line();
+}()) {
+  return l;
+}
+static_assert(nested_lambda() == __LINE__ - 4);
+
+constexpr int lambda_param(int l = [](int l = SL::current().line()) {
+  return l;
+}()) {
+  return l;
+}
+static_assert(lambda_param() == __LINE__);
+
+
+}
+
+constexpr int compound_literal_fun(int a =
+  (int){ SL::current().line() }
+) { return a ;}
+static_assert(compound_literal_fun() == __LINE__);
+
+struct CompoundLiteral {
+  int a = (int){ SL::current().line() };
+};
+static_assert(CompoundLiteral{}.a == __LINE__);
+
+
+// FIXME
+// Init captures are subexpressions of the lambda expression
+// so according to the standard immediate invocations in init captures
+// should be evaluated at the call site.
+// However Clang does not yet implement this as it would introduce
+// a fair bit of complexity.
+// We intend to implement that functionality once we find real world
+// use cases that require it.
+constexpr int test_init_capture(int a =
+[b = SL::current().line()] { return b; }()) {
+  return a;
+}
+#ifdef USE_CONSTEVAL
+static_assert(test_init_capture() == __LINE__ - 4);
+#else
+static_assert(test_init_capture() == __LINE__ );
+#endif
+
+namespace check_immediate_invocations_in_templates {
+
+template 
+struct G {
+T line = __builtin_LINE();
+};
+template 

[PATCH] D140462: [clangd] Add schema for `.clangd` config

2022-12-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

I think there's a clear benefit, but my feeling is it's outweighed by the 
costs, which are fairly high given lack of any automation/tests.
If clangd contributors should maintain this, how should contributors/reviewers 
know whether changes are correct?
If they needn't maintain it, then having it on a third-party site seems 
appropriate. Maybe a `/contrib/` directory is a useful compromise?

This is definitely informed by my biases: I have to make/review changes that 
touch config, don't have a good understanding of JSON-schema, and I don't use 
VSCode.

---

One practical question: AIUI the main point of having this is so it can be 
provided to the VSCode YAML extension so it understands .clangd files. How does 
this work mechanically? Does it need to be part of the vscode-clangd repo 
instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140462

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


[PATCH] D140462: [clangd] Add schema for `.clangd` config

2022-12-23 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

In D140462#4014944 , @sammccall wrote:

> given lack of any automation/tests

That's a fair point, it would definitely help validate the correctness of the 
schema if we had tests in the form of example config files that pass or fail 
validation.

I would be supportive of adding such tests, but I'm also hesitant to require 
them as a condition of accepting the addition of the schema file since it does 
add a fair amount of effort and complexity.

> If clangd contributors should maintain this, how should 
> contributors/reviewers know whether changes are correct?

Is "look at existing sections of our schema file as a guide, or barring that, 
the JSON-schema specification" too unsatisfactory an answer?

My feeling is that, at the end of the day, the schema format is relatively 
straightforward compared to other things that a clangd reviewer needs to know 
(like C++, or the Clang AST API), and the stakes of letting a mistake slip in 
are quite low (i.e. maybe a user will fail to get code completion for a config 
file key, as opposed to say clangd crashing on your code).

> If they needn't maintain it, then having it on a third-party site seems 
> appropriate. Maybe a `/contrib/` directory is a useful compromise?

My original thinking was that reviewers should ask for patches that change 
config to make correspoding changes to the schema, which I guess would fall 
under "clangd contributors should maintain this".

But I'm definitely happy to compromise on this -- perhaps we could keep it in a 
`/contrib/` directory like you say, and encourage but not require that config 
changes keep it up to date? And perhaps, if someone contributes automated tests 
for the schema in the future, we could consider upgrading its status to 
"maintained" at that time?

> I don't use VSCode

(Note, there's nothing tying this to VSCode in particular. For example, 
lsp-mode seems to have support for consuming schemas from SchemaStore based on 
https://emacs-lsp.github.io/lsp-mode/page/lsp-yaml/#lsp-yaml-schema-store-uri.)

> One practical question: AIUI the main point of having this is so it can be 
> provided to the VSCode YAML extension so it understands .clangd files. How 
> does this work mechanically?

My understanding, based on the discussion in the issue and my experimentation 
is:

- If the YAML extension's `"yaml.schemaStore.enable"` setting is enabled (which 
is the default), the extension downloads a catalog of schemas from 
schemastore.org
- Clangd's entry in that catalog, which you can see if you load 
https://www.schemastore.org/api/json/catalog.json and filter for "clangd" 
[aside: I recommend Firefox's built-in JSON viewer for such tasks, the builtin 
JSON visualization and filtering is really neat; if you have any pull with the 
Chrome team, maybe put in a good word for adding a similar JSON viewer], 
declares that the schema applies to files named `.clangd`
- The extension automatically applies the schema to the `.clangd` file in your 
workspace

> Does it need to be part of the vscode-clangd repo instead?

I think being in the vscode-clangd repo would have the small advantage that the 
vscode-clangd extension could use the YAML extension's contribution point to 
install the schema locally even if `"yaml.schemaStore.enable"` is set to false. 
Not sure whether that's worth putting in place.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140462

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


[PATCH] D140538: [Clang][CodeGen] Use poison instead of undef for dummy values in CGExpr [NFC]

2022-12-23 Thread Manuel Brito via Phabricator via cfe-commits
ManuelJBrito updated this revision to Diff 485072.
ManuelJBrito added a comment.

Fix demangle test


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

https://reviews.llvm.org/D140538

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  libcxxabi/test/test_demangle.pass.cpp

Index: libcxxabi/test/test_demangle.pass.cpp
===
--- libcxxabi/test/test_demangle.pass.cpp
+++ libcxxabi/test/test_demangle.pass.cpp
@@ -3169,7 +3169,7 @@
 {"_ZN5clang7CodeGen15CodeGenFunction9EmitCheckEPN4llvm5ValueEj", "clang::CodeGen::CodeGenFunction::EmitCheck(llvm::Value*, unsigned int)"},
 {"_ZN5clang7CodeGen15CodeGenFunction9getTrapBBEv", "clang::CodeGen::CodeGenFunction::getTrapBB()"},
 {"_ZN5clang7CodeGen15CodeGenFunction24EmitComplexPrePostIncDecEPKNS_13UnaryOperatorENS0_6LValueEbb", "clang::CodeGen::CodeGenFunction::EmitComplexPrePostIncDec(clang::UnaryOperator const*, clang::CodeGen::LValue, bool, bool)"},
-{"_ZN5clang7CodeGen15CodeGenFunction14GetUndefRValueENS_8QualTypeE", "clang::CodeGen::CodeGenFunction::GetUndefRValue(clang::QualType)"},
+{"_ZN5clang7CodeGen15CodeGenFunction15GetPoisonRValueENS_8QualTypeE", "clang::CodeGen::CodeGenFunction::GetPoisonRValue(clang::QualType)"},
 {"_ZN5clang7CodeGen15CodeGenFunction21EmitUnsupportedRValueEPKNS_4ExprEPKc", "clang::CodeGen::CodeGenFunction::EmitUnsupportedRValue(clang::Expr const*, char const*)"},
 {"_ZN5clang7CodeGen15CodeGenFunction21EmitUnsupportedLValueEPKNS_4ExprEPKc", "clang::CodeGen::CodeGenFunction::EmitUnsupportedLValue(clang::Expr const*, char const*)"},
 {"_ZN5clang7CodeGen15CodeGenFunction17EmitCheckedLValueEPKNS_4ExprE", "clang::CodeGen::CodeGenFunction::EmitCheckedLValue(clang::Expr const*)"},
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -3740,8 +3740,8 @@
   /// Create a check that a scalar RValue is non-null.
   llvm::Value *EmitNonNullRValueCheck(RValue RV, QualType T);
 
-  /// GetUndefRValue - Get an appropriate 'undef' rvalue for the given type.
-  RValue GetUndefRValue(QualType Ty);
+  /// GetPoisonRValue - Get an appropriate 'poison' rvalue for the given type.
+  RValue GetPoisonRValue(QualType Ty);
 
   /// EmitUnsupportedRValue - Emit a dummy r-value using the type of E
   /// and issue an ErrorUnsupported style diagnostic (using the
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -1624,7 +1624,7 @@
   CGF.ErrorUnsupported(E, "scalar expression");
   if (E->getType()->isVoidType())
 return nullptr;
-  return llvm::UndefValue::get(CGF.ConvertType(E->getType()));
+  return llvm::PoisonValue::get(CGF.ConvertType(E->getType()));
 }
 
 Value *
@@ -4906,7 +4906,7 @@
   // If EmitVAArg fails, emit an error.
   if (!ArgPtr.isValid()) {
 CGF.ErrorUnsupported(VE, "va_arg expression");
-return llvm::UndefValue::get(ArgTy);
+return llvm::PoisonValue::get(ArgTy);
   }
 
   // FIXME Volatility.
Index: clang/lib/CodeGen/CGExprComplex.cpp
===
--- clang/lib/CodeGen/CGExprComplex.cpp
+++ clang/lib/CodeGen/CGExprComplex.cpp
@@ -419,7 +419,7 @@
   CGF.ErrorUnsupported(E, "complex expression");
   llvm::Type *EltTy =
 CGF.ConvertType(getComplexType(E->getType())->getElementType());
-  llvm::Value *U = llvm::UndefValue::get(EltTy);
+  llvm::Value *U = llvm::PoisonValue::get(EltTy);
   return ComplexPairTy(U, U);
 }
 
@@ -1274,7 +1274,7 @@
 CGF.ErrorUnsupported(E, "complex va_arg expression");
 llvm::Type *EltTy =
   CGF.ConvertType(E->getType()->castAs()->getElementType());
-llvm::Value *U = llvm::UndefValue::get(EltTy);
+llvm::Value *U = llvm::PoisonValue::get(EltTy);
 return ComplexPairTy(U, U);
   }
 
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -1169,7 +1169,7 @@
   return Builder.CreateICmpNE(V, llvm::Constant::getNullValue(V->getType()));
 }
 
-RValue CodeGenFunction::GetUndefRValue(QualType Ty) {
+RValue CodeGenFunction::GetPoisonRValue(QualType Ty) {
   if (Ty->isVoidType())
 return RValue::get(nullptr);
 
@@ -1177,7 +1177,7 @@
   case TEK_Complex: {
 llvm::Type *EltTy =
   ConvertType(Ty->castAs()->getElementType());
-llvm::Value *U = llvm::UndefValue::get(EltTy);
+llvm::Value *U = llvm::PoisonValue::get(EltTy);
 return RValue::getComplex(std::make_pair(U, U));
   }
 
@@ -1190,7 +1190,7 @@
   }
 
   case TEK_Scalar:
-return RValue::get(llvm::U

[PATCH] D140587: [clang] Fix a clang crash on invalid code in C++20 mode.

2022-12-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added subscribers: ayzhao, ilya-biryukov.
ilya-biryukov added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:6177
   // constructors. For example, conversion function.
   if (const auto *RD =
   
dyn_cast(DestType->getAs()->getDecl());

@ayzhao it's a bit surprising that this code path runs for braced 
initializations even though the patch was written for parenthesized inits. Is 
this intended?



Comment at: clang/lib/Sema/SemaInit.cpp:6179
   
dyn_cast(DestType->getAs()->getDecl());
-  S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
+  S.getLangOpts().CPlusPlus20 && RD && RD->hasDefinition() &&
+  RD->isAggregate() && Failed() &&

NIT: could you add a comment that we don't need to call `RequireCompleteType` 
as `TryConstructorInitialization` already does this for us?

`RequireCompleteType` should be the default choice in general as we might need 
to pick the right template specialization and do the corresponding template 
instantiation. However, in this case it has already been done.



Comment at: clang/test/SemaCXX/recovery-expr-type.cpp:181
+A foo() { // expected-error {{implicit instantiation of undefined 
template}}
+  return A{1}; // expected-error 2{{implicit instantiation of 
undefined template}}
+}

Could you add a test for `A(1)` too?
The code path somehow runs for `{}` too, but I think it's unintended and the 
relevant code path might only run for parenthesized init.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140587

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


[PATCH] D140587: [clang] Fix a clang crash on invalid code in C++20 mode.

2022-12-23 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM to unbreak clangd, this seems to pop up a lot for Chrome developers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140587

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


[PATCH] D105584: [MLIR][OpenMP] Distribute Construct Operation

2022-12-23 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added a comment.

Ping!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105584

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


[PATCH] D140617: [clangd] Fix a clangd crash when indexing the standard library.

2022-12-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Setup a current working directory (the build directoy) when creating a compile
instance. (otherwise clangd may die immediately when the VFS doesn't get input
files e.g. -fsanitize-ignorelist="../ignores.txt").


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140617

Files:
  clang-tools-extra/clangd/index/StdLib.cpp


Index: clang-tools-extra/clangd/index/StdLib.cpp
===
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -224,10 +224,11 @@
   IgnoreDiagnostics IgnoreDiags;
   // CompilerInvocation is taken from elsewhere, and may map a dirty buffer.
   CI->getPreprocessorOpts().clearRemappedFiles();
+  std::string CWD = CI->getFileSystemOpts().WorkingDir;
   auto Clang = prepareCompilerInstance(
   std::move(CI), /*Preamble=*/nullptr,
   llvm::MemoryBuffer::getMemBuffer(HeaderSources, Input.getFile()),
-  TFS.view(/*CWD=*/std::nullopt), IgnoreDiags);
+  TFS.view(CWD), IgnoreDiags);
   if (!Clang) {
 elog("Standard Library Index: Couldn't build compiler instance");
 return Symbols;


Index: clang-tools-extra/clangd/index/StdLib.cpp
===
--- clang-tools-extra/clangd/index/StdLib.cpp
+++ clang-tools-extra/clangd/index/StdLib.cpp
@@ -224,10 +224,11 @@
   IgnoreDiagnostics IgnoreDiags;
   // CompilerInvocation is taken from elsewhere, and may map a dirty buffer.
   CI->getPreprocessorOpts().clearRemappedFiles();
+  std::string CWD = CI->getFileSystemOpts().WorkingDir;
   auto Clang = prepareCompilerInstance(
   std::move(CI), /*Preamble=*/nullptr,
   llvm::MemoryBuffer::getMemBuffer(HeaderSources, Input.getFile()),
-  TFS.view(/*CWD=*/std::nullopt), IgnoreDiags);
+  TFS.view(CWD), IgnoreDiags);
   if (!Clang) {
 elog("Standard Library Index: Couldn't build compiler instance");
 return Symbols;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e0fa7c7 - Remove empty header file.

2022-12-23 Thread Dani Ferreira Franco Moura via cfe-commits

Author: Dani Ferreira Franco Moura
Date: 2022-12-23T11:34:50Z
New Revision: e0fa7c730d01fafd877863a145462cf1e0d5fd5b

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

LOG: Remove empty header file.

Reviewed By: gribozavr2, merrymeerkat

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

Added: 


Modified: 
clang/docs/tools/clang-formatted-files.txt
clang/include/clang/module.modulemap

Removed: 
clang/include/clang/Analysis/AnalysisDiagnostic.h



diff  --git a/clang/docs/tools/clang-formatted-files.txt 
b/clang/docs/tools/clang-formatted-files.txt
index c7443e7a228dc..3babeeeab03f5 100644
--- a/clang/docs/tools/clang-formatted-files.txt
+++ b/clang/docs/tools/clang-formatted-files.txt
@@ -116,7 +116,6 @@ clang/bindings/python/tests/cindex/INPUTS/header3.h
 clang/examples/Attribute/Attribute.cpp
 clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
 clang/examples/PluginsOrder/PluginsOrder.cpp
-clang/include/clang/Analysis/AnalysisDiagnostic.h
 clang/include/clang/Analysis/BodyFarm.h
 clang/include/clang/Analysis/IssueHash.h
 clang/include/clang/Analysis/MacroExpansionContext.h

diff  --git a/clang/include/clang/Analysis/AnalysisDiagnostic.h 
b/clang/include/clang/Analysis/AnalysisDiagnostic.h
deleted file mode 100644
index fd5f2ffe6483d..0
--- a/clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- DiagnosticAnalysis.h - Diagnostics for libanalysis -*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-#define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticAnalysis.h"
-
-#endif

diff  --git a/clang/include/clang/module.modulemap 
b/clang/include/clang/module.modulemap
index c182da1d830a8..9810add761f81 100644
--- a/clang/include/clang/module.modulemap
+++ b/clang/include/clang/module.modulemap
@@ -94,10 +94,7 @@ module Clang_Diagnostics {
   requires cplusplus
 
   module All { header "Basic/AllDiagnostics.h" export * }
-  module Analysis {
-header "Analysis/AnalysisDiagnostic.h" export *
-textual header "Analysis/Analyses/UnsafeBufferUsageGadgets.def"
-  }
+  module Analysis { textual header 
"Analysis/Analyses/UnsafeBufferUsageGadgets.def" }
   module AST { header "AST/ASTDiagnostic.h" export * }
   module Comment { header "AST/CommentDiagnostic.h" export * }
   module Driver { header "Driver/DriverDiagnostic.h" export * }



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


[PATCH] D140483: Remove empty header file.

2022-12-23 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe0fa7c730d01: Remove empty header file. (authored by 
merrymeerkat).

Changed prior to commit:
  https://reviews.llvm.org/D140483?vs=484578&id=485075#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140483

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/include/clang/Analysis/AnalysisDiagnostic.h
  clang/include/clang/module.modulemap


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -94,10 +94,7 @@
   requires cplusplus
 
   module All { header "Basic/AllDiagnostics.h" export * }
-  module Analysis {
-header "Analysis/AnalysisDiagnostic.h" export *
-textual header "Analysis/Analyses/UnsafeBufferUsageGadgets.def"
-  }
+  module Analysis { textual header 
"Analysis/Analyses/UnsafeBufferUsageGadgets.def" }
   module AST { header "AST/ASTDiagnostic.h" export * }
   module Comment { header "AST/CommentDiagnostic.h" export * }
   module Driver { header "Driver/DriverDiagnostic.h" export * }
Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- DiagnosticAnalysis.h - Diagnostics for libanalysis -*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-#define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticAnalysis.h"
-
-#endif
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -116,7 +116,6 @@
 clang/examples/Attribute/Attribute.cpp
 clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
 clang/examples/PluginsOrder/PluginsOrder.cpp
-clang/include/clang/Analysis/AnalysisDiagnostic.h
 clang/include/clang/Analysis/BodyFarm.h
 clang/include/clang/Analysis/IssueHash.h
 clang/include/clang/Analysis/MacroExpansionContext.h


Index: clang/include/clang/module.modulemap
===
--- clang/include/clang/module.modulemap
+++ clang/include/clang/module.modulemap
@@ -94,10 +94,7 @@
   requires cplusplus
 
   module All { header "Basic/AllDiagnostics.h" export * }
-  module Analysis {
-header "Analysis/AnalysisDiagnostic.h" export *
-textual header "Analysis/Analyses/UnsafeBufferUsageGadgets.def"
-  }
+  module Analysis { textual header "Analysis/Analyses/UnsafeBufferUsageGadgets.def" }
   module AST { header "AST/ASTDiagnostic.h" export * }
   module Comment { header "AST/CommentDiagnostic.h" export * }
   module Driver { header "Driver/DriverDiagnostic.h" export * }
Index: clang/include/clang/Analysis/AnalysisDiagnostic.h
===
--- clang/include/clang/Analysis/AnalysisDiagnostic.h
+++ /dev/null
@@ -1,14 +0,0 @@
-//===--- DiagnosticAnalysis.h - Diagnostics for libanalysis -*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#ifndef LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-#define LLVM_CLANG_ANALYSIS_ANALYSISDIAGNOSTIC_H
-
-#include "clang/Basic/DiagnosticAnalysis.h"
-
-#endif
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -116,7 +116,6 @@
 clang/examples/Attribute/Attribute.cpp
 clang/examples/CallSuperAttribute/CallSuperAttrInfo.cpp
 clang/examples/PluginsOrder/PluginsOrder.cpp
-clang/include/clang/Analysis/AnalysisDiagnostic.h
 clang/include/clang/Analysis/BodyFarm.h
 clang/include/clang/Analysis/IssueHash.h
 clang/include/clang/Analysis/MacroExpansionContext.h
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140587: [clang] Fix a clang crash on invalid code in C++20 mode.

2022-12-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 485076.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140587

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast 
-frecovery-ast-type -o - %s -std=gnu++17 -fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++17 
-fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++20 
-fsyntax-only -verify
+
 
 namespace test0 {
 struct Indestructible {
@@ -171,3 +173,13 @@
   S.m(1); // no crash
 }
 }
+
+namespace test16 {
+// verify we do not crash on incomplete class type.
+template struct A; // expected-note 5{{template is 
declared here}}
+A foo() { // expected-error {{implicit instantiation of undefined 
template}}
+  if (1 == 1)
+return A{1}; // expected-error 2{{implicit instantiation of 
undefined template}}
+  return A(1); // expected-error 2{{implicit instantiation of 
undefined template}}
+}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6176,7 +6176,11 @@
   // constructors. For example, conversion function.
   if (const auto *RD =
   
dyn_cast(DestType->getAs()->getDecl());
-  S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
+  // In general, we should call isCompleteType for RD to check its
+  // completeness, we don't call it here as it was already called in 
the
+  // above TryConstructorInitialization.
+  S.getLangOpts().CPlusPlus20 && RD && RD->hasDefinition() &&
+  RD->isAggregate() && Failed() &&
   getFailureKind() == FK_ConstructorOverloadFailed) {
 // C++20 [dcl.init] 17.6.2.2:
 //   - Otherwise, if no constructor is viable, the destination type is


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -std=gnu++17 -fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++17 -fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++20 -fsyntax-only -verify
+
 
 namespace test0 {
 struct Indestructible {
@@ -171,3 +173,13 @@
   S.m(1); // no crash
 }
 }
+
+namespace test16 {
+// verify we do not crash on incomplete class type.
+template struct A; // expected-note 5{{template is declared here}}
+A foo() { // expected-error {{implicit instantiation of undefined template}}
+  if (1 == 1)
+return A{1}; // expected-error 2{{implicit instantiation of undefined template}}
+  return A(1); // expected-error 2{{implicit instantiation of undefined template}}
+}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6176,7 +6176,11 @@
   // constructors. For example, conversion function.
   if (const auto *RD =
   dyn_cast(DestType->getAs()->getDecl());
-  S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
+  // In general, we should call isCompleteType for RD to check its
+  // completeness, we don't call it here as it was already called in the
+  // above TryConstructorInitialization.
+  S.getLangOpts().CPlusPlus20 && RD && RD->hasDefinition() &&
+  RD->isAggregate() && Failed() &&
   getFailureKind() == FK_ConstructorOverloadFailed) {
 // C++20 [dcl.init] 17.6.2.2:
 //   - Otherwise, if no constructor is viable, the destination type is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 32d7aae - [clang] Fix a clang crash on invalid code in C++20 mode.

2022-12-23 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-12-23T12:40:39+01:00
New Revision: 32d7aae04fdb58e65a952f281ff2f2c3f396d98f

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

LOG: [clang] Fix a clang crash on invalid code in C++20 mode.

This crash is a combination of recovery-expr + new SemaInit.cpp code
introduced by by https://reviews.llvm.org/D129531.

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

Added: 


Modified: 
clang/lib/Sema/SemaInit.cpp
clang/test/SemaCXX/recovery-expr-type.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 103986521f76e..efc3274ce7d3c 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -6176,7 +6176,11 @@ void InitializationSequence::InitializeFrom(Sema &S,
   // constructors. For example, conversion function.
   if (const auto *RD =
   
dyn_cast(DestType->getAs()->getDecl());
-  S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
+  // In general, we should call isCompleteType for RD to check its
+  // completeness, we don't call it here as it was already called in 
the
+  // above TryConstructorInitialization.
+  S.getLangOpts().CPlusPlus20 && RD && RD->hasDefinition() &&
+  RD->isAggregate() && Failed() &&
   getFailureKind() == FK_ConstructorOverloadFailed) {
 // C++20 [dcl.init] 17.6.2.2:
 //   - Otherwise, if no constructor is viable, the destination type is

diff  --git a/clang/test/SemaCXX/recovery-expr-type.cpp 
b/clang/test/SemaCXX/recovery-expr-type.cpp
index a5ba1ae2b8222..479039f284799 100644
--- a/clang/test/SemaCXX/recovery-expr-type.cpp
+++ b/clang/test/SemaCXX/recovery-expr-type.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast 
-frecovery-ast-type -o - %s -std=gnu++17 -fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++17 
-fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++20 
-fsyntax-only -verify
+
 
 namespace test0 {
 struct Indestructible {
@@ -171,3 +173,13 @@ void f() {
   S.m(1); // no crash
 }
 }
+
+namespace test16 {
+// verify we do not crash on incomplete class type.
+template struct A; // expected-note 5{{template is 
declared here}}
+A foo() { // expected-error {{implicit instantiation of undefined 
template}}
+  if (1 == 1)
+return A{1}; // expected-error 2{{implicit instantiation of 
undefined template}}
+  return A(1); // expected-error 2{{implicit instantiation of 
undefined template}}
+}
+}



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


[PATCH] D140587: [clang] Fix a clang crash on invalid code in C++20 mode.

2022-12-23 Thread Haojian Wu 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 rG32d7aae04fdb: [clang] Fix a clang crash on invalid code in 
C++20 mode. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140587

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast 
-frecovery-ast-type -o - %s -std=gnu++17 -fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++17 
-fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++20 
-fsyntax-only -verify
+
 
 namespace test0 {
 struct Indestructible {
@@ -171,3 +173,13 @@
   S.m(1); // no crash
 }
 }
+
+namespace test16 {
+// verify we do not crash on incomplete class type.
+template struct A; // expected-note 5{{template is 
declared here}}
+A foo() { // expected-error {{implicit instantiation of undefined 
template}}
+  if (1 == 1)
+return A{1}; // expected-error 2{{implicit instantiation of 
undefined template}}
+  return A(1); // expected-error 2{{implicit instantiation of 
undefined template}}
+}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6176,7 +6176,11 @@
   // constructors. For example, conversion function.
   if (const auto *RD =
   
dyn_cast(DestType->getAs()->getDecl());
-  S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
+  // In general, we should call isCompleteType for RD to check its
+  // completeness, we don't call it here as it was already called in 
the
+  // above TryConstructorInitialization.
+  S.getLangOpts().CPlusPlus20 && RD && RD->hasDefinition() &&
+  RD->isAggregate() && Failed() &&
   getFailureKind() == FK_ConstructorOverloadFailed) {
 // C++20 [dcl.init] 17.6.2.2:
 //   - Otherwise, if no constructor is viable, the destination type is


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -std=gnu++17 -fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++17 -fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -o - %s -std=gnu++20 -fsyntax-only -verify
+
 
 namespace test0 {
 struct Indestructible {
@@ -171,3 +173,13 @@
   S.m(1); // no crash
 }
 }
+
+namespace test16 {
+// verify we do not crash on incomplete class type.
+template struct A; // expected-note 5{{template is declared here}}
+A foo() { // expected-error {{implicit instantiation of undefined template}}
+  if (1 == 1)
+return A{1}; // expected-error 2{{implicit instantiation of undefined template}}
+  return A(1); // expected-error 2{{implicit instantiation of undefined template}}
+}
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -6176,7 +6176,11 @@
   // constructors. For example, conversion function.
   if (const auto *RD =
   dyn_cast(DestType->getAs()->getDecl());
-  S.getLangOpts().CPlusPlus20 && RD && RD->isAggregate() && Failed() &&
+  // In general, we should call isCompleteType for RD to check its
+  // completeness, we don't call it here as it was already called in the
+  // above TryConstructorInitialization.
+  S.getLangOpts().CPlusPlus20 && RD && RD->hasDefinition() &&
+  RD->isAggregate() && Failed() &&
   getFailureKind() == FK_ConstructorOverloadFailed) {
 // C++20 [dcl.init] 17.6.2.2:
 //   - Otherwise, if no constructor is viable, the destination type is
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140614: [C++20] Check the dependency of declaration contexts before pumping diagnostics

2022-12-23 Thread Liming Liu via Phabricator via cfe-commits
lime added a comment.

I submitted it a little early. The correct fix may be letting the declaration 
be dependent.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140614

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


[PATCH] D140619: ExtractFunction: support extracting expressions and selected part of it

2022-12-23 Thread Kacper Kowalski via Phabricator via cfe-commits
KKoovalsky created this revision.
Herald added subscribers: kadircet, arphaman, mgrang.
Herald added a project: All.
KKoovalsky requested review of this revision.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang-tools-extra.

This is mainly insipred by ExtractVariable's ParsedBinaryOperator,
tweaked a little to collect references within the selected area.

On the side:
This is my first PR to the LLVM (and clangd) - I wanted to see how it
goes for the future, to contribute even more, as I am a C++ fan and I
love open-source, plus recently, I really like to automate stuff when
coding!

Getting back to the implemented functionality:
it upports extraction of expressions to a function or method:

- int x{[[a + b + c]]},
- int x{a + [[b + c]] + d};

Handles:

- Binary operators.
- Operator overloads, which resemble binary operators, e.g. struct S{ S& 
operator+(const S&); }
- Infers return type of the expression basing on the operation return type; 
refs and const-refs are properly inferred as well.
- Collects parameters from the selected area. Skips global variables and 
members. (Uses already-in-place DeclInfoMap containing info about the 
declarations within the enclosing function).
- Handles deeply nested arguments within function calls, and collects them as 
the extracted function parameters.

Known limitations:

- Macros within the selected area; the selected area is treated as the expr 
would be selected to the most-LHS entity; effectively: int x{a + 
[[SOME_MACRO(A) + b]] + c} becomes: int x{[[a + SOME_MACRO(A) + b]] + c} This 
is known limitation of ExtractVariable, thus nothing new here.
- Does not make the method 'const' if the selected members are not mutated, in 
case the enclosing method is non-const.

PS. This contribution is a little messy, since it was hard to support
partially selected expressions, because the code already-in-place used
the term "root statement", which assumes that the entire statement is
selected. With this PR this assumption will be broken.
Yet, adding this feature taught me a lot, and I understand the code
structure better. I would like to boil down all the details of
implementing the Extract Function feature as a whole.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140619

Files:
  clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp

Index: clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
===
--- clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
+++ clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
@@ -24,8 +24,6 @@
 
   // Root statements should have common parent.
   EXPECT_EQ(apply("for(;;) [[1+2; 1+2;]]"), "unavailable");
-  // Expressions aren't extracted.
-  EXPECT_EQ(apply("int x = 0; [[x++;]]"), "unavailable");
   // We don't support extraction from lambdas.
   EXPECT_EQ(apply("auto lam = [](){ [[int x;]] }; "), "unavailable");
   // Partial statements aren't extracted.
@@ -190,6 +188,16 @@
 }]]
   )cpp";
   EXPECT_EQ(apply(CompoundFailInput), "unavailable");
+
+  std::string CompoundWithMultipleStatementsFailInput = R"cpp(
+void f() [[{
+  int a = 1;
+  int b = 2;
+  ++b;
+  b += a;
+}]]
+  )cpp";
+  EXPECT_EQ(apply(CompoundWithMultipleStatementsFailInput), "unavailable");
 }
 
 TEST_F(ExtractFunctionTest, DifferentHeaderSourceTest) {
@@ -571,6 +579,795 @@
   EXPECT_EQ(apply(Before), After);
 }
 
+TEST_F(ExtractFunctionTest, Expressions) {
+  std::vector> InputOutputs{
+  // FULL BINARY EXPRESSIONS
+  // Full binary expression, basic maths
+  {R"cpp(
+void wrapperFun() {
+  double a{2.0}, b{3.2}, c{31.55};
+  double v{[[b * b - 4 * a * c]]};
+}
+  )cpp",
+   R"cpp(
+double extracted(double &a, double &b, double &c) {
+return b * b - 4 * a * c;
+}
+void wrapperFun() {
+  double a{2.0}, b{3.2}, c{31.55};
+  double v{extracted(a, b, c)};
+}
+  )cpp"},
+  // Full binary expression composed of '+' operator overloads ops
+  {
+  R"cpp(
+struct S {
+  S operator+(const S&) {
+return *this;
+  }
+};
+void wrapperFun() {
+  S S1, S2, S3;
+  auto R{[[S1 + S2 + S3]]};
+}
+  )cpp",
+  R"cpp(
+struct S {
+  S operator+(const S&) {
+return *this;
+  }
+};
+S extracted(S &S1, S &S2, S &S3) {
+return S1 + S2 + S3;
+}
+void wrapperFun() {
+  S S1, S2, S3;
+  auto R{extracted(S1, S2, S3)};
+}
+  )cpp"},
+  // Boolean predicate as expression
+  {
+  R"cpp(
+void wrapperFun() {
+  int a{1};
+  auto R{[[a > 1]]};
+}
+  )cpp",
+  R"cpp(
+bool extracted(int &a) {
+return a > 1;
+}
+void wrapperFun() {
+  int a{1};
+  auto R{extracted(a)};
+}
+  )cpp"},
+  // Expression: captures no global variable
+  {R"cpp(
+static int a{2};
+void wrapperFun() {
+  int b{3}, c{31}, d{311};
+  auto v{[[a + b + c + d]]};
+}
+ 

[PATCH] D140620: [clang] Migrate away from a deprecated Clang CFG factory function

2022-12-23 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
gribozavr added a reviewer: merrymeerkat.
Herald added a subscriber: carlosgalvezp.
Herald added a reviewer: njames93.
Herald added a project: All.
gribozavr requested review of this revision.
Herald added projects: clang, clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140620

Files:
  clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -68,7 +68,7 @@
   assert(Body != nullptr);
 
   auto CFCtx = llvm::cantFail(
-  ControlFlowContext::build(nullptr, Body, &AST->getASTContext()));
+  ControlFlowContext::build(nullptr, *Body, AST->getASTContext()));
 
   AnalysisT Analysis = MakeAnalysis(AST->getASTContext());
   DataflowAnalysisContext DACtx(std::make_unique());
Index: clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
@@ -43,7 +43,7 @@
   using llvm::Expected;
 
   Expected Context =
-  ControlFlowContext::build(&FuncDecl, FuncDecl.getBody(), &ASTCtx);
+  ControlFlowContext::build(&FuncDecl, *FuncDecl.getBody(), ASTCtx);
   if (!Context)
 return std::nullopt;
 


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -68,7 +68,7 @@
   assert(Body != nullptr);
 
   auto CFCtx = llvm::cantFail(
-  ControlFlowContext::build(nullptr, Body, &AST->getASTContext()));
+  ControlFlowContext::build(nullptr, *Body, AST->getASTContext()));
 
   AnalysisT Analysis = MakeAnalysis(AST->getASTContext());
   DataflowAnalysisContext DACtx(std::make_unique());
Index: clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
@@ -43,7 +43,7 @@
   using llvm::Expected;
 
   Expected Context =
-  ControlFlowContext::build(&FuncDecl, FuncDecl.getBody(), &ASTCtx);
+  ControlFlowContext::build(&FuncDecl, *FuncDecl.getBody(), ASTCtx);
   if (!Context)
 return std::nullopt;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129531: [clang][C++20] P0960R3 and P1975R0: Allow initializing aggregates from a parenthesized list of values

2022-12-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

FYI, this patch triggers a crash in chromium, see 
https://github.com/llvm/llvm-project/issues/59675 for details.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

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


[PATCH] D82087: AMDGPU/clang: Add builtins for llvm.amdgcn.ballot

2022-12-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/test/CodeGenOpenCL/amdgpu-features.cl:7
+// RUN: %clang_cc1 -triple amdgcn -S -emit-llvm -o - %s | FileCheck 
--check-prefix=NOCPU %s
+// RUN: %clang_cc1 -triple amdgcn -target-feature +wavefrontsize32 -S 
-emit-llvm -o - %s | FileCheck --check-prefix=NOCPU-WAVE32 %s
+// RUN: %clang_cc1 -triple amdgcn -target-feature +wavefrontsize64 -S 
-emit-llvm -o - %s | FileCheck --check-prefix=NOCPU-WAVE64 %s

sameerds wrote:
> yaxunl wrote:
> > what happens if both +wavefrontsize32 and +wavefrontsize64 are specified?
> Shouldn't this be separately an error in itself? Is it tested elsewhere?
It looks like you end up with both features set by clang, and wave64 wins in 
codegen


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

https://reviews.llvm.org/D82087

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


[PATCH] D82087: AMDGPU/clang: Add builtins for llvm.amdgcn.ballot

2022-12-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm planned changes to this revision.
arsenm added a comment.

This doesn't work correctly for unspecified wavesize for non-wave32 targets


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

https://reviews.llvm.org/D82087

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


[clang-tools-extra] 3a39b0a - [clang] Migrate away from a deprecated Clang CFG factory function

2022-12-23 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2022-12-23T14:36:52+01:00
New Revision: 3a39b0ac1a72a2fb554e2ccc286003da5166faeb

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

LOG: [clang] Migrate away from a deprecated Clang CFG factory function

Reviewed By: merrymeerkat

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
index c97917ebc3e05..ccf9365940191 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
@@ -43,7 +43,7 @@ analyzeFunction(const FunctionDecl &FuncDecl, ASTContext 
&ASTCtx,
   using llvm::Expected;
 
   Expected Context =
-  ControlFlowContext::build(&FuncDecl, FuncDecl.getBody(), &ASTCtx);
+  ControlFlowContext::build(&FuncDecl, *FuncDecl.getBody(), ASTCtx);
   if (!Context)
 return std::nullopt;
 

diff  --git 
a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
index 8e0e27efae9e8..31d51173d29b2 100644
--- a/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -68,7 +68,7 @@ runAnalysis(llvm::StringRef Code, AnalysisT 
(*MakeAnalysis)(ASTContext &)) {
   assert(Body != nullptr);
 
   auto CFCtx = llvm::cantFail(
-  ControlFlowContext::build(nullptr, Body, &AST->getASTContext()));
+  ControlFlowContext::build(nullptr, *Body, AST->getASTContext()));
 
   AnalysisT Analysis = MakeAnalysis(AST->getASTContext());
   DataflowAnalysisContext DACtx(std::make_unique());



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


[PATCH] D140620: [clang] Migrate away from a deprecated Clang CFG factory function

2022-12-23 Thread Dmitri Gribenko 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 rG3a39b0ac1a72: [clang] Migrate away from a deprecated Clang 
CFG factory function (authored by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140620

Files:
  clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -68,7 +68,7 @@
   assert(Body != nullptr);
 
   auto CFCtx = llvm::cantFail(
-  ControlFlowContext::build(nullptr, Body, &AST->getASTContext()));
+  ControlFlowContext::build(nullptr, *Body, AST->getASTContext()));
 
   AnalysisT Analysis = MakeAnalysis(AST->getASTContext());
   DataflowAnalysisContext DACtx(std::make_unique());
Index: clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
@@ -43,7 +43,7 @@
   using llvm::Expected;
 
   Expected Context =
-  ControlFlowContext::build(&FuncDecl, FuncDecl.getBody(), &ASTCtx);
+  ControlFlowContext::build(&FuncDecl, *FuncDecl.getBody(), ASTCtx);
   if (!Context)
 return std::nullopt;
 


Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -68,7 +68,7 @@
   assert(Body != nullptr);
 
   auto CFCtx = llvm::cantFail(
-  ControlFlowContext::build(nullptr, Body, &AST->getASTContext()));
+  ControlFlowContext::build(nullptr, *Body, AST->getASTContext()));
 
   AnalysisT Analysis = MakeAnalysis(AST->getASTContext());
   DataflowAnalysisContext DACtx(std::make_unique());
Index: clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
@@ -43,7 +43,7 @@
   using llvm::Expected;
 
   Expected Context =
-  ControlFlowContext::build(&FuncDecl, FuncDecl.getBody(), &ASTCtx);
+  ControlFlowContext::build(&FuncDecl, *FuncDecl.getBody(), ASTCtx);
   if (!Context)
 return std::nullopt;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140625: [clang] Remove deprecated ControlFlowContext::build()

2022-12-23 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
gribozavr added a reviewer: merrymeerkat.
Herald added a reviewer: NoQ.
Herald added a project: All.
gribozavr 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/D140625

Files:
  clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
  clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp


Index: clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -67,12 +67,5 @@
   return ControlFlowContext(D, std::move(Cfg), std::move(StmtToBlock));
 }
 
-llvm::Expected
-ControlFlowContext::build(const Decl *D, Stmt *S, ASTContext *C) {
-  assert(S != nullptr);
-  assert(C != nullptr);
-  return build(D, *S, *C);
-}
-
 } // namespace dataflow
 } // namespace clang
Index: clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -35,10 +35,6 @@
   static llvm::Expected build(const Decl *D, Stmt &S,
   ASTContext &C);
 
-  // DEPRECATED. Use overload above.
-  static llvm::Expected build(const Decl *D, Stmt *S,
-  ASTContext *C);
-
   /// Returns the `Decl` containing the statement used to construct the CFG, if
   /// available.
   const Decl *getDecl() const { return ContainingDecl; }


Index: clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -67,12 +67,5 @@
   return ControlFlowContext(D, std::move(Cfg), std::move(StmtToBlock));
 }
 
-llvm::Expected
-ControlFlowContext::build(const Decl *D, Stmt *S, ASTContext *C) {
-  assert(S != nullptr);
-  assert(C != nullptr);
-  return build(D, *S, *C);
-}
-
 } // namespace dataflow
 } // namespace clang
Index: clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -35,10 +35,6 @@
   static llvm::Expected build(const Decl *D, Stmt &S,
   ASTContext &C);
 
-  // DEPRECATED. Use overload above.
-  static llvm::Expected build(const Decl *D, Stmt *S,
-  ASTContext *C);
-
   /// Returns the `Decl` containing the statement used to construct the CFG, if
   /// available.
   const Decl *getDecl() const { return ContainingDecl; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140312: [clang-format] Disallow decltype in the middle of constraints

2022-12-23 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:3494
 ///
 /// This is either the definition of a concept, or the body of a requires
 /// clause. It returns, when the parsing is complete, or the expression is

rymiel wrote:
> HazardyKnusperkeks wrote:
> > HazardyKnusperkeks wrote:
> > > The comment needs to be adapted.
> > > 
> > > But I think it could just be merged into the parsing of the requires 
> > > clause, or not?
> > Actually this needs to be done on D140339.
> You are right, thank you. D140339 will make it so `parseConstraintExpression` 
> will only ever be called from `parseRequiresClause`. Should I do that 
> refactor in D140339 or leave it for a future patch?
Either way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140312

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


[PATCH] D140626: [clang][nullability] Remove old overload for getNullability()

2022-12-23 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
merrymeerkat created this revision.
Herald added a project: All.
merrymeerkat 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/D140626

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -4157,10 +4157,6 @@
   }
   return std::nullopt;
 }
-// TODO: Remove overload.
-Optional Type::getNullability(const ASTContext &) const {
-  return getNullability();
-}
 
 bool Type::canHaveNullability(bool ResultIfUnknown) const {
   QualType type = getCanonicalTypeInternal();
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -2548,8 +2548,6 @@
   /// system, not as part of the canonical type, so nullability will
   /// be lost by canonicalization and desugaring.
   Optional getNullability() const;
-  // TODO: Remove overload.
-  Optional getNullability(const ASTContext &) const;
 
   /// Determine whether the given type can have a nullability
   /// specifier applied to it, i.e., if it is any kind of pointer type.


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -4157,10 +4157,6 @@
   }
   return std::nullopt;
 }
-// TODO: Remove overload.
-Optional Type::getNullability(const ASTContext &) const {
-  return getNullability();
-}
 
 bool Type::canHaveNullability(bool ResultIfUnknown) const {
   QualType type = getCanonicalTypeInternal();
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -2548,8 +2548,6 @@
   /// system, not as part of the canonical type, so nullability will
   /// be lost by canonicalization and desugaring.
   Optional getNullability() const;
-  // TODO: Remove overload.
-  Optional getNullability(const ASTContext &) const;
 
   /// Determine whether the given type can have a nullability
   /// specifier applied to it, i.e., if it is any kind of pointer type.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d273863 - [clang] Remove deprecated ControlFlowContext::build()

2022-12-23 Thread Dmitri Gribenko via cfe-commits

Author: Dmitri Gribenko
Date: 2022-12-23T15:06:59+01:00
New Revision: d27386384a2a414bcd7c7a18491db32f4ca86881

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

LOG: [clang] Remove deprecated ControlFlowContext::build()

Reviewed By: merrymeerkat

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h 
b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
index 58e901fac0047..e641468f77d00 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -35,10 +35,6 @@ class ControlFlowContext {
   static llvm::Expected build(const Decl *D, Stmt &S,
   ASTContext &C);
 
-  // DEPRECATED. Use overload above.
-  static llvm::Expected build(const Decl *D, Stmt *S,
-  ASTContext *C);
-
   /// Returns the `Decl` containing the statement used to construct the CFG, if
   /// available.
   const Decl *getDecl() const { return ContainingDecl; }

diff  --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp 
b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
index 2bdb1cdcc9534..2492b5203724c 100644
--- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -67,12 +67,5 @@ ControlFlowContext::build(const Decl *D, Stmt &S, ASTContext 
&C) {
   return ControlFlowContext(D, std::move(Cfg), std::move(StmtToBlock));
 }
 
-llvm::Expected
-ControlFlowContext::build(const Decl *D, Stmt *S, ASTContext *C) {
-  assert(S != nullptr);
-  assert(C != nullptr);
-  return build(D, *S, *C);
-}
-
 } // namespace dataflow
 } // namespace clang



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


[PATCH] D140625: [clang] Remove deprecated ControlFlowContext::build()

2022-12-23 Thread Dmitri Gribenko 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 rGd27386384a2a: [clang] Remove deprecated 
ControlFlowContext::build() (authored by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140625

Files:
  clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
  clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp


Index: clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -67,12 +67,5 @@
   return ControlFlowContext(D, std::move(Cfg), std::move(StmtToBlock));
 }
 
-llvm::Expected
-ControlFlowContext::build(const Decl *D, Stmt *S, ASTContext *C) {
-  assert(S != nullptr);
-  assert(C != nullptr);
-  return build(D, *S, *C);
-}
-
 } // namespace dataflow
 } // namespace clang
Index: clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -35,10 +35,6 @@
   static llvm::Expected build(const Decl *D, Stmt &S,
   ASTContext &C);
 
-  // DEPRECATED. Use overload above.
-  static llvm::Expected build(const Decl *D, Stmt *S,
-  ASTContext *C);
-
   /// Returns the `Decl` containing the statement used to construct the CFG, if
   /// available.
   const Decl *getDecl() const { return ContainingDecl; }


Index: clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -67,12 +67,5 @@
   return ControlFlowContext(D, std::move(Cfg), std::move(StmtToBlock));
 }
 
-llvm::Expected
-ControlFlowContext::build(const Decl *D, Stmt *S, ASTContext *C) {
-  assert(S != nullptr);
-  assert(C != nullptr);
-  return build(D, *S, *C);
-}
-
 } // namespace dataflow
 } // namespace clang
Index: clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
+++ clang/include/clang/Analysis/FlowSensitive/ControlFlowContext.h
@@ -35,10 +35,6 @@
   static llvm::Expected build(const Decl *D, Stmt &S,
   ASTContext &C);
 
-  // DEPRECATED. Use overload above.
-  static llvm::Expected build(const Decl *D, Stmt *S,
-  ASTContext *C);
-
   /// Returns the `Decl` containing the statement used to construct the CFG, if
   /// available.
   const Decl *getDecl() const { return ContainingDecl; }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0026874 - fix warn-xparser test

2022-12-23 Thread Mikhail Goncharov via cfe-commits

Author: Mikhail Goncharov
Date: 2022-12-23T15:34:06+01:00
New Revision: 0026874c8bd0616b520779b9fcfdb05e53ea4dca

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

LOG: fix warn-xparser test

for https://reviews.llvm.org/D140224

Added: 


Modified: 
clang/test/Driver/warn-Xparser.c

Removed: 




diff  --git a/clang/test/Driver/warn-Xparser.c 
b/clang/test/Driver/warn-Xparser.c
index 191826a6f4af9..d20db97dbd820 100644
--- a/clang/test/Driver/warn-Xparser.c
+++ b/clang/test/Driver/warn-Xparser.c
@@ -1,5 +1,5 @@
 /// Some macOS projects use -Xparser.
-// RUN: %clang -c -Xparser %s 2>&1 | FileCheck %s
+// RUN: %clang -c -o /dev/null -Xparser %s 2>&1 | FileCheck %s
 
 // CHECK: warning: argument unused during compilation: '-Xparser' 
[-Wunused-command-line-argument]
 



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


[PATCH] D82087: AMDGPU/clang: Add builtins for llvm.amdgcn.ballot

2022-12-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 485110.
arsenm added a comment.

Fix unknown target handling, diagnose some more of the errors


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

https://reviews.llvm.org/D82087

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/amdgpu-features-illegal.cl
  clang/test/CodeGenOpenCL/amdgpu-features.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-gfx10.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-wave32.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-wave64.cl
  clang/test/OpenMP/amdgcn-attributes.cpp
  clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
  clang/test/SemaOpenCL/builtins-amdgcn-error-wave64.cl

Index: clang/test/SemaOpenCL/builtins-amdgcn-error-wave64.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/builtins-amdgcn-error-wave64.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple amdgcn-- -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-feature +wavefrontsize32 -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -target-feature +wavefrontsize32 -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -target-feature -wavefrontsize64 -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -verify -S -o - %s
+
+typedef unsigned long ulong;
+
+void test_ballot_wave64(global ulong* out, int a, int b) {
+  *out = __builtin_amdgcn_ballot_w64(a == b);  // expected-error {{'__builtin_amdgcn_ballot_w64' needs target feature wavefrontsize64}}
+}
+
+__attribute__((target("wavefrontsize64")))
+void test_ballot_wave64_target_attr(global ulong* out, int a, int b) {
+  *out = __builtin_amdgcn_ballot_w64(a == b);
+}
Index: clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
===
--- /dev/null
+++ clang/test/SemaOpenCL/builtins-amdgcn-error-wave32.cl
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple amdgcn-- -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx900 -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx900 -target-feature +wavefrontsize64 -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -target-feature +wavefrontsize64 -verify -S -o - %s
+// RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1010 -target-feature -wavefrontsize32 -verify -S -o - %s
+
+typedef unsigned int uint;
+
+void test_ballot_wave32(global uint* out, int a, int b) {
+  *out = __builtin_amdgcn_ballot_w32(a == b);  // expected-error {{'__builtin_amdgcn_ballot_w32' needs target feature wavefrontsize32}}
+}
+
+// FIXME: Should error for subtargets that don't support wave32
+__attribute__((target("wavefrontsize32")))
+void test_ballot_wave32_target_attr(global uint* out, int a, int b) {
+  *out = __builtin_amdgcn_ballot_w32(a == b);
+}
Index: clang/test/OpenMP/amdgcn-attributes.cpp
===
--- clang/test/OpenMP/amdgcn-attributes.cpp
+++ clang/test/OpenMP/amdgcn-attributes.cpp
@@ -33,11 +33,11 @@
 }
 
 // DEFAULT: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
-// CPU: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst" "uniform-work-group-size"="true" }
+// CPU: attributes #0 = { convergent noinline norecurse nounwind optnone "frame-pointer"="none" "kernel" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts,+dpp,+flat-address-space,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64" "uniform-work-group-size"="true" }
 // NOIEEE: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-ieee"="false" "frame-pointer"="none" "kernel" "no-nans-fp-math"="true" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
 // UNSAFEATOMIC: attributes #0 = { convergent noinline norecurse nounwind optnone "amdgpu-unsafe-fp-atomics"="true" "frame-pointer"="none" "kernel" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
 
 // DEFAULT: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
-// CPU: attributes #1 = { convergent mustprogress noinline nounwind optnone "frame-pointer"="none" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="gfx900" "target-features"="+16-bit-insts,+ci-insts

[PATCH] D140628: [flang] Add driver install directory to AIX toolchain program paths list

2022-12-23 Thread Paul Scoropan via Phabricator via cfe-commits
pscoro created this revision.
Herald added a project: All.
pscoro requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140628

Files:
  clang/lib/Driver/ToolChains/AIX.cpp


Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -268,6 +268,11 @@
 /// AIX - AIX tool chain which can call as(1) and ld(1) directly.
 AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
 : ToolChain(D, Triple, Args) {
+
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)
+getProgramPaths().push_back(getDriver().Dir);
+
   ParseInlineAsmUsingAsmParser = Args.hasFlag(
   options::OPT_fintegrated_as, options::OPT_fno_integrated_as, true);
   getLibraryPaths().push_back(getDriver().SysRoot + "/usr/lib");


Index: clang/lib/Driver/ToolChains/AIX.cpp
===
--- clang/lib/Driver/ToolChains/AIX.cpp
+++ clang/lib/Driver/ToolChains/AIX.cpp
@@ -268,6 +268,11 @@
 /// AIX - AIX tool chain which can call as(1) and ld(1) directly.
 AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
 : ToolChain(D, Triple, Args) {
+
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)
+getProgramPaths().push_back(getDriver().Dir);
+
   ParseInlineAsmUsingAsmParser = Args.hasFlag(
   options::OPT_fintegrated_as, options::OPT_fno_integrated_as, true);
   getLibraryPaths().push_back(getDriver().SysRoot + "/usr/lib");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D140626: [clang][nullability] Remove old overload for getNullability()

2022-12-23 Thread Dani Ferreira Franco Moura via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfbee2dd9a4ba: [clang][nullability] Remove old overload for 
getNullability() (authored by merrymeerkat).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140626

Files:
  clang/include/clang/AST/Type.h
  clang/lib/AST/Type.cpp


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -4157,10 +4157,6 @@
   }
   return std::nullopt;
 }
-// TODO: Remove overload.
-Optional Type::getNullability(const ASTContext &) const {
-  return getNullability();
-}
 
 bool Type::canHaveNullability(bool ResultIfUnknown) const {
   QualType type = getCanonicalTypeInternal();
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -2548,8 +2548,6 @@
   /// system, not as part of the canonical type, so nullability will
   /// be lost by canonicalization and desugaring.
   Optional getNullability() const;
-  // TODO: Remove overload.
-  Optional getNullability(const ASTContext &) const;
 
   /// Determine whether the given type can have a nullability
   /// specifier applied to it, i.e., if it is any kind of pointer type.


Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -4157,10 +4157,6 @@
   }
   return std::nullopt;
 }
-// TODO: Remove overload.
-Optional Type::getNullability(const ASTContext &) const {
-  return getNullability();
-}
 
 bool Type::canHaveNullability(bool ResultIfUnknown) const {
   QualType type = getCanonicalTypeInternal();
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -2548,8 +2548,6 @@
   /// system, not as part of the canonical type, so nullability will
   /// be lost by canonicalization and desugaring.
   Optional getNullability() const;
-  // TODO: Remove overload.
-  Optional getNullability(const ASTContext &) const;
 
   /// Determine whether the given type can have a nullability
   /// specifier applied to it, i.e., if it is any kind of pointer type.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fbee2dd - [clang][nullability] Remove old overload for getNullability()

2022-12-23 Thread Dani Ferreira Franco Moura via cfe-commits

Author: Dani Ferreira Franco Moura
Date: 2022-12-23T16:50:58Z
New Revision: fbee2dd9a4ba226590d16546728e436ad9e5ed6c

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

LOG: [clang][nullability] Remove old overload for getNullability()

Reviewed By: gribozavr2

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

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 2407400b31315..8f7a4836381ae 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2548,8 +2548,6 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// system, not as part of the canonical type, so nullability will
   /// be lost by canonicalization and desugaring.
   Optional getNullability() const;
-  // TODO: Remove overload.
-  Optional getNullability(const ASTContext &) const;
 
   /// Determine whether the given type can have a nullability
   /// specifier applied to it, i.e., if it is any kind of pointer type.

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 0b551ae9af432..54bfb023237b0 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -4157,10 +4157,6 @@ Optional Type::getNullability() const {
   }
   return std::nullopt;
 }
-// TODO: Remove overload.
-Optional Type::getNullability(const ASTContext &) const {
-  return getNullability();
-}
 
 bool Type::canHaveNullability(bool ResultIfUnknown) const {
   QualType type = getCanonicalTypeInternal();



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


[PATCH] D131963: [libc++] Add custom clang-tidy checks

2022-12-23 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added inline comments.



Comment at: libcxx/test/libcxx/clang_tidy.sh.cpp:15
 // TODO: run clang-tidy with modules enabled once they are supported
+// RUN: clang-tidy %s --warnings-as-errors=* -header-filter=.* 
--checks='-*,libcpp-*' 
--load=%{test-tools}/clang_tidy_checks/libcxx-tidy.plugin -- %{compile_flags} 
-fno-modules
 // RUN: clang-tidy %s --warnings-as-errors=* -header-filter=.* 
--config-file=%S/../../.clang-tidy -- -Wweak-vtables %{compile_flags} 
-fno-modules

I actually think it would be better to do this is a separate script.

Is there any documentation on how to run this test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131963

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


[PATCH] D134410: [clang][CodeGen] Add noundef metadata to load instructions (preliminary 1 or 5)

2022-12-23 Thread Nuno Lopes via Phabricator via cfe-commits
nlopes added a comment.

In D134410#3983684 , @nikic wrote:

> The other problem I see here is that we still need to do something about the 
> memcpy -> load/store fold. As soon as we have poison from uninit values 
> (either directly or via `!uninit_is_poison`) this will start causing 
> miscompiles very quickly. The only way to do this right now is again with an 
> `` vector load/store, which still optimizes terribly. This needs 
> either load+store of integer to preserve poison, or again some form of byte 
> type.
>
> Something I've only recently realized is that we also run into this problem 
> when inserting spurious load/store pairs, e.g. as done by LICM scalar 
> promotion. If we're promoting say an i32 value to scalar that previously used 
> a conditional store, then promotion will now introduce an unconditional load 
> and store, which will spread poison from individual bytes. So that means that 
> technically scalar promotion (and SimplifyCFG store speculation) also need to 
> do some special dance to preserve poison. And without preservation of poison 
> across load/store/phi in plain ints, this is going to be a bad optimization 
> outcome either way: We'd have to use either a vector of i8 or a byte type for 
> the inserted phi nodes and only cast to integer and back when manipulating 
> the value, which would probably defeat the optimization. At that point 
> probably best to freeze the first load (which again needs a freezing load).

For this stuff, I think the ideal solution is the byte type. That's the only 
way to do this kind of raw byte copies. Doesn't spread poison between bits nor 
do you need to know if you are reading a pointer or something else. Nor does it 
require a freeze, which is annoying.

John will submit a proposal (next week?) using poison for uninit loads. I think 
we have converged on something cool. Thanks for insisting on that one!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134410

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


[PATCH] D140544: [DebugInfo] make DW_LANG_C11 respect -gstrict-dwarf

2022-12-23 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

Looks good


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140544

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


[PATCH] D140639: clang: Fix handling of __builtin_elementwise_copysign

2022-12-23 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added a reviewer: fhahn.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.

  I realized the handling of copysign made no sense at all.
  Only the type of the first operand should really matter, and
  it should not perform a conversion between them.


Also fixes misleading errors and producing broken IR for
integers.

  

We could accept different FP types for the sign argument,
if the intrinsic permitted different types like the DAG node.
As it is we would need to insert a cast, which could have
other effects (like trapping on snan) which should not happen
for a copysign.


https://reviews.llvm.org/D140639

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtins-elementwise-math.c
  clang/test/Sema/builtins-elementwise-math.c

Index: clang/test/Sema/builtins-elementwise-math.c
===
--- clang/test/Sema/builtins-elementwise-math.c
+++ clang/test/Sema/builtins-elementwise-math.c
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -std=c99 %s -pedantic -verify -triple=x86_64-apple-darwin9
 
+typedef double double2 __attribute__((ext_vector_type(2)));
+typedef double double4 __attribute__((ext_vector_type(4)));
+typedef float float2 __attribute__((ext_vector_type(2)));
 typedef float float4 __attribute__((ext_vector_type(4)));
 typedef int int3 __attribute__((ext_vector_type(3)));
 typedef unsigned unsigned3 __attribute__((ext_vector_type(3)));
@@ -13,6 +16,11 @@
 typedef int bar;
 bar b;
 
+__attribute__((address_space(1))) float float_as_one;
+typedef float waffle;
+waffle waf;
+
+
 void test_builtin_elementwise_abs(int i, double d, float4 v, int3 iv, unsigned u, unsigned4 uv) {
   struct Foo s = __builtin_elementwise_abs(i);
   // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
@@ -406,12 +414,12 @@
   // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned4' (vector of 4 'unsigned int' values))}}
 }
 
-void test_builtin_elementwise_copysign(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) {
+void test_builtin_elementwise_copysign(int i, short s, double d, float f, float4 v, int3 iv, unsigned3 uv, int *p) {
   i = __builtin_elementwise_copysign(p, d);
-  // expected-error@-1 {{arguments are of different types ('int *' vs 'double')}}
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int *')}}
 
-  struct Foo foo = __builtin_elementwise_copysign(i, i);
-  // expected-error@-1 {{initializing 'struct Foo' with an expression of incompatible type 'int'}}
+  i = __builtin_elementwise_copysign(i, i);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
 
   i = __builtin_elementwise_copysign(i);
   // expected-error@-1 {{too few arguments to function call, expected 2, have 1}}
@@ -423,40 +431,81 @@
   // expected-error@-1 {{too many arguments to function call, expected 2, have 3}}
 
   i = __builtin_elementwise_copysign(v, iv);
-  // expected-error@-1 {{arguments are of different types ('float4' (vector of 4 'float' values) vs 'int3' (vector of 3 'int' values))}}
+  // expected-error@-1 {{2nd argument must be a floating point type (was 'int3' (vector of 3 'int' values))}}
 
   i = __builtin_elementwise_copysign(uv, iv);
-  // expected-error@-1 {{arguments are of different types ('unsigned3' (vector of 3 'unsigned int' values) vs 'int3' (vector of 3 'int' values))}}
+  // expected-error@-1 {{1st argument must be a floating point type (was 'unsigned3' (vector of 3 'unsigned int' values))}}
 
   s = __builtin_elementwise_copysign(i, s);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
+
+  f = __builtin_elementwise_copysign(f, i);
+  // expected-error@-1 {{2nd argument must be a floating point type (was 'int')}}
+
+  f = __builtin_elementwise_copysign(i, f);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
 
   enum e { one,
two };
   i = __builtin_elementwise_copysign(one, two);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
 
   enum f { three };
   enum f x = __builtin_elementwise_copysign(one, three);
+  // expected-error@-1 {{1st argument must be a floating point type (was 'int')}}
 
   _BitInt(32) ext; // expected-warning {{'_BitInt' in C17 and earlier is a Clang extension}}
   ext = __builtin_elementwise_copysign(ext, ext);
+  // expected-error@-1 {{1st argument must be a floating point type (was '_BitInt(32)')}}
 
-  const int ci;
-  i = __builtin_elementwise_copysign(ci, i);
-  i = __builtin_elementwise_copysign(i, ci);
-  i = __builtin_elementwise_copysign(ci, ci);
+  const float cf32;
+  f = __builtin_elementwise_copysign(cf32, f);
+  f = __builtin_elementwise_copysign(f, cf32);
+  f = __builtin_elementwise_copysign(cf32, f);
 
-  i = __builtin_elementwise_copysign(i, int_as_one); // ok (attributes

[PATCH] D78441: Delete NaCl support

2022-12-23 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.
Herald added subscribers: llvm-commits, StephenFan, pengfei.
Herald added projects: LLVM, All.

@dschuff Is NaCL dead in 2022 ? :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78441

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


[PATCH] D140543: [clang-format] Add an option to format integer literal separators

2022-12-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 485180.
owenpan added a comment.
This revision is now accepted and ready to land.

- Adds support for C#, Java, and JavaScript using `_`.
- Adds support for only formatting affected ranges.
- Simplifies ``IntegerLiteralSeparatorFixer::format()``.
- Adds more assertions and makes minor efficiency improvements.


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

https://reviews.llvm.org/D140543

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/lib/Format/IntegerLiteralSeparatorFixer.h
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25121,6 +25121,50 @@
 #endif
 }
 
+TEST_F(FormatTest, IntegerLiteralSeparator) {
+  FormatStyle Style = getLLVMStyle();
+
+  const StringRef Binary("b = 0b10011'11'0110'1u;");
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Binary, 0);
+  verifyFormat(Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = -1;
+  verifyFormat("b = 0b10001101u;", Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = 1;
+  verifyFormat("b = 0b1'0'0'1'1'1'1'0'1'1'0'1u;", Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = 3;
+  verifyFormat("b = 0b100'111'101'101u;", Binary, Style);
+  Style.IntegerLiteralSeparator.Binary = 4;
+  verifyFormat("b = 0b1001'1110'1101u;", Binary, Style);
+
+  const StringRef Decimal("d = 184467'440737'0'95505'92ull;");
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Decimal, 0);
+  verifyFormat(Decimal, Style);
+  Style.IntegerLiteralSeparator.Decimal = -1;
+  verifyFormat("d = 18446744073709550592ull;", Decimal, Style);
+  Style.IntegerLiteralSeparator.Decimal = 3;
+  verifyFormat("d = 18'446'744'073'709'550'592ull;", Decimal, Style);
+
+  const StringRef Hex("h = 0xDEAD'BEEF'DE'AD'BEE'Fuz;");
+  EXPECT_EQ(Style.IntegerLiteralSeparator.Hex, 0);
+  verifyFormat(Hex, Style);
+  Style.IntegerLiteralSeparator.Hex = -1;
+  verifyFormat("h = 0xDEADBEEFDEADBEEFuz;", Hex, Style);
+  Style.IntegerLiteralSeparator.Hex = 2;
+  verifyFormat("h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;", Hex, Style);
+
+  verifyFormat("i = -1'234;\n"
+   "// clang-format off\n"
+   "j = 123'4;\n"
+   "// clang-format on\n"
+   "k = +1'234;",
+   "i = -12'34;\n"
+   "// clang-format off\n"
+   "j = 123'4;\n"
+   "// clang-format on\n"
+   "k = +1'23'4;",
+   Style);
+}
+
 } // namespace
 } // namespace format
 } // namespace clang
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.h
===
--- /dev/null
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.h
@@ -0,0 +1,38 @@
+//===--- IntegerLiteralSeparatorFixer.h -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file declares IntegerLiteralSeparatorFixer that fixes C++ integer
+/// literal separators.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_FORMAT_INTEGERLITERALSEPARATORFIXER_H
+#define LLVM_CLANG_LIB_FORMAT_INTEGERLITERALSEPARATORFIXER_H
+
+#include "TokenAnalyzer.h"
+
+namespace clang {
+namespace format {
+
+class IntegerLiteralSeparatorFixer {
+public:
+  std::pair process(const Environment &Env,
+ const FormatStyle &Style);
+
+private:
+  bool checkSeparator(const StringRef IntegerLiteral, int DigitsPerGroup) const;
+  std::string format(const StringRef IntegerLiteral, int DigitsPerGroup) const;
+
+  char Separator;
+};
+
+} // end namespace format
+} // end namespace clang
+
+#endif
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===
--- /dev/null
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -0,0 +1,201 @@
+//===--- IntegerLiteralSeparatorFixer.cpp ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// This file implements IntegerLiteralSeparatorFixer that fixes C++ integer
+/// literal separators.
+///
+//===---

[PATCH] D140543: [clang-format] Add an option to format integer literal separators

2022-12-23 Thread Owen Pan via Phabricator via cfe-commits
owenpan planned changes to this revision.
owenpan added a comment.

Will add more unit tests and perhaps move them to their own file.


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

https://reviews.llvm.org/D140543

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


[clang] 073cc29 - [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-23 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2022-12-24T11:41:17+08:00
New Revision: 073cc29e04b756cb4997bf3538c733c0938cd4ae

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

LOG: [X86][Reduce] Preserve fast math flags when change it. NFCI

@arsenm raised a good question that we should use a flag guard.
But I found it is not a problem as long as user uses intrinsics only: 
https://godbolt.org/z/WoYsqqjh3
Anyway, it is still nice to have.

Reviewed By: arsenm

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

Added: 
clang/test/CodeGen/builtins-x86-reduce.c

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a194fc7b105cb..ca21612e442e6 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -14741,6 +14741,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_reduce_fadd_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fadd, Ops[1]->getType());
+IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
 Builder.getFastMathFlags().setAllowReassoc();
 return Builder.CreateCall(F, {Ops[0], Ops[1]});
   }
@@ -14751,6 +14752,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_reduce_fmul_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fmul, Ops[1]->getType());
+IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
 Builder.getFastMathFlags().setAllowReassoc();
 return Builder.CreateCall(F, {Ops[0], Ops[1]});
   }
@@ -14761,6 +14763,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_reduce_fmax_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fmax, Ops[0]->getType());
+IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
 Builder.getFastMathFlags().setNoNaNs();
 return Builder.CreateCall(F, {Ops[0]});
   }
@@ -14771,6 +14774,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   case X86::BI__builtin_ia32_reduce_fmin_ph128: {
 Function *F =
 CGM.getIntrinsic(Intrinsic::vector_reduce_fmin, Ops[0]->getType());
+IRBuilder<>::FastMathFlagGuard FMFGuard(Builder);
 Builder.getFastMathFlags().setNoNaNs();
 return Builder.CreateCall(F, {Ops[0]});
   }

diff  --git a/clang/test/CodeGen/builtins-x86-reduce.c 
b/clang/test/CodeGen/builtins-x86-reduce.c
new file mode 100644
index 0..9e5b479df6584
--- /dev/null
+++ b/clang/test/CodeGen/builtins-x86-reduce.c
@@ -0,0 +1,92 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -target-feature +avx512f 
-target-feature +avx512vl -target-feature +avx512fp16 -emit-llvm -o - | 
FileCheck %s
+
+typedef double double8 __attribute__((ext_vector_type(8)));
+
+// CHECK-LABEL: @fadd1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <8 x double>, align 64
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca double, align 8
+// CHECK-NEXT:store <8 x double> [[A:%.*]], ptr [[A_ADDR]], align 64
+// CHECK-NEXT:store double [[B:%.*]], ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x double>, ptr [[A_ADDR]], align 64
+// CHECK-NEXT:[[TMP1:%.*]] = call reassoc double 
@llvm.vector.reduce.fadd.v8f64(double 0.00e+00, <8 x double> [[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[ADD:%.*]] = fadd double [[TMP1]], [[TMP2]]
+// CHECK-NEXT:ret double [[ADD]]
+//
+double fadd1(double8 a, double b) {
+  return __builtin_ia32_reduce_fadd_pd512(0.0, a) + b;
+}
+
+#pragma clang fp reassociate(on)
+// CHECK-LABEL: @fadd2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <8 x double>, align 64
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca double, align 8
+// CHECK-NEXT:store <8 x double> [[A:%.*]], ptr [[A_ADDR]], align 64
+// CHECK-NEXT:store double [[B:%.*]], ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x double>, ptr [[A_ADDR]], align 64
+// CHECK-NEXT:[[TMP1:%.*]] = call reassoc double 
@llvm.vector.reduce.fadd.v8f64(double 0.00e+00, <8 x double> [[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[ADD:%.*]] = fadd reassoc double [[TMP1]], [[TMP2]]
+// CHECK-NEXT:ret double [[ADD]]
+//
+double fadd2(double8 a, double b) {
+  return __builtin_ia32_reduce_fadd_pd512(0.0, a) + b;
+}
+
+typedef float float16 __attribute__((ext_vector_type(16)));
+
+#pragma clang fp reassociate(off)
+// CHECK-LABEL: @fmul1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <16 x float>, ali

[PATCH] D140467: [X86][Reduce] Preserve fast math flags when change it. NFCI

2022-12-23 Thread Phoebe Wang via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG073cc29e04b7: [X86][Reduce] Preserve fast math flags when 
change it. NFCI (authored by pengfei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140467

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-x86-reduce.c

Index: clang/test/CodeGen/builtins-x86-reduce.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-x86-reduce.c
@@ -0,0 +1,92 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 %s -triple x86_64-unknown-unknown -target-feature +avx512f -target-feature +avx512vl -target-feature +avx512fp16 -emit-llvm -o - | FileCheck %s
+
+typedef double double8 __attribute__((ext_vector_type(8)));
+
+// CHECK-LABEL: @fadd1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <8 x double>, align 64
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca double, align 8
+// CHECK-NEXT:store <8 x double> [[A:%.*]], ptr [[A_ADDR]], align 64
+// CHECK-NEXT:store double [[B:%.*]], ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x double>, ptr [[A_ADDR]], align 64
+// CHECK-NEXT:[[TMP1:%.*]] = call reassoc double @llvm.vector.reduce.fadd.v8f64(double 0.00e+00, <8 x double> [[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[ADD:%.*]] = fadd double [[TMP1]], [[TMP2]]
+// CHECK-NEXT:ret double [[ADD]]
+//
+double fadd1(double8 a, double b) {
+  return __builtin_ia32_reduce_fadd_pd512(0.0, a) + b;
+}
+
+#pragma clang fp reassociate(on)
+// CHECK-LABEL: @fadd2(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <8 x double>, align 64
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca double, align 8
+// CHECK-NEXT:store <8 x double> [[A:%.*]], ptr [[A_ADDR]], align 64
+// CHECK-NEXT:store double [[B:%.*]], ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x double>, ptr [[A_ADDR]], align 64
+// CHECK-NEXT:[[TMP1:%.*]] = call reassoc double @llvm.vector.reduce.fadd.v8f64(double 0.00e+00, <8 x double> [[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = load double, ptr [[B_ADDR]], align 8
+// CHECK-NEXT:[[ADD:%.*]] = fadd reassoc double [[TMP1]], [[TMP2]]
+// CHECK-NEXT:ret double [[ADD]]
+//
+double fadd2(double8 a, double b) {
+  return __builtin_ia32_reduce_fadd_pd512(0.0, a) + b;
+}
+
+typedef float float16 __attribute__((ext_vector_type(16)));
+
+#pragma clang fp reassociate(off)
+// CHECK-LABEL: @fmul1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <16 x float>, align 64
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca float, align 4
+// CHECK-NEXT:store <16 x float> [[A:%.*]], ptr [[A_ADDR]], align 64
+// CHECK-NEXT:store float [[B:%.*]], ptr [[B_ADDR]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x float>, ptr [[A_ADDR]], align 64
+// CHECK-NEXT:[[TMP1:%.*]] = call reassoc float @llvm.vector.reduce.fmul.v16f32(float 1.00e+00, <16 x float> [[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = load float, ptr [[B_ADDR]], align 4
+// CHECK-NEXT:[[ADD:%.*]] = fadd float [[TMP1]], [[TMP2]]
+// CHECK-NEXT:ret float [[ADD]]
+//
+float fmul1(float16 a, float b) {
+  return __builtin_ia32_reduce_fmul_ps512(1.0f, a) + b;
+}
+
+typedef _Float16 half8 __attribute__((ext_vector_type(8)));
+
+// CHECK-LABEL: @fmax1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <8 x half>, align 16
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store <8 x half> [[A:%.*]], ptr [[A_ADDR]], align 16
+// CHECK-NEXT:store half [[B:%.*]], ptr [[B_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load <8 x half>, ptr [[A_ADDR]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = call nnan half @llvm.vector.reduce.fmax.v8f16(<8 x half> [[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = load half, ptr [[B_ADDR]], align 2
+// CHECK-NEXT:[[ADD:%.*]] = fadd half [[TMP1]], [[TMP2]]
+// CHECK-NEXT:ret half [[ADD]]
+//
+_Float16 fmax1(half8 a, _Float16 b) {
+  return __builtin_ia32_reduce_fmax_ph128(a) + b;
+}
+
+typedef _Float16 half16 __attribute__((ext_vector_type(16)));
+
+// CHECK-LABEL: @fmin1(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca <16 x half>, align 32
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca half, align 2
+// CHECK-NEXT:store <16 x half> [[A:%.*]], ptr [[A_ADDR]], align 32
+// CHECK-NEXT:store half [[B:%.*]], ptr [[B_ADDR]], align 2
+// CHECK-NEXT:[[TMP0:%.*]] = load <16 x half>, ptr [[A_ADDR]], align 32
+// CHECK-NEXT:[[TMP1:%.*]] = call nnan half @llvm.vector.reduce.fmin.v16f16(<16 x half> [[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = load half, ptr [[B