[PATCH] D123763: [randstruct] Enforce using a designated init for a randomized struct

2022-04-14 Thread Bill Wendling via Phabricator via cfe-commits
void created this revision.
void added reviewers: aaron.ballman, MaskRay.
Herald added a subscriber: StephenFan.
Herald added a project: All.
void requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A randomized structure needs to use a designated or default initializer.
Using a non-designated initializer will result in values being assigned
to the wrong fields.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123763

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaInit.cpp
  clang/unittests/AST/RandstructTest.cpp

Index: clang/unittests/AST/RandstructTest.cpp
===
--- clang/unittests/AST/RandstructTest.cpp
+++ clang/unittests/AST/RandstructTest.cpp
@@ -156,68 +156,6 @@
   EXPECT_TRUE(RD->isRandomized());
 }
 
-TEST(RANDSTRUCT_TEST, MismatchedAttrsDeclVsDef) {
-  const std::unique_ptr AST = makeAST(R"c(
-struct test __attribute__((randomize_layout));
-struct test {
-int bacon;
-long lettuce;
-long long tomato;
-float mayonnaise;
-} __attribute__((no_randomize_layout));
-  )c");
-
-  EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
-
-  DiagnosticsEngine &Diags = AST->getDiagnostics();
-
-  EXPECT_FALSE(Diags.hasFatalErrorOccurred());
-  EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
-  EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
-  EXPECT_EQ(Diags.getNumWarnings(), 1u);
-  EXPECT_EQ(Diags.getNumErrors(), 0u);
-}
-
-TEST(RANDSTRUCT_TEST, MismatchedAttrsRandomizeVsNoRandomize) {
-  const std::unique_ptr AST = makeAST(R"c(
-struct test2 {
-int bacon;
-long lettuce;
-long long tomato;
-float mayonnaise;
-} __attribute__((randomize_layout)) __attribute__((no_randomize_layout));
-  )c");
-
-  EXPECT_TRUE(AST->getDiagnostics().hasErrorOccurred());
-
-  DiagnosticsEngine &Diags = AST->getDiagnostics();
-
-  EXPECT_TRUE(Diags.hasUncompilableErrorOccurred());
-  EXPECT_TRUE(Diags.hasUnrecoverableErrorOccurred());
-  EXPECT_EQ(Diags.getNumWarnings(), 0u);
-  EXPECT_EQ(Diags.getNumErrors(), 1u);
-}
-
-TEST(RANDSTRUCT_TEST, MismatchedAttrsNoRandomizeVsRandomize) {
-  const std::unique_ptr AST = makeAST(R"c(
-struct test3 {
-int bacon;
-long lettuce;
-long long tomato;
-float mayonnaise;
-} __attribute__((no_randomize_layout)) __attribute__((randomize_layout));
-  )c");
-
-  EXPECT_TRUE(AST->getDiagnostics().hasErrorOccurred());
-
-  DiagnosticsEngine &Diags = AST->getDiagnostics();
-
-  EXPECT_TRUE(Diags.hasUncompilableErrorOccurred());
-  EXPECT_TRUE(Diags.hasUnrecoverableErrorOccurred());
-  EXPECT_EQ(Diags.getNumWarnings(), 0u);
-  EXPECT_EQ(Diags.getNumErrors(), 1u);
-}
-
 TEST(RANDSTRUCT_TEST, CheckAdjacentBitfieldsRemainAdjacentAfterRandomization) {
   const std::unique_ptr AST = makeAST(R"c(
 struct test {
@@ -417,5 +355,133 @@
   EXPECT_TRUE(AnonUnionTested);
 }
 
+TEST(RANDSTRUCT_TEST, MismatchedAttrsDeclVsDef) {
+  const std::unique_ptr AST = makeAST(R"c(
+struct test __attribute__((randomize_layout));
+struct test {
+int bacon;
+long lettuce;
+long long tomato;
+float mayonnaise;
+} __attribute__((no_randomize_layout));
+  )c");
+
+  EXPECT_FALSE(AST->getDiagnostics().hasErrorOccurred());
+
+  DiagnosticsEngine &Diags = AST->getDiagnostics();
+
+  EXPECT_FALSE(Diags.hasFatalErrorOccurred());
+  EXPECT_FALSE(Diags.hasUncompilableErrorOccurred());
+  EXPECT_FALSE(Diags.hasUnrecoverableErrorOccurred());
+  EXPECT_EQ(Diags.getNumWarnings(), 1u);
+  EXPECT_EQ(Diags.getNumErrors(), 0u);
+}
+
+TEST(RANDSTRUCT_TEST, MismatchedAttrsRandomizeVsNoRandomize) {
+  const std::unique_ptr AST = makeAST(R"c(
+struct test2 {
+int bacon;
+long lettuce;
+long long tomato;
+float mayonnaise;
+} __attribute__((randomize_layout)) __attribute__((no_randomize_layout));
+  )c");
+
+  EXPECT_TRUE(AST->getDiagnostics().hasErrorOccurred());
+
+  DiagnosticsEngine &Diags = AST->getDiagnostics();
+
+  EXPECT_TRUE(Diags.hasUncompilableErrorOccurred());
+  EXPECT_TRUE(Diags.hasUnrecoverableErrorOccurred());
+  EXPECT_EQ(Diags.getNumWarnings(), 0u);
+  EXPECT_EQ(Diags.getNumErrors(), 1u);
+}
+
+TEST(RANDSTRUCT_TEST, MismatchedAttrsNoRandomizeVsRandomize) {
+  const std::unique_ptr AST = makeAST(R"c(
+struct test3 {
+int bacon;
+long lettuce;
+long long tomato;
+float mayonnaise;
+} __attribute__((no_randomize_layout)) __attribute__((randomize_layout));
+  )c");
+
+  EXPECT_TRUE(AST->getDiagnostics().hasErrorOccurred());
+
+  DiagnosticsEngine &Diags = AST->getDiagnostics();
+
+  EXPECT_TRUE(Diags.hasUncompilableErrorOccurred());
+  EXPECT_TRUE(Diags.hasUnrecoverableErrorOccurred());
+  EXPECT_EQ(Diags.getNumWarnings(), 0u);
+  EXPECT_EQ(Diags.getNumErrors(), 1u);
+}
+
+TEST(RANDSTRUCT_TEST, RandomizedStructWit

[PATCH] D122789: [compiler-rt] [scudo] Use -mcrc32 on x86 when available

2022-04-14 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

GCC supports "-mcrc32", but seems only for built-in functions: 
https://godbolt.org/z/veeGMoY11

https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#x86-Options


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122789

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


[PATCH] D80344: [Windows SEH]: HARDWARE EXCEPTION HANDLING (MSVC -EHa) - Part 1

2022-04-14 Thread Bo Wang via Phabricator via cfe-commits
bowang added a comment.

Any updates on this patch? Would like to see it moving forward.

I was trying to use Google Breakpad with Clang. Breakpad is a crash handling 
library that generates a minidump at crash. The exception handler on Windows 
relies on SEH.

Breakpad works fine with MSVC. But when it is built with Clang, the exception 
code returned in `exinfo>ExceptionRecord->ExceptionCode` is incorrect. In my 
test program, an access to nullptr should trigger `EXCEPTION_ACCESS_VIOLATION` 
but what's returned is `EXCEPTION_BREAKPOINT`. I suspect it is due to Hardware 
Exception Handling in Clang.

I tried to add flag `-fasync-exceptions` but the problem stays the same.

I tried to add flag `-fseh-exceptions` but received an error `error: invalid 
exception model 'seh' for target 'x86_64-pc-windows-msvc19.0.24245'`

I'm not fully sure whether this patch can address my issue, but would 
appreciate if anyone could shed some light on this. Thanks in advance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80344

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


[PATCH] D121984: [RISCV] Moving RVV intrinsic type related util to clang/Support

2022-04-14 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

Hi @aaron.ballman:

> Why shouldn't this live in clang/utils/TableGen along with the others?

We plan to use those stuffs on clang side in https://reviews.llvm.org/D111617, 
my original change was put those stuffs on `llvm/Support`, but actually those 
stuffs are only used for clang and clang-tblgen, so that's why we try to create 
`clang/Support`.

It's target specific but need to used in `clang` and `clang-tblgen` so target 
specific stuffs should putting that in `llvm/lib/Target/RISCV` in theory, but 
that made clang dependent on that.

Thanks :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121984

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


[PATCH] D123574: [clang] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 422763.
jansvoboda11 added a comment.

Rebase, apply review suggestions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123574

Files:
  clang-tools-extra/clang-move/Move.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
  clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/modularize/CoverageChecker.cpp
  clang-tools-extra/modularize/PreprocessorTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.h
  clang/include/clang/Lex/PPCallbacks.h
  clang/include/clang/Lex/PreprocessingRecord.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/CodeGen/MacroPPCallbacks.cpp
  clang/lib/CodeGen/MacroPPCallbacks.h
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Frontend/DependencyGraph.cpp
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PreprocessingRecord.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXIndexDataConsumer.cpp
  clang/tools/libclang/CXIndexDataConsumer.h
  clang/tools/libclang/Indexing.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp

Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -35,9 +35,9 @@
 public:
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 this->HashLoc = HashLoc;
 this->IncludeTok = IncludeTok;
@@ -56,7 +56,7 @@
   SmallString<16> FileName;
   bool IsAngled;
   CharSourceRange FilenameRange;
-  const FileEntry* File;
+  Optional File;
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
Index: clang/tools/libclang/Indexing.cpp
===
--- clang/tools/libclang/Indexing.cpp
+++ clang/tools/libclang/Indexing.cpp
@@ -261,9 +261,9 @@
 
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 bool isImport = (IncludeTok.is(tok::identifier) &&
 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
Index: clang/tools/libclang/CXIndexDataConsumer.h
===
--- clang/tools/libclang/CXIndexDataConsumer.h
+++ clang/tools/libclang/CXIndexDataConsumer.h
@@ -362,9 +362,9 @@
 
   void enteredMainFile(const FileEntry *File);
 
-  void ppIncludedFile(SourceLocation hashLoc,
-  StringRef filename, const FileEntry *File,
-

[PATCH] D123574: [clang] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 marked 3 inline comments as done.
jansvoboda11 added inline comments.



Comment at: clang-tools-extra/clangd/unittests/ParsedASTTests.cpp:564-565
   IncludeStructure Includes = ExpectedAST.getIncludeStructure();
-  auto MainFE = FM.getFile(testPath("foo.cpp"));
+  auto MainFE = FM.getOptionalFileRef(testPath("foo.cpp"));
   ASSERT_TRUE(MainFE);
   auto MainID = Includes.getOrCreateID(*MainFE);

dexonsmith wrote:
> It might be nice to see the errors here on failures. You could do that with:
> ```
> lang=c++
> Optional MainFE;
> ASSERT_THAT_ERROR(FM.getFileRef(testPath("foo.cpp")).moveInto(MainFE), 
> Succeeded());
> ```
> The `{EXPECT,ASSERT}_THAT_ERROR` live in `llvm/Testing/Support/Error.h`.
That's pretty sweet, thanks for the suggestion!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123574

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


[PATCH] D120639: [RISCV] Pass -mno-relax to assembler when -fno-integrated-as specified

2022-04-14 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

@maskray: Are you happy all your comments are addressed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D120639

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


[clang] d79ad2f - [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective()

2022-04-14 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-04-14T10:46:12+02:00
New Revision: d79ad2f1dbc2db63121620f55d6cfa915f2733ac

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

LOG: [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective()

This patch changes type of the `File` parameter in 
`PPCallbacks::InclusionDirective()` from `const FileEntry *` to 
`Optional`.

With the API change in place, this patch then removes some uses of the 
deprecated `FileEntry::getName()` (e.g. in `DependencyGraph.cpp` and 
`ModuleDependencyCollector.cpp`).

Reviewed By: dexonsmith, bnbarham

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

Added: 


Modified: 
clang-tools-extra/clang-move/Move.cpp
clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/Headers.h
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/index/IndexAction.cpp
clang-tools-extra/clangd/unittests/HeadersTests.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
clang-tools-extra/modularize/CoverageChecker.cpp
clang-tools-extra/modularize/PreprocessorTracker.cpp
clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
clang-tools-extra/pp-trace/PPCallbacksTracker.h
clang/include/clang/Lex/PPCallbacks.h
clang/include/clang/Lex/PreprocessingRecord.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/CodeGen/MacroPPCallbacks.cpp
clang/lib/CodeGen/MacroPPCallbacks.h
clang/lib/Frontend/DependencyFile.cpp
clang/lib/Frontend/DependencyGraph.cpp
clang/lib/Frontend/ModuleDependencyCollector.cpp
clang/lib/Frontend/PrecompiledPreamble.cpp
clang/lib/Frontend/PrintPreprocessedOutput.cpp
clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PreprocessingRecord.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXIndexDataConsumer.cpp
clang/tools/libclang/CXIndexDataConsumer.h
clang/tools/libclang/Indexing.cpp
clang/unittests/Lex/PPCallbacksTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-move/Move.cpp 
b/clang-tools-extra/clang-move/Move.cpp
index 8e0ec0f73c4dd..6419bd3372dce 100644
--- a/clang-tools-extra/clang-move/Move.cpp
+++ b/clang-tools-extra/clang-move/Move.cpp
@@ -131,7 +131,7 @@ class FindAllIncludes : public PPCallbacks {
   void InclusionDirective(SourceLocation HashLoc, const Token & /*IncludeTok*/,
   StringRef FileName, bool IsAngled,
   CharSourceRange FilenameRange,
-  const FileEntry * /*File*/, StringRef SearchPath,
+  Optional /*File*/, StringRef 
SearchPath,
   StringRef /*RelativePath*/,
   const Module * /*Imported*/,
   SrcMgr::CharacteristicKind /*FileType*/) override {

diff  --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index a75fca13e2e5a..f88e24c10901c 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -162,8 +162,9 @@ void ExpandModularHeadersPPCallbacks::FileChanged(
 void ExpandModularHeadersPPCallbacks::InclusionDirective(
 SourceLocation DirectiveLoc, const Token &IncludeToken,
 StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange,
-const FileEntry *IncludedFile, StringRef SearchPath, StringRef 
RelativePath,
-const Module *Imported, SrcMgr::CharacteristicKind FileType) {
+Optional IncludedFile, StringRef SearchPath,
+StringRef RelativePath, const Module *Imported,
+SrcMgr::CharacteristicKind FileType) {
   if (Imported) {
 serialization::ModuleFile *MF =
 

[PATCH] D123574: [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective()

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
jansvoboda11 marked an inline comment as done.
Closed by commit rGd79ad2f1dbc2: [clang][lex] NFCI: Use FileEntryRef in 
PPCallbacks::InclusionDirective() (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123574

Files:
  clang-tools-extra/clang-move/Move.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
  clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
  clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
  clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
  clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/index/IndexAction.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp
  clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
  clang-tools-extra/modularize/CoverageChecker.cpp
  clang-tools-extra/modularize/PreprocessorTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.h
  clang/include/clang/Lex/PPCallbacks.h
  clang/include/clang/Lex/PreprocessingRecord.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/CodeGen/MacroPPCallbacks.cpp
  clang/lib/CodeGen/MacroPPCallbacks.h
  clang/lib/Frontend/DependencyFile.cpp
  clang/lib/Frontend/DependencyGraph.cpp
  clang/lib/Frontend/ModuleDependencyCollector.cpp
  clang/lib/Frontend/PrecompiledPreamble.cpp
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
  clang/lib/Lex/PPDirectives.cpp
  clang/lib/Lex/PreprocessingRecord.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXIndexDataConsumer.cpp
  clang/tools/libclang/CXIndexDataConsumer.h
  clang/tools/libclang/Indexing.cpp
  clang/unittests/Lex/PPCallbacksTest.cpp

Index: clang/unittests/Lex/PPCallbacksTest.cpp
===
--- clang/unittests/Lex/PPCallbacksTest.cpp
+++ clang/unittests/Lex/PPCallbacksTest.cpp
@@ -35,9 +35,9 @@
 public:
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 this->HashLoc = HashLoc;
 this->IncludeTok = IncludeTok;
@@ -56,7 +56,7 @@
   SmallString<16> FileName;
   bool IsAngled;
   CharSourceRange FilenameRange;
-  const FileEntry* File;
+  Optional File;
   SmallString<16> SearchPath;
   SmallString<16> RelativePath;
   const Module* Imported;
Index: clang/tools/libclang/Indexing.cpp
===
--- clang/tools/libclang/Indexing.cpp
+++ clang/tools/libclang/Indexing.cpp
@@ -261,9 +261,9 @@
 
   void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
   StringRef FileName, bool IsAngled,
-  CharSourceRange FilenameRange, const FileEntry *File,
-  StringRef SearchPath, StringRef RelativePath,
-  const Module *Imported,
+  CharSourceRange FilenameRange,
+  Optional File, StringRef SearchPath,
+  StringRef RelativePath, const Module *Imported,
   SrcMgr::CharacteristicKind FileType) override {
 bool isImport = (IncludeTok.is(tok::identifier) &&
 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
Index: clang/tools/libclang/CXIndexDataConsumer.h
===
--- clang/tools/libclang/CXIndexDataConsumer.h
+++ clang/tools/libclang/CXIndexDataConsumer.

[PATCH] D123767: [clang][parse] NFCI: Use FileEntryRef in Parser::ParseModuleImport()

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes use of the deprecated `DirectoryEntry::getName()` from 
`Parser` by using `{File,Directory}EntryRef` instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123767

Files:
  clang/lib/Parse/Parser.cpp


Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2518,8 +2518,8 @@
   // the header is parseable. Emit a warning to make the user aware.
   if (IsObjCAtImport && AtLoc.isValid()) {
 auto &SrcMgr = PP.getSourceManager();
-auto *FE = SrcMgr.getFileEntryForID(SrcMgr.getFileID(AtLoc));
-if (FE && llvm::sys::path::parent_path(FE->getDir()->getName())
+auto FE = SrcMgr.getFileEntryRefForID(SrcMgr.getFileID(AtLoc));
+if (FE && llvm::sys::path::parent_path(FE->getDir().getName())
   .endswith(".framework"))
   Diags.Report(AtLoc, diag::warn_atimport_in_framework_header);
   }


Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -2518,8 +2518,8 @@
   // the header is parseable. Emit a warning to make the user aware.
   if (IsObjCAtImport && AtLoc.isValid()) {
 auto &SrcMgr = PP.getSourceManager();
-auto *FE = SrcMgr.getFileEntryForID(SrcMgr.getFileID(AtLoc));
-if (FE && llvm::sys::path::parent_path(FE->getDir()->getName())
+auto FE = SrcMgr.getFileEntryRefForID(SrcMgr.getFileID(AtLoc));
+if (FE && llvm::sys::path::parent_path(FE->getDir().getName())
   .endswith(".framework"))
   Diags.Report(AtLoc, diag::warn_atimport_in_framework_header);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123300: [Clang] Enable opaque pointers by default

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

Hi,

I noticed this produces broken code:
clang -cc1 -triple amdgcn-- -emit-llvm -o - -x c op.c

with op.c being

  void bar();
  
  void foo() {
bar();
  }

The result is

  define dso_local void @foo() #0 {
  entry:
call void @bar(i32 noundef 42)
ret void
  }
  
  declare void @bar(...) #1

and feeding it to e.g. opt we get

  build-all-builtins/bin/opt: :9:13: error: invalid forward reference to 
function 'bar' with wrong type: expected 'void (...)*' but was 'void ()*'
call void @bar()
  ^

Probably the same for several targets.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123300

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


[PATCH] D123768: [clang][CodeGen] NFCI: Use FileEntryRef

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes use of the deprecated `DirectoryEntry::getName()` from 
clangCodeGen by using `{File,Directory}EntryRef` instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123768

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGObjCGNU.cpp


Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3862,9 +3862,10 @@
 
 // The path to the source file where this module was declared
 SourceManager &SM = CGM.getContext().getSourceManager();
-const FileEntry *mainFile = SM.getFileEntryForID(SM.getMainFileID());
+Optional mainFile =
+SM.getFileEntryRefForID(SM.getMainFileID());
 std::string path =
-  (Twine(mainFile->getDir()->getName()) + "/" + mainFile->getName()).str();
+(mainFile->getDir().getName() + "/" + mainFile->getName()).str();
 module.add(MakeConstantString(path, ".objc_source_file_name"));
 module.add(symtab);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -519,8 +519,9 @@
   // a relative path, so we look into the actual file entry for the main
   // file to determine the real absolute path for the file.
   std::string MainFileDir;
-  if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
-MainFileDir = std::string(MainFile->getDir()->getName());
+  if (Optional MainFile =
+  SM.getFileEntryRefForID(SM.getMainFileID())) {
+MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
   llvm::sys::path::append(MainFileDirSS, MainFileName);


Index: clang/lib/CodeGen/CGObjCGNU.cpp
===
--- clang/lib/CodeGen/CGObjCGNU.cpp
+++ clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3862,9 +3862,10 @@
 
 // The path to the source file where this module was declared
 SourceManager &SM = CGM.getContext().getSourceManager();
-const FileEntry *mainFile = SM.getFileEntryForID(SM.getMainFileID());
+Optional mainFile =
+SM.getFileEntryRefForID(SM.getMainFileID());
 std::string path =
-  (Twine(mainFile->getDir()->getName()) + "/" + mainFile->getName()).str();
+(mainFile->getDir().getName() + "/" + mainFile->getName()).str();
 module.add(MakeConstantString(path, ".objc_source_file_name"));
 module.add(symtab);
 
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -519,8 +519,9 @@
   // a relative path, so we look into the actual file entry for the main
   // file to determine the real absolute path for the file.
   std::string MainFileDir;
-  if (const FileEntry *MainFile = SM.getFileEntryForID(SM.getMainFileID())) {
-MainFileDir = std::string(MainFile->getDir()->getName());
+  if (Optional MainFile =
+  SM.getFileEntryRefForID(SM.getMainFileID())) {
+MainFileDir = std::string(MainFile->getDir().getName());
 if (!llvm::sys::path::is_absolute(MainFileName)) {
   llvm::SmallString<1024> MainFileDirSS(MainFileDir);
   llvm::sys::path::append(MainFileDirSS, MainFileName);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123769: [clang] NFCI: Use DirectoryEntryRef in collectIncludePCH

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes use of the deprecated `DirectoryEntry::getName()` from 
`collectIncludePCH` by using `{File,Directory}EntryRef` instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123769

Files:
  clang/lib/Frontend/CompilerInstance.cpp


Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -232,7 +232,7 @@
 
   StringRef PCHInclude = PPOpts.ImplicitPCHInclude;
   FileManager &FileMgr = CI.getFileManager();
-  auto PCHDir = FileMgr.getDirectory(PCHInclude);
+  auto PCHDir = FileMgr.getOptionalDirectoryRef(PCHInclude);
   if (!PCHDir) {
 MDC->addFile(PCHInclude);
 return;
@@ -240,7 +240,7 @@
 
   std::error_code EC;
   SmallString<128> DirNative;
-  llvm::sys::path::native((*PCHDir)->getName(), DirNative);
+  llvm::sys::path::native(PCHDir->getName(), DirNative);
   llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
   SimpleASTReaderListener Validator(CI.getPreprocessor());
   for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;


Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -232,7 +232,7 @@
 
   StringRef PCHInclude = PPOpts.ImplicitPCHInclude;
   FileManager &FileMgr = CI.getFileManager();
-  auto PCHDir = FileMgr.getDirectory(PCHInclude);
+  auto PCHDir = FileMgr.getOptionalDirectoryRef(PCHInclude);
   if (!PCHDir) {
 MDC->addFile(PCHInclude);
 return;
@@ -240,7 +240,7 @@
 
   std::error_code EC;
   SmallString<128> DirNative;
-  llvm::sys::path::native((*PCHDir)->getName(), DirNative);
+  llvm::sys::path::native(PCHDir->getName(), DirNative);
   llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
   SimpleASTReaderListener Validator(CI.getPreprocessor());
   for (llvm::vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123770: [clang] NFCI: Use FileEntryRef in FileManagerTest

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes use of the deprecated `{File,Directory}Entry::getName()` 
from `FileManager` unit tests by using `{File,Directory}EntryRef` instead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123770

Files:
  clang/unittests/Basic/FileManagerTest.cpp

Index: clang/unittests/Basic/FileManagerTest.cpp
===
--- clang/unittests/Basic/FileManagerTest.cpp
+++ clang/unittests/Basic/FileManagerTest.cpp
@@ -99,22 +99,13 @@
   FileManager manager;
 };
 
-// When a virtual file is added, its getDir() field is set correctly
-// (not NULL, correct name).
+// When a virtual file is added, its getDir() field has correct name.
 TEST_F(FileManagerTest, getVirtualFileSetsTheDirFieldCorrectly) {
-  const FileEntry *file = manager.getVirtualFile("foo.cpp", 42, 0);
-  ASSERT_TRUE(file != nullptr);
-
-  const DirectoryEntry *dir = file->getDir();
-  ASSERT_TRUE(dir != nullptr);
-  EXPECT_EQ(".", dir->getName());
-
-  file = manager.getVirtualFile("x/y/z.cpp", 42, 0);
-  ASSERT_TRUE(file != nullptr);
+  FileEntryRef file = manager.getVirtualFileRef("foo.cpp", 42, 0);
+  EXPECT_EQ(".", file.getDir().getName());
 
-  dir = file->getDir();
-  ASSERT_TRUE(dir != nullptr);
-  EXPECT_EQ("x/y", dir->getName());
+  file = manager.getVirtualFileRef("x/y/z.cpp", 42, 0);
+  EXPECT_EQ("x/y", file.getDir().getName());
 }
 
 // Before any virtual file is added, no virtual directory exists.
@@ -138,16 +129,16 @@
   manager.getVirtualFile("virtual/dir/bar.h", 100, 0);
   ASSERT_FALSE(manager.getDirectory("virtual/dir/foo"));
 
-  auto dir = manager.getDirectory("virtual/dir");
-  ASSERT_TRUE(dir);
-  EXPECT_EQ("virtual/dir", (*dir)->getName());
+  auto dir = manager.getDirectoryRef("virtual/dir");
+  ASSERT_THAT_EXPECTED(dir, llvm::Succeeded());
+  EXPECT_EQ("virtual/dir", dir->getName());
 
-  dir = manager.getDirectory("virtual");
-  ASSERT_TRUE(dir);
-  EXPECT_EQ("virtual", (*dir)->getName());
+  dir = manager.getDirectoryRef("virtual");
+  ASSERT_THAT_EXPECTED(dir, llvm::Succeeded());
+  EXPECT_EQ("virtual", dir->getName());
 }
 
-// getFile() returns non-NULL if a real file exists at the given path.
+// getFileRef() succeeds if a real file exists at the given path.
 TEST_F(FileManagerTest, getFileReturnsValidFileEntryForExistingRealFile) {
   // Inject fake files into the file system.
   auto statCache = std::make_unique();
@@ -163,37 +154,29 @@
 
   manager.setStatCache(std::move(statCache));
 
-  auto file = manager.getFile("/tmp/test");
-  ASSERT_TRUE(file);
-  EXPECT_EQ("/tmp/test", (*file)->getName());
+  auto file = manager.getFileRef("/tmp/test");
+  ASSERT_THAT_EXPECTED(file, llvm::Succeeded());
+  EXPECT_EQ("/tmp/test", file->getName());
 
-  const DirectoryEntry *dir = (*file)->getDir();
-  ASSERT_TRUE(dir != nullptr);
-  EXPECT_EQ("/tmp", dir->getName());
+  EXPECT_EQ("/tmp", file->getDir().getName());
 
 #ifdef _WIN32
-  file = manager.getFile(FileName);
-  ASSERT_TRUE(file);
-
-  dir = (*file)->getDir();
-  ASSERT_TRUE(dir != NULL);
-  EXPECT_EQ(DirName, dir->getName());
+  file = manager.getFileRef(FileName);
+  ASSERT_THAT_EXPECTED(file, llvm::Succeeded());
+  EXPECT_EQ(DirName, file->getDir().getName());
 #endif
 }
 
-// getFile() returns non-NULL if a virtual file exists at the given path.
+// getFileRef() succeeds if a virtual file exists at the given path.
 TEST_F(FileManagerTest, getFileReturnsValidFileEntryForExistingVirtualFile) {
   // Fake an empty real file system.
   manager.setStatCache(std::make_unique());
 
   manager.getVirtualFile("virtual/dir/bar.h", 100, 0);
-  auto file = manager.getFile("virtual/dir/bar.h");
-  ASSERT_TRUE(file);
-  EXPECT_EQ("virtual/dir/bar.h", (*file)->getName());
-
-  const DirectoryEntry *dir = (*file)->getDir();
-  ASSERT_TRUE(dir != nullptr);
-  EXPECT_EQ("virtual/dir", dir->getName());
+  auto file = manager.getFileRef("virtual/dir/bar.h");
+  ASSERT_THAT_EXPECTED(file, llvm::Succeeded());
+  EXPECT_EQ("virtual/dir/bar.h", file->getName());
+  EXPECT_EQ("virtual/dir", file->getDir().getName());
 }
 
 // getFile() returns different FileEntries for different paths when
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123300: [Clang] Enable opaque pointers by default

2022-04-14 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

@uabelho The IR is correct, but requires using `opt -opaque-pointers` 
explicitly. Normally, opaque pointer mode is automatically enabled, but there 
is no explicit mention of `ptr` in the IR. Not sure if we can do anything to 
improve that before the default on the opt side is switched.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123300

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


[clang] 6ba1b90 - Reland "[AST] Add a new TemplateKind for template decls found via a using decl.""

2022-04-14 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-04-14T11:04:55+02:00
New Revision: 6ba1b9075dc1fef6c32eafa71495bfec803321e4

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

LOG: Reland "[AST] Add a new TemplateKind for template decls found via a using 
decl.""

This is the template version of https://reviews.llvm.org/D114251.

This patch introduces a new template name kind (UsingTemplateName). The
UsingTemplateName stores the found using-shadow decl (and underlying
template can be retrieved from the using-shadow decl). With the new
template name, we can be able to find the using decl that a template
typeloc (e.g. TemplateSpecializationTypeLoc) found its underlying template,
which is useful for tooling use cases (include cleaner etc).

This patch merely focuses on adding the node to the AST.

Next steps:
- support using-decl in qualified template name;
- update the clangd and other tools to use this new node;
- add ast matchers for matching different kinds of template names;

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

Added: 
clang/test/AST/ast-dump-using-template.cpp
clang/unittests/AST/TemplateNameTest.cpp

Modified: 
clang-tools-extra/clangd/DumpAST.cpp
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang/include/clang/AST/PropertiesBase.td
clang/include/clang/AST/TemplateName.h
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/ODRHash.cpp
clang/lib/AST/TemplateName.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.deduct.guide/p3.cpp
clang/tools/libclang/CIndex.cpp
clang/unittests/AST/ASTImporterTest.cpp
clang/unittests/AST/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clangd/DumpAST.cpp 
b/clang-tools-extra/clangd/DumpAST.cpp
index 4c36de88aea1f..8f640ad821f8c 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -184,6 +184,7 @@ class DumpVisitor : public RecursiveASTVisitor 
{
   TEMPLATE_KIND(DependentTemplate);
   TEMPLATE_KIND(SubstTemplateTemplateParm);
   TEMPLATE_KIND(SubstTemplateTemplateParmPack);
+  TEMPLATE_KIND(UsingTemplate);
 #undef TEMPLATE_KIND
 }
 llvm_unreachable("Unhandled NameKind enum");

diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index fce83d1834a50..489bb93856a04 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -762,6 +762,7 @@ class CollectExtraHighlightings
 case TemplateName::QualifiedTemplate:
 case TemplateName::SubstTemplateTemplateParm:
 case TemplateName::SubstTemplateTemplateParmPack:
+case TemplateName::UsingTemplate:
   // Names that could be resolved to a TemplateDecl are handled elsewhere.
   break;
 }

diff  --git a/clang/include/clang/AST/PropertiesBase.td 
b/clang/include/clang/AST/PropertiesBase.td
index 3da7fd9030aac..0ab18b6d59c3d 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -620,6 +620,16 @@ let Class = PropertyTypeCase in {
 return TemplateName(declaration);
   }]>;
 }
+
+let Class = PropertyTypeCase in {
+  def : Property<"foundDecl", UsingShadowDeclRef> {
+let Read = [{ node.getAsUsingShadowDecl() }];
+  }
+  def : Creator<[{
+return TemplateName(foundDecl);
+  }]>;
+}
+
 let Class = PropertyTypeCase in {
   def : Property<"overloads", Array> {
 let Read = [{ node.getAsOverloadedTemplate()->decls() }];

diff  --git a/clang/include/clang/AST/TemplateName.h 
b/clang/include/clang/AST/TemplateName.h
index 26c64d0e277ff..1bd86b0bdcf11 100644
--- a/clang/include/clang/AST/TemplateName.h
+++ b/clang/include/clang/AST/TemplateName.h
@@ -25,6 +25,7 @@
 namespace clang {
 
 class ASTContext;
+class Decl;
 class DependentTemplateName;
 class IdentifierInfo;
 class NamedDecl;
@@ -39,6 +40,7 @@ class SubstTemplateTemplateParmStorage;
 class TemplateArgument;
 class TemplateDecl;
 class TemplateTemplateParmDecl;
+class UsingShadowDecl;
 
 /// Implementation class used to describe either a set of overloaded
 /// template names or an already-substituted template template parameter pack.
@@ -188,8 +190,12 @@ class SubstTemplateTemplateParmPackStorage
 /// specifier in the typedef. "apply" is a nested template, and can
 /// only be understood in the context of
 class TemplateName {
+  // NameDecl is either a TemplateDecl or a UsingShadowDecl depending on the
+  // NameKind.
+  /

[PATCH] D123127: [AST] Add a new TemplateName for templates found via a using declaration.

2022-04-14 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6ba1b9075dc1: Reland "[AST] Add a new TemplateKind for 
template decls found via a using decl. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123127

Files:
  clang-tools-extra/clangd/DumpAST.cpp
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TemplateName.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/ast-dump-using-template.cpp
  clang/test/CXX/temp/temp.deduct.guide/p3.cpp
  clang/tools/libclang/CIndex.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  clang/unittests/AST/CMakeLists.txt
  clang/unittests/AST/TemplateNameTest.cpp

Index: clang/unittests/AST/TemplateNameTest.cpp
===
--- /dev/null
+++ clang/unittests/AST/TemplateNameTest.cpp
@@ -0,0 +1,62 @@
+//===- unittests/AST/TemplateNameTest.cpp --- Tests for TemplateName --===//
+//
+// 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 "ASTPrint.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace {
+using namespace ast_matchers;
+
+std::string printTemplateName(TemplateName TN, const PrintingPolicy &Policy,
+  TemplateName::Qualified Qual) {
+  std::string Result;
+  llvm::raw_string_ostream Out(Result);
+  TN.print(Out, Policy, Qual);
+  return Out.str();
+}
+
+TEST(TemplateName, PrintUsingTemplate) {
+  std::string Code = R"cpp(
+namespace std {
+  template  struct vector {};
+}
+namespace absl { using std::vector; }
+
+template class T> class X;
+
+using absl::vector;
+using A = X;
+  )cpp";
+  auto AST = tooling::buildASTFromCode(Code);
+  ASTContext &Ctx = AST->getASTContext();
+  // Match the template argument vector in X.
+  auto MatchResults = match(templateArgumentLoc().bind("id"), Ctx);
+  const auto *Template = selectFirst("id", MatchResults);
+  ASSERT_TRUE(Template);
+
+  TemplateName TN = Template->getArgument().getAsTemplate();
+  EXPECT_EQ(TN.getKind(), TemplateName::UsingTemplate);
+  EXPECT_EQ(TN.getAsUsingShadowDecl()->getTargetDecl(), TN.getAsTemplateDecl());
+
+  EXPECT_EQ(printTemplateName(TN, Ctx.getPrintingPolicy(),
+  TemplateName::Qualified::Fully),
+"std::vector");
+  EXPECT_EQ(printTemplateName(TN, Ctx.getPrintingPolicy(),
+  TemplateName::Qualified::AsWritten),
+"vector");
+  EXPECT_EQ(printTemplateName(TN, Ctx.getPrintingPolicy(),
+  TemplateName::Qualified::None),
+"vector");
+}
+
+} // namespace
+} // namespace clang
Index: clang/unittests/AST/CMakeLists.txt
===
--- clang/unittests/AST/CMakeLists.txt
+++ clang/unittests/AST/CMakeLists.txt
@@ -31,6 +31,7 @@
   SourceLocationTest.cpp
   StmtPrinterTest.cpp
   StructuralEquivalenceTest.cpp
+  TemplateNameTest.cpp
   TypePrinterTest.cpp
   )
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -890,6 +890,18 @@
  functionDecl(hasDescendant(usingDecl(hasName("bar");
 }
 
+TEST_P(ImportDecl, ImportUsingTemplate) {
+  MatchVerifier Verifier;
+  testImport("namespace ns { template  struct S {}; }"
+ "template  class T> class X {};"
+ "void declToImport() {"
+ "using ns::S;  X xi; }",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ functionDecl(
+ hasDescendant(varDecl(hasTypeLoc(templateSpecializationTypeLoc(
+ hasAnyTemplateArgumentLoc(templateArgumentLoc(;
+}
+
 TEST_P(ImportDecl, ImportUsingEnumDecl) {
   MatchVerifier Verifier;
   testImport("namespace foo { enum bar { baz, toto, quux }; }"
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/lib

[PATCH] D123676: [clang-format] Fix WhitespaceSensitiveMacros not being honoured when macro closing parenthesis is followed by a newline.

2022-04-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/FormatTokenLexer.cpp:1031-1035
+  if (it->second.Finalized) {
+FormatTok->setFinalizedType(it->second.Type);
+  } else {
+FormatTok->setType(it->second.Type);
+  }

It seems we can simply do this and leave the rest of `FormatTokenLexer` alone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123676

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


[PATCH] D123676: [clang-format] Fix WhitespaceSensitiveMacros not being honoured when macro closing parenthesis is followed by a newline.

2022-04-14 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/UnwrappedLineParser.cpp:1791
+tokenCanStartNewLine(*FormatTok) && Text == Text.upper() &&
+!PreviousToken->isTypeFinalized()) {
   PreviousToken->setFinalizedType(TT_FunctionLikeOrFreestandingMacro);

curdeius wrote:
> owenpan wrote:
> > Can we simply do this and leave `FormatTokenLexer` alone?
> We can too. It seemed hacky to me because we can miss 
> `TT_UntouchableMacroFunc` in other places.
> Setting the token type finalized in the lexer will avoid such problems in the 
> future.
> I'm okay however to just apply your suggestion.
> We can too. It seemed hacky to me because we can miss 
> `TT_UntouchableMacroFunc` in other places.
> Setting the token type finalized in the lexer will avoid such problems in the 
> future.

Yeah. Please see my [[ https://reviews.llvm.org/D123676#3451098 | comment ]] 
above though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123676

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


[PATCH] D123771: [clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::load*()

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch removes uses of the deprecated `DirectoryEntry::getName()` from 
`HeaderSearch::load*()` functions by using `DirectoryEntryRef` instead.

Note that we bail out in one case and use the also deprecated 
`FileEntry::getLastRef()`. That's to prevent this patch from growing, and is 
addressed in a follow-up.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123771

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/lib/Lex/HeaderSearch.cpp

Index: clang/lib/Lex/HeaderSearch.cpp
===
--- clang/lib/Lex/HeaderSearch.cpp
+++ clang/lib/Lex/HeaderSearch.cpp
@@ -319,7 +319,8 @@
   SmallString<128> FrameworkDirName;
   FrameworkDirName += Dir.getFrameworkDir()->getName();
   llvm::sys::path::append(FrameworkDirName, SearchName + ".framework");
-  if (auto FrameworkDir = FileMgr.getDirectory(FrameworkDirName)) {
+  if (auto FrameworkDir =
+  FileMgr.getOptionalDirectoryRef(FrameworkDirName)) {
 bool IsSystem = Dir.getDirCharacteristic() != SrcMgr::C_User;
 Module = loadFrameworkModule(ModuleName, *FrameworkDir, IsSystem);
 if (Module)
@@ -335,7 +336,7 @@
 
 bool IsSystem = Dir.isSystemHeaderDirectory();
 // Search for a module map file in this directory.
-if (loadModuleMapFile(Dir.getDir(), IsSystem,
+if (loadModuleMapFile(*Dir.getDirRef(), IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded) {
   // We just loaded a module map file; check whether the module is
   // available now.
@@ -507,7 +508,7 @@
 /// \param DirName The name of the framework directory.
 /// \param SubmodulePath Will be populated with the submodule path from the
 /// returned top-level module to the originally named framework.
-static const DirectoryEntry *
+static Optional
 getTopFrameworkDir(FileManager &FileMgr, StringRef DirName,
SmallVectorImpl &SubmodulePath) {
   assert(llvm::sys::path::extension(DirName) == ".framework" &&
@@ -527,12 +528,10 @@
   //
   // Similar issues occur when a top-level framework has moved into an
   // embedded framework.
-  const DirectoryEntry *TopFrameworkDir = nullptr;
-  if (auto TopFrameworkDirOrErr = FileMgr.getDirectory(DirName))
-TopFrameworkDir = *TopFrameworkDirOrErr;
+  auto TopFrameworkDir = FileMgr.getOptionalDirectoryRef(DirName);
 
   if (TopFrameworkDir)
-DirName = FileMgr.getCanonicalName(TopFrameworkDir);
+DirName = FileMgr.getCanonicalName(*TopFrameworkDir);
   do {
 // Get the parent directory name.
 DirName = llvm::sys::path::parent_path(DirName);
@@ -540,7 +539,7 @@
   break;
 
 // Determine whether this directory exists.
-auto Dir = FileMgr.getDirectory(DirName);
+auto Dir = FileMgr.getOptionalDirectoryRef(DirName);
 if (!Dir)
   break;
 
@@ -1476,13 +1475,13 @@
   return false;
 
 // Determine whether this directory exists.
-auto Dir = FileMgr.getDirectory(DirName);
+auto Dir = FileMgr.getOptionalDirectoryRef(DirName);
 if (!Dir)
   return false;
 
 // Try to load the module map file in this directory.
 switch (loadModuleMapFile(*Dir, IsSystem,
-  llvm::sys::path::extension((*Dir)->getName()) ==
+  llvm::sys::path::extension(Dir->getName()) ==
   ".framework")) {
 case LMM_NewlyLoaded:
 case LMM_AlreadyLoaded:
@@ -1579,15 +1578,16 @@
   if (needModuleLookup(RequestingModule, SuggestedModule)) {
 // Find the top-level framework based on this framework.
 SmallVector SubmodulePath;
-const DirectoryEntry *TopFrameworkDir
-  = ::getTopFrameworkDir(FileMgr, FrameworkName, SubmodulePath);
+Optional TopFrameworkDir =
+::getTopFrameworkDir(FileMgr, FrameworkName, SubmodulePath);
+assert(TopFrameworkDir && "Could not find the top-most framework dir");
 
 // Determine the name of the top-level framework.
 StringRef ModuleName = llvm::sys::path::stem(TopFrameworkDir->getName());
 
 // Load this framework module. If that succeeds, find the suggested module
 // for this header, if any.
-loadFrameworkModule(ModuleName, TopFrameworkDir, IsSystemFramework);
+loadFrameworkModule(ModuleName, *TopFrameworkDir, IsSystemFramework);
 
 // FIXME: This can find a module not part of ModuleName, which is
 // important so that we're consistent about whether this header
@@ -1618,39 +1618,37 @@
  StringRef OriginalModuleMapFile) {
   // Find the directory for the module. For frameworks, that may require going
   // up from the 'Modules' directory.
-  const DirectoryEntry *Dir = nullptr;
+  Optional Dir;
 

[PATCH] D123300: [Clang] Enable opaque pointers by default

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

In D123300#3451087 , @nikic wrote:

> @uabelho The IR is correct, but requires using `opt -opaque-pointers` 
> explicitly. Normally, opaque pointer mode is automatically enabled, but there 
> is no explicit mention of `ptr` in the IR. Not sure if we can do anything to 
> improve that before the default on the opt side is switched.

Oh, didn't realize this. Yes we'll need to start passing -opaque-pointers to 
opt (and llc I suppose) explicitly then.
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123300

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


[PATCH] D123772: [clang][lex] NFC: Use FileEntryRef in PreprocessorLexer::getFileEntry()

2022-04-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: dexonsmith, bnbarham.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch changes the return type of `PreprocessorLexer::getFileEntry()` so 
that its clients may stop using the deprecated APIs of `FileEntry`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123772

Files:
  clang/include/clang/Lex/PreprocessorLexer.h
  clang/lib/Lex/PreprocessorLexer.cpp
  clang/lib/Sema/SemaCodeComplete.cpp


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -9972,7 +9972,7 @@
   using llvm::make_range;
   if (!Angled) {
 // The current directory is on the include path for "quoted" includes.
-auto *CurFile = PP.getCurrentFileLexer()->getFileEntry();
+const FileEntry *CurFile = PP.getCurrentFileLexer()->getFileEntry();
 if (CurFile && CurFile->getDir())
   AddFilesFromIncludeDir(CurFile->getDir()->getName(), false,
  DirectoryLookup::LT_NormalDir);
Index: clang/lib/Lex/PreprocessorLexer.cpp
===
--- clang/lib/Lex/PreprocessorLexer.cpp
+++ clang/lib/Lex/PreprocessorLexer.cpp
@@ -47,6 +47,7 @@
 
 /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
 /// getFileID(), this only works for lexers with attached preprocessors.
-const FileEntry *PreprocessorLexer::getFileEntry() const {
-  return PP->getSourceManager().getFileEntryForID(getFileID());
+OptionalFileEntryRefDegradesToFileEntryPtr
+PreprocessorLexer::getFileEntry() const {
+  return PP->getSourceManager().getFileEntryRefForID(getFileID());
 }
Index: clang/include/clang/Lex/PreprocessorLexer.h
===
--- clang/include/clang/Lex/PreprocessorLexer.h
+++ clang/include/clang/Lex/PreprocessorLexer.h
@@ -165,7 +165,7 @@
 
   /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
   /// getFileID(), this only works for lexers with attached preprocessors.
-  const FileEntry *getFileEntry() const;
+  OptionalFileEntryRefDegradesToFileEntryPtr getFileEntry() const;
 
   /// Iterator that traverses the current stack of preprocessor
   /// conditional directives (\#if/\#ifdef/\#ifndef).


Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -9972,7 +9972,7 @@
   using llvm::make_range;
   if (!Angled) {
 // The current directory is on the include path for "quoted" includes.
-auto *CurFile = PP.getCurrentFileLexer()->getFileEntry();
+const FileEntry *CurFile = PP.getCurrentFileLexer()->getFileEntry();
 if (CurFile && CurFile->getDir())
   AddFilesFromIncludeDir(CurFile->getDir()->getName(), false,
  DirectoryLookup::LT_NormalDir);
Index: clang/lib/Lex/PreprocessorLexer.cpp
===
--- clang/lib/Lex/PreprocessorLexer.cpp
+++ clang/lib/Lex/PreprocessorLexer.cpp
@@ -47,6 +47,7 @@
 
 /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
 /// getFileID(), this only works for lexers with attached preprocessors.
-const FileEntry *PreprocessorLexer::getFileEntry() const {
-  return PP->getSourceManager().getFileEntryForID(getFileID());
+OptionalFileEntryRefDegradesToFileEntryPtr
+PreprocessorLexer::getFileEntry() const {
+  return PP->getSourceManager().getFileEntryRefForID(getFileID());
 }
Index: clang/include/clang/Lex/PreprocessorLexer.h
===
--- clang/include/clang/Lex/PreprocessorLexer.h
+++ clang/include/clang/Lex/PreprocessorLexer.h
@@ -165,7 +165,7 @@
 
   /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
   /// getFileID(), this only works for lexers with attached preprocessors.
-  const FileEntry *getFileEntry() const;
+  OptionalFileEntryRefDegradesToFileEntryPtr getFileEntry() const;
 
   /// Iterator that traverses the current stack of preprocessor
   /// conditional directives (\#if/\#ifdef/\#ifndef).
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123498: [clang] Adding Platform/Architecture Specific Resource Header Installation Targets

2022-04-14 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

> Sure, we can have an AArch64 specific section. I have no AArch64/arm 
> background to comment on what the lists should look like. Could you provide a 
> pointer on how to decide what should be AArch64 specific? Thank you!

I looked through the list and here's what goes where:

arm_acle.h - both
arm_cmse.h - Arm only (CMSE is an M profile feature)
armintr.h - Arm only (Windows intrinsics)
arm64intr.h - AArch64 only (Windows intrinsics)

arm_neon.h - both
arm_fp16.h - both

Only includes AArch64 stuff at this time but according to the docs:

  FEAT_FP16 supports:
  • Half-precision data-processing instructions for Advanced SIMD and 
floating-point in both
  AArch64 and AArch32 states.

arm_sve.h - AArch64 (SVE is AArch64 exclusive)
arm_bf16.h - AArch64 only

  "FEAT_BF16 supports the BFloat16, or BF16, 16-bit floating-point storage 
format in AArch64 state." 

arm_mve.h - Arm only (MVE is an M profile feature)
arm_cde.h - Arm only (CDE is an M profile feature)
arm_neon_sve_bridge.h - AArch64 only (SVE is AArch64 exclusive)

@momchil.velikov Please double check I got that right.

So you'd probably want to have an `arm_common`, like you have for the `core`. 
Arm installs `arm_common` and `arm`, AArch64 installs `arm_common` and 
`aarch64`.

Not sure if you'd expect the Windows intrisics files to show up in the 
`windows` headers. My guess is no because you'd configure with Windows and Arm, 
or Windows and AArch64 headers. `windows` would just be arch agnostic stuff.

This split reduces each install by 4 headers. So hardly amazing disk space wise 
but I think your goal is more to only have relevant files and this achieves 
that.

> Then again a lot of Arm systems can run 32 bit code as well so there is a 
> situation where you might include both.

I would guess that having two install targets makes it obvious that if you want 
32 bit code you need to opt into both. (though I am biased since I'm already 
familiar with Arm)

Also, what's the feedback mechanism for issues with these listings? Say we add 
a new Arm header but forget to put it on these lists, who would be the first to 
notice? (I admit I'm not very familiar with the process of distributions)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123498

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


[PATCH] D121984: [RISCV] Moving RVV intrinsic type related util to clang/Support

2022-04-14 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 422783.
kito-cheng added a comment.

Fix comment in RISCVVIntrinsicUtils.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121984

Files:
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/CMakeLists.txt
  clang/lib/Support/CMakeLists.txt
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -14,6 +14,7 @@
 //
 //===--===//
 
+#include "clang/Support/RISCVVIntrinsicUtils.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
@@ -25,206 +26,9 @@
 #include 
 
 using namespace llvm;
-using BasicType = char;
-using VScaleVal = Optional;
+using namespace clang::RISCV;
 
 namespace {
-
-// Exponential LMUL
-struct LMULType {
-  int Log2LMUL;
-  LMULType(int Log2LMUL);
-  // Return the C/C++ string representation of LMUL
-  std::string str() const;
-  Optional getScale(unsigned ElementBitwidth) const;
-  void MulLog2LMUL(int Log2LMUL);
-  LMULType &operator*=(uint32_t RHS);
-};
-
-// This class is compact representation of a valid and invalid RVVType.
-class RVVType {
-  enum ScalarTypeKind : uint32_t {
-Void,
-Size_t,
-Ptrdiff_t,
-UnsignedLong,
-SignedLong,
-Boolean,
-SignedInteger,
-UnsignedInteger,
-Float,
-Invalid,
-  };
-  BasicType BT;
-  ScalarTypeKind ScalarType = Invalid;
-  LMULType LMUL;
-  bool IsPointer = false;
-  // IsConstant indices are "int", but have the constant expression.
-  bool IsImmediate = false;
-  // Const qualifier for pointer to const object or object of const type.
-  bool IsConstant = false;
-  unsigned ElementBitwidth = 0;
-  VScaleVal Scale = 0;
-  bool Valid;
-
-  std::string BuiltinStr;
-  std::string ClangBuiltinStr;
-  std::string Str;
-  std::string ShortStr;
-
-public:
-  RVVType() : RVVType(BasicType(), 0, StringRef()) {}
-  RVVType(BasicType BT, int Log2LMUL, StringRef prototype);
-
-  // Return the string representation of a type, which is an encoded string for
-  // passing to the BUILTIN() macro in Builtins.def.
-  const std::string &getBuiltinStr() const { return BuiltinStr; }
-
-  // Return the clang builtin type for RVV vector type which are used in the
-  // riscv_vector.h header file.
-  const std::string &getClangBuiltinStr() const { return ClangBuiltinStr; }
-
-  // Return the C/C++ string representation of a type for use in the
-  // riscv_vector.h header file.
-  const std::string &getTypeStr() const { return Str; }
-
-  // Return the short name of a type for C/C++ name suffix.
-  const std::string &getShortStr() {
-// Not all types are used in short name, so compute the short name by
-// demanded.
-if (ShortStr.empty())
-  initShortStr();
-return ShortStr;
-  }
-
-  bool isValid() const { return Valid; }
-  bool isScalar() const { return Scale.hasValue() && Scale.getValue() == 0; }
-  bool isVector() const { return Scale.hasValue() && Scale.getValue() != 0; }
-  bool isVector(unsigned Width) const {
-return isVector() && ElementBitwidth == Width;
-  }
-  bool isFloat() const { return ScalarType == ScalarTypeKind::Float; }
-  bool isSignedInteger() const {
-return ScalarType == ScalarTypeKind::SignedInteger;
-  }
-  bool isFloatVector(unsigned Width) const {
-return isVector() && isFloat() && ElementBitwidth == Width;
-  }
-  bool isFloat(unsigned Width) const {
-return isFloat() && ElementBitwidth == Width;
-  }
-
-private:
-  // Verify RVV vector type and set Valid.
-  bool verifyType() const;
-
-  // Creates a type based on basic types of TypeRange
-  void applyBasicType();
-
-  // Applies a prototype modifier to the current type. The result maybe an
-  // invalid type.
-  void applyModifier(StringRef prototype);
-
-  // Compute and record a string for legal type.
-  void initBuiltinStr();
-  // Compute and record a builtin RVV vector type string.
-  void initClangBuiltinStr();
-  // Compute and record a type string for used in the header.
-  void initTypeStr();
-  // Compute and record a short name of a type for C/C++ name suffix.
-  void initShortStr();
-};
-
-using RVVTypePtr = RVVType *;
-using RVVTypes = std::vector;
-using RISCVPredefinedMacroT = uint8_t;
-
-enum RISCVPredefinedMacro : RISCVPredefinedMacroT {
-  Basic = 0,
-  V = 1 << 1,
-  Zvfh = 1 << 2,
-  RV64 = 1 << 3,
-  VectorMaxELen64 = 1 << 4,
-  VectorMaxELenFp32 = 1 << 5,
-  VectorMaxELenFp64 = 1 << 6,
-};
-
-enum PolicyScheme : uint8_t {
-  SchemeNone,
-  HasPassthruOperand,
-  HasPolicyOperand,
-};
-
-// TODO refactor RVVIntrinsic class design after support all intrinsic
-// combination. This r

[PATCH] D123773: [clang][analyzer][ctu] Make CTU a two phase analysis

2022-04-14 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: steakhal, NoQ.
Herald added subscribers: manas, ASDenysPetrov, gamesh411, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This new CTU implementation is the natural extension of the normal single TU
analysis. The approach consists of two analysis phases. During the first phase,
we do a normal single TU analysis. During this phase, if we find a foreign
function (that could be inlined from another TU) then we don’t inline that
immediately, we rather mark that to be analysed later.
When the first phase is finished then we start the second phase, the CTU phase.
In this phase, we continue the analysis from those points (exploded nodes)
which had been enqueued during the first phase. We gradually extend the
exploded graph of the single TU analysis with new nodes that are created by the
inlining of foreign functions.

We count the number of analysis steps of the first phase and we limit the
second (ctu) phase with this number.

Discussion:
https://discourse.llvm.org/t/rfc-much-faster-cross-translation-unit-ctu-analysis-implementation/61728


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123773

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
  clang/test/Analysis/Inputs/ctu-onego-existingdef-other.cpp
  
clang/test/Analysis/Inputs/ctu-onego-existingdef-other.cpp.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-onego-indirect-other.cpp
  
clang/test/Analysis/Inputs/ctu-onego-indirect-other.cpp.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-onego-toplevel-other.cpp
  
clang/test/Analysis/Inputs/ctu-onego-toplevel-other.cpp.externalDefMap.ast-dump.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/ctu-implicit.c
  clang/test/Analysis/ctu-main.c
  clang/test/Analysis/ctu-main.cpp
  clang/test/Analysis/ctu-on-demand-parsing.c
  clang/test/Analysis/ctu-on-demand-parsing.cpp
  clang/test/Analysis/ctu-onego-existingdef.cpp
  clang/test/Analysis/ctu-onego-indirect.cpp
  clang/test/Analysis/ctu-onego-toplevel.cpp

Index: clang/test/Analysis/ctu-onego-toplevel.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-onego-toplevel.cpp
@@ -0,0 +1,52 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -emit-pch -o %t/ctudir/ctu-onego-toplevel-other.cpp.ast %S/Inputs/ctu-onego-toplevel-other.cpp
+// RUN: cp %S/Inputs/ctu-onego-toplevel-other.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
+
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -verify=ctu %s
+
+// RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
+// RUN:   -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -analyzer-config display-ctu-progress=true \
+// RUN:   -analyzer-display-progress \
+// RUN:   -verify=ctu %s 2>&1 | FileCheck %s
+//
+// CallGraph: c->b
+// topological sort: c, b
+// Note that `other` calls into `b` but that is not visible in the CallGraph
+// b/c that happens in another TU.
+
+// During the onego CTU analysis, we start with c() as top level function.
+// Then we visit b() as non-toplevel during the processing of the FWList, thus
+// that would not be visited as toplevel without special care.
+
+// `c` is analyzed as toplevel and during that the other TU is loaded:
+// CHECK: ANALYZE (Path,  Inline_Regular): {{.*}} c(int){{.*}}CTU loaded AST file
+// next, `b` is analyzed as toplevel:
+// CHECK: ANALYZE (Path,  Inline_Regular): {{.*}} b(int)
+
+void b(int x);
+void other(int y);
+void c(int y) {
+  other(y);
+  return;
+  // The below call is here to form the proper CallGraph, but will not be
+  // analyzed.
+  b(1);
+}
+
+void b(int x) {
+  if (x == 0)
+(void)(1 / x)

[PATCH] D121984: [RISCV] Moving RVV intrinsic type related util to clang/Support

2022-04-14 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 422786.
kito-cheng marked an inline comment as done.
kito-cheng added a comment.

Fix comment in RISCVVIntrinsicUtils.h...again :P


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121984

Files:
  clang/include/clang/Support/RISCVVIntrinsicUtils.h
  clang/lib/CMakeLists.txt
  clang/lib/Support/CMakeLists.txt
  clang/lib/Support/RISCVVIntrinsicUtils.cpp
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/RISCVVEmitter.cpp

Index: clang/utils/TableGen/RISCVVEmitter.cpp
===
--- clang/utils/TableGen/RISCVVEmitter.cpp
+++ clang/utils/TableGen/RISCVVEmitter.cpp
@@ -14,6 +14,7 @@
 //
 //===--===//
 
+#include "clang/Support/RISCVVIntrinsicUtils.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/StringExtras.h"
@@ -25,206 +26,9 @@
 #include 
 
 using namespace llvm;
-using BasicType = char;
-using VScaleVal = Optional;
+using namespace clang::RISCV;
 
 namespace {
-
-// Exponential LMUL
-struct LMULType {
-  int Log2LMUL;
-  LMULType(int Log2LMUL);
-  // Return the C/C++ string representation of LMUL
-  std::string str() const;
-  Optional getScale(unsigned ElementBitwidth) const;
-  void MulLog2LMUL(int Log2LMUL);
-  LMULType &operator*=(uint32_t RHS);
-};
-
-// This class is compact representation of a valid and invalid RVVType.
-class RVVType {
-  enum ScalarTypeKind : uint32_t {
-Void,
-Size_t,
-Ptrdiff_t,
-UnsignedLong,
-SignedLong,
-Boolean,
-SignedInteger,
-UnsignedInteger,
-Float,
-Invalid,
-  };
-  BasicType BT;
-  ScalarTypeKind ScalarType = Invalid;
-  LMULType LMUL;
-  bool IsPointer = false;
-  // IsConstant indices are "int", but have the constant expression.
-  bool IsImmediate = false;
-  // Const qualifier for pointer to const object or object of const type.
-  bool IsConstant = false;
-  unsigned ElementBitwidth = 0;
-  VScaleVal Scale = 0;
-  bool Valid;
-
-  std::string BuiltinStr;
-  std::string ClangBuiltinStr;
-  std::string Str;
-  std::string ShortStr;
-
-public:
-  RVVType() : RVVType(BasicType(), 0, StringRef()) {}
-  RVVType(BasicType BT, int Log2LMUL, StringRef prototype);
-
-  // Return the string representation of a type, which is an encoded string for
-  // passing to the BUILTIN() macro in Builtins.def.
-  const std::string &getBuiltinStr() const { return BuiltinStr; }
-
-  // Return the clang builtin type for RVV vector type which are used in the
-  // riscv_vector.h header file.
-  const std::string &getClangBuiltinStr() const { return ClangBuiltinStr; }
-
-  // Return the C/C++ string representation of a type for use in the
-  // riscv_vector.h header file.
-  const std::string &getTypeStr() const { return Str; }
-
-  // Return the short name of a type for C/C++ name suffix.
-  const std::string &getShortStr() {
-// Not all types are used in short name, so compute the short name by
-// demanded.
-if (ShortStr.empty())
-  initShortStr();
-return ShortStr;
-  }
-
-  bool isValid() const { return Valid; }
-  bool isScalar() const { return Scale.hasValue() && Scale.getValue() == 0; }
-  bool isVector() const { return Scale.hasValue() && Scale.getValue() != 0; }
-  bool isVector(unsigned Width) const {
-return isVector() && ElementBitwidth == Width;
-  }
-  bool isFloat() const { return ScalarType == ScalarTypeKind::Float; }
-  bool isSignedInteger() const {
-return ScalarType == ScalarTypeKind::SignedInteger;
-  }
-  bool isFloatVector(unsigned Width) const {
-return isVector() && isFloat() && ElementBitwidth == Width;
-  }
-  bool isFloat(unsigned Width) const {
-return isFloat() && ElementBitwidth == Width;
-  }
-
-private:
-  // Verify RVV vector type and set Valid.
-  bool verifyType() const;
-
-  // Creates a type based on basic types of TypeRange
-  void applyBasicType();
-
-  // Applies a prototype modifier to the current type. The result maybe an
-  // invalid type.
-  void applyModifier(StringRef prototype);
-
-  // Compute and record a string for legal type.
-  void initBuiltinStr();
-  // Compute and record a builtin RVV vector type string.
-  void initClangBuiltinStr();
-  // Compute and record a type string for used in the header.
-  void initTypeStr();
-  // Compute and record a short name of a type for C/C++ name suffix.
-  void initShortStr();
-};
-
-using RVVTypePtr = RVVType *;
-using RVVTypes = std::vector;
-using RISCVPredefinedMacroT = uint8_t;
-
-enum RISCVPredefinedMacro : RISCVPredefinedMacroT {
-  Basic = 0,
-  V = 1 << 1,
-  Zvfh = 1 << 2,
-  RV64 = 1 << 3,
-  VectorMaxELen64 = 1 << 4,
-  VectorMaxELenFp32 = 1 << 5,
-  VectorMaxELenFp64 = 1 << 6,
-};
-
-enum PolicyScheme : uint8_t {
-  SchemeNone,
-  HasPassthruOperand,
-  HasPolicyOperand,
-};
-
-// TODO refactor RVVIntrinsic class de

[clang] 6c93e1d - [flang][driver] Add support for `-mmlir`

2022-04-14 Thread Andrzej Warzynski via cfe-commits

Author: Andrzej Warzynski
Date: 2022-04-14T09:40:31Z
New Revision: 6c93e1d329e6c6ef828ec63c66f4cb39ee9cb9ce

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

LOG: [flang][driver] Add support for `-mmlir`

The semantics of `-mmlir` are identical to `-mllvm`. The only notable
difference is that `-mmlir` options should be forwarded to MLIR rather
than LLVM.

Note that MLIR llvm::cl options are lazily constructed on demand (see
the definition of options in PassManagerOptions.cpp). This means that:
  * MLIR global options are only visible when explicitly initialised and
displayed only when using `-mmlir --help`,
  * Flang and LLVM global options are always visible and displayed when
using either `-mllvm -help` or `-mmlir --help`.

In other words, `-mmlir --help` is a superset of `-mllvm --help`. This is not
ideal, but we'd need to refactor all option definitions in Flang and
LLVM to improve this. I suggesting leaving this for later.

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

Added: 
flang/test/Driver/mllvm_vs_mmlir.f90

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/include/flang/Frontend/FrontendOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/lib/FrontendTool/CMakeLists.txt
flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 87b5ef2d39c33..104c8ea8483d1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3264,6 +3264,8 @@ def mlinker_version_EQ : Joined<["-"], 
"mlinker-version=">,
 def mllvm : Separate<["-"], 
"mllvm">,Flags<[CC1Option,CC1AsOption,CoreOption,FC1Option,FlangOption]>,
   HelpText<"Additional arguments to forward to LLVM's option processing">,
   MarshallingInfoStringVector>;
+def mmlir : Separate<["-"], "mmlir">, 
Flags<[CoreOption,FC1Option,FlangOption]>,
+  HelpText<"Additional arguments to forward to MLIR's option processing">;
 def ffuchsia_api_level_EQ : Joined<["-"], "ffuchsia-api-level=">,
   Group, Flags<[CC1Option]>, HelpText<"Set Fuchsia API level">,
   MarshallingInfoInt>;

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 283b5ca80b28c..63e3c080a7e7f 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -113,6 +113,11 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 A->render(Args, CmdArgs);
   }
 
+  for (const Arg *A : Args.filtered(options::OPT_mmlir)) {
+A->claim();
+A->render(Args, CmdArgs);
+  }
+
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());

diff  --git a/flang/include/flang/Frontend/FrontendOptions.h 
b/flang/include/flang/Frontend/FrontendOptions.h
index d0459e4bf06ff..ab085172e6d9f 100644
--- a/flang/include/flang/Frontend/FrontendOptions.h
+++ b/flang/include/flang/Frontend/FrontendOptions.h
@@ -273,6 +273,10 @@ struct FrontendOptions {
   /// should only be used for debugging and experimental features.
   std::vector llvmArgs;
 
+  /// A list of arguments to forward to MLIR's option processing; this
+  /// should only be used for debugging and experimental features.
+  std::vector mlirArgs;
+
   // Return the appropriate input kind for a file extension. For example,
   /// "*.f" would return Language::Fortran.
   ///

diff  --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index ea5accd76bca2..0f0db576a4fed 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -597,6 +597,9 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation 
&res,
   res.frontendOpts_.llvmArgs =
   args.getAllArgValues(clang::driver::options::OPT_mllvm);
 
+  res.frontendOpts_.mlirArgs =
+  args.getAllArgValues(clang::driver::options::OPT_mmlir);
+
   return success;
 }
 

diff  --git a/flang/lib/Frontend/FrontendActions.cpp 
b/flang/lib/Frontend/FrontendActions.cpp
index a05c2e27a34b4..83e795c16906f 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -427,6 +427,7 @@ void CodeGenAction::GenerateLLVMIR() {
 
   // Create the pass pipeline
   fir::createMLIRToLLVMPassPipeline(pm);
+  mlir::applyPassManagerCLOptions(pm);
 
   // Run the pass manager
   if (!mlir::succeeded(pm.run(*mlirModule))) {

diff  --git a/flang/lib/FrontendTool/CMakeLists.txt 
b/flang/lib/FrontendTool/CMakeLists.txt
index 1a29f4acd9ae7..0753313d73427 100644
--- a/flang/lib/FrontendToo

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-14 Thread Andrzej Warzynski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6c93e1d329e6: [flang][driver] Add support for `-mmlir` 
(authored by awarzynski).

Changed prior to commit:
  https://reviews.llvm.org/D123297?vs=422163&id=422787#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/FrontendTool/CMakeLists.txt
  flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/mllvm_vs_mmlir.f90

Index: flang/test/Driver/mllvm_vs_mmlir.f90
===
--- /dev/null
+++ flang/test/Driver/mllvm_vs_mmlir.f90
@@ -0,0 +1,19 @@
+! Verify that `-mllvm` options are forwarded to LLVM and `-mmlir` to MLIR.
+
+! In practice, '-mmlir --help' is a super-set of '-mllvm --help' and that limits what we can test here. With a better seperation of
+! LLVM, MLIR and Flang global options, we should be able to write a stricter test.
+
+!
+! RUN COMMAND
+!
+! RUN: %flang_fc1  -mmlir --help | FileCheck %s --check-prefix=MLIR
+! RUN: %flang_fc1  -mllvm --help | FileCheck %s --check-prefix=MLLVM
+
+!
+! EXPECTED OUTPUT
+!
+! MLIR: flang (MLIR option parsing) [options]
+! MLIR: --mlir-{{.*}}
+
+! MLLVM: flang (LLVM option parsing) [options]
+! MLLVM-NOT: --mlir-{{.*}}
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -48,6 +48,7 @@
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-NEXT: -module-dir   Put MODULE files in 
 ! HELP-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! HELP-NEXT: -o   Write output to 
@@ -124,6 +125,7 @@
 ! HELP-FC1-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-FC1-NEXT: -load Load the named plugin (dynamic shared object)
 ! HELP-FC1-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! HELP-FC1-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! HELP-FC1-NEXT: -module-dir   Put MODULE files in 
 ! HELP-FC1-NEXT: -module-suffix  Use  as the suffix for module files (the default value is `.mod`)
 ! HELP-FC1-NEXT: -nocpp Disable predefined and command line preprocessor macros
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -48,6 +48,7 @@
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -mllvm  Additional arguments to forward to LLVM's option processing
+! CHECK-NEXT: -mmlir  Additional arguments to forward to MLIR's option processing
 ! CHECK-NEXT: -module-dir   Put MODULE files in 
 ! CHECK-NEXT: -nocpp Disable predefined and command line preprocessor macros
 ! CHECK-NEXT: -o  Write output to 
Index: flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ flang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -19,6 +19,8 @@
 #include "llvm/Option/Option.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CommandLine.h"
+#include "mlir/IR/MLIRContext.h"
+#include "mlir/Pass/PassManager.h"
 
 namespace Fortran::frontend {
 
@@ -150,6 +152,21 @@
 llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
   }
 
+  // Honor -mmlir. This should happen AFTER plugins have been loaded!
+  if (!flang->frontendOpts().mlirArgs.empty()) {
+mlir::registerMLIRContextCLOptions();
+mlir::registerPassManagerCLOptions();
+unsigned numArgs = flang->frontendOpts().mlirArgs.size();
+auto args = std::make_unique(numArgs + 2);
+args[0] = "flang (MLIR option parsing)";
+
+for (unsigned i = 0; i != numArgs; ++i)
+  args[i + 1] = flang->frontendOpts().mlirArgs[i].c_str();
+
+args[numArgs + 1] = nullptr;
+llvm::cl::ParseCommandLineOptions(numArgs + 1, args.get());
+  }
+
   // If there were errors in proc

[PATCH] D123297: [flang][driver] Add support for -mmlir

2022-04-14 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3272
   MarshallingInfoStringVector>;
+def mmlir : Separate<["-"], "mmlir">,Flags<[CoreOption,FC1Option,FlangOption]>,
+  HelpText<"Additional arguments to forward to MLIR's option processing">;

MaskRay wrote:
> 
Thanks, included in the final version!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123297

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


[PATCH] D123775: [AST] Support template declaration found through using-decl for QualifiedTemplateName.

2022-04-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang.

This is a followup of https://reviews.llvm.org/D123127, adding support
for the QualifiedTemplateName.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123775

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/PropertiesBase.td
  clang/include/clang/AST/TemplateName.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/QualTypeNames.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/unittests/AST/TemplateNameTest.cpp

Index: clang/unittests/AST/TemplateNameTest.cpp
===
--- clang/unittests/AST/TemplateNameTest.cpp
+++ clang/unittests/AST/TemplateNameTest.cpp
@@ -58,5 +58,66 @@
 "vector");
 }
 
+TEST(TemplateName, QualifiedUsingTemplate) {
+  std::string Code = R"cpp(
+namespace std {
+  template  struct vector {};
+}
+namespace absl { using std::vector; }
+
+template class T> class X;
+
+using A = X; // QualifiedTemplateName in template argument.
+  )cpp";
+  auto AST = tooling::buildASTFromCode(Code);
+  // Match the template argument absl::vector in X.
+  auto Matcher = templateArgumentLoc().bind("id");
+  auto MatchResults = match(Matcher, AST->getASTContext());
+  const auto *TAL = MatchResults.front().getNodeAs("id");
+  ASSERT_TRUE(TAL);
+  TemplateName TN = TAL->getArgument().getAsTemplate();
+  EXPECT_EQ(TN.getKind(), TemplateName::QualifiedTemplate);
+  const auto *QTN = TN.getAsQualifiedTemplateName();
+  // Verify that we have the Using template name in the QualifiedTemplateName.
+  EXPECT_TRUE(QTN->getUsingShadowDecl());
+  EXPECT_EQ(QTN->getUsingShadowDecl()->getTargetDecl(), TN.getAsTemplateDecl());
+}
+
+TEST(TemplateName, UsingTemplate) {
+  auto AST = tooling::buildASTFromCode(R"cpp(
+namespace std {
+  template  struct vector { public: vector(T); };
+}
+namespace absl { using std::vector; }
+// absl::vector is a TemplateSpecializationType with an inner Using
+// TemplateName (not a Qualified TemplateName, the qualifiers are
+// stripped when constructing the TemplateSpecializationType)!
+absl::vector* Ptr;
+  )cpp");
+  auto Matcher = typeLoc(loc(templateSpecializationType().bind("id")));
+  auto MatchResults = match(Matcher, AST->getASTContext());
+  const auto *TST =
+  MatchResults.front().getNodeAs("id");
+  ASSERT_TRUE(TST);
+  EXPECT_EQ(TST->getTemplateName().getKind(), TemplateName::UsingTemplate);
+
+  AST = tooling::buildASTFromCodeWithArgs(R"cpp(
+namespace std {
+  template  struct vector { public: vector(T); };
+}
+namespace absl { using std::vector; }
+// Similiar to the TemplateSpecializationType, absl::vector is a
+// DeducedTemplateSpecializationType with an inner Using TemplateName!
+absl::vector DTST(123);
+)cpp",
+  {"-std=c++17"});
+  Matcher = typeLoc(loc(deducedTemplateSpecializationType().bind("id")));
+  MatchResults = match(Matcher, AST->getASTContext());
+  const auto *DTST =
+  MatchResults.front().getNodeAs("id");
+  ASSERT_TRUE(DTST);
+  EXPECT_EQ(DTST->getTemplateName().getKind(), TemplateName::UsingTemplate);
+}
+
 } // namespace
 } // namespace clang
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -14714,7 +14714,7 @@
 bool TemplateKW,
 TemplateDecl *Template) {
   return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
-  Template);
+  TemplateName(Template));
 }
 
 template
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -284,17 +284,13 @@
 }
 
 TemplateDecl *TD = cast(D);
-
+Template =
+FoundUsingShadow ? TemplateName(FoundUsingShadow) : TemplateName(TD);
+assert(!FoundUsingShadow || FoundUsingShadow->getTargetDecl() == TD);
 if (SS.isSet() && !SS.isInvalid()) {
   NestedNameSpecifier *Qualifier = SS.getScopeRep();
-  // FIXME: store the using TemplateName in QualifiedTemplateName if
-  // the TD is referred via a using-declaration.
-  Template =
-  Context.getQualifiedTemplateName(Qualifier, hasTemplateKeyword, TD);
-} else {
-  Template =
-  FoundUsingShadow ? TemplateName(FoundUsingShadow) : TemplateName(TD);
-  assert(!FoundUsingShadow || FoundUsingShadow-

[PATCH] D123773: [clang][analyzer][ctu] Make CTU a two phase analysis

2022-04-14 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:167
+  // Let CTU run as many steps we had in the single TU run.
+  // However, we need at least some minimal value to pass those lit tests that
+  // report a bug only in the CTU mode.

Well, not just for lit tests, I'll update the comment.



Comment at: clang/test/Analysis/ctu-main.cpp:178
 
+  // FIXME we should report an UNKNOWN as well for all external variables!
   clang_analyzer_eval(extInt == 2); // expected-warning{{TRUE}}

This FIXME is outdated, got here during rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123773

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


[PATCH] D122255: Meta directive runtime support

2022-04-14 Thread Abid via Phabricator via cfe-commits
abidmalikwaterloo added a comment.

The last update removed all previous updates. Can you point me to the correct 
way to do it?
I did the following :
arc patch D122255 
"did something/cleaning"
git commit -a --amend
arc diff


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122255

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


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

> Presumably we should be parsing the attribute in the enclosing context rather 
> than in the half-way-inside-the-lambda context in which we parse parameters?

That's a good question.

  void f() {
  int y;
  (void)[=, x = 1]() 
  __attribute__((diagnose_if(!is_same, "wrong type", 
"warning")))  // do we want this to work?
  __attribute__((diagnose_if(x != 1, "wrong type", "warning"))) // do we 
want this to work?
  mutable {}();
  }

I think we *probably* want both of this to compile and evaluate the conditions 
consistently with the new rule for trailing return type/`requires`/`noexcept` 
specifier (in that case triggering no warning).
So the consistent approach would be to parse them in the context of the call 
operator, once the captures and their type is known.

Is there any reason we should not be consistent with the spirit of the c++ spec 
here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

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


[PATCH] D123627: Correctly diagnose prototype redeclaration errors in C

2022-04-14 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

It looks like this caused the LNT build bot to fail (at least on s390x), 
because one of the test cases now triggers this error:
https://lab.llvm.org/buildbot/#/builders/45/builds/6787

  /usr/bin/make -f 
SingleSource/Regression/C/gcc-c-torture/execute/ieee/CMakeFiles/GCC-C-execute-ieee-compare-fp-4.dir/build.make
 
SingleSource/Regression/C/gcc-c-torture/execute/ieee/CMakeFiles/GCC-C-execute-ieee-compare-fp-4.dir/build
  
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/test/test-suite/SingleSource/Regression/C/gcc-c-torture/execute/ieee/20030331-1.c:6:1:
 error: conflicting types for 'rintf'
  rintf ()
  ^
  
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/test/test-suite/SingleSource/Regression/C/gcc-c-torture/execute/ieee/20030331-1.c:6:1:
 note: previous implicit declaration is here
  make[2]: Entering directory 
'/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/test/sandbox/build'
  
/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/test/test-suite/SingleSource/Regression/C/gcc-c-torture/execute/ieee/20030331-1.c:29:14:
 error: too few arguments to function call, expected 1, have 0
if (rintf () != -2.0)
~  ^
  2 errors generated.

I guess the error is valid, but should either be disabled for this LNT test, or 
else the test fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123627

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


[PATCH] D123655: [clang-tidy] Add portability-std-allocator-const check

2022-04-14 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Looks like this breaks tests on windows: http://45.33.8.238/win/56334/step_8.txt

Please take a look and revert for now if it takes a while to fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123655

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


[PATCH] D123609: [Clang] Remove support for legacy pass manager

2022-04-14 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen added a comment.

Hi @nikic,
We recently noticed legacy PM was removed from many places.
Does community plan to remove legacy PM completely?
Do you know when will CG switch to new PM?
Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123609

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


[PATCH] D123609: [Clang] Remove support for legacy pass manager

2022-04-14 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D123609#3451320 , @HaohaiWen wrote:

> Hi @nikic,
> We recently noticed legacy PM was removed from many places.
> Does community plan to remove legacy PM completely?
> Do you know when will CG switch to new PM?
> Thanks.

At this time, the ability to run a middle-end optimization pipeline using the 
legacy pass manager (basically anything based on PassManagerBuilder) is being 
removed. The CodeGen pipeline continues to use the legacy pass manager at this 
time -- I'm not aware of anyone doing active migration work in that area.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123609

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


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 422806.
cor3ntin added a comment.

  Properly support GNU Attributes
  
  Perform delayed parsing of GNU attributes (using code that already
  existed to delay the parsing of class methods), so that
  gnu attributes can refer to captured variables,
  with the same semantics as decltype/noexcept/requires.
  
  In order we:
   * Lex the attributes
   * Parse the mutable keyword
   * Inject parameter names in the scope of the call operator
 so they get found during attribute parsing
   * Parse the attributes and attach them to the declarator
 being parsed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/Scope.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1356,7 +1356,7 @@
 
   Change scope of lambda trailing-return-type
   https://wg21.link/P2036R3";>P2036R3
-  No
+  Clang 15
 
 
   Multidimensional subscript operator
Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -95,7 +95,7 @@
 #ifdef AVOID
   auto l4 = [var = param] (int param) { ; }; // no warning
 #else
-  auto l4 = [var = param] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+  auto l4 = [var = param](int param) { ; }; // expected-warning 2{{declaration shadows a local variable}}
 #endif
 
   // Make sure that inner lambdas work as well.
Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -0,0 +1,173 @@
+// RUN: %clang_cc1 -std=c++2b -verify -fsyntax-only %s
+
+template 
+constexpr bool is_same = false;
+
+template 
+constexpr bool is_same = true;
+
+void f() {
+
+  int y;
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  auto ref = [&x = y](
+ decltype([&](decltype(x)) { return 0; }) y) {
+return x;
+  };
+}
+
+void test_noexcept() {
+
+  int y;
+
+  static_assert(noexcept([x = 1] noexcept(is_same) {}()));
+  static_assert(noexcept([x = 1] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([y] noexcept(is_same) {}()));
+  static_assert(noexcept([y] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([=] noexcept(is_same) {}()));
+  static_assert(noexcept([=] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([&] noexcept(is_same) {}()));
+  static_assert(noexcept([&] mutable noexcept(is_same) {}()));
+
+  static_assert(noexcept([&] mutable noexcept(!is_same) {}())); // expected-error {{static_assert failed due}}
+}
+
+void test_requires() {
+
+  int x;
+
+  [x = 1]() requires is_same {}
+  ();
+  [x = 1]() mutable requires is_same {}
+  ();
+  [x]() requires is_same {}
+  ();
+  [x]() mutable requires is_same {}
+  ();
+  [=]() requires is_same {}
+  ();
+  [=]() mutable requires is_same {}
+  ();
+  [&]() requires is_same {}
+  ();
+  [&]() mutable requires is_same {}
+  ();
+  [&x]() requires is_same {}
+  ();
+  [&x]() mutable requires is_same {}
+  ();
+
+  [x = 1]() requires is_same {} (); //expected-error {{no matching function for call to object of type}} \
+   // expected-note {{candidate function not viable}} \
+   // expected-note {{'is_same' evaluated to false}}
+  [x = 1]() mutable requires is_same {} (); // expected-error {{no matching function for call to object of type}} \
+ // expected-note {{candidate function not viable}} \
+   

[PATCH] D123627: Correctly diagnose prototype redeclaration errors in C

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman marked an inline comment as done.
aaron.ballman added a comment.

In D123627#3451269 , @uweigand wrote:

> It looks like this caused the LNT build bot to fail (at least on s390x), 
> because one of the test cases now triggers this error:
> https://lab.llvm.org/buildbot/#/builders/45/builds/6787
>
>   /usr/bin/make -f 
> SingleSource/Regression/C/gcc-c-torture/execute/ieee/CMakeFiles/GCC-C-execute-ieee-compare-fp-4.dir/build.make
>  
> SingleSource/Regression/C/gcc-c-torture/execute/ieee/CMakeFiles/GCC-C-execute-ieee-compare-fp-4.dir/build
>   
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/test/test-suite/SingleSource/Regression/C/gcc-c-torture/execute/ieee/20030331-1.c:6:1:
>  error: conflicting types for 'rintf'
>   rintf ()
>   ^
>   
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/test/test-suite/SingleSource/Regression/C/gcc-c-torture/execute/ieee/20030331-1.c:6:1:
>  note: previous implicit declaration is here
>   make[2]: Entering directory 
> '/home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/test/sandbox/build'
>   
> /home/uweigand/sandbox/buildbot/clang-s390x-linux-lnt/test/test-suite/SingleSource/Regression/C/gcc-c-torture/execute/ieee/20030331-1.c:29:14:
>  error: too few arguments to function call, expected 1, have 0
> if (rintf () != -2.0)
> ~  ^
>   2 errors generated.
>
> I guess the error is valid, but should either be disabled for this LNT test, 
> or else the test fixed.

Thank you for letting me know -- I've speculatively fixed the issue in 
726901d06aab2f92d684d28507711308368c29d6


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123627

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


[PATCH] D123783: [clang] Eliminate TypeProcessingState::trivial.

2022-04-14 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This flag is redundant -- it's true iff `savedAttrs` is empty.

Querying `savedAttrs.empty()` should not take any more time than querying the
`trivial` flag, so this should not have a performance impact either.

I noticed this while working on https://reviews.llvm.org/D111548.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123783

Files:
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -166,9 +166,6 @@
 /// DeclSpec.
 unsigned chunkIndex;
 
-/// Whether there are non-trivial modifications to the decl spec.
-bool trivial;
-
 /// Whether we saved the attributes in the decl spec.
 bool hasSavedAttrs;
 
@@ -200,8 +197,8 @@
   public:
 TypeProcessingState(Sema &sema, Declarator &declarator)
 : sema(sema), declarator(declarator),
-  chunkIndex(declarator.getNumTypeObjects()), trivial(true),
-  hasSavedAttrs(false), parsedNoDeref(false) {}
+  chunkIndex(declarator.getNumTypeObjects()), hasSavedAttrs(false),
+  parsedNoDeref(false) {}
 
 Sema &getSema() const {
   return sema;
@@ -238,7 +235,6 @@
   DeclSpec &spec = getMutableDeclSpec();
   llvm::append_range(savedAttrs,
  llvm::make_pointer_range(spec.getAttributes()));
-  trivial &= savedAttrs.empty();
   hasSavedAttrs = true;
 }
 
@@ -330,7 +326,8 @@
 bool didParseNoDeref() const { return parsedNoDeref; }
 
 ~TypeProcessingState() {
-  if (trivial) return;
+  if (savedAttrs.empty())
+return;
 
   restoreDeclSpecAttrs();
 }


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -166,9 +166,6 @@
 /// DeclSpec.
 unsigned chunkIndex;
 
-/// Whether there are non-trivial modifications to the decl spec.
-bool trivial;
-
 /// Whether we saved the attributes in the decl spec.
 bool hasSavedAttrs;
 
@@ -200,8 +197,8 @@
   public:
 TypeProcessingState(Sema &sema, Declarator &declarator)
 : sema(sema), declarator(declarator),
-  chunkIndex(declarator.getNumTypeObjects()), trivial(true),
-  hasSavedAttrs(false), parsedNoDeref(false) {}
+  chunkIndex(declarator.getNumTypeObjects()), hasSavedAttrs(false),
+  parsedNoDeref(false) {}
 
 Sema &getSema() const {
   return sema;
@@ -238,7 +235,6 @@
   DeclSpec &spec = getMutableDeclSpec();
   llvm::append_range(savedAttrs,
  llvm::make_pointer_range(spec.getAttributes()));
-  trivial &= savedAttrs.empty();
   hasSavedAttrs = true;
 }
 
@@ -330,7 +326,8 @@
 bool didParseNoDeref() const { return parsedNoDeref; }
 
 ~TypeProcessingState() {
-  if (trivial) return;
+  if (savedAttrs.empty())
+return;
 
   restoreDeclSpecAttrs();
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123784: [clang][analyzer][ctu] Traverse the ctu CallEnter nodes in reverse order

2022-04-14 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: NoQ, steakhal, xazax.hun.
Herald added subscribers: manas, ASDenysPetrov, gamesh411, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware.
Herald added a reviewer: Szelethus.
Herald added a project: All.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This change reverses the traverse order of those nodes that had been added to
the ctu worklist during the first phase of the analysis. By reversing the order
of these nodes, we start in the ctu phase with the nodes that are closer to the
root node. Measurements show that this way the length of the bug-paths are
decreasing with roughly by 10%.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123784

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
  clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
  clang/lib/StaticAnalyzer/Core/WorkList.cpp

Index: clang/lib/StaticAnalyzer/Core/WorkList.cpp
===
--- clang/lib/StaticAnalyzer/Core/WorkList.cpp
+++ clang/lib/StaticAnalyzer/Core/WorkList.cpp
@@ -190,7 +190,9 @@
 }
 
 namespace {
+
 class UnexploredFirstPriorityQueue : public WorkList {
+protected:
   using BlockID = unsigned;
   using LocIdentifier = std::pair;
 
@@ -202,7 +204,7 @@
   // Compare by number of times the location was visited first (negated
   // to prefer less often visited locations), then by insertion time (prefer
   // expanding nodes inserted sooner first).
-  using QueuePriority = std::pair;
+  using QueuePriority = std::pair;
   using QueueItem = std::pair;
 
   struct ExplorationComparator {
@@ -213,7 +215,7 @@
 
   // Number of inserted nodes, used to emulate DFS ordering in the priority
   // queue when insertions are equal.
-  unsigned long Counter = 0;
+  long Counter = 0;
 
   // Number of times a current location was reached.
   VisitedTimesMap NumReached;
@@ -222,12 +224,7 @@
   llvm::PriorityQueue, ExplorationComparator>
   queue;
 
-public:
-  bool hasWork() const override {
-return !queue.empty();
-  }
-
-  void enqueue(const WorkListUnit &U) override {
+  unsigned getNumVisited(const WorkListUnit &U) {
 const ExplodedNode *N = U.getNode();
 unsigned NumVisited = 0;
 if (auto BE = N->getLocation().getAs()) {
@@ -236,7 +233,14 @@
   N->getLocationContext()->getStackFrame());
   NumVisited = NumReached[LocId]++;
 }
+return NumVisited;
+  }
 
+public:
+  bool hasWork() const override { return !queue.empty(); }
+
+  void enqueue(const WorkListUnit &U) override {
+unsigned NumVisited = getNumVisited(U);
 queue.push(std::make_pair(U, std::make_pair(-NumVisited, ++Counter)));
   }
 
@@ -246,12 +250,41 @@
 return U.first;
   }
 };
+
+class CTUWorkList : public UnexploredFirstPriorityQueue {
+  enum class SecondaryOrder { DFS = 1, ReverseDFS };
+  SecondaryOrder ScndOrd = SecondaryOrder::ReverseDFS;
+
+  long ReverseDFSCounter = 0;
+
+public:
+  void enqueue(const WorkListUnit &U) override {
+unsigned NumVisited = getNumVisited(U);
+queue.push(std::make_pair(
+U, std::make_pair(-NumVisited, ScndOrd == SecondaryOrder::DFS
+   ? ++Counter
+   : --ReverseDFSCounter)));
+  }
+
+  WorkListUnit dequeue() override {
+// During the first phase we never call dequeue(). Thus, the first call of
+// dequeue() indicates the start of the second phase. We want to have the
+// normal ordering during the second phase.
+ScndOrd = SecondaryOrder::DFS;
+return UnexploredFirstPriorityQueue::dequeue();
+  }
+};
+
 } // namespace
 
 std::unique_ptr WorkList::makeUnexploredFirstPriorityQueue() {
   return std::make_unique();
 }
 
+std::unique_ptr WorkList::makeCTUWorkList() {
+  return std::make_unique();
+}
+
 namespace {
 class UnexploredFirstPriorityLocationQueue : public WorkList {
   using LocIdentifier = const CFGBlock *;
Index: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -75,7 +75,7 @@
 CoreEngine::CoreEngine(ExprEngine &exprengine, FunctionSummariesTy *FS,
AnalyzerOptions &Opts)
 : ExprEng(exprengine), WList(generateWorkList(Opts)),
-  CTUWList(generateWorkList(Opts)), BCounterFactory(G.getAllocator()),
+  CTUWList(WorkList::makeCTUWorkList()), BCounterFactory(G.getAllocator()),
   FunctionSummaries(FS) {}
 
 void CoreEngine::setBlockCounter(BlockCounter C) {
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/WorkList.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/

[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D122983#3450177 , @rsmith wrote:

> It seems surprising to me for the diagnostic to change from warn-by-default 
> to error-by-default when changing from C99 to C11, given that the language 
> rule did not change between C99 and C11 (as a Clang user, when changing my 
> `-std=` flag, I don't want other changes to come in that are unrelated to the 
> language mode change I requested).

FWIW, that's the approach I originally considered. I eventually discarded it as 
being likely too disruptive for users (with risk of pushing some people to not 
upgrade to Clang 15).

This situation is a somewhat unique one. C89 supported this feature and it was 
not obsolescent in that revision of the standard. C99 removed the feature 
outright. (The same thing happened to implicit int.) Because there was no 
deprecation period, people got caught off guard and so compilers made it a 
warning in C99 that also triggered in C89. As best I can tell, this is the 
first time the severity question has been revisited. The reason I took the 
approach I did is because of the lack of deprecation period and the somewhat 
common user practice of using an effectively-C89 code base with some C99 
features (most often: ability to mix decls + code, `//` comments, and `long 
long` support -- aka, what MSVC considered "C" to be for many, many years).

> I think we should just make this an error by default in C99 onwards; if we're 
> happy promoting this from warning-by-default to error-by-default for the 
> folks using `-std=c11` and later (and I think we are), then we should be 
> happy doing the same for the `-std=c99` folks too -- especially given that 
> C17 is the default everywhere other than on PS4.

I see where you're coming from, but I don't think it's practical. We've given 
users this as a warning in C99 and later for a *long* time (since Clang 2.6 
from 2009), so I anticipate an error breaking some amount of code for people 
passing `-std=c99` explicitly. We do still run the risk of breaking people who 
are on C11 or C17 (particularly, given it's the default when no `-std=` is 
provided), but that feels like a more manageable risk. Those folks are clearly 
interested in upgrading language modes that I don't think apply to folks 
specifying C99 specifically (now that it's 20+ years old).

tl;dr: I think the current approach strikes a good balance between pushing 
people to improve their code and giving them a reasonable upgrade path through 
the language standards.


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

https://reviews.llvm.org/D122983

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


[PATCH] D123212: [clangd] Handle the new UsingTemplateName.

2022-04-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 422823.
hokein added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123212

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp

Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -79,9 +79,22 @@
   "using namespace ns;",
   },
   {
+  // Refs from UsingTypeLoc and implicit constructor!
   "struct ^A {}; using B = A; using ^C = B;",
   "C a;",
   },
+  {"namespace ns { template class A {}; } using ns::^A;",
+   "A* a;"},
+  {"namespace ns { template class A {}; } using ns::^A;",
+   R"cpp(
+  template  class T> class X {};
+  X x;
+)cpp"},
+  {R"cpp(
+  namespace ns { template struct ^A { ^A(T); }; }
+  using ns::^A;
+   )cpp",
+   "A CATD(123);"},
   {
   "typedef bool ^Y; template  struct ^X {};",
   "X x;",
@@ -227,6 +240,7 @@
 TU.Code = T.MainCode;
 Annotations Header(T.HeaderCode);
 TU.HeaderCode = Header.code().str();
+TU.ExtraArgs.push_back("-std=c++17");
 auto AST = TU.build();
 
 std::vector Points;
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -229,6 +229,45 @@
 )cpp";
   EXPECT_DECLS("UnresolvedUsingValueDecl", {"using Base::waldo", Rel::Alias},
{"void waldo()"});
+
+  Code = R"cpp(
+namespace ns {
+template class S {};
+}
+
+using ns::S;
+
+template
+using A = [[S]];
+  )cpp";
+  EXPECT_DECLS("TemplateSpecializationTypeLoc", {"using ns::S", Rel::Alias},
+   {"template  class S"},
+   {"class S", Rel::TemplatePattern});
+
+  Code = R"cpp(
+namespace ns {
+template class S {};
+}
+
+using ns::S;
+template  class T> class X {};
+using B = X<[[S]]>;
+  )cpp";
+  EXPECT_DECLS("TemplateArgumentLoc", {"using ns::S", Rel::Alias},
+   {"template  class S"});
+
+  Code = R"cpp(
+namespace ns {
+template class S { public: S(T); };
+}
+
+using ns::S;
+[[S]] s(123);
+  )cpp";
+  Flags.push_back("-std=c++17"); // For CTAD feature.
+  EXPECT_DECLS("DeducedTemplateSpecializationTypeLoc",
+   {"using ns::S", Rel::Alias}, {"template  class S"},
+   {"class S", Rel::TemplatePattern});
 }
 
 TEST_F(TargetDeclTest, BaseSpecifier) {
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -75,11 +75,22 @@
   }
 
   bool VisitTemplateSpecializationType(TemplateSpecializationType *TST) {
+// Using templateName case is handled by the override TraverseTemplateName.
+if (TST->getTemplateName().getKind() == TemplateName::UsingTemplate)
+  return true;
 add(TST->getTemplateName().getAsTemplateDecl()); // Primary template.
 add(TST->getAsCXXRecordDecl());  // Specialization
 return true;
   }
 
+  // There is no VisitTemplateName in RAV, thus we override the Traverse version
+  // to handle the Using TemplateName case.
+  bool TraverseTemplateName(TemplateName TN) {
+if (const auto *USD = TN.getAsUsingShadowDecl())
+  add(USD);
+return Base::TraverseTemplateName(TN);
+  }
+
   bool VisitUsingType(UsingType *UT) {
 add(UT->getFoundDecl());
 return true;
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -384,11 +384,14 @@
   }
   void VisitDeducedTemplateSpecializationType(
   const DeducedTemplateSpecializationType *DTST) {
+if (const auto *USD = DTST->getTemplateName().getAsUsingShadowDecl())
+  Outer.add(USD, Flags);
+
 // FIXME: This is a workaround for https://llvm.org/PR42914,
 // which is causing DTST->getDeducedType() to be empty. We
 // fall back to the template pattern and miss the instantiation
 // even when it's known in principle. Once that bug is fixed,
-// this method can be removed (the existing handling in
+// the following code can be removed (the existing handling in
 // VisitDeducedType() is sufficient).
 if (auto *TD = DTST->getTemplate

[clang] 53fd8db - [Clang][AArch64][SVE] Allow subscript operator for SVE types

2022-04-14 Thread David Truby via cfe-commits

Author: David Truby
Date: 2022-04-14T13:20:50+01:00
New Revision: 53fd8db79192f38feaec11c761e0d0fbdf1516b0

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

LOG: [Clang][AArch64][SVE] Allow subscript operator for SVE types

Undefined behaviour is just passed on to extract_element when the
index is out of bounds. Subscript on svbool_t is not allowed as
this doesn't really have meaningful semantics.

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

Added: 
clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
clang/test/Sema/aarch64-sve-vector-subscript-ops.c

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/ExprConstant.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 3213163ee7876..ea3db40aad571 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6638,6 +6638,8 @@ def err_subscript_function_type : Error<
   "subscript of pointer to function type %0">;
 def err_subscript_incomplete_or_sizeless_type : Error<
   "subscript of pointer to %select{incomplete|sizeless}0 type %1">;
+def err_subscript_svbool_t : Error<
+  "subscript of svbool_t is not allowed">;
 def err_dereference_incomplete_type : Error<
   "dereference of pointer to incomplete type %0">;
 def ext_gnu_subscript_void_type : Extension<

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 93950ac5341ba..50d6340ed31f7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -8423,7 +8423,8 @@ bool LValueExprEvaluator::VisitMemberExpr(const 
MemberExpr *E) {
 
 bool LValueExprEvaluator::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) 
{
   // FIXME: Deal with vectors as array subscript bases.
-  if (E->getBase()->getType()->isVectorType())
+  if (E->getBase()->getType()->isVectorType() ||
+  E->getBase()->getType()->isVLSTBuiltinType())
 return Error(E);
 
   APSInt Index;

diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 0711c993088bc..d3fe04d5a7915 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1767,7 +1767,8 @@ Value 
*ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
   // loads the lvalue formed by the subscript expr.  However, we have to be
   // careful, because the base of a vector subscript is occasionally an rvalue,
   // so we can't get it as an lvalue.
-  if (!E->getBase()->getType()->isVectorType())
+  if (!E->getBase()->getType()->isVectorType() &&
+  !E->getBase()->getType()->isVLSTBuiltinType())
 return EmitLoadOfLValue(E);
 
   // Handle the vector case.  The base must be a vector, the index must be an

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index da1fed4d72aec..faff375314e92 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -27,11 +27,13 @@
 #include "clang/AST/OperationKinds.h"
 #include "clang/AST/ParentMapContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.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/Specifiers.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Lex/LiteralSupport.h"
 #include "clang/Lex/Preprocessor.h"
@@ -5683,6 +5685,33 @@ Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, 
SourceLocation LLoc,
   OK = OK_VectorComponent;
 
 ResultType = VTy->getElementType();
+QualType BaseType = BaseExpr->getType();
+Qualifiers BaseQuals = BaseType.getQualifiers();
+Qualifiers MemberQuals = ResultType.getQualifiers();
+Qualifiers Combined = BaseQuals + MemberQuals;
+if (Combined != MemberQuals)
+  ResultType = Context.getQualifiedType(ResultType, Combined);
+  } else if (LHSTy->isBuiltinType() &&
+ LHSTy->getAs()->isVLSTBuiltinType()) {
+const BuiltinType *BTy = LHSTy->getAs();
+if (BTy->isSVEBool())
+  return ExprError(Diag(LLoc, diag::err_subscript_svbool_t)
+   << LHSExp->getSourceRange() << 
RHSExp->getSourceRange());
+
+BaseExpr = LHSExp;
+IndexExpr = RHSExp;
+if (getLangOpts().CPlusPlus11 && LHSExp->isPRValue()) {
+  ExprResult Materialized = TemporaryMaterializationConversion(LHSExp);
+  if (Materialized.isInvalid())
+return ExprError();
+  LHSExp = Materialized.get();
+}
+VK = LHSExp->getValueKind();
+if (VK != VK_PRValue)
+  OK = OK_VectorComponent;
+
+

[PATCH] D122732: [Clang][AArch64][SVE] Allow subscript operator for SVE types

2022-04-14 Thread David Truby via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG53fd8db79192: [Clang][AArch64][SVE] Allow subscript operator 
for SVE types (authored by DavidTruby).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122732

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
  clang/test/Sema/aarch64-sve-vector-subscript-ops.c

Index: clang/test/Sema/aarch64-sve-vector-subscript-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-subscript-ops.c
@@ -0,0 +1,47 @@
+// RUN: %clang_cc1 -verify -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -fsyntax-only %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+void subscript(svint8_t i8, svint16_t i16, svint32_t i32, svint64_t i64,
+   svuint8_t u8, svuint16_t u16, svuint32_t u32, svuint64_t u64,
+   svfloat16_t f16, svfloat32_t f32, svfloat64_t f64,
+   svbool_t b) {
+  (void)b[0];// expected-error{{subscript of svbool_t is not allowed}}
+  (void)b[0.f];  // expected-error{{subscript of svbool_t is not allowed}}
+  (void)b[0.];   // expected-error{{subscript of svbool_t is not allowed}}
+
+  (void)i8[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)i8[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)u8[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)u8[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)i16[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)i16[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)u16[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)u16[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)i32[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)i32[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)u32[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)u32[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)i64[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)i64[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)u64[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)u64[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)f16[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)f16[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)f32[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)f32[0.];  // expected-error{{array subscript is not an integer}}
+
+  (void)f64[0.f]; // expected-error{{array subscript is not an integer}}
+  (void)f64[0.];  // expected-error{{array subscript is not an integer}}
+}
Index: clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sve-vector-subscript-ops.c
@@ -0,0 +1,90 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve \
+// RUN: -fallow-half-arguments-and-returns -disable-O0-optnone \
+// RUN:  -emit-llvm -o - %s | opt -S -sroa | FileCheck %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+#include 
+
+// CHECK-LABEL: @subscript_int16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECEXT:%.*]] = extractelement  [[A:%.*]], i64 [[B:%.*]]
+// CHECK-NEXT:ret i16 [[VECEXT]]
+//
+int16_t subscript_int16(svint16_t a, size_t b) {
+  return a[b];
+}
+
+// CHECK-LABEL: @subscript_uint16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECEXT:%.*]] = extractelement  [[A:%.*]], i64 [[B:%.*]]
+// CHECK-NEXT:ret i16 [[VECEXT]]
+//
+uint16_t subscript_uint16(svuint16_t a, size_t b) {
+  return a[b];
+}
+
+// CHECK-LABEL: @subscript_int32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECEXT:%.*]] = extractelement  [[A:%.*]], i64 [[B:%.*]]
+// CHECK-NEXT:ret i32 [[VECEXT]]
+//
+int32_t subscript_int32(svint32_t a, size_t b) {
+  return a[b];
+}
+
+// CHECK-LABEL: @subscript_uint32(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECEXT:%.*]] = extractelement  [[A:%.*]], i64 [[B:%.*]]
+// CHECK-NEXT:ret i32 [[VECEXT]]
+//
+uint32_t subscript_uint32(svuint32_t a, size_t b) {
+  return a[b];
+}
+
+// CHECK-LABEL: @subscript_int64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VECEXT:%.*]] = extractelement  [[A:%.*]], i64 [[B:%.*]]
+// CHECK-NEXT:ret i64 [[VECEXT]]
+//
+int64_t subscript_int64(svint64_t a, size_t b) {
+  return a[b];
+}
+
+// CHECK-LABEL: @subscript_uint64(
+// CHECK-NEXT:

[PATCH] D123303: [Clang][AArch64][SVE] Add shift operators for SVE vector types

2022-04-14 Thread David Truby via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG66c44b20b4a5: [Clang][AArch64][SVE] Add shift operators for 
SVE vector types (authored by DavidTruby).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123303

Files:
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGen/aarch64-sve-vector-shift-ops.c
  clang/test/Sema/aarch64-sve-vector-shift-ops.c
  clang/test/Sema/sizeless-1.c
  clang/test/SemaCXX/sizeless-1.cpp

Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -210,14 +210,9 @@
   __real init_int8; // expected-error {{invalid type 'svint8_t'}}
   __imag init_int8; // expected-error {{invalid type 'svint8_t'}}
 
-  local_int8 << init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 >> init_int8; // expected-error {{invalid operands to binary expression}}
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}} expected-error {{not contextually convertible}}
 
-  local_int8 <<= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 >>= init_int8; // expected-error {{invalid operands to binary expression}}
-
   local_int8 + 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 - 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 * 0;  // expected-error {{invalid operands to binary expression}}
@@ -226,8 +221,6 @@
   local_int8 & 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 | 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 ^ 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 << 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 >> 0; // expected-error {{invalid operands to binary expression}}
   local_int8 < 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 <= 0; // expected-error {{invalid operands to binary expression}}
   local_int8 == 0; // expected-error {{invalid operands to binary expression}}
Index: clang/test/Sema/sizeless-1.c
===
--- clang/test/Sema/sizeless-1.c
+++ clang/test/Sema/sizeless-1.c
@@ -198,14 +198,9 @@
   __real init_int8; // expected-error {{invalid type 'svint8_t'}}
   __imag init_int8; // expected-error {{invalid type 'svint8_t'}}
 
-  local_int8 << init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 >> init_int8; // expected-error {{invalid operands to binary expression}}
   local_int8 &&init_int8;  // expected-error {{invalid operands to binary expression}}
   local_int8 || init_int8; // expected-error {{invalid operands to binary expression}}
 
-  local_int8 <<= init_int8; // expected-error {{invalid operands to binary expression}}
-  local_int8 >>= init_int8; // expected-error {{invalid operands to binary expression}}
-
   local_int8 + 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 - 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 * 0;  // expected-error {{invalid operands to binary expression}}
@@ -214,8 +209,6 @@
   local_int8 & 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 | 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 ^ 0;  // expected-error {{invalid operands to binary expression}}
-  local_int8 << 0; // expected-error {{invalid operands to binary expression}}
-  local_int8 >> 0; // expected-error {{invalid operands to binary expression}}
   local_int8 < 0;  // expected-error {{invalid operands to binary expression}}
   local_int8 <= 0; // expected-error {{invalid operands to binary expression}}
   local_int8 == 0; // expected-error {{invalid operands to binary expression}}
Index: clang/test/Sema/aarch64-sve-vector-shift-ops.c
===
--- /dev/null
+++ clang/test/Sema/aarch64-sve-vector-shift-ops.c
@@ -0,0 +1,583 @@
+// RUN: %clang_cc1 -verify -triple aarch64-none-linux-gnu -target-feature +sve -fallow-half-arguments-and-returns -fsyntax-only %s
+
+// REQUIRES: aarch64-registered-target
+
+#include 
+
+void lshift(svint8_t i8, svint16_t i16, svint32_t i32, svint64_t i64,
+svuint8_t u8, svuint16_t u16, svuint32_t u32, svuint64_t u64,
+svfloat16_t f16, svfloat32_t f32, svfloat64_t f64,
+svbool_t b) {
+  (void)(b << b); // expected-error{{invalid operands to binary expression}}
+
+  (void)(i8 << b);   // expected-error{{invalid operands to binary expression}}
+  (void)(i8 << i16); // expec

[clang] 66c44b2 - [Clang][AArch64][SVE] Add shift operators for SVE vector types

2022-04-14 Thread David Truby via cfe-commits

Author: David Truby
Date: 2022-04-14T13:20:50+01:00
New Revision: 66c44b20b4a538fbb1bae8bc9533c25f5a006bd5

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

LOG: [Clang][AArch64][SVE] Add shift operators for SVE vector types

This patch enables shift operators on SVE vector types, as well as
supporting vector-scalar shift operations.
Shifts by a scalar that is wider than the contained type in the
vector are permitted but as in the C standard if the value is larger
than the width of the type the behavior is undefined.

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

Added: 
clang/test/CodeGen/aarch64-sve-vector-shift-ops.c
clang/test/Sema/aarch64-sve-vector-shift-ops.c

Modified: 
clang/lib/Sema/SemaExpr.cpp
clang/test/Sema/sizeless-1.c
clang/test/SemaCXX/sizeless-1.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index faff375314e92..f210a8ba7aac2 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -11476,6 +11476,97 @@ static QualType checkVectorShift(Sema &S, ExprResult 
&LHS, ExprResult &RHS,
   return LHSType;
 }
 
+static QualType checkSizelessVectorShift(Sema &S, ExprResult &LHS,
+ ExprResult &RHS, SourceLocation Loc,
+ bool IsCompAssign) {
+  if (!IsCompAssign) {
+LHS = S.UsualUnaryConversions(LHS.get());
+if (LHS.isInvalid())
+  return QualType();
+  }
+
+  RHS = S.UsualUnaryConversions(RHS.get());
+  if (RHS.isInvalid())
+return QualType();
+
+  QualType LHSType = LHS.get()->getType();
+  const BuiltinType *LHSBuiltinTy = LHSType->getAs();
+  QualType LHSEleType = LHSType->isVLSTBuiltinType()
+? LHSBuiltinTy->getSveEltType(S.getASTContext())
+: LHSType;
+
+  // Note that RHS might not be a vector
+  QualType RHSType = RHS.get()->getType();
+  const BuiltinType *RHSBuiltinTy = RHSType->getAs();
+  QualType RHSEleType = RHSType->isVLSTBuiltinType()
+? RHSBuiltinTy->getSveEltType(S.getASTContext())
+: RHSType;
+
+  if ((LHSBuiltinTy && LHSBuiltinTy->isSVEBool()) ||
+  (RHSBuiltinTy && RHSBuiltinTy->isSVEBool())) {
+S.Diag(Loc, diag::err_typecheck_invalid_operands)
+<< LHSType << RHSType << LHS.get()->getSourceRange();
+return QualType();
+  }
+
+  if (!LHSEleType->isIntegerType()) {
+S.Diag(Loc, diag::err_typecheck_expect_int)
+<< LHS.get()->getType() << LHS.get()->getSourceRange();
+return QualType();
+  }
+
+  if (!RHSEleType->isIntegerType()) {
+S.Diag(Loc, diag::err_typecheck_expect_int)
+<< RHS.get()->getType() << RHS.get()->getSourceRange();
+return QualType();
+  }
+
+  if (LHSType->isVLSTBuiltinType() && RHSType->isVLSTBuiltinType() &&
+  (S.Context.getBuiltinVectorTypeInfo(LHSBuiltinTy).EC !=
+   S.Context.getBuiltinVectorTypeInfo(RHSBuiltinTy).EC)) {
+S.Diag(Loc, diag::err_typecheck_invalid_operands)
+<< LHSType << RHSType << LHS.get()->getSourceRange()
+<< RHS.get()->getSourceRange();
+return QualType();
+  }
+
+  if (!LHSType->isVLSTBuiltinType()) {
+assert(RHSType->isVLSTBuiltinType());
+if (IsCompAssign)
+  return RHSType;
+if (LHSEleType != RHSEleType) {
+  LHS = S.ImpCastExprToType(LHS.get(), RHSEleType, clang::CK_IntegralCast);
+  LHSEleType = RHSEleType;
+}
+const llvm::ElementCount VecSize =
+S.Context.getBuiltinVectorTypeInfo(RHSBuiltinTy).EC;
+QualType VecTy =
+S.Context.getScalableVectorType(LHSEleType, 
VecSize.getKnownMinValue());
+LHS = S.ImpCastExprToType(LHS.get(), VecTy, clang::CK_VectorSplat);
+LHSType = VecTy;
+  } else if (RHSBuiltinTy && RHSBuiltinTy->isVLSTBuiltinType()) {
+if (S.Context.getTypeSize(RHSBuiltinTy) !=
+S.Context.getTypeSize(LHSBuiltinTy)) {
+  S.Diag(Loc, diag::err_typecheck_vector_lengths_not_equal)
+  << LHSType << RHSType << LHS.get()->getSourceRange()
+  << RHS.get()->getSourceRange();
+  return QualType();
+}
+  } else {
+const llvm::ElementCount VecSize =
+S.Context.getBuiltinVectorTypeInfo(LHSBuiltinTy).EC;
+if (LHSEleType != RHSEleType) {
+  RHS = S.ImpCastExprToType(RHS.get(), LHSEleType, clang::CK_IntegralCast);
+  RHSEleType = LHSEleType;
+}
+QualType VecTy =
+S.Context.getScalableVectorType(RHSEleType, 
VecSize.getKnownMinValue());
+RHS = S.ImpCastExprToType(RHS.get(), VecTy, CK_VectorSplat);
+  }
+
+  return LHSType;
+}
+
 // C99 6.5.7
 QualType Sema::CheckShiftOperands(ExprResult &LHS, ExprResult &RHS,
   SourceLocation Loc, BinaryOperatorKind Opc,
@@ -11501,7 +115

[PATCH] D123212: [clangd] Handle the new UsingTemplateName.

2022-04-14 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked an inline comment as done.
hokein added inline comments.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:446
   Outer.add(RD, Flags); // add(Decl) will despecialize if needed.
+else if (const auto *UTN =
+ TST->getTemplateName().getAsUsingTemplateName())

sammccall wrote:
> I don't think this really belongs in the else-if chain, if the previous catch 
> matches (known class specialization) then we still want to recognize the 
> alias.
> 
> I suspect this probably belongs right at the top, outside the chain
oh, you're right.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:76
   bool VisitTemplateSpecializationType(TemplateSpecializationType *TST) {
+if (const auto *UTN = TST->getTemplateName().getAsUsingTemplateName()) {
+  add(UTN->getFoundDecl());

sammccall wrote:
> TraverseTemplateSpecializationType calls TraverseTemplateName, isn't this 
> redundant with below?
yeah, the `add(..FoundDecl)` is redundant, but the key point here we do an 
early return, which means we will not traverse the underlying template decl if 
this template decl is found via the using decl.

I think this is a policy problem of whether we count the underlying decl as a 
reference for include-cleaner -- currently I just keep it consistent with the 
UsingType.




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:87
+  // to handle the UsingTemplateName case.
+  bool TraverseTemplateName(TemplateName TN) {
+if (const auto *UTN = TN.getAsUsingTemplateName())

kadircet wrote:
> what's the reason for not doing this in base method instead?
Traversing the underlying decl doesn't seem to follow the existing principle of 
RAV (e.g. the underlying TemplateDecl of TemplateName is not traversed 
neighter), the base method merely traverses written qualifiers of templateName 
if any. 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123212

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


[PATCH] D121984: [RISCV] Moving RVV intrinsic type related util to clang/Support

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D121984#3450956 , @kito-cheng 
wrote:

> Hi @aaron.ballman:
>
>> Why shouldn't this live in clang/utils/TableGen along with the others?
>
> We plan to use those stuffs on clang side in 
> https://reviews.llvm.org/D111617, my original change was put those stuffs on 
> `llvm/Support`, but actually those stuffs are only used for clang and 
> clang-tblgen, so that's why we try to create `clang/Support`.
>
> It's target specific but need to used in `clang` and `clang-tblgen` so target 
> specific stuffs should putting that in `llvm/lib/Target/RISCV` in theory, but 
> that made clang dependent on that.

Thank you for the explanation. I still don't think this is really "Support" 
material, but I'm also struggling to think of a better place to put it in an 
existing directory in Clang aside from Basic, but that would still be a bit of 
a layering violation it feels like. So I think I'm convinced that `Support` is 
a reasonable place to put it.

Should it live within a `RISCV` direction inside of the `Support` directory? Or 
should we use folders like that for host platform support files instead of 
target platform support files (as the LLVM `Support` directory appears to do)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121984

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


[clang] 52d346e - [PS4] NFC refactor of PS4 toolchain class, prep for PS5

2022-04-14 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-04-14T05:37:39-07:00
New Revision: 52d346e715cfaa08a71cdc8982627a3a598e47dd

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

LOG: [PS4] NFC refactor of PS4 toolchain class, prep for PS5

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/lib/Driver/ToolChains/PS4CPU.h

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 4756edd28a925..64af4c84672fe 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -539,8 +539,8 @@ def warn_drv_ps4_force_pic : Warning<
   "option '%0' was ignored by the PS4 toolchain, using '-fPIC'">,
   InGroup;
 
-def warn_drv_ps4_sdk_dir : Warning<
-  "environment variable SCE_ORBIS_SDK_DIR is set, but points to invalid or 
nonexistent directory '%0'">,
+def warn_drv_ps_sdk_dir : Warning<
+  "environment variable '%0' is set, but points to invalid or nonexistent 
directory '%1'">,
   InGroup;
 
 def err_drv_defsym_invalid_format : Error<"defsym must be of the form: 
sym=value: %0">;

diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.cpp 
b/clang/lib/Driver/ToolChains/PS4CPU.cpp
index 5aab0a6d1bf87..154eb78ce207c 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.cpp
+++ b/clang/lib/Driver/ToolChains/PS4CPU.cpp
@@ -8,7 +8,6 @@
 
 #include "PS4CPU.h"
 #include "CommonArgs.h"
-#include "FreeBSD.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
@@ -23,8 +22,18 @@ using namespace clang::driver;
 using namespace clang;
 using namespace llvm::opt;
 
+// Helper to paste bits of an option together and return a saved string.
+static const char *makeArgString(const ArgList &Args, const char *Prefix,
+ const char *Base, const char *Suffix) {
+  // Basically "Prefix + Base + Suffix" all converted to Twine then saved.
+  return Args.MakeArgString(Twine(StringRef(Prefix), Base) + Suffix);
+}
+
 void tools::PS4cpu::addProfileRTArgs(const ToolChain &TC, const ArgList &Args,
  ArgStringList &CmdArgs) {
+  assert(TC.getTriple().isPS());
+  auto &PSTC = static_cast(TC);
+
   if ((Args.hasFlag(options::OPT_fprofile_arcs, options::OPT_fno_profile_arcs,
 false) ||
Args.hasFlag(options::OPT_fprofile_generate,
@@ -41,7 +50,8 @@ void tools::PS4cpu::addProfileRTArgs(const ToolChain &TC, 
const ArgList &Args,
 options::OPT_fno_profile_generate, false) ||
Args.hasArg(options::OPT_fcreate_profile) ||
Args.hasArg(options::OPT_coverage)))
-CmdArgs.push_back("--dependent-lib=libclang_rt.profile-x86_64.a");
+CmdArgs.push_back(makeArgString(
+Args, "--dependent-lib=", PSTC.getProfileRTLibName(), ""));
 }
 
 void tools::PS4cpu::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
@@ -49,6 +59,7 @@ void tools::PS4cpu::Assemble::ConstructJob(Compilation &C, 
const JobAction &JA,
const InputInfoList &Inputs,
const ArgList &Args,
const char *LinkingOutput) const {
+  auto &TC = static_cast(getToolChain());
   claimNoWarnArgs(Args);
   ArgStringList CmdArgs;
 
@@ -62,31 +73,32 @@ void tools::PS4cpu::Assemble::ConstructJob(Compilation &C, 
const JobAction &JA,
   assert(Input.isFilename() && "Invalid input.");
   CmdArgs.push_back(Input.getFilename());
 
-  const char *Exec =
-  Args.MakeArgString(getToolChain().GetProgramPath("orbis-as"));
+  std::string AsName = TC.qualifyPSCmdName("as");
+  const char *Exec = Args.MakeArgString(TC.GetProgramPath(AsName.c_str()));
   C.addCommand(std::make_unique(JA, *this,
  ResponseFileSupport::AtFileUTF8(),
  Exec, CmdArgs, Inputs, Output));
 }
 
-static void AddPS4SanitizerArgs(const ToolChain &TC, const ArgList &Args,
-ArgStringList &CmdArgs) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
-  if (SanArgs.needsUbsanRt()) {
-CmdArgs.push_back("-lSceDbgUBSanitizer_stub_weak");
-  }
-  if (SanArgs.needsAsanRt()) {
-CmdArgs.push_back("-lSceDbgAddressSanitizer_stub_weak");
-  }
-}
-
 void tools::PS4cpu::addSanitizerArgs(const ToolChain &TC, const ArgList &Args,
  ArgStringList &CmdArgs) {
-  const SanitizerArgs &SanArgs = TC.getSanitizerArgs(Args);
+  assert(TC.getTriple().isPS());
+  auto &PSTC = static_cast(TC);
+  PSTC.addSanitizerArgs(Args, CmdArgs, "--dependent-lib=lib", ".a");
+

[PATCH] D123787: [clang][OpenMP][DebugInfo] Debug support for TLS variables when present in OpenMP consructs

2022-04-14 Thread Alok Kumar Sharma via Phabricator via cfe-commits
alok created this revision.
alok added reviewers: jmorse, aprantl, djtodoro, jini.susan.
alok added a project: debug-info.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
alok requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

In case of OpenMP programs, thread local variables can be present in any clause 
pertaining to
OpenMP constructs, as we know that compiler generates artificial functions and 
in some cases
values are passed to those artificial functions thru parameters.
 For an example, if thread local variable is present in copyin clause (testcase 
attached with the
patch), parameter with same name is generated as parameter to artificial 
function. When user
inquires the thread Local variable, its debug info is hidden by the parameter. 
The debug info
for parameters (for thread local) must be suppressed.

Without the patch, attached testcase behaves wrongly under debuggers.

  Thread 3 "a.out" hit Breakpoint 3, .omp_outlined._debug__ 
(.global_tid.=0x155547ffde20, .bound_tid.=0x155547ffde18, nt=@0x7fffe2b8: 
4, gbl_int=@0x155c: 65)
  at simple.c:29
  29  printf ("In parallel region total threads = %d, thread id 
= %d data=%d gbl_addr = %p\n", nt, tid, data, &gbl_int);
  (gdb) p tid
  $1 = 2
  (gdb) p &gbl_int
  $2 = (int *) 0x155c
  (gdb) c
  Continuing.
  [Switching to Thread 0x13ad2b80 (LWP 12279)]
  
  Thread 2 "a.out" hit Breakpoint 2, .omp_outlined._debug__ 
(.global_tid.=0x13ad1de0, .bound_tid.=0x13ad1dd8, nt=@0x7fffe2b8: 
4, gbl_int=@0x155c: 65)
  at simple.c:27
  27  printf ("In parallel region total threads = %d, thread id 
= %d data=%d gbl_addr = %p\n", nt, tid, data, &gbl_int);
  (gdb) p tid
  $3 = 1
  (gdb) p &gbl_int
  $4 = (int *) 0x155c

Please note that same address is shown for all the threads which is wrong (for 
thread local variable).

With the current patch, the issue is fixed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123787

Files:
  clang/include/clang/AST/Decl.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/debug_threadprivate_copyin.c

Index: clang/test/OpenMP/debug_threadprivate_copyin.c
===
--- /dev/null
+++ clang/test/OpenMP/debug_threadprivate_copyin.c
@@ -0,0 +1,59 @@
+// This testcase checks emission of debug info for threadprivate variables
+// present in any clause of OpenMP construct.
+
+// REQUIRES: x86_64-linux
+
+// RUN: %clang_cc1 -debug-info-kind=constructor -x c -verify -triple x86_64-pc-linux-gnu -fopenmp -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+
+// CHECK: define internal void @.omp_outlined._debug__(
+// CHECK: call void @llvm.dbg.declare(metadata i32** %.global_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata i32** %.bound_tid..addr,
+// CHECK: call void @llvm.dbg.declare(metadata i32** %nt.addr
+// CHECK: store i32* %gbl_dynamic_int, i32** %gbl_dynamic_int.addr, align 8
+// CHECK-NOT: call void @llvm.dbg.declare(metadata i32** %gbl_dynamic_int.addr
+// CHECK-NOT: call void @llvm.dbg.declare(metadata i32** %gbl_static_int.addr
+
+extern int printf(const char *, ...);
+extern void omp_set_num_threads(int);
+extern int omp_get_num_threads(void);
+extern int omp_get_thread_num(void);
+
+int gbl_dynamic_int;
+__thread int gbl_static_int;
+
+#pragma omp threadprivate(gbl_dynamic_int)
+
+int main() {
+  int nt = 0;
+  int offset = 10;
+  gbl_dynamic_int = 55;
+  gbl_static_int = 77;
+
+  omp_set_num_threads(4);
+#pragma omp parallel copyin(gbl_dynamic_int, gbl_static_int)
+  {
+int data;
+int tid;
+nt = omp_get_num_threads();
+tid = omp_get_thread_num();
+data = gbl_dynamic_int + gbl_static_int;
+gbl_dynamic_int += 10;
+gbl_static_int += 20;
+#pragma omp barrier
+if (tid == 0)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 1)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 2)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+if (tid == 3)
+  printf("In parallel region total threads = %d, thread id = %d data=%d gbl_dyn_addr = %p, gbl_static_addr = %p\n",
+ nt, tid, data, &gbl_dynamic_int, &gbl_static_int);
+  }
+
+  return 0;
+}
Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGS

[PATCH] D123403: [OpenMP] Refactor OMPScheduleType enum.

2022-04-14 Thread Peixin Qiao via Phabricator via cfe-commits
peixin added a comment.

A few comments. Mostly nits.




Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:3767
+  /*HasMonotonicModifier=*/false, /*HasNonmonotonicModifier=*/false,
+  /*HasOrdedClause=*/false);
   return;





Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:87
+  BaseAuto = 6,
+  BaseRuntime = 5,
+  BaseTrapezoidal = 7,

  BaseRuntime = 5,
  BaseAuto = 6,



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:135
+  UnorderedGuidedSimd = BaseGuidedSimd | ModifierUnordered,   // (46)
+  UnorderedRuntimeSimd = BaseRuntimeSimd | ModifierUnordered, // (47)
+

Why not using the following to be consistent with the name in kmp.h?
StaticBalancedChunked 
GuidedSimd
RuntimeSimd



Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:2114
+  DL, CLI, AllocaIP, /*NeedsBarrier=*/true, getSchedKind(SchedType),
+  ChunkVal, /*Simd*/ false,
+  (SchedType & omp::OMPScheduleType::ModifierMonotonic) ==

Nit



Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:2254
+  DL, CLI, AllocaIP, /*NeedsBarrier=*/true, OMP_SCHEDULE_Static, ChunkVal,
+  /*HasSimdModifier*/ false, /*HasMonotonicModifier*/ false,
+  /*HasNonmonotonicModifier*/ false,





Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:2255
+  /*HasSimdModifier*/ false, /*HasMonotonicModifier*/ false,
+  /*HasNonmonotonicModifier*/ false,
+  /*HasOrderedClause*/ true);





Comment at: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp:2256
+  /*HasNonmonotonicModifier*/ false,
+  /*HasOrderedClause*/ true);
 





Comment at: mlir/test/Target/LLVMIR/openmp-llvm.mlir:809
  for (%iv) : i64 = (%lb) to (%ub) step (%step) {
-  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 
%{{.*}}, i32 1073741894, i64 1, i64 %{{.*}}, i64 1, i64 1)
+  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 
%{{.*}},i32 70, i64 1, i64 %{{.*}}, i64 1, i64 1)
   // CHECK: call void @__kmpc_dispatch_fini_8u

Is this one tab?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123403

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


[PATCH] D123763: [randstruct] Enforce using a designated init for a randomized struct

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for this!

Because we're not checking anything about the randomized output or the AST 
nodes directly, this should be tested through the usual `lit` tests instead of 
using a unit test.




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11591-11596
+// Layout randomization diagnostics.
+def err_non_designated_init_used : Error<
+  "non-designated initializers cannot be used on a randomized struct">;
 def err_cast_from_randomized_struct : Error<
   "casting from randomized structure pointer type %0 to %1">;
+





Comment at: clang/unittests/AST/RandstructTest.cpp:484
+  EXPECT_EQ(Diags.getNumErrors(), 1u);
+}
+

Other things to test:
```
struct test t1 = {}; // This should be fine per WG14 N2900 (in C23) + our 
extension handling of it in earlier modes
struct test t2 = {0}; // This should also be fine per C99 6.7.8p19
struct test t3 = { .a = foo, bar, baz }; // Error

struct other_test {
  func_ptr a;
  func_ptr b[3];
  func_ptr c;
};

struct other_test t4 = { .a = foo, .b[0] = foo }; // Ok
struct other_test t5 = { .a = foo, .b[0] = foo, bar, baz }; // Ok
struct other_test t6 = { .a = foo, .b[0] = foo, bar, baz, gaz }; // Error
struct other_test t7 = { .a = foo, .b = { foo, bar, baz } }; // Ok
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123763

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


[PATCH] D123636: [randstruct] Add test for "-frandomize-layout-seed-file" flag

2022-04-14 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 but please wait a bit in case @MaskRay has comments.




Comment at: clang/unittests/AST/RandstructTest.cpp:72
+
+  return std::tuple(AST.release(), 
ASTFileSeed.release());
+};

void wrote:
> aaron.ballman wrote:
> > Why not keep these as unique pointers and move them into the tuple? Then 
> > the callers don't have to call delete manually.
> The d'tors for the `unique_ptr`s is called if I place them in the tuple. I 
> think it's because I can't do something like this:
> 
> ```
> const unique_ptr std::tie(AST, ASTFileSeed) = makeAST(...);
> ```
> 
> in the test functions. When I assign it as a non-initializer, it apparently 
> calls the d'tor. So, kinda stumped on what to do.
> 
> And the `EXPECT_FALSE` above is used because the `ASSERT_FALSE` adds an extra 
> return point, which messes with the lambda.
Okay, thank you for the explanations!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123636

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


Re: [clang] 26dbb93 - [Driver] Fix -fpascal-strings on Darwin

2022-04-14 Thread Aaron Ballman via cfe-commits
Should there be some test coverage for this change (or was this fixing
an already failing test)?

~Aaron

On Thu, Apr 14, 2022 at 2:01 AM Fangrui Song via cfe-commits
 wrote:
>
>
> Author: Fangrui Song
> Date: 2022-04-13T23:00:57-07:00
> New Revision: 26dbb93704bf39a198909d04ad8c49b4bde46cce
>
> URL: 
> https://github.com/llvm/llvm-project/commit/26dbb93704bf39a198909d04ad8c49b4bde46cce
> DIFF: 
> https://github.com/llvm/llvm-project/commit/26dbb93704bf39a198909d04ad8c49b4bde46cce.diff
>
> LOG: [Driver] Fix -fpascal-strings on Darwin
>
> Added:
>
>
> Modified:
> clang/lib/Driver/ToolChains/Darwin.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
> b/clang/lib/Driver/ToolChains/Darwin.cpp
> index 9f0eeea8d54e2..aaa4c6e5aabb8 100644
> --- a/clang/lib/Driver/ToolChains/Darwin.cpp
> +++ b/clang/lib/Driver/ToolChains/Darwin.cpp
> @@ -2554,11 +2554,11 @@ DerivedArgList *MachO::TranslateArgs(const 
> DerivedArgList &Args,
>break;
>
>  case options::OPT_fpascal_strings:
> -  DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings));
> +  DAL->AddFlagArg(A, Opts.getOption(options::OPT_fpascal_strings));
>break;
>
>  case options::OPT_fno_pascal_strings:
> -  DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings));
> +  DAL->AddFlagArg(A, Opts.getOption(options::OPT_fno_pascal_strings));
>break;
>  }
>}
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122008: [flang][driver] Add support for generating executables

2022-04-14 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

@h-vetinari & @rouson, thanks for the encouragement!

In D122008#3450214 , @h-vetinari 
wrote:

> I'd be more than a little surprised that there's no way to do this. Have you 
> tried CMAKE_Fortran_FLAGS 
> ? AFAICT, 
> the environment variables should be respected.

I completely forgot about `CMAKE_Fortran_FLAGS`! Indeed, it worked :) I really 
appreciate you doing all that digging and the suggestion itself! Yes, sounds 
like we can return to Option 2, which is fantastic news and great team effort!

I will post an updated version of this patch shortly. My suggestion for the new 
flag: `-flang-experimental-exec`. Hopefully not too long or to vague and 
informative enough. WDYT?

In D122008#3450346 , @rouson wrote:

> I don't know the time required to complete the remaining tasks, but the 
> following issues show 216 of 235 tasks completed with 2 in progress:

Thanks for that executive summary @rouson, it does look encouraging :) 
Unfortunately, upstreaming is effectively on hold ATM. People are not too keen 
to commit to any dates (understandable), but we (Arm) will continue working 
towards the LLVM 15 target (fingers crossed!).

**Summary**
AFAICT, Option 2 addresses all the issues raised here and (more importantly) 
unblocks a few new streams of development. IMO, it's a very good compromise and 
we should go ahead with it. I will leave this here for a few more days in case 
people have more comments.

Thank you,
-Andrzej


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122008

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


[PATCH] D122008: [flang][driver] Add support for generating executables

2022-04-14 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 422836.
awarzynski added a comment.

Add a flang, `-flang-experimental-exec`, to guard the new functionality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122008

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Gnu.cpp
  flang/include/flang/Runtime/stop.h
  flang/runtime/CMakeLists.txt
  flang/runtime/FortranMain/CMakeLists.txt
  flang/runtime/FortranMain/Fortran_main.c
  flang/test/CMakeLists.txt
  flang/test/Driver/linker-flags.f90

Index: flang/test/Driver/linker-flags.f90
===
--- /dev/null
+++ flang/test/Driver/linker-flags.f90
@@ -0,0 +1,30 @@
+! Verify that the Fortran runtime libraries are present in the linker
+! invocation. These libraries are added on top of other standard runtime
+! libraries that the Clang driver will include.
+
+! NOTE: The additional linker flags tested here are currently specified in
+! clang/lib/Driver/Toolchains/Gnu.cpp. This makes the current implementation GNU
+! (Linux) specific. The following line will make sure that this test is skipped
+! on Windows. Ideally we should find a more robust way of testing this.
+! REQUIRES: shell
+! UNSUPPORTED: darwin, macos
+
+!
+! RUN COMMAND
+!
+! RUN: %flang -### --ld-path=/usr/bin/ld %S/Inputs/hello.f90 2>&1 | FileCheck %s
+
+!
+! EXPECTED OUTPUT
+!
+! Compiler invocation to generate the object file
+! CHECK-LABEL: {{.*}} "-emit-obj"
+! CHECK-SAME:  "-o" "[[object_file:.*]]" {{.*}}Inputs/hello.f90
+
+! Linker invocation to generate the executable
+! CHECK-LABEL:  "/usr/bin/ld"
+! CHECK-SAME: "[[object_file]]"
+! CHECK-SAME: -lFortran_main
+! CHECK-SAME: -lFortranRuntime
+! CHECK-SAME: -lFortranDecimal
+! CHECK-SAME: -lm
Index: flang/test/CMakeLists.txt
===
--- flang/test/CMakeLists.txt
+++ flang/test/CMakeLists.txt
@@ -58,6 +58,9 @@
   llvm-dis
   llvm-objdump
   split-file
+  FortranRuntime
+  Fortran_main
+  FortranDecimal
 )
 
 if (FLANG_INCLUDE_TESTS)
Index: flang/runtime/FortranMain/Fortran_main.c
===
--- /dev/null
+++ flang/runtime/FortranMain/Fortran_main.c
@@ -0,0 +1,21 @@
+//===-- runtime/FortranMain/Fortran_main.c ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "flang/Runtime/main.h"
+#include "flang/Runtime/stop.h"
+
+/* main entry into PROGRAM */
+void _QQmain();
+
+/* C main stub */
+int main(int argc, const char *argv[], const char *envp[]) {
+  RTNAME(ProgramStart)(argc, argv, envp);
+  _QQmain();
+  RTNAME(ProgramEndStatement)();
+  return 0;
+}
Index: flang/runtime/FortranMain/CMakeLists.txt
===
--- /dev/null
+++ flang/runtime/FortranMain/CMakeLists.txt
@@ -0,0 +1,3 @@
+llvm_add_library(Fortran_main STATIC
+  Fortran_main.c
+)
Index: flang/runtime/CMakeLists.txt
===
--- flang/runtime/CMakeLists.txt
+++ flang/runtime/CMakeLists.txt
@@ -30,6 +30,8 @@
 # with different names
 include_directories(AFTER ${CMAKE_CURRENT_BINARY_DIR})
 
+add_subdirectory(FortranMain)
+
 add_flang_library(FortranRuntime
   ISO_Fortran_binding.cpp
   allocatable.cpp
Index: flang/include/flang/Runtime/stop.h
===
--- flang/include/flang/Runtime/stop.h
+++ flang/include/flang/Runtime/stop.h
@@ -27,7 +27,7 @@
 NORETURN void RTNAME(ProgramEndStatement)(NO_ARGUMENTS);
 
 // Extensions
-NORETURN void RTNAME(Exit)(int status = EXIT_SUCCESS);
+NORETURN void RTNAME(Exit)(int status DEFAULT_VALUE(EXIT_SUCCESS));
 NORETURN void RTNAME(Abort)(NO_ARGUMENTS);
 
 // Crash with an error message when the program dynamically violates a Fortran
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -382,6 +382,28 @@
  Exec, CmdArgs, Inputs, Output));
 }
 
+static void addFortranRuntimeLibraryPath(const ToolChain &TC,
+ const ArgList &Args,
+ ArgStringList &CmdArgs) {
+  // Default to the /../lib directory. This works fine on the
+  // platforms that we have tested so far. We will probably have to re-fine
+  // this in the future. In particular:
+  //* on some platforms, we may need to use lib64 instead of lib
+  //* this 

[PATCH] D123655: [clang-tidy] Add portability-std-allocator-const check

2022-04-14 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Reverted in a29d9ba1f584745c1a169da5d08f10b27623cfb0 
 for now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123655

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


[PATCH] D123167: [HLSL] Pointers are unsupported in HLSL

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:11579-11584
+def err_hlsl_pointers_unsupported : Error<"%select{pointers|references}0 are "
+  "unsupported in HLSL">;
+
+def err_hlsl_operator_unsupported : Error<"the %select{address of (&)|"
+   "dereference (*)|arrow (->)}0 "
+   "operator is unsupported in HLSL">;

Should we be adding `.*` and `->*` to the list of unsupported operators? (Hmmm, 
or can we never get to those operators because we can't form the base 
expression anyway?)



Comment at: clang/lib/Sema/SemaExpr.cpp:15252-15257
+  if (getLangOpts().HLSL) {
+if (Opc == UO_AddrOf)
+  return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 0);
+if (Opc == UO_Deref)
+  return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 1);
+  }

How should this interplay with overloaded operators on user-defined types? Is 
that case allowed so long as it doesn't form a pointer or a reference? (We 
should add test coverage for that.)



Comment at: clang/lib/Sema/SemaExprMember.cpp:1739-1740
 
+  if (getLangOpts().HLSL && IsArrow)
+return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 2);
+

Same question here for overloaded operators.



Comment at: clang/test/SemaHLSL/prohibit_reference.hlsl:4
+int& bark(int); // expected-error {{references are unsupported in HLSL}}
+void meow(int&); // expected-error {{references are unsupported in HLSL}}
+

void chirp(int &&); // error


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123167

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


[PATCH] D122008: [flang][driver] Add support for generating executables

2022-04-14 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 422841.
awarzynski added a comment.

Update the tests after the previous update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122008

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Gnu.cpp
  flang/include/flang/Runtime/stop.h
  flang/runtime/CMakeLists.txt
  flang/runtime/FortranMain/CMakeLists.txt
  flang/runtime/FortranMain/Fortran_main.c
  flang/test/CMakeLists.txt
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/linker-flags.f90

Index: flang/test/Driver/linker-flags.f90
===
--- /dev/null
+++ flang/test/Driver/linker-flags.f90
@@ -0,0 +1,30 @@
+! Verify that the Fortran runtime libraries are present in the linker
+! invocation. These libraries are added on top of other standard runtime
+! libraries that the Clang driver will include.
+
+! NOTE: The additional linker flags tested here are currently specified in
+! clang/lib/Driver/Toolchains/Gnu.cpp. This makes the current implementation GNU
+! (Linux) specific. The following line will make sure that this test is skipped
+! on Windows. Ideally we should find a more robust way of testing this.
+! REQUIRES: shell
+! UNSUPPORTED: darwin, macos
+
+!
+! RUN COMMAND
+!
+! RUN: %flang -### -flang-experimental-exec --ld-path=/usr/bin/ld %S/Inputs/hello.f90 2>&1 | FileCheck %s
+
+!
+! EXPECTED OUTPUT
+!
+! Compiler invocation to generate the object file
+! CHECK-LABEL: {{.*}} "-emit-obj"
+! CHECK-SAME:  "-o" "[[object_file:.*]]" {{.*}}Inputs/hello.f90
+
+! Linker invocation to generate the executable
+! CHECK-LABEL:  "/usr/bin/ld"
+! CHECK-SAME: "[[object_file]]"
+! CHECK-SAME: -lFortran_main
+! CHECK-SAME: -lFortranRuntime
+! CHECK-SAME: -lFortranDecimal
+! CHECK-SAME: -lm
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -38,6 +38,8 @@
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
 ! HELP-NEXT: -fintrinsic-modules-path 
 ! HELP-NEXT:Specify where to find the compiled intrinsic modules
+! HELP-NEXT: -flang-experimental-exec
+! HELP-NEXT:Enable support for generating executables (experimental)
 ! HELP-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -38,6 +38,8 @@
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
 ! CHECK-NEXT: -fintrinsic-modules-path 
 ! CHECK-NEXT:Specify where to find the compiled intrinsic modules
+! CHECK-NEXT: -flang-experimental-exec
+! CHECK-NEXT:Enable support for generating executables (experimental)
 ! CHECK-NEXT: -flarge-sizes  Use INTEGER(KIND=8) for the result type in size-related intrinsics
 ! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
 ! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
Index: flang/test/CMakeLists.txt
===
--- flang/test/CMakeLists.txt
+++ flang/test/CMakeLists.txt
@@ -58,6 +58,9 @@
   llvm-dis
   llvm-objdump
   split-file
+  FortranRuntime
+  Fortran_main
+  FortranDecimal
 )
 
 if (FLANG_INCLUDE_TESTS)
Index: flang/runtime/FortranMain/Fortran_main.c
===
--- /dev/null
+++ flang/runtime/FortranMain/Fortran_main.c
@@ -0,0 +1,21 @@
+//===-- runtime/FortranMain/Fortran_main.c ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "flang/Runtime/main.h"
+#include "flang/Runtime/stop.h"
+
+/* main entry into PROGRAM */
+void _QQmain();
+
+/* C main stub */
+int main(int argc, const char *argv[], const char *envp[]) {
+  RTNAME(ProgramStart)(argc, argv, envp);
+  _QQmain();
+  RTNAME(ProgramEndStatement)();
+  return 0;
+}
Index: flang/runtime/FortranMain/CMakeLists.txt
===
--- /

[PATCH] D123775: [AST] Support template declaration found through using-decl for QualifiedTemplateName.

2022-04-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/include/clang/AST/PropertiesBase.td:666
   }
-  def : Property<"declaration", TemplateDeclRef> {
+  def : Property<"templateDecl", TemplateDeclRef> {
 let Read = [{ qtn->getTemplateDecl() }];

this seems to be flattening the TemplateName into its possible attributes.

Is it possible to encode it as a single TemplateName property? are there 
particular advantages/disadvantages?



Comment at: clang/include/clang/AST/TemplateName.h:418
+  /// The underlying template name, it is either
+  //  1) a Template TemplateName -- a template declaration or set of overloaded
+  // function templates that this qualified name refers to.

I'm confused about the overloaded case: before this patch it was a single 
TemplateDecl. Have we actually added the possibility that UnderlyingTemplate is 
an Overload in this patch? Where?



Comment at: clang/include/clang/AST/TemplateName.h:418
+  /// The underlying template name, it is either
+  //  1) a Template TemplateName -- a template declaration or set of overloaded
+  // function templates that this qualified name refers to.

sammccall wrote:
> I'm confused about the overloaded case: before this patch it was a single 
> TemplateDecl. Have we actually added the possibility that UnderlyingTemplate 
> is an Overload in this patch? Where?
nit: "Template TemplateName" reads a little strangely or reminds of 
TemplateTemplateParm
I think "a Template" is clear in context. (and below)



Comment at: clang/include/clang/AST/TemplateName.h:426
+TemplateName Template)
+  : Qualifier(NNS, TemplateKeyword ? 1 : 0), UnderlyingTemplate(Template) 
{}
 

you've documented the invariant above, probably makes sense to assert it here



Comment at: clang/include/clang/AST/TemplateName.h:444
+  /// declaration, returns the using-shadow declaration.
+  UsingShadowDecl *getUsingShadowDecl() const {
+return UnderlyingTemplate.getAsUsingShadowDecl();

It seems all of the callers of this function ultimately just use it to 
reconstruct the underlying template name. This makes sense, because you mostly 
don't look at QualifiedTemplateName unless you're handling every TemplateName 
case, and normally handle it by recursion.

I think:
- we should definitely expose the underlying TemplateName and many callers 
should use that
- we should probably remove getUsingShadowDecl() unless there are enough 
callers that benefit from not getting it via TemplateName
- we should *consider* removing getTemplateDecl(), it makes for a simpler 
logical model (basically the top TemplateName::getTemplateName() decl does this 
smart unwrapping of sugar, but the specific representations like 
QualifiedTemplateName just expose their components). If it's too much of a pain 
for callers, we don't need to do this of course.



Comment at: clang/lib/AST/ASTContext.cpp:4854
   // Look through qualified template names.
-  if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
-Template = TemplateName(QTN->getTemplateDecl());
+  if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) {
+if (UsingShadowDecl *USD = QTN->getUsingShadowDecl())

This seems like an obvious example where we want:
```
if (QTN = ...)
  Template = QTN->getUnderlyingTemplate();
```



Comment at: clang/unittests/AST/TemplateNameTest.cpp:92
+namespace absl { using std::vector; }
+// absl::vector is a TemplateSpecializationType with an inner Using
+// TemplateName (not a Qualified TemplateName, the qualifiers are

absl::vector -> absl::vector

is a TemplateSpecializationType -> is an elaborated TemplateSpecializationType
(I think the TST itself just covers the vector part)



Comment at: clang/unittests/AST/TemplateNameTest.cpp:93
+// absl::vector is a TemplateSpecializationType with an inner Using
+// TemplateName (not a Qualified TemplateName, the qualifiers are
+// stripped when constructing the TemplateSpecializationType)!

the qualifiers are rather part of the ElaboratedTypeLoc



Comment at: clang/unittests/AST/TemplateNameTest.cpp:97
+  )cpp");
+  auto Matcher = typeLoc(loc(templateSpecializationType().bind("id")));
+  auto MatchResults = match(Matcher, AST->getASTContext());

Describe more of the structure?

elaboratedTypeLoc(hasNamedTypeLoc(loc(templateSpecializationType(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123775

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


[PATCH] D123682: [clang-tblgen] Automatically document options values

2022-04-14 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.

In D123682#3450215 , @MaskRay wrote:

> Thank you for improving the tool :)
>
>   cd clang
>   path/to/clang-tblgen --gen-opt-docs -I ../llvm/include -I 
> include/clang/Driver include/clang/Driver/ClangOptionDocs.td > /tmp/0
>   nvim -d docs/ClangCommandLineReference.rst /tmp/0
>
> Hope a native speaker (@aaron.ballman @dexonsmith @jhenderson ) can suggest 
> the usage here.
>
> For an option with more than 2 choices: the current documentation is ` 
> can be one of 'return', 'branch', 'full' or 'none'`,
> I'm thinking of: ` should be 'return', 'branch', 'full', or 'none'`
>
> When there are two choices (`-gsplit-dwarf=`), currently the 
> documentation is ` can be one of 'split' or 'single'.`
> I am thinking of ` should be 'split' or 'single'`.

Both of these suggestions seem reasonable to me (shorter but equally as clear 
as before), but we should fix to be consistent in 
`llvm/utils/TableGen/OptRSTEmitter.cpp` if we opt to go this route.

The changes here LGTM as-is (I'm happy with either current wording or the 
changed wording). Thanks for this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123682

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


[clang-tools-extra] dd47ab7 - Revert "[clang-tidy] Add portability-std-allocator-const check"

2022-04-14 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-04-14T09:20:51-04:00
New Revision: dd47ab750b584a320bf61d58a3965a03f3871c1b

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

LOG: Revert "[clang-tidy] Add portability-std-allocator-const check"

This reverts commit 73da7eed8fac84c9005518740f12d58389998d95.
Breaks check-clang-tools on Windows, see comment on
https://reviews.llvm.org/D123655

Added: 


Modified: 
clang-tools-extra/clang-tidy/portability/CMakeLists.txt
clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 
clang-tools-extra/clang-tidy/portability/StdAllocatorConstCheck.cpp
clang-tools-extra/clang-tidy/portability/StdAllocatorConstCheck.h
clang-tools-extra/docs/clang-tidy/checks/portability-std-allocator-const.rst

clang-tools-extra/test/clang-tidy/checkers/portability-std-allocator-const.cpp



diff  --git a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt
index 579e459bc72bc..a0de5871e036a 100644
--- a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt
@@ -7,7 +7,6 @@ add_clang_library(clangTidyPortabilityModule
   PortabilityTidyModule.cpp
   RestrictSystemIncludesCheck.cpp
   SIMDIntrinsicsCheck.cpp
-  StdAllocatorConstCheck.cpp
 
   LINK_LIBS
   clangTidy

diff  --git 
a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp
index 1e4f1d5de1d97..c87a119aa81fc 100644
--- a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp
@@ -11,7 +11,6 @@
 #include "../ClangTidyModuleRegistry.h"
 #include "RestrictSystemIncludesCheck.h"
 #include "SIMDIntrinsicsCheck.h"
-#include "StdAllocatorConstCheck.h"
 
 namespace clang {
 namespace tidy {
@@ -24,8 +23,6 @@ class PortabilityModule : public ClangTidyModule {
 "portability-restrict-system-includes");
 CheckFactories.registerCheck(
 "portability-simd-intrinsics");
-CheckFactories.registerCheck(
-"portability-std-allocator-const");
   }
 };
 

diff  --git 
a/clang-tools-extra/clang-tidy/portability/StdAllocatorConstCheck.cpp 
b/clang-tools-extra/clang-tidy/portability/StdAllocatorConstCheck.cpp
deleted file mode 100644
index a95048d71ef92..0
--- a/clang-tools-extra/clang-tidy/portability/StdAllocatorConstCheck.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-//===-- StdAllocatorConstCheck.cpp - clang-tidy --===//
-//
-// 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 "StdAllocatorConstCheck.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-
-using namespace clang::ast_matchers;
-
-namespace clang {
-namespace tidy {
-namespace portability {
-
-void StdAllocatorConstCheck::registerMatchers(MatchFinder *Finder) {
-  // Match std::allocator.
-  auto allocatorConst =
-  recordType(hasDeclaration(classTemplateSpecializationDecl(
-  hasName("::std::allocator"),
-  hasTemplateArgument(0, 
refersToType(qualType(isConstQualified()));
-
-  auto hasContainerName =
-  hasAnyName("::std::vector", "::std::deque", "::std::list",
- "::std::multiset", "::std::set", "::std::unordered_multiset",
- "::std::unordered_set", "::absl::flat_hash_set");
-
-  // Match `std::vector var;` and other common containers like deque,
-  // list, and absl::flat_hash_set. Containers like queue and stack use deque
-  // but do not directly use std::allocator as a template argument, so they
-  // aren't caught.
-  Finder->addMatcher(
-  typeLoc(
-  templateSpecializationTypeLoc(),
-  loc(hasUnqualifiedDesugaredType(anyOf(
-  recordType(hasDeclaration(classTemplateSpecializationDecl(
-  hasContainerName,
-  anyOf(
-  hasTemplateArgument(1, refersToType(allocatorConst)),
-  hasTemplateArgument(2, refersToType(allocatorConst)),
-  hasTemplateArgument(3, refersToType(allocatorConst)),
-  // Match std::vector
-  templateSpecializationType(
-  templateArgumentCountIs(1),
-  hasTemplateArgument(
-  0, refersToType(qualType(isConstQualified(,
-  hasDeclaration(namedDecl(hasCont

[PATCH] D123655: [clang-tidy] Add portability-std-allocator-const check

2022-04-14 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Err, actually in dd47ab750b584a320bf61d58a3965a03f3871c1b


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123655

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


[PATCH] D115620: [AArch64] Lowering and legalization of strict FP16

2022-04-14 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

OK Thanks. This LGTM then.


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

https://reviews.llvm.org/D115620

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


[PATCH] D123655: [clang-tidy] Add portability-std-allocator-const check

2022-04-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Thanks Nico!

@MaskRay my guess is this is related to implicit -fdelayed-template-parsing on 
windows, which causes non-instantiated templates not really to be parsed.
If that's the case, best just to add -fno-delayed-template-parsing to the test 
and accept that these cases will be missed on windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123655

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


[PATCH] D123212: [clangd] Handle the new UsingTemplateName.

2022-04-14 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:76
   bool VisitTemplateSpecializationType(TemplateSpecializationType *TST) {
+if (const auto *UTN = TST->getTemplateName().getAsUsingTemplateName()) {
+  add(UTN->getFoundDecl());

hokein wrote:
> sammccall wrote:
> > TraverseTemplateSpecializationType calls TraverseTemplateName, isn't this 
> > redundant with below?
> yeah, the `add(..FoundDecl)` is redundant, but the key point here we do an 
> early return, which means we will not traverse the underlying template decl 
> if this template decl is found via the using decl.
> 
> I think this is a policy problem of whether we count the underlying decl as a 
> reference for include-cleaner -- currently I just keep it consistent with the 
> UsingType.
> 
Makes sense.

But if we're creating a pseudo-`VisitTemplateName` by overriding its traverse 
function, can we move the `add(getTemplateName() .getAsTemplateDecl())` logic 
there too?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123212

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


[PATCH] D122766: [clang] Use forward slash as the path separator for Windows in __FILE__, __builtin_FILE(), and std::source_location

2022-04-14 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D122766#3450298 , @ayzhao wrote:

> So, the general consensus seems to be that we should use backslashes when 
> targeting Windows.
>
> I implemented using only backslashes for Windows; however, 
> clang/test/SemaCXX/destructor.cpp 
> 
>  fails when running on Linux with the following error (among other errors, 
> but the one below is the most important).
>
>   ...
>   error: 'error' diagnostics seen but not expected:
> Line 32: 
> '\\clang\\test\\SemaCXX\\destructor.cpp'
>  file not found
>   ...
>
> The reason for this is that the test has Clang target windows 
> 
>  and the test also has the statement #include __FILE__ 
> .

That seems like an unusual use case of `__FILE__`. I wonder if we could just 
change the test to `#include "destructor.cpp"` instead and not worry about the 
case of `#include __FILE__` in cross-builds targeting Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122766

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


[PATCH] D123167: [HLSL] Pointers are unsupported in HLSL

2022-04-14 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

One comment inline. Update coming in a few minutes.




Comment at: clang/lib/Sema/SemaExpr.cpp:15252-15257
+  if (getLangOpts().HLSL) {
+if (Opc == UO_AddrOf)
+  return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 0);
+if (Opc == UO_Deref)
+  return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 1);
+  }

aaron.ballman wrote:
> How should this interplay with overloaded operators on user-defined types? Is 
> that case allowed so long as it doesn't form a pointer or a reference? (We 
> should add test coverage for that.)
So, the "correct" end goal is that we don't support overloading those 
operators. We have a few limitations on which operators we allow overloading 
for, generally any operators that in normal use return references or pointers, 
we don't allow you to overload.

That said, I wrote some test code to see where this falls over with my current 
change:

```
struct Fish {
  struct Fins {
int Left;
int Right;
  };
  int X;
  int operator *() {
return X;
  }

  Fins operator ->() {
return Fins();
  }
};

int gone_fishing() {
  Fish F;
  int Result = *F;   // works... and is consistent with DXC
  Result += F->Left; // error: member reference type 'Fish::Fins' is not a 
pointer
  return Result;
}
```

In the existing compiler we produce an error on definition of operators that 
aren't supported. I'd like to handle improving the diagnostics for those 
operators that way in a later patch if that is okay.

The `.*` and `.->` operators I couldn't get errors to actually trigger because 
I couldn't think of a way to write them that wasn't dependent on getting a 
member pointer, which errors and causes the remaining expression to not be 
checked.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123167

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


[PATCH] D123403: [OpenMP] Refactor OMPScheduleType enum.

2022-04-14 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur marked 7 inline comments as done.
Meinersbur added inline comments.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPConstants.h:135
+  UnorderedGuidedSimd = BaseGuidedSimd | ModifierUnordered,   // (46)
+  UnorderedRuntimeSimd = BaseRuntimeSimd | ModifierUnordered, // (47)
+

peixin wrote:
> Why not using the following to be consistent with the name in kmp.h?
> StaticBalancedChunked 
> GuidedSimd
> RuntimeSimd
As mentioned in the summary. to avoid confusion by not using the original name. 
`StaticBalancedChunked` could mean either the algorithm to use (now 
`BaseStaticBalancedChunked`, as in `omp_sched_t`/`enum kmp_sched`), or that 
algorithm with the unordered flag set (now `UnorderedStaticBalancedChunked `). 
I would the former because that's how the enum is structured.

The name in `kmp.h` for it is actually `kmp_sch_static_balanced_chunked`. `sch` 
for "unordered"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123403

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


[PATCH] D123167: [HLSL] Pointers are unsupported in HLSL

2022-04-14 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 422860.
beanz added a comment.

Updates to test cases to increase coverage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123167

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprMember.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaHLSL/prohibit_pointer.hlsl
  clang/test/SemaHLSL/prohibit_reference.hlsl

Index: clang/test/SemaHLSL/prohibit_reference.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/prohibit_reference.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -o - -fsyntax-only %s -verify
+
+int& bark(int); // expected-error {{references are unsupported in HLSL}}
+void meow(int&); // expected-error {{references are unsupported in HLSL}}
+void chirp(int &&); // expected-error {{references are unsupported in HLSL}}
+// expected-warning@-1 {{rvalue references are a C++11 extension}}
+
+struct Foo {
+  int X;
+  int Y;
+};
+
+int entry() {
+  int X;
+  int &Y = X; // expected-error {{references are unsupported in HLSL}}
+}
+
+int roar(Foo &F) { // expected-error {{references are unsupported in HLSL}}
+  return F.X;
+}
Index: clang/test/SemaHLSL/prohibit_pointer.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/prohibit_pointer.hlsl
@@ -0,0 +1,80 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -o - -fsyntax-only %s -verify
+
+// expected-error@+1 {{pointers are unsupported in HLSL}}
+typedef int (*fn_int)(int);
+void* bark(int); // expected-error {{pointers are unsupported in HLSL}}
+void meow(int*); // expected-error {{pointers are unsupported in HLSL}}
+
+struct Foo {
+  int X;
+  int Y;
+} *bad; // expected-error {{pointers are unsupported in HLSL}}
+
+// expected-error@+1 {{pointers are unsupported in HLSL}}
+void woof(int Foo::*Member);
+
+int entry() {
+  int X;
+  Foo F;
+  
+  // expected-error@+2 {{the address of (&) operator is unsupported in HLSL}}
+  // expected-error@+1 {{pointers are unsupported in HLSL}}
+  int Foo::*Member = &F.X;
+  
+  // expected-error@+1 {{the address of (&) operator is unsupported in HLSL}}
+  int *Y = &X; // expected-error {{pointers are unsupported in HLSL}}
+  
+  // expected-error@+2 {{the arrow (->) operator is unsupported in HLSL}}
+  // expected-error@+1 {{the address of (&) operator is unsupported in HLSL}}
+  int W = (&F)->X;
+
+  int Array[2];
+  // expected-error@+1 {{the address of (&) operator is unsupported in HLSL}}
+  *(&Array[0] + 1) = 12;
+  // expected-error@+1 {{the dereference (*) operator is unsupported in HLSL}}
+  *Array = 12;
+}
+
+int roar(Foo *F) { // expected-error {{pointers are unsupported in HLSL}}
+  // expected-error@+1 {{the arrow (->) operator is unsupported in HLSL}}
+  return F->X;
+}
+
+template 
+void devilish_language(T look_ma_no_pointers);
+
+void make_me_cry() {
+  int X;
+  // expected-error@+1 {{the address of (&) operator is unsupported in HLSL}}
+  devilish_language(&X);
+
+  // not-expected-error@+1 {{pointers are unsupported in HLSL}}
+  devilish_language(roar); // allow function pointer decay
+
+  // not-expected-error@+1 {{pointers are unsupported in HLSL}}
+  devilish_language("roar"); // allow array pointer decay
+}
+
+struct Fish {
+  struct Fins {
+int Left;
+int Right;
+  };
+  int X;
+  int operator *() {
+return X;
+  }
+
+  // expected-note@+1 {{'->' applied to return value of the operator->() declared here}}
+  Fins operator ->() {
+return Fins();
+  }
+};
+
+int gone_fishing() {
+  Fish F;
+  int Result = *F; // user-defined dereference operators work
+  // expected-error@+1 {{member reference type 'Fish::Fins' is not a pointer}}
+  Result += F->Left;
+  return Result;
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2143,6 +2143,11 @@
 return QualType();
   }
 
+  if (getLangOpts().HLSL) {
+Diag(Loc, diag::err_hlsl_pointers_unsupported) << 0;
+return QualType();
+  }
+
   if (checkQualifiedFunction(*this, T, Loc, QFK_Pointer))
 return QualType();
 
@@ -2208,6 +2213,11 @@
 return QualType();
   }
 
+  if (getLangOpts().HLSL) {
+Diag(Loc, diag::err_hlsl_pointers_unsupported) << 1;
+return QualType();
+  }
+
   if (checkQualifiedFunction(*this, T, Loc, QFK_Reference))
 return QualType();
 
@@ -2967,6 +2977,11 @@
 return QualType();
   }
 
+  if (getLangOpts().HLSL) {
+Diag(Loc, diag::err_hlsl_pointers_unsupported) << 0;
+return QualType();
+  }
+
   // Adjust the default free function calling convention to the default method
   // calling convention.
   bool IsCtorOrDtor =
Index: clang/lib/Sema/SemaExprMember.cpp
==

[PATCH] D123403: [OpenMP] Refactor OMPScheduleType enum.

2022-04-14 Thread Michael Kruse via Phabricator via cfe-commits
Meinersbur updated this revision to Diff 422862.
Meinersbur added a comment.

- address review


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123403

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/irbuilder_for_unsigned_auto.c
  clang/test/OpenMP/irbuilder_for_unsigned_dynamic.c
  clang/test/OpenMP/irbuilder_for_unsigned_dynamic_chunked.c
  clang/test/OpenMP/irbuilder_for_unsigned_runtime.c
  llvm/include/llvm/Frontend/OpenMP/OMPConstants.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/test/Target/LLVMIR/openmp-llvm.mlir

Index: mlir/test/Target/LLVMIR/openmp-llvm.mlir
===
--- mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -657,7 +657,7 @@
 llvm.func @test_omp_wsloop_runtime_simd(%lb : i64, %ub : i64, %step : i64) -> () {
   omp.wsloop schedule(runtime, simd)
   for (%iv) : i64 = (%lb) to (%ub) step (%step) {
-// CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 47
+// CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 1073741871
 // CHECK: %[[continue:.*]] = call i32 @__kmpc_dispatch_next_8u
 // CHECK: %[[cond:.*]] = icmp ne i32 %[[continue]], 0
 // CHECK  br i1 %[[cond]], label %omp_loop.header{{.*}}, label %omp_loop.exit{{.*}}
@@ -674,7 +674,7 @@
 llvm.func @test_omp_wsloop_guided_simd(%lb : i64, %ub : i64, %step : i64) -> () {
   omp.wsloop schedule(guided, simd)
   for (%iv) : i64 = (%lb) to (%ub) step (%step) {
-// CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 46
+// CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 1073741870
 // CHECK: %[[continue:.*]] = call i32 @__kmpc_dispatch_next_8u
 // CHECK: %[[cond:.*]] = icmp ne i32 %[[continue]], 0
 // CHECK  br i1 %[[cond]], label %omp_loop.header{{.*}}, label %omp_loop.exit{{.*}}
@@ -788,7 +788,7 @@
 llvm.func @test_omp_wsloop_dynamic_ordered(%lb : i64, %ub : i64, %step : i64) -> () {
  omp.wsloop schedule(dynamic) ordered(0)
  for (%iv) : i64 = (%lb) to (%ub) step (%step) {
-  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 1073741891, i64 1, i64 %{{.*}}, i64 1, i64 1)
+  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 67, i64 1, i64 %{{.*}}, i64 1, i64 1)
   // CHECK: call void @__kmpc_dispatch_fini_8u
   // CHECK: %[[continue:.*]] = call i32 @__kmpc_dispatch_next_8u
   // CHECK: %[[cond:.*]] = icmp ne i32 %[[continue]], 0
@@ -806,7 +806,7 @@
 llvm.func @test_omp_wsloop_auto_ordered(%lb : i64, %ub : i64, %step : i64) -> () {
  omp.wsloop schedule(auto) ordered(0)
  for (%iv) : i64 = (%lb) to (%ub) step (%step) {
-  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 1073741894, i64 1, i64 %{{.*}}, i64 1, i64 1)
+  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 70, i64 1, i64 %{{.*}}, i64 1, i64 1)
   // CHECK: call void @__kmpc_dispatch_fini_8u
   // CHECK: %[[continue:.*]] = call i32 @__kmpc_dispatch_next_8u
   // CHECK: %[[cond:.*]] = icmp ne i32 %[[continue]], 0
@@ -824,7 +824,7 @@
 llvm.func @test_omp_wsloop_runtime_ordered(%lb : i64, %ub : i64, %step : i64) -> () {
  omp.wsloop schedule(runtime) ordered(0)
  for (%iv) : i64 = (%lb) to (%ub) step (%step) {
-  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 1073741893, i64 1, i64 %{{.*}}, i64 1, i64 1)
+  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 69, i64 1, i64 %{{.*}}, i64 1, i64 1)
   // CHECK: call void @__kmpc_dispatch_fini_8u
   // CHECK: %[[continue:.*]] = call i32 @__kmpc_dispatch_next_8u
   // CHECK: %[[cond:.*]] = icmp ne i32 %[[continue]], 0
@@ -842,7 +842,7 @@
 llvm.func @test_omp_wsloop_guided_ordered(%lb : i64, %ub : i64, %step : i64) -> () {
  omp.wsloop schedule(guided) ordered(0)
  for (%iv) : i64 = (%lb) to (%ub) step (%step) {
-  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 1073741892, i64 1, i64 %{{.*}}, i64 1, i64 1)
+  // CHECK: call void @__kmpc_dispatch_init_8u(%struct.ident_t* @{{.*}}, i32 %{{.*}}, i32 68, i64 1, i64 %{{.*}}, i64 1, i64 1)
   // CHECK: call void @__kmpc_dispatch_fini_8u
   // CHECK: %[[continue:.*]] = call i32 @__kmpc_dispatch_next_8u
   // CHECK: %[[cond:.*]] = icmp ne i32 %[[continue]], 0
Index: mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPTo

[PATCH] D123456: [C89/C2x] Diagnose calls to a function without a prototype but passes arguments

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

FYI -- I plan to land this tomorrow unless I hear more feedback from reviewers 
(but as always, I'll happily take post-commit feedback as well).


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

https://reviews.llvm.org/D123456

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


[PATCH] D122069: [Object] Add binary format for bundling offloading metadata

2022-04-14 Thread Joseph Huber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe471ba3d0122: [Object] Add binary format for bundling 
offloading metadata (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122069

Files:
  llvm/include/llvm/Object/OffloadBinary.h
  llvm/lib/Object/CMakeLists.txt
  llvm/lib/Object/OffloadBinary.cpp
  llvm/unittests/Object/CMakeLists.txt
  llvm/unittests/Object/OffloadingTest.cpp

Index: llvm/unittests/Object/OffloadingTest.cpp
===
--- /dev/null
+++ llvm/unittests/Object/OffloadingTest.cpp
@@ -0,0 +1,65 @@
+#include "llvm/Object/OffloadBinary.h"
+
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+#include 
+
+TEST(OffloadingTest, checkOffloadingBinary) {
+  // Create random data to fill the image.
+  std::mt19937 Rng(std::random_device{}());
+  std::uniform_int_distribution SizeDist(0, 256);
+  std::uniform_int_distribution KindDist(0);
+  std::uniform_int_distribution BinaryDist(
+  std::numeric_limits::min(), std::numeric_limits::max());
+  std::uniform_int_distribution StringDist('!', '~');
+  std::vector Image(SizeDist(Rng));
+  std::generate(Image.begin(), Image.end(), [&]() { return BinaryDist(Rng); });
+  std::vector> Strings(SizeDist(Rng));
+  for (auto &KeyAndValue : Strings) {
+std::string Key(SizeDist(Rng), '\0');
+std::string Value(SizeDist(Rng), '\0');
+
+std::generate(Key.begin(), Key.end(), [&]() { return StringDist(Rng); });
+std::generate(Value.begin(), Value.end(),
+  [&]() { return StringDist(Rng); });
+
+KeyAndValue = std::make_pair(Key, Value);
+  }
+
+  // Create the image.
+  llvm::StringMap StringData;
+  for (auto &KeyAndValue : Strings)
+StringData[KeyAndValue.first] = KeyAndValue.second;
+  std::unique_ptr ImageData =
+  llvm::MemoryBuffer::getMemBuffer(
+  {reinterpret_cast(Image.data()), Image.size()}, "", false);
+
+  llvm::OffloadBinary::OffloadingImage Data;
+  Data.TheImageKind = static_cast(KindDist(Rng));
+  Data.TheOffloadKind = static_cast(KindDist(Rng));
+  Data.Flags = KindDist(Rng);
+  Data.StringData = StringData;
+  Data.Image = *ImageData;
+
+  auto BinaryBuffer = llvm::OffloadBinary::write(Data);
+
+  auto BinaryOrErr = llvm::OffloadBinary::create(*BinaryBuffer);
+  if (!BinaryOrErr)
+FAIL();
+
+  // Make sure we get the same data out.
+  auto &Binary = **BinaryOrErr;
+  ASSERT_EQ(Data.TheImageKind, Binary.getImageKind());
+  ASSERT_EQ(Data.TheOffloadKind, Binary.getOffloadKind());
+  ASSERT_EQ(Data.Flags, Binary.getFlags());
+
+  for (auto &KeyAndValue : Strings)
+ASSERT_TRUE(StringData[KeyAndValue.first] ==
+Binary.getString(KeyAndValue.first));
+
+  EXPECT_TRUE(Data.Image.getBuffer() == Binary.getImage());
+
+  // Ensure the size and alignment of the data is correct.
+  EXPECT_TRUE(Binary.getSize() % llvm::OffloadBinary::getAlignment() == 0);
+  EXPECT_TRUE(Binary.getSize() == BinaryBuffer->getBuffer().size());
+}
Index: llvm/unittests/Object/CMakeLists.txt
===
--- llvm/unittests/Object/CMakeLists.txt
+++ llvm/unittests/Object/CMakeLists.txt
@@ -11,6 +11,7 @@
   ELFTest.cpp
   MinidumpTest.cpp
   ObjectFileTest.cpp
+  OffloadingTest.cpp
   SymbolSizeTest.cpp
   SymbolicFileTest.cpp
   XCOFFObjectFileTest.cpp
Index: llvm/lib/Object/OffloadBinary.cpp
===
--- /dev/null
+++ llvm/lib/Object/OffloadBinary.cpp
@@ -0,0 +1,144 @@
+//===- Offloading.cpp - Utilities for handling offloading code  -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/Object/OffloadBinary.h"
+
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/MC/StringTableBuilder.h"
+#include "llvm/Object/Error.h"
+#include "llvm/Support/FileOutputBuffer.h"
+
+using namespace llvm;
+
+namespace llvm {
+
+Expected>
+OffloadBinary::create(MemoryBufferRef Buf) {
+  if (Buf.getBufferSize() < sizeof(Header) + sizeof(Entry))
+return errorCodeToError(llvm::object::object_error::parse_failed);
+
+  // Check for 0x10FF1OAD magic bytes.
+  if (!Buf.getBuffer().startswith("\x10\xFF\x10\xAD"))
+return errorCodeToError(llvm::object::object_error::parse_failed);
+
+  const char *Start = Buf.getBufferStart();
+  const Header *TheHeader = reinterpret_cast(Start);
+  const Entry *TheEntry =
+  reinterpret_cast(&Start[TheHeader->EntryOffset]);
+
+  return std::unique_ptr(
+  new OffloadBinary(Buf.getBufferStart(), TheHeader, TheEntry));
+}
+
+std::un

[PATCH] D122983: [C11/C2x] Change the behavior of the implicit function declaration warning

2022-04-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

FWIW, Aaron and I discussed this at length while he was preparing this patch.  
I think the current behavior (warn in C99, warn-as-error in C11/C17, hard error 
in C20) is about as aggressive as I'd want us to be with erroring without 
causing extensive heartache on our users. WG14 did us no favors here in 1999, 
and our delay on making this an error for 20 years since then has created an 
environment where I wish for us to be somewhat understanding of our users.  If 
you'd asked me in 1998 of course my answer would have been different.

I think Aaron's approach provides a proper 'depreciation' period in our 
compiler, as best as we have the ability to do.  I consider MOST projects who 
use C99 to be 'legacy' code bases with little maintenance, so introducing new 
errors to them would be unfortunate (even default-W-as-E). I see value to still 
warning in the C99 case, as it _IS_ a good improvement for anyone going through 
the source code trying to do small improvements, but a default-W-as-E causes 
greater overhead in that case.

Comparatively, I see projects using C11/C17 to be 'modern' or 'maintained' code 
bases, so the disable-able error seems to me to be a proper 'kick' to let them 
know this is something they need to change ASAP.  I would be VERY against this 
being 'just a warning' though, as they are more simply/commonly ignored, and 
makes the hard-error in C20 that much more jarring.

While I agree this is quite a odd of a transition, I see it as the most-gentle 
we can be for our users.  Anything 'more aggressive' in the C99/C11/C17 case 
would be an unfortunate burden, and anything 'less aggressive' would make the 
C20 change a further jarring/unfortunate burden.


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

https://reviews.llvm.org/D122983

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


[clang] 1fdf952 - [HLSL] Add Semantic syntax, and SV_GroupIndex

2022-04-14 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-04-14T10:21:58-05:00
New Revision: 1fdf952deeb9a02aa34794af3c1a7d13a30e068e

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

LOG: [HLSL] Add Semantic syntax, and SV_GroupIndex

HLSL has a language feature called Semantics which get attached to
declarations like attributes and are used in a variety of ways.

One example of semantic use is here with the `SV_GroupIndex` semantic
which, when applied to an input for a compute shader is pre-populated
by the driver with a flattened thread index.

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

# Conflicts:
#   clang/include/clang/Basic/Attr.td
#   clang/include/clang/Basic/AttrDocs.td

Added: 
clang/lib/Parse/ParseHLSL.cpp
clang/test/ParserHLSL/lit.local.cfg
clang/test/ParserHLSL/semantic_parsing.hlsl
clang/test/SemaHLSL/Semantics/entry_parameter.hlsl

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/AttributeCommonInfo.h
clang/include/clang/Basic/Attributes.h
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/Parser.h
clang/lib/Parse/CMakeLists.txt
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dee9ede951745..727e6180b41b2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -300,6 +300,9 @@ class Clang : Spelling {
   bit AllowInC = allowInC;
 }
 
+// HLSL Semantic spellings
+class HLSLSemantic : Spelling;
+
 class Accessor spellings> {
   string Name = name;
   list Spellings = spellings;
@@ -3958,6 +3961,13 @@ def HLSLNumThreads: InheritableAttr {
   let Documentation = [NumThreadsDocs];
 }
 
+def HLSLSV_GroupIndex: InheritableAttr {
+  let Spellings = [HLSLSemantic<"SV_GroupIndex">];
+  let Subjects = SubjectList<[ParmVar, GlobalVar]>;
+  let LangOpts = [HLSL];
+  let Documentation = [HLSLSV_GroupIndexDocs];
+}
+
 def RandomizeLayout : InheritableAttr {
   let Spellings = [GCC<"randomize_layout">];
   let Subjects = SubjectList<[Record]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 6a8b2e600f949..cda143eeb1ca1 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -6411,3 +6411,14 @@ instructs the compiler that this structure should not 
have its field layout
 randomized.
   }];
 }
+
+def HLSLSV_GroupIndexDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``SV_GroupIndex`` semantic, when applied to an input parameter, specifies a
+data binding to map the group index to the specified parameter. This attribute
+is only supported in compute shaders.
+
+The full documentation is available here: 
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupindex
+  }];
+}

diff  --git a/clang/include/clang/Basic/AttributeCommonInfo.h 
b/clang/include/clang/Basic/AttributeCommonInfo.h
index 4be598e109fd8..478b9df371209 100644
--- a/clang/include/clang/Basic/AttributeCommonInfo.h
+++ b/clang/include/clang/Basic/AttributeCommonInfo.h
@@ -48,6 +48,9 @@ class AttributeCommonInfo {
 // without adding related code to TableGen/ClangAttrEmitter.cpp.
 /// Context-sensitive version of a keyword attribute.
 AS_ContextSensitiveKeyword,
+
+///  : 
+AS_HLSLSemantic,
   };
   enum Kind {
 #define PARSED_ATTR(NAME) AT_##NAME,

diff  --git a/clang/include/clang/Basic/Attributes.h 
b/clang/include/clang/Basic/Attributes.h
index c69633decd572..4afb6a1b9ca25 100644
--- a/clang/include/clang/Basic/Attributes.h
+++ b/clang/include/clang/Basic/Attributes.h
@@ -28,7 +28,9 @@ enum class AttrSyntax {
   // Is the identifier known as a C-style attribute?
   C,
   // Is the identifier known as a pragma attribute?
-  Pragma
+  Pragma,
+  // Is the identifier known as a HLSL semantic?
+  HLSLSemantic,
 };
 
 /// Return the version number associated with the attribute if we

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 1640a75391831..d8d78dfa0befa 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1594,4 +1594,10 @@ def warn_max_tokens_total : Warning<
 
 def note_max_tokens_total_override : Note<"total token limit set here">;
 
+// HLSL Parser Diagnostics
+
+def err_expected_semantic_identifier : Error<
+  "expected HLSL Semantic identifier">;
+def err_unknown_hlsl_semantic : Error<"unknown HLSL semantic %0">;
+
 } // end of Parser diagnostics

diff  --git a/clang/include/clang/Parse/Pa

[PATCH] D122699: [HLSL] Add Semantic syntax, and SV_GroupIndex

2022-04-14 Thread Chris Bieneman 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 rG1fdf952deeb9: [HLSL] Add Semantic syntax, and SV_GroupIndex 
(authored by beanz).

Changed prior to commit:
  https://reviews.llvm.org/D122699?vs=420620&id=422874#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122699

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/AttributeCommonInfo.h
  clang/include/clang/Basic/Attributes.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/CMakeLists.txt
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseHLSL.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/ParserHLSL/lit.local.cfg
  clang/test/ParserHLSL/semantic_parsing.hlsl
  clang/test/SemaHLSL/Semantics/entry_parameter.hlsl
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -1493,6 +1493,9 @@
 Spelling += Namespace;
 Spelling += " ";
   }
+} else if (Variety == "HLSLSemantic") {
+  Prefix = ":";
+  Suffix = "";
 } else {
   llvm_unreachable("Unknown attribute syntax variety!");
 }
@@ -3300,7 +3303,7 @@
   // Separate all of the attributes out into four group: generic, C++11, GNU,
   // and declspecs. Then generate a big switch statement for each of them.
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
-  std::vector Declspec, Microsoft, GNU, Pragma;
+  std::vector Declspec, Microsoft, GNU, Pragma, HLSLSemantic;
   std::map> CXX, C2x;
 
   // Walk over the list of all attributes, and split them out based on the
@@ -3321,6 +3324,8 @@
 C2x[SI.nameSpace()].push_back(R);
   else if (Variety == "Pragma")
 Pragma.push_back(R);
+  else if (Variety == "HLSLSemantic")
+HLSLSemantic.push_back(R);
 }
   }
 
@@ -3338,6 +3343,9 @@
   OS << "case AttrSyntax::Pragma:\n";
   OS << "  return llvm::StringSwitch(Name)\n";
   GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma");
+  OS << "case AttrSyntax::HLSLSemantic:\n";
+  OS << "  return llvm::StringSwitch(Name)\n";
+  GenerateHasAttrSpellingStringSwitch(HLSLSemantic, OS, "HLSLSemantic");
   auto fn = [&OS](const char *Spelling, const char *Variety,
   const std::map> &List) {
 OS << "case AttrSyntax::" << Variety << ": {\n";
@@ -4286,7 +4294,7 @@
 
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
   std::vector GNU, Declspec, Microsoft, CXX11,
-  Keywords, Pragma, C2x;
+  Keywords, Pragma, C2x, HLSLSemantic;
   std::set Seen;
   for (const auto *A : Attrs) {
 const Record &Attr = *A;
@@ -4338,6 +4346,8 @@
   Matches = &Keywords;
 else if (Variety == "Pragma")
   Matches = &Pragma;
+else if (Variety == "HLSLSemantic")
+  Matches = &HLSLSemantic;
 
 assert(Matches && "Unsupported spelling variety found");
 
@@ -4373,6 +4383,8 @@
   StringMatcher("Name", Keywords, OS).Emit();
   OS << "  } else if (AttributeCommonInfo::AS_Pragma == Syntax) {\n";
   StringMatcher("Name", Pragma, OS).Emit();
+  OS << "  } else if (AttributeCommonInfo::AS_HLSLSemantic == Syntax) {\n";
+  StringMatcher("Name", HLSLSemantic, OS).Emit();
   OS << "  }\n";
   OS << "  return AttributeCommonInfo::UnknownAttribute;\n"
  << "}\n";
@@ -4482,7 +4494,7 @@
   }
 }
 
-enum class SpellingKind {
+enum class SpellingKind : size_t {
   GNU,
   CXX11,
   C2x,
@@ -4490,8 +4502,10 @@
   Microsoft,
   Keyword,
   Pragma,
+  HLSLSemantic,
+  NumSpellingKinds
 };
-static const size_t NumSpellingKinds = (size_t)SpellingKind::Pragma + 1;
+static const size_t NumSpellingKinds = (size_t)SpellingKind::NumSpellingKinds;
 
 class SpellingList {
   std::vector Spellings[NumSpellingKinds];
@@ -4509,7 +4523,8 @@
 .Case("Declspec", SpellingKind::Declspec)
 .Case("Microsoft", SpellingKind::Microsoft)
 .Case("Keyword", SpellingKind::Keyword)
-.Case("Pragma", SpellingKind::Pragma);
+.Case("Pragma", SpellingKind::Pragma)
+.Case("HLSLSemantic", SpellingKind::HLSLSemantic);
 std::string Name;
 if (!Spelling.nameSpace().empty()) {
   switch (Kind) {
@@ -4610,8 +4625,8 @@
   // List what spelling syntaxes the attribute supports.
   OS << ".. csv-table:: Supported Syntaxes\n";
   OS << "   :header: \"GNU\", \"C++11\", \"C2x\", \"``__declspec``\",";
-  OS << " \"Keyword\", \"``#pragma``\", \"``#pragma clang attribute``\"\n\n";
-  OS << "   \"";
+  OS << " \"Keyword\", \"``#pragma``\", \"``#pragma clang attribut

[PATCH] D122789: [compiler-rt] [scudo] Use -mcrc32 on x86 when available

2022-04-14 Thread H.J Lu via Phabricator via cfe-commits
hjl.tools added a comment.

In D122789#3447413 , @pengfei wrote:

> In D122789#3446865 , @MaskRay wrote:
>
>> To kurly (original Gentoo reporter):
>>
>>   printf '#include \n#include \nuint32_t 
>> computeHardwareCRC32(uint32_t Crc, uint32_t Data) { return 
>> _mm_crc32_u32(Crc, Data); }' > a.c
>>
>>
>>
>>   % clang -m32 -march=i686 -msse4.2 -c a.c  # seems to compile fine
>>   % gcc -m32 -march=i686 -msse4.2 -c a.c
>>   % gcc -m32 -march=i686 -mcrc32 -c a.c
>>   In file included from a.c:1:
>>   a.c: In function ‘computeHardwareCRC32’:
>>   /usr/lib/gcc/x86_64-linux-gnu/11/include/smmintrin.h:839:1: error: 
>> inlining failed in call to ‘always_inline’ ‘_mm_crc32_u32’: target specific 
>> option mismatch
>> 839 | _mm_crc32_u32 (unsigned int __C, unsigned int __V)
>> | ^
>>   a.c:3:69: note: called from here
>>   3 | uint32_t computeHardwareCRC32(uint32_t Crc, uint32_t Data) { 
>> return _mm_crc32_u32(Crc, Data); }
>> |
>>  ^~~~
>>
>> I have some older GCC and latest GCC (2022-04, multilib), `gcc -m32 
>> -march=i686 -msse4.2 -c a.c`  builds while `-mcrc32` doesn't.
>>
>> I suspect we should revert the `-mcrc32` change. The `__CRC32__` macro may 
>> be fine.
>
> Thanks for the infromation. I got the same result. That's weird. I believe at 
> some point, GCC supported `-mcrc32`. @hjl.tools, did GCC intentionally remove 
> the support for `-mcrc32`?

"gcc -m32 -march=i686 -mcrc32" works with GCC 11.2: 
https://godbolt.org/z/nWzoofeKs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122789

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


[PATCH] D121299: [NVPTX] Disable DWARF .file directory for PTX

2022-04-14 Thread Andrew Savonichev via Phabricator via cfe-commits
asavonic added a comment.
Herald added a subscriber: gchakrabarti.

@MaskRay, should we merge this patch or rework it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121299

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


[clang] 1b1466c - [AArch64] Adjust aarch64 constrained intrinsics tests and un-XFAIL

2022-04-14 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2022-04-14T16:51:22+01:00
New Revision: 1b1466c346694c02ff0e30c96a50701b58bc4830

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

LOG: [AArch64] Adjust aarch64 constrained intrinsics tests and un-XFAIL

Remove the checking of the generated asm, as that's already tested
elsewhere, and adjust some tests that were expecting the wrong
intrinsic to be generated.

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

Added: 


Modified: 
clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c

Removed: 




diff  --git a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c 
b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
index fccafefd9d30c..e8c6b32128ffa 100644
--- a/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
+++ b/clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
@@ -1,27 +1,15 @@
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
 // RUN:  -flax-vector-conversions=none -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -ffp-exception-behavior=strict \
+// RUN:  -ffp-exception-behavior=strict -fexperimental-strict-floating-point \
 // RUN:  -flax-vector-conversions=none -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR 
--check-prefix=CONSTRAINED %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -flax-vector-conversions=none -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +neon \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN:  -ffp-exception-behavior=strict \
-// RUN:  -flax-vector-conversions=none -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,CONSTRAINED %s
 
 // REQUIRES: aarch64-registered-target
 
-// Fails during instruction selection:
-// XFAIL: *
-
 // Test new aarch64 intrinsics and types but constrained
 
 #include 
@@ -29,7 +17,6 @@
 // COMMON-LABEL: test_vadd_f32
 // UNCONSTRAINED: [[ADD_I:%.*]] = fadd <2 x float> %v1, %v2
 // CONSTRAINED:   [[ADD_I:%.*]] = call <2 x float> 
@llvm.experimental.constrained.fadd.v2f32(<2 x float> %v1, <2 x float> %v2, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM: fadd v{{[0-9]+}}.2s, v{{[0-9]+}}.2s, v{{[0-9]+}}.2s
 // COMMONIR:  ret <2 x float> [[ADD_I]]
 float32x2_t test_vadd_f32(float32x2_t v1, float32x2_t v2) {
   return vadd_f32(v1, v2);
@@ -38,7 +25,6 @@ float32x2_t test_vadd_f32(float32x2_t v1, float32x2_t v2) {
 // COMMON-LABEL: test_vaddq_f32
 // UNCONSTRAINED: [[ADD_I:%.*]] = fadd <4 x float> %v1, %v2
 // CONSTRAINED:   [[ADD_I:%.*]] = call <4 x float> 
@llvm.experimental.constrained.fadd.v4f32(<4 x float> %v1, <4 x float> %v2, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM: fadd v{{[0-9]+}}.4s, v{{[0-9]+}}.4s, v{{[0-9]+}}.4s
 // COMMONIR:  ret <4 x float> [[ADD_I]]
 float32x4_t test_vaddq_f32(float32x4_t v1, float32x4_t v2) {
   return vaddq_f32(v1, v2);
@@ -47,7 +33,6 @@ float32x4_t test_vaddq_f32(float32x4_t v1, float32x4_t v2) {
 // COMMON-LABEL: test_vsub_f32
 // UNCONSTRAINED: [[SUB_I:%.*]] = fsub <2 x float> %v1, %v2
 // CONSTRAINED:   [[SUB_I:%.*]] = call <2 x float> 
@llvm.experimental.constrained.fsub.v2f32(<2 x float> %v1, <2 x float> %v2, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM: fsub v{{[0-9]+}}.2s, v{{[0-9]+}}.2s, v{{[0-9]+}}.2s
 // COMMONIR:  ret <2 x float> [[SUB_I]]
 float32x2_t test_vsub_f32(float32x2_t v1, float32x2_t v2) {
   return vsub_f32(v1, v2);
@@ -56,7 +41,6 @@ float32x2_t test_vsub_f32(float32x2_t v1, float32x2_t v2) {
 // COMMON-LABEL: test_vsubq_f32
 // UNCONSTRAINED: [[SUB_I:%.*]] = fsub <4 x float> %v1, %v2
 // CONSTRAINED:   [[SUB_I:%.*]] = call <4 x float> 
@llvm.experimental.constrained.fsub.v4f32(<4 x float> %v1, <4 x float> %v2, 
metadata !"round.tonearest", metadata !"fpexcept.strict")
-// CHECK-ASM: fsub v{{[0-9]+}}.4s, v{{[0-9]+}}.4s, v{{[0-9]+}}.4s
 // COMMONIR:  ret <4 x float> [[SUB_I]]
 float32x4_t test_vsubq_f32(float32x4_t v1, float32x4_t v2) {
   return vsu

[PATCH] D115620: [AArch64] Lowering and legalization of strict FP16

2022-04-14 Thread John Brawn 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 rG12c1022679d4: [AArch64] Lowering and legalization of strict 
FP16 (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115620

Files:
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
  llvm/test/CodeGen/AArch64/fp-intrinsics.ll

Index: llvm/test/CodeGen/AArch64/fp-intrinsics.ll
===
--- llvm/test/CodeGen/AArch64/fp-intrinsics.ll
+++ llvm/test/CodeGen/AArch64/fp-intrinsics.ll
@@ -1,5 +1,5 @@
-; RUN: llc -mtriple=aarch64-none-eabi %s -disable-strictnode-mutation -o - | FileCheck %s
-; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -disable-strictnode-mutation %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s
 
 ; Check that constrained fp intrinsics are correctly lowered.
 
Index: llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/fp-intrinsics-fp16.ll
@@ -0,0 +1,1173 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64-none-eabi %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOFP16
+; RUN: llc -mtriple=aarch64-none-eabi -global-isel=true -global-isel-abort=2 -mattr=+fullfp16 %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-FP16
+
+; Check that constrained fp intrinsics are correctly lowered.
+
+
+; Half-precision intrinsics
+
+define half @add_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: add_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fadd s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: add_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fadd h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fadd.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @sub_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: sub_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fsub s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: sub_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fsub h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fsub.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @mul_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: mul_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fmul s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: mul_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fmul h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fmul.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @div_f16(half %x, half %y) #0 {
+; CHECK-NOFP16-LABEL: div_f16:
+; CHECK-NOFP16:   // %bb.0:
+; CHECK-NOFP16-NEXT:fcvt s1, h1
+; CHECK-NOFP16-NEXT:fcvt s0, h0
+; CHECK-NOFP16-NEXT:fdiv s0, s0, s1
+; CHECK-NOFP16-NEXT:fcvt h0, s0
+; CHECK-NOFP16-NEXT:ret
+;
+; CHECK-FP16-LABEL: div_f16:
+; CHECK-FP16:   // %bb.0:
+; CHECK-FP16-NEXT:fdiv h0, h0, h1
+; CHECK-FP16-NEXT:ret
+  %val = call half @llvm.experimental.constrained.fdiv.f16(half %x, half %y, metadata !"round.tonearest", metadata !"fpexcept.strict") #0
+  ret half %val
+}
+
+define half @frem_f16(half %x, half %y) #0 {
+; CHECK-LABEL: frem_f16:
+; CHECK:   // %bb.0:
+; CHECK-NEXT:str x30, [sp, #-16]! // 8-byte Folded Spill
+; CHECK-NEXT:.cfi_def_cfa_offset 16
+; CHECK-NEXT:.cfi_offset w30, -16
+; CHECK-NEXT:fcvt s1, h1
+; CHECK-NEXT:fcvt s0, h0
+; CHECK-NEXT:bl fmodf
+; CHECK-NEXT:fcvt h0, s0
+; CHECK-NEXT:ldr x30, [sp], #16 // 8-byte Folded Reload
+; CHECK-NEXT:ret
+  %val = call half @llvm.experimental.constrained.frem.f16(half %x, half %y, meta

[PATCH] D118259: [AArch64] Adjust aarch64 constrained intrinsics tests and un-XFAIL

2022-04-14 Thread John Brawn 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 rG1b1466c34669: [AArch64] Adjust aarch64 constrained 
intrinsics tests and un-XFAIL (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D118259

Files:
  clang/test/CodeGen/aarch64-neon-intrinsics-constrained.c
  clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c

Index: clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
===
--- clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
+++ clang/test/CodeGen/aarch64-v8.2a-fp16-intrinsics-constrained.c
@@ -1,31 +1,19 @@
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
 // RUN: -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=UNCONSTRAINED %s
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,UNCONSTRAINED %s
 // RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
 // RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone \
-// RUN: -ffp-exception-behavior=strict -emit-llvm -o - %s | opt -S -mem2reg \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=COMMONIR --check-prefix=CONSTRAINED %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -target-feature +fullfp16 \
-// RUN: -ffp-exception-behavior=strict \
-// RUN: -fallow-half-arguments-and-returns -S -disable-O0-optnone -o - %s \
-// RUN: | FileCheck --check-prefix=COMMON --check-prefix=CHECK-ASM %s
+// RUN: -ffp-exception-behavior=strict -fexperimental-strict-floating-point -emit-llvm -o - %s | opt -S -mem2reg \
+// RUN: | FileCheck --check-prefixes=COMMON,COMMONIR,CONSTRAINED %s
 
 // REQUIRES: aarch64-registered-target
 
-// "Lowering of strict fp16 not yet implemented"
-// XFAIL: *
-
 #include 
 
 // COMMON-LABEL: test_vceqzh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp oeq half %a, 0xH
 // CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"oeq", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, eq
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vceqzh_f16(float16_t a) {
@@ -34,9 +22,7 @@
 
 // COMMON-LABEL: test_vcgezh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp oge half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"oge", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, ge
+// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f16(half %a, half 0xH, metadata !"oge", metadata !"fpexcept.strict")
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vcgezh_f16(float16_t a) {
@@ -45,9 +31,7 @@
 
 // COMMON-LABEL: test_vcgtzh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp ogt half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"ogt", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, gt
+// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f16(half %a, half 0xH, metadata !"ogt", metadata !"fpexcept.strict")
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vcgtzh_f16(float16_t a) {
@@ -56,9 +40,7 @@
 
 // COMMON-LABEL: test_vclezh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp ole half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"ole", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, ls
+// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmps.f16(half %a, half 0xH, metadata !"ole", metadata !"fpexcept.strict")
 // COMMONIR:   [[TMP2:%.*]] = sext i1 [[TMP1]] to i16
 // COMMONIR:   ret i16 [[TMP2]]
 uint16_t test_vclezh_f16(float16_t a) {
@@ -67,9 +49,7 @@
 
 // COMMON-LABEL: test_vcltzh_f16
 // UNCONSTRAINED:  [[TMP1:%.*]] = fcmp olt half %a, 0xH
-// CONSTRAINED:[[TMP1:%.*]] = call i1 @llvm.experimental.constrained.fcmp.f16(half %a, half 0xH, metadata !"olt", metadata !"fpexcept.strict")
-// CHECK-ASM:  fcmp
-// CHECK-ASM:  cset {{w[0-9]+}}, mi
+// CONSTRAINED:[[TMP1:%.*]] = call i1

[PATCH] D123773: [clang][analyzer][ctu] Make CTU a two phase analysis

2022-04-14 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

> Make CTU a two phase analysis

At this point maybe it will be a three phase, as we might dump the ASTs/create 
index in phase 1 :)

> During this phase, if we find a foreign function (that could be inlined from 
> another TU) then we don’t inline that immediately, we rather mark that to be 
> analysed later.

I wonder whether this is the right approach. Not inlining a function can also 
introduce false positives. While I do see why we do not want to inline ALL 
functions upfront, I wonder if we actually want to inline small functions. The 
CSA already has heuristics like this, to always inline really small functions 
(defined by the number of nodes in the Cfg) despite other cut heuristics and it 
was found to improve the quality of the results overall. I think doing 
something similar for CTU might ultimately improve the precision of the 
analysis. What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123773

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


[PATCH] D123767: [clang][parse] NFCI: Use FileEntryRef in Parser::ParseModuleImport()

2022-04-14 Thread Ben Barham via Phabricator via cfe-commits
bnbarham accepted this revision.
bnbarham added a comment.
This revision is now accepted and ready to land.

Thanks for doing all these Jan!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123767

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


[PATCH] D123737: [clang-format] Skip preprocessor lines when finding the record lbrace

2022-04-14 Thread Arthur Eubanks 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 rGf14ebe91c5dd: [clang-format] Skip preprocessor lines when 
finding the record lbrace (authored by aeubanks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123737

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12766,6 +12766,13 @@
"};",
MergeInlineOnly);
 
+  verifyFormat("class C {\n"
+   "#ifdef A\n"
+   "  int f() { return 42; }\n"
+   "#endif\n"
+   "};",
+   MergeInlineOnly);
+
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
   MergeInlineOnly.BraceWrapping.AfterFunction = true;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -308,7 +308,7 @@
   // Find the last line with lower level.
   auto J = I - 1;
   for (; J != AnnotatedLines.begin(); --J)
-if ((*J)->Level < TheLine->Level)
+if (!(*J)->InPPDirective && (*J)->Level < TheLine->Level)
   break;
   if ((*J)->Level >= TheLine->Level)
 return false;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -12766,6 +12766,13 @@
"};",
MergeInlineOnly);
 
+  verifyFormat("class C {\n"
+   "#ifdef A\n"
+   "  int f() { return 42; }\n"
+   "#endif\n"
+   "};",
+   MergeInlineOnly);
+
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
   MergeInlineOnly.BraceWrapping.AfterFunction = true;
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -308,7 +308,7 @@
   // Find the last line with lower level.
   auto J = I - 1;
   for (; J != AnnotatedLines.begin(); --J)
-if ((*J)->Level < TheLine->Level)
+if (!(*J)->InPPDirective && (*J)->Level < TheLine->Level)
   break;
   if ((*J)->Level >= TheLine->Level)
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f14ebe9 - [clang-format] Skip preprocessor lines when finding the record lbrace

2022-04-14 Thread Arthur Eubanks via cfe-commits

Author: Arthur Eubanks
Date: 2022-04-14T09:31:15-07:00
New Revision: f14ebe91c5dd6be5b64a45e479291cd08676be0c

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

LOG: [clang-format] Skip preprocessor lines when finding the record lbrace

With D117142, we would now format

```
struct A {
#define A
  void f() { a(); }
#endif
};
```

into

```
struct A {
#ifdef A
  void f() {
a();
  }
#endif
};
```

because we were looking for the record lbrace without skipping preprocess lines.

Fixes https://github.com/llvm/llvm-project/issues/54901.

Reviewed By: curdeius, owenpan

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index e2dbc35c22004..9154999e2644f 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -308,7 +308,7 @@ class LineJoiner {
   // Find the last line with lower level.
   auto J = I - 1;
   for (; J != AnnotatedLines.begin(); --J)
-if ((*J)->Level < TheLine->Level)
+if (!(*J)->InPPDirective && (*J)->Level < TheLine->Level)
   break;
   if ((*J)->Level >= TheLine->Level)
 return false;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index e837dbd566957..bf4ba3d4738ee 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12766,6 +12766,13 @@ TEST_F(FormatTest, 
PullInlineFunctionDefinitionsIntoSingleLine) {
"};",
MergeInlineOnly);
 
+  verifyFormat("class C {\n"
+   "#ifdef A\n"
+   "  int f() { return 42; }\n"
+   "#endif\n"
+   "};",
+   MergeInlineOnly);
+
   // Also verify behavior when BraceWrapping.AfterFunction = true
   MergeInlineOnly.BreakBeforeBraces = FormatStyle::BS_Custom;
   MergeInlineOnly.BraceWrapping.AfterFunction = true;



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


[PATCH] D123771: [clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::load*()

2022-04-14 Thread Ben Barham via Phabricator via cfe-commits
bnbarham added inline comments.



Comment at: clang/lib/Lex/HeaderSearch.cpp:339
 // Search for a module map file in this directory.
-if (loadModuleMapFile(Dir.getDir(), IsSystem,
+if (loadModuleMapFile(*Dir.getDirRef(), IsSystem,
   /*IsFramework*/false) == LMM_NewlyLoaded) {

I'd prefer the following since I had to specifically go and check `getDirRef`, 
though I suppose I probably would have done so even with a comment 😅 :
```
// Only returns None if not a normal directory, which we just checked
DirectoryEntryRef NormalDir = *Dir.getDirRef();
...loadModuleMapFile(NormalDir, ...
```



Comment at: clang/lib/Lex/HeaderSearch.cpp:1583
+::getTopFrameworkDir(FileMgr, FrameworkName, SubmodulePath);
+assert(TopFrameworkDir && "Could not find the top-most framework dir");
 

Can we just return false in this case, or is it definitely always a logic error?



Comment at: clang/lib/Lex/HeaderSearch.cpp:1630
+  llvm::sys::path::parent_path(OriginalModuleMapFile))) {
+Dir = *MaybeDir;
   } else {

Shouldn't need the * should it? Also doesn't seem necessary to actually check 
here since `Dir` hasn't been set yet. Just `Dir = 
FileMgr.getOptionalDirectoryRef...` should be fine.



Comment at: clang/lib/Lex/HeaderSearch.cpp:1636
 } else {
-  Dir = File->getDir();
+  Dir = File->getLastRef().getDir();
 }

I assume this is the place you mentioned in the message? (ie. to prevent patch 
from growing even more)



Comment at: clang/lib/Lex/HeaderSearch.cpp:1639
 
 StringRef DirName(Dir->getName());
 if (llvm::sys::path::filename(DirName) == "Modules") {

Can't `Dir` still be `None` here? It *shouldn't* be since the directory for 
`OriginalModuleMapFile` should exist, but I'd feel more comfortable with either 
an early return or an assert here.

Same thing below at the switch as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123771

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


[PATCH] D123352: [analyzer] Add FixItHint to `nullability.NullReturnedFromNonnull` and `nullability.NullableReturnedFromNonnull`

2022-04-14 Thread Moshe via Phabricator via cfe-commits
MosheBerman updated this revision to Diff 422902.
MosheBerman added a comment.

The tests now pass and actually verify the behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123352

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  clang/test/Analysis/nullability-fixits.mm

Index: clang/test/Analysis/nullability-fixits.mm
===
--- /dev/null
+++ clang/test/Analysis/nullability-fixits.mm
@@ -0,0 +1,70 @@
+// This test runs the nullability checkers with fixits enabled to verify that the
+// fixits are produced as expected. Note that we disable `-Wnonnull` since it
+// pollutes the output and doesn't provide fixits.
+
+// RUN: %clang_cc1 -analyze \
+// RUN: -Wno-nonnull \
+// RUN: -analyzer-checker=core,nullability.NullableReturnedFromNonnull,nullability.NullReturnedFromNonnull \
+// RUN: -fdiagnostics-parseable-fixits %s 2>%t
+// RUN: cat %t | FileCheck %s -check-prefix=CHECK-FIXIT-DISABLED-IMPLICIT
+
+// RUN: %clang_cc1 -analyze \
+// RUN: -Wno-nonnull \
+// RUN: -analyzer-checker=core,nullability.NullableReturnedFromNonnull,nullability.NullReturnedFromNonnull \
+// RUN: -analyzer-config nullability.NullReturnedFromNonnull:ShowFixIts=false \
+// RUN: -analyzer-config nullability.NullableReturnedFromNonnull:ShowFixIts=false \
+// RUN: -fdiagnostics-parseable-fixits %s 2>%t
+// RUN: cat %t | FileCheck %s -check-prefix=CHECK-FIXIT-DISABLED-EXPLICIT
+
+// RUN: %clang_cc1 -analyze \
+// RUN: -Wno-nonnull \
+// RUN: -analyzer-checker=core,nullability.NullableReturnedFromNonnull,nullability.NullReturnedFromNonnull \
+// RUN: -analyzer-config nullability.NullReturnedFromNonnull:ShowFixIts=true \
+// RUN: -analyzer-config nullability.NullableReturnedFromNonnull:ShowFixIts=true \
+// RUN: -fdiagnostics-parseable-fixits %s 2>%t
+// RUN: cat %t | FileCheck %s -check-prefix=CHECK-FIXIT-ENABLED
+
+
+// CHECK-FIXIT-ENABLED: fix-it:"{{.*[/\\]*}}clang/test/Analysis/nullability-fixits.mm"
+// CHECK-FIXIT-DISABLED-EXPLICIT-NOT: fix-it:"{{.*[/\\]*}}clang/test/Analysis/nullability-fixits.mm"
+// CHECK-FIXIT-DISABLED-IMPLICIT-NOT: fix-it:"{{.*[/\\]*}}clang/test/Analysis/nullability-fixits.mm"
+
+#include "Inputs/system-header-simulator-for-nullability.h"
+
+@interface TestObject : NSObject
+@end
+
+NSObject *_Nonnull returnsNilObjCInstanceIndirectly() {
+  TestObject *local = nil;
+  return local;
+}
+
+TestObject *_Nonnull returnsNilObjCInstanceDirectly() {
+  return nil;
+}
+
+@interface ClassWithInitializers : NSObject
+@end
+
+@implementation ClassWithInitializers
+
+- (TestObject *_Nonnull)returnsNilUnsuppressed {
+  return nil;
+}
+
+- (TestObject *_Nullable)returnsNil {
+  return (TestObject *_Nonnull)nil;
+}
+- (TestObject *_Nonnull)inlineOfReturnsNilObjCInstanceDirectlyWithSuppressingCast {
+  TestObject *o = [self returnsNil];
+  return o;
+}
+@end
+
+NS_ASSUME_NONNULL_BEGIN
+
+NSObject * returnsNilAssumeNonnull() {
+  return nil;
+}
+
+NS_ASSUME_NONNULL_END
Index: clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
@@ -117,6 +117,9 @@
 
   DefaultBool ChecksEnabled[CK_NumCheckKinds];
   CheckerNameRef CheckNames[CK_NumCheckKinds];
+  // FIXME: Should we consider changing the invariant behavior for `nil`
+  // and/or NS collection classes if this is enabled?
+  DefaultBool ShowFixIts[CK_NumCheckKinds];
   mutable std::unique_ptr BTs[CK_NumCheckKinds];
 
   const std::unique_ptr &getBugType(CheckKind Kind) const {
@@ -152,6 +155,20 @@
 const MemRegion *Region;
   };
 
+  /// There are a few cases where we want to move the insertion point.
+  /// 1. If we are inserting after the pointer, we need to offset ourselves,
+  ///because `getReturnTypeSourceRange` does not include qualifiers so the
+  ///annotation would be inserted incorrectly before the pointer symbol.
+  /// 2. If we are annotating an Objective-C method, and not a function, we
+  ///want to use the `nullable` form instead of `_Nullable`.
+  ///When \p SyntaxSugar is true, we handle the second case.
+  SourceLocation getInsertionLocForTypeInfo(TypeSourceInfo *TypeSourceInfo,
+const size_t Offset = 0,
+bool SyntaxSugar = false) const {
+return TypeSourceInfo->getTypeLoc().getBeginLoc().getLocWithOffset(
+SyntaxSugar ? 0 : Offset);
+  }
+
   /// When any of the nonnull arguments of the analyzed function is null, do not
   /// report anything and turn off the check.
   ///
@@ -160,12 +177,13 @@
   void reportBugIfInvariantHolds(StringRef Msg, ErrorKind Error, CheckKind CK,
  ExplodedNode *N, cons

[clang] 7ef9dd3 - [PS4] Fix a couple of typos

2022-04-14 Thread Paul Robinson via cfe-commits

Author: Paul Robinson
Date: 2022-04-14T10:14:17-07:00
New Revision: 7ef9dd3c61fd85b430bcd74f7ce2c075d93fe4fa

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

LOG: [PS4] Fix a couple of typos

Added: 


Modified: 
clang/lib/Driver/ToolChains/PS4CPU.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/PS4CPU.h 
b/clang/lib/Driver/ToolChains/PS4CPU.h
index 21352f9fdf52e..dbb9c14b6373c 100644
--- a/clang/lib/Driver/ToolChains/PS4CPU.h
+++ b/clang/lib/Driver/ToolChains/PS4CPU.h
@@ -105,7 +105,7 @@ class LLVM_LIBRARY_VISIBILITY PS4PS5Base : public 
Generic_ELF {
   virtual void addSanitizerArgs(const llvm::opt::ArgList &Args,
 llvm::opt::ArgStringList &CmdArgs,
 const char *Prefix,
-const char *Suffic) const = 0;
+const char *Suffix) const = 0;
   virtual const char *getProfileRTLibName() const = 0;
 
 protected:
@@ -122,7 +122,7 @@ class LLVM_LIBRARY_VISIBILITY PS4CPU : public PS4PS5Base {
   unsigned GetDefaultDwarfVersion() const override { return 4; }
 
   // PS4 toolchain uses legacy thin LTO API, which is not
-  // capable of unit splitt.
+  // capable of unit splitting.
   bool canSplitThinLTOUnit() const override { return false; }
 
   const char *getLinkerBaseName() const override { return "ld"; }



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


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1234
 
+void Parser::ParseLambdaLexedAttribute(LateParsedAttribute &LA,
+   ParsedAttributes &Attrs, Declarator &D) 
{

I think this should likely be named `ParseLambdaLexedGNUAttributeArgs()` 
instead, because this is pretty specific to GNU-style attribute argument lists 
and shouldn't be used for other attribute syntaxes, correct?



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1253-1256
+  // Due to a parsing error, we either went over the cached tokens or
+  // there are still cached tokens left, so we skip the leftover tokens.
+  while (Tok.isNot(tok::eof))
+ConsumeAnyToken();

This comment reads a bit oddly to me. I think it may be better as "After 
parsing attribute arguments, we've either reached the EOF token (signaling that 
parsing was successful) or we have tokens we need to consume until we reach the 
EOF."



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1258
+
+  if (Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData())
+ConsumeAnyToken();

Then I think we can assert that the token is EOF here and consume it always.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1369
+// we delay the parsing of gnu attributes - by reusing the mechanism used
+// for C++ late method parsing.
+MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes,





Comment at: clang/lib/Parse/ParseExprCXX.cpp:1397
+for (LateParsedAttribute *Attr : LateParsedAttrs) {
+  ParseLambdaLexedAttribute(*Attr, Attributes, D);
+  delete Attr;

I think you should add an assert before this call to ensure that all attributes 
are GNU ones.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1486
+  if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
+  tok::kw___declspec, tok::kw_constexpr, tok::kw_consteval,
+  tok::kw___private, tok::kw___global, tok::kw___local,

Do we have test coverage for this change? (It seems orthogonal to your patch, 
so this might be worth splitting out.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

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


[PATCH] D123667: [clang][AST] Fix crash getting name of a template decl

2022-04-14 Thread Tom Eccles via Phabricator via cfe-commits
tblah updated this revision to Diff 422906.
tblah added a comment.

Added a unit test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123667

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/unittests/AST/TypePrinterTest.cpp


Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -64,6 +64,22 @@
   [](PrintingPolicy &Policy) { Policy.FullyQualifiedName = true; }));
 }
 
+TEST(TypePrinter, TemplateId2) {
+  std::string Code = R"cpp(
+  template  class TemplatedType>
+  void func(TemplatedType Param);
+)cpp";
+  auto Matcher = parmVarDecl(hasType(qualType().bind("id")));
+
+  // regression test ensuring we do not segfault getting the qualtype as a
+  // string
+  ASSERT_TRUE(PrintedTypeMatches(Code, {}, Matcher, "",
+ [](PrintingPolicy &Policy) {
+   Policy.FullyQualifiedName = true;
+   Policy.PrintCanonicalTypes = true;
+ }));
+}
+
 TEST(TypePrinter, ParamsUglified) {
   llvm::StringLiteral Code = R"cpp(
 template  class __f>
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1467,8 +1467,7 @@
 if (!Policy.SuppressScope)
   AppendScope(TD->getDeclContext(), OS, TD->getDeclName());
 
-IdentifierInfo *II = TD->getIdentifier();
-OS << II->getName();
+OS << TD->getName();
   } else {
 T->getTemplateName().print(OS, Policy);
   }


Index: clang/unittests/AST/TypePrinterTest.cpp
===
--- clang/unittests/AST/TypePrinterTest.cpp
+++ clang/unittests/AST/TypePrinterTest.cpp
@@ -64,6 +64,22 @@
   [](PrintingPolicy &Policy) { Policy.FullyQualifiedName = true; }));
 }
 
+TEST(TypePrinter, TemplateId2) {
+  std::string Code = R"cpp(
+  template  class TemplatedType>
+  void func(TemplatedType Param);
+)cpp";
+  auto Matcher = parmVarDecl(hasType(qualType().bind("id")));
+
+  // regression test ensuring we do not segfault getting the qualtype as a
+  // string
+  ASSERT_TRUE(PrintedTypeMatches(Code, {}, Matcher, "",
+ [](PrintingPolicy &Policy) {
+   Policy.FullyQualifiedName = true;
+   Policy.PrintCanonicalTypes = true;
+ }));
+}
+
 TEST(TypePrinter, ParamsUglified) {
   llvm::StringLiteral Code = R"cpp(
 template  class __f>
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1467,8 +1467,7 @@
 if (!Policy.SuppressScope)
   AppendScope(TD->getDeclContext(), OS, TD->getDeclName());
 
-IdentifierInfo *II = TD->getIdentifier();
-OS << II->getName();
+OS << TD->getName();
   } else {
 T->getTemplateName().print(OS, Policy);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked an inline comment as done.
cor3ntin added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1253-1256
+  // Due to a parsing error, we either went over the cached tokens or
+  // there are still cached tokens left, so we skip the leftover tokens.
+  while (Tok.isNot(tok::eof))
+ConsumeAnyToken();

aaron.ballman wrote:
> This comment reads a bit oddly to me. I think it may be better as "After 
> parsing attribute arguments, we've either reached the EOF token (signaling 
> that parsing was successful) or we have tokens we need to consume until we 
> reach the EOF."
Agreed



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1258
+
+  if (Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData())
+ConsumeAnyToken();

aaron.ballman wrote:
> Then I think we can assert that the token is EOF here and consume it always.
Agreed, that seems better



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1369
+// we delay the parsing of gnu attributes - by reusing the mechanism used
+// for C++ late method parsing.
+MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attributes,

aaron.ballman wrote:
> 
It's more like there is no `__declspec` that can refer to expression so this 
was never implemented



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1397
+for (LateParsedAttribute *Attr : LateParsedAttrs) {
+  ParseLambdaLexedAttribute(*Attr, Attributes, D);
+  delete Attr;

aaron.ballman wrote:
> I think you should add an assert before this call to ensure that all 
> attributes are GNU ones.
I'm not sure that gains much? 
In the future if late parsing is implemented for `__declspec` this would just 
work , unless we add an assert. I'd be fine adding it though.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1486
+  if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
+  tok::kw___declspec, tok::kw_constexpr, tok::kw_consteval,
+  tok::kw___private, tok::kw___global, tok::kw___local,

aaron.ballman wrote:
> Do we have test coverage for this change? (It seems orthogonal to your patch, 
> so this might be worth splitting out.)
I'm happy doing that, or to add a test somewhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

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


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1397
+for (LateParsedAttribute *Attr : LateParsedAttrs) {
+  ParseLambdaLexedAttribute(*Attr, Attributes, D);
+  delete Attr;

cor3ntin wrote:
> aaron.ballman wrote:
> > I think you should add an assert before this call to ensure that all 
> > attributes are GNU ones.
> I'm not sure that gains much? 
> In the future if late parsing is implemented for `__declspec` this would just 
> work , unless we add an assert. I'd be fine adding it though.
Because `ParseLambdaLexedAttribute()` specifically parses GNU attribute args 
and not declspec ones, I think that function should be renamed. Once that 
function is renamed to say GNU explicitly, then there's a question of what 
happens when we hand it late parsed declspec attribute. Which is why I was 
suggesting a comment above to mention that declspec attributes don't late parse 
anyway.

Another way to handle this that's more general would be to change 
`ParseLambdaLexedAttribute()` to parse different args depending on the syntax 
of the attribute (then it can keep its generic name).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

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


Re: [clang] 26dbb93 - [Driver] Fix -fpascal-strings on Darwin

2022-04-14 Thread Fangrui Song via cfe-commits
This fixed failure of clang_f_opts.c after
bfafa105aab05e2c243e74114739b7d37f8ab0be
when the LLVM_DEFAULT_TARGET_TRIPLE looks like arm64-apple-darwin.
Sorry that I did not provide enough information in the message.

I think the few lines in Darwin.cpp should just be removed since
-mpascal-strings is an alias for -fpascal-strings on all targets.

On Thu, Apr 14, 2022 at 5:53 AM Aaron Ballman  wrote:
>
> Should there be some test coverage for this change (or was this fixing
> an already failing test)?
>
> ~Aaron
>
> On Thu, Apr 14, 2022 at 2:01 AM Fangrui Song via cfe-commits
>  wrote:
> >
> >
> > Author: Fangrui Song
> > Date: 2022-04-13T23:00:57-07:00
> > New Revision: 26dbb93704bf39a198909d04ad8c49b4bde46cce
> >
> > URL: 
> > https://github.com/llvm/llvm-project/commit/26dbb93704bf39a198909d04ad8c49b4bde46cce
> > DIFF: 
> > https://github.com/llvm/llvm-project/commit/26dbb93704bf39a198909d04ad8c49b4bde46cce.diff
> >
> > LOG: [Driver] Fix -fpascal-strings on Darwin
> >
> > Added:
> >
> >
> > Modified:
> > clang/lib/Driver/ToolChains/Darwin.cpp
> >
> > Removed:
> >
> >
> >
> > 
> > diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
> > b/clang/lib/Driver/ToolChains/Darwin.cpp
> > index 9f0eeea8d54e2..aaa4c6e5aabb8 100644
> > --- a/clang/lib/Driver/ToolChains/Darwin.cpp
> > +++ b/clang/lib/Driver/ToolChains/Darwin.cpp
> > @@ -2554,11 +2554,11 @@ DerivedArgList *MachO::TranslateArgs(const 
> > DerivedArgList &Args,
> >break;
> >
> >  case options::OPT_fpascal_strings:
> > -  DAL->AddFlagArg(A, Opts.getOption(options::OPT_mpascal_strings));
> > +  DAL->AddFlagArg(A, Opts.getOption(options::OPT_fpascal_strings));
> >break;
> >
> >  case options::OPT_fno_pascal_strings:
> > -  DAL->AddFlagArg(A, Opts.getOption(options::OPT_mno_pascal_strings));
> > +  DAL->AddFlagArg(A, Opts.getOption(options::OPT_fno_pascal_strings));
> >break;
> >  }
> >}
> >
> >
> >
> > ___
> > cfe-commits mailing list
> > cfe-commits@lists.llvm.org
> > https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked an inline comment as done.
cor3ntin added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1486
+  if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
+  tok::kw___declspec, tok::kw_constexpr, tok::kw_consteval,
+  tok::kw___private, tok::kw___global, tok::kw___local,

cor3ntin wrote:
> aaron.ballman wrote:
> > Do we have test coverage for this change? (It seems orthogonal to your 
> > patch, so this might be worth splitting out.)
> I'm happy doing that, or to add a test somewhere.
This was actually a _very_ stupid change on my part, the previous code was 
correct. ie, msvc does not support `[] __declspec(deprecated) {};` 
https://godbolt.org/z/cEKP44rY1
and so the omission of `__declspec` here, which i thought was a bug, is 
actually very purposeful


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

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


[PATCH] D123167: [HLSL] Pointers are unsupported in HLSL

2022-04-14 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 aside from the formatting nit.




Comment at: clang/lib/Sema/SemaExpr.cpp:15252-15257
+  if (getLangOpts().HLSL) {
+if (Opc == UO_AddrOf)
+  return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 0);
+if (Opc == UO_Deref)
+  return ExprError(Diag(OpLoc, diag::err_hlsl_operator_unsupported) << 1);
+  }

beanz wrote:
> aaron.ballman wrote:
> > How should this interplay with overloaded operators on user-defined types? 
> > Is that case allowed so long as it doesn't form a pointer or a reference? 
> > (We should add test coverage for that.)
> So, the "correct" end goal is that we don't support overloading those 
> operators. We have a few limitations on which operators we allow overloading 
> for, generally any operators that in normal use return references or 
> pointers, we don't allow you to overload.
> 
> That said, I wrote some test code to see where this falls over with my 
> current change:
> 
> ```
> struct Fish {
>   struct Fins {
> int Left;
> int Right;
>   };
>   int X;
>   int operator *() {
> return X;
>   }
> 
>   Fins operator ->() {
> return Fins();
>   }
> };
> 
> int gone_fishing() {
>   Fish F;
>   int Result = *F;   // works... and is consistent with DXC
>   Result += F->Left; // error: member reference type 'Fish::Fins' is not a 
> pointer
>   return Result;
> }
> ```
> 
> In the existing compiler we produce an error on definition of operators that 
> aren't supported. I'd like to handle improving the diagnostics for those 
> operators that way in a later patch if that is okay.
> 
> The `.*` and `.->` operators I couldn't get errors to actually trigger 
> because I couldn't think of a way to write them that wasn't dependent on 
> getting a member pointer, which errors and causes the remaining expression to 
> not be checked.
> In the existing compiler we produce an error on definition of operators that 
> aren't supported. I'd like to handle improving the diagnostics for those 
> operators that way in a later patch if that is okay.

That's fine by me.


> The .* and .-> operators I couldn't get errors to actually trigger because I 
> couldn't think of a way to write them that wasn't dependent on getting a 
> member pointer, which errors and causes the remaining expression to not be 
> checked.

Perfect, I couldn't find a way either, we can punt on that until we find a 
concrete issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123167

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


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1486
+  if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
+  tok::kw___declspec, tok::kw_constexpr, tok::kw_consteval,
+  tok::kw___private, tok::kw___global, tok::kw___local,

cor3ntin wrote:
> cor3ntin wrote:
> > aaron.ballman wrote:
> > > Do we have test coverage for this change? (It seems orthogonal to your 
> > > patch, so this might be worth splitting out.)
> > I'm happy doing that, or to add a test somewhere.
> This was actually a _very_ stupid change on my part, the previous code was 
> correct. ie, msvc does not support `[] __declspec(deprecated) {};` 
> https://godbolt.org/z/cEKP44rY1
> and so the omission of `__declspec` here, which i thought was a bug, is 
> actually very purposeful
Thank you for double-checking that; I thought that might be the case, but I 
hadn't tested it myself yet.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

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


[PATCH] D122766: [clang] Use forward slash as the path separator for Windows in __FILE__, __builtin_FILE(), and std::source_location

2022-04-14 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added a subscriber: rsmith.
ayzhao added a comment.

In D122766#3451775 , @hans wrote:

> In D122766#3450298 , @ayzhao wrote:
>
>> So, the general consensus seems to be that we should use backslashes when 
>> targeting Windows.
>>
>> I implemented using only backslashes for Windows; however, 
>> clang/test/SemaCXX/destructor.cpp 
>> 
>>  fails when running on Linux with the following error (among other errors, 
>> but the one below is the most important).
>>
>>   ...
>>   error: 'error' diagnostics seen but not expected:
>> Line 32: 
>> '\\clang\\test\\SemaCXX\\destructor.cpp'
>>  file not found
>>   ...
>>
>> The reason for this is that the test has Clang target windows 
>> 
>>  and the test also has the statement #include __FILE__ 
>> .
>
> That seems like an unusual use case of `__FILE__`. I wonder if we could just 
> change the test to `#include "destructor.cpp"` instead and not worry about 
> the case of `#include __FILE__` in cross-builds targeting Windows.

This line was introduced in D37235  
(coincidentally written by @thakis), and in that review, @rsmith made a comment 
on this exact line that said

> Do we guarantee that `__FILE__` names a path that can be used to include the 
> current file? In other tests, we add `-include %s` to the `RUN:` line to 
> model this situation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122766

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


[PATCH] D123783: [clang] Eliminate TypeProcessingState::trivial.

2022-04-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:170
 /// Whether we saved the attributes in the decl spec.
 bool hasSavedAttrs;
 

Isn't the same true for this variable? It seems like:

`trivial` == `savedAttrs.empty()`
`hasSavedAttrs` == `!savedAttrs.empty()`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123783

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


[PATCH] D119136: [clang] Implement Change scope of lambda trailing-return-type

2022-04-14 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 422920.
cor3ntin marked 2 inline comments as done.
cor3ntin added a comment.

Address aarons comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119136

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Scope.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/Scope.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaCXXScopeSpec.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/expr/expr.prim/expr.prim.lambda/p11-1y.cpp
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp
  clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1356,7 +1356,7 @@
 
   Change scope of lambda trailing-return-type
   https://wg21.link/P2036R3";>P2036R3
-  No
+  Clang 15
 
 
   Multidimensional subscript operator
Index: clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
===
--- clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
+++ clang/test/SemaCXX/warn-shadow-in-lambdas.cpp
@@ -95,7 +95,7 @@
 #ifdef AVOID
   auto l4 = [var = param] (int param) { ; }; // no warning
 #else
-  auto l4 = [var = param] (int param) { ; }; // expected-warning {{declaration shadows a local variable}}
+  auto l4 = [var = param](int param) { ; }; // expected-warning 2{{declaration shadows a local variable}}
 #endif
 
   // Make sure that inner lambdas work as well.
Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -0,0 +1,173 @@
+// RUN: %clang_cc1 -std=c++2b -verify -fsyntax-only %s
+
+template 
+constexpr bool is_same = false;
+
+template 
+constexpr bool is_same = true;
+
+void f() {
+
+  int y;
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((x)) { return x; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  static_assert(is_same decltype((y)) { return y; }())>);
+
+  auto ref = [&x = y](
+ decltype([&](decltype(x)) { return 0; }) y) {
+return x;
+  };
+}
+
+void test_noexcept() {
+
+  int y;
+
+  static_assert(noexcept([x = 1] noexcept(is_same) {}()));
+  static_assert(noexcept([x = 1] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([y] noexcept(is_same) {}()));
+  static_assert(noexcept([y] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([=] noexcept(is_same) {}()));
+  static_assert(noexcept([=] mutable noexcept(is_same) {}()));
+  static_assert(noexcept([&] noexcept(is_same) {}()));
+  static_assert(noexcept([&] mutable noexcept(is_same) {}()));
+
+  static_assert(noexcept([&] mutable noexcept(!is_same) {}())); // expected-error {{static_assert failed due}}
+}
+
+void test_requires() {
+
+  int x;
+
+  [x = 1]() requires is_same {}
+  ();
+  [x = 1]() mutable requires is_same {}
+  ();
+  [x]() requires is_same {}
+  ();
+  [x]() mutable requires is_same {}
+  ();
+  [=]() requires is_same {}
+  ();
+  [=]() mutable requires is_same {}
+  ();
+  [&]() requires is_same {}
+  ();
+  [&]() mutable requires is_same {}
+  ();
+  [&x]() requires is_same {}
+  ();
+  [&x]() mutable requires is_same {}
+  ();
+
+  [x = 1]() requires is_same {} (); //expected-error {{no matching function for call to object of type}} \
+   // expected-note {{candidate function not viable}} \
+   // expected-note {{'is_same' evaluated to false}}
+  [x = 1]() mutable requires is_same {} (); // expected-error {{no matching function for call to object of type}} \
+ // expected-note {{candidate function not viable}} \
+ // expected-note {{'is_same' evaluated to false}}
+}
+
+void err() {
+  int y, z;// expected-note 2{{declared here}}
+  auto implicit_tpl = [=]( // expected-note {{variable 'y' is captured here}}
+  decltype(
+  [&] { return 0; }) y) { //expected-error{{captured variable 'y' cannot appear here}}
+return y;
+  };
+
+  auto init_tpl = [x = 1]( 

  1   2   >