[PATCH] D110051: [clangd] Deduplicate inlay hints

2021-09-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!

> I don't think we're likely to get a parameter hint and a type hint at the 
> same location, but if you're concerned, I could revise the patch to ignore 
> the hint kind during the comparison.

That's hard call to make, there are probably good arguments for:

- keeping them all
- keeping only one
- dropping them all.

I was just worried about breaking clients. We should probably account for this 
in the spec, as by probably forbidding any intersecting hints completely for a 
better UX (as discussed with @sammccall offline).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110051

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


[clang-tools-extra] d87d1aa - [clangd] Deduplicate inlay hints

2021-09-21 Thread Nathan Ridge via cfe-commits

Author: Nathan Ridge
Date: 2021-09-21T03:23:04-04:00
New Revision: d87d1aa07612116a5c2a660f678856d3bda94f46

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

LOG: [clangd] Deduplicate inlay hints

Duplicates can sometimes appear due to e.g. explicit template
instantiations

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

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/Protocol.cpp
clang-tools-extra/clangd/Protocol.h
clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 167f8001d6e43..73864b7849345 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -366,6 +366,12 @@ std::vector inlayHints(ParsedAST &AST) {
   std::vector Results;
   InlayHintVisitor Visitor(Results, AST);
   Visitor.TraverseAST(AST.getASTContext());
+
+  // De-duplicate hints. Duplicates can sometimes occur due to e.g. explicit
+  // template instantiations.
+  llvm::sort(Results);
+  Results.erase(std::unique(Results.begin(), Results.end()), Results.end());
+
   return Results;
 }
 

diff  --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index c0e96f63952c8..5fa2d21f5df71 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -1326,6 +1326,14 @@ llvm::json::Value toJSON(const InlayHint &H) {
   return llvm::json::Object{
   {"range", H.range}, {"kind", H.kind}, {"label", H.label}};
 }
+bool operator==(const InlayHint &A, const InlayHint &B) {
+  return std::tie(A.kind, A.range, A.label) ==
+ std::tie(B.kind, B.range, B.label);
+}
+bool operator<(const InlayHint &A, const InlayHint &B) {
+  return std::tie(A.kind, A.range, A.label) <
+ std::tie(B.kind, B.range, B.label);
+}
 
 static const char *toString(OffsetEncoding OE) {
   switch (OE) {

diff  --git a/clang-tools-extra/clangd/Protocol.h 
b/clang-tools-extra/clangd/Protocol.h
index cd469c2394072..3a43a48367c05 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -1548,6 +1548,8 @@ struct InlayHint {
   std::string label;
 };
 llvm::json::Value toJSON(const InlayHint &);
+bool operator==(const InlayHint &, const InlayHint &);
+bool operator<(const InlayHint &, const InlayHint &);
 
 struct ReferenceContext {
   /// Include the declaration of the current symbol.

diff  --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index cda2ba41e2648..1c69d504ec6dc 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -612,6 +612,18 @@ TEST(TypeHints, DefaultTemplateArgs) {
   ExpectedHint{": A", "var"});
 }
 
+TEST(TypeHints, Deduplication) {
+  assertTypeHints(R"cpp(
+template 
+void foo() {
+  auto $var[[var]] = 42;
+}
+template void foo();
+template void foo();
+  )cpp",
+  ExpectedHint{": int", "var"});
+}
+
 // FIXME: Low-hanging fruit where we could omit a type hint:
 //  - auto x = TypeName(...);
 //  - auto x = (TypeName) (...);
@@ -625,4 +637,4 @@ TEST(TypeHints, DefaultTemplateArgs) {
 
 } // namespace
 } // namespace clangd
-} // namespace clang
\ No newline at end of file
+} // namespace clang



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


[PATCH] D110051: [clangd] Deduplicate inlay hints

2021-09-21 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd87d1aa07612: [clangd] Deduplicate inlay hints (authored by 
nridge).

Changed prior to commit:
  https://reviews.llvm.org/D110051?vs=373782&id=373790#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110051

Files:
  clang-tools-extra/clangd/InlayHints.cpp
  clang-tools-extra/clangd/Protocol.cpp
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/unittests/InlayHintTests.cpp


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -612,6 +612,18 @@
   ExpectedHint{": A", "var"});
 }
 
+TEST(TypeHints, Deduplication) {
+  assertTypeHints(R"cpp(
+template 
+void foo() {
+  auto $var[[var]] = 42;
+}
+template void foo();
+template void foo();
+  )cpp",
+  ExpectedHint{": int", "var"});
+}
+
 // FIXME: Low-hanging fruit where we could omit a type hint:
 //  - auto x = TypeName(...);
 //  - auto x = (TypeName) (...);
@@ -625,4 +637,4 @@
 
 } // namespace
 } // namespace clangd
-} // namespace clang
\ No newline at end of file
+} // namespace clang
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -1548,6 +1548,8 @@
   std::string label;
 };
 llvm::json::Value toJSON(const InlayHint &);
+bool operator==(const InlayHint &, const InlayHint &);
+bool operator<(const InlayHint &, const InlayHint &);
 
 struct ReferenceContext {
   /// Include the declaration of the current symbol.
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -1326,6 +1326,14 @@
   return llvm::json::Object{
   {"range", H.range}, {"kind", H.kind}, {"label", H.label}};
 }
+bool operator==(const InlayHint &A, const InlayHint &B) {
+  return std::tie(A.kind, A.range, A.label) ==
+ std::tie(B.kind, B.range, B.label);
+}
+bool operator<(const InlayHint &A, const InlayHint &B) {
+  return std::tie(A.kind, A.range, A.label) <
+ std::tie(B.kind, B.range, B.label);
+}
 
 static const char *toString(OffsetEncoding OE) {
   switch (OE) {
Index: clang-tools-extra/clangd/InlayHints.cpp
===
--- clang-tools-extra/clangd/InlayHints.cpp
+++ clang-tools-extra/clangd/InlayHints.cpp
@@ -366,6 +366,12 @@
   std::vector Results;
   InlayHintVisitor Visitor(Results, AST);
   Visitor.TraverseAST(AST.getASTContext());
+
+  // De-duplicate hints. Duplicates can sometimes occur due to e.g. explicit
+  // template instantiations.
+  llvm::sort(Results);
+  Results.erase(std::unique(Results.begin(), Results.end()), Results.end());
+
   return Results;
 }
 


Index: clang-tools-extra/clangd/unittests/InlayHintTests.cpp
===
--- clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -612,6 +612,18 @@
   ExpectedHint{": A", "var"});
 }
 
+TEST(TypeHints, Deduplication) {
+  assertTypeHints(R"cpp(
+template 
+void foo() {
+  auto $var[[var]] = 42;
+}
+template void foo();
+template void foo();
+  )cpp",
+  ExpectedHint{": int", "var"});
+}
+
 // FIXME: Low-hanging fruit where we could omit a type hint:
 //  - auto x = TypeName(...);
 //  - auto x = (TypeName) (...);
@@ -625,4 +637,4 @@
 
 } // namespace
 } // namespace clangd
-} // namespace clang
\ No newline at end of file
+} // namespace clang
Index: clang-tools-extra/clangd/Protocol.h
===
--- clang-tools-extra/clangd/Protocol.h
+++ clang-tools-extra/clangd/Protocol.h
@@ -1548,6 +1548,8 @@
   std::string label;
 };
 llvm::json::Value toJSON(const InlayHint &);
+bool operator==(const InlayHint &, const InlayHint &);
+bool operator<(const InlayHint &, const InlayHint &);
 
 struct ReferenceContext {
   /// Include the declaration of the current symbol.
Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -1326,6 +1326,14 @@
   return llvm::json::Object{
   {"range", H.range}, {"kind", H.kind}, {"label", H.label}};
 }
+bool operator==(const InlayHint &A, const InlayHint &B) {
+  return std::tie(A.kind, A.range, A.label) ==
+ std::tie(B.kind, B.range, B.label);
+}
+bool operator<(const InlayHint &A, const InlayHint &B) {
+  retu

[PATCH] D110130: [clangd] Semantic highlighting for lambda init-capture

2021-09-21 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110130

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -729,6 +729,14 @@
   }
 };
   )cpp",
+  // init-captures
+  R"cpp(
+void $Function_decl[[foo]]() {
+  int $LocalVariable_decl[[a]], $LocalVariable_decl[[b]];
+  [ $LocalVariable_decl[[c]] = $LocalVariable[[a]],
+$LocalVariable_decl[[d]]($LocalVariable[[b]]) ]() {}();
+}
+  )cpp",
   };
   for (const auto &TestCase : TestCases)
 // Mask off scope modifiers to keep the tests manageable.
@@ -797,7 +805,7 @@
   )cpp",
   R"cpp(
 // Lambdas are considered functions, not classes.
-auto $Variable_fileScope[[x]] = [m(42)] { // FIXME: annotate capture
+auto $Variable_fileScope[[x]] = 
[$LocalVariable_functionScope[[m]](42)] {
   return $LocalVariable_functionScope[[m]];
 };
   )cpp",
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -514,13 +514,20 @@
   return true;
 if (auto K = kindForType(AT->getDeducedType().getTypePtrOrNull(),
  H.getResolver())) {
-  auto &Tok = H.addToken(D->getTypeSpecStartLoc(), *K)
-  .addModifier(HighlightingModifier::Deduced);
-  const Type *Deduced = AT->getDeducedType().getTypePtrOrNull();
-  if (auto Mod = scopeModifier(Deduced))
-Tok.addModifier(*Mod);
-  if (isDefaultLibrary(Deduced))
-Tok.addModifier(HighlightingModifier::DefaultLibrary);
+  SourceLocation StartLoc = D->getTypeSpecStartLoc();
+  // The AutoType may not have a corresponding token, e.g. in the case of
+  // init-captures, so there's nothing to color.
+  // Detect this case by checking if the type specifier's location
+  // is the same as the location of the declared name itself.
+  if (StartLoc != D->getLocation()) {
+auto &Tok =
+H.addToken(StartLoc, 
*K).addModifier(HighlightingModifier::Deduced);
+const Type *Deduced = AT->getDeducedType().getTypePtrOrNull();
+if (auto Mod = scopeModifier(Deduced))
+  Tok.addModifier(*Mod);
+if (isDefaultLibrary(Deduced))
+  Tok.addModifier(HighlightingModifier::DefaultLibrary);
+  }
 }
 return true;
   }


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -729,6 +729,14 @@
   }
 };
   )cpp",
+  // init-captures
+  R"cpp(
+void $Function_decl[[foo]]() {
+  int $LocalVariable_decl[[a]], $LocalVariable_decl[[b]];
+  [ $LocalVariable_decl[[c]] = $LocalVariable[[a]],
+$LocalVariable_decl[[d]]($LocalVariable[[b]]) ]() {}();
+}
+  )cpp",
   };
   for (const auto &TestCase : TestCases)
 // Mask off scope modifiers to keep the tests manageable.
@@ -797,7 +805,7 @@
   )cpp",
   R"cpp(
 // Lambdas are considered functions, not classes.
-auto $Variable_fileScope[[x]] = [m(42)] { // FIXME: annotate capture
+auto $Variable_fileScope[[x]] = [$LocalVariable_functionScope[[m]](42)] {
   return $LocalVariable_functionScope[[m]];
 };
   )cpp",
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -514,13 +514,20 @@
   return true;
 if (auto K = kindForType(AT->getDeducedType().getTypePtrOrNull(),
  H.getResolver())) {
-  auto &Tok = H.addToken(D->getTypeSpecStartLoc(), *K)
-  .addModifier(HighlightingModifier::Deduced);
-  const Type *Deduced = AT->getDeducedType().getTypePtrOrNull();
-  if (auto Mod = scopeModifier(Deduced))
-Tok.addModifier(*Mod);
-  if (isDefaultLibrary(Deduced))
-Tok.addModifier(HighlightingModifier::DefaultLibrary);
+  SourceLoca

[PATCH] D110130: [clangd] Semantic highlighting for lambda init-capture

2021-09-21 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:522
+  // is the same as the location of the declared name itself.
+  if (StartLoc != D->getLocation()) {
+auto &Tok =

Note, I initially tried `D->getTypeSpecStartLoc() != D->getTypeSpecEndLoc()`, 
but it turns out they are equal both in the init-capture case and in the 
regular `auto` case, so that check cannot be used to discriminate between the 
two.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110130

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


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 373795.
MyDeveloperDay marked 11 inline comments as done.
MyDeveloperDay added a comment.

Address review comments.

- reorder functions to match header

Fix an overlapping replacement issue when going from Right to Left (just jump 
past the token once done)


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -0,0 +1,829 @@
+//===- unittest/Format/QualifierFixerTest.cpp - Formatting unit tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "FormatTestUtils.h"
+#include "TestLexer.h"
+#include "gtest/gtest.h"
+
+#include "../../lib/Format/QualifierAlignmentFixer.h"
+
+#define DEBUG_TYPE "format-qualifier-fixer-test"
+
+using testing::ScopedTrace;
+
+namespace clang {
+namespace format {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class QualifierFixerTest : public ::testing::Test {
+protected:
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
+
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+
+  std::string format(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(0, Code.size()));
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, Ranges, "", &Status);
+if (CheckComplete != SC_DoNotCheck) {
+  bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
+  EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
+  << Code << "\n\n";
+}
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style));
+if (Style.Language == FormatStyle::LK_Cpp) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+_verifyFormat(File, Line, Code, test::messUp(Code), Style);
+  }
+
+  void _verifyIncompleteFormat(const char *File, int Line, llvm::StringRef Code,
+  

[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 373802.
MyDeveloperDay added a comment.

Allow the use of "TypenameMacros" to allow for Capitialized types (be aware 
they should be non pointer types and don't have to be macros, so may need its 
own future "NonPtrTypes" setting)


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -0,0 +1,846 @@
+//===- unittest/Format/QualifierFixerTest.cpp - Formatting unit tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "FormatTestUtils.h"
+#include "TestLexer.h"
+#include "gtest/gtest.h"
+
+#include "../../lib/Format/QualifierAlignmentFixer.h"
+
+#define DEBUG_TYPE "format-qualifier-fixer-test"
+
+using testing::ScopedTrace;
+
+namespace clang {
+namespace format {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class QualifierFixerTest : public ::testing::Test {
+protected:
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
+
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+
+  std::string format(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(0, Code.size()));
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, Ranges, "", &Status);
+if (CheckComplete != SC_DoNotCheck) {
+  bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
+  EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
+  << Code << "\n\n";
+}
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style));
+if (Style.Language == FormatStyle::LK_Cpp) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+_verifyFormat(File, Line, Code, test::messUp(Code), Style);
+  }
+
+  void _verifyIncompleteFormat(const char *File, int Line, llvm::StringRef Code,
+   const FormatStyle &Style = 

[PATCH] D109951: [clang-format] Constructor initializer lists format with pp directives

2021-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

mark the comments as done once addressed please


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109951

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


[PATCH] D109557: Adds a BreakBeforeClosingParen option

2021-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

This seems ok, might be worth adding a release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109557

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


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:28
+
+static void replaceToken(const SourceManager &SourceMgr,
+ tooling::Replacements &Fixes,

HazardyKnusperkeks wrote:
> Out of curiosity, on what premise do you choose a static member function that 
> is only used in this file or a local free function? I would always choose the 
> latter (with an anon namespace), to keep the header smaller.
I've been pulled up on using anon namespaces before in previous reviews, 
personally I always use them myself in my code. To be honest I've been moving 
most of these functions into actual class statics functions so I can test the 
functions explicitly in the unit tests (anon namespaces aren't good for that 
obvs)

I'd like to leave them as statics so I can more easily do that move and add 
more tests if I find issues. 



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:57
+
+  std::string NewText = " " + Qualifier + " ";
+  NewText += Next->TokenText;

HazardyKnusperkeks wrote:
> Does not need to be addressed here, but does LLVM have a string builder or 
> so? This produces a lot of (de-)allocations.
I'm not a massive fan of this either, but I'm unsure if LLVM has anything, I 
think getting functional first is important, we can go for fast if someone can 
point out a better pattern.



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:129
+
+bool LeftRightQualifierAlignmentFixer::isQualifierOrType(
+const FormatToken *Tok) {

HazardyKnusperkeks wrote:
> I would prefer to match the order of functions in the header with the order 
> in the cpp.
I can spin that around, (its going to mess with review comments, but I know 
what you mean)



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:347
+   QualifierToken);
+  else if (Alignment == FormatStyle::QAS_Left)
+Tok = analyzeLeft(SourceMgr, Keywords, Fixes, Tok, Qualifier,

HazardyKnusperkeks wrote:
> Only else and assert? It does nothing if Alignment is something different, or?
You know this was my bad because I reused the alignment type  because it had 
the left and right but this could be a boolean  as its different from the 
QualifierAlignment, let me change this for clarity



Comment at: clang/lib/Format/QualifierAlignmentFixer.cpp:366
+  // Split the Order list by type and reverse the left side
+  bool left = true;
+  for (const auto &s : Order) {

HazardyKnusperkeks wrote:
> Couldn't you just
> ```
> LeftOrder.assign(std::reverse_iterator(type) /*maybe with a next or prev, 
> haven't thought too much about it*/, Order.rend());
> RightOrder.assign(std::next(type), Order.end());
> ```
> ?
There is probably a better way but it needs to handle "type" being the first or 
last element, I tried and it didn't quite work.



Comment at: clang/lib/Format/QualifierAlignmentFixer.h:24
+
+typedef std::function(
+const Environment &)>

HazardyKnusperkeks wrote:
> I don't know what the LLVM style is on that, but I prefer `using` anytime 
> over `typedef`.
I was actually just following what is in Format.cpp



Comment at: clang/lib/Format/QualifierAlignmentFixer.h:30
+  // Left to Right ordering requires multiple passes
+  SmallVector Passes;
+  StringRef &Code;

HazardyKnusperkeks wrote:
> Has the 8 some meaning? Then maybe give it a name. Or is it just coincidence 
> that you repeat the 8 for QualifierTokens?
For SmallVector this is basically a "ShortStringOptimization" for vector i.e. 
its stack allocated until the vector goes over 8, I have 7 qualifiers, and I 
wanted it an order of 2 so hence 8 (its shouldn't grow (and heap allocation) 
unless we define more qualifier types (this only supports what I say for now)

I think the use of a literal is quite common in this case, its really just a 
hint, I think its ok to use without it being a variable.


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

https://reviews.llvm.org/D69764

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


[PATCH] D109023: libclang: Document the soname change in the release notes

2021-09-21 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru closed this revision.
sylvestre.ledru added a comment.

it landed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109023

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


[PATCH] D109967: Simplify handling of builtin with inline redefinition

2021-09-21 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 373801.
serge-sans-paille added a comment.
Herald added a subscriber: whisperity.

Update formatting / extra comments

Update test to be more explicit about their intent / run them through 
update_cc_test_checks


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

https://reviews.llvm.org/D109967

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/memcpy-inline-builtin.c
  clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.c
  clang/test/CodeGen/memcpy-nobuiltin.c
  clang/test/CodeGen/pr9614.c
  clang/tools/scan-build-py/lib/libscanbuild/analyze.py

Index: clang/tools/scan-build-py/lib/libscanbuild/analyze.py
===
--- clang/tools/scan-build-py/lib/libscanbuild/analyze.py
+++ clang/tools/scan-build-py/lib/libscanbuild/analyze.py
@@ -39,7 +39,7 @@
 
 __all__ = ['scan_build', 'analyze_build', 'analyze_compiler_wrapper']
 
-scanbuild_dir = os.path.dirname(__import__('sys').argv[0])
+scanbuild_dir = os.path.dirname(os.path.realpath(__import__('sys').argv[0]))
 
 COMPILER_WRAPPER_CC = os.path.join(scanbuild_dir, '..', 'libexec', 'analyze-cc')
 COMPILER_WRAPPER_CXX = os.path.join(scanbuild_dir, '..', 'libexec', 'analyze-c++')
Index: clang/test/CodeGen/pr9614.c
===
--- clang/test/CodeGen/pr9614.c
+++ clang/test/CodeGen/pr9614.c
@@ -32,14 +32,14 @@
 
 // CHECK-LABEL: define{{.*}} void @f()
 // CHECK: call void @foo()
-// CHECK: call i32 @abs(i32 0)
+// CHECK: call i32 @abs(i32 %0)
 // CHECK: call i8* @strrchr(
 // CHECK: call void @llvm.prefetch.p0i8(
 // CHECK: call i8* @memchr(
 // CHECK: ret void
 
 // CHECK: declare void @foo()
-// CHECK: declare i32 @abs(i32
 // CHECK: declare i8* @strrchr(i8*, i32)
 // CHECK: declare i8* @memchr(
+// CHECK: declare i32 @abs(i32
 // CHECK: declare void @llvm.prefetch.p0i8(
Index: clang/test/CodeGen/memcpy-nobuiltin.c
===
--- clang/test/CodeGen/memcpy-nobuiltin.c
+++ clang/test/CodeGen/memcpy-nobuiltin.c
@@ -4,7 +4,8 @@
 //
 // CHECK-WITH-DECL-NOT: @llvm.memcpy
 // CHECK-NO-DECL: @llvm.memcpy
-// CHECK-SELF-REF-DECL: @llvm.memcpy
+// CHECK-SELF-REF-DECL-LABEL: define dso_local i8* @memcpy.inline
+// CHECK-SELF-REF-DECL:   @memcpy(
 //
 #include 
 void test(void *dest, void const *from, size_t n) {
Index: clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.c
===
--- clang/test/CodeGen/memcpy-no-nobuiltin-if-not-emitted.c
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - %s | FileCheck %s
-//
-// Verifies that clang doesn't mark an inline builtin definition as `nobuiltin`
-// if the builtin isn't emittable.
-
-typedef unsigned long size_t;
-
-// always_inline is used so clang will emit this body. Otherwise, we need >=
-// -O1.
-#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) \
-__attribute__((gnu_inline))
-
-AVAILABLE_EXTERNALLY void *memcpy(void *a, const void *b, size_t c) {
-  return __builtin_memcpy(a, b, c);
-}
-
-// CHECK-LABEL: define{{.*}} void @foo
-void foo(void *a, const void *b, size_t c) {
-  // Clang will always _emit_ this as memcpy. LLVM turns it into @llvm.memcpy
-  // later on if optimizations are enabled.
-  // CHECK: call i8* @memcpy
-  memcpy(a, b, c);
-}
-
-// CHECK-NOT: nobuiltin
Index: clang/test/CodeGen/memcpy-inline-builtin.c
===
--- /dev/null
+++ clang/test/CodeGen/memcpy-inline-builtin.c
@@ -0,0 +1,44 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - %s | FileCheck %s
+//
+// Verifies that clang detects memcpy inline version and uses it instead of the builtin.
+
+typedef unsigned long size_t;
+
+// Clang requires these attributes for a function to be redefined.
+#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) __attribute__((gnu_inline))
+
+// Clang recognizes an inline builtin and renames it to prevent conflict with builtins.
+AVAILABLE_EXTERNALLY void *memcpy(void *a, const void *b, size_t c) {
+  asm("# memcpy.inline marker");
+  return __builtin_memcpy(a, b, c);
+}
+
+// CHECK-LABEL: @foo(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[A_ADDR_I:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[B_ADDR_I:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[C_ADDR_I:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[A_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[B_ADDR:%.*]] = alloca i8*, align 8
+// CHECK-NEXT:[[C_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store i8* [[A:%.*]], i8** [[A_ADDR]], align 8
+// CHECK-NEXT:store i8* [[B:%.*]], i8** [[B_ADDR]], align 8
+// CHECK-NEXT:store i64

[PATCH] D53014: Add CMAKE_BUILD_TYPE to the list of BOOTSTRAP_DEFAULT_PASSTHROUGH variables

2021-09-21 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru updated this revision to Diff 373804.
sylvestre.ledru added a comment.
Herald added a project: clang.

Rebase of the patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53014

Files:
  clang/CMakeLists.txt


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -706,6 +706,7 @@
 CMAKE_CXX_COMPILER_LAUNCHER
 CMAKE_MAKE_PROGRAM
 CMAKE_OSX_ARCHITECTURES
+CMAKE_BUILD_TYPE
 LLVM_ENABLE_PROJECTS
 LLVM_ENABLE_RUNTIMES)
 


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -706,6 +706,7 @@
 CMAKE_CXX_COMPILER_LAUNCHER
 CMAKE_MAKE_PROGRAM
 CMAKE_OSX_ARCHITECTURES
+CMAKE_BUILD_TYPE
 LLVM_ENABLE_PROJECTS
 LLVM_ENABLE_RUNTIMES)
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] eccd477 - Add CMAKE_BUILD_TYPE to the list of BOOTSTRAP_DEFAULT_PASSTHROUGH variables

2021-09-21 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2021-09-21T10:44:08+02:00
New Revision: eccd477ce312c54e317876ca714c661325f3e318

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

LOG: Add CMAKE_BUILD_TYPE to the list of BOOTSTRAP_DEFAULT_PASSTHROUGH variables

When building clang in stage2, when -DCMAKE_BUILD_TYPE=RelWithDebInfo is set,
the developer can expect that the stage2 clang is built using the same mode.
Especially as the performances are much worst in debug mode.
(Principle of least astonishment)

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

Added: 


Modified: 
clang/CMakeLists.txt

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 29ceef8a4bd38..6e18e74c6294c 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -706,6 +706,7 @@ if (CLANG_ENABLE_BOOTSTRAP)
 CMAKE_CXX_COMPILER_LAUNCHER
 CMAKE_MAKE_PROGRAM
 CMAKE_OSX_ARCHITECTURES
+CMAKE_BUILD_TYPE
 LLVM_ENABLE_PROJECTS
 LLVM_ENABLE_RUNTIMES)
 



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


[PATCH] D53014: Add CMAKE_BUILD_TYPE to the list of BOOTSTRAP_DEFAULT_PASSTHROUGH variables

2021-09-21 Thread Sylvestre Ledru 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 rGeccd477ce312: Add CMAKE_BUILD_TYPE to the list of 
BOOTSTRAP_DEFAULT_PASSTHROUGH variables (authored by sylvestre.ledru).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53014

Files:
  clang/CMakeLists.txt


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -706,6 +706,7 @@
 CMAKE_CXX_COMPILER_LAUNCHER
 CMAKE_MAKE_PROGRAM
 CMAKE_OSX_ARCHITECTURES
+CMAKE_BUILD_TYPE
 LLVM_ENABLE_PROJECTS
 LLVM_ENABLE_RUNTIMES)
 


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -706,6 +706,7 @@
 CMAKE_CXX_COMPILER_LAUNCHER
 CMAKE_MAKE_PROGRAM
 CMAKE_OSX_ARCHITECTURES
+CMAKE_BUILD_TYPE
 LLVM_ENABLE_PROJECTS
 LLVM_ENABLE_RUNTIMES)
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109642: -Wunused-but-set-parameter/-Wunused-but-set-variable Add to the release notes

2021-09-21 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

it landed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109642

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


[PATCH] D109642: -Wunused-but-set-parameter/-Wunused-but-set-variable Add to the release notes

2021-09-21 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru abandoned this revision.
sylvestre.ledru added a comment.

https://github.com/llvm/llvm-project/blob/release/13.x/clang/docs/ReleaseNotes.rst#new-compiler-flags


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109642

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


[PATCH] D109967: Simplify handling of builtin with inline redefinition

2021-09-21 Thread serge via Phabricator via cfe-commits
serge-sans-paille marked 6 inline comments as done.
serge-sans-paille added inline comments.



Comment at: clang/test/CodeGen/memcpy-inline-builtin.c:1
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -emit-llvm -o - %s 
-disable-llvm-passes | FileCheck %s
+//

nickdesaulniers wrote:
> nickdesaulniers wrote:
> > Would `-emit-codegen-only` be more appropriate here than 
> > `-disable-llvm-passes`?
> No; but I don't think we need `-disable-llvm-passes` since we haven't 
> explicitly enabled additional optimization modes via `-O` flags? ie. I 
> suspect if we drop `-disable-llvm-passes` then nothing changes?
`-disable-llvm-passes` was tehre to disable the always inliner. I used another 
approach to keep merker from the inlined function and keep the test easy to 
review.



Comment at: clang/test/CodeGen/memcpy-inline-builtin.c:7
+
+// always_inline is used so clang will emit this body. Otherwise, we need >= 
-O1.
+#define AVAILABLE_EXTERNALLY extern inline __attribute__((always_inline)) \

nickdesaulniers wrote:
> I'm not sure what `this` refers to in the comment?
> 
> Also, this whole bit about `always_inline` smells fishy to me.  The semantics 
> of `gnu_inline` is that no body is emitted.  If you //don't// want a body 
> //don't// use `gnu_inline`.  Or was this set of qualifiers+fn attrs taken 
> directly from the kernel, or glibc?  
> `FunctionDecl::isInlineBuiltinDeclaration` only checks for builtin ID, has 
> body, and whether inline was specified.
Comment updated. Basically these attributes are needed for a function to be 
considered by clang as redfinable, which is the case here. these attributes are 
extensively used in glibc headers for that purpose.



Comment at: clang/test/CodeGen/pr9614.c:44
 // CHECK: declare i8* @memchr(
+// CHECK: declare i32 @abs(i32
 // CHECK: declare void @llvm.prefetch.p0i8(

nickdesaulniers wrote:
> Can you elaborate on these changes? Surprising.
Before the patch, the redefined version of bas was ignored as the function is a 
trivially recursive redefinition. Thanks to current patch, the redefinition is 
correctly detected, renamed and inlined (the always inliner still runs here)


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

https://reviews.llvm.org/D109967

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


[PATCH] D109608: [clang][ASTImporter] Generic attribute import handling (first step).

2021-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
Herald added a subscriber: rnkovacs.

Look good! Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109608

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


[clang] 57b8b5c - [OpenCL] Test case for C++ for OpenCL 2021 in OpenCL C header test

2021-09-21 Thread Justas Janickas via cfe-commits

Author: Justas Janickas
Date: 2021-09-21T10:27:46+01:00
New Revision: 57b8b5c114b6e595f8d9118807d741ef30518777

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

LOG: [OpenCL] Test case for C++ for OpenCL 2021 in OpenCL C header test

RUN line representing C++ for OpenCL 2021 added to the test. This
should have been done as part of earlier commit fb321c2ea274 but
was missed during rebasing.

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

Added: 


Modified: 
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index d300803f86fbb..bcce9623fafcb 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -1,8 +1,9 @@
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1 
| FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2 
| FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++ 
| FileCheck %s --check-prefix=CHECK20
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify 
-cl-std=clc++1.0 | FileCheck %s --check-prefix=CHECK20
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL3.0 
| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify 
-cl-std=clc++2021 | FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -57,7 +58,7 @@
 // CHECK20: _Z16convert_char_rtec
 char f(char x) {
 // Check functionality from OpenCL 2.0 onwards
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
+#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
   ndrange_t t;
   x = ctz(x);
 #endif //__OPENCL_C_VERSION__
@@ -82,7 +83,7 @@ void test_atomics(__generic volatile unsigned int* a) {
 #endif
 
 // Verify that ATOMIC_VAR_INIT is defined.
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
+#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
 global atomic_int z = ATOMIC_VAR_INIT(99);
 #endif //__OPENCL_C_VERSION__
 // CHECK-MOD: Reading modules



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


[PATCH] D109492: [OpenCL] Test case for C++ for OpenCL 2021 in OpenCL C header test

2021-09-21 Thread Justas Janickas 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 rG57b8b5c114b6: [OpenCL] Test case for C++ for OpenCL 2021 in 
OpenCL C header test (authored by Topotuna).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109492

Files:
  clang/test/Headers/opencl-c-header.cl


Index: clang/test/Headers/opencl-c-header.cl
===
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -1,8 +1,9 @@
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1 
| FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2 
| FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++ 
| FileCheck %s --check-prefix=CHECK20
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify 
-cl-std=clc++1.0 | FileCheck %s --check-prefix=CHECK20
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL3.0 
| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify 
-cl-std=clc++2021 | FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -57,7 +58,7 @@
 // CHECK20: _Z16convert_char_rtec
 char f(char x) {
 // Check functionality from OpenCL 2.0 onwards
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
+#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
   ndrange_t t;
   x = ctz(x);
 #endif //__OPENCL_C_VERSION__
@@ -82,7 +83,7 @@
 #endif
 
 // Verify that ATOMIC_VAR_INIT is defined.
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
+#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
 global atomic_int z = ATOMIC_VAR_INIT(99);
 #endif //__OPENCL_C_VERSION__
 // CHECK-MOD: Reading modules


Index: clang/test/Headers/opencl-c-header.cl
===
--- clang/test/Headers/opencl-c-header.cl
+++ clang/test/Headers/opencl-c-header.cl
@@ -1,8 +1,9 @@
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1 | FileCheck %s
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2 | FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++ | FileCheck %s --check-prefix=CHECK20
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++1.0 | FileCheck %s --check-prefix=CHECK20
 // RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL3.0 | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=clc++2021 | FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -57,7 +58,7 @@
 // CHECK20: _Z16convert_char_rtec
 char f(char x) {
 // Check functionality from OpenCL 2.0 onwards
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
+#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
   ndrange_t t;
   x = ctz(x);
 #endif //__OPENCL_C_VERSION__
@@ -82,7 +83,7 @@
 #endif
 
 // Verify that ATOMIC_VAR_INIT is defined.
-#if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
+#if (__OPENCL_CPP_VERSION__ == 100) || (__OPENCL_C_VERSION__ == CL_VERSION_2_0)
 global atomic_int z = ATOMIC_VAR_INIT(99);
 #endif //__OPENCL_C_VERSION__
 // CHECK-MOD: Reading modules
___
cfe-commits mailing list
cfe-commits@lists.llvm.o

[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 373817.
MyDeveloperDay added a comment.

If we don't specify types in the QualifierOrder (say static or inline as in 
default Left/Right) then don't push const through them just because they can be 
a type of qualifier we support.

i.e. only push through what we specify, ultimately this helps reduce the number 
of changes (caused by inline/static) being in different orders (perhaps 
unintentional) but where you don't care (i.e. you haven't specified them)


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -0,0 +1,885 @@
+//===- unittest/Format/QualifierFixerTest.cpp - Formatting unit tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "FormatTestUtils.h"
+#include "TestLexer.h"
+#include "gtest/gtest.h"
+
+#include "../../lib/Format/QualifierAlignmentFixer.h"
+
+#define DEBUG_TYPE "format-qualifier-fixer-test"
+
+using testing::ScopedTrace;
+
+namespace clang {
+namespace format {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class QualifierFixerTest : public ::testing::Test {
+protected:
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
+
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+
+  std::string format(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(0, Code.size()));
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, Ranges, "", &Status);
+if (CheckComplete != SC_DoNotCheck) {
+  bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
+  EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
+  << Code << "\n\n";
+}
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style));
+if (Style.Language == FormatStyle::LK_Cpp) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = ge

[PATCH] D109874: [OpenCL] Defines helper function for OpenCL default address space

2021-09-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/include/clang/AST/ASTContext.h:1366
+  /// Returns default address space based on OpenCL version and enabled 
features
+  inline LangAS getDefaultOpenCLAddrSpace() {
+return LangOpts.OpenCLGenericAddressSpace ? LangAS::opencl_generic

We should probably rename this to `getDefaultPointeeOpenCLAddrSpace` because 
this only reflects the default address space for the pointer types.



Comment at: clang/lib/AST/Expr.cpp:3782
 // since it cannot be assigned to a pointer to constant address space.
-if ((Ctx.getLangOpts().OpenCLVersion >= 200 &&
- Pointee.getAddressSpace() == LangAS::opencl_generic) ||
-(Ctx.getLangOpts().OpenCL &&
- Ctx.getLangOpts().OpenCLVersion < 200 &&
- Pointee.getAddressSpace() == LangAS::opencl_private))
+if (Pointee.getAddressSpace() == Ctx.getDefaultOpenCLAddrSpace())
   Qs.removeAddressSpace();

Let's add `Ctx.getLangOpts().OpenCL` check at the start to make sure this only 
runs for OpenCL.


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

https://reviews.llvm.org/D109874

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


[PATCH] D109818: [HIPSPV] Convert HIP kernels to SPIR-V kernels

2021-09-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:10221
+ABIArgInfo SPIRABIInfo::classifyKernelArgumentType(QualType Ty) const {
+  if (getContext().getLangOpts().HIP && getTarget().getTriple().isSPIRV()) {
+// Coerce pointer arguments with default address space to CrossWorkGroup

It feels like this needs to be in `SPIRVABIInfo`  or something? Or can this be 
generalized to both  - SPIR and SPIR-V?



Comment at: clang/lib/CodeGen/TargetInfo.cpp:10224
+// pointers for HIPSPV. When the language mode is HIP, the SPIRTargetInfo
+// maps cuda_device to SPIR-V's CrossWorkGroup address space.
+llvm::Type *LTy = CGT.ConvertType(Ty);

Can you explain why this mapping is needed? We already have an address space 
map to perform the mapping of address spaces b/w language and target. It would 
be good if we don't replicate similar logic in too many places.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:10271
+  if (getABIInfo().getContext().getLangOpts().HIP &&
+  getABIInfo().getTarget().getTriple().isSPIRV()) {
+FT = getABIInfo().getContext().adjustFunctionType(

Again this feels like we need `SPIRVTargetCodeGenInfo` unless the logic is 
generalizable to both. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109818

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


[PATCH] D110142: [clang][Driver] Correct runtime path for Arm hard float targets

2021-09-21 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett created this revision.
Herald added a subscriber: kristof.beyls.
DavidSpickett requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

On armv8l and arm (armv7) the architecture in the library
path will be "armhf" if we have hard float enabled.

This fixes failures like:
https://lab.llvm.org/buildbot/#/builders/178/builds/591

Where we can't find the libraries since
https://reviews.llvm.org/D107799 landed.

Before:
$ ./bin/clang --target=armv8l-unknown-linux-gnueabihf -print-runtime-dir
<...>/build-llvm-arm/lib/clang/14.0.0/lib/linux

After:
$ ./bin/clang --target=armv8l-unknown-linux-gnueabihf -print-runtime-dir
<...>/build-llvm-arm/lib/clang/14.0.0/lib/armhf-unknown-linux-gnueabihf


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110142

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp


Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -75,7 +75,7 @@
  const ArgList &Args)
 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
   CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
-  std::string RuntimePath = getRuntimePath();
+  std::string RuntimePath = getRuntimePath(Args);
   if (getVFS().exists(RuntimePath))
 getLibraryPaths().push_back(RuntimePath);
 
@@ -487,9 +487,13 @@
   return Args.MakeArgString(getCompilerRT(Args, Component, Type));
 }
 
-std::string ToolChain::getRuntimePath() const {
+std::string ToolChain::getRuntimePath(const llvm::opt::ArgList &Args) const {
+  llvm::Triple triple = getTriple();
+  RegisterEffectiveTriple TripleRAII(*this, triple);
+  auto arch_name = getArchNameForCompilerRTLib(*this, Args);
+  triple.setArchName(arch_name);
   SmallString<128> P(D.ResourceDir);
-  llvm::sys::path::append(P, "lib", getTripleString());
+  llvm::sys::path::append(P, "lib", triple.getTriple());
   return std::string(P.str());
 }
 
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1830,7 +1830,7 @@
   }
 
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
-std::string CandidateRuntimePath = TC.getRuntimePath();
+std::string CandidateRuntimePath = TC.getRuntimePath(C.getArgs());
 if (getVFS().exists(CandidateRuntimePath))
   llvm::outs() << CandidateRuntimePath << '\n';
 else
Index: clang/include/clang/Driver/ToolChain.h
===
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -446,7 +446,7 @@
 FileType Type = ToolChain::FT_Static) 
const;
 
   // Returns target specific runtime path if it exists.
-  virtual std::string getRuntimePath() const;
+  virtual std::string getRuntimePath(const llvm::opt::ArgList &Args) const;
 
   // Returns target specific standard library path if it exists.
   virtual std::string getStdlibPath() const;


Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -75,7 +75,7 @@
  const ArgList &Args)
 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
   CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
-  std::string RuntimePath = getRuntimePath();
+  std::string RuntimePath = getRuntimePath(Args);
   if (getVFS().exists(RuntimePath))
 getLibraryPaths().push_back(RuntimePath);
 
@@ -487,9 +487,13 @@
   return Args.MakeArgString(getCompilerRT(Args, Component, Type));
 }
 
-std::string ToolChain::getRuntimePath() const {
+std::string ToolChain::getRuntimePath(const llvm::opt::ArgList &Args) const {
+  llvm::Triple triple = getTriple();
+  RegisterEffectiveTriple TripleRAII(*this, triple);
+  auto arch_name = getArchNameForCompilerRTLib(*this, Args);
+  triple.setArchName(arch_name);
   SmallString<128> P(D.ResourceDir);
-  llvm::sys::path::append(P, "lib", getTripleString());
+  llvm::sys::path::append(P, "lib", triple.getTriple());
   return std::string(P.str());
 }
 
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1830,7 +1830,7 @@
   }
 
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
-std::string CandidateRuntimePath = TC.getRuntimePath();
+std::string CandidateRuntimePath = TC.getRuntimePath(C.getArgs());
 if (getVFS().exists(CandidateRuntimePath))
   llvm::outs() << CandidateRuntimePath << '\n';
 else
Index: clang/include/clang/Driver/ToolChain.h
===
-

[PATCH] D110142: [clang][Driver] Correct runtime path for Arm hard float targets

2021-09-21 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a reviewer: MaskRay.
DavidSpickett added a comment.

`getRuntimePath` seems like the place to fix it given that 
https://reviews.llvm.org/D50547 calls it. This fixes the tests but I'm not sure 
if there's other places to consider.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110142

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


[PATCH] D110142: [clang][Driver] Correct runtime path for Arm hard float targets

2021-09-21 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

I should probably *add* a test somewhere for this too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110142

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


[PATCH] D109874: [OpenCL] Defines helper function for OpenCL default address space

2021-09-21 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna updated this revision to Diff 373834.
Topotuna edited the summary of this revision.
Topotuna added a comment.

Helper function renamed for clarity. Additional check added to `if` statement 
to ensure it is only carried out in OpenCL.


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

https://reviews.llvm.org/D109874

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2092,9 +2092,7 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
- ? LangAS::opencl_generic
- : LangAS::opencl_private);
+PointeeType, S.getASTContext().getDefaultPointeeOpenCLAddrSpace());
   return PointeeType;
 }
 
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3894,8 +3894,9 @@
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
 Arg->isLValue()) {
-  if (S.getLangOpts().OpenCL  && !ArgType.hasAddressSpace())
-ArgType = S.Context.getAddrSpaceQualType(ArgType, 
LangAS::opencl_generic);
+  if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace())
+ArgType = S.Context.getAddrSpaceQualType(
+ArgType, S.Context.getDefaultPointeeOpenCLAddrSpace());
   ArgType = S.Context.getLValueReferenceType(ArgType);
 }
   } else {
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1430,7 +1430,7 @@
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
   if (getLangOpts().OpenCL)
-return LangAS::opencl_generic;
+return getASTContext().getDefaultPointeeOpenCLAddrSpace();
   return LangAS::Default;
 }
 
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -3779,11 +3779,8 @@
 // has non-default address space it is not treated as nullptr.
 // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr
 // since it cannot be assigned to a pointer to constant address space.
-if ((Ctx.getLangOpts().OpenCLVersion >= 200 &&
- Pointee.getAddressSpace() == LangAS::opencl_generic) ||
-(Ctx.getLangOpts().OpenCL &&
- Ctx.getLangOpts().OpenCLVersion < 200 &&
- Pointee.getAddressSpace() == LangAS::opencl_private))
+if (Ctx.getLangOpts().OpenCL &&
+Pointee.getAddressSpace() == 
Ctx.getDefaultPointeeOpenCLAddrSpace())
   Qs.removeAddressSpace();
 
 if (Pointee->isVoidType() && Qs.empty() && // to void*
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -1362,6 +1362,12 @@
   /// Get address space for OpenCL type.
   LangAS getOpenCLTypeAddrSpace(const Type *T) const;
 
+  /// Returns default address space based on OpenCL version and enabled 
features
+  inline LangAS getDefaultPointeeOpenCLAddrSpace() {
+return LangOpts.OpenCLGenericAddressSpace ? LangAS::opencl_generic
+  : LangAS::opencl_private;
+  }
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
 cudaConfigureCallDecl = FD;
   }


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2092,9 +2092,7 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
- ? LangAS::opencl_generic
- : LangAS::opencl_private);
+PointeeType, S.getASTContext().getDefaultPointeeOpenCLAddrSpace());
   return PointeeType;
 }
 
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3894,8 +3894,9 @@
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
 Arg->isLValue()) {
-  if (S.getLangOpts().OpenCL  && !

[PATCH] D109874: [OpenCL] Defines helper function for OpenCL default address space

2021-09-21 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna marked 2 inline comments as done.
Topotuna added a comment.

Both comments addressed. Personally, I would shuffle words around to rename 
helper function as `getDefaultOpenCLPointeeAddrSpace` or 
`getOpenCLDefaultPointeeAddrSpace`. Although I am not sure if there are some 
assumed naming conventions in Clang. Originally, I was following the name of 
`getDefaultCXXMethodAddrSpace`.


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

https://reviews.llvm.org/D109874

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


[PATCH] D109865: [NFC] `goto fail` has failed us in the past...

2021-09-21 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

Looks good, thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109865

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


[PATCH] D108621: [HIPSPV] Add CUDA->SPIR-V address space mapping

2021-09-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/Basic/Targets/SPIR.h:59
+// translation). This mapping is enabled when the language mode is HIP.
+1, // cuda_device
+// cuda_constant pointer can be casted to default/"flat" pointer, but in

linjamaki wrote:
> bader wrote:
> > keryell wrote:
> > > Anastasia wrote:
> > > > bader wrote:
> > > > > Anastasia wrote:
> > > > > > I am slightly confused as in the LLVM project those address spaces 
> > > > > > are for SPIR not SPIR-V though. It is however used outside of LLVM 
> > > > > > project by some tools like SPIRV-LLVM Translator as a path to 
> > > > > > SPIR-V, but it has only been done as a workaround since we had no 
> > > > > > SPIR-V support in the LLVM project yet. And if we are adding it 
> > > > > > let's do it clean to avoid/resolve any confusion.
> > > > > > 
> > > > > > I think we need to keep both because some vendors do target/use 
> > > > > > SPIR but not SPIR-V.
> > > > > > 
> > > > > > So if you are interested in SPIR-V and not SPIR you should probably 
> > > > > > add a new target that will make things cleaner.
> > > > > > I think we need to keep both because some vendors do target/use 
> > > > > > SPIR but not SPIR-V.
> > > > > 
> > > > > @Anastasia, could you elaborate more on the difference between SPIR 
> > > > > and SPIR-V?
> > > > > I would like to understand what these terms mean in the context of 
> > > > > LLVM project.
> > > > Their conceptual differences are just that they are two different 
> > > > intermediate formats.
> > > > 
> > > > The important thing to highlight is that it is not impossible that some 
> > > > vendors use SPIR (without using SPIR-V) even despite the fact it has 
> > > > been discontinued by Khronos. 
> > > > 
> > > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > > > Their conceptual differences are just that they are two different 
> > > > intermediate formats.
> > > > 
> > > > The important thing to highlight is that it is not impossible that some 
> > > > vendors use SPIR (without using SPIR-V) even despite the fact it has 
> > > > been discontinued by Khronos. 
> > > > 
> > > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > > 
> > > All the official Xilinx OpenCL stack is based on legacy SPIR (encoded in 
> > > LLVM 6.x IR but this is another story) and I suspect this is the case for 
> > > other companies.
> > > So, do not deprecate or discontinue, please. :-)
> > > The important thing to highlight is that it is not impossible that some 
> > > vendors use SPIR (without using SPIR-V) even despite the fact it has been 
> > > discontinued by Khronos.
> > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > 
> > Strictly speaking `SPIR` is not defined as an intermediate language. 
> > Khronos defines `SPIR-1.2` and `SPIR-2.0` formats which are based on LLVM 
> > 3.2 and LLVM 3.4 version (https://www.khronos.org/spir/). There is no 
> > definition of SPIR format based on current version of LLVM IR. Another note 
> > is that metadata and intrinsics emitted for OpenCL with clang-14 doesn't 
> > follow neither `SPIR-1.2` nor `SPIR-2.0`.
> > 
> > I always think of LLVM IR as leaving thing that is subject to change by 
> > LLVM community, so tools working with LLVM IR must adjust to the particular 
> > version (e.g. release version like LLVM 13 or ToT). We apply this logic to 
> > SPIRV-LLVM-Translator tool and update it according to LLVM format changes 
> > (e.g. kernel argument information defined in Khronos spec must be named 
> > metadata whereas clang emits function metadata).
> > 
> > > I am slightly confused as in the LLVM project those address spaces are 
> > > for SPIR not SPIR-V though.
> > [skip]
> > > Their conceptual differences are just that they are two different 
> > > intermediate formats.
> > 
> > If this is the only difference, I don't think it a good idea to create 
> > another LLVM target to separate SPIR and SPIR-V. From my point of view it 
> > creates logic ambiguity and code duplication with no additional value. 
> > @Anastasia, what problems do you see if we continue treating LLVM IR with 
> > spir* target triple as LLVM IR representation of SPIR-V format?
> The state of SPIR 1.2/2.0 in Clang seems to be that the SPIR target has 
> transformed to mean “SPIR 1.2/2.0 derivative”, but that does not still make 
> it SPIR-V, which is not based on LLVM IR. When one is targeting spir* there 
> is ambiguity on whether one is aiming to produce the old-SPIR-derivative or 
> SPIR-V. Considering that there are still SPIR-derivative consumers, in my 
> opinion we should have separate LLVM targets for SPIR-V to have explicit 
> disambiguation of intent for producing the SPIR-derivative vs SPIR-V.
@bader, if you would like to migrate SPIR into SPIR-V properly then we should 
at least rename it. I would certainly prefer triple SPIR-V to SPIR which 
eliminates the need to explain wh

[PATCH] D109874: [OpenCL] Defines helper function for OpenCL default address space

2021-09-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D109874#3011792 , @Topotuna wrote:

> Both comments addressed. Personally, I would shuffle words around to rename 
> helper function as `getDefaultOpenCLPointeeAddrSpace` or 
> `getOpenCLDefaultPointeeAddrSpace`. Although I am not sure if there are some 
> assumed naming conventions in Clang. Originally, I was following the name of 
> `getDefaultCXXMethodAddrSpace`.

I agree this naming scheme makes more sense.


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

https://reviews.llvm.org/D109874

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


[PATCH] D109874: [OpenCL] Defines helper function for OpenCL default address space

2021-09-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks

Feel free to adjust the naming scheme either in the same commit or separately.


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

https://reviews.llvm.org/D109874

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


[PATCH] D108359: [clang][NFC] Fix needless double-parenthisation

2021-09-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108359

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


[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-21 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1696
+  const llvm::APSInt &Idx = CI->getValue();
+  const uint64_t I = static_cast(Idx.getExtValue());
+  // Use `getZExtValue` because array extent can not be negative.

ASDenysPetrov wrote:
> martong wrote:
> > aaron.ballman wrote:
> > > 
> > This `static_cast` seems to be dangerous to me, it might overflow. Can't we 
> > compare `Idx` directly to `Extent`? I see that `Idx` is an `APSint` and 
> > `Extent` is an `APInt`, but  I think we should be able to handle the 
> > comparison on the APInt level b/c that takes care of the signedness. And 
> > the overflow situation should be handled as well properly with `APInt`, 
> > given from it's name "arbitrary precision int". In this sense I don't see 
> > why do we need `I` at all.
> We can't get rid of `I` because we use it below anyway in `I >= 
> InitList->getNumInits()` and `InitList->getInit(I)`.
> I couldn't find any appropriate function to compare without additional 
> checking for signedness or bit-width adjusting.
> I'll try to improve this snippet.
This is not dangerous because we check for negatives separately in `Idx < 0`, 
so we can be sure that `I` is positive while `I >= Extent`. Unfortunately, I 
didn't find any suitable way to compare `APSint` //of unknown sign and 
bitwidth// with //signless// `APInt` without adding another checks for sign and 
bitwidth conversions. In this way I prefer the currect condition `I >= Extent`.


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

https://reviews.llvm.org/D104285

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


[PATCH] D110142: [clang][Driver] Correct runtime path for Arm hard float targets

2021-09-21 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett updated this revision to Diff 373854.
DavidSpickett added a comment.

Added a test.

I have not checked what adding an -mfloat-abi that doesn't
match the ABI part of the triple does because then
we'd need to modify the ABI part of the triple as well.

Which might be the correct thing to do in the end but I'll wait
and see what people think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110142

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  
clang/test/Driver/Inputs/arm_float_abi_runtime_path/lib/arm-pc-windows-msvc/.keep
  
clang/test/Driver/Inputs/arm_float_abi_runtime_path/lib/arm-unknown-linux-gnueabi/.keep
  
clang/test/Driver/Inputs/arm_float_abi_runtime_path/lib/armhf-unknown-linux-gnueabihf/.keep
  clang/test/Driver/arm-float-abi-runtime-path.c


Index: clang/test/Driver/arm-float-abi-runtime-path.c
===
--- /dev/null
+++ clang/test/Driver/arm-float-abi-runtime-path.c
@@ -0,0 +1,25 @@
+// REQUIRES: arm-registered-target
+
+// RUN: %clang %s -target armv8l-unknown-linux-gnueabihf -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | 
FileCheck -check-prefix=ARMHF %s
+// RUN: %clang %s -target arm-unknown-linux-gnueabihf -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | 
FileCheck -check-prefix=ARMHF %s
+// RUN: %clang %s -target armv7-unknown-linux-gnueabihf -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | 
FileCheck -check-prefix=ARMHF %s
+
+// RUN: %clang %s -target armv8l-unknown-linux-gnueabi -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | 
FileCheck -check-prefix=ARM %s
+// RUN: %clang %s -target arm-unknown-linux-gnueabi -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | 
FileCheck -check-prefix=ARM %s
+// RUN: %clang %s -target armv7-unknown-linux-gnueabi -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | 
FileCheck -check-prefix=ARM %s
+
+// RUN: %clang %s -target arm-pc-windows-msvc -print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | 
FileCheck -check-prefix=WINDOWS %s
+/// armhf-pc... isn't recognised so just check that the float-abi option is 
ignored
+// RUN: %clang %s -target arm-pc-windows-msvc -mfloat-abi=hard 
-print-runtime-dir \
+// RUN:-resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | 
FileCheck -check-prefix=WINDOWS %s
+
+// ARMHF:   lib{{/|\\}}armhf-unknown-linux-gnueabihf{{$}}
+// ARM: lib{{/|\\}}arm-unknown-linux-gnueabi{{$}}
+// WINDOWS: lib{{/|\\}}arm-pc-windows-msvc{{$}}
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -75,7 +75,7 @@
  const ArgList &Args)
 : D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
   CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
-  std::string RuntimePath = getRuntimePath();
+  std::string RuntimePath = getRuntimePath(Args);
   if (getVFS().exists(RuntimePath))
 getLibraryPaths().push_back(RuntimePath);
 
@@ -487,9 +487,13 @@
   return Args.MakeArgString(getCompilerRT(Args, Component, Type));
 }
 
-std::string ToolChain::getRuntimePath() const {
+std::string ToolChain::getRuntimePath(const llvm::opt::ArgList &Args) const {
+  llvm::Triple triple = getTriple();
+  RegisterEffectiveTriple TripleRAII(*this, triple);
+  auto arch_name = getArchNameForCompilerRTLib(*this, Args);
+  triple.setArchName(arch_name);
   SmallString<128> P(D.ResourceDir);
-  llvm::sys::path::append(P, "lib", getTripleString());
+  llvm::sys::path::append(P, "lib", triple.getTriple());
   return std::string(P.str());
 }
 
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1830,7 +1830,7 @@
   }
 
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
-std::string CandidateRuntimePath = TC.getRuntimePath();
+std::string CandidateRuntimePath = TC.getRuntimePath(C.getArgs());
 if (getVFS().exists(CandidateRuntimePath))
   llvm::outs() << CandidateRuntimePath << '\n';
 else
Index: clang/include/clang/Driver/ToolChain.h
===
--- clang/include/clang/Driver/ToolChain.h
+++ clang/include/clang/Driver/ToolChain.h
@@ -446,7 +446,7 @@
 FileType Type = ToolChain::FT_Static) 
const;
 
   // Returns target specific runtime path if it exists.
-  virtual std::string getRuntimePath() const;
+  virtual std::s

[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-09-21 Thread Ilya Kuteev via Phabricator via cfe-commits
ilyakuteev updated this revision to Diff 373859.

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

https://reviews.llvm.org/D106876

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-mobile-map.m
  clang/test/SemaCXX/Inputs/compare.modulemap
  clang/test/SemaCXX/compare-modules-cxx2a.cpp

Index: clang/test/SemaCXX/compare-modules-cxx2a.cpp
===
--- clang/test/SemaCXX/compare-modules-cxx2a.cpp
+++ clang/test/SemaCXX/compare-modules-cxx2a.cpp
@@ -1,15 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -verify -std=c++2a -fmodules -I%S/Inputs %s -fno-modules-error-recovery
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
 
-#pragma clang module build compare
-module compare {
-  explicit module cmp {}
-  explicit module other {}
-}
-#pragma clang module contents
-#pragma clang module begin compare.cmp
-#include "std-compare.h"
-#pragma clang module end
-#pragma clang module endbuild
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -verify -std=c++2a -fmodules -fmodules-cache-path=%t.mcp -I%S/Inputs %s -fno-modules-error-recovery -fmodule-map-file=%S/Inputs/compare.modulemap
 
 struct CC { CC(...); };
 
@@ -24,10 +16,10 @@
 
 // expected-note@std-compare.h:* 2+{{not reachable}}
 
-void b() { void(0 <=> 0); } // expected-error 1+{{missing '#include "std-compare.h"'; 'strong_ordering' must be defined}}
+void b() { void(0 <=> 0); } // expected-error 1+{{definition of 'strong_ordering' must be imported from module 'compare.cmp' before it is required}}
 
 struct B {
-  CC operator<=>(const B&) const = default; // expected-error 1+{{missing '#include "std-compare.h"'; 'strong_ordering' must be defined}}
+  CC operator<=>(const B&) const = default; // expected-error 1+{{definition of 'strong_ordering' must be imported from module 'compare.cmp' before it is required}}
 };
 auto vb = B() <=> B(); // expected-note {{required here}}
 
Index: clang/test/SemaCXX/Inputs/compare.modulemap
===
--- /dev/null
+++ clang/test/SemaCXX/Inputs/compare.modulemap
@@ -0,0 +1,6 @@
+module compare {
+  explicit module cmp {
+header "std-compare.h"
+  }
+  explicit module other {}
+}
Index: clang/test/Modules/add-remove-irrelevant-mobile-map.m
===
--- /dev/null
+++ clang/test/Modules/add-remove-irrelevant-mobile-map.m
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
+
+// Build without b.modulemap
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
+// RUN: cp %t.mcp/a.pcm %t/a.pcm
+
+// Build with b.modulemap
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
+// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+
+// expected-no-diagnostics
+
+@import a;
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
@@ -0,0 +1 @@
+module b { }
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
@@ -0,0 +1 @@
+module a { }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -149,6 +149,60 @@
 
 namespace {
 
+std::set GetAllModuleMaps(const HeaderSearch &HS,
+ Module *RootModule) {
+  std::set ModuleMaps{};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
+
+  SmallVector FilesByUID;
+  HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
+
+  if (FilesByUID.size() > HS.header_file_size())
+FilesByUID.resize(HS.header_file_size());
+
+  for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
+const FileEntry *File = FilesByUID[UID];
+if (!File)
+  continue;
+
+const HeaderFileInfo *HFI =
+HS.getExistingFileInfo(File, /*WantExternal*/ false);
+if (!HFI)
+  continue;
+
+const auto KnownHeaders = HS.findAllModulesForHeader(File);
+for (const auto &KH : KnownHeaders) {
+  if (!KH.getModule())
+con

[PATCH] D110044: Print nullptr_t namespace qualified within std::

2021-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: clang/lib/AST/Type.cpp:3045
   case NullPtr:
-return "nullptr_t";
+return "std::nullptr_t";
   case Overload:

dblaikie wrote:
> aaron.ballman wrote:
> > Should this be `::std::nullptr_t` to differentiate it from odd things like:
> > ```
> > namespace my {
> > namespace std {
> > class nullptr_t {};
> > }
> > }
> > ```
> I was hoping not to get overly pedantic - I think clang omits the global 
> namespace scope when naming other types in namespaces?
> 
> Yeah:
> ```
> scope.cpp:5:5: error: invalid operands to binary expression ('int' and 
> 'ns::inner')
>   1 + ns::inner();
>   ~ ^ ~~~
> ```
> 
> So this seems consistent with that, at least. That's true also when rendering 
> template parameter type names, etc, so far as I know.
Okay, I'm sold, thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110044

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


[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-09-21 Thread Ilya Kuteev via Phabricator via cfe-commits
ilyakuteev updated this revision to Diff 373861.

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

https://reviews.llvm.org/D106876

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-mobile-map.m
  clang/test/SemaCXX/Inputs/compare.modulemap

Index: clang/test/Modules/add-remove-irrelevant-mobile-map.m
===
--- /dev/null
+++ clang/test/Modules/add-remove-irrelevant-mobile-map.m
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
+
+// Build without b.modulemap
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
+// RUN: cp %t.mcp/a.pcm %t/a.pcm
+
+// Build with b.modulemap
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
+// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+
+// expected-no-diagnostics
+
+@import a;
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
@@ -0,0 +1 @@
+module b { }
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
@@ -0,0 +1 @@
+module a { }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -149,6 +149,60 @@
 
 namespace {
 
+std::set GetAllModuleMaps(const HeaderSearch &HS,
+ Module *RootModule) {
+  std::set ModuleMaps{};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
+
+  SmallVector FilesByUID;
+  HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
+
+  if (FilesByUID.size() > HS.header_file_size())
+FilesByUID.resize(HS.header_file_size());
+
+  for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
+const FileEntry *File = FilesByUID[UID];
+if (!File)
+  continue;
+
+const HeaderFileInfo *HFI =
+HS.getExistingFileInfo(File, /*WantExternal*/ false);
+if (!HFI)
+  continue;
+
+const auto KnownHeaders = HS.findAllModulesForHeader(File);
+for (const auto &KH : KnownHeaders) {
+  if (!KH.getModule())
+continue;
+  ModulesToProcess.push_back(KH.getModule());
+}
+  }
+
+  while (!ModulesToProcess.empty()) {
+auto *CurrentModule = ModulesToProcess.pop_back_val();
+ProcessedModules.insert(CurrentModule);
+
+auto *ModuleMapFile =
+HS.getModuleMap().getModuleMapFileForUniquing(CurrentModule);
+if (!ModuleMapFile) {
+  continue;
+}
+
+ModuleMaps.insert(ModuleMapFile);
+
+for (auto *ImportedModule : (CurrentModule)->Imports) {
+  if (!ImportedModule ||
+  ProcessedModules.find(ImportedModule) != ProcessedModules.end()) {
+continue;
+  }
+  ModulesToProcess.push_back(ImportedModule);
+}
+  }
+
+  return ModuleMaps;
+}
+
 class ASTTypeWriter {
   ASTWriter &Writer;
   ASTWriter::RecordData Record;
@@ -1396,9 +1450,15 @@
 Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir);
   }
 
+  std::set AffectingModuleMaps;
+  if (WritingModule) {
+AffectingModuleMaps =
+GetAllModuleMaps(PP.getHeaderSearchInfo(), WritingModule);
+  }
+
   WriteInputFiles(Context.SourceMgr,
   PP.getHeaderSearchInfo().getHeaderSearchOpts(),
-  PP.getLangOpts().Modules);
+  AffectingModuleMaps);
   Stream.ExitBlock();
 }
 
@@ -1416,9 +1476,9 @@
 
 } // namespace
 
-void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
-HeaderSearchOptions &HSOpts,
-bool Modules) {
+void ASTWriter::WriteInputFiles(
+SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
+std::set &AffectingModuleMaps) {
   using namespace llvm;
 
   Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4);
@@ -1458,6 +1518,19 @@
 if (!Cache->OrigEntry)
   continue;
 
+if (isModuleMap(File.getFileCharacteristic()) &&
+!isSystem(File.getFileCharacteristic()) &&
+!AffectingModuleMaps.empty() &&
+std::find_if(AffectingModuleMaps.begin(), AffectingModuleMaps.end(),
+ [&](const auto &

[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-09-21 Thread Ilya Kuteev via Phabricator via cfe-commits
ilyakuteev updated this revision to Diff 373862.

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

https://reviews.llvm.org/D106876

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-mobile-map.m

Index: clang/test/Modules/add-remove-irrelevant-mobile-map.m
===
--- /dev/null
+++ clang/test/Modules/add-remove-irrelevant-mobile-map.m
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
+
+// Build without b.modulemap
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
+// RUN: cp %t.mcp/a.pcm %t/a.pcm
+
+// Build with b.modulemap
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
+// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+
+// expected-no-diagnostics
+
+@import a;
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
@@ -0,0 +1 @@
+module b { }
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
@@ -0,0 +1 @@
+module a { }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -149,6 +149,60 @@
 
 namespace {
 
+std::set GetAllModuleMaps(const HeaderSearch &HS,
+ Module *RootModule) {
+  std::set ModuleMaps{};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
+
+  SmallVector FilesByUID;
+  HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
+
+  if (FilesByUID.size() > HS.header_file_size())
+FilesByUID.resize(HS.header_file_size());
+
+  for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
+const FileEntry *File = FilesByUID[UID];
+if (!File)
+  continue;
+
+const HeaderFileInfo *HFI =
+HS.getExistingFileInfo(File, /*WantExternal*/ false);
+if (!HFI)
+  continue;
+
+const auto KnownHeaders = HS.findAllModulesForHeader(File);
+for (const auto &KH : KnownHeaders) {
+  if (!KH.getModule())
+continue;
+  ModulesToProcess.push_back(KH.getModule());
+}
+  }
+
+  while (!ModulesToProcess.empty()) {
+auto *CurrentModule = ModulesToProcess.pop_back_val();
+ProcessedModules.insert(CurrentModule);
+
+auto *ModuleMapFile =
+HS.getModuleMap().getModuleMapFileForUniquing(CurrentModule);
+if (!ModuleMapFile) {
+  continue;
+}
+
+ModuleMaps.insert(ModuleMapFile);
+
+for (auto *ImportedModule : (CurrentModule)->Imports) {
+  if (!ImportedModule ||
+  ProcessedModules.find(ImportedModule) != ProcessedModules.end()) {
+continue;
+  }
+  ModulesToProcess.push_back(ImportedModule);
+}
+  }
+
+  return ModuleMaps;
+}
+
 class ASTTypeWriter {
   ASTWriter &Writer;
   ASTWriter::RecordData Record;
@@ -1396,9 +1450,15 @@
 Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir);
   }
 
+  std::set AffectingModuleMaps;
+  if (WritingModule) {
+AffectingModuleMaps =
+GetAllModuleMaps(PP.getHeaderSearchInfo(), WritingModule);
+  }
+
   WriteInputFiles(Context.SourceMgr,
   PP.getHeaderSearchInfo().getHeaderSearchOpts(),
-  PP.getLangOpts().Modules);
+  AffectingModuleMaps);
   Stream.ExitBlock();
 }
 
@@ -1416,9 +1476,9 @@
 
 } // namespace
 
-void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
-HeaderSearchOptions &HSOpts,
-bool Modules) {
+void ASTWriter::WriteInputFiles(
+SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
+std::set &AffectingModuleMaps) {
   using namespace llvm;
 
   Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4);
@@ -1458,6 +1518,19 @@
 if (!Cache->OrigEntry)
   continue;
 
+if (isModuleMap(File.getFileCharacteristic()) &&
+!isSystem(File.getFileCharacteristic()) &&
+!AffectingModuleMaps.empty() &&
+std::find_if(AffectingModuleMaps.begin(), AffectingModuleMaps.end(),
+ [&](const auto &FE) {
+   return F

[PATCH] D110155: [OpenCL] Allow optional __generic in __remove_address_space utility

2021-09-21 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna created this revision.
Topotuna added a reviewer: Anastasia.
Herald added subscribers: ldrumm, yaxunl.
Topotuna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang builtin utility `__remove_address_space` now works if generic
address space is not supported in C++ for OpenCL 2021.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110155

Files:
  clang/lib/Headers/opencl-c-base.h
  clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp


Index: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
===
--- clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
+++ clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins 
-finclude-default-header
+// RUN: %clang_cc1 %s -cl-std=clc++1.0 -fdeclare-opencl-builtins 
-finclude-default-header
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -fdeclare-opencl-builtins 
-finclude-default-header
+// RUN: %clang_cc1 %s -cl-std=clc++2021 
-cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes 
-fdeclare-opencl-builtins -finclude-default-header
 
 template
 struct is_same {
@@ -19,8 +21,10 @@
 void test_remove_address_space() {
   static_assert(is_same<__remove_address_space::type, int>::value,
 "type without an address space unexpectedly modified by 
__remove_address_space");
+#if defined(__opencl_c_generic_address_space)
   static_assert(is_same<__remove_address_space<__generic int>::type, 
int>::value,
 "__generic address space not removed by 
__remove_address_space");
+#endif
   static_assert(is_same<__remove_address_space<__global char>::type, 
char>::value,
 "__global address space not removed by 
__remove_address_space");
   static_assert(is_same<__remove_address_space<__private ulong>::type, 
ulong>::value,
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -600,9 +600,11 @@
 // C++ for OpenCL - __remove_address_space
 #if defined(__OPENCL_CPP_VERSION__)
 template  struct __remove_address_space { using type = _Tp; };
+#if defined(__opencl_c_generic_address_space)
 template  struct __remove_address_space<__generic _Tp> {
   using type = _Tp;
 };
+#endif
 template  struct __remove_address_space<__global _Tp> {
   using type = _Tp;
 };


Index: clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
===
--- clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
+++ clang/test/CodeGenOpenCLCXX/remove-address-space.clcpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 %s -cl-std=clc++ -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -cl-std=clc++1.0 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -fdeclare-opencl-builtins -finclude-default-header
 
 template
 struct is_same {
@@ -19,8 +21,10 @@
 void test_remove_address_space() {
   static_assert(is_same<__remove_address_space::type, int>::value,
 "type without an address space unexpectedly modified by __remove_address_space");
+#if defined(__opencl_c_generic_address_space)
   static_assert(is_same<__remove_address_space<__generic int>::type, int>::value,
 "__generic address space not removed by __remove_address_space");
+#endif
   static_assert(is_same<__remove_address_space<__global char>::type, char>::value,
 "__global address space not removed by __remove_address_space");
   static_assert(is_same<__remove_address_space<__private ulong>::type, ulong>::value,
Index: clang/lib/Headers/opencl-c-base.h
===
--- clang/lib/Headers/opencl-c-base.h
+++ clang/lib/Headers/opencl-c-base.h
@@ -600,9 +600,11 @@
 // C++ for OpenCL - __remove_address_space
 #if defined(__OPENCL_CPP_VERSION__)
 template  struct __remove_address_space { using type = _Tp; };
+#if defined(__opencl_c_generic_address_space)
 template  struct __remove_address_space<__generic _Tp> {
   using type = _Tp;
 };
+#endif
 template  struct __remove_address_space<__global _Tp> {
   using type = _Tp;
 };
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108560: [clang-tidy] Add support for NOLINTBEGIN ... NOLINTEND comments to suppress clang-tidy warnings over multiple lines

2021-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thanks, I think this is getting close! There are two more test cases that I 
think are interesting (and should cause any issues, hopefully):

  // NOLINTEND
  // CHECK-MESSAGES: for diagnostic on the previous line

and

  // CHECK-MESSAGES: for diagnostic on the subsequent line
  // NOLINTBEGIN

as the only contents in the file. The idea is that we want to check that 
searching for a "begin" when seeing an "end" at the top of the file doesn't do 
anything silly like try to read off the start of the file, and similar for 
"end" when seeing a "begin" at the end of a file.




Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:208
+  SourceManager &SM = DiagEngine->getSourceManager();
+  auto File = SM.getFileManager().getFile(Error.Message.FilePath);
+  FileID ID = SM.getOrCreateFileID(*File, SrcMgr::C_User);

This helps the reader of the code to understand that `*File` below is doing 
something special (that includes an assert check, which is great).



Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:367
+   Context.getCurrentBuildDirectory(), false);
+  Error.Message = tooling::DiagnosticMessage("mismatched pair of NOLINTBEGIN/"
+ "NOLINTEND comments",

This message works, but I think it'd be better if we split it into two messages:

`unmatched 'NOLINTBEGIN' comment without a subsequent 'NOLINTEND' comment`
`unmatched 'NOLINTEND' comment without a previous 'NOLINTBEGIN' comment`



Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:381-387
+// Check if a new block is being started.
+if (isNOLINTFound("NOLINTBEGIN", CheckName, Line, &NolintIndex)) {
+  NolintBegins.emplace_back(LinesLoc.getLocWithOffset(NolintIndex));
+}
+// Check if the previous block is being closed.
+else if (isNOLINTFound("NOLINTEND", CheckName, Line, &NolintIndex)) {
+  if (!NolintBegins.empty()) {





Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:390
+  } else {
+// Trying to close a non-existant block. Return a diagnostic about this
+// misuse that can be displayed along with the original clang-tidy 
check





Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:509-510
   bool AllowIO) {
+  std::vector Unused;
+  return shouldSuppressDiagnostic(DiagLevel, Info, Context, Unused, AllowIO);
+}

Should we assert that `Unused` is empty before returning?



Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h:237
   const Diagnostic &Info, ClangTidyContext 
&Context,
+  std::vector &SuppressionErrors,
   bool AllowIO = true);

Might be better as a `SmallVectorImpl` as this should almost always be a 
container of 0 or 1 elements.



Comment at: 
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-without-end.cpp:6-8
+// Note: the expected output has been split over several lines so that 
clang-tidy
+//   does not see the "no lint" suppression comment and mistakenly assume 
it
+//   is meant for itself.

THANK YOU for these comments! :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108560

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


[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1692-1694
+const bool IsOneDimensionalArray =
+!isa(CAT->getElementType());
+if (IsOneDimensionalArray) {

ASDenysPetrov wrote:
> martong wrote:
> > aaron.ballman wrote:
> > > 
> > +1 for Aaron's suggestion, but then it would be really helpful to have an 
> > explanatory comment. E.g.:
> > ```
> > if (!isa(CAT->getElementType())) { // This is a one 
> > dimensional array.
> > ```
> I think that self-descriptive code is better than comments nearby. And it 
> does not affect anything in terms of performance.
FWIW, I found the condensed form more readable (I don't have to wonder what's 
going to care about that variable later in the function with lots of nesting).


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

https://reviews.llvm.org/D104285

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


[PATCH] D110160: [clang][tooling] NFC: Refactor command-line diagnostic tests

2021-09-21 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: Bigcheese, dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch uses a different command-line arguments to test 
`clang::tooling::ToolInvocation` in order to simplify downstream integration.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110160

Files:
  clang/unittests/Tooling/ToolingTest.cpp

Index: clang/unittests/Tooling/ToolingTest.cpp
===
--- clang/unittests/Tooling/ToolingTest.cpp
+++ clang/unittests/Tooling/ToolingTest.cpp
@@ -15,6 +15,7 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
 #include "clang/Tooling/ArgumentsAdjusters.h"
 #include "clang/Tooling/CompilationDatabase.h"
 #include "clang/Tooling/Tooling.h"
@@ -224,16 +225,6 @@
   EXPECT_TRUE(Invocation.run());
 }
 
-struct ErrorCountingDiagnosticConsumer : public DiagnosticConsumer {
-  ErrorCountingDiagnosticConsumer() : NumErrorsSeen(0) {}
-  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
-const Diagnostic &Info) override {
-if (DiagLevel == DiagnosticsEngine::Level::Error)
-  ++NumErrorsSeen;
-  }
-  unsigned NumErrorsSeen;
-};
-
 TEST(ToolInvocation, DiagnosticsEngineProperlyInitializedForCC1Construction) {
   llvm::IntrusiveRefCntPtr OverlayFileSystem(
   new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
@@ -245,24 +236,23 @@
 
   std::vector Args;
   Args.push_back("tool-executable");
-  Args.push_back("-target");
-  // Invalid argument that by default results in an error diagnostic:
-  Args.push_back("i386-apple-ios14.0-simulator");
-  // Argument that downgrades the error into a warning:
-  Args.push_back("-Wno-error=invalid-ios-deployment-target");
+  // Invalid argument (non-existent sysroot path) that will result in a warning.
+  Args.push_back("-isysroot");
+  Args.push_back("/dev/null/sysroot");
+  // Argument that will suppress the warning above.
+  Args.push_back("-Wno-missing-sysroot");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
 
   clang::tooling::ToolInvocation Invocation(
   Args, std::make_unique(), Files.get());
   InMemoryFileSystem->addFile(
-  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int a() {}\n"));
-  ErrorCountingDiagnosticConsumer Consumer;
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void a() {}\n"));
+  TextDiagnosticBuffer Consumer;
   Invocation.setDiagnosticConsumer(&Consumer);
   EXPECT_TRUE(Invocation.run());
-  // Check that `-Wno-error=invalid-ios-deployment-target` downgraded the error
-  // into a warning.
-  EXPECT_EQ(Consumer.NumErrorsSeen, 0u);
+  // Check that the warning was ignored due to `-Wno-missing-sysroot`.
+  EXPECT_EQ(std::distance(Consumer.warn_begin(), Consumer.warn_end()), 0u);
 }
 
 TEST(ToolInvocation, CustomDiagnosticOptionsOverwriteParsedOnes) {
@@ -276,28 +266,29 @@
 
   std::vector Args;
   Args.push_back("tool-executable");
-  Args.push_back("-target");
-  // Invalid argument that by default results in an error diagnostic:
-  Args.push_back("i386-apple-ios14.0-simulator");
-  // Argument that downgrades the error into a warning:
-  Args.push_back("-Wno-error=invalid-ios-deployment-target");
+  // Invalid argument (non-existent sysroot path) that will result in a warning.
+  Args.push_back("-isysroot");
+  Args.push_back("/dev/null/sysroot");
+  // Argument that will suppress the warning above.
+  Args.push_back("-Wno-missing-sysroot");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
 
   clang::tooling::ToolInvocation Invocation(
   Args, std::make_unique(), Files.get());
   InMemoryFileSystem->addFile(
-  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("int a() {}\n"));
-  ErrorCountingDiagnosticConsumer Consumer;
+  "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("void a() {}\n"));
+  TextDiagnosticBuffer Consumer;
   Invocation.setDiagnosticConsumer(&Consumer);
 
+  // Inject custom `DiagnosticOptions` for command-line parsing.
   auto DiagOpts = llvm::makeIntrusiveRefCnt();
   Invocation.setDiagnosticOptions(&*DiagOpts);
 
   EXPECT_TRUE(Invocation.run());
-  // Check that `-Wno-error=invalid-ios-deployment-target` didn't downgrade the
-  // error into a warning due to being overwritten by custom diagnostic options.
-  EXPECT_EQ(Consumer.NumErrorsSeen, 1u);
+  // Check that the warning was issued during command-line parsing due to the
+  // custom `DiagnosticOptions` without `-Wno-missing-sysroot`.
+  EXPECT_EQ(std::distance(Consumer.warn_begin(), Consumer.warn_end()), 1u);
 }
 
 struct DiagnosticConsumerExpectingSourceManager : public DiagnosticConsumer {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https

[PATCH] D109557: Adds a BreakBeforeClosingParen option

2021-09-21 Thread Cameron Mulhern via Phabricator via cfe-commits
csmulhern updated this revision to Diff 373877.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109557

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/ContinuationIndenter.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -18242,6 +18242,7 @@
   CHECK_PARSE_BOOL(BinPackArguments);
   CHECK_PARSE_BOOL(BinPackParameters);
   CHECK_PARSE_BOOL(BreakAfterJavaFieldAnnotations);
+  CHECK_PARSE_BOOL(BreakBeforeClosingParen);
   CHECK_PARSE_BOOL(BreakBeforeConceptDeclarations);
   CHECK_PARSE_BOOL(BreakBeforeTernaryOperators);
   CHECK_PARSE_BOOL(BreakStringLiterals);
@@ -22294,6 +22295,162 @@
   "}";
   EXPECT_EQ(Code, format(Code, Style));
 }
+
+TEST_F(FormatTest, BreakBeforeClosingParen) {
+  auto Style = getLLVMStyle();
+
+  StringRef Short = "functionCall(paramA, paramB, paramC);\n"
+"void functionDecl(int a, int b, int c);";
+
+  StringRef Medium = "functionCall(paramA, paramB, paramC, paramD, paramE, "
+ "paramF, paramG, paramH, paramI);\n"
+ "void functionDecl(int argumentA, int argumentB, int "
+ "argumentC, int argumentD, int argumentE);";
+
+  verifyFormat(Short, Style);
+
+  StringRef NoBreak = "functionCall(paramA, paramB, paramC, paramD, paramE, "
+  "paramF, paramG, paramH,\n"
+  " paramI);\n"
+  "void functionDecl(int argumentA, int argumentB, int "
+  "argumentC, int argumentD,\n"
+  "  int argumentE);";
+
+  verifyFormat(NoBreak, Medium, Style);
+  verifyFormat(NoBreak,
+   "functionCall(\n"
+   "paramA,\n"
+   "paramB,\n"
+   "paramC,\n"
+   "paramD,\n"
+   "paramE,\n"
+   "paramF,\n"
+   "paramG,\n"
+   "paramH,\n"
+   "paramI\n"
+   ");\n"
+   "void functionDecl(\n"
+   "int argumentA,\n"
+   "int argumentB,\n"
+   "int argumentC,\n"
+   "int argumentD,\n"
+   "int argumentE\n"
+   ");",
+   Style);
+
+  verifyFormat("outerFunctionCall(nestedFunctionCall(argument1),\n"
+   "  nestedLongFunctionCall(argument1, "
+   "argument2, argument3,\n"
+   " argument4, "
+   "argument5));",
+   Style);
+
+  Style.BreakBeforeClosingParen = true;
+
+  verifyFormat(Short, Style);
+  verifyFormat(NoBreak, Medium, Style);
+
+  Style.AllowAllArgumentsOnNextLine = false;
+  Style.AllowAllConstructorInitializersOnNextLine = false;
+  Style.AllowAllParametersOfDeclarationOnNextLine = false;
+
+  verifyFormat(Short, Style);
+  verifyFormat(NoBreak, Medium, Style);
+
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+
+  verifyFormat(Short, Style);
+  verifyFormat(
+  "functionCall(\n"
+  "paramA, paramB, paramC, paramD, paramE, paramF, paramG, paramH, "
+  "paramI\n"
+  ");\n"
+  "void functionDecl(\n"
+  "int argumentA, int argumentB, int argumentC, int argumentD, int "
+  "argumentE\n"
+  ");",
+  Medium, Style);
+
+  Style.BinPackArguments = false;
+  Style.BinPackParameters = false;
+
+  verifyFormat(Short, Style);
+
+  verifyFormat("functionCall(\n"
+   "paramA,\n"
+   "paramB,\n"
+   "paramC,\n"
+   "paramD,\n"
+   "paramE,\n"
+   "paramF,\n"
+   "paramG,\n"
+   "paramH,\n"
+   "paramI\n"
+   ");\n"
+   "void functionDecl(\n"
+   "int argumentA,\n"
+   "int argumentB,\n"
+   "int argumentC,\n"
+   "int argumentD,\n"
+   "int argumentE\n"
+   ");",
+   Medium, Style);
+
+  verifyFormat("outerFunctionCall(\n"
+   "nestedFunctionCall(argument1),\n"
+   "nestedLongFunctionCall(\n"
+   "argument1,\n"
+   "argument2,\n"
+   "argument3,\n"
+   "argument4,\n"
+   "argument5\n"
+   ")\n"
+   ");",
+   Style);
+
+  verifyFormat("int a = (int)b;", Style);
+  ve

[PATCH] D109557: Adds a BreakBeforeClosingParen option

2021-09-21 Thread Cameron Mulhern via Phabricator via cfe-commits
csmulhern added a comment.

In D109557#3011516 , @MyDeveloperDay 
wrote:

> This seems ok, might be worth adding a release note

Done.

I don't have commit access, so please submit this change on my behalf.

Thanks for all the help!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109557

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


[PATCH] D110116: [Clang] Ignore BTFTag attr if used as a type attribute

2021-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:8132
 
+case ParsedAttr::AT_BTFTag:
+  // FIXME: Linux kernel may also use this attribute for type casting 
check,

Errr, this attribute isn't a type attribute in the first place, so I'd feel 
more comfortable if this was also modified in Attr.td to be a `DeclOrTypeAttr` 
instead of an `InheritableAttr`.

There should also be a change to AttrDocs.td to explain what's going on.



Comment at: clang/test/Sema/attr-btf_tag.c:45
+void __tag1 * convert(long arg) {
+  return (void __tag1 *)arg;
+}

I'd appreciate a FIXME comment here about why this is silently accepted but 
does nothing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110116

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


[PATCH] D109557: Adds a BreakBeforeClosingParen option

2021-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109557

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


[PATCH] D110127: [Clang] Support typedef with btf_tag attributes

2021-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

> First, to build linux kernel with btf_tag annotated user pointer, we have
>
> #define __user __attribute__((btf_tag("user")))
> and the linux kernel contains code like below ([2])
>
> typedef __signalfn_t __user *__sighandler_t;
> and the user attribute applies to typedef type sighandler_t.
> So clang needs to support btf_tag attribute with typedef type
> to avoid compilation error.

I want to make sure we're clear on the semantics here. That defines 
`__sighandler_t` to be the type `__signalfn_t __user *`, so you expect this to 
annotate the type, not the declaration of the typedef. So this is about 
allowing `btf_tag` on types in addition to declarations?

> typedef struct { ... } target_type __btf_tag

Similar here -- this applies the __btf_tag to the type, not to the declaration 
of the typedef, right?

I'm asking because this raises other questions. For example:

  void func(int i);
  void func(int __attribute__((btf_tag("__user"))) i);

Is the second a valid redeclaration of the first? Additionally:

  __attribute__((overloadable)) void func(int i) { puts("one"); }
  __attribute__((overloadable)) void func(int 
__attribute__((btf_tag("__user"))) i) { puts("two"); }

Is this a valid overload set because of the type attribute? Along the same 
lines, does adding this attribute to the type cause any ABI differences in how 
the type is passed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110127

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


[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-21 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1692-1694
+const bool IsOneDimensionalArray =
+!isa(CAT->getElementType());
+if (IsOneDimensionalArray) {

aaron.ballman wrote:
> ASDenysPetrov wrote:
> > martong wrote:
> > > aaron.ballman wrote:
> > > > 
> > > +1 for Aaron's suggestion, but then it would be really helpful to have an 
> > > explanatory comment. E.g.:
> > > ```
> > > if (!isa(CAT->getElementType())) { // This is a one 
> > > dimensional array.
> > > ```
> > I think that self-descriptive code is better than comments nearby. And it 
> > does not affect anything in terms of performance.
> FWIW, I found the condensed form more readable (I don't have to wonder what's 
> going to care about that variable later in the function with lots of nesting).
I see what you mean. That's fair in terms of variables caring. I think it's 
just the other hand of the approach. I don't have strong preferences here, it's 
just my personal flavor because it doesn't need to introspect the expression to 
undersand what it means. But I'll make an update using your proposition.


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

https://reviews.llvm.org/D104285

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


[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1692-1694
+const bool IsOneDimensionalArray =
+!isa(CAT->getElementType());
+if (IsOneDimensionalArray) {

ASDenysPetrov wrote:
> aaron.ballman wrote:
> > ASDenysPetrov wrote:
> > > martong wrote:
> > > > aaron.ballman wrote:
> > > > > 
> > > > +1 for Aaron's suggestion, but then it would be really helpful to have 
> > > > an explanatory comment. E.g.:
> > > > ```
> > > > if (!isa(CAT->getElementType())) { // This is a one 
> > > > dimensional array.
> > > > ```
> > > I think that self-descriptive code is better than comments nearby. And it 
> > > does not affect anything in terms of performance.
> > FWIW, I found the condensed form more readable (I don't have to wonder 
> > what's going to care about that variable later in the function with lots of 
> > nesting).
> I see what you mean. That's fair in terms of variables caring. I think it's 
> just the other hand of the approach. I don't have strong preferences here, 
> it's just my personal flavor because it doesn't need to introspect the 
> expression to undersand what it means. But I'll make an update using your 
> proposition.
FWIW, my preference is weak as well -- the code is readable either way. :-)


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

https://reviews.llvm.org/D104285

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


[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-21 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 373895.
ASDenysPetrov added a comment.

Fixed nits.


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

https://reviews.llvm.org/D104285

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initialization.c
  clang/test/Analysis/initialization.cpp

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++14 -triple i386-apple-darwin10 -analyze -analyzer-checker=core.builtin,debug.ExprInspection -verify %s
+// RUN: %clang_cc1 -std=c++14 -triple i386-apple-darwin10 -analyze -analyzer-config eagerly-assume=false -analyzer-checker=core.uninitialized.Assign,core.builtin,debug.ExprInspection,core.uninitialized.UndefReturn -verify %s
 
 void clang_analyzer_eval(int);
 
@@ -18,3 +18,113 @@
   // FIXME: Should recognize that it is 0.
   clang_analyzer_eval(arr[i][0]); // expected-warning{{UNKNOWN}}
 }
+
+int const glob_arr1[3] = {};
+void glob_array_index1() {
+  clang_analyzer_eval(glob_arr1[0] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr1[1] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr1[2] == 0); // expected-warning{{TRUE}}
+}
+
+void glob_invalid_index1() {
+  const int *ptr = glob_arr1;
+  int idx = -42;
+  auto x = ptr[idx]; // expected-warning{{garbage or undefined}}
+}
+
+int const glob_arr2[4] = {1, 2};
+void glob_ptr_index1() {
+  int const *ptr = glob_arr2;
+  clang_analyzer_eval(ptr[0] == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[4] == 0); // expected-warning{{UNDEFINED}}
+}
+
+void glob_invalid_index2() {
+  const int *ptr = glob_arr2;
+  int idx = 42;
+  auto x = ptr[idx]; // expected-warning{{garbage or undefined}}
+}
+
+const float glob_arr3[] = {
+0., 0.0235, 0.0470, 0.0706, 0.0941, 0.1176};
+float no_warn_garbage_value() {
+  return glob_arr3[0]; // no-warning (garbage or undefined)
+}
+
+// TODO: Support multidimensional array.
+int const glob_arr4[4][2] = {};
+void glob_array_index2() {
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr4[1][0] == 0); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr4[1][1] == 0); // expected-warning{{UNKNOWN}}
+}
+
+// TODO: Support multidimensional array.
+void glob_invalid_index3() {
+  int idx = -42;
+  // FIXME: Should warn {{garbage or undefined}}.
+  auto x = glob_arr4[1][idx]; // no-warning
+}
+
+// TODO: Support multidimensional array.
+void glob_invalid_index4() {
+  const int *ptr = glob_arr4[1];
+  int idx = -42;
+  // FIXME: Should warn {{garbage or undefined}}.
+  auto x = ptr[idx]; // no-warning
+}
+
+// TODO: Support multidimensional array.
+int const glob_arr5[4][2] = {{1}, 3, 4, 5};
+void glob_array_index3() {
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr5[0][0] == 1); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr5[0][1] == 0); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr5[1][0] == 3); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr5[1][1] == 4); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr5[2][0] == 5); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr5[2][1] == 0); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr5[3][0] == 0); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(glob_arr5[3][1] == 0); // expected-warning{{UNKNOWN}}
+}
+
+// TODO: Support multidimensional array.
+void glob_ptr_index2() {
+  int const *ptr = glob_arr5[1];
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(ptr[0] == 3); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be TRUE.
+  clang_analyzer_eval(ptr[1] == 4); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be UNDEFINED.
+  clang_analyzer_eval(ptr[2] == 5); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be UNDEFINED.
+  clang_analyzer_eval(ptr[3] == 0); // expected-warning{{UNKNOWN}}
+  // FIXME: Should be UNDEFINED.
+  clang_analyzer_eval(ptr[4] == 0); // expected-warning{{UNKNOWN}}
+}
+
+// TODO: Support multidimensional array.
+void glob_invalid_index5() {
+  int idx = -42;
+  // FIXME: Should warn {{garbage or undefined}}.
+  auto x = glob_arr5[1][idx]; // no-warning
+}
+
+// TODO: Support multidimensional array.
+void glob_invalid_index6() {
+  int const *ptr = &glob_arr5[1][0];
+  int idx = 42;
+  // FIXME: Should warn {{garbage or undefined}}.
+  auto x = ptr[idx]; // // no-warning
+}
Index: clang/test/Analys

[clang] ee31ad0 - [clang-offload-bundler][docs][NFC] Add archive unbundling documentation

2021-09-21 Thread Saiyedul Islam via cfe-commits

Author: Saiyedul Islam
Date: 2021-09-21T19:24:44+05:30
New Revision: ee31ad0ab5f7d443b0bd582582a3524dcf7f13f0

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

LOG: [clang-offload-bundler][docs][NFC] Add archive unbundling documentation

Add documentation of unbundling of heterogeneous device archives to
create device specific archives, as introduced by D93525. Also, add
documentation for supported text file formats.

Reviewed By: yaxunl

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

Added: 


Modified: 
clang/docs/ClangOffloadBundler.rst

Removed: 




diff  --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index a0e446f766eea..312c45602c991 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -30,9 +30,62 @@ includes an ``init`` function that will use the runtime 
corresponding to the
 offload kind (see :ref:`clang-offload-kind-table`) to load the offload code
 objects appropriate to the devices present when the host program is executed.
 
+Supported File Formats
+==
+Several text and binary file formats are supported for bundling/unbundling. See
+:ref:`supported-file-formats-table` for a list of currently supported formats.
+
+  .. table:: Supported File Formats
+ :name: supported-file-formats-table
+
+ +++-+
+ | File Format| File Extension | Text/Binary |
+ +++=+
+ | CPP output |i   | Text|
+ +++-+
+ | C++ CPP output |   ii   | Text|
+ +++-+
+ | CUDA/HIP output|   cui  | Text|
+ +++-+
+ | Dependency |d   | Text|
+ +++-+
+ | LLVM   |   ll   | Text|
+ +++-+
+ | LLVM Bitcode   |   bc   |Binary   |
+ +++-+
+ | Assembler  |s   | Text|
+ +++-+
+ | Object |o   |Binary   |
+ +++-+
+ | Archive of objects |a   |Binary   |
+ +++-+
+ | Precompiled header |   gch  |Binary   |
+ +++-+
+ | Clang AST file |   ast  |Binary   |
+ +++-+
+
+.. _clang-bundled-code-object-layout-text:
+
+Bundled Text File Layout
+
+
+The format of the bundled files is currently very simple: text formats are
+concatenated with comments that have a magic string and bundle entry ID in
+between.
+
+::
+
+  "Comment OFFLOAD_BUNDLER_MAGIC_STR__START__ 1st Bundle Entry ID"
+  Bundle 1
+  "Comment OFFLOAD_BUNDLER_MAGIC_STR__END__ 1st Bundle Entry ID"
+  ...
+  "Comment OFFLOAD_BUNDLER_MAGIC_STR__START__ Nth Bundle Entry ID"
+  Bundle N
+  "Comment OFFLOAD_BUNDLER_MAGIC_STR__END__ 1st Bundle Entry ID"
+
 .. _clang-bundled-code-object-layout:
 
-Bundled Code Object Layout
+Bundled Binary File Layout
 ==
 
 The layout of a bundled code object is defined by the following table:
@@ -209,3 +262,35 @@ Target specific information is available for the following:
   supported.
 
 Most other targets do not support target IDs.
+
+Archive Unbundling
+==
+
+Unbundling of heterogeneous device archive is done to create device specific
+archives. Heterogeneous Device Archive is in a format compatible with GNU ar
+utility and contains a collection of bundled device binaries where each bundle
+file will contain device binaries for a host and one or more targets. The
+output device specific archive is in a format compatible with GNU ar utility
+and contains a collection of device binaries for a specific target.
+
+  Heterogeneous Device Archive, HDA = {F1.X, F2.X, ..., FN.Y}
+  where, Fi = Bundle{Host-DeviceBinary, T1-DeviceBinary, T2-DeviceBinary, ...,
+ Tm-DeviceBinary},
+ Ti = {Target i, qualified using Bundle Entry ID},
+ X/Y = \*.bc for AMDGPU and \*.cubin for NVPTX
+
+  Device Specific Archive, DSA(Tk) = {F1-Tk-DeviceBinary.X, 
F2-Tk-DeviceBinary.X, ...
+  FN-Tk-DeviceBinary.Y}
+  where, Fi-Tj-DeviceBinary.X represents device binary of i-th bun

[PATCH] D110083: [clang-offload-bundler][docs][NFC] Add archive unbundling documentation

2021-09-21 Thread Saiyedul Islam via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
saiislam marked an inline comment as done.
Closed by commit rGee31ad0ab5f7: [clang-offload-bundler][docs][NFC] Add archive 
unbundling documentation (authored by saiislam).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110083

Files:
  clang/docs/ClangOffloadBundler.rst

Index: clang/docs/ClangOffloadBundler.rst
===
--- clang/docs/ClangOffloadBundler.rst
+++ clang/docs/ClangOffloadBundler.rst
@@ -30,9 +30,62 @@
 offload kind (see :ref:`clang-offload-kind-table`) to load the offload code
 objects appropriate to the devices present when the host program is executed.
 
+Supported File Formats
+==
+Several text and binary file formats are supported for bundling/unbundling. See
+:ref:`supported-file-formats-table` for a list of currently supported formats.
+
+  .. table:: Supported File Formats
+ :name: supported-file-formats-table
+
+ +++-+
+ | File Format| File Extension | Text/Binary |
+ +++=+
+ | CPP output |i   | Text|
+ +++-+
+ | C++ CPP output |   ii   | Text|
+ +++-+
+ | CUDA/HIP output|   cui  | Text|
+ +++-+
+ | Dependency |d   | Text|
+ +++-+
+ | LLVM   |   ll   | Text|
+ +++-+
+ | LLVM Bitcode   |   bc   |Binary   |
+ +++-+
+ | Assembler  |s   | Text|
+ +++-+
+ | Object |o   |Binary   |
+ +++-+
+ | Archive of objects |a   |Binary   |
+ +++-+
+ | Precompiled header |   gch  |Binary   |
+ +++-+
+ | Clang AST file |   ast  |Binary   |
+ +++-+
+
+.. _clang-bundled-code-object-layout-text:
+
+Bundled Text File Layout
+
+
+The format of the bundled files is currently very simple: text formats are
+concatenated with comments that have a magic string and bundle entry ID in
+between.
+
+::
+
+  "Comment OFFLOAD_BUNDLER_MAGIC_STR__START__ 1st Bundle Entry ID"
+  Bundle 1
+  "Comment OFFLOAD_BUNDLER_MAGIC_STR__END__ 1st Bundle Entry ID"
+  ...
+  "Comment OFFLOAD_BUNDLER_MAGIC_STR__START__ Nth Bundle Entry ID"
+  Bundle N
+  "Comment OFFLOAD_BUNDLER_MAGIC_STR__END__ 1st Bundle Entry ID"
+
 .. _clang-bundled-code-object-layout:
 
-Bundled Code Object Layout
+Bundled Binary File Layout
 ==
 
 The layout of a bundled code object is defined by the following table:
@@ -209,3 +262,35 @@
   supported.
 
 Most other targets do not support target IDs.
+
+Archive Unbundling
+==
+
+Unbundling of heterogeneous device archive is done to create device specific
+archives. Heterogeneous Device Archive is in a format compatible with GNU ar
+utility and contains a collection of bundled device binaries where each bundle
+file will contain device binaries for a host and one or more targets. The
+output device specific archive is in a format compatible with GNU ar utility
+and contains a collection of device binaries for a specific target.
+
+  Heterogeneous Device Archive, HDA = {F1.X, F2.X, ..., FN.Y}
+  where, Fi = Bundle{Host-DeviceBinary, T1-DeviceBinary, T2-DeviceBinary, ...,
+ Tm-DeviceBinary},
+ Ti = {Target i, qualified using Bundle Entry ID},
+ X/Y = \*.bc for AMDGPU and \*.cubin for NVPTX
+
+  Device Specific Archive, DSA(Tk) = {F1-Tk-DeviceBinary.X, F2-Tk-DeviceBinary.X, ...
+  FN-Tk-DeviceBinary.Y}
+  where, Fi-Tj-DeviceBinary.X represents device binary of i-th bundled device
+  binary file for target Tj.
+
+clang-offload-bundler extracts compatible device binaries for a given target
+from the bundled device binaries in a heterogeneous device archive and creates
+a target specific device archive without bundling.
+
+clang-offlocad-bundler determines whether a device binary is compatible with a
+target by comparing bundle ID's. Two bundle ID's are considered compatible if:
+
+  * Their offload kind are the same
+  * Their target trip

[PATCH] D107339: [analyzer] Retrieve a character from StringLiteral as an initializer for constant arrays.

2021-09-21 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 373908.
ASDenysPetrov added a comment.

Rebased.


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

https://reviews.llvm.org/D107339

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initialization.cpp

Index: clang/test/Analysis/initialization.cpp
===
--- clang/test/Analysis/initialization.cpp
+++ clang/test/Analysis/initialization.cpp
@@ -128,3 +128,39 @@
   // FIXME: Should warn {{garbage or undefined}}.
   auto x = ptr[idx]; // // no-warning
 }
+
+char const glob_arr6[5] = "123";
+void glob_array_index4() {
+  clang_analyzer_eval(glob_arr6[0] == '1');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[1] == '2');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[2] == '3');  // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[3] == '\0'); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr6[4] == '\0'); // expected-warning{{TRUE}}
+}
+
+void glob_ptr_index3() {
+  char const *ptr = glob_arr6;
+  clang_analyzer_eval(ptr[-42] == '\0'); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[0] == '1');// expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == '2');// expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == '3');// expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == '\0');   // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[4] == '\0');   // expected-warning{{TRUE}}
+  // FIXME: Should be UNDEFINED.
+  clang_analyzer_eval(ptr[5] == '\0'); // expected-warning{{TRUE}}
+  // FIXME: Should be UNDEFINED.
+  clang_analyzer_eval(ptr[6] == '\0'); // expected-warning{{TRUE}}
+}
+
+void glob_invalid_index7() {
+  int idx = -42;
+  auto x = glob_arr6[idx]; // expected-warning{{garbage or undefined}}
+}
+
+// TODO: Support multidimensional array.
+void glob_invalid_index8() {
+  const char *ptr = glob_arr6;
+  int idx = 42;
+  // FIXME: Should warn {{garbage or undefined}}.
+  auto x = ptr[idx]; // no-warning
+}
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -573,6 +573,8 @@
   SVal getBindingForFieldOrElementCommon(RegionBindingsConstRef B,
  const TypedValueRegion *R,
  QualType Ty);
+  SVal getSValFromStringLiteralByIndex(const StringLiteral *SL,
+   const llvm::APSInt &Idx, QualType ElemT);
 
   SVal getLazyBinding(const SubRegion *LazyBindingRegion,
   RegionBindingsRef LazyBinding);
@@ -1625,6 +1627,23 @@
   return Result;
 }
 
+SVal RegionStoreManager::getSValFromStringLiteralByIndex(
+const StringLiteral *SL, const llvm::APSInt &Idx, QualType ElemT) {
+  assert(SL && "StringLiteral should not be null");
+  // If index is out of bounds, return Undef.
+  if (Idx < 0)
+return UndefinedVal();
+  // Technically, only i == length is guaranteed to be null.
+  // However, such overflows should be caught before reaching this point;
+  // the only time such an access would be made is if a string literal was
+  // used to initialize a larger array.
+  // FIXME: Take array dimension into account to prevent exceeding its size.
+  const int64_t I = Idx.getExtValue();
+  uint32_t Code =
+  (static_cast(I) >= SL->getLength()) ? 0 : SL->getCodeUnit(I);
+  return svalBuilder.makeIntVal(Code, ElemT);
+}
+
 SVal RegionStoreManager::getBindingForElement(RegionBindingsConstRef B,
   const ElementRegion* R) {
   // Check if the region has a binding.
@@ -1636,26 +1655,16 @@
   // Check if the region is an element region of a string literal.
   if (const StringRegion *StrR = dyn_cast(superR)) {
 // FIXME: Handle loads from strings where the literal is treated as
-// an integer, e.g., *((unsigned int*)"hello")
+// an integer, e.g., *((unsigned int*)"hello"). Such loads are UB according
+// to C++20 7.2.1.11 [basic.lval].
 QualType T = Ctx.getAsArrayType(StrR->getValueType())->getElementType();
 if (!Ctx.hasSameUnqualifiedType(T, R->getElementType()))
   return UnknownVal();
 
-const StringLiteral *Str = StrR->getStringLiteral();
 SVal Idx = R->getIndex();
 if (Optional CI = Idx.getAs()) {
-  int64_t i = CI->getValue().getSExtValue();
-  // Abort on string underrun.  This can be possible by arbitrary
-  // clients of getBindingForElement().
-  if (i < 0)
-return UndefinedVal();
-  int64_t length = Str->getLength();
-  // Technically, only i == length is guaranteed to be null.
-  // However, such overflows should be caught before reaching this point;
-  // the only time such an access would be made is if a string literal was
-  // used to initialize a larg

[PATCH] D110129: [DebugInfo] Support typedef with btf_tag attributes

2021-09-21 Thread Paul Robinson via Phabricator via cfe-commits
probinson added inline comments.



Comment at: clang/test/CodeGen/attr-btf_tag-typedef.c:2
+// REQUIRES: x86-registered-target
+// RUN: %clang -target x86_64 -g -S -emit-llvm -o - %s | FileCheck %s
+

Outside of clang/test/Driver, tests should use `%clang_cc1` to run the frontend 
directly instead of via the driver.  This will require some minor adjustment to 
the command-line options, for example `-target` becomes `-triple` and `-g` 
generally becomes `-debug-info-kind=limited`.

Also, the `x86_64` triple will do the wrong thing on a Windows host.  You 
probably want `%itanium_abi_triple` there.



Comment at: llvm/test/Bitcode/attr-btf_tag-typedef.ll:1
+; REQUIRES: x86-registered-target
+; RUN: llvm-as < %s | llvm-dis | FileCheck %s

Does this really require a specific target?  I don't see anything 
target-dependent in the test.



Comment at: llvm/test/DebugInfo/attr-btf_tag-typedef.ll:1
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s

Move this test to llvm/test/DebugInfo/X86 and remove the REQUIRES line.



Comment at: llvm/test/DebugInfo/attr-btf_tag-typedef.ll:2
+; REQUIRES: x86-registered-target
+; RUN: llc -filetype=obj -o %t %s
+; RUN: llvm-dwarfdump -debug-info %t | FileCheck %s

Use `%itanium_abi_triple` so the test will work correctly on Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110129

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


[clang] 32b994b - [OpenCL] Defines helper function for OpenCL default address space

2021-09-21 Thread Justas Janickas via cfe-commits

Author: Justas Janickas
Date: 2021-09-21T15:12:08+01:00
New Revision: 32b994bca66641cdac8586f25315daf349921ebc

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

LOG: [OpenCL] Defines helper function for OpenCL default address space

Helper function `getDefaultOpenCLPointeeAddrSpace()` introduced to
`ASTContext` class. It returns default OpenCL address space
depending on language version and enabled features. If generic
address space is supported, the helper function returns value
`LangAS::opencl_generic`. Otherwise, value `LangAS::opencl_private`
is returned. Code refactoring changes performed in several suitable
places.

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/lib/AST/Expr.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b8f7c3aae2608..f1b057c8003f8 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1362,6 +1362,12 @@ class ASTContext : public RefCountedBase {
   /// Get address space for OpenCL type.
   LangAS getOpenCLTypeAddrSpace(const Type *T) const;
 
+  /// Returns default address space based on OpenCL version and enabled 
features
+  inline LangAS getDefaultOpenCLPointeeAddrSpace() {
+return LangOpts.OpenCLGenericAddressSpace ? LangAS::opencl_generic
+  : LangAS::opencl_private;
+  }
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
 cudaConfigureCallDecl = FD;
   }

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 31733932361f3..9fde21c7ee9e1 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3779,11 +3779,8 @@ Expr::isNullPointerConstant(ASTContext &Ctx,
 // has non-default address space it is not treated as nullptr.
 // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr
 // since it cannot be assigned to a pointer to constant address space.
-if ((Ctx.getLangOpts().OpenCLVersion >= 200 &&
- Pointee.getAddressSpace() == LangAS::opencl_generic) ||
-(Ctx.getLangOpts().OpenCL &&
- Ctx.getLangOpts().OpenCLVersion < 200 &&
- Pointee.getAddressSpace() == LangAS::opencl_private))
+if (Ctx.getLangOpts().OpenCL &&
+Pointee.getAddressSpace() == 
Ctx.getDefaultOpenCLPointeeAddrSpace())
   Qs.removeAddressSpace();
 
 if (Pointee->isVoidType() && Qs.empty() && // to void*

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 0b936d60fc5ee..c997c70d17cef 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1430,7 +1430,7 @@ NamedDecl *Sema::getCurFunctionOrMethodDecl() {
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
   if (getLangOpts().OpenCL)
-return LangAS::opencl_generic;
+return getASTContext().getDefaultOpenCLPointeeAddrSpace();
   return LangAS::Default;
 }
 

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 826abbd8c3623..060f42bf9d644 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3894,8 +3894,9 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
 Arg->isLValue()) {
-  if (S.getLangOpts().OpenCL  && !ArgType.hasAddressSpace())
-ArgType = S.Context.getAddrSpaceQualType(ArgType, 
LangAS::opencl_generic);
+  if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace())
+ArgType = S.Context.getAddrSpaceQualType(
+ArgType, S.Context.getDefaultOpenCLPointeeAddrSpace());
   ArgType = S.Context.getLValueReferenceType(ArgType);
 }
   } else {

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index fcc2cf055be9e..d2d54281c63e0 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2092,9 +2092,7 @@ static QualType deduceOpenCLPointeeAddrSpace(Sema &S, 
QualType PointeeType) {
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
- ? LangAS::opencl_generic
- : LangAS::opencl_private);
+PointeeType, S.getASTContext().getDefaultOpenCLPointeeAddrSpace());
   return PointeeType;
 }
 



___
cfe-commits mailin

[PATCH] D109874: [OpenCL] Defines helper function for OpenCL default address space

2021-09-21 Thread Justas Janickas 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 rG32b994bca666: [OpenCL] Defines helper function for OpenCL 
default address space (authored by Topotuna).

Changed prior to commit:
  https://reviews.llvm.org/D109874?vs=373834&id=373915#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109874

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2092,9 +2092,7 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
- ? LangAS::opencl_generic
- : LangAS::opencl_private);
+PointeeType, S.getASTContext().getDefaultOpenCLPointeeAddrSpace());
   return PointeeType;
 }
 
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3894,8 +3894,9 @@
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
 Arg->isLValue()) {
-  if (S.getLangOpts().OpenCL  && !ArgType.hasAddressSpace())
-ArgType = S.Context.getAddrSpaceQualType(ArgType, 
LangAS::opencl_generic);
+  if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace())
+ArgType = S.Context.getAddrSpaceQualType(
+ArgType, S.Context.getDefaultOpenCLPointeeAddrSpace());
   ArgType = S.Context.getLValueReferenceType(ArgType);
 }
   } else {
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1430,7 +1430,7 @@
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
   if (getLangOpts().OpenCL)
-return LangAS::opencl_generic;
+return getASTContext().getDefaultOpenCLPointeeAddrSpace();
   return LangAS::Default;
 }
 
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -3779,11 +3779,8 @@
 // has non-default address space it is not treated as nullptr.
 // (__generic void*)0 in OpenCL 2.0 should not be treated as nullptr
 // since it cannot be assigned to a pointer to constant address space.
-if ((Ctx.getLangOpts().OpenCLVersion >= 200 &&
- Pointee.getAddressSpace() == LangAS::opencl_generic) ||
-(Ctx.getLangOpts().OpenCL &&
- Ctx.getLangOpts().OpenCLVersion < 200 &&
- Pointee.getAddressSpace() == LangAS::opencl_private))
+if (Ctx.getLangOpts().OpenCL &&
+Pointee.getAddressSpace() == 
Ctx.getDefaultOpenCLPointeeAddrSpace())
   Qs.removeAddressSpace();
 
 if (Pointee->isVoidType() && Qs.empty() && // to void*
Index: clang/include/clang/AST/ASTContext.h
===
--- clang/include/clang/AST/ASTContext.h
+++ clang/include/clang/AST/ASTContext.h
@@ -1362,6 +1362,12 @@
   /// Get address space for OpenCL type.
   LangAS getOpenCLTypeAddrSpace(const Type *T) const;
 
+  /// Returns default address space based on OpenCL version and enabled 
features
+  inline LangAS getDefaultOpenCLPointeeAddrSpace() {
+return LangOpts.OpenCLGenericAddressSpace ? LangAS::opencl_generic
+  : LangAS::opencl_private;
+  }
+
   void setcudaConfigureCallDecl(FunctionDecl *FD) {
 cudaConfigureCallDecl = FD;
   }


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2092,9 +2092,7 @@
   !PointeeType->isSamplerT() &&
   !PointeeType.hasAddressSpace())
 PointeeType = S.getASTContext().getAddrSpaceQualType(
-PointeeType, S.getLangOpts().OpenCLGenericAddressSpace
- ? LangAS::opencl_generic
- : LangAS::opencl_private);
+PointeeType, S.getASTContext().getDefaultOpenCLPointeeAddrSpace());
   return PointeeType;
 }
 
Index: clang/lib/Sema/SemaTemplateDeduction.cpp
===
--- clang/lib/Sema/SemaTemplateDeduction.cpp
+++ clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3894,8 +3894,9 @@
 //   "lvalue reference to A" is used in place of A for type deduction.
 if (is

[clang] 744ec74 - [NFC] `goto fail` has failed us in the past...

2021-09-21 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2021-09-21T09:18:37-05:00
New Revision: 744ec74b305a5039dc74e2d043e1c136e06beac1

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

LOG: [NFC] `goto fail` has failed us in the past...

This patch replaces reliance on `goto failure` pattern with
`llvm::scope_exit`.

Reviewed By: bkramer

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

Added: 


Modified: 
clang/lib/Frontend/FrontendAction.cpp

Removed: 




diff  --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index c996c9c486bc4..0bb62a96e02cc 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -27,6 +27,7 @@
 #include "clang/Serialization/ASTDeserializationListener.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -558,8 +559,20 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
   bool HasBegunSourceFile = false;
   bool ReplayASTFile = Input.getKind().getFormat() == InputKind::Precompiled &&
usesPreprocessorOnly();
+
+  // If we fail, reset state since the client will not end up calling the
+  // matching EndSourceFile(). All paths that return true should release this.
+  auto FailureCleanup = llvm::make_scope_exit([&]() {
+if (HasBegunSourceFile)
+  CI.getDiagnosticClient().EndSourceFile();
+CI.clearOutputFiles(/*EraseFiles=*/true);
+CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
+setCurrentInput(FrontendInputFile());
+setCompilerInstance(nullptr);
+  });
+
   if (!BeginInvocation(CI))
-goto failure;
+return false;
 
   // If we're replaying the build of an AST file, import it and set up
   // the initial state from its build.
@@ -580,7 +593,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 ASTUnit::LoadPreprocessorOnly, ASTDiags, CI.getFileSystemOpts(),
 CI.getCodeGenOpts().DebugTypeExtRefs);
 if (!AST)
-  goto failure;
+  return false;
 
 // Options relating to how we treat the input (but not what we do with it)
 // are inherited from the AST unit.
@@ -649,7 +662,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 CI.getCodeGenOpts().DebugTypeExtRefs);
 
 if (!AST)
-  goto failure;
+  return false;
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
@@ -669,20 +682,21 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 
 // Initialize the action.
 if (!BeginSourceFileAction(CI))
-  goto failure;
+  return false;
 
 // Create the AST consumer.
 CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile));
 if (!CI.hasASTConsumer())
-  goto failure;
+  return false;
 
+FailureCleanup.release();
 return true;
   }
 
   // Set up the file and source managers, if needed.
   if (!CI.hasFileManager()) {
 if (!CI.createFileManager()) {
-  goto failure;
+  return false;
 }
   }
   if (!CI.hasSourceManager())
@@ -710,12 +724,13 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 
 // Initialize the action.
 if (!BeginSourceFileAction(CI))
-  goto failure;
+  return false;
 
 // Initialize the main file entry.
 if (!CI.InitializeSourceManager(CurrentInput))
-  goto failure;
+  return false;
 
+FailureCleanup.release();
 return true;
   }
 
@@ -748,7 +763,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 
   if (!Found) {
 CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude;
-goto failure;
+return false;
   }
 }
   }
@@ -765,7 +780,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 
   // Initialize the main file entry.
   if (!CI.InitializeSourceManager(Input))
-goto failure;
+return false;
 
   // For module map files, we first parse the module map and synthesize a
   // "" buffer before more conventional processing.
@@ -777,11 +792,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 if (loadModuleMapForModuleBuild(CI, Input.isSystem(),
 Input.isPreprocessed(),
 PresumedModuleMapFile, OffsetToContents))
-  goto failure;
+  return false;
 
 auto *CurrentModule = prepareToBuildModule(CI, Input.getFile());
 if (!CurrentModule)
-  goto failure;
+  return false;
 
 CurrentModule->PresumedModuleMapFile = PresumedModuleMapFile;
 
@@ -792,7 +807,

[PATCH] D109865: [NFC] `goto fail` has failed us in the past...

2021-09-21 Thread Chris Bieneman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG744ec74b305a: [NFC] `goto fail` has failed us in the past... 
(authored by beanz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109865

Files:
  clang/lib/Frontend/FrontendAction.cpp

Index: clang/lib/Frontend/FrontendAction.cpp
===
--- clang/lib/Frontend/FrontendAction.cpp
+++ clang/lib/Frontend/FrontendAction.cpp
@@ -27,6 +27,7 @@
 #include "clang/Serialization/ASTDeserializationListener.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/GlobalModuleIndex.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
@@ -558,8 +559,20 @@
   bool HasBegunSourceFile = false;
   bool ReplayASTFile = Input.getKind().getFormat() == InputKind::Precompiled &&
usesPreprocessorOnly();
+
+  // If we fail, reset state since the client will not end up calling the
+  // matching EndSourceFile(). All paths that return true should release this.
+  auto FailureCleanup = llvm::make_scope_exit([&]() {
+if (HasBegunSourceFile)
+  CI.getDiagnosticClient().EndSourceFile();
+CI.clearOutputFiles(/*EraseFiles=*/true);
+CI.getLangOpts().setCompilingModule(LangOptions::CMK_None);
+setCurrentInput(FrontendInputFile());
+setCompilerInstance(nullptr);
+  });
+
   if (!BeginInvocation(CI))
-goto failure;
+return false;
 
   // If we're replaying the build of an AST file, import it and set up
   // the initial state from its build.
@@ -580,7 +593,7 @@
 ASTUnit::LoadPreprocessorOnly, ASTDiags, CI.getFileSystemOpts(),
 CI.getCodeGenOpts().DebugTypeExtRefs);
 if (!AST)
-  goto failure;
+  return false;
 
 // Options relating to how we treat the input (but not what we do with it)
 // are inherited from the AST unit.
@@ -649,7 +662,7 @@
 CI.getCodeGenOpts().DebugTypeExtRefs);
 
 if (!AST)
-  goto failure;
+  return false;
 
 // Inform the diagnostic client we are processing a source file.
 CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
@@ -669,20 +682,21 @@
 
 // Initialize the action.
 if (!BeginSourceFileAction(CI))
-  goto failure;
+  return false;
 
 // Create the AST consumer.
 CI.setASTConsumer(CreateWrappedASTConsumer(CI, InputFile));
 if (!CI.hasASTConsumer())
-  goto failure;
+  return false;
 
+FailureCleanup.release();
 return true;
   }
 
   // Set up the file and source managers, if needed.
   if (!CI.hasFileManager()) {
 if (!CI.createFileManager()) {
-  goto failure;
+  return false;
 }
   }
   if (!CI.hasSourceManager())
@@ -710,12 +724,13 @@
 
 // Initialize the action.
 if (!BeginSourceFileAction(CI))
-  goto failure;
+  return false;
 
 // Initialize the main file entry.
 if (!CI.InitializeSourceManager(CurrentInput))
-  goto failure;
+  return false;
 
+FailureCleanup.release();
 return true;
   }
 
@@ -748,7 +763,7 @@
 
   if (!Found) {
 CI.getDiagnostics().Report(diag::err_fe_no_pch_in_dir) << PCHInclude;
-goto failure;
+return false;
   }
 }
   }
@@ -765,7 +780,7 @@
 
   // Initialize the main file entry.
   if (!CI.InitializeSourceManager(Input))
-goto failure;
+return false;
 
   // For module map files, we first parse the module map and synthesize a
   // "" buffer before more conventional processing.
@@ -777,11 +792,11 @@
 if (loadModuleMapForModuleBuild(CI, Input.isSystem(),
 Input.isPreprocessed(),
 PresumedModuleMapFile, OffsetToContents))
-  goto failure;
+  return false;
 
 auto *CurrentModule = prepareToBuildModule(CI, Input.getFile());
 if (!CurrentModule)
-  goto failure;
+  return false;
 
 CurrentModule->PresumedModuleMapFile = PresumedModuleMapFile;
 
@@ -792,7 +807,7 @@
   // Otherwise, convert the module description to a suitable input buffer.
   auto Buffer = getInputBufferForModule(CI, CurrentModule);
   if (!Buffer)
-goto failure;
+return false;
 
   // Reinitialize the main file entry to refer to the new input.
   auto Kind = CurrentModule->IsSystem ? SrcMgr::C_System : SrcMgr::C_User;
@@ -805,7 +820,7 @@
 
   // Initialize the action.
   if (!BeginSourceFileAction(CI))
-goto failure;
+return false;
 
   // If we were asked to load any module map files, do so now.
   for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
@@ -839,7 +854,7 @@
 std::unique_ptr Consumer =
 CreateWrappedASTConsumer(CI, PresumedInputFile);
 if (!Consumer)
-  goto failure;
+  return false;
 
 // FIX

[PATCH] D109608: [clang][ASTImporter] Generic attribute import handling (first step).

2021-09-21 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 373922.
balazske added a comment.

Dump to 'llvm::nulls()'.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109608

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6406,6 +6406,83 @@
 ToSM.getBufferOrFake(ImportedID, SourceLocation()).getBuffer());
 }
 
+struct ImportAttributes : public ASTImporterOptionSpecificTestBase {
+  void checkAttrImportCommon(const Attr *From, const Attr *To,
+ const Decl *ToD) {
+
+// Verify that dump does not crash because invalid data.
+ToD->dump(llvm::nulls());
+
+EXPECT_EQ(From->getParsedKind(), To->getParsedKind());
+EXPECT_EQ(From->getSyntax(), To->getSyntax());
+if (From->getAttrName()) {
+  EXPECT_TRUE(To->getAttrName());
+  EXPECT_STREQ(From->getAttrName()->getNameStart(),
+   To->getAttrName()->getNameStart());
+} else {
+  EXPECT_FALSE(To->getAttrName());
+}
+if (From->getScopeName()) {
+  EXPECT_TRUE(To->getScopeName());
+  EXPECT_STREQ(From->getScopeName()->getNameStart(),
+   To->getScopeName()->getNameStart());
+} else {
+  EXPECT_FALSE(To->getScopeName());
+}
+EXPECT_EQ(From->getSpellingListIndex(), To->getSpellingListIndex());
+EXPECT_STREQ(From->getSpelling(), To->getSpelling());
+EXPECT_EQ(From->isInherited(), To->isInherited());
+EXPECT_EQ(From->isImplicit(), To->isImplicit());
+EXPECT_EQ(From->isPackExpansion(), To->isPackExpansion());
+EXPECT_EQ(From->isLateParsed(), To->isLateParsed());
+  }
+
+  template 
+  void importAttr(const char *Code, AT *&FromAttr, AT *&ToAttr) {
+static_assert(std::is_base_of::value, "AT should be an Attr");
+static_assert(std::is_base_of::value, "DT should be a Decl");
+
+Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cc");
+DT *FromD =
+FirstDeclMatcher().match(FromTU, namedDecl(hasName("test")));
+ASSERT_TRUE(FromD);
+
+DT *ToD = Import(FromD, Lang_CXX11);
+ASSERT_TRUE(ToD);
+
+FromAttr = FromD->template getAttr();
+ToAttr = ToD->template getAttr();
+ASSERT_TRUE(FromAttr);
+EXPECT_TRUE(ToAttr);
+
+checkAttrImportCommon(FromAttr, ToAttr, ToD);
+  }
+
+  template  void checkImported(const T *From, const T *To) {
+EXPECT_TRUE(To);
+EXPECT_NE(From, To);
+  }
+
+  template 
+  void checkImportVariadicArg(const llvm::iterator_range &From,
+  const llvm::iterator_range &To) {
+for (auto FromI = From.begin(), ToI = To.begin(); FromI != From.end();
+ ++FromI, ++ToI) {
+  ASSERT_NE(ToI, To.end());
+  checkImported(*FromI, *ToI);
+}
+  }
+};
+
+template <>
+void ImportAttributes::checkImported(const Decl *From, const Decl *To) {
+  EXPECT_TRUE(To);
+  EXPECT_NE(From, To);
+  EXPECT_EQ(To->getTranslationUnitDecl(),
+ToAST->getASTContext().getTranslationUnitDecl());
+}
+
+// FIXME: Use ImportAttributes for this test.
 TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
   // Test if import of these packed and aligned attributes does not trigger an
   // error situation where source location from 'From' context is referenced in
@@ -6441,6 +6518,7 @@
   EXPECT_TRUE(ToA);
 }
 
+// FIXME: Use ImportAttributes for this test.
 TEST_P(ASTImporterOptionSpecificTestBase, ImportFormatAttr) {
   Decl *FromTU = getTuDecl(
   R"(
@@ -6466,6 +6544,15 @@
 ToAttr->getAttributeSpellingListIndex());
   EXPECT_EQ(FromAttr->getType()->getName(), ToAttr->getType()->getName());
 }
+
+TEST_P(ImportAttributes, ImportAssertCapability) {
+  AssertCapabilityAttr *FromAttr, *ToAttr;
+  importAttr(
+  "void test(int A1, int A2) __attribute__((assert_capability(A1, A2)));",
+  FromAttr, ToAttr);
+  checkImportVariadicArg(FromAttr->args(), ToAttr->args());
+}
+
 template 
 auto ExtendWithOptions(const T &Values, const std::vector &Args) {
   auto Copy = Values;
@@ -6849,5 +6936,8 @@
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportWithExternalSource,
  DefaultTestValuesForRunOptions);
 
+INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ImportAttributes,
+ DefaultTestValuesForRunOptions);
+
 } // end namespace ast_matchers
 } // end namespace clang
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -186,22 +186,6 @@
   return import(*From);
 }
 
-// Helper for chaining together multiple imports. If an error is detected,
-// subsequent imports will return default constructed nodes, so that failure
-   

[PATCH] D110029: [OpenMP][Offloading] Use bitset to indicate execution mode instead of value

2021-09-21 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Just more style things, I think the rest is fine.




Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:134
+  SPMD = 0x2,
+};
+

If you copy the LLVM_MARK_AS_BITMASK_ENUM stuff you can actually use the enum 
class as bitmask w/o the static casts all the time.
I'd also suggest to create the combinations here, so GenericSPMD = Generic | 
SPMD;.



Comment at: openmp/libomptarget/plugins/cuda/src/rtl.cpp:863
   // default value GENERIC (in case symbol is missing from cubin file)
-  int8_t ExecModeVal = ExecutionModeType::GENERIC;
+  int8_t ExecModeVal = 1;
   std::string ExecModeNameStr(E->name);




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110029

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


[PATCH] D104285: [analyzer] Retrieve a value from list initialization of constant array declaration in a global scope.

2021-09-21 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1696
+  const llvm::APSInt &Idx = CI->getValue();
+  const uint64_t I = static_cast(Idx.getExtValue());
+  // Use `getZExtValue` because array extent can not be negative.

ASDenysPetrov wrote:
> ASDenysPetrov wrote:
> > martong wrote:
> > > aaron.ballman wrote:
> > > > 
> > > This `static_cast` seems to be dangerous to me, it might overflow. Can't 
> > > we compare `Idx` directly to `Extent`? I see that `Idx` is an `APSint` 
> > > and `Extent` is an `APInt`, but  I think we should be able to handle the 
> > > comparison on the APInt level b/c that takes care of the signedness. And 
> > > the overflow situation should be handled as well properly with `APInt`, 
> > > given from it's name "arbitrary precision int". In this sense I don't see 
> > > why do we need `I` at all.
> > We can't get rid of `I` because we use it below anyway in `I >= 
> > InitList->getNumInits()` and `InitList->getInit(I)`.
> > I couldn't find any appropriate function to compare without additional 
> > checking for signedness or bit-width adjusting.
> > I'll try to improve this snippet.
> This is not dangerous because we check for negatives separately in `Idx < 0`, 
> so we can be sure that `I` is positive while `I >= Extent`. Unfortunately, I 
> didn't find any suitable way to compare `APSint` //of unknown sign and 
> bitwidth// with //signless// `APInt` without adding another checks for sign 
> and bitwidth conversions. In this way I prefer the currect condition `I >= 
> Extent`.
I think it would be possible to use `bool llvm::APInt::uge` that does an 
Unsigned greater or equal comparison. Or you could use `sge` for the signed 
comparison. Also, both have overload that take another APInt as parameter.


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

https://reviews.llvm.org/D104285

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


[PATCH] D108379: [OpenCL] Fix version reporting of C++ for OpenCL 2021

2021-09-21 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna added a comment.

Changes rG054e331d9dbd 
 and 
rG37cdc7ebd9a3 
 contain 
test cases that display C++ for OpenCL version 2021 in diagnostics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108379

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


[PATCH] D109002: [OpenCL] Supports optional image types in C++ for OpenCL 2021

2021-09-21 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:1729
 bool IsOpenCLC30 = (S.getLangOpts().OpenCLVersion == 300);
+bool IsOpenCLC30Comp = S.getLangOpts().getOpenCLCompatibleVersion() == 300;
 // OpenCL C v3.0 s6.3.3 - OpenCL image types require __opencl_c_images

Topotuna wrote:
> Anastasia wrote:
> > Topotuna wrote:
> > > Anastasia wrote:
> > > > I think we should just replace `IsOpenCLC30` as it is when only used in 
> > > > the diagnostic that we should report the same as for OpenCL 3.0.
> > > > 
> > > > 
> > > > Also I would suggest changing name to `IsOpenCLC30Compatible` to make 
> > > > it clearer. 
> > > That diagnostic is responsible for `__opencl_c_3d_image_writes` feature 
> > > while current commit addresses `__opencl_c_images`. I wanted to keep 
> > > commits separate and was planning to finish transitioning from 
> > > `IsOpenCLC30` to `IsOpenCLC30Compatible` in a future commit.
> > > 
> > > I agree that `IsOpenCLC30Compatible` would be clearer. Thank you.
> > Ok, let's just only rename it for now and add a FIXME comment explaining 
> > that the variables should be unified later on.
> > 
> > I suspect your subsequent commits would include the unification?
> Yes, I will perform unification when adding support for 
> `__opencl_c_3d_image_writes` optional core feature.
Change rGca3bebd8440f performs mentioned variable unification.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109002

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


[PATCH] D110084: [PowerPC] Support for vector bool int128 on vector comparison builtins

2021-09-21 Thread Lei Huang via Phabricator via cfe-commits
lei accepted this revision as: lei.
lei added a comment.
This revision is now accepted and ready to land.

LGTM
thx


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110084

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


[PATCH] D109632: [clang] de-duplicate methods from AST files

2021-09-21 Thread Richard Howell via Phabricator via cfe-commits
rmaz added a comment.

> What folks are thinking about writing less in METHOD_POOL?

I prefer the idea of it, but I think the `ReadMethodPoolVisitor` also has to be 
changed for this to work. When it finds a selector in a module it will return 
true, which causes the search to stop descending into dependent modules:

  if (!Visitor(*CurrentModule))
continue;
  
  // The visitor has requested that cut off visitation of any
  // module that the current module depends on. To indicate this
  // behavior, we mark all of the reachable modules as having been visited.

Wouldn't this logic have to be changed to ensure we pick up all the transitive 
methods from dependent modules?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109632

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


[PATCH] D108560: [clang-tidy] Add support for NOLINTBEGIN ... NOLINTEND comments to suppress clang-tidy warnings over multiple lines

2021-09-21 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz updated this revision to Diff 373932.
salman-javed-nz added a comment.

Updated according to review comments.

- `test/clang-tidy/infrastructure/nolintbeginend-begin-at-eof.cpp`: new test
- `test/clang-tidy/infrastructure/nolintbeginend-end-at-sof.cpp`: new test
- Use `llvm::ErrorOr` return type with `getFile()`
- Split diagnostic message into 2 messages (one specific to `NOLINTBEGIN` and 
one specific to `NOLINTEND`)
- `if ... else` brace wrapping
- Spelling corrected to "nonexistent"
- Assert that `Unused` diagnostic container is empty
- change std::vector to llvm::SmallVectorImpl


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108560

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/error_in_include.inc
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/nolint_in_include.inc
  clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-at-eof.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-without-end.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-at-sof.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-without-begin.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp

Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp
@@ -1,49 +1,51 @@
+// NOLINTNEXTLINE
 class A { A(int i); };
+
+class B { B(int i); };
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
 
 // NOLINTNEXTLINE
-class B { B(int i); };
+class C { C(int i); };
 
 // NOLINTNEXTLINE(for-some-other-check)
-class C { C(int i); };
+class D { D(int i); };
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
 
 // NOLINTNEXTLINE(*)
-class C1 { C1(int i); };
+class D1 { D1(int i); };
 
 // NOLINTNEXTLINE(not-closed-bracket-is-treated-as-skip-all
-class C2 { C2(int i); };
+class D2 { D2(int i); };
 
 // NOLINTNEXTLINE(google-explicit-constructor)
-class C3 { C3(int i); };
+class D3 { D3(int i); };
 
 // NOLINTNEXTLINE(some-check, google-explicit-constructor)
-class C4 { C4(int i); };
+class D4 { D4(int i); };
 
 // NOLINTNEXTLINE without-brackets-skip-all, another-check
-class C5 { C5(int i); };
-
+class D5 { D5(int i); };
 
 // NOLINTNEXTLINE
 
-class D { D(int i); };
+class E { E(int i); };
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
 
 // NOLINTNEXTLINE
 //
-class E { E(int i); };
+class F { F(int i); };
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
 
 #define MACRO(X) class X { X(int i); };
-MACRO(F)
+MACRO(G)
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit
 // NOLINTNEXTLINE
-MACRO(G)
+MACRO(H)
 
-#define MACRO_NOARG class H { H(int i); };
+#define MACRO_NOARG class I { I(int i); };
 // NOLINTNEXTLINE
 MACRO_NOARG
 
-// CHECK-MESSAGES: Suppressed 8 warnings (8 NOLINT)
+// CHECK-MESSAGES: Suppressed 9 warnings (9 NOLINT)
 
 // RUN: %check_clang_tidy %s google-explicit-constructor %t --
Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
@@ -0,0 +1,127 @@
+// RUN: %check_clang_tidy %s google-explicit-constructor %t -- --header-filter=.* -system-headers -- -isystem %S/Inputs/nolintbeginend
+
+class A { A(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+// NOLINTBEGIN
+class B1 { B1(int i); };
+// NOLINTEND
+
+// NOLINTBEGIN
+// NOLINTEND
+// NOLINTBEGIN
+class B2 { B2(int i); };
+// NOLINTEND
+
+// NOLINTBEGIN
+// NOLINTBEGIN
+class B3 { B3(int i); };
+// NOLINTEND
+// NOLINTEND
+
+// NOLINTBEGIN
+// NOLINTBEGIN
+// NOLINTEND
+class B4 { B4(int i); };
+// NOLINTEND
+
+// NOLINTBEGIN
+// NOLINTEND
+class B5 { B5(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+
+// NOLINTBEGIN(google-explicit-constructor)
+class C1 { C1(int i); };
+// NOLINTEND(google-explicit-constructor)
+
+// NOLI

[PATCH] D109902: [PowerPC] Improved codegen related to xscvdpsxws/xscvdpuxws

2021-09-21 Thread Kamau Bridgeman via Phabricator via cfe-commits
kamaub added a reviewer: kamaub.
kamaub added a comment.

This patch seems almost ready to land to me, I'm just a bit concerned about the 
testing coverage, 
is the little endian testing case suppose to target `pwr7` as the big endian 
test does? The default 
FileCheck line seems redundant to me, did I misunderstand?




Comment at: llvm/test/CodeGen/PowerPC/test-vector-insert.ll:8
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix \
+; RUN:  -mcpu=pwr7 < %s | FileCheck %s
+

It seems like this run line is redundant, it produces the same assembly as the 
big endian specific line above. Maybe the `-mcpu=pwr7` can be moved to the 
first Little-endian specific run line? That line currently only test the target 
cpu of the test machine.


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

https://reviews.llvm.org/D109902

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


[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-09-21 Thread Ilya Kuteev via Phabricator via cfe-commits
ilyakuteev updated this revision to Diff 373936.

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

https://reviews.llvm.org/D106876

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-mobile-map.m

Index: clang/test/Modules/add-remove-irrelevant-mobile-map.m
===
--- /dev/null
+++ clang/test/Modules/add-remove-irrelevant-mobile-map.m
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
+
+// Build without b.modulemap
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
+// RUN: cp %t.mcp/a.pcm %t/a.pcm
+
+// Build with b.modulemap
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
+// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+
+// expected-no-diagnostics
+
+@import a;
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
@@ -0,0 +1 @@
+module b { }
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
@@ -0,0 +1 @@
+module a { }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -149,6 +149,59 @@
 
 namespace {
 
+std::set GetAllModuleMaps(const HeaderSearch &HS,
+ Module *RootModule) {
+  std::set ModuleMaps{};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
+
+  SmallVector FilesByUID;
+  HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
+
+  if (FilesByUID.size() > HS.header_file_size())
+FilesByUID.resize(HS.header_file_size());
+
+  for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
+const FileEntry *File = FilesByUID[UID];
+if (!File)
+  continue;
+
+const HeaderFileInfo *HFI =
+HS.getExistingFileInfo(File, /*WantExternal*/ false);
+if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
+  continue;
+
+for (const auto &KH : HS.findAllModulesForHeader(File)) {
+  if (!KH.getModule())
+continue;
+  ModulesToProcess.push_back(KH.getModule());
+}
+  }
+
+  while (!ModulesToProcess.empty()) {
+auto *CurrentModule = ModulesToProcess.pop_back_val();
+ProcessedModules.insert(CurrentModule);
+
+auto *ModuleMapFile =
+HS.getModuleMap().getModuleMapFileForUniquing(CurrentModule);
+if (!ModuleMapFile) {
+  continue;
+}
+
+ModuleMaps.insert(ModuleMapFile);
+
+for (auto *ImportedModule : (CurrentModule)->Imports) {
+  if (!ImportedModule ||
+  ProcessedModules.find(ImportedModule) != ProcessedModules.end()) {
+continue;
+  }
+  ModulesToProcess.push_back(ImportedModule);
+}
+  }
+
+  return ModuleMaps;
+}
+
 class ASTTypeWriter {
   ASTWriter &Writer;
   ASTWriter::RecordData Record;
@@ -1396,9 +1449,15 @@
 Stream.EmitRecordWithBlob(AbbrevCode, Record, origDir);
   }
 
+  std::set AffectingModuleMaps;
+  if (WritingModule) {
+AffectingModuleMaps =
+GetAllModuleMaps(PP.getHeaderSearchInfo(), WritingModule);
+  }
+
   WriteInputFiles(Context.SourceMgr,
   PP.getHeaderSearchInfo().getHeaderSearchOpts(),
-  PP.getLangOpts().Modules);
+  AffectingModuleMaps);
   Stream.ExitBlock();
 }
 
@@ -1416,9 +1475,9 @@
 
 } // namespace
 
-void ASTWriter::WriteInputFiles(SourceManager &SourceMgr,
-HeaderSearchOptions &HSOpts,
-bool Modules) {
+void ASTWriter::WriteInputFiles(
+SourceManager &SourceMgr, HeaderSearchOptions &HSOpts,
+std::set &AffectingModuleMaps) {
   using namespace llvm;
 
   Stream.EnterSubblock(INPUT_FILES_BLOCK_ID, 4);
@@ -1458,6 +1517,16 @@
 if (!Cache->OrigEntry)
   continue;
 
+if (isModuleMap(File.getFileCharacteristic()) &&
+!isSystem(File.getFileCharacteristic()) &&
+!AffectingModuleMaps.empty() &&
+AffectingModuleMaps.find(Cache->OrigEntry) ==
+AffectingModuleMaps.end()) {
+  SkippedModuleMaps.insert(Cache->OrigEntry);
+  //

[clang] 9ae4275 - [clang][NFC] Fix needless double-parenthisation

2021-09-21 Thread Andy Wingo via cfe-commits

Author: Andy Wingo
Date: 2021-09-21T17:03:23+02:00
New Revision: 9ae4275557ca10f79af91ca99a2aa79d5dfd7ed3

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

LOG: [clang][NFC] Fix needless double-parenthisation

Strip a layer of parentheses in TreeTransform::RebuildQualifiedType.

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

Added: 


Modified: 
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 0aee33a51633..9c1236841b30 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4745,8 +4745,8 @@ QualType 
TreeTransform::RebuildQualifiedType(QualType T,
   SourceLocation Loc = TL.getBeginLoc();
   Qualifiers Quals = TL.getType().getLocalQualifiers();
 
-  if (((T.getAddressSpace() != LangAS::Default &&
-Quals.getAddressSpace() != LangAS::Default)) &&
+  if ((T.getAddressSpace() != LangAS::Default &&
+   Quals.getAddressSpace() != LangAS::Default) &&
   T.getAddressSpace() != Quals.getAddressSpace()) {
 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
 << TL.getType() << T;



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


[PATCH] D108359: [clang][NFC] Fix needless double-parenthisation

2021-09-21 Thread Andy Wingo via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9ae4275557ca: [clang][NFC] Fix needless 
double-parenthisation (authored by wingo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108359

Files:
  clang/lib/Sema/TreeTransform.h


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4745,8 +4745,8 @@
   SourceLocation Loc = TL.getBeginLoc();
   Qualifiers Quals = TL.getType().getLocalQualifiers();
 
-  if (((T.getAddressSpace() != LangAS::Default &&
-Quals.getAddressSpace() != LangAS::Default)) &&
+  if ((T.getAddressSpace() != LangAS::Default &&
+   Quals.getAddressSpace() != LangAS::Default) &&
   T.getAddressSpace() != Quals.getAddressSpace()) {
 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
 << TL.getType() << T;


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4745,8 +4745,8 @@
   SourceLocation Loc = TL.getBeginLoc();
   Qualifiers Quals = TL.getType().getLocalQualifiers();
 
-  if (((T.getAddressSpace() != LangAS::Default &&
-Quals.getAddressSpace() != LangAS::Default)) &&
+  if ((T.getAddressSpace() != LangAS::Default &&
+   Quals.getAddressSpace() != LangAS::Default) &&
   T.getAddressSpace() != Quals.getAddressSpace()) {
 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
 << TL.getType() << T;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D108621: [HIPSPV] Add CUDA->SPIR-V address space mapping

2021-09-21 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: clang/lib/Basic/Targets/SPIR.h:59
+// translation). This mapping is enabled when the language mode is HIP.
+1, // cuda_device
+// cuda_constant pointer can be casted to default/"flat" pointer, but in

Anastasia wrote:
> linjamaki wrote:
> > bader wrote:
> > > keryell wrote:
> > > > Anastasia wrote:
> > > > > bader wrote:
> > > > > > Anastasia wrote:
> > > > > > > I am slightly confused as in the LLVM project those address 
> > > > > > > spaces are for SPIR not SPIR-V though. It is however used outside 
> > > > > > > of LLVM project by some tools like SPIRV-LLVM Translator as a 
> > > > > > > path to SPIR-V, but it has only been done as a workaround since 
> > > > > > > we had no SPIR-V support in the LLVM project yet. And if we are 
> > > > > > > adding it let's do it clean to avoid/resolve any confusion.
> > > > > > > 
> > > > > > > I think we need to keep both because some vendors do target/use 
> > > > > > > SPIR but not SPIR-V.
> > > > > > > 
> > > > > > > So if you are interested in SPIR-V and not SPIR you should 
> > > > > > > probably add a new target that will make things cleaner.
> > > > > > > I think we need to keep both because some vendors do target/use 
> > > > > > > SPIR but not SPIR-V.
> > > > > > 
> > > > > > @Anastasia, could you elaborate more on the difference between SPIR 
> > > > > > and SPIR-V?
> > > > > > I would like to understand what these terms mean in the context of 
> > > > > > LLVM project.
> > > > > Their conceptual differences are just that they are two different 
> > > > > intermediate formats.
> > > > > 
> > > > > The important thing to highlight is that it is not impossible that 
> > > > > some vendors use SPIR (without using SPIR-V) even despite the fact it 
> > > > > has been discontinued by Khronos. 
> > > > > 
> > > > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > > > > Their conceptual differences are just that they are two different 
> > > > > intermediate formats.
> > > > > 
> > > > > The important thing to highlight is that it is not impossible that 
> > > > > some vendors use SPIR (without using SPIR-V) even despite the fact it 
> > > > > has been discontinued by Khronos. 
> > > > > 
> > > > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > > > 
> > > > All the official Xilinx OpenCL stack is based on legacy SPIR (encoded 
> > > > in LLVM 6.x IR but this is another story) and I suspect this is the 
> > > > case for other companies.
> > > > So, do not deprecate or discontinue, please. :-)
> > > > The important thing to highlight is that it is not impossible that some 
> > > > vendors use SPIR (without using SPIR-V) even despite the fact it has 
> > > > been discontinued by Khronos.
> > > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > > 
> > > Strictly speaking `SPIR` is not defined as an intermediate language. 
> > > Khronos defines `SPIR-1.2` and `SPIR-2.0` formats which are based on LLVM 
> > > 3.2 and LLVM 3.4 version (https://www.khronos.org/spir/). There is no 
> > > definition of SPIR format based on current version of LLVM IR. Another 
> > > note is that metadata and intrinsics emitted for OpenCL with clang-14 
> > > doesn't follow neither `SPIR-1.2` nor `SPIR-2.0`.
> > > 
> > > I always think of LLVM IR as leaving thing that is subject to change by 
> > > LLVM community, so tools working with LLVM IR must adjust to the 
> > > particular version (e.g. release version like LLVM 13 or ToT). We apply 
> > > this logic to SPIRV-LLVM-Translator tool and update it according to LLVM 
> > > format changes (e.g. kernel argument information defined in Khronos spec 
> > > must be named metadata whereas clang emits function metadata).
> > > 
> > > > I am slightly confused as in the LLVM project those address spaces are 
> > > > for SPIR not SPIR-V though.
> > > [skip]
> > > > Their conceptual differences are just that they are two different 
> > > > intermediate formats.
> > > 
> > > If this is the only difference, I don't think it a good idea to create 
> > > another LLVM target to separate SPIR and SPIR-V. From my point of view it 
> > > creates logic ambiguity and code duplication with no additional value. 
> > > @Anastasia, what problems do you see if we continue treating LLVM IR with 
> > > spir* target triple as LLVM IR representation of SPIR-V format?
> > The state of SPIR 1.2/2.0 in Clang seems to be that the SPIR target has 
> > transformed to mean “SPIR 1.2/2.0 derivative”, but that does not still make 
> > it SPIR-V, which is not based on LLVM IR. When one is targeting spir* there 
> > is ambiguity on whether one is aiming to produce the old-SPIR-derivative or 
> > SPIR-V. Considering that there are still SPIR-derivative consumers, in my 
> > opinion we should have separate LLVM targets for SPIR-V to have explicit 
> > disambiguation of intent for producing the SPIR-derivative vs SPIR-V.
> @bade

[PATCH] D109517: [Clang][ARM][AArch64] Add support for Armv9-A, Armv9.1-A and Armv9.2-A

2021-09-21 Thread Victor Campos via Phabricator via cfe-commits
vhscampos updated this revision to Diff 373943.
vhscampos added a comment.

1. Fix bug in "+sve2" feature position in the target features list. It was 
being inserted at the end, which made it impossible to disable it using 
+nosve2, as the positive option would always be placed after the negative one.
2. Add tests to the bug fix above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109517

Files:
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arm-cortex-cpus.c
  clang/test/Preprocessor/aarch64-target-features.c
  clang/test/Preprocessor/arm-target-features.c
  llvm/include/llvm/ADT/Triple.h
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/lib/Support/ARMTargetParser.cpp
  llvm/lib/Support/Triple.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
  llvm/lib/Target/ARM/ARM.td
  llvm/lib/Target/ARM/ARMSubtarget.h
  llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
  llvm/test/MC/AArch64/SME/directives-negative.s
  llvm/test/MC/AArch64/SME/directives.s
  llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
  llvm/test/MC/AArch64/SVE2/directive-arch.s
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -31,6 +31,7 @@
 "armv8.5a","armv8.6-a","armv8.6a","armv8.7-a","armv8.7a",
 "armv8-r", "armv8r",   "armv8-m.base","armv8m.base",  "armv8-m.main",
 "armv8m.main", "iwmmxt",   "iwmmxt2", "xscale",   "armv8.1-m.main",
+"armv9-a", "armv9.1-a","armv9.2-a",
 };
 
 template 
@@ -492,6 +493,15 @@
   EXPECT_TRUE(
   testARMArch("armv8.7-a", "generic", "v8.7a",
   ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(
+  testARMArch("armv9-a", "generic", "v9a",
+  ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(
+  testARMArch("armv9.1-a", "generic", "v9.1a",
+  ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(
+  testARMArch("armv9.2-a", "generic", "v9.2a",
+  ARMBuildAttrs::CPUArch::v8_A));
   EXPECT_TRUE(
   testARMArch("armv8-r", "cortex-r52", "v8r",
   ARMBuildAttrs::CPUArch::v8_R));
@@ -821,6 +831,9 @@
 case ARM::ArchKind::ARMV8_5A:
 case ARM::ArchKind::ARMV8_6A:
 case ARM::ArchKind::ARMV8_7A:
+case ARM::ArchKind::ARMV9A:
+case ARM::ArchKind::ARMV9_1A:
+case ARM::ArchKind::ARMV9_2A:
   EXPECT_EQ(ARM::ProfileKind::A, ARM::parseArchProfile(ARMArch[i]));
   break;
 default:
@@ -1204,6 +1217,12 @@
   ARMBuildAttrs::CPUArch::v8_A));
   EXPECT_TRUE(testAArch64Arch("armv8.7-a", "generic", "v8.7a",
   ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(testAArch64Arch("armv9-a", "generic", "v9a",
+  ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(testAArch64Arch("armv9.1-a", "generic", "v9.1a",
+  ARMBuildAttrs::CPUArch::v8_A));
+  EXPECT_TRUE(testAArch64Arch("armv9.2-a", "generic", "v9.2a",
+  ARMBuildAttrs::CPUArch::v8_A));
 }
 
 bool testAArch64Extension(StringRef CPUName, AArch64::ArchKind AK,
Index: llvm/test/MC/AArch64/SVE2/directive-arch.s
===
--- llvm/test/MC/AArch64/SVE2/directive-arch.s
+++ llvm/test/MC/AArch64/SVE2/directive-arch.s
@@ -1,21 +1,21 @@
 // RUN: llvm-mc -triple aarch64 -filetype asm -o - %s 2>&1 | FileCheck %s
 
-.arch armv8-a+sve2
+.arch armv9-a+sve2
 tbx z0.b, z1.b, z2.b
 // CHECK: tbx z0.b, z1.b, z2.b
 
-.arch armv8-a+sve2-aes
+.arch armv9-a+sve2-aes
 aesd z23.b, z23.b, z13.b
 // CHECK: aesd z23.b, z23.b, z13.b
 
-.arch armv8-a+sve2-sm4
+.arch armv9-a+sve2-sm4
 sm4e z0.s, z0.s, z0.s
 // CHECK: sm4e z0.s, z0.s, z0.s
 
-.arch armv8-a+sve2-sha3
+.arch armv9-a+sve2-sha3
 rax1 z0.d, z0.d, z0.d
 // CHECK: rax1 z0.d, z0.d, z0.d
 
-.arch armv8-a+sve2-bitperm
+.arch armv9-a+sve2-bitperm
 bgrp z21.s, z10.s, z21.s
 // CHECK: bgrp z21.s, z10.s, z21.s
Index: llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
===
--- llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
+++ llvm/test/MC/AArch64/SVE2/directive-arch-negative.s
@@ -1,31 +1,31 @@
 // RUN: not llvm-mc -triple aarch64 -filetype asm -o - %s 2>&1 | FileCheck %s
 
-.arch armv8-a+sve2
-.a

[PATCH] D109517: [Clang][ARM][AArch64] Add support for Armv9-A, Armv9.1-A and Armv9.2-A

2021-09-21 Thread Victor Campos via Phabricator via cfe-commits
vhscampos requested review of this revision.
vhscampos added a comment.

Sorry @SjoerdMeijer , I found a bug in the implementation (as described in the 
latest comment). Therefore I kindly ask another round of review, please.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109517

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


[PATCH] D110130: [clangd] Semantic highlighting for lambda init-capture

2021-09-21 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

Naming of the patch is a little bit confusing. We're actually dropping the 
semantic highlighting for the type of lambdacaptures, which was showing up in 
the declarator names since there was no explicit type spelled in the source 
code. This turns on highlighting for the capture variables because we're left 
with a single token now.

Can you reword the description to reflect that?




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:515
   return true;
 if (auto K = kindForType(AT->getDeducedType().getTypePtrOrNull(),
  H.getResolver())) {

nit: while here do you mind turning this into an early exit as well? the 
nesting below seems a little distracting.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:522
+  // is the same as the location of the declared name itself.
+  if (StartLoc != D->getLocation()) {
+auto &Tok =

nridge wrote:
> Note, I initially tried `D->getTypeSpecStartLoc() != D->getTypeSpecEndLoc()`, 
> but it turns out they are equal both in the init-capture case and in the 
> regular `auto` case, so that check cannot be used to discriminate between the 
> two.
why not just check if `D` is implicit?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110130

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


[PATCH] D108560: [clang-tidy] Add support for NOLINTBEGIN ... NOLINTEND comments to suppress clang-tidy warnings over multiple lines

2021-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Sorry for not thinking of this sooner, but there is another diagnostic we might 
want to consider.

  // NOLINTBEGIN(check)
  // NOLINTEND(other-check)

where the file does not contain a `NOLINTEND(check)` comment anywhere. In this 
case, the markers are not actually matched, so it's a `NOLINTBEGIN(check)` 
comment with no end and a `NOLINTEND(other-check)` comment with no begin. That 
seems like user confusion we'd also want to diagnose, but it also could be 
tricky because you really want to add diagnostic arguments for the check name. 
My concern here is mostly with catching typos where the user types `check` in 
the first and `chekc` in the second, so if we wanted to use the edit distance 
between what was provided and the list of check names to provide a fix-it, that 
would be very handy (and also probably difficult to implement so I definitely 
don't insist on a fix-it).

Relatedly, I think this construct is perhaps fine:

  // NOLINTBEGIN(check)
  // NOLINTEND(*)

because the end "covers" the begin. I'm a bit less clear on this though:

  // NOLINTBEGIN(*)
  // NOLINTEND(check)

because the begin is not fully covered by the end. However, I'm a bit less 
clear on what should or should not be diagnosed here, so if we wanted to leave 
that for follow-up work, that'd be fine.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108560

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


[PATCH] D108560: [clang-tidy] Add support for NOLINTBEGIN ... NOLINTEND comments to suppress clang-tidy warnings over multiple lines

2021-09-21 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz updated this revision to Diff 373944.
salman-javed-nz marked 6 inline comments as done.
salman-javed-nz added a comment.

`lineIsWithinNolintBegin()`:

- If the search through the preceding lines returns no active `NOLINTBEGINs`, 
carry on reading the rest of the file anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108560

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/index.rst
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/error_in_include.inc
  
clang-tools-extra/test/clang-tidy/infrastructure/Inputs/nolintbeginend/nolint_in_include.inc
  clang-tools-extra/test/clang-tidy/infrastructure/nolint.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-at-eof.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-begin-without-end.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-at-sof.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-end-without-begin.cpp
  
clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend-mismatched-delims.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
  clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp

Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp
===
--- clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolintnextline.cpp
@@ -1,49 +1,51 @@
+// NOLINTNEXTLINE
 class A { A(int i); };
+
+class B { B(int i); };
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
 
 // NOLINTNEXTLINE
-class B { B(int i); };
+class C { C(int i); };
 
 // NOLINTNEXTLINE(for-some-other-check)
-class C { C(int i); };
+class D { D(int i); };
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
 
 // NOLINTNEXTLINE(*)
-class C1 { C1(int i); };
+class D1 { D1(int i); };
 
 // NOLINTNEXTLINE(not-closed-bracket-is-treated-as-skip-all
-class C2 { C2(int i); };
+class D2 { D2(int i); };
 
 // NOLINTNEXTLINE(google-explicit-constructor)
-class C3 { C3(int i); };
+class D3 { D3(int i); };
 
 // NOLINTNEXTLINE(some-check, google-explicit-constructor)
-class C4 { C4(int i); };
+class D4 { D4(int i); };
 
 // NOLINTNEXTLINE without-brackets-skip-all, another-check
-class C5 { C5(int i); };
-
+class D5 { D5(int i); };
 
 // NOLINTNEXTLINE
 
-class D { D(int i); };
+class E { E(int i); };
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
 
 // NOLINTNEXTLINE
 //
-class E { E(int i); };
+class F { F(int i); };
 // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
 
 #define MACRO(X) class X { X(int i); };
-MACRO(F)
+MACRO(G)
 // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: single-argument constructors must be marked explicit
 // NOLINTNEXTLINE
-MACRO(G)
+MACRO(H)
 
-#define MACRO_NOARG class H { H(int i); };
+#define MACRO_NOARG class I { I(int i); };
 // NOLINTNEXTLINE
 MACRO_NOARG
 
-// CHECK-MESSAGES: Suppressed 8 warnings (8 NOLINT)
+// CHECK-MESSAGES: Suppressed 9 warnings (9 NOLINT)
 
 // RUN: %check_clang_tidy %s google-explicit-constructor %t --
Index: clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/infrastructure/nolintbeginend.cpp
@@ -0,0 +1,127 @@
+// RUN: %check_clang_tidy %s google-explicit-constructor %t -- --header-filter=.* -system-headers -- -isystem %S/Inputs/nolintbeginend
+
+class A { A(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit
+
+// NOLINTBEGIN
+class B1 { B1(int i); };
+// NOLINTEND
+
+// NOLINTBEGIN
+// NOLINTEND
+// NOLINTBEGIN
+class B2 { B2(int i); };
+// NOLINTEND
+
+// NOLINTBEGIN
+// NOLINTBEGIN
+class B3 { B3(int i); };
+// NOLINTEND
+// NOLINTEND
+
+// NOLINTBEGIN
+// NOLINTBEGIN
+// NOLINTEND
+class B4 { B4(int i); };
+// NOLINTEND
+
+// NOLINTBEGIN
+// NOLINTEND
+class B5 { B5(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+
+// NOLINTBEGIN(google-explicit-constructor)
+class C1 { C1(int i); };
+// NOLINTEND(google-explicit-constructor)
+
+// NOLINTBEGIN(*)
+class C2 { C2(int i); };
+// NOLINTEND(*)
+
+// NOLINTBEGIN(some-other-check)
+class C3 { C3(int i); };
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+// NOLINTEND(some-other-check)
+
+// NOLINTBEGIN(some-other-check, google-explicit-constructor)
+

[PATCH] D110155: [OpenCL] Allow optional __generic in __remove_address_space utility

2021-09-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110155

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


[PATCH] D108560: [clang-tidy] Add support for NOLINTBEGIN ... NOLINTEND comments to suppress clang-tidy warnings over multiple lines

2021-09-21 Thread Salman Javed via Phabricator via cfe-commits
salman-javed-nz added a comment.

In D108560#3012057 , @aaron.ballman 
wrote:

> Thanks, I think this is getting close! There are two more test cases that I 
> think are interesting (and should cause any issues, hopefully):
>
>   // NOLINTEND
>   // CHECK-MESSAGES: for diagnostic on the previous line
>
> and
>
>   // CHECK-MESSAGES: for diagnostic on the subsequent line
>   // NOLINTBEGIN
>
> as the only contents in the file. The idea is that we want to check that 
> searching for a "begin" when seeing an "end" at the top of the file doesn't 
> do anything silly like try to read off the start of the file, and similar for 
> "end" when seeing a "begin" at the end of a file.

The good news is that the program does not do anything silly like read off the 
boundaries of the file. :-)
What is noteworthy, however, is that in 
`test/clang-tidy/infrastructure/nolintbeginend-begin-at-eof.cpp` only the 
original clang-tidy check diag is shown, not the diag about the unmatched 
NOLINTBEGIN. This is because of the early exit in `lineIsWithinNolintBegin()`:

  // Check if there's an open NOLINT(BEGIN...END) block on the previous lines.
  // ...
  auto Error = tallyNolintBegins(Context, SM, CheckName, PrevLines,
 FileStartLoc, NolintBegins);
  // ...
  if (NolintBegins.empty())
return false;
  
  // Check that every block is terminated correctly on the following lines.
  // ...

This has been fixed in the patch I just posted.

As for your latest message about NOLINTBEGIN(check) ... NOLINTEND(other-check), 
I'll have a think about it and get back to you in a day or two.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D108560

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


[PATCH] D110160: [clang][tooling] NFC: Refactor command-line diagnostic tests

2021-09-21 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added inline comments.



Comment at: clang/unittests/Tooling/ToolingTest.cpp:238-245
   Args.push_back("tool-executable");
-  Args.push_back("-target");
-  // Invalid argument that by default results in an error diagnostic:
-  Args.push_back("i386-apple-ios14.0-simulator");
-  // Argument that downgrades the error into a warning:
-  Args.push_back("-Wno-error=invalid-ios-deployment-target");
+  // Invalid argument (non-existent sysroot path) that will result in a 
warning.
+  Args.push_back("-isysroot");
+  Args.push_back("/dev/null/sysroot");
+  // Argument that will suppress the warning above.
+  Args.push_back("-Wno-missing-sysroot");
   Args.push_back("-fsyntax-only");

I'm worried this is going to behave differently when the unit test isn't run on 
Darwin, since I think `-isysroot` is only valid for Darwin targets and there's 
no `-arch` or `-target` option. Can you confirm whether this should reproduce 
properly when run on other hosts as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110160

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


[PATCH] D110068: [Clang][AST] Resolve FIXME: Remove ObjCObjectPointer from isSpecifierType

2021-09-21 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 373955.
gAlfonso-bit added a comment.

Rebased to upstream


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

https://reviews.llvm.org/D110068

Files:
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -310,7 +310,6 @@
   SaveAndRestore PrevPHIsEmpty(HasEmptyPlaceHolder);
 
   // Print qualifiers as appropriate.
-
   bool CanPrefixQualifiers = false;
   bool NeedARCStrongQualifier = false;
   CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2785,7 +2785,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -153,11 +153,14 @@
   while (!BaseType->isSpecifierType()) {
 if (const PointerType *PTy = BaseType->getAs())
   BaseType = PTy->getPointeeType();
+else if (const ObjCObjectPointerType *OPT =
+ BaseType->getAs())
+  BaseType = OPT->getPointeeType();
 else if (const BlockPointerType *BPy = BaseType->getAs())
   BaseType = BPy->getPointeeType();
-else if (const ArrayType* ATy = dyn_cast(BaseType))
+else if (const ArrayType *ATy = dyn_cast(BaseType))
   BaseType = ATy->getElementType();
-else if (const FunctionType* FTy = BaseType->getAs())
+else if (const FunctionType *FTy = BaseType->getAs())
   BaseType = FTy->getReturnType();
 else if (const VectorType *VTy = BaseType->getAs())
   BaseType = VTy->getElementType();


Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -310,7 +310,6 @@
   SaveAndRestore PrevPHIsEmpty(HasEmptyPlaceHolder);
 
   // Print qualifiers as appropriate.
-
   bool CanPrefixQualifiers = false;
   bool NeedARCStrongQualifier = false;
   CanPrefixQualifiers = canPrefixQualifiers(T, NeedARCStrongQualifier);
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2785,7 +2785,6 @@
   case DependentTemplateSpecialization:
   case ObjCInterface:
   case ObjCObject:
-  case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
 return true;
   default:
 return false;
Index: clang/lib/AST/DeclPrinter.cpp
===
--- clang/lib/AST/DeclPrinter.cpp
+++ clang/lib/AST/DeclPrinter.cpp
@@ -153,11 +153,14 @@
   while (!BaseType->isSpecifierType()) {
 if (const PointerType *PTy = BaseType->getAs())
   BaseType = PTy->getPointeeType();
+else if (const ObjCObjectPointerType *OPT =
+ BaseType->getAs())
+  BaseType = OPT->getPointeeType();
 else if (const BlockPointerType *BPy = BaseType->getAs())
   BaseType = BPy->getPointeeType();
-else if (const ArrayType* ATy = dyn_cast(BaseType))
+else if (const ArrayType *ATy = dyn_cast(BaseType))
   BaseType = ATy->getElementType();
-else if (const FunctionType* FTy = BaseType->getAs())
+else if (const FunctionType *FTy = BaseType->getAs())
   BaseType = FTy->getReturnType();
 else if (const VectorType *VTy = BaseType->getAs())
   BaseType = VTy->getElementType();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69764: [clang-format] Add Left/Right Const fixer capability

2021-09-21 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay updated this revision to Diff 373954.
MyDeveloperDay added a comment.

Its no longer essential to compare the fixes against the original code, as this 
was needed because of an artifact with adding double spaces and was resolved 
with checking for if the previous token already ended or started with a space, 
(this speeds things up a little).

Added a unit test to validate that const splitting unsigned and char correctly 
resolves.


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

https://reviews.llvm.org/D69764

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h
  clang/lib/Format/CMakeLists.txt
  clang/lib/Format/Format.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/QualifierAlignmentFixer.h
  clang/tools/clang-format/ClangFormat.cpp
  clang/unittests/Format/CMakeLists.txt
  clang/unittests/Format/FormatTest.cpp
  clang/unittests/Format/QualifierFixerTest.cpp

Index: clang/unittests/Format/QualifierFixerTest.cpp
===
--- /dev/null
+++ clang/unittests/Format/QualifierFixerTest.cpp
@@ -0,0 +1,905 @@
+//===- unittest/Format/QualifierFixerTest.cpp - Formatting unit tests -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "FormatTestUtils.h"
+#include "TestLexer.h"
+#include "gtest/gtest.h"
+
+#include "../../lib/Format/QualifierAlignmentFixer.h"
+
+#define DEBUG_TYPE "format-qualifier-fixer-test"
+
+using testing::ScopedTrace;
+
+namespace clang {
+namespace format {
+namespace {
+
+#define CHECK_PARSE(TEXT, FIELD, VALUE)\
+  EXPECT_NE(VALUE, Style.FIELD) << "Initial value already the same!";  \
+  EXPECT_EQ(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+#define FAIL_PARSE(TEXT, FIELD, VALUE) \
+  EXPECT_NE(0, parseConfiguration(TEXT, &Style).value());  \
+  EXPECT_EQ(VALUE, Style.FIELD) << "Unexpected value after parsing!"
+
+class QualifierFixerTest : public ::testing::Test {
+protected:
+  enum StatusCheck { SC_ExpectComplete, SC_ExpectIncomplete, SC_DoNotCheck };
+
+  TokenList annotate(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+return TestLexer(Allocator, Buffers, Style).annotate(Code);
+  }
+  llvm::SpecificBumpPtrAllocator Allocator;
+  std::vector> Buffers;
+
+  std::string format(llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle(),
+ StatusCheck CheckComplete = SC_ExpectComplete) {
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(0, Code.size()));
+FormattingAttemptStatus Status;
+tooling::Replacements Replaces =
+reformat(Style, Code, Ranges, "", &Status);
+if (CheckComplete != SC_DoNotCheck) {
+  bool ExpectedCompleteFormat = CheckComplete == SC_ExpectComplete;
+  EXPECT_EQ(ExpectedCompleteFormat, Status.FormatComplete)
+  << Code << "\n\n";
+}
+ReplacementCount = Replaces.size();
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  FormatStyle getStyleWithColumns(FormatStyle Style, unsigned ColumnLimit) {
+Style.ColumnLimit = ColumnLimit;
+return Style;
+  }
+
+  FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) {
+return getStyleWithColumns(getLLVMStyle(), ColumnLimit);
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Expected,
+ llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+ScopedTrace t(File, Line, ::testing::Message() << Code.str());
+EXPECT_EQ(Expected.str(), format(Expected, Style))
+<< "Expected code is not stable";
+EXPECT_EQ(Expected.str(), format(Code, Style));
+if (Style.Language == FormatStyle::LK_Cpp) {
+  // Objective-C++ is a superset of C++, so everything checked for C++
+  // needs to be checked for Objective-C++ as well.
+  FormatStyle ObjCStyle = Style;
+  ObjCStyle.Language = FormatStyle::LK_ObjC;
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
+}
+  }
+
+  void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
+ const FormatStyle &Style = getLLVMStyle()) {
+_verifyFormat(File, Line, Code, te

[PATCH] D106876: Remove non-affecting module maps from PCM files.

2021-09-21 Thread Ilya Kuteev via Phabricator via cfe-commits
ilyakuteev updated this revision to Diff 373957.

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

https://reviews.llvm.org/D106876

Files:
  clang/include/clang/Serialization/ASTWriter.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
  clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
  clang/test/Modules/add-remove-irrelevant-mobile-map.m
  clang/test/SemaCXX/compare-modules-cxx2a.cpp

Index: clang/test/SemaCXX/compare-modules-cxx2a.cpp
===
--- clang/test/SemaCXX/compare-modules-cxx2a.cpp
+++ clang/test/SemaCXX/compare-modules-cxx2a.cpp
@@ -1,15 +1,7 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -verify -std=c++2a -fmodules -I%S/Inputs %s -fno-modules-error-recovery
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
 
-#pragma clang module build compare
-module compare {
-  explicit module cmp {}
-  explicit module other {}
-}
-#pragma clang module contents
-#pragma clang module begin compare.cmp
-#include "std-compare.h"
-#pragma clang module end
-#pragma clang module endbuild
+// RUN: %clang_cc1 -triple x86_64-apple-darwin -fcxx-exceptions -verify -std=c++2a -fmodules -fmodules-cache-path=%t.mcp -I%S/Inputs %s -fno-modules-error-recovery -fmodule-map-file=%S/Inputs/compare.modulemap
 
 struct CC { CC(...); };
 
@@ -24,10 +16,10 @@
 
 // expected-note@std-compare.h:* 2+{{not reachable}}
 
-void b() { void(0 <=> 0); } // expected-error 1+{{missing '#include "std-compare.h"'; 'strong_ordering' must be defined}}
+void b() { void(0 <=> 0); } // expected-error 1+{{definition of 'strong_ordering' must be imported from module 'compare.cmp' before it is required}}
 
 struct B {
-  CC operator<=>(const B&) const = default; // expected-error 1+{{missing '#include "std-compare.h"'; 'strong_ordering' must be defined}}
+  CC operator<=>(const B&) const = default; // expected-error 1+{{definition of 'strong_ordering' must be imported from module 'compare.cmp' before it is required}}
 };
 auto vb = B() <=> B(); // expected-note {{required here}}
 
Index: clang/test/Modules/add-remove-irrelevant-mobile-map.m
===
--- /dev/null
+++ clang/test/Modules/add-remove-irrelevant-mobile-map.m
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: rm -rf %t.mcp
+// RUN: mkdir -p %t
+
+// Build without b.modulemap
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap %s -verify
+// RUN: cp %t.mcp/a.pcm %t/a.pcm
+
+// Build with b.modulemap
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -fdisable-module-hash -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap -fmodule-map-file=%S/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap %s -verify
+// RUN: not diff %t.mcp/a.pcm %t/a.pcm
+
+// expected-no-diagnostics
+
+@import a;
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/b.modulemap
@@ -0,0 +1 @@
+module b { }
Index: clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
===
--- /dev/null
+++ clang/test/Modules/Inputs/AddRemoveIrrelevantModuleMap/a.modulemap
@@ -0,0 +1 @@
+module a { }
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -149,6 +149,59 @@
 
 namespace {
 
+std::set GetAllModuleMaps(const HeaderSearch &HS,
+ Module *RootModule) {
+  std::set ModuleMaps{};
+  std::set ProcessedModules;
+  SmallVector ModulesToProcess{RootModule};
+
+  SmallVector FilesByUID;
+  HS.getFileMgr().GetUniqueIDMapping(FilesByUID);
+
+  if (FilesByUID.size() > HS.header_file_size())
+FilesByUID.resize(HS.header_file_size());
+
+  for (unsigned UID = 0, LastUID = FilesByUID.size(); UID != LastUID; ++UID) {
+const FileEntry *File = FilesByUID[UID];
+if (!File)
+  continue;
+
+const HeaderFileInfo *HFI =
+HS.getExistingFileInfo(File, /*WantExternal*/ false);
+if (!HFI || (HFI->isModuleHeader && !HFI->isCompilingModuleHeader))
+  continue;
+
+for (const auto &KH : HS.findAllModulesForHeader(File)) {
+  if (!KH.getModule())
+continue;
+  ModulesToProcess.push_back(KH.getModule());
+}
+  }
+
+  while (!ModulesToProcess.empty()) {
+auto *CurrentModule = ModulesToProcess.pop_back_val();
+ProcessedModules.insert(CurrentModule);
+
+auto *ModuleMapFile =
+HS.getModuleMap().getModuleMapFileForUniquing(CurrentModule);
+if (!ModuleMapFi

[PATCH] D110029: [OpenMP][Offloading] Use bitset to indicate execution mode instead of value

2021-09-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 updated this revision to Diff 373961.
tianshilei1992 added a comment.

fix comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110029

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/test/Transforms/OpenMP/get_hardware_num_threads_in_block_fold.ll
  llvm/test/Transforms/OpenMP/is_spmd_exec_mode_fold.ll
  llvm/test/Transforms/OpenMP/spmdization.ll
  llvm/test/Transforms/OpenMP/spmdization_assumes.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  openmp/libomptarget/plugins/cuda/CMakeLists.txt
  openmp/libomptarget/plugins/cuda/src/rtl.cpp

Index: openmp/libomptarget/plugins/cuda/src/rtl.cpp
===
--- openmp/libomptarget/plugins/cuda/src/rtl.cpp
+++ openmp/libomptarget/plugins/cuda/src/rtl.cpp
@@ -28,6 +28,8 @@
 
 #include "MemoryManager.h"
 
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+
 // Utility for retrieving and printing CUDA error string.
 #ifdef OMPTARGET_DEBUG
 #define CUDA_ERR_STRING(err)   \
@@ -71,28 +73,18 @@
   std::vector<__tgt_offload_entry> Entries;
 };
 
-enum ExecutionModeType {
-  SPMD, // constructors, destructors,
-// combined constructs (`teams distribute parallel for [simd]`)
-  GENERIC,  // everything else
-  SPMD_GENERIC, // Generic kernel with SPMD execution
-  NONE
-};
-
 /// Use a single entity to encode a kernel and a set of flags.
 struct KernelTy {
   CUfunction Func;
 
   // execution mode of kernel
-  // 0 - SPMD mode (without master warp)
-  // 1 - Generic mode (with master warp)
-  // 2 - SPMD mode execution with Generic mode semantics.
-  int8_t ExecutionMode;
+  llvm::omp::OMPTargetExecutionModeMaskType ExecutionMode;
 
   /// Maximal number of threads per block for this kernel.
   int MaxThreadsPerBlock = 0;
 
-  KernelTy(CUfunction _Func, int8_t _ExecutionMode)
+  KernelTy(CUfunction _Func,
+   llvm::omp::OMPTargetExecutionModeMaskType _ExecutionMode)
   : Func(_Func), ExecutionMode(_ExecutionMode) {}
 };
 
@@ -867,7 +859,7 @@
  DPxPTR(E - HostBegin), E->name, DPxPTR(Func));
 
   // default value GENERIC (in case symbol is missing from cubin file)
-  int8_t ExecModeVal = ExecutionModeType::GENERIC;
+  llvm::omp::OMPTargetExecutionModeMaskType ExecModeVal;
   std::string ExecModeNameStr(E->name);
   ExecModeNameStr += "_exec_mode";
   const char *ExecModeName = ExecModeNameStr.c_str();
@@ -876,9 +868,10 @@
   size_t CUSize;
   Err = cuModuleGetGlobal(&ExecModePtr, &CUSize, Module, ExecModeName);
   if (Err == CUDA_SUCCESS) {
-if (CUSize != sizeof(int8_t)) {
+if (CUSize != sizeof(llvm::omp::OMPTargetExecutionModeMaskType)) {
   DP("Loading global exec_mode '%s' - size mismatch (%zd != %zd)\n",
- ExecModeName, CUSize, sizeof(int8_t));
+ ExecModeName, CUSize,
+ sizeof(llvm::omp::OMPTargetExecutionModeMaskType));
   return nullptr;
 }
 
@@ -890,12 +883,6 @@
   CUDA_ERR_STRING(Err);
   return nullptr;
 }
-
-if (ExecModeVal < 0 || ExecModeVal > 2) {
-  DP("Error wrong exec_mode value specified in cubin file: %d\n",
- ExecModeVal);
-  return nullptr;
-}
   } else {
 DP("Loading global exec_mode '%s' - symbol missing, using default "
"value GENERIC (1)\n",
@@ -1098,12 +1085,21 @@
 
 KernelTy *KernelInfo = reinterpret_cast(TgtEntryPtr);
 
+const bool IsSPMDGenericMode =
+KernelInfo->ExecutionMode ==
+llvm::omp::OMPTargetExecutionModeMaskType::GenericSPMD;
+const bool IsSPMDMode = KernelInfo->ExecutionMode ==
+llvm::omp::OMPTargetExecutionModeMaskType::SPMD;
+const bool IsGenericMode =
+KernelInfo->ExecutionMode ==
+llvm::omp::OMPTargetExecutionModeMaskType::Generic;
+
 int CudaThreadsPerBlock;
 if (ThreadLimit > 0) {
   DP("Setting CUDA threads per block to requested %d\n", ThreadLimit);
   CudaThreadsPerBlock = ThreadLimit;
   // Add master warp if necessary
-  if (KernelInfo->ExecutionMode == GENERIC) {
+  if (IsGenericMode) {
 DP("Adding master warp: +%d threads\n", DeviceData[DeviceId].WarpSize);
 CudaThreadsPerBlock += DeviceData[DeviceId].WarpSize;
   }
@@ -1136,13 +1132,21 @@
 unsigned int CudaBlocksPerGrid;
 if (TeamNum <= 0) {
   if (LoopTripCount > 0 && EnvNumTeams < 0) {
-if (KernelInfo->ExecutionMode == SPMD) {
+   

[PATCH] D110029: [OpenMP][Offloading] Use bitset to indicate execution mode instead of value

2021-09-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked 2 inline comments as done.
tianshilei1992 added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:134
+  SPMD = 0x2,
+};
+

jdoerfert wrote:
> If you copy the LLVM_MARK_AS_BITMASK_ENUM stuff you can actually use the enum 
> class as bitmask w/o the static casts all the time.
> I'd also suggest to create the combinations here, so GenericSPMD = Generic | 
> SPMD;.
That's very nice to know.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110029

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


[PATCH] D110029: [OpenMP][Offloading] Use bitset to indicate execution mode instead of value

2021-09-21 Thread Shilei Tian via Phabricator via cfe-commits
tianshilei1992 marked an inline comment as done.
tianshilei1992 added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:132
+enum class OMPTargetExecutionModeMaskType : int8_t {
+  Generic = 0x1,
+  SPMD = 0x2,

Do we want to set a `NONE = 0x0` here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110029

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


[PATCH] D108032: [analyzer] Retrieve a character from CompoundLiteralExpr as an initializer for constant arrays.

2021-09-21 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov updated this revision to Diff 373964.
ASDenysPetrov edited the summary of this revision.
ASDenysPetrov added a comment.

Rebased.


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

https://reviews.llvm.org/D108032

Files:
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/compound-literals.c

Index: clang/test/Analysis/compound-literals.c
===
--- clang/test/Analysis/compound-literals.c
+++ clang/test/Analysis/compound-literals.c
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -triple=i386-apple-darwin10 -verify %s -analyze \
-// RUN:   -analyzer-checker=debug.ExprInspection
+// RUN:   -analyzer-checker=debug.ExprInspection,core.uninitialized.Assign
 
 #define NULL 0
 void clang_analyzer_eval(int);
@@ -21,3 +21,63 @@
   clang_analyzer_eval(pointers[0] == NULL); // expected-warning{{FALSE}}
   clang_analyzer_eval(pointers[1] == NULL); // expected-warning{{TRUE}}
 }
+
+const int glob_arr1[8] = (const int[8]){[2] = 3, [0] = 1, [1] = 2, [3] = 4};
+void glob_arr_index1() {
+  clang_analyzer_eval(glob_arr1[0] == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr1[1] == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr1[2] == 3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr1[3] == 4); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr1[4] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr1[5] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr1[6] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr1[7] == 0); // expected-warning{{TRUE}}
+}
+
+void glob_invalid_index1() {
+  int x = -42;
+  int res = glob_arr1[x]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_invalid_index2() {
+  int x = 42;
+  int res = glob_arr1[x]; // expected-warning{{garbage or undefined}}
+}
+
+const int glob_arr2[8] = (const int[8]){1, 2, 3, 4};
+void glob_arr_index2() {
+  clang_analyzer_eval(glob_arr2[0] == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr2[1] == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr2[2] == 3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr2[3] == 4); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr2[4] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr2[5] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr2[6] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(glob_arr2[7] == 0); // expected-warning{{TRUE}}
+}
+
+void glob_ptr_index1() {
+  int const *ptr = glob_arr2;
+  clang_analyzer_eval(ptr[0] == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[1] == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[2] == 3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[3] == 4); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[4] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[5] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[6] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[7] == 0); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr[8] == 0); // expected-warning{{UNDEFINED}}
+  clang_analyzer_eval(ptr[9] == 0); // expected-warning{{UNDEFINED}}
+}
+
+void glob_invalid_index3() {
+  int const *ptr = glob_arr2;
+  int idx = -42;
+  int res = ptr[idx]; // expected-warning{{garbage or undefined}}
+}
+
+void glob_invalid_index4() {
+  int const *ptr = glob_arr2;
+  int idx = 42;
+  int res = ptr[idx]; // expected-warning{{garbage or undefined}}
+}
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -1680,52 +1680,63 @@
 QualType ElemT = R->getElementType();
 return getSValFromStringLiteralByIndex(SL, Idx, ElemT);
   }
-} else if (const auto *InitList = dyn_cast(Init)) {
-  // The array index has to be known.
-  if (auto CI = R->getIndex().getAs()) {
-// If it is not an array, return Undef.
-QualType T = VD->getType();
-const ConstantArrayType *CAT = Ctx.getAsConstantArrayType(T);
-if (!CAT)
-  return UndefinedVal();
-
-// Support one-dimensional array.
-// C++20 [expr.add] 7.6.6.4 (excerpt):
-//   If P points to an array element i of an array object x with n
-//   elements, where i < 0 or i > n, the behavior is undefined.
-//   Dereferencing is not allowed on the "one past the last
-//   element", when i == n.
-// Example:
-//   const int arr[4] = {1, 2};
-//   const int *ptr = arr;
-//   int x0 = ptr[0]; // 1
-//   int x1 = ptr[1]; // 2
-//   int x2 = ptr[2]; // 0
-//   int x3 = ptr[3]; // 0
-// 

[clang] 5793930 - [PowerPC] Fix signature of lxvp and stxvp builtins

2021-09-21 Thread Quinn Pham via cfe-commits

Author: Quinn Pham
Date: 2021-09-21T11:19:29-05:00
New Revision: 57939309501c33b264b777e04186c7747ebc3de1

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

LOG: [PowerPC] Fix signature of lxvp and stxvp builtins

This patch changes the signature of the load and store vector pair
builtins to match their documentation. The type of the `signed long long`
argument is changed to `signed long`. This patch also changes existing testcases
to match the signature change.

Reviewed By: lei, Conanap

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsPPC.def
clang/test/CodeGen/builtins-ppc-pair-mma.c
clang/test/Sema/ppc-pair-mma-types.c

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index 7a1795d9e550d..f3f8614f21ca0 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -813,8 +813,8 @@ BUILTIN(__builtin_dcbf, "vvC*", "")
 // its given accumulator.
 
 // Provided builtins with _mma_ prefix for compatibility.
-CUSTOM_BUILTIN(mma_lxvp, vsx_lxvp, "W256SLLiW256C*", false)
-CUSTOM_BUILTIN(mma_stxvp, vsx_stxvp, "vW256SLLiW256C*", false)
+CUSTOM_BUILTIN(mma_lxvp, vsx_lxvp, "W256SLiW256C*", false)
+CUSTOM_BUILTIN(mma_stxvp, vsx_stxvp, "vW256SLiW256C*", false)
 CUSTOM_BUILTIN(mma_assemble_pair, vsx_assemble_pair, "vW256*VV", false)
 CUSTOM_BUILTIN(mma_disassemble_pair, vsx_disassemble_pair, "vv*W256*", false)
 
@@ -823,8 +823,8 @@ CUSTOM_BUILTIN(mma_disassemble_pair, vsx_disassemble_pair, 
"vv*W256*", false)
 // ID and INTR are the same.
 // This avoids repeating the ID and INTR in the macro expression.
 
-UNALIASED_CUSTOM_BUILTIN(vsx_lxvp, "W256SLLiW256C*", false)
-UNALIASED_CUSTOM_BUILTIN(vsx_stxvp, "vW256SLLiW256C*", false)
+UNALIASED_CUSTOM_BUILTIN(vsx_lxvp, "W256SLiW256C*", false)
+UNALIASED_CUSTOM_BUILTIN(vsx_stxvp, "vW256SLiW256C*", false)
 UNALIASED_CUSTOM_BUILTIN(vsx_assemble_pair, "vW256*VV", false)
 UNALIASED_CUSTOM_BUILTIN(vsx_disassemble_pair, "vv*W256*", false)
 

diff  --git a/clang/test/CodeGen/builtins-ppc-pair-mma.c 
b/clang/test/CodeGen/builtins-ppc-pair-mma.c
index b8dda03498044..ef13348276a64 100644
--- a/clang/test/CodeGen/builtins-ppc-pair-mma.c
+++ b/clang/test/CodeGen/builtins-ppc-pair-mma.c
@@ -1049,8 +1049,8 @@ void test65(unsigned char *vqp, unsigned char *vpp, 
vector unsigned char vc, uns
 // CHECK-NEXT:ret void
 //
 void test66(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(0LL, vpp);
-  __builtin_vsx_stxvp(vp, 0LL, vp2);
+  __vector_pair vp = __builtin_vsx_lxvp(0L, vpp);
+  __builtin_vsx_stxvp(vp, 0L, vp2);
 }
 
 // CHECK-LABEL: @test67(
@@ -1063,7 +1063,7 @@ void test66(const __vector_pair *vpp, const __vector_pair 
*vp2) {
 // CHECK-NEXT:tail call void @llvm.ppc.vsx.stxvp(<256 x i1> [[TMP2]], i8* 
[[TMP4]])
 // CHECK-NEXT:ret void
 //
-void test67(const __vector_pair *vpp, signed long long offset, const 
__vector_pair *vp2) {
+void test67(const __vector_pair *vpp, signed long offset, const __vector_pair 
*vp2) {
   __vector_pair vp = __builtin_vsx_lxvp(offset, vpp);
   __builtin_vsx_stxvp(vp, offset, vp2);
 }
@@ -1079,8 +1079,8 @@ void test67(const __vector_pair *vpp, signed long long 
offset, const __vector_pa
 // CHECK-NEXT:ret void
 //
 void test68(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(18LL, vpp);
-  __builtin_vsx_stxvp(vp, 18LL, vp2);
+  __vector_pair vp = __builtin_vsx_lxvp(18L, vpp);
+  __builtin_vsx_stxvp(vp, 18L, vp2);
 }
 
 // CHECK-LABEL: @test69(
@@ -1094,8 +1094,8 @@ void test68(const __vector_pair *vpp, const __vector_pair 
*vp2) {
 // CHECK-NEXT:ret void
 //
 void test69(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(1LL, vpp);
-  __builtin_vsx_stxvp(vp, 1LL, vp2);
+  __vector_pair vp = __builtin_vsx_lxvp(1L, vpp);
+  __builtin_vsx_stxvp(vp, 1L, vp2);
 }
 
 // CHECK-LABEL: @test70(
@@ -1109,8 +1109,8 @@ void test69(const __vector_pair *vpp, const __vector_pair 
*vp2) {
 // CHECK-NEXT:ret void
 //
 void test70(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(42LL, vpp);
-  __builtin_vsx_stxvp(vp, 42LL, vp2);
+  __vector_pair vp = __builtin_vsx_lxvp(42L, vpp);
+  __builtin_vsx_stxvp(vp, 42L, vp2);
 }
 
 // CHECK-LABEL: @test71(
@@ -1124,8 +1124,8 @@ void test70(const __vector_pair *vpp, const __vector_pair 
*vp2) {
 // CHECK-NEXT:ret void
 //
 void test71(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(32768LL, vpp);
-  __builtin_vsx_stxvp(vp, 32768LL, vp2);
+  __vector_pair vp = __builtin_vsx_lxvp

[PATCH] D109996: [PowerPC] Fix signature of lxvp and stxvp builtins

2021-09-21 Thread Quinn Pham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG57939309501c: [PowerPC] Fix signature of lxvp and stxvp 
builtins (authored by quinnp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109996

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/test/CodeGen/builtins-ppc-pair-mma.c
  clang/test/Sema/ppc-pair-mma-types.c

Index: clang/test/Sema/ppc-pair-mma-types.c
===
--- clang/test/Sema/ppc-pair-mma-types.c
+++ clang/test/Sema/ppc-pair-mma-types.c
@@ -322,16 +322,16 @@
 }
 
 void testBuiltinTypes1(const __vector_pair *vpp, const __vector_pair *vp2, float f) {
-  __vector_pair vp = __builtin_vsx_lxvp(f, vpp); // expected-error {{passing 'float' to parameter of incompatible type 'long long'}}
-  __builtin_vsx_stxvp(vp, 32799, vp2);   // expected-error {{passing 'int' to parameter of incompatible type 'long long'}}
+  __vector_pair vp = __builtin_vsx_lxvp(f, vpp); // expected-error {{passing 'float' to parameter of incompatible type 'long'}}
+  __builtin_vsx_stxvp(vp, 32799, vp2);   // expected-error {{passing 'int' to parameter of incompatible type 'long'}}
 }
 
 void testBuiltinTypes2(__vector_pair *vpp, const __vector_pair *vp2, unsigned char c) {
-  __vector_pair vp = __builtin_vsx_lxvp(6LL, vpp); // expected-error {{passing '__vector_pair *' to parameter of incompatible type 'const __vector_pair *'}}
-  __builtin_vsx_stxvp(vp, c, vp2); // expected-error {{passing 'unsigned char' to parameter of incompatible type 'long long'}}
+  __vector_pair vp = __builtin_vsx_lxvp(6L, vpp); // expected-error {{passing '__vector_pair *' to parameter of incompatible type 'const __vector_pair *'}}
+  __builtin_vsx_stxvp(vp, c, vp2);// expected-error {{passing 'unsigned char' to parameter of incompatible type 'long'}}
 }
 
-void testBuiltinTypes3(vector int v, __vector_pair *vp2, signed long long ll, unsigned short s) {
-  __vector_pair vp = __builtin_vsx_lxvp(ll, v); // expected-error {{passing '__vector int' (vector of 4 'int' values) to parameter of incompatible type 'const __vector_pair *'}}
-  __builtin_vsx_stxvp(vp, ll, s);   // expected-error {{passing 'unsigned short' to parameter of incompatible type 'const __vector_pair *'}}
+void testBuiltinTypes3(vector int v, __vector_pair *vp2, signed long l, unsigned short s) {
+  __vector_pair vp = __builtin_vsx_lxvp(l, v); // expected-error {{passing '__vector int' (vector of 4 'int' values) to parameter of incompatible type 'const __vector_pair *'}}
+  __builtin_vsx_stxvp(vp, l, s);   // expected-error {{passing 'unsigned short' to parameter of incompatible type 'const __vector_pair *'}}
 }
Index: clang/test/CodeGen/builtins-ppc-pair-mma.c
===
--- clang/test/CodeGen/builtins-ppc-pair-mma.c
+++ clang/test/CodeGen/builtins-ppc-pair-mma.c
@@ -1049,8 +1049,8 @@
 // CHECK-NEXT:ret void
 //
 void test66(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(0LL, vpp);
-  __builtin_vsx_stxvp(vp, 0LL, vp2);
+  __vector_pair vp = __builtin_vsx_lxvp(0L, vpp);
+  __builtin_vsx_stxvp(vp, 0L, vp2);
 }
 
 // CHECK-LABEL: @test67(
@@ -1063,7 +1063,7 @@
 // CHECK-NEXT:tail call void @llvm.ppc.vsx.stxvp(<256 x i1> [[TMP2]], i8* [[TMP4]])
 // CHECK-NEXT:ret void
 //
-void test67(const __vector_pair *vpp, signed long long offset, const __vector_pair *vp2) {
+void test67(const __vector_pair *vpp, signed long offset, const __vector_pair *vp2) {
   __vector_pair vp = __builtin_vsx_lxvp(offset, vpp);
   __builtin_vsx_stxvp(vp, offset, vp2);
 }
@@ -1079,8 +1079,8 @@
 // CHECK-NEXT:ret void
 //
 void test68(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(18LL, vpp);
-  __builtin_vsx_stxvp(vp, 18LL, vp2);
+  __vector_pair vp = __builtin_vsx_lxvp(18L, vpp);
+  __builtin_vsx_stxvp(vp, 18L, vp2);
 }
 
 // CHECK-LABEL: @test69(
@@ -1094,8 +1094,8 @@
 // CHECK-NEXT:ret void
 //
 void test69(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(1LL, vpp);
-  __builtin_vsx_stxvp(vp, 1LL, vp2);
+  __vector_pair vp = __builtin_vsx_lxvp(1L, vpp);
+  __builtin_vsx_stxvp(vp, 1L, vp2);
 }
 
 // CHECK-LABEL: @test70(
@@ -1109,8 +1109,8 @@
 // CHECK-NEXT:ret void
 //
 void test70(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(42LL, vpp);
-  __builtin_vsx_stxvp(vp, 42LL, vp2);
+  __vector_pair vp = __builtin_vsx_lxvp(42L, vpp);
+  __builtin_vsx_stxvp(vp, 42L, vp2);
 }
 
 // CHECK-LABEL: @test71(
@@ -1124,8 +1124,8 @@
 // CHECK-NEXT:ret void
 //
 void test71(const __vector_pair *vpp, const __vector_pair *vp2) {
-  __vector_pair vp = __builtin_vsx_lxvp(32768LL, vpp);
-  __builtin_vsx_s

[clang] 73a8bcd - Revert "Diagnose -Wunused-value based on CFG reachability"

2021-09-21 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2021-09-21T12:25:13-04:00
New Revision: 73a8bcd78921d38130fc42c90fd75d47b05b063d

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

LOG: Revert "Diagnose -Wunused-value based on CFG reachability"

This reverts commit 63e0d038fc20c894a3d541effa1bc2b1fdea37b9.

It causes test failures:

http://lab.llvm.org:8011/#/builders/119/builds/5612
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8835548361443044001/+/u/clang/test/stdout

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/Analysis/dead-stores.c
clang/test/CXX/basic/basic.link/p8.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CXX/drs/dr7xx.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
clang/test/CodeCompletion/pragma-macro-token-caching.c
clang/test/Frontend/fixed_point_crash.c
clang/test/PCH/cxx-explicit-specifier.cpp
clang/test/Parser/cxx-ambig-decl-expr.cpp
clang/test/Parser/cxx0x-ambig.cpp
clang/test/Parser/cxx1z-init-statement.cpp
clang/test/Parser/objc-messaging-1.m
clang/test/Parser/objc-try-catch-1.m
clang/test/Parser/objcxx11-attributes.mm
clang/test/Sema/const-eval.c
clang/test/Sema/exprs.c
clang/test/Sema/i-c-e.c
clang/test/Sema/sizeless-1.c
clang/test/Sema/switch-1.c
clang/test/Sema/vla-2.c
clang/test/Sema/warn-type-safety.c
clang/test/Sema/warn-unused-value.c
clang/test/SemaCXX/attr-annotate.cpp
clang/test/SemaCXX/builtin-constant-p.cpp
clang/test/SemaCXX/constant-expression-cxx2a.cpp
clang/test/SemaCXX/constant-expression.cpp
clang/test/SemaCXX/expression-traits.cpp
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/overloaded-operator.cpp
clang/test/SemaCXX/sizeless-1.cpp
clang/test/SemaCXX/vector.cpp
clang/test/SemaCXX/warn-comma-operator.cpp
clang/test/SemaCXX/warn-unused-value.cpp
clang/test/SemaTemplate/derived.cpp
clang/test/SemaTemplate/lambda-capture-pack.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 530e8cf2e9725..3cadd986b8ae4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8565,9 +8565,6 @@ def err_typecheck_choose_expr_requires_constant : Error<
   "'__builtin_choose_expr' requires a constant expression">;
 def warn_unused_expr : Warning<"expression result unused">,
   InGroup;
-def warn_unused_comma_left_operand : Warning<
-  "left operand of comma operator has no effect">,
-  InGroup;
 def warn_unused_voidptr : Warning<
   "expression result unused; should this cast be to 'void'?">,
   InGroup;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index fc0b6919bd50b..93d5558b8267c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4912,7 +4912,7 @@ class Sema final {
 
   /// DiagnoseUnusedExprResult - If the statement passed in is an expression
   /// whose result is unused, warn.
-  void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID);
+  void DiagnoseUnusedExprResult(const Stmt *S);
   void DiagnoseUnusedNestedTypedefs(const RecordDecl *D);
   void DiagnoseUnusedDecl(const NamedDecl *ND);
 
@@ -5118,16 +5118,6 @@ class Sema final {
   /// conversion.
   ExprResult tryConvertExprToType(Expr *E, QualType Ty);
 
-  /// Conditionally issue a diagnostic based on the statement's reachability
-  /// analysis evaluation context.
-  ///
-  /// \param Statement If Statement is non-null, delay reporting the
-  /// diagnostic until the function body is parsed, and then do a basic
-  /// reachability analysis to determine if the statement is reachable.
-  /// If it is unreachable, the diagnostic will not be emitted.
-  bool DiagIfReachable(SourceLocation Loc, ArrayRef Stmts,
-   const PartialDiagnostic &PD);
-
   /// Conditionally issue a diagnostic based on the current
   /// evaluation context.
   ///

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 83ff35b056e2e..7991e4c5e8b0a 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -28,7 +28,6 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Builtins.h"
-#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
@@ -13372,7 +13371,7 @@ static QualType CheckCommaOperands(Se

[PATCH] D103938: Diagnose -Wunused-value based on CFG reachability

2021-09-21 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D103938#3012910 , @gulfem wrote:

> We also started seeing similar `libc++` test failures in our Fuchsia builds:
> https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8835548361443044001/+/u/clang/test/stdout
>
>   Failed Tests (89):
> libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/assign.pass.cpp
> libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/copy.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_result_type.pass.cpp
> libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_sseq.pass.cpp
> libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/default.pass.cpp
> libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/discard.pass.cpp
> libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/eval.pass.cpp
> libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/io.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_result_type.pass.cpp
> libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_sseq.pass.cpp
> libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval_param.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eval.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/assign.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/copy.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.eng/rand.eng.lcong/ctor_result_type.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/default.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/result_type.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/assign.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/copy.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.eng/rand.eng.mers/ctor_result_type.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/default.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/discard.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/eval.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/io.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/result_type.pass.cpp
> libc++ :: 
> std/numerics/rand/rand.eng/rand.eng.mers/seed_result_type.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/seed_sseq.pass.cpp
> libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp
> libc++ :: std/numerics/rand/rand.predef/mt19937_64.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.cons/default.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.hash/bitset.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.hash/enabled_hash.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/all.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/any.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/count.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/flip_all.pass.cpp
> libc++ :: 
> std/utilities/template.bitset/bitset.members/flip_one.out_of_range.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/flip_one.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/index.pass.cpp
> libc++ :: 
> std/utilities/template.bitset/bitset.members/index_const.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/left_shift.pass.cpp
> libc++ :: 
> std/utilities/template.bitset/bitset.members/left_shift_eq.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/none.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/not_all.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/op_and_eq.pass.cpp
> libc++ :: std/utilities/template.bitset/bitset.members/op_eq_eq.p

[PATCH] D103938: Diagnose -Wunused-value based on CFG reachability

2021-09-21 Thread Gulfem Savrun Yeniceri via Phabricator via cfe-commits
gulfem added a comment.

We also started seeing similar `libc++` test failures in our Fuchsia builds:
https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8835548361443044001/+/u/clang/test/stdout

  Failed Tests (89):
libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/assign.pass.cpp
libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/copy.pass.cpp
libc++ :: 
std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_result_type.pass.cpp
libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/ctor_sseq.pass.cpp
libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/default.pass.cpp
libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/discard.pass.cpp
libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/eval.pass.cpp
libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/io.pass.cpp
libc++ :: 
std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_result_type.pass.cpp
libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/seed_sseq.pass.cpp
libc++ :: std/numerics/rand/rand.adapt/rand.adapt.ibits/values.pass.cpp
libc++ :: 
std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval.pass.cpp
libc++ :: 
std/numerics/rand/rand.dis/rand.dist.bern/rand.dist.bern.bin/eval_param.pass.cpp
libc++ :: 
std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval.pass.cpp
libc++ :: 
std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.pconst/eval_param.pass.cpp
libc++ :: 
std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval.pass.cpp
libc++ :: 
std/numerics/rand/rand.dis/rand.dist.samp/rand.dist.samp.plinear/eval_param.pass.cpp
libc++ :: 
std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.int/eval.pass.cpp
libc++ :: 
std/numerics/rand/rand.dis/rand.dist.uni/rand.dist.uni.real/eval.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/assign.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/copy.pass.cpp
libc++ :: 
std/numerics/rand/rand.eng/rand.eng.lcong/ctor_result_type.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/default.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/result_type.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.lcong/values.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/assign.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/copy.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/ctor_result_type.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/ctor_sseq.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/default.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/discard.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/eval.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/io.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/result_type.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/seed_result_type.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/seed_sseq.pass.cpp
libc++ :: std/numerics/rand/rand.eng/rand.eng.mers/values.pass.cpp
libc++ :: std/numerics/rand/rand.predef/mt19937_64.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.cons/char_ptr_ctor.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.cons/default.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.cons/string_ctor.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.cons/ull_ctor.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.hash/bitset.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.hash/enabled_hash.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/all.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/any.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/count.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/flip_all.pass.cpp
libc++ :: 
std/utilities/template.bitset/bitset.members/flip_one.out_of_range.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/flip_one.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/index.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/index_const.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/left_shift.pass.cpp
libc++ :: 
std/utilities/template.bitset/bitset.members/left_shift_eq.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/none.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/not_all.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/op_and_eq.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/op_eq_eq.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/op_or_eq.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/op_xor_eq.pass.cpp
libc++ :: std/utilities/template.bitset/bitset.members/reset_all.pass.cpp
   

[clang] 8c68bd4 - [OpenMP][NFC] Add declare variant and metadirective to support page

2021-09-21 Thread via cfe-commits

Author: cchen
Date: 2021-09-21T11:28:13-05:00
New Revision: 8c68bd480f3d8a5bf6087f47837d320f9d6dba2d

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

LOG: [OpenMP][NFC] Add declare variant and metadirective to support page

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 23de4b5f0c2d4..0e3cd25e59e3c 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -235,7 +235,7 @@ implementation.
 
+--+--+--+---+
 | misc extension   | library shutdown (omp_pause_resource[_all])   
   | :none:`unclaimed parts`  | D55078  
  |
 
+--+--+--+---+
-| misc extension   | metadirectives
   | :part:`worked on`| 
  |
+| misc extension   | metadirectives
   | :part:`worked on`| D91944  
  |
 
+--+--+--+---+
 | misc extension   | conditional modifier for lastprivate clause   
   | :good:`done` | 
  |
 
+--+--+--+---+
@@ -243,7 +243,7 @@ implementation.
 
+--+--+--+---+
 | misc extension   | depobj directive and depobj dependency kind   
   | :good:`done` | 
  |
 
+--+--+--+---+
-| misc extension   | user-defined function variants
   | :part:`worked on`| D67294, D64095, D71847, D71830  
  |
+| misc extension   | user-defined function variants
   | :part:`worked on`| D67294, D64095, D71847, D71830, 
D109635   |
 
+--+--+--+---+
 | misc extension   | pointer/reference to pointer based array 
reductions  | :none:`unclaimed`|
   |
 
+--+--+--+---+



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


[PATCH] D103938: Diagnose -Wunused-value based on CFG reachability

2021-09-21 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

@uabelho @gulfem  Thanks for the remainder. I could not reproduce the issue 
with my Ubuntu box. Could you please attach a reproducer?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103938

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


[PATCH] D103938: Diagnose -Wunused-value based on CFG reachability

2021-09-21 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D103938#3012940 , @ychen wrote:

> @uabelho @gulfem  Thanks for the remainder. I could not reproduce the issue 
> with my Ubuntu box. Could you please attach a reproducer?

Never mind, I think I need "-Werror" to reproduce these.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103938

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


[PATCH] D108621: [HIPSPV] Add CUDA->SPIR-V address space mapping

2021-09-21 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: clang/lib/Basic/Targets/SPIR.h:59
+// translation). This mapping is enabled when the language mode is HIP.
+1, // cuda_device
+// cuda_constant pointer can be casted to default/"flat" pointer, but in

bader wrote:
> Anastasia wrote:
> > linjamaki wrote:
> > > bader wrote:
> > > > keryell wrote:
> > > > > Anastasia wrote:
> > > > > > bader wrote:
> > > > > > > Anastasia wrote:
> > > > > > > > I am slightly confused as in the LLVM project those address 
> > > > > > > > spaces are for SPIR not SPIR-V though. It is however used 
> > > > > > > > outside of LLVM project by some tools like SPIRV-LLVM 
> > > > > > > > Translator as a path to SPIR-V, but it has only been done as a 
> > > > > > > > workaround since we had no SPIR-V support in the LLVM project 
> > > > > > > > yet. And if we are adding it let's do it clean to avoid/resolve 
> > > > > > > > any confusion.
> > > > > > > > 
> > > > > > > > I think we need to keep both because some vendors do target/use 
> > > > > > > > SPIR but not SPIR-V.
> > > > > > > > 
> > > > > > > > So if you are interested in SPIR-V and not SPIR you should 
> > > > > > > > probably add a new target that will make things cleaner.
> > > > > > > > I think we need to keep both because some vendors do target/use 
> > > > > > > > SPIR but not SPIR-V.
> > > > > > > 
> > > > > > > @Anastasia, could you elaborate more on the difference between 
> > > > > > > SPIR and SPIR-V?
> > > > > > > I would like to understand what these terms mean in the context 
> > > > > > > of LLVM project.
> > > > > > Their conceptual differences are just that they are two different 
> > > > > > intermediate formats.
> > > > > > 
> > > > > > The important thing to highlight is that it is not impossible that 
> > > > > > some vendors use SPIR (without using SPIR-V) even despite the fact 
> > > > > > it has been discontinued by Khronos. 
> > > > > > 
> > > > > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > > > > > Their conceptual differences are just that they are two different 
> > > > > > intermediate formats.
> > > > > > 
> > > > > > The important thing to highlight is that it is not impossible that 
> > > > > > some vendors use SPIR (without using SPIR-V) even despite the fact 
> > > > > > it has been discontinued by Khronos. 
> > > > > > 
> > > > > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > > > > 
> > > > > All the official Xilinx OpenCL stack is based on legacy SPIR (encoded 
> > > > > in LLVM 6.x IR but this is another story) and I suspect this is the 
> > > > > case for other companies.
> > > > > So, do not deprecate or discontinue, please. :-)
> > > > > The important thing to highlight is that it is not impossible that 
> > > > > some vendors use SPIR (without using SPIR-V) even despite the fact it 
> > > > > has been discontinued by Khronos.
> > > > > Nobody has deprecated or discontinued SPIR in the LLVM project yet.
> > > > 
> > > > Strictly speaking `SPIR` is not defined as an intermediate language. 
> > > > Khronos defines `SPIR-1.2` and `SPIR-2.0` formats which are based on 
> > > > LLVM 3.2 and LLVM 3.4 version (https://www.khronos.org/spir/). There is 
> > > > no definition of SPIR format based on current version of LLVM IR. 
> > > > Another note is that metadata and intrinsics emitted for OpenCL with 
> > > > clang-14 doesn't follow neither `SPIR-1.2` nor `SPIR-2.0`.
> > > > 
> > > > I always think of LLVM IR as leaving thing that is subject to change by 
> > > > LLVM community, so tools working with LLVM IR must adjust to the 
> > > > particular version (e.g. release version like LLVM 13 or ToT). We apply 
> > > > this logic to SPIRV-LLVM-Translator tool and update it according to 
> > > > LLVM format changes (e.g. kernel argument information defined in 
> > > > Khronos spec must be named metadata whereas clang emits function 
> > > > metadata).
> > > > 
> > > > > I am slightly confused as in the LLVM project those address spaces 
> > > > > are for SPIR not SPIR-V though.
> > > > [skip]
> > > > > Their conceptual differences are just that they are two different 
> > > > > intermediate formats.
> > > > 
> > > > If this is the only difference, I don't think it a good idea to create 
> > > > another LLVM target to separate SPIR and SPIR-V. From my point of view 
> > > > it creates logic ambiguity and code duplication with no additional 
> > > > value. @Anastasia, what problems do you see if we continue treating 
> > > > LLVM IR with spir* target triple as LLVM IR representation of SPIR-V 
> > > > format?
> > > The state of SPIR 1.2/2.0 in Clang seems to be that the SPIR target has 
> > > transformed to mean “SPIR 1.2/2.0 derivative”, but that does not still 
> > > make it SPIR-V, which is not based on LLVM IR. When one is targeting 
> > > spir* there is ambiguity on whether one is aiming to produce the 
> > > old-SPIR-derivative or SPIR-V. Considerin

[PATCH] D110184: [OpenCL] Constructor address space test adjusted for C++ for OpenCL 2021

2021-09-21 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna created this revision.
Topotuna added a reviewer: Anastasia.
Herald added subscribers: ldrumm, yaxunl.
Topotuna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Reuses C++ for OpenCL constructor address space test so that it
supports optional generic address spaces in version 2021.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110184

Files:
  clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp


Index: clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -triple spir-unknown-unknown | 
FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=clc++1.0 -DGENERIC -emit-llvm -o - -O0 -triple 
spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -DGENERIC -emit-llvm -o - -O0 -triple 
spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=clc++2021 
-cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -emit-llvm -o - -O0 
-triple spir-unknown-unknown | FileCheck %s
 
 // CHECK: %struct.X = type { i32 }
 
@@ -11,8 +13,10 @@
   int x;
 
   // Local variables are handled in local_addrspace_init.clcpp
-  X() /*__generic*/ : x(0) {}
+  X() /*__generic or __private*/ : x(0) {}
+#if defined(GENERIC)
   X() __private : x(0) {}
+#endif
   X() __global : x(0) {}
   constexpr X() __constant : x(0) {}
   constexpr X(int x) __constant : x(x) {}


Index: clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-constructors.clcpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=clc++1.0 -DGENERIC -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -DGENERIC -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes -emit-llvm -o - -O0 -triple spir-unknown-unknown | FileCheck %s
 
 // CHECK: %struct.X = type { i32 }
 
@@ -11,8 +13,10 @@
   int x;
 
   // Local variables are handled in local_addrspace_init.clcpp
-  X() /*__generic*/ : x(0) {}
+  X() /*__generic or __private*/ : x(0) {}
+#if defined(GENERIC)
   X() __private : x(0) {}
+#endif
   X() __global : x(0) {}
   constexpr X() __constant : x(0) {}
   constexpr X(int x) __constant : x(x) {}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D110185: [OpenCL] Reuse C++ for OpenCL 1.0 address space tests for version 2021

2021-09-21 Thread Justas Janickas via Phabricator via cfe-commits
Topotuna created this revision.
Topotuna added a reviewer: Anastasia.
Herald added subscribers: ldrumm, yaxunl.
Topotuna requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adds `RUN` lines in C++ for OpenCL address space tests to cover
version 2021. With all optional core features enabled by default,
C++ for OpenCL 2021 is expected to behave exactly the same way as
C++ for OpenCL 1.0. Therefore, no adjustments were needed in test
code itself.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110185

Files:
  clang/test/CodeGenOpenCLCXX/address-space-castoperators.cpp
  clang/test/CodeGenOpenCLCXX/address-space-deduction.clcpp
  clang/test/CodeGenOpenCLCXX/address-space-deduction2.clcpp
  clang/test/CodeGenOpenCLCXX/addrspace-conversion.clcpp
  clang/test/CodeGenOpenCLCXX/addrspace-derived-base.clcpp
  clang/test/CodeGenOpenCLCXX/addrspace-new-delete.clcpp
  clang/test/CodeGenOpenCLCXX/addrspace-of-this.clcpp
  clang/test/CodeGenOpenCLCXX/addrspace-operators.clcpp
  clang/test/CodeGenOpenCLCXX/addrspace-references.clcpp
  clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
  clang/test/CodeGenOpenCLCXX/addrspace_cast.clcpp

Index: clang/test/CodeGenOpenCLCXX/addrspace_cast.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace_cast.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace_cast.clcpp
@@ -1,4 +1,5 @@
-//RUN: %clang_cc1 %s -triple spir -emit-llvm -O0 -o - | FileCheck %s
+//RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir -emit-llvm -O0 -o - | FileCheck %s
+//RUN: %clang_cc1 %s -cl-std=clc++2021 -triple spir -emit-llvm -O0 -o - | FileCheck %s
 
 //CHECK-LABEL: define{{.*}} spir_func void @_Z3barPU3AS1i
 void bar(global int *gl) {
Index: clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -emit-llvm -O0 -o - | FileCheck %s
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -emit-llvm -O0 -o - | FileCheck %s --check-prefix=CHECK-DEFINITIONS
+// RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir-unknown-unknown -emit-llvm -O0 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir-unknown-unknown -emit-llvm -O0 -o - | FileCheck %s --check-prefix=CHECK-DEFINITIONS
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -triple spir-unknown-unknown -emit-llvm -O0 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -cl-std=clc++2021 -triple spir-unknown-unknown -emit-llvm -O0 -o - | FileCheck %s --check-prefix=CHECK-DEFINITIONS
 
 // This test ensures the proper address spaces and address space cast are used
 // for constructors, member functions and destructors.
Index: clang/test/CodeGenOpenCLCXX/addrspace-references.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-references.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-references.clcpp
@@ -1,4 +1,5 @@
-//RUN: %clang_cc1 %s -triple spir -emit-llvm -o - -O0 | FileCheck %s
+//RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir -emit-llvm -o - -O0 | FileCheck %s
+//RUN: %clang_cc1 %s -cl-std=clc++2021 -triple spir -emit-llvm -o - -O0 | FileCheck %s
 
 typedef short short2 __attribute__((ext_vector_type(2)));
 
Index: clang/test/CodeGenOpenCLCXX/addrspace-operators.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-operators.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-operators.clcpp
@@ -1,4 +1,5 @@
-//RUN: %clang_cc1 %s -triple spir -emit-llvm -O0 -o - | FileCheck %s
+//RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir -emit-llvm -O0 -o - | FileCheck %s
+//RUN: %clang_cc1 %s -cl-std=clc++2021 -triple spir -emit-llvm -O0 -o - | FileCheck %s
 
 enum E {
   a,
Index: clang/test/CodeGenOpenCLCXX/addrspace-of-this.clcpp
===
--- clang/test/CodeGenOpenCLCXX/addrspace-of-this.clcpp
+++ clang/test/CodeGenOpenCLCXX/addrspace-of-this.clcpp
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -emit-llvm -pedantic -verify -O0 -o - -DDECL | FileCheck %s --check-prefixes="COMMON,EXPL"
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -emit-llvm -pedantic -verify -O0 -o - -DDECL -DUSE_DEFLT | FileCheck %s --check-prefixes="COMMON,IMPL"
-// RUN: %clang_cc1 %s -triple spir-unknown-unknown -emit-llvm -pedantic -verify -O0 -o - | FileCheck %s --check-prefixes="COMMON,IMPL"
+// RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir-unknown-unknown -emit-llvm -pedantic -verify -O0 -o - -DDECL | FileCheck %s --check-prefixes="COMMON,EXPL"
+// RUN: %clang_cc1 %s -cl-std=clc++1.0 -triple spir-unknown-unknown -emit-llvm -pedantic -verify -O0 -o - -DDECL -DUSE_DEFLT | FileCheck %s --check-prefixes="COMMO

[PATCH] D109951: [clang-format] Constructor initializer lists format with pp directives

2021-09-21 Thread Josh Learn via Phabricator via cfe-commits
guitard0g updated this revision to Diff 373977.
guitard0g added a comment.

Add test case for space between directives.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109951

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19268,6 +19268,78 @@
Style);
 }
 
+TEST_F(FormatTest, ConstructorInitializersWithPreprocessorDirective) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakConstructorInitializers = FormatStyle::BCIS_BeforeComma;
+  Style.ConstructorInitializerIndentWidth = 4;
+  verifyFormat("SomeClass::Constructor()\n"
+   ": a{a}\n"
+   ", b{b} {}",
+   Style);
+  verifyFormat("SomeClass::Constructor()\n"
+   ": a{a}\n"
+   "#if CONDITION\n"
+   ", b{b}\n"
+   "#endif\n"
+   "{\n}",
+   Style);
+  Style.ConstructorInitializerIndentWidth = 2;
+  verifyFormat("SomeClass::Constructor()\n"
+   "#if CONDITION\n"
+   "  : a{a}\n"
+   "#endif\n"
+   "  , b{b}\n"
+   "  , c{c} {\n}",
+   Style);
+  Style.ConstructorInitializerIndentWidth = 0;
+  verifyFormat("SomeClass::Constructor()\n"
+   ": a{a}\n"
+   "#ifdef CONDITION\n"
+   ", b{b}\n"
+   "#else\n"
+   ", c{c}\n"
+   "#endif\n"
+   ", d{d} {\n}",
+   Style);
+  Style.ConstructorInitializerIndentWidth = 4;
+  verifyFormat("SomeClass::Constructor()\n"
+   ": a{a}\n"
+   "#if WINDOWS\n"
+   "#if DEBUG\n"
+   ", b{0}\n"
+   "#else\n"
+   ", b{1}\n"
+   "#endif\n"
+   "#else\n"
+   "#if DEBUG\n"
+   ", b{2}\n"
+   "#else\n"
+   ", b{3}\n"
+   "#endif\n"
+   "#endif\n"
+   "{\n}",
+   Style);
+  verifyFormat("SomeClass::Constructor()\n"
+   ": a{a}\n"
+   "#if WINDOWS\n"
+   ", b{0}\n"
+   "#if DEBUG\n"
+   ", c{0}\n"
+   "#else\n"
+   ", c{1}\n"
+   "#endif\n"
+   "#else\n"
+   "#if DEBUG\n"
+   ", c{2}\n"
+   "#else\n"
+   ", c{3}\n"
+   "#endif\n"
+   ", b{1}\n"
+   "#endif\n"
+   "{\n}",
+   Style);
+}
+
 TEST_F(FormatTest, Destructors) {
   verifyFormat("void F(int &i) { i.~int(); }");
   verifyFormat("void F(int &i) { i->~int(); }");
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -489,6 +489,17 @@
 if (Style.Language == FormatStyle::LK_Proto) {
   ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square);
 } else {
+  // Skip NextTok over preprocessor lines, otherwise we may not
+  // properly diagnose the block as a braced intializer
+  // if the comma separator appears after the pp directive.
+  while (NextTok->is(tok::hash)) {
+ScopedMacroState MacroState(*Line, Tokens, NextTok);
+do {
+  NextTok = Tokens->getNextToken();
+  ++ReadTokens;
+} while (NextTok->isNot(tok::eof));
+  }
+
   // Using OriginalColumn to distinguish between ObjC methods and
   // binary operators is a bit hacky.
   bool NextIsObjCMethod = NextTok->isOneOf(tok::plus, tok::minus) &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >