[PATCH] D144703: [clangd] Avoid using CompletionItemKind.Text for macro completions

2023-02-23 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added reviewers: kadircet, hokein.
Herald added a subscriber: arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Fixes https://github.com/clangd/clangd/issues/1484


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144703

Files:
  clang-tools-extra/clangd/CodeComplete.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -627,7 +627,7 @@
 has("variable", CompletionItemKind::Variable),
 has("int", CompletionItemKind::Keyword),
 has("Struct", CompletionItemKind::Struct),
-has("MACRO", CompletionItemKind::Text),
+has("MACRO", CompletionItemKind::Variable),
 has("indexFunction", CompletionItemKind::Function),
 has("indexVariable", CompletionItemKind::Variable),
 has("indexClass", CompletionItemKind::Class)));
@@ -3789,7 +3789,7 @@
  kind(CompletionItemKind::Constructor;
   EXPECT_THAT(completions(Context + "MAC^(2)", {}, Opts).Completions,
   Contains(AllOf(labeled("MACRO(x)"), snippetSuffix(""),
- kind(CompletionItemKind::Text;
+ kind(CompletionItemKind::Function;
 }
 
 TEST(CompletionTest, NoCrashDueToMacroOrdering) {
Index: clang-tools-extra/clangd/CodeComplete.cpp
===
--- clang-tools-extra/clangd/CodeComplete.cpp
+++ clang-tools-extra/clangd/CodeComplete.cpp
@@ -150,22 +150,24 @@
   llvm_unreachable("Unhandled clang::index::SymbolKind.");
 }
 
-CompletionItemKind
-toCompletionItemKind(CodeCompletionResult::ResultKind ResKind,
- const NamedDecl *Decl,
- CodeCompletionContext::Kind CtxKind) {
-  if (Decl)
-return toCompletionItemKind(index::getSymbolInfo(Decl).Kind);
+CompletionItemKind toCompletionItemKind(const CodeCompletionResult &Res,
+CodeCompletionContext::Kind CtxKind) {
+  if (Res.Declaration)
+return toCompletionItemKind(index::getSymbolInfo(Res.Declaration).Kind);
   if (CtxKind == CodeCompletionContext::CCC_IncludedFile)
 return CompletionItemKind::File;
-  switch (ResKind) {
+  switch (Res.Kind) {
   case CodeCompletionResult::RK_Declaration:
 llvm_unreachable("RK_Declaration without Decl");
   case CodeCompletionResult::RK_Keyword:
 return CompletionItemKind::Keyword;
   case CodeCompletionResult::RK_Macro:
-return CompletionItemKind::Text; // unfortunately, there's no 'Macro'
- // completion items in LSP.
+// There is no 'Macro' kind in LSP.
+// Avoid using 'Text' to avoid confusion with client-side word-based
+// completion proposals.
+return Res.MacroDefInfo && Res.MacroDefInfo->isFunctionLike()
+   ? CompletionItemKind::Function
+   : CompletionItemKind::Variable;
   case CodeCompletionResult::RK_Pattern:
 return CompletionItemKind::Snippet;
   }
@@ -337,8 +339,7 @@
   Completion.Scope = std::string(
   splitQualifiedName(printQualifiedName(*ND)).first);
   }
-  Completion.Kind = toCompletionItemKind(
-  C.SemaResult->Kind, C.SemaResult->Declaration, ContextKind);
+  Completion.Kind = toCompletionItemKind(*C.SemaResult, ContextKind);
   // Sema could provide more info on whether the completion was a file or
   // folder.
   if (Completion.Kind == CompletionItemKind::File &&


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -627,7 +627,7 @@
 has("variable", CompletionItemKind::Variable),
 has("int", CompletionItemKind::Keyword),
 has("Struct", CompletionItemKind::Struct),
-has("MACRO", CompletionItemKind::Text),
+has("MACRO", CompletionItemKind::Variable),
 has("indexFunction", CompletionItemKind::Function),
 has("indexVariable", CompletionItemKind::Variable),
 has("indexClass", CompletionItemKind::Class)));
@@ -3789,7 +3789,7 @@
  kind(CompletionItemKind::Constructor;
   EXPECT_THAT(completions(Context + "MAC^(2)", {}, Opts).Completions,
   Contains(AllOf(labeled("MACRO(x)"), snippetSuf

[PATCH] D144696: [RISCV][NFC] Package version number information using RISCVExtensionVersion.

2023-02-23 Thread yanming via Phabricator via cfe-commits
ym1813382441 marked 2 inline comments as done.
ym1813382441 added a comment.

F26630797: Screenshot from 2023-02-24 15-54-21.png 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144696

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


[PATCH] D144696: [RISCV][NFC] Package version number information using RISCVExtensionVersion.

2023-02-23 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

You outline your full plan and why you want to do this. We need to see the 
bigger picture.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144696

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


[PATCH] D144696: [RISCV][NFC] Package version number information using RISCVExtensionVersion.

2023-02-23 Thread yanming via Phabricator via cfe-commits
ym1813382441 added a comment.

I want to use arrays to maintain the supported version number of each 
extension, this patch in using the `find` algorithm helps to simplify the code.




Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:24
+  unsigned Minor;
+  bool operator==(const RISCVExtensionVersion &Vers) const {
+return this->Major == Vers.Major && this->Minor == Vers.Minor;

eopXD wrote:
> Does the structure already work as-is?
I've tested it and it works.



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:190
+RISCVExtensionVersion Version) {
+  assert(!Exts.count(ExtName.str()) && "Extension already exists");
+  Exts[ExtName.str()] = Version;

eopXD wrote:
> Maybe handling this with a compiler error is better than an assertion error.
Currently the compiler does not allow the same extension to appear more than 
once.
If it happens something has gone wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144696

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


[PATCH] D144510: [clang-tidy] improve readability-identifier-naming hungarian options test

2023-02-23 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

@amurzeau I'm having some trouble downloading the patch, would you mind trying 
out a rebase on top of latest master? Otherwise I'll try downloading the raw 
diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144510

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


[PATCH] D144431: [clang-tidy] Fix readability-identifer-naming Hungarian CString options

2023-02-23 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG87447bedac34: [clang-tidy] Fix readability-identifer-naming 
Hungarian CString options (authored by amurzeau, committed by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144431

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -169,6 +169,10 @@
   ` check.
   Global options of the same name should be used instead.
 
+- Fixed reading `HungarianNotation.CString.*` options in
+  :doc:`readability-identifier-naming
+  ` check.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -472,7 +472,7 @@
 Buffer.append(CStr.first);
 StringRef Val = Options.get(Buffer, "");
 if (!Val.empty())
-  HNOption.CString[CStr.first] = Val.str();
+  HNOption.CString[CStr.second] = Val.str();
   }
 
   Buffer = {Section, "PrimitiveType."};


Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -169,6 +169,10 @@
   ` check.
   Global options of the same name should be used instead.
 
+- Fixed reading `HungarianNotation.CString.*` options in
+  :doc:`readability-identifier-naming
+  ` check.
+
 Removed checks
 ^^
 
Index: clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -472,7 +472,7 @@
 Buffer.append(CStr.first);
 StringRef Val = Options.get(Buffer, "");
 if (!Val.empty())
-  HNOption.CString[CStr.first] = Val.str();
+  HNOption.CString[CStr.second] = Val.str();
   }
 
   Buffer = {Section, "PrimitiveType."};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 87447be - [clang-tidy] Fix readability-identifer-naming Hungarian CString options

2023-02-23 Thread Carlos Galvez via cfe-commits

Author: Alexis Murzeau
Date: 2023-02-24T07:15:19Z
New Revision: 87447bedac341f023569f1b444f9b3b62bba5aa6

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

LOG: [clang-tidy] Fix readability-identifer-naming Hungarian CString options

When reading readability-identifier-naming.HungarianNotation.CString
options, correctly use the type string stored in CStr.second instead of
the option name (CStr.first) as the HNOption.CString map key.

This will make CString options really working and properly parsed by the
checker.

Reviewed By: carlosgalvezp

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 96bf035843577..dd9a4fa9b8e30 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -472,7 +472,7 @@ void 
IdentifierNamingCheck::HungarianNotation::loadFileConfig(
 Buffer.append(CStr.first);
 StringRef Val = Options.get(Buffer, "");
 if (!Val.empty())
-  HNOption.CString[CStr.first] = Val.str();
+  HNOption.CString[CStr.second] = Val.str();
   }
 
   Buffer = {Section, "PrimitiveType."};

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6b757656377d3..10f8e4c179777 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -169,6 +169,10 @@ Changes in existing checks
   ` check.
   Global options of the same name should be used instead.
 
+- Fixed reading `HungarianNotation.CString.*` options in
+  :doc:`readability-identifier-naming
+  ` check.
+
 Removed checks
 ^^
 



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


[clang] 255b2d8 - Add test for issue 60486

2023-02-23 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2023-02-24T14:32:05+08:00
New Revision: 255b2d8162ead0ad444698506f97484572e574b1

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

LOG: Add test for issue 60486

Close https://github.com/llvm/llvm-project/issues/60486.

When I look back at this problem again, it only appears if we specify it
with `-fmodule-file=`. And it disappears after we specify it
as `-fmodule-file==`. Since we want to depreacate
the form `-fmodule-file=`, we can think the problem goes
away.

Added: 
clang/test/Modules/pr60486.cppm

Modified: 


Removed: 




diff  --git a/clang/test/Modules/pr60486.cppm b/clang/test/Modules/pr60486.cppm
new file mode 100644
index 0..13802a4917e6e
--- /dev/null
+++ b/clang/test/Modules/pr60486.cppm
@@ -0,0 +1,28 @@
+// Address: https://github.com/llvm/llvm-project/issues/60486
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 -fmodule-file=a=%t/a.pcm %t/b.cppm -fsyntax-only 
-verify
+
+//--- foo.h
+template
+struct s {
+};
+
+template
+concept c = requires { s{}; };
+
+//--- a.cppm
+module;
+#include "foo.h"
+export module a;
+
+//--- b.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module b;
+import a;



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


[PATCH] D144074: [clangd] Hide inlay hints when using a macro as a calling argument that with a param comment

2023-02-23 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added inline comments.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:520
 auto ExprStartLoc = SM.getTopMacroCallerLoc(E->getBeginLoc());
-auto Decomposed = SM.getDecomposedLoc(ExprStartLoc);
+auto Decomposed = SM.getDecomposedExpansionLoc(ExprStartLoc);
 if (Decomposed.first != MainFileID)

I admit I struggle with this spelling/expansion loc stuff. But having spent a 
bit of time reading the implementations of these functions, would I be correct 
to say that another, perhaps easier to follow, way to express the same thing 
would be:

```
auto Decomposed = SM.getDecomposedLoc(SM.getFileLoc(E->getBeginLoc()));
```

?



Comment at: clang-tools-extra/clangd/InlayHints.cpp:521
+auto Decomposed = SM.getDecomposedExpansionLoc(ExprStartLoc);
 if (Decomposed.first != MainFileID)
   return false;

zyounan wrote:
> stupid question: I was suspicious with this check that when would 
> `Decomposed.first` not being the same as MainFileID? Should the "top-caller" 
> of the macro always be in main file? I didn't find a case that differs, 
> except when `getDecomposedLoc` provides wrong FileID.
I tried adding an assertion in this early-return branch, and it tripped in 
`ParameterHints.IncludeAtNonGlobalScope`.

The code there is:

```
  Annotations FooInc(R"cpp(
void bar() { foo(42); }
  )cpp");
  Annotations FooCC(R"cpp(
struct S {
  void foo(int param);
  #include "foo.inc"
};
  )cpp");
```

so I guess the decomposed loc there is a file loc, but not in the main file 
(but rather in `foo.inc`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144074

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


[PATCH] D144696: [RISCV][NFC] Package version number information using RISCVExtensionVersion.

2023-02-23 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added a comment.

Thank you for the patch. May you explain how this would help support 
multi-versioning?




Comment at: llvm/include/llvm/Support/RISCVISAInfo.h:24
+  unsigned Minor;
+  bool operator==(const RISCVExtensionVersion &Vers) const {
+return this->Major == Vers.Major && this->Minor == Vers.Minor;

Does the structure already work as-is?



Comment at: llvm/lib/Support/RISCVISAInfo.cpp:190
+RISCVExtensionVersion Version) {
+  assert(!Exts.count(ExtName.str()) && "Extension already exists");
+  Exts[ExtName.str()] = Version;

Maybe handling this with a compiler error is better than an assertion error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144696

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


[PATCH] D144696: [RISCV][NFC] Package version number information using RISCVExtensionVersion.

2023-02-23 Thread yanming via Phabricator via cfe-commits
ym1813382441 created this revision.
Herald added subscribers: luke, VincentWu, vkmr, frasercrmck, evandro, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, 
hiraditya, arichardson.
Herald added a project: All.
ym1813382441 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, pcwang-thead, eopXD, 
MaskRay.
Herald added projects: clang, LLVM.

This helps to support multiple version number extensions later.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144696

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/RISCVISAInfo.cpp

Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -23,11 +23,6 @@
 using namespace llvm;
 
 namespace {
-/// Represents the major and version number components of a RISC-V extension
-struct RISCVExtensionVersion {
-  unsigned Major;
-  unsigned Minor;
-};
 
 struct RISCVSupportedExtension {
   const char *Name;
@@ -190,13 +185,10 @@
   return std::nullopt;
 }
 
-void RISCVISAInfo::addExtension(StringRef ExtName, unsigned MajorVersion,
-unsigned MinorVersion) {
-  RISCVExtensionInfo Ext;
-  Ext.ExtName = ExtName.str();
-  Ext.MajorVersion = MajorVersion;
-  Ext.MinorVersion = MinorVersion;
-  Exts[ExtName.str()] = Ext;
+void RISCVISAInfo::addExtension(StringRef ExtName,
+RISCVExtensionVersion Version) {
+  assert(!Exts.count(ExtName.str()) && "Extension already exists");
+  Exts[ExtName.str()] = Version;
 }
 
 static StringRef getExtensionTypeDesc(StringRef Ext) {
@@ -247,11 +239,10 @@
  llvm::any_of(SupportedExperimentalExtensions, FindByName(Ext));
 }
 
-bool RISCVISAInfo::isSupportedExtension(StringRef Ext, unsigned MajorVersion,
-unsigned MinorVersion) {
+bool RISCVISAInfo::isSupportedExtension(StringRef Ext,
+RISCVExtensionVersion Version) {
   auto FindByNameAndVersion = [=](const RISCVSupportedExtension &ExtInfo) {
-return ExtInfo.Name == Ext && (MajorVersion == ExtInfo.Version.Major) &&
-   (MinorVersion == ExtInfo.Version.Minor);
+return ExtInfo.Name == Ext && (Version == ExtInfo.Version);
   };
   return llvm::any_of(SupportedExtensions, FindByNameAndVersion) ||
  llvm::any_of(SupportedExperimentalExtensions, FindByNameAndVersion);
@@ -381,13 +372,14 @@
 // Version number is divided into major and minor version numbers,
 // separated by a 'p'. If the minor version is 0 then 'p0' can be
 // omitted from the version string. E.g., rv32i2p0, rv32i2, rv32i2p1.
-static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major,
- unsigned &Minor, unsigned &ConsumeLength,
+static Error getExtensionVersion(StringRef Ext, StringRef In,
+ RISCVExtensionVersion &Version,
+ unsigned &ConsumeLength,
  bool EnableExperimentalExtension,
  bool ExperimentalExtensionVersionCheck) {
   StringRef MajorStr, MinorStr;
-  Major = 0;
-  Minor = 0;
+  Version.Major = 0;
+  Version.Minor = 0;
   ConsumeLength = 0;
   MajorStr = In.take_while(isDigit);
   In = In.substr(MajorStr.size());
@@ -404,12 +396,12 @@
 }
   }
 
-  if (!MajorStr.empty() && MajorStr.getAsInteger(10, Major))
+  if (!MajorStr.empty() && MajorStr.getAsInteger(10, Version.Major))
 return createStringError(
 errc::invalid_argument,
 "Failed to parse major version number for extension '" + Ext + "'");
 
-  if (!MinorStr.empty() && MinorStr.getAsInteger(10, Minor))
+  if (!MinorStr.empty() && MinorStr.getAsInteger(10, Version.Minor))
 return createStringError(
 errc::invalid_argument,
 "Failed to parse minor version number for extension '" + Ext + "'");
@@ -446,8 +438,7 @@
 }
 
 auto SupportedVers = *ExperimentalExtension;
-if (ExperimentalExtensionVersionCheck &&
-(Major != SupportedVers.Major || Minor != SupportedVers.Minor)) {
+if (ExperimentalExtensionVersionCheck && (Version != SupportedVers)) {
   std::string Error = "unsupported version number " + MajorStr.str();
   if (!MinorStr.empty())
 Error += "." + MinorStr.str();
@@ -466,15 +457,14 @@
 
   if (MajorStr.empty() && MinorStr.empty()) {
 if (auto DefaultVersion = findDefaultVersion(Ext)) {
-  Major = DefaultVersion->Major;
-  Minor = DefaultVersion->Minor;
+  Version = *DefaultVersion;
 }
 // No matter found or not, return success, assume other place will
 // verify.
 return Error::success();
   }

[PATCH] D144626: [C++20] [Modules] Trying to compare the trailing require clause of the primary template when performing ODR checking

2023-02-23 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Yeah, it looks better indeed to not store additional information.


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

https://reviews.llvm.org/D144626

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


[PATCH] D144626: [C++20] [Modules] Provide OriginalTrailingRequiresClause for serializer to perform ODR-Checking correctly

2023-02-23 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 500046.
ChuanqiXu added a comment.

Address comments:

- Don't store the original trailing require clause. Trying to get the trailing 
require clause of the primary template function when ODR checking instead.


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

https://reviews.llvm.org/D144626

Files:
  clang/lib/AST/ASTContext.cpp
  clang/test/Modules/pr60890.cppm

Index: clang/test/Modules/pr60890.cppm
===
--- /dev/null
+++ clang/test/Modules/pr60890.cppm
@@ -0,0 +1,82 @@
+// https://github.com/llvm/llvm-project/issues/60890
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/a.cppm -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/b.cppm -fprebuilt-module-path=%t -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/c.cppm -fprebuilt-module-path=%t -o %t/c.pcm
+// RUN: %clang_cc1 -std=c++20 %t/d.cpp -fprebuilt-module-path=%t -S -emit-llvm -o -
+
+//--- a.cppm
+export module a;
+ 
+export template
+struct a {
+	friend void aa(a x) requires(true) {}
+	void aaa() requires(true) {}
+};
+
+export template struct a;
+
+export template
+void foo(T) requires(true) {}
+
+export template void foo(double);
+
+export template 
+class A {
+	friend void foo<>(A);
+};
+
+//--- b.cppm
+export module b;
+
+import a;
+
+void b() {
+a _;
+	a __;
+}
+
+//--- c.cppm
+export module c;
+
+import a;
+
+struct c {
+	void f() const {
+		a _;
+		aa(_);
+		_.aaa();
+
+		a __;
+		aa(__);
+		__.aaa();
+
+		foo(5);
+		foo(3.0);
+		foo(A());
+	}
+};
+
+//--- d.cpp
+// expected-no-diagnostics
+import a;
+import b;
+import c;
+
+void d() {
+	a _;
+	aa(_);
+	_.aaa();
+
+	a __;
+	aa(__);
+	__.aaa();
+
+	foo(5);
+	foo(3.0);
+	foo(A());
+}
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -6683,8 +6683,28 @@
 return false;
 }
 
-if (!isSameConstraintExpr(FuncX->getTrailingRequiresClause(),
-  FuncY->getTrailingRequiresClause()))
+// The trailing require clause of instantiated function may change during
+// the semantic analysis. Trying to get the primary template function (if
+// exists) to compare the primary trailing require clause.
+auto TryToGetPrimaryTemplatedFunction =
+[](const FunctionDecl *FD) -> const FunctionDecl * {
+  switch (FD->getTemplatedKind()) {
+  case FunctionDecl::TK_DependentNonTemplate:
+return FD->getInstantiatedFromDecl();
+  case FunctionDecl::TK_FunctionTemplate:
+return FD->getDescribedFunctionTemplate()->getTemplatedDecl();
+  case FunctionDecl::TK_MemberSpecialization:
+return FD->getInstantiatedFromMemberFunction();
+  case FunctionDecl::TK_FunctionTemplateSpecialization:
+return FD->getPrimaryTemplate()->getTemplatedDecl();
+  default:
+return FD;
+  }
+};
+const FunctionDecl *PrimaryX = TryToGetPrimaryTemplatedFunction(FuncX);
+const FunctionDecl *PrimaryY = TryToGetPrimaryTemplatedFunction(FuncY);
+if (!isSameConstraintExpr(PrimaryX->getTrailingRequiresClause(),
+  PrimaryY->getTrailingRequiresClause()))
   return false;
 
 auto GetTypeAsWritten = [](const FunctionDecl *FD) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-23 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:19036
 
 bool Sema::tryCaptureVariable(
 ValueDecl *Var, SourceLocation ExprLoc, TryCaptureKind Kind,

We have a bunch of bugs that crash in the method and it would be good to 
rescreen those bugs after landing this to see if it fixes any of those. 



Comment at: clang/lib/Sema/SemaLambda.cpp:906
+  // C++11 [expr.prim.lambda]p5:
+  //   The closure type for a lambda-expression has a public inline function
+  //   call operator (13.5.4) whose parameters and return type are described

This has changed a bit so might be worth updating the wording here to reflect 
C++20.



Comment at: clang/lib/Sema/SemaLambda.cpp:918-920
+  QualType(), nullptr, SC_None, getCurFPFeatures().isFPConstrained(),
+  /*isInline=*/true, ConstexprSpecKind::Unspecified, SourceLocation(),
+  nullptr);

minor fix



Comment at: clang/lib/Sema/SemaLambda.cpp:1007
+  CXXRecordDecl *Class = createLambdaClosureType(
+  Intro.Range, nullptr, LambdaDependencyKind, Intro.Default);
+  LSI->Lambda = Class;





Comment at: clang/lib/Sema/SemaLambda.cpp:1010
+
+  // C++11 [expr.prim.lambda]p5:
+  //   The closure type for a lambda-expression has a public inline function

Same as comment above about updating wording to reflect C++20.



Comment at: clang/lib/Sema/SemaLambda.cpp:1258-1259
+  (getCurrentThisType().isNull() ||
+   CheckCXXThisCapture(SourceLocation(), /*Explicit*/ true,
+   /*BuildAndDiagnose*/ false)))
+Diag(Intro.DefaultLoc, diag::err_capture_default_non_local);





Comment at: clang/lib/Sema/TreeTransform.h:13255
+  CXXRecordDecl *Class = getSema().createLambdaClosureType(
+  E->getIntroducerRange(), nullptr, DependencyKind, 
E->getCaptureDefault());
   getDerived().transformedLocalDecl(OldClass, {Class});




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D142890: [clangd] Add config option for fast diagnostics mode

2023-02-23 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added subscribers: kstoimenov, vitalybuka.
vitalybuka added a comment.

One of your patches likely introduced UB 
https://lab.llvm.org/buildbot/#/builders/85/builds/14558
Can you please take a look?

FYI, @kstoimenov


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142890

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


[PATCH] D143840: [clang] Add the check of membership for the issue #58674 and improve the lookup process

2023-02-23 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht added a comment.

This has already been reverted, but I found a breakage (not a crash) caused by 
this:

  #include 
  
  class Base {
   protected:
int member;
  };
  
  template 
  struct Subclass : public Parent {
static_assert(std::is_base_of::value,
  "Parent not derived from Base");
int func() { return Base::member; }
  };
  
  using Impl = Subclass;
  
  int use() {
Impl i;
return i.func();
  }

gcc/msvc both accept this. But clang says:

  :8:29: error: 'member' is a protected member of 'Base'
int func() { return Base::member; }
  ^
  :15:12: note: in instantiation of member function 
'Subclass::func' requested here
return i.func();
 ^
  :3:7: note: must name member using the type of the current context 
'Subclass'
int member;
^

A fix is to write `Parent::member` instead of `Base::member`, but I'm wondering 
what the spec actually says about this, and if clang is right to reject it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143840

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


[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-23 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Sema/SemaConcept.cpp:537
+if (!CapturedPattern->isParameterPack()) {
+  ValueDecl *CapturedVar =
+  LambdaClass->getCapture(Instantiated)->getCapturedVar();

This is just duplicated across the `if` and `else`, please refactor it out. If 
this ever gets modified folks have to fix it in both places and that is easy to 
mess up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D144680: [Coroutines] Avoid creating conditional cleanup markers in suspend block

2023-02-23 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

BTW, what is the conclusion for the concern about sanitizers? Would change make 
sanitizers to perform false positive diagnostics?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144680

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


[PATCH] D144686: [CodeGen] Remove the template specialization of `Address` that stores alignment information into pointers

2023-02-23 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: clang/lib/CodeGen/Address.h:28
 
-// We try to save some space by using 6 bits over two PointerIntPairs to store
-// the alignment. However, some arches don't support 3 bits in a PointerIntPair
-// so we fallback to storing the alignment separately.
-template = 8> class AddressImpl {};
-
-template  class AddressImpl {
+class AddressImpl {
   llvm::PointerIntPair PointerAndKnownNonNull;

we should remove this class altogether


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144686

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


[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-23 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1301-1302
 SourceLocation AttrNameLoc = ConsumeToken();
-Attr.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr, 0,
-ParsedAttr::AS_Keyword);
+Attributes.addNew(AttrName, AttrNameLoc, nullptr, AttrNameLoc, nullptr,
+  0, ParsedAttr::AS_Keyword);
   } else if (Tok.is(tok::kw___attribute))

Minor edit



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1304
   } else if (Tok.is(tok::kw___attribute))
-ParseGNUAttributes(Attr, nullptr, &D);
+ParseGNUAttributes(Attributes, nullptr, &D);
   else





Comment at: clang/lib/Parse/ParseExprCXX.cpp:1494
 
-// Parse lambda-specifiers.
-ParseLambdaSpecifiers(LParenLoc, /*DeclEndLoc=*/T.getCloseLocation(),
-  ParamInfo, EllipsisLoc);
-
-// Parse requires-clause[opt].
-if (Tok.is(tok::kw_requires))
-  ParseTrailingRequiresClause(D);
-  } else if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
- tok::kw_constexpr, tok::kw_consteval, tok::kw_static,
- tok::kw___private, tok::kw___global, tok::kw___local,
- tok::kw___constant, tok::kw___generic,
- tok::kw_groupshared, tok::kw_requires,
- tok::kw_noexcept) ||
- (Tok.is(tok::l_square) && NextToken().is(tok::l_square))) {
-if (!getLangOpts().CPlusPlus2b)
+  if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
+  tok::kw_constexpr, tok::kw_consteval, tok::kw_static,

This `if` feels pretty messy maybe refactor into something like 
`CheckHasSpecificers`, maybe?



Comment at: clang/lib/Parse/ParseExprCXX.cpp:1381
+  SourceLocation MutableLoc;
+  LateParsedAttrList LateParsedAttrs(true);
+

cor3ntin wrote:
> aaron.ballman wrote:
> > This isn't being used?
> It used to be! Thanks for catching that
If only we had a diagnostic for that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D144680: [Coroutines] Avoid creating conditional cleanup markers in suspend block

2023-02-23 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

The test should be required here.




Comment at: clang/lib/CodeGen/CGExpr.cpp:544
   // so that it's unconditional. Don't do this with sanitizers which need
   // more precise lifetime marks.
   ConditionalEvaluation *OldConditional = nullptr;

We should add comment to explain why we add a forward path for coroutines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144680

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


[PATCH] D124351: [Clang] Implement Change scope of lambda trailing-return-type

2023-02-23 Thread Jordan Rupprecht via Phabricator via cfe-commits
rupprecht accepted this revision as: rupprecht.
rupprecht added a comment.

All the things that were broken before are no longer broken, so LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124351

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


[PATCH] D144686: [CodeGen] Remove the template specialization of `Address` that stores alignment information into pointers

2023-02-23 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

I don't have a test case for this change because there is a bug that prevents 
using the maximum allowed alignment (see 
https://github.com/llvm/llvm-project/issues/60752).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144686

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


[PATCH] D144686: [CodeGen] Remove the template specialization of `Address` that stores alignment information into pointers

2023-02-23 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak created this revision.
ahatanak added reviewers: aeubanks, efriedma, rjmccall.
ahatanak added a project: clang.
Herald added a project: All.
ahatanak requested review of this revision.

This fixes a bug introduced in https://reviews.llvm.org/D142584. The patch 
reduced the number of bits used for alignment from 6 bits to 5 bits, which made 
it impossible to encode the maximum allowed alignment in llvm (1 << 32).

This reverts b1613f05ae0ce4efc6b6475ea4459957ebcb0150 
. The 
change was made in an attempt to reduce memory consumption by storing the 
alignment information into pointers, but it turns out it doesn't make much 
difference.

https://llvm-compile-time-tracker.com/compare.php?from=998ad085e865f2e5acc589d6bee0e3379042da2e&to=5de4a1989c474f37ac03f20ccb0aef50f6e3b854&stat=max-rss


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144686

Files:
  clang/lib/CodeGen/Address.h


Index: clang/lib/CodeGen/Address.h
===
--- clang/lib/CodeGen/Address.h
+++ clang/lib/CodeGen/Address.h
@@ -25,12 +25,7 @@
 // Indicates whether a pointer is known not to be null.
 enum KnownNonNull_t { NotKnownNonNull, KnownNonNull };
 
-// We try to save some space by using 6 bits over two PointerIntPairs to store
-// the alignment. However, some arches don't support 3 bits in a PointerIntPair
-// so we fallback to storing the alignment separately.
-template = 8> class AddressImpl {};
-
-template  class AddressImpl {
+class AddressImpl {
   llvm::PointerIntPair PointerAndKnownNonNull;
   llvm::Type *ElementType;
   CharUnits Alignment;
@@ -51,45 +46,9 @@
   void setKnownNonNull() { PointerAndKnownNonNull.setInt(true); }
 };
 
-template  class AddressImpl {
-  // Int portion stores the non-null bit and the upper 2 bits of the log of the
-  // alignment.
-  llvm::PointerIntPair Pointer;
-  // Int portion stores lower 3 bits of the log of the alignment.
-  llvm::PointerIntPair ElementType;
-
-public:
-  AddressImpl(llvm::Value *Pointer, llvm::Type *ElementType,
-  CharUnits Alignment, KnownNonNull_t IsKnownNonNull)
-  : Pointer(Pointer), ElementType(ElementType) {
-if (Alignment.isZero()) {
-  this->Pointer.setInt(IsKnownNonNull << 2);
-  return;
-}
-// Currently the max supported alignment is exactly 1 << 32 and is
-// guaranteed to be a power of 2, so we can store the log of the alignment
-// into 5 bits.
-assert(Alignment.isPowerOfTwo() && "Alignment cannot be zero");
-auto AlignLog = llvm::Log2_64(Alignment.getQuantity());
-assert(AlignLog < (1 << 5) && "cannot fit alignment into 5 bits");
-this->Pointer.setInt(IsKnownNonNull << 2 | AlignLog >> 3);
-this->ElementType.setInt(AlignLog & 7);
-  }
-  llvm::Value *getPointer() const { return Pointer.getPointer(); }
-  llvm::Type *getElementType() const { return ElementType.getPointer(); }
-  CharUnits getAlignment() const {
-unsigned AlignLog = ((Pointer.getInt() & 0x3) << 3) | ElementType.getInt();
-return CharUnits::fromQuantity(CharUnits::QuantityType(1) << AlignLog);
-  }
-  KnownNonNull_t isKnownNonNull() const {
-return (KnownNonNull_t)(!!(Pointer.getInt() & 0x4));
-  }
-  void setKnownNonNull() { Pointer.setInt(Pointer.getInt() | 0x4); }
-};
-
 /// An aligned address.
 class Address {
-  AddressImpl A;
+  AddressImpl A;
 
 protected:
   Address(std::nullptr_t)


Index: clang/lib/CodeGen/Address.h
===
--- clang/lib/CodeGen/Address.h
+++ clang/lib/CodeGen/Address.h
@@ -25,12 +25,7 @@
 // Indicates whether a pointer is known not to be null.
 enum KnownNonNull_t { NotKnownNonNull, KnownNonNull };
 
-// We try to save some space by using 6 bits over two PointerIntPairs to store
-// the alignment. However, some arches don't support 3 bits in a PointerIntPair
-// so we fallback to storing the alignment separately.
-template = 8> class AddressImpl {};
-
-template  class AddressImpl {
+class AddressImpl {
   llvm::PointerIntPair PointerAndKnownNonNull;
   llvm::Type *ElementType;
   CharUnits Alignment;
@@ -51,45 +46,9 @@
   void setKnownNonNull() { PointerAndKnownNonNull.setInt(true); }
 };
 
-template  class AddressImpl {
-  // Int portion stores the non-null bit and the upper 2 bits of the log of the
-  // alignment.
-  llvm::PointerIntPair Pointer;
-  // Int portion stores lower 3 bits of the log of the alignment.
-  llvm::PointerIntPair ElementType;
-
-public:
-  AddressImpl(llvm::Value *Pointer, llvm::Type *ElementType,
-  CharUnits Alignment, KnownNonNull_t IsKnownNonNull)
-  : Pointer(Pointer), ElementType(ElementType) {
-if (Alignment.isZero()) {
-  this->Pointer.setInt(IsKnownNonNull << 2);
-  return;
-}
-// Currently the max supported alignment is exactly 1 << 32 and is
-// guaranteed to be a power of 2, so we can store the log of the alignme

[clang-tools-extra] 5a623c2 - Revert "Revert "[Tooling/Inclusion] Handle std::get symbol.""

2023-02-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-02-24T01:24:53+01:00
New Revision: 5a623c2a082d007c1cc7a878b666b3581bb8f8dc

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

LOG: Revert "Revert "[Tooling/Inclusion] Handle std::get symbol.""

This reverts commit 7c9b15fbaeb2846ad25e797d55ffe1ccef9e1379. Breakage
was in downstream code.

Added: 


Modified: 
clang-tools-extra/clangd/index/CanonicalIncludes.cpp
clang/include/clang/Tooling/Inclusions/StandardLibrary.h
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
clang/unittests/Tooling/StandardLibraryTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp 
b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
index 0c61a7bd7e929..4311eb9f481f8 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -717,7 +717,8 @@ llvm::StringRef 
CanonicalIncludes::mapSymbol(llvm::StringRef Scope,
   if (Scope == "std::" && Name == "move")
 return "";
   if (auto StdSym = tooling::stdlib::Symbol::named(Scope, Name, Lang))
-return StdSym->header().name();
+if (auto Header = StdSym->header())
+  return Header->name();
   return "";
 }
 

diff  --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h 
b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
index 9d45d84a429be..a39ceb520dcf8 100644
--- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
+++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
@@ -81,7 +81,7 @@ class Symbol {
   llvm::StringRef name() const;
   llvm::StringRef qualifiedName() const;
   // The preferred header for this symbol (e.g. the suggested insertion).
-  Header header() const;
+  std::optional header() const;
   // Some symbols may be provided by multiple headers.
   llvm::SmallVector headers() const;
 

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 416b53117d16b..cfcb955831ad2 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -14,6 +14,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
+#include 
 
 namespace clang {
 namespace tooling {
@@ -120,7 +121,8 @@ static int initialize(Lang Language) {
 }
 Mapping->SymbolNames[SymIndex] = {
 QName.data(), NSLen, static_cast(QName.size() - NSLen)};
-Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
+if (!HeaderName.empty())
+   Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
 
 NSSymbolMap &NSSymbols = AddNS(QName.take_front(NSLen));
 NSSymbols.try_emplace(QName.drop_front(NSLen), SymIndex);
@@ -205,8 +207,11 @@ std::optional Symbol::named(llvm::StringRef Scope, 
llvm::StringRef Name,
   }
   return std::nullopt;
 }
-Header Symbol::header() const {
-  return Header(getMappingPerLang(Language)->SymbolHeaderIDs[ID][0], Language);
+std::optional Symbol::header() const {
+  const auto& Headers = getMappingPerLang(Language)->SymbolHeaderIDs[ID];
+  if (Headers.empty())
+return std::nullopt;
+  return Header(Headers.front(), Language);
 }
 llvm::SmallVector Symbol::headers() const {
   llvm::SmallVector Results;

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index 3d2ea91a94d36..c9632bee1cbec 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -218,3 +218,8 @@ SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
+
+// std::get has a few variants for 
diff erent types (tuple, array, pair etc)
+// which is tricky to disambiguate without type information.
+// Don't set any header for it, as it comes with the type header.
+SYMBOL(get, std::, /*no headers*/)

diff  --git a/clang/unittests/Tooling/StandardLibraryTest.cpp 
b/clang/unittests/Tooling/StandardLibraryTest.cpp
index 47d064bdd2a92..6d90bbdf3b6eb 100644
--- a/clang/unittests/Tooling/StandardLibraryTest.cpp
+++ b/clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -58,6 +58,9 @@ TEST(StdlibTest, All) {
   EXPECT_EQ(Vector->header(), *VectorH);
   EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
 
+  EXPECT_TRUE(stdlib::Symbol::named("std::", "get"));
+  EXPECT_FALSE(stdlib::Symbol::named("std::", "get")->header());
+
   EXPECT_THAT(stdlib::Symbol::named("std::", "basic_iostream")->headers(),
   ElementsAre(stdlib::Header::named(""),
   stdlib::H

[PATCH] D144684: [clang][Driver] Pass /INFERASANLIBS:NO to link.exe under -fsanitize=address

2023-02-23 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks created this revision.
aeubanks added reviewers: hans, thakis.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

With recent MSVC releases, STL headers will add /INFERASANLIBS to the drectve 
section of object files that are compiled with clang. With this flag, link.exe 
will automatically attempt to look for asan libs.

When using clang as the driver to invoke the linker, we want to disable this 
feature because we explicitly pass the proper asan libraries, otherwise we get 
symbols defined multiple times.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144684

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/cl-link.c


Index: clang/test/Driver/cl-link.c
===
--- clang/test/Driver/cl-link.c
+++ clang/test/Driver/cl-link.c
@@ -65,3 +65,11 @@
 
 // RUN: %clang_cl /Tc%s -fuse-ld=lld -### 2>&1 | FileCheck 
--check-prefix=USE_LLD %s
 // USE_LLD: lld-link
+
+// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=link 
-### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LINK %s
+// INFER-LINK: link.exe
+// INFER-LINK: /INFERASANLIBS:NO
+
+// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld 
-### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s
+// INFER-LLD: lld-link
+// INFER-LLD-NOT: INFERASANLIBS
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -336,6 +336,11 @@
   }
 }
 
+// Clang handles passing the proper asan libs to the linker, which goes
+// against link.exe's /INFERASANLIBS which automatically finds asan libs.
+if (TC.getSanitizerArgs(Args).needsAsanRt())
+  CmdArgs.push_back("/INFERASANLIBS:NO");
+
 #ifdef _WIN32
 // When cross-compiling with VS2017 or newer, link.exe expects to have
 // its containing bin directory at the top of PATH, followed by the


Index: clang/test/Driver/cl-link.c
===
--- clang/test/Driver/cl-link.c
+++ clang/test/Driver/cl-link.c
@@ -65,3 +65,11 @@
 
 // RUN: %clang_cl /Tc%s -fuse-ld=lld -### 2>&1 | FileCheck --check-prefix=USE_LLD %s
 // USE_LLD: lld-link
+
+// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=link -### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LINK %s
+// INFER-LINK: link.exe
+// INFER-LINK: /INFERASANLIBS:NO
+
+// RUN: %clang_cl -m32 -arch:IA32 --target=i386-pc-win32 /Tc%s -fuse-ld=lld -### -fsanitize=address 2>&1 | FileCheck --check-prefix=INFER-LLD %s
+// INFER-LLD: lld-link
+// INFER-LLD-NOT: INFERASANLIBS
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -336,6 +336,11 @@
   }
 }
 
+// Clang handles passing the proper asan libs to the linker, which goes
+// against link.exe's /INFERASANLIBS which automatically finds asan libs.
+if (TC.getSanitizerArgs(Args).needsAsanRt())
+  CmdArgs.push_back("/INFERASANLIBS:NO");
+
 #ifdef _WIN32
 // When cross-compiling with VS2017 or newer, link.exe expects to have
 // its containing bin directory at the top of PATH, followed by the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D144683: [analyzer] Fix of the initialization list parsing.

2023-02-23 Thread Eänolituri Lómitaurë via Phabricator via cfe-commits
earnol created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
earnol requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  What had been done:
   - Passing a proper QualType for the initlist conversion
   - Compatibility fixes for unit tests introduced.
   - Various contingincies added to make sure the new code will be
 invoked only where it is needed.
   - New tests added to cover some cases in which new code will work
 properly. The cases where it will fail were not added
 intentionally as proper solution requires less localized
 changes.
   - Account for the case when source type info unavailable.
  
  NB: Negative test cases were not added as problem was not fully
  fixed and interlaced combinations of compound structures will
  still cause crash, like union in array or array in struct
  containing array with struct.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144683

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/lib/StaticAnalyzer/Core/RegionStore.cpp
  clang/test/Analysis/initializer-list-struct-analysis-crash.c

Index: clang/test/Analysis/initializer-list-struct-analysis-crash.c
===
--- /dev/null
+++ clang/test/Analysis/initializer-list-struct-analysis-crash.c
@@ -0,0 +1,30 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-checker=alpha.unix.cstring.OutOfBounds,alpha.unix.cstring.UninitializedRead -verify %s
+// expected-no-diagnostics
+
+
+// Just don't crash.
+
+typedef __typeof(sizeof(int)) size_t;
+void *memcpy(void *to, void const *from, size_t count);
+
+// test 1
+
+typedef struct _shortStruct {
+  short a;
+  short b;
+} shortStruct, *p_shortStruct;
+const shortStruct Info[2] = { { 0, 1, },  { 2, 3, },};
+void clang_analyzer_dump(short);
+static void xxx_shortStruct(void)
+{
+  shortStruct local_info[2];
+  memcpy(local_info, Info, sizeof(struct _shortStruct) * 2);
+}
+
+// test 2
+const short InfoArray[2][2] = { { 0, 1, },  { 2, 3, },};
+static void xxxArray(void)
+{
+  short local_info[2][2];
+  memcpy(local_info, InfoArray, sizeof(short) * 4);
+}
Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -27,6 +27,7 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
+#include "llvm/ADT/ImmutableList.h"
 #include "llvm/ADT/ImmutableMap.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -427,9 +428,9 @@
 const SubRegion *R);
   std::optional
   getConstantValFromConstArrayInitializer(RegionBindingsConstRef B,
-  const ElementRegion *R);
+  const ElementRegion *R, QualType T);
   std::optional
-  getSValFromInitListExpr(const InitListExpr *ILE,
+  getSValFromInitListExpr(const InitListExpr *ILE, QualType VarT,
   const SmallVector &ConcreteOffsets,
   QualType ElemT);
   SVal getSValFromStringLiteral(const StringLiteral *SL, uint64_t Offset,
@@ -560,7 +561,8 @@
 
   SVal getBinding(RegionBindingsConstRef B, Loc L, QualType T = QualType());
 
-  SVal getBindingForElement(RegionBindingsConstRef B, const ElementRegion *R);
+  SVal getBindingForElement(RegionBindingsConstRef B, const ElementRegion *R,
+QualType T = QualType());
 
   SVal getBindingForField(RegionBindingsConstRef B, const FieldRegion *R);
 
@@ -1476,7 +1478,7 @@
 // more intelligently.  For example, an 'element' can encompass multiple
 // bound regions (e.g., several bound bytes), or could be a subset of
 // a larger value.
-return svalBuilder.evalCast(getBindingForElement(B, ER), T, QualType{});
+return svalBuilder.evalCast(getBindingForElement(B, ER, T), T, QualType{});
   }
 
   if (const ObjCIvarRegion *IVR = dyn_cast(R)) {
@@ -1723,7 +1725,7 @@
 }
 
 std::optional RegionStoreManager::getConstantValFromConstArrayInitializer(
-RegionBindingsConstRef B, const ElementRegion *R) {
+RegionBindingsConstRef B, const ElementRegion *R, QualType targetType) {
   assert(R && "ElementRegion should not be null");
 
   // Treat an n-dimensional array.
@@ -1779,15 +1781,17 @@
 return std::nullopt;
 
   SmallVector ConcreteOffsets;
-  if (std::optional V = convertOffsetsFromSvalToUnsigneds(
-  SValOffsets, Extents, ConcreteOffsets))
+  std::optional V =
+  convertOffsetsFromSvalToUnsigneds(SValOffsets

[clang] 21631b5 - [clang] fix intendation in newly added release note

2023-02-23 Thread Alex Lorenz via cfe-commits

Author: Alex Lorenz
Date: 2023-02-23T15:53:07-08:00
New Revision: 21631b567e88b5a1146a74b0a25f7a20afef8afb

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

LOG: [clang] fix intendation in newly added release note

This fixes the llvm docs build bot.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c7204d8615a9..d7413def4d06 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -128,10 +128,10 @@ Attribute Changes in Clang
   the attributes on ``__declspec`` was ignored, while now it will be forwarded 
to the
   point where the alias is used.
 - Introduced a new ``USR`` (unified symbol resolution) clause inside of the
-existing ``__attribute__((external_source_symbol))`` attribute. Clang's indexer
-uses the optional USR value when indexing Clang's AST. This value is expected
-to be generated by an external compiler when generating C++ bindings during
-the compilation of the foreign language sources (e.g. Swift).
+  existing ``__attribute__((external_source_symbol))`` attribute. Clang's 
indexer
+  uses the optional USR value when indexing Clang's AST. This value is expected
+  to be generated by an external compiler when generating C++ bindings during
+  the compilation of the foreign language sources (e.g. Swift).
 
 Improvements to Clang's diagnostics
 ---



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


[PATCH] D144680: [Coroutines] Avoid creating conditional cleanup markers in suspend block

2023-02-23 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Thanks for working on this Wei!

Can you please add a testcase?




Comment at: clang/lib/CodeGen/CodeGenFunction.h:336
 std::unique_ptr Data;
+bool InSuspendBlock = false;
 CGCoroInfo();

Should this live inside CGCoroData instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144680

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


[clang] 7c9b15f - Revert "[Tooling/Inclusion] Handle std::get symbol."

2023-02-23 Thread Caroline Tice via cfe-commits

Author: Caroline Tice
Date: 2023-02-23T15:18:17-08:00
New Revision: 7c9b15fbaeb2846ad25e797d55ffe1ccef9e1379

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

LOG: Revert "[Tooling/Inclusion] Handle std::get symbol."

This reverts commit cbcb3eef70def3509bdffd4fe1ebfb6422afeaa2.

Causing many clangd test breakages, similar to:

error: no matching constructor for initialization of 
'llvm::SmallVector'
: llvm::SmallVector(
  ^

Added: 


Modified: 
clang-tools-extra/clangd/index/CanonicalIncludes.cpp
clang/include/clang/Tooling/Inclusions/StandardLibrary.h
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
clang/unittests/Tooling/StandardLibraryTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp 
b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
index 4311eb9f481f8..0c61a7bd7e929 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -717,8 +717,7 @@ llvm::StringRef 
CanonicalIncludes::mapSymbol(llvm::StringRef Scope,
   if (Scope == "std::" && Name == "move")
 return "";
   if (auto StdSym = tooling::stdlib::Symbol::named(Scope, Name, Lang))
-if (auto Header = StdSym->header())
-  return Header->name();
+return StdSym->header().name();
   return "";
 }
 

diff  --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h 
b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
index a39ceb520dcf8..9d45d84a429be 100644
--- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
+++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
@@ -81,7 +81,7 @@ class Symbol {
   llvm::StringRef name() const;
   llvm::StringRef qualifiedName() const;
   // The preferred header for this symbol (e.g. the suggested insertion).
-  std::optional header() const;
+  Header header() const;
   // Some symbols may be provided by multiple headers.
   llvm::SmallVector headers() const;
 

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index cfcb955831ad2..416b53117d16b 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -14,7 +14,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"
-#include 
 
 namespace clang {
 namespace tooling {
@@ -121,8 +120,7 @@ static int initialize(Lang Language) {
 }
 Mapping->SymbolNames[SymIndex] = {
 QName.data(), NSLen, static_cast(QName.size() - NSLen)};
-if (!HeaderName.empty())
-   Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
+Mapping->SymbolHeaderIDs[SymIndex].push_back(AddHeader(HeaderName));
 
 NSSymbolMap &NSSymbols = AddNS(QName.take_front(NSLen));
 NSSymbols.try_emplace(QName.drop_front(NSLen), SymIndex);
@@ -207,11 +205,8 @@ std::optional Symbol::named(llvm::StringRef Scope, 
llvm::StringRef Name,
   }
   return std::nullopt;
 }
-std::optional Symbol::header() const {
-  const auto& Headers = getMappingPerLang(Language)->SymbolHeaderIDs[ID];
-  if (Headers.empty())
-return std::nullopt;
-  return Header(Headers.front(), Language);
+Header Symbol::header() const {
+  return Header(getMappingPerLang(Language)->SymbolHeaderIDs[ID][0], Language);
 }
 llvm::SmallVector Symbol::headers() const {
   llvm::SmallVector Results;

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc 
b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
index c9632bee1cbec..3d2ea91a94d36 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StdSpecialSymbolMap.inc
@@ -218,8 +218,3 @@ SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
 SYMBOL(ssize, std::, )
-
-// std::get has a few variants for 
diff erent types (tuple, array, pair etc)
-// which is tricky to disambiguate without type information.
-// Don't set any header for it, as it comes with the type header.
-SYMBOL(get, std::, /*no headers*/)

diff  --git a/clang/unittests/Tooling/StandardLibraryTest.cpp 
b/clang/unittests/Tooling/StandardLibraryTest.cpp
index 6d90bbdf3b6eb..47d064bdd2a92 100644
--- a/clang/unittests/Tooling/StandardLibraryTest.cpp
+++ b/clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -58,9 +58,6 @@ TEST(StdlibTest, All) {
   EXPECT_EQ(Vector->header(), *VectorH);
   EXPECT_THAT(Vector->headers(), ElementsAre(*VectorH));
 
-  EXPECT_TRUE(stdlib::Symbol::named("std::", "get"));
-  EXPECT_FALSE(stdlib::Symbol::named("std::", "get")->header());
-
   EXPECT_THAT(stdlib::Symbol

[PATCH] D144620: [clang][driver] Handle '-mrelax' and '-mno-relax' for AVR

2023-02-23 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added inline comments.



Comment at: clang/lib/Driver/ToolChains/AVR.cpp:548
 
+// '-mrelax' is default unless '-mno-relax' is specified.
+if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))

MaskRay wrote:
> The comment just repeats what the code does. I think it can be dropped.
I will drop when commit it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144620

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


[clang] 9161043 - [clang][driver] Handle '-mrelax' and '-mno-relax' for AVR

2023-02-23 Thread Ben Shi via cfe-commits

Author: Ben Shi
Date: 2023-02-24T07:16:31+08:00
New Revision: 91610433907ebc335576f0da286f0c8a7793e3a9

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

LOG: [clang][driver] Handle '-mrelax' and '-mno-relax' for AVR

Reviewed By: MaskRay, aykevl

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

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Driver/avr-ld.c
clang/test/Driver/avr-toolchain.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 91d89f5441a2..92d9d2a24cfc 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -545,6 +545,9 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 // Add user specified linker script.
 Args.AddAllArgs(CmdArgs, options::OPT_T);
 
+if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
+  CmdArgs.push_back("--relax");
+
 // Specify the family name as the emulation mode to use.
 // This is almost always required because otherwise avr-ld
 // will assume 'avr2' and warn about the program being larger

diff  --git a/clang/test/Driver/avr-ld.c b/clang/test/Driver/avr-ld.c
index 9dcbf6ab42d5..03da363bfa6f 100644
--- a/clang/test/Driver/avr-ld.c
+++ b/clang/test/Driver/avr-ld.c
@@ -1,44 +1,45 @@
 // RUN: %clang -### --target=avr -mmcu=at90s2313 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKA %s
-// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" {{.*}} "--end-group" "-mavr2"
+// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" {{.*}} "--end-group" "--relax" "-mavr2"
 
-// RUN: %clang -### --target=avr -mmcu=at90s8515 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKB %s
-// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" {{.*}} "--end-group" "-mavr2"
+// RUN: %clang -### --target=avr -mmcu=at90s8515 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s -mrelax 2>&1 | FileCheck -check-prefix LINKB %s
+// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" {{.*}} "--end-group" "--relax" "-mavr2"
 
-// RUN: %clang -### --target=avr -mmcu=attiny13 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKC %s
+// RUN: %clang -### --target=avr -mmcu=attiny13 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s -mno-relax 2>&1 | FileCheck -check-prefix LINKC %s
 // LINKC: {{".*ld.*"}} {{.*}} {{"-L.*avr25/tiny-stack"}} {{.*}} 
"-Tdata=0x800060" "--start-group" {{.*}} "-lattiny13" {{.*}} "--end-group" 
"-mavr25"
+// LINLC-NOT: "--relax"
 
 // RUN: %clang -### --target=avr -mmcu=attiny44 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKD %s
-// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" {{.*}} "--end-group" "-mavr25"
+// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" {{.*}} "--end-group" "--relax" "-mavr25"
 
 // RUN: %clang -### --target=avr -mmcu=atmega103 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKE %s
-// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" {{.*}} "--end-group" "-mavr31"
+// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" {{.*}} "--end-group" "--relax" "-mavr31"
 
 // RUN: %clang -### --target=avr -mmcu=atmega8u2 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKF %s
-// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" {{.*}} "--end-group" "-mavr35"
+// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" {{.*}} "--end-group" "--relax" "-mavr35"
 
 // RUN: %clang -### --target=avr -mmcu=atmega48pa --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKG %s
-// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa" {{.*}} "--end-group" "-mavr4"
+// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa" {{.*}} "--end-group" "--relax" "-mavr4"
 
 // RUN: %clang -### --target=avr -mmcu=atmega328 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKH %s
-// LINKH: {{"

[PATCH] D144620: [clang][driver] Handle '-mrelax' and '-mno-relax' for AVR

2023-02-23 Thread Ben Shi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
benshi001 marked an inline comment as done.
Closed by commit rG91610433907e: [clang][driver] Handle '-mrelax' and 
'-mno-relax' for AVR (authored by benshi001).

Changed prior to commit:
  https://reviews.llvm.org/D144620?vs=499757&id=48#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144620

Files:
  clang/lib/Driver/ToolChains/AVR.cpp
  clang/test/Driver/avr-ld.c
  clang/test/Driver/avr-toolchain.c


Index: clang/test/Driver/avr-toolchain.c
===
--- clang/test/Driver/avr-toolchain.c
+++ clang/test/Driver/avr-toolchain.c
@@ -67,7 +67,7 @@
 // LLD-NOT: "-mavr5"
 
 // RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree 
-mmcu=atmega328 %s -T avr.lds 2>&1 | FileCheck --check-prefix=LDS0 %s
-// LDS0: "-T" "avr.lds" "-mavr5"
+// LDS0: "-T" "avr.lds" "--relax" "-mavr5"
 
 // RUN: %clang -### --target=avr --sysroot=%S/Inputs/basic_avr_tree 
-mmcu=atmega328 %s -fuse-ld=%S/Inputs/basic_avr_tree/usr/bin/ld.lld -T avr.lds 
2>&1 | FileCheck --check-prefix=LDS1 %s
 // LDS1: "-T" "avr.lds"
Index: clang/test/Driver/avr-ld.c
===
--- clang/test/Driver/avr-ld.c
+++ clang/test/Driver/avr-ld.c
@@ -1,44 +1,45 @@
 // RUN: %clang -### --target=avr -mmcu=at90s2313 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKA %s
-// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" {{.*}} "--end-group" "-mavr2"
+// LINKA: {{".*ld.*"}} {{.*}} {{"-L.*tiny-stack"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lat90s2313" {{.*}} "--end-group" "--relax" "-mavr2"
 
-// RUN: %clang -### --target=avr -mmcu=at90s8515 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKB %s
-// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" {{.*}} "--end-group" "-mavr2"
+// RUN: %clang -### --target=avr -mmcu=at90s8515 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s -mrelax 2>&1 | FileCheck -check-prefix LINKB %s
+// LINKB: {{".*ld.*"}} {{.*}} "-Tdata=0x800060" "--start-group" {{.*}} 
"-lat90s8515" {{.*}} "--end-group" "--relax" "-mavr2"
 
-// RUN: %clang -### --target=avr -mmcu=attiny13 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKC %s
+// RUN: %clang -### --target=avr -mmcu=attiny13 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s -mno-relax 2>&1 | FileCheck -check-prefix LINKC %s
 // LINKC: {{".*ld.*"}} {{.*}} {{"-L.*avr25/tiny-stack"}} {{.*}} 
"-Tdata=0x800060" "--start-group" {{.*}} "-lattiny13" {{.*}} "--end-group" 
"-mavr25"
+// LINLC-NOT: "--relax"
 
 // RUN: %clang -### --target=avr -mmcu=attiny44 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKD %s
-// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" {{.*}} "--end-group" "-mavr25"
+// LINKD: {{".*ld.*"}} {{.*}} {{"-L.*avr25"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-lattiny44" {{.*}} "--end-group" "--relax" "-mavr25"
 
 // RUN: %clang -### --target=avr -mmcu=atmega103 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKE %s
-// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" {{.*}} "--end-group" "-mavr31"
+// LINKE: {{".*ld.*"}} {{.*}} {{"-L.*avr31"}} {{.*}} "-Tdata=0x800060" 
"--start-group" {{.*}} "-latmega103" {{.*}} "--end-group" "--relax" "-mavr31"
 
 // RUN: %clang -### --target=avr -mmcu=atmega8u2 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKF %s
-// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" {{.*}} "--end-group" "-mavr35"
+// LINKF: {{".*ld.*"}} {{.*}} {{"-L.*avr35"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega8u2" {{.*}} "--end-group" "--relax" "-mavr35"
 
 // RUN: %clang -### --target=avr -mmcu=atmega48pa --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKG %s
-// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa" {{.*}} "--end-group" "-mavr4"
+// LINKG: {{".*ld.*"}} {{.*}} {{"-L.*avr4"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega48pa" {{.*}} "--end-group" "--relax" "-mavr4"
 
 // RUN: %clang -### --target=avr -mmcu=atmega328 --rtlib=libgcc --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKH %s
-// LINKH: {{".*ld.*"}} {{.*}} {{"-L.*avr5"}} {{.*}} "-Tdata=0x800100" 
"--start-group" {{.*}} "-latmega328" {{.*}} "--end-group" "-mavr5"
+// LINKH: {{".*ld.*"}} {{.*}} {{"-L.*avr5"}} {{.*}} "-Tdata=0x800100" 
"--start-group"

[clang] ab9b2fe - [Driver] Define BareMetal::HasNativeLLVMSupport to return true

2023-02-23 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-02-23T15:06:02-08:00
New Revision: ab9b2fe2a5f817f3bbca0d187a99aaae23e75d6a

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

LOG: [Driver] Define BareMetal::HasNativeLLVMSupport to return true

D33259 switched the default linker to ld.lld which supports LLVM LTO.
We can support LTO compile/link in one command and drop the
`unable to pass LLVM bit-code files to linker` error.

Fix https://github.com/llvm/llvm-project/issues/52807

Added: 


Modified: 
clang/lib/Driver/ToolChains/BareMetal.h
clang/test/Driver/native-llvm.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.h 
b/clang/lib/Driver/ToolChains/BareMetal.h
index 2a16a5beb08d7..54de97c734c19 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.h
+++ b/clang/lib/Driver/ToolChains/BareMetal.h
@@ -37,6 +37,7 @@ class LLVM_LIBRARY_VISIBILITY BareMetal : public ToolChain {
   bool useIntegratedAs() const override { return true; }
   bool isBareMetal() const override { return true; }
   bool isCrossCompiling() const override { return true; }
+  bool HasNativeLLVMSupport() const override { return true; }
   bool isPICDefault() const override { return false; }
   bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
 return false;

diff  --git a/clang/test/Driver/native-llvm.c b/clang/test/Driver/native-llvm.c
index c9543b855bc76..a1f9569317081 100644
--- a/clang/test/Driver/native-llvm.c
+++ b/clang/test/Driver/native-llvm.c
@@ -3,3 +3,5 @@
 
 // RUN: %clang -### -flto -target x86_64-unknown-unknown %s 2>&1 | FileCheck %s
 // CHECK: error: {{.*}} unable to pass LLVM bit-code files to linker
+
+// RUN: %clang -### -flto --target=arm-none-eabi %s 2>&1 | FileCheck /dev/null 
--implicit-check-not=error:



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


[PATCH] D142794: [-Wunsafe-buffer-usage] Fixits for assignment to array subscript expr

2023-02-23 Thread Ziqing Luo 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 rGcd2652963b6b: [-Wunsafe-buffer-usage] Fixits for assignments 
to array subscript expressions (authored by ziqingluo-90).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142794

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-assign-to-array-subscr-on-ptr.cpp


Index: 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-assign-to-array-subscr-on-ptr.cpp
===
--- /dev/null
+++ 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-assign-to-array-subscr-on-ptr.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+// TODO cases where we don't want fixits
+
+// The Fix-It for unsafe operation is trivially empty.
+// In order to test that our machinery recognizes that we can test if the 
variable declaration gets a Fix-It.
+// If the operation wasn't handled propertly the declaration won't get Fix-It.
+// By testing presence of the declaration Fix-It we indirectly test presence 
of the trivial Fix-It for its operations.
+void test() {
+  int *p = new int[10];
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+  p[5] = 1;
+  // CHECK-NOT: fix-it:
+}
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -129,11 +129,19 @@
 
 // Returns a matcher that matches any expression 'e' such that `innerMatcher`
 // matches 'e' and 'e' is in an Unspecified Lvalue Context.
-static internal::Matcher
-isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
-  return implicitCastExpr(hasCastKind(CastKind::CK_LValueToRValue),
-  castSubExpr(innerMatcher));
-  // FIXME: add assignmentTo context...
+static auto isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) 
{
+// clang-format off
+  return
+expr(anyOf(
+  implicitCastExpr(
+hasCastKind(CastKind::CK_LValueToRValue),
+castSubExpr(innerMatcher)),
+  binaryOperator(
+hasAnyOperatorName("="),
+hasLHS(innerMatcher)
+  )
+));
+// clang-format off
 }
 } // namespace clang::ast_matchers
 


Index: clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-assign-to-array-subscr-on-ptr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-assign-to-array-subscr-on-ptr.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+// TODO cases where we don't want fixits
+
+// The Fix-It for unsafe operation is trivially empty.
+// In order to test that our machinery recognizes that we can test if the variable declaration gets a Fix-It.
+// If the operation wasn't handled propertly the declaration won't get Fix-It.
+// By testing presence of the declaration Fix-It we indirectly test presence of the trivial Fix-It for its operations.
+void test() {
+  int *p = new int[10];
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+  p[5] = 1;
+  // CHECK-NOT: fix-it:
+}
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -129,11 +129,19 @@
 
 // Returns a matcher that matches any expression 'e' such that `innerMatcher`
 // matches 'e' and 'e' is in an Unspecified Lvalue Context.
-static internal::Matcher
-isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
-  return implicitCastExpr(hasCastKind(CastKind::CK_LValueToRValue),
-  castSubExpr(innerMatcher));
-  // FIXME: add assignmentTo context...
+static auto isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
+// clang-format off
+  return
+expr(anyOf(
+  implicitCastExpr(
+hasCastKind(CastKind::CK_LValueToRValue),
+castSubExpr(innerMatcher)),
+  binaryOperator(
+hasAnyOperatorName("="),
+hasLHS(innerMatcher)
+  )
+));
+// clang-format off
 }
 } // namespace clang::ast_matchers
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/ma

[clang] cd26529 - [-Wunsafe-buffer-usage] Fixits for assignments to array subscript expressions

2023-02-23 Thread Ziqing Luo via cfe-commits

Author: Ziqing Luo
Date: 2023-02-23T15:02:46-08:00
New Revision: cd2652963b6b97c01329419f15c336e5560afa98

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

LOG: [-Wunsafe-buffer-usage] Fixits for assignments to array subscript 
expressions

Let generate fix-its to make assignments' left-hand side of the form
`dre[e]` safe if `e` is known to be non-negative.

Commit on behalf of jkorous (Jan Korous)

Reviewed by: NoQ (Artem Dergachev)

Differential revision: https://reviews.llvm.org/D142794

Added: 

clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-assign-to-array-subscr-on-ptr.cpp

Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index bfae5a6ea3351..d9602a41af787 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -129,11 +129,19 @@ AST_MATCHER_P(CastExpr, castSubExpr, 
internal::Matcher, innerMatcher) {
 
 // Returns a matcher that matches any expression 'e' such that `innerMatcher`
 // matches 'e' and 'e' is in an Unspecified Lvalue Context.
-static internal::Matcher
-isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) {
-  return implicitCastExpr(hasCastKind(CastKind::CK_LValueToRValue),
-  castSubExpr(innerMatcher));
-  // FIXME: add assignmentTo context...
+static auto isInUnspecifiedLvalueContext(internal::Matcher innerMatcher) 
{
+// clang-format off
+  return
+expr(anyOf(
+  implicitCastExpr(
+hasCastKind(CastKind::CK_LValueToRValue),
+castSubExpr(innerMatcher)),
+  binaryOperator(
+hasAnyOperatorName("="),
+hasLHS(innerMatcher)
+  )
+));
+// clang-format off
 }
 } // namespace clang::ast_matchers
 

diff  --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-assign-to-array-subscr-on-ptr.cpp
 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-assign-to-array-subscr-on-ptr.cpp
new file mode 100644
index 0..ba3b5bc22d543
--- /dev/null
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-assign-to-array-subscr-on-ptr.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+// TODO cases where we don't want fixits
+
+// The Fix-It for unsafe operation is trivially empty.
+// In order to test that our machinery recognizes that we can test if the 
variable declaration gets a Fix-It.
+// If the operation wasn't handled propertly the declaration won't get Fix-It.
+// By testing presence of the declaration Fix-It we indirectly test presence 
of the trivial Fix-It for its operations.
+void test() {
+  int *p = new int[10];
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:11}:"std::span p"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:12-[[@LINE-2]]:12}:"{"
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:23-[[@LINE-3]]:23}:", 10}"
+  p[5] = 1;
+  // CHECK-NOT: fix-it:
+}



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


[PATCH] D144680: [Coroutines] Avoid creating conditional cleanup markers in suspend block

2023-02-23 Thread Wei Wang via Phabricator via cfe-commits
weiwang created this revision.
Herald added subscribers: ChuanqiXu, hoy, wenlei.
Herald added a project: All.
weiwang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144680

Files:
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenFunction.h


Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -333,6 +333,7 @@
   // in this header.
   struct CGCoroInfo {
 std::unique_ptr Data;
+bool InSuspendBlock = false;
 CGCoroInfo();
 ~CGCoroInfo();
   };
@@ -342,6 +343,10 @@
 return CurCoro.Data != nullptr;
   }
 
+  bool inSuspendBlock() const {
+return isCoroutine() && CurCoro.InSuspendBlock;
+  }
+
   /// CurGD - The GlobalDecl for the current function being compiled.
   GlobalDecl CurGD;
 
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -545,9 +545,10 @@
   ConditionalEvaluation *OldConditional = nullptr;
   CGBuilderTy::InsertPoint OldIP;
   if (isInConditionalBranch() && !E->getType().isDestructedType() &&
-  !SanOpts.has(SanitizerKind::HWAddress) &&
-  !SanOpts.has(SanitizerKind::Memory) &&
-  !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
+  ((!SanOpts.has(SanitizerKind::HWAddress) &&
+!SanOpts.has(SanitizerKind::Memory) &&
+!CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) ||
+   inSuspendBlock())) {
 OldConditional = OutermostConditional;
 OutermostConditional = nullptr;
 
Index: clang/lib/CodeGen/CGCoroutine.cpp
===
--- clang/lib/CodeGen/CGCoroutine.cpp
+++ clang/lib/CodeGen/CGCoroutine.cpp
@@ -198,7 +198,9 @@
   auto *NullPtr = llvm::ConstantPointerNull::get(CGF.CGM.Int8PtrTy);
   auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});
 
+  CGF.CurCoro.InSuspendBlock = true;
   auto *SuspendRet = CGF.EmitScalarExpr(S.getSuspendExpr());
+  CGF.CurCoro.InSuspendBlock = false;
   if (SuspendRet != nullptr && SuspendRet->getType()->isIntegerTy(1)) {
 // Veto suspension if requested by bool returning await_suspend.
 BasicBlock *RealSuspendBlock =


Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -333,6 +333,7 @@
   // in this header.
   struct CGCoroInfo {
 std::unique_ptr Data;
+bool InSuspendBlock = false;
 CGCoroInfo();
 ~CGCoroInfo();
   };
@@ -342,6 +343,10 @@
 return CurCoro.Data != nullptr;
   }
 
+  bool inSuspendBlock() const {
+return isCoroutine() && CurCoro.InSuspendBlock;
+  }
+
   /// CurGD - The GlobalDecl for the current function being compiled.
   GlobalDecl CurGD;
 
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -545,9 +545,10 @@
   ConditionalEvaluation *OldConditional = nullptr;
   CGBuilderTy::InsertPoint OldIP;
   if (isInConditionalBranch() && !E->getType().isDestructedType() &&
-  !SanOpts.has(SanitizerKind::HWAddress) &&
-  !SanOpts.has(SanitizerKind::Memory) &&
-  !CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) {
+  ((!SanOpts.has(SanitizerKind::HWAddress) &&
+!SanOpts.has(SanitizerKind::Memory) &&
+!CGM.getCodeGenOpts().SanitizeAddressUseAfterScope) ||
+   inSuspendBlock())) {
 OldConditional = OutermostConditional;
 OutermostConditional = nullptr;
 
Index: clang/lib/CodeGen/CGCoroutine.cpp
===
--- clang/lib/CodeGen/CGCoroutine.cpp
+++ clang/lib/CodeGen/CGCoroutine.cpp
@@ -198,7 +198,9 @@
   auto *NullPtr = llvm::ConstantPointerNull::get(CGF.CGM.Int8PtrTy);
   auto *SaveCall = Builder.CreateCall(CoroSave, {NullPtr});
 
+  CGF.CurCoro.InSuspendBlock = true;
   auto *SuspendRet = CGF.EmitScalarExpr(S.getSuspendExpr());
+  CGF.CurCoro.InSuspendBlock = false;
   if (SuspendRet != nullptr && SuspendRet->getType()->isIntegerTy(1)) {
 // Veto suspension if requested by bool returning await_suspend.
 BasicBlock *RealSuspendBlock =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141324: [clang] extend external_source_symbol attribute with the USR clause

2023-02-23 Thread Alex Lorenz 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 rGc8b37e48f6f0: [clang] extend external_source_symbol 
attribute with USR clause (authored by arphaman).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D141324?vs=495202&id=41#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141324

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Parse/Parser.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/AST/ast-dump-attr.cpp
  clang/test/Index/Core/external-source-symbol-attr-cxx.cpp
  clang/test/Index/Core/external-source-symbol-attr.m
  clang/test/Parser/attr-external-source-symbol.m
  clang/test/Sema/attr-external-source-symbol-cxx.cpp
  clang/test/Sema/attr-external-source-symbol.c
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -51,14 +51,18 @@
 class FlattenedSpelling {
   std::string V, N, NS;
   bool K = false;
+  const Record &OriginalSpelling;
 
 public:
   FlattenedSpelling(const std::string &Variety, const std::string &Name,
-const std::string &Namespace, bool KnownToGCC) :
-V(Variety), N(Name), NS(Namespace), K(KnownToGCC) {}
+const std::string &Namespace, bool KnownToGCC,
+const Record &OriginalSpelling)
+  : V(Variety), N(Name), NS(Namespace), K(KnownToGCC),
+OriginalSpelling(OriginalSpelling) {}
   explicit FlattenedSpelling(const Record &Spelling)
   : V(std::string(Spelling.getValueAsString("Variety"))),
-N(std::string(Spelling.getValueAsString("Name"))) {
+N(std::string(Spelling.getValueAsString("Name"))),
+OriginalSpelling(Spelling) {
 assert(V != "GCC" && V != "Clang" &&
"Given a GCC spelling, which means this hasn't been flattened!");
 if (V == "CXX11" || V == "C2x" || V == "Pragma")
@@ -69,6 +73,7 @@
   const std::string &name() const { return N; }
   const std::string &nameSpace() const { return NS; }
   bool knownToGCC() const { return K; }
+  const Record &getSpellingRecord() const { return OriginalSpelling; }
 };
 
 } // end anonymous namespace
@@ -82,15 +87,15 @@
 StringRef Variety = Spelling->getValueAsString("Variety");
 StringRef Name = Spelling->getValueAsString("Name");
 if (Variety == "GCC") {
-  Ret.emplace_back("GNU", std::string(Name), "", true);
-  Ret.emplace_back("CXX11", std::string(Name), "gnu", true);
+  Ret.emplace_back("GNU", std::string(Name), "", true, *Spelling);
+  Ret.emplace_back("CXX11", std::string(Name), "gnu", true, *Spelling);
   if (Spelling->getValueAsBit("AllowInC"))
-Ret.emplace_back("C2x", std::string(Name), "gnu", true);
+Ret.emplace_back("C2x", std::string(Name), "gnu", true, *Spelling);
 } else if (Variety == "Clang") {
-  Ret.emplace_back("GNU", std::string(Name), "", false);
-  Ret.emplace_back("CXX11", std::string(Name), "clang", false);
+  Ret.emplace_back("GNU", std::string(Name), "", false, *Spelling);
+  Ret.emplace_back("CXX11", std::string(Name), "clang", false, *Spelling);
   if (Spelling->getValueAsBit("AllowInC"))
-Ret.emplace_back("C2x", std::string(Name), "clang", false);
+Ret.emplace_back("C2x", std::string(Name), "clang", false, *Spelling);
 } else
   Ret.push_back(FlattenedSpelling(*Spelling));
   }
@@ -3309,18 +3314,31 @@
 // C2x-style attributes have the same kind of version information
 // associated with them. The unscoped attribute version information should
 // be taken from the specification of the attribute in the C Standard.
+//
+// Clang-specific attributes have the same kind of version information
+// associated with them. This version is typically the default value (1).
+// These version values are clang-specific and should typically be
+// incremented once the attribute changes its syntax and/or semantics in a
+// a way that is impactful to the end user.
 int Version = 1;
 
-if (Variety == "CXX11" || Variety == "C2x") {
-  std::vector Spellings = Attr->getValueAsListOfDefs("Spellings");
-  for (const auto &Spelling : Spellings) {
-if (Spelling->getValueAsString("Variety") == Variety) {
-  Version = static_cast(Spelling->getValueAsInt("Version"));
-  if (Scope.empty() && Version == 1)
-PrintError(Spelling->getLoc(), 

[clang] c8b37e4 - [clang] extend external_source_symbol attribute with USR clause

2023-02-23 Thread Alex Lorenz via cfe-commits

Author: Alex Lorenz
Date: 2023-02-23T14:59:26-08:00
New Revision: c8b37e48f6f00bb2aa3882ca3cc26082f85ca999

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

LOG: [clang] extend external_source_symbol attribute with USR clause

Allow the user to specify a concrete USR in the external_source_symbol 
attribute.
That will let Clang's indexer to use Swift USRs for Swift declarations that are
represented with C++ declarations.

This new clause is used by Swift when generating a C++ header representation
of a Swift module:
https://github.com/apple/swift/pull/63002

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

Added: 
clang/test/Index/Core/external-source-symbol-attr-cxx.cpp
clang/test/Sema/attr-external-source-symbol-cxx.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Parse/Parser.h
clang/lib/Index/USRGeneration.cpp
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/Parser.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/AST/ast-dump-attr.cpp
clang/test/Index/Core/external-source-symbol-attr.m
clang/test/Parser/attr-external-source-symbol.m
clang/test/Sema/attr-external-source-symbol.c
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2a636ebb00f79..c7204d8615a90 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -127,6 +127,11 @@ Attribute Changes in Clang
 - ``__declspec`` attributes can now be used together with the using keyword. 
Before
   the attributes on ``__declspec`` was ignored, while now it will be forwarded 
to the
   point where the alias is used.
+- Introduced a new ``USR`` (unified symbol resolution) clause inside of the
+existing ``__attribute__((external_source_symbol))`` attribute. Clang's indexer
+uses the optional USR value when indexing Clang's AST. This value is expected
+to be generated by an external compiler when generating C++ bindings during
+the compilation of the foreign language sources (e.g. Swift).
 
 Improvements to Clang's diagnostics
 ---

diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index fc2c7f7e37f45..8858bb6bec850 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -287,23 +287,22 @@ class VariadicEnumArgument values,
 }
 
 // This handles one spelling of an attribute.
-class Spelling {
+class Spelling {
   string Name = name;
   string Variety = variety;
+  int Version = version;
 }
 
 class GNU : Spelling;
 class Declspec : Spelling;
 class Microsoft : Spelling;
 class CXX11
-: Spelling {
+: Spelling {
   string Namespace = namespace;
-  int Version = version;
 }
 class C2x
-: Spelling {
+: Spelling {
   string Namespace = namespace;
-  int Version = version;
 }
 
 class Keyword : Spelling;
@@ -321,7 +320,8 @@ class GCC : Spelling {
 // The Clang spelling implies GNU, CXX11<"clang", name>, and optionally,
 // C2x<"clang", name>. This spelling should be used for any Clang-specific
 // attributes.
-class Clang : Spelling {
+class Clang
+: Spelling {
   bit AllowInC = allowInC;
 }
 
@@ -958,10 +958,12 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
 }
 
 def ExternalSourceSymbol : InheritableAttr {
-  let Spellings = [Clang<"external_source_symbol">];
+  let Spellings = [Clang<"external_source_symbol", /*allowInC=*/1,
+   /*version=*/20230206>];
   let Args = [StringArgument<"language", 1>,
   StringArgument<"definedIn", 1>,
-  BoolArgument<"generatedDeclaration", 1>];
+  BoolArgument<"generatedDeclaration", 1>,
+  StringArgument<"USR", 1>];
   let HasCustomParsing = 1;
   let Subjects = SubjectList<[Named]>;
   let Documentation = [ExternalSourceSymbolDocs];

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index eebbf6863dd43..cbf28688a7408 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1750,6 +1750,19 @@ defined_in=\ *string-literal*
   source containers are modules, so ``defined_in`` should specify the Swift
   module name.
 
+USR=\ *string-literal*
+  String that specifies a unified symbol resolution (USR) value for this
+  declaration. USR string uniquely identifies this particular declaration, and
+  is typically used when constructing an index of a codebase.
+  The USR value in this attribute is expected to be generated by an external
+  compiler that compiled the

[PATCH] D135495: [clang-tidy] handle exceptions properly in `ExceptionAnalyzer`

2023-02-23 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs updated this revision to Diff 40.
isuckatcs added a comment.

fixed failing test


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

https://reviews.llvm.org/D135495

Files:
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -101,6 +101,126 @@
   }
 }
 
+void throw_catch_pointer_c() noexcept {
+  try {
+int a = 1;
+throw &a;
+  } catch(const int *) {}
+}
+
+void throw_catch_pointer_v() noexcept {
+  try {
+int a = 1;
+throw &a;
+  } catch(volatile int *) {}
+}
+
+void throw_catch_pointer_cv() noexcept {
+  try {
+int a = 1;
+throw &a;
+  } catch(const volatile int *) {}
+}
+
+void throw_catch_multi_ptr_1() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_multi_ptr_1' which should not throw exceptions
+  try {
+char **p = 0;
+throw p;
+  } catch (const char **) {
+  }
+}
+
+void throw_catch_multi_ptr_2() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (const char *const *) {
+  }
+}
+
+void throw_catch_multi_ptr_3() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (volatile char *const *) {
+  }
+}
+
+void throw_catch_multi_ptr_4() noexcept {
+  try {
+char **p = 0;
+throw p;
+  } catch (volatile const char *const *) {
+  }
+}
+
+// FIXME: In this case 'a' is convertible to the handler and should be caught
+// but in reality it's thrown. Note that clang doesn't report a warning for 
+// this either.
+void throw_catch_multi_ptr_5() noexcept {
+  try {
+double *a[2][3];
+throw a;
+  } catch (double *(*)[3]) {
+  }
+}
+
+
+void throw_c_catch_pointer() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_c_catch_pointer' which should not throw exceptions
+  try {
+int a = 1;
+const int *p = &a;
+throw p;
+  } catch(int *) {}
+}
+
+void throw_c_catch_pointer_v() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_c_catch_pointer_v' which should not throw exceptions
+  try {
+int a = 1;
+const int *p = &a;
+throw p;
+  } catch(volatile int *) {}
+}
+
+void throw_v_catch_pointer() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_v_catch_pointer' which should not throw exceptions
+  try {
+int a = 1;
+volatile int *p = &a;
+throw p;
+  } catch(int *) {}
+}
+
+void throw_v_catch_pointer_c() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_v_catch_pointer_c' which should not throw exceptions
+  try {
+int a = 1;
+volatile int *p = &a;
+throw p;
+  } catch(const int *) {}
+}
+
+void throw_cv_catch_pointer_c() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_cv_catch_pointer_c' which should not throw exceptions
+  try {
+int a = 1;
+const volatile int *p = &a;
+throw p;
+  } catch(const int *) {}
+}
+
+void throw_cv_catch_pointer_v() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_cv_catch_pointer_v' which should not throw exceptions
+  try {
+int a = 1;
+const volatile int *p = &a;
+throw p;
+  } catch(volatile int *) {}
+}
+
 class base {};
 class derived: public base {};
 
@@ -112,6 +232,229 @@
   }
 }
 
+void throw_derived_alias_catch_base() noexcept {
+  using alias = derived;
+
+  try {
+throw alias();
+  } catch(base &) {
+  }
+}
+
+void throw_derived_catch_base_alias() noexcept {
+  using alias = base;
+
+  try {
+throw derived();
+  } catch(alias &) {
+  }
+}
+
+void throw_derived_catch_base_ptr_c() noexcept {
+  try {
+derived d;
+throw &d; 
+  } catch(const base *) {
+  }
+}
+
+void throw_derived_catch_base_ptr() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_derived_catch_base_ptr' which should not throw exceptions
+  try {
+derived d;
+const derived *p = &d;
+throw p; 
+  } catch(base *) {
+  }
+}
+
+class A {};
+class B : A {};
+
+// The following alias hell is deliberately created for testing.
+using aliasedA = A;
+class C : protected aliasedA {};
+
+typedef aliasedA moreAliasedA;
+class D : public moreAliasedA {};
+
+using moreMoreAliasedA = moreAliasedA;
+using aliasedD = D;
+class E : public moreMoreAliasedA, public aliasedD {};
+
+void throw_derived_catch_base_private() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warni

[PATCH] D144136: Add a "remark" to report on array accesses

2023-02-23 Thread Kees Cook via Phabricator via cfe-commits
kees added a comment.

This gets me all 6 reports. The details about the array and the index don't 
really matter for the basic metrics:

  diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/Diagnostic
  SemaKinds.td
  index ba831c026342..29d2167b504b 100644
  --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
  +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
  @@ -9451,7 +9451,7 @@ def note_array_declared_here : Note<
   
 "array %0 declared here">;

   def remark_array_access : Remark<
  -  "accessing %select{fixed|dynamic}0 sized array %1 by %2">,
  +  "accessing %select{fixed|unknown|dynamic}0 sized array %1 by %2">,
 InGroup;   
  

   def warn_inconsistent_array_form : Warning<
  diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
  index 9ced29a5f5d0..1c6aa7f05c7f 100644   
  --- a/clang/lib/Sema/SemaChecking.cpp 
  
  +++ b/clang/lib/Sema/SemaChecking.cpp
  @@ -16207,8 +16207,26 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, 
const Expr *IndexExpr,   
   return;  

 Expr::EvalResult Result;
  -  if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))
  +  if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects)) 
{
  +SmallString<128> sizeString;
  +llvm::raw_svector_ostream OS(sizeString);
  +
  +OS << "'";
  +IndexExpr->printPretty(OS, nullptr, getPrintingPolicy());
  +OS << "'";
  +
  +if (!IsUnboundedArray) {
  +  Context.getDiagnostics().Report(
  +  BaseExpr->getBeginLoc(), diag::remark_array_access)
  +  << 0 << ArrayTy->desugar() << OS.str();
  +} else {
  +  Context.getDiagnostics().Report(
  +  BaseExpr->getBeginLoc(), diag::remark_array_access)
  +  << 1 << "something" << OS.str();
  +}
  +
   return;
  +  }

 llvm::APSInt index = Result.Val.getInt();
 if (IndexNegated) {
  @@ -16219,6 +16237,11 @@ void Sema::CheckArrayAccess(const Expr *BaseExpr, 
const Expr *IndexExpr,
 if (IsUnboundedArray) {
   if (EffectiveType->isFunctionType())
 return;
  +
  +Context.getDiagnostics().Report(
  +BaseExpr->getBeginLoc(), diag::remark_array_access)
  +<< 1 << "something" << "whatever";
  +
   if (index.isUnsigned() || !index.isNegative()) {
 const auto &ASTC = getASTContext();
 unsigned AddrBits = ASTC.getTargetInfo().getPointerWidth(

Using "desugar" on a flexible array appears to blow up. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144136

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


[PATCH] D143697: [-Wunsafe-buffer-usage] Create Fix-Its only if they are emitted

2023-02-23 Thread Ziqing Luo 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 rGf78c34346635: [-Wunsafe-buffer-usage] Create Fix-Its only if 
they are emitted (authored by ziqingluo-90).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143697

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Sema/AnalysisBasedWarnings.cpp


Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2518,7 +2518,8 @@
 UnsafeBufferUsageReporter R(S);
 checkUnsafeBufferUsage(
 D, R,
-/*EmitFixits=*/S.getLangOpts().CPlusPlus20);
+/*EmitFixits=*/S.getDiagnostics().getDiagnosticOptions().ShowFixits &&
+S.getLangOpts().CPlusPlus20);
   }
 
   // If none of the previous checks caused a CFG build, trigger one here
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1017,8 +1017,6 @@
   DeclUseTracker Tracker;
 
   {
-// FIXME: We could skip even matching Fixables' matchers if EmitFixits ==
-// false.
 auto [FixableGadgets, WarningGadgets, TrackerRes] = findGadgets(D, 
Handler);
 UnsafeOps = groupWarningGadgetsByVar(std::move(WarningGadgets));
 FixablesForUnsafeVars = groupFixablesByVar(std::move(FixableGadgets));


Index: clang/lib/Sema/AnalysisBasedWarnings.cpp
===
--- clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2518,7 +2518,8 @@
 UnsafeBufferUsageReporter R(S);
 checkUnsafeBufferUsage(
 D, R,
-/*EmitFixits=*/S.getLangOpts().CPlusPlus20);
+/*EmitFixits=*/S.getDiagnostics().getDiagnosticOptions().ShowFixits &&
+S.getLangOpts().CPlusPlus20);
   }
 
   // If none of the previous checks caused a CFG build, trigger one here
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1017,8 +1017,6 @@
   DeclUseTracker Tracker;
 
   {
-// FIXME: We could skip even matching Fixables' matchers if EmitFixits ==
-// false.
 auto [FixableGadgets, WarningGadgets, TrackerRes] = findGadgets(D, Handler);
 UnsafeOps = groupWarningGadgetsByVar(std::move(WarningGadgets));
 FixablesForUnsafeVars = groupFixablesByVar(std::move(FixableGadgets));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f78c343 - [-Wunsafe-buffer-usage] Create Fix-Its only if they are emitted

2023-02-23 Thread Ziqing Luo via cfe-commits

Author: Ziqing Luo
Date: 2023-02-23T14:47:43-08:00
New Revision: f78c34346635e25919e2777b1b1cbb9627d5ad43

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

LOG: [-Wunsafe-buffer-usage] Create Fix-Its only if they are emitted

`-Wunsafe-buffer-usage` diagnostics shall not emit fix-its if fix-its
are globally disabled.

Commit on behalf of jkorous (Jan Korous)

Reviewed by: NoQ (Artem Dergachev)

Differential revision: https://reviews.llvm.org/D143697

Added: 


Modified: 
clang/lib/Analysis/UnsafeBufferUsage.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp

Removed: 




diff  --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 61c2c4e4b52ad..bfae5a6ea3351 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1017,8 +1017,6 @@ void clang::checkUnsafeBufferUsage(const Decl *D,
   DeclUseTracker Tracker;
 
   {
-// FIXME: We could skip even matching Fixables' matchers if EmitFixits ==
-// false.
 auto [FixableGadgets, WarningGadgets, TrackerRes] = findGadgets(D, 
Handler);
 UnsafeOps = groupWarningGadgetsByVar(std::move(WarningGadgets));
 FixablesForUnsafeVars = groupFixablesByVar(std::move(FixableGadgets));

diff  --git a/clang/lib/Sema/AnalysisBasedWarnings.cpp 
b/clang/lib/Sema/AnalysisBasedWarnings.cpp
index 85dc3a7eb9507..07e17f9f71072 100644
--- a/clang/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/clang/lib/Sema/AnalysisBasedWarnings.cpp
@@ -2518,7 +2518,8 @@ void clang::sema::AnalysisBasedWarnings::IssueWarnings(
 UnsafeBufferUsageReporter R(S);
 checkUnsafeBufferUsage(
 D, R,
-/*EmitFixits=*/S.getLangOpts().CPlusPlus20);
+/*EmitFixits=*/S.getDiagnostics().getDiagnosticOptions().ShowFixits &&
+S.getLangOpts().CPlusPlus20);
   }
 
   // If none of the previous checks caused a CFG build, trigger one here



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


[PATCH] D144269: [Analyzer] Show "taint originated here" note of alpha.security.taint.TaintPropagation checker at the correct place

2023-02-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Yeah looks like I replied without properly reading the patch.

`TaintBugReport` is brilliant and we already have a precedent for subclassing 
`BugReport` in another checker. However I'm somewhat worried that once we start 
doing more of this, we'll eventually end up with multiple inheritance 
situations when the report needs multiple kinds of information. So at a glance 
my approach with a "generic data map" in bugreport objects looks a bit more 
future-proof to me. Also a bit easier to set up, no need to deal with custom 
RTTI.

So I think interestingness is just an example of such "generic data" attached 
to bug report. Interestingness is also somewhat confusing, because indeed, 
there are existing interesting rules, and I don't think anybody remembers what 
they are or what was even the purpose of having interestingness in the first 
place. Interestingness is currently used for tracking symbols with 
`trackExpressionValue()`, and we have those tracking kinds added by @Szelethus 
to make tracking behave slightly differently. So, yeah, I think interestingness 
shouldn't be used; it's already in use. I think it should be generalized upon 
i.e. just let checkers track whatever/however they want.

I guess my main point is, there shouldn't be a need to assist tracking by 
adding extra information to the program state. Information in the state should 
ideally be "material" to program execution, "tangible", it has to describe 
something that's actually stored somewhere in memory (either by directly 
defining it, or by constraining it). In particular, if two nodes result in 
indistinguishable future behavior of the program, we're supposed to merge them; 
but any "immaterial" bits of information in the state will prevent that from 
happening.

In our case it should be enough to have the lambda for propagation method ask 
"Hey, is this freshly produced propagation target value relevant to this 
specific report?" and if yes, mark the corresponding propagation source value 
as relevant to the report as well; also emit a note and "consume" the mark on 
the target value. Such chain of local decisions can easily replace the global 
taint flow identifier, and it's more flexible because this way the flow doesn't 
need to be "linear", it may branch in various ways and that's ok.


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

https://reviews.llvm.org/D144269

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


[PATCH] D144431: [clang-tidy] Fix readability-identifer-naming Hungarian CString options

2023-02-23 Thread Alexis Murzeau via Phabricator via cfe-commits
amurzeau added a comment.

In D144431#4146524 , @carlosgalvezp 
wrote:

> Alright, sounds good, thanks for the clarification! Then I misunderstood the 
> change in the tests and indeed it belonged together in this patch, sorry for 
> the confusion. I have approved both patches so we can land them now. Can you 
> land the patch or would you like me to do it for you? If so please provide 
> name and email (same as your Github account) for attribution.

No worries, yes please land the patches for me as `Alexis Murzeau 
` (phabricator mail and handle is the same as github).
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144431

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


[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-02-23 Thread Stephen Peckham via Phabricator via cfe-commits
stephenpeckham accepted this revision.
stephenpeckham added a comment.
This revision is now accepted and ready to land.

I don't have issues with this code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

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


[PATCH] D143587: [Docs] Multilib design

2023-02-23 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 499963.
michaelplatings added a comment.

PrintArgs -> PrintOptions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143587

Files:
  clang/docs/Multilib.rst
  clang/docs/index.rst

Index: clang/docs/index.rst
===
--- clang/docs/index.rst
+++ clang/docs/index.rst
@@ -100,6 +100,7 @@
CodeOwners
InternalsManual
DriverInternals
+   Multilib
OffloadingDesign
PCHInternals
ItaniumMangleAbiTags
Index: clang/docs/Multilib.rst
===
--- /dev/null
+++ clang/docs/Multilib.rst
@@ -0,0 +1,327 @@
+
+Multilib
+
+
+Introduction
+
+
+This document describes how multilib is implemented in Clang.
+
+What is multilib and why might you care?
+If you're :doc:`cross compiling` then you can't use native
+system headers and libraries. To address this, you can use a combination of
+``--sysroot``, ``-isystem`` and ``-L`` options to point Clang at suitable
+directories for your target.
+However, when there are many possible directories to choose from, it's not
+necessarily obvious which one to pick.
+Multilib allows a toolchain designer to imbue the toolchain with the ability to
+pick a suitable directory automatically, based on the options the user provides
+to Clang. For example, if the user specifies
+``--target=arm-none-eabi -mcpu=cortex-m4`` the toolchain can choose a directory
+containing headers and libraries suitable for Armv7E-M, because it knows that's
+a suitable architecture for Arm Cortex-M4.
+Multilib can also choose between libraries for the same architecture based on
+other options. For example if the user specifies ``-fno-exceptions`` then a
+toolchain could select libraries built without exception support, thereby
+reducing the size of the resulting binary.
+
+Design
+==
+
+Clang supports GCC's ``-print-multi-lib`` and ``-print-multi-directory``
+options. These are described in
+`GCC Developer Options `_.
+
+There are two ways to configure multilib in Clang: hard-coded or via a
+configuration file.
+
+Hard-coded Multilib
+===
+
+The available libraries can be hard-coded in Clang. Typically this is done
+using the ``MultilibBuilder`` interface in
+``clang/include/clang/Driver/MultilibBuilder.h``.
+There are many examples of this in ``lib/Driver/ToolChains/Gnu.cpp``.
+The remainder of this document will not focus on this type of multilib.
+
+Multilib via configuration file
+===
+
+Some Clang toolchains support loading multilib configuration from a
+``multilib.yaml`` configuration file.
+
+A ``multilib.yaml`` configuration file specifies which multilib variants are
+available, their relative location, what compilation options were used to build
+them, and the criteria by which they are selected.
+
+Multilib processing
+===
+
+Clang goes through the following steps to use multilib from a configuration
+file:
+#. Convert command line arguments to flags. Clang can accept the same
+   information via different arguments - for example,
+   ``--target=arm-none-eabi -march=armv7-m`` and
+   ``--target=armv7m-none-eabi`` are equivalent. Clang can also accept many
+   independent pieces of information within a single flag - for example
+   ``-march=armv8.1m.main+fp+mve`` specifies the architecture and two
+   extensions in a single command line argument.
+   To make it easier for the multilib system, Clang converts the command line
+   arguments into a standard set of simpler "flags". In many cases these flags
+   will look like a command line argument with the leading ``-`` stripped off,
+   but where a suitable form for the flag doesn't exist in command line
+   arguments then its form will be different. For example, an Arm architecture
+   extension is represented like ``march=+mve`` since there's no way to specify
+   it in isolation in a command line argument.
+   To see what flags are emitted for a given set of command line arguments, use
+   the ``-print-multi-selection-flags-experimental`` command line argument
+   along with the rest of the arguments you want to use.
+#. Load ``multilib.yaml`` from sysroot.
+#. Generate additional flags. ``multilib.yaml`` contains a ``flagMap`` section,
+   which specifies how to generate additional flags based on the flags derived
+   from command line arguments. Flags are matched using regular expressions.
+   These regular expressions shall use the POSIX extended regular expression
+   syntax.
+#. Match flags against multilib variants. If the generated flags are a superset
+   of the flags specified for a multilib variant then the variant is considered
+   a match.
+   If more than one variant matches then a toolchain may opt to either use only
+  

[PATCH] D143075: BareMetal ToolChain multilib layering

2023-02-23 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 499962.
michaelplatings added a comment.

PrintArgs -> PrintOptions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143075

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/BareMetal.h
  clang/test/Driver/baremetal-multilib.yaml

Index: clang/test/Driver/baremetal-multilib.yaml
===
--- clang/test/Driver/baremetal-multilib.yaml
+++ clang/test/Driver/baremetal-multilib.yaml
@@ -25,6 +25,23 @@
 # RUN:   | FileCheck --check-prefix=CHECK-PRINT-MULTI-DIRECTORY %s
 # CHECK-PRINT-MULTI-DIRECTORY: arm-none-eabi/thumb/v8-m.main/fp
 
+# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -x c++ %s -### -o %t.out 2>&1 \
+# RUN: --target=thumbv8.1m.main-none-eabihf -fno-exceptions --sysroot= \
+# RUN:   | FileCheck -DSYSROOT=%T/baremetal_multilib --check-prefix=CHECK-LAYERED-MULTILIB %s
+# CHECK-LAYERED-MULTILIB:  "-cc1" "-triple" "thumbv8.1m.main-none-unknown-eabihf"
+# CHECK-LAYERED-MULTILIB-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8.1-m.main/fp/noexcept/include/c++/v1"
+# CHECK-LAYERED-MULTILIB-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8.1-m.main/fp/include/c++/v1"
+# CHECK-LAYERED-MULTILIB-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8.1-m.main/fp/noexcept/include"
+# CHECK-LAYERED-MULTILIB-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8.1-m.main/fp/include"
+# CHECK-LAYERED-MULTILIB-NEXT: "-L[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8.1-m.main/fp/noexcept/lib"
+# CHECK-LAYERED-MULTILIB-SAME: "-L[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8.1-m.main/fp/lib"
+
+# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -print-multi-directory 2>&1 \
+# RUN: --target=thumbv8.1m.main-none-eabihf -fno-exceptions --sysroot= \
+# RUN:   | FileCheck --check-prefix=CHECK-LAYERED-PRINT-MULTI-DIRECTORY %s
+# CHECK-LAYERED-PRINT-MULTI-DIRECTORY:  arm-none-eabi/thumb/v8.1-m.main/fp
+# CHECK-LAYERED-PRINT-MULTI-DIRECTORY-NEXT: arm-none-eabi/thumb/v8.1-m.main/fp/noexcept
+
 # RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -print-multi-lib 2>&1 \
 # RUN: --target=arm-none-eabi --sysroot= \
 # RUN:   | FileCheck --check-prefix=CHECK-PRINT-MULTI-LIB %s
@@ -38,6 +55,7 @@
 # CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v8-m.main/fp;@-target=thumbv8m.main-none-eabihf
 # CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v8.1-m.main/fp;@-target=thumbv8.1m.main-none-eabihf
 # CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v8.1-m.main/nofp/mve;@-target=arm-none-eabihf@march=armv8.1m.main+nofp+mve
+# CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v8.1-m.main/fp/noexcept;@-target=thumbv8.1m.main-none-eabihf@fno-exceptions
 
 # RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -x assembler -mexecute-only \
 # RUN: --target=arm-none-eabi --sysroot= %s -c -### 2>&1 \
@@ -118,6 +136,14 @@
   Flags: [target=thumbv8.1m.main-none-unknown-eabihf, march=+mve]
   PrintOptions: [--target=arm-none-eabihf, -march=armv8.1m.main+nofp+mve]
 
+# A specialisation of v8.1-m.main/fp without exceptions.
+# This layers over the top of the regular v8.1-m.main/fp so it doesn't
+# need to have its own include directory or C library, thereby saving
+# disk space.
+- Dir: arm-none-eabi/thumb/v8.1-m.main/fp/noexcept
+  Flags: [target=thumbv8.1m.main-none-unknown-eabihf, hasfpu, fno-exceptions]
+  PrintOptions: [--target=thumbv8.1m.main-none-eabihf, -fno-exceptions]
+
 
 # The second section of the file is a map from auto-detected flags
 # to custom flags. The auto-detected flags can be printed out
Index: clang/lib/Driver/ToolChains/BareMetal.h
===
--- clang/lib/Driver/ToolChains/BareMetal.h
+++ clang/lib/Driver/ToolChains/BareMetal.h
@@ -70,6 +70,9 @@
   void AddLinkRuntimeLib(const llvm::opt::ArgList &Args,
  llvm::opt::ArgStringList &CmdArgs) const;
   std::string computeSysRoot() const override;
+
+private:
+  llvm::SmallVector getOrderedMultilibs() const;
 };
 
 } // namespace toolchains
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -103,9 +103,12 @@
   findMultilibs(D, Triple, Args);
   SmallString<128> SysRoot(computeSysRoot());
   if (!SysRoot.empty()) {
-llvm::sys::path::append(SysRoot, "lib");
-getFilePaths().push_back(std::string(SysRoot));
-getLibraryPaths().push_back(std::string(SysRoot));
+for (const Multilib &M : getOrderedMultilibs()) {
+  SmallString<128> Dir(SysRoot);
+  llvm::sys::path::append(Dir, M.osSuffix(), "lib

[PATCH] D142986: Enable multilib.yaml in the BareMetal ToolChain

2023-02-23 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 499953.
michaelplatings added a comment.

PrintArgs -> PrintOptions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142986

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.h
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal-multilib.yaml
  clang/test/Driver/baremetal.cpp
  clang/test/Driver/lit.local.cfg

Index: clang/test/Driver/lit.local.cfg
===
--- clang/test/Driver/lit.local.cfg
+++ clang/test/Driver/lit.local.cfg
@@ -1,7 +1,7 @@
 from lit.llvm import llvm_config
 
 config.suffixes = ['.c', '.cpp', '.cppm', '.h', '.m', '.mm', '.S', '.s', '.f90', '.F90', '.f95',
-   '.cu', '.rs', '.cl', '.clcpp', '.hip', '.hipi', '.hlsl']
+   '.cu', '.rs', '.cl', '.clcpp', '.hip', '.hipi', '.hlsl', '.yaml']
 config.substitutions = list(config.substitutions)
 config.substitutions.insert(0,
 ('%clang_cc1',
Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -118,9 +118,9 @@
 // Verify that the bare metal driver does not include any host system paths:
 // CHECK-AARCH64-NO-HOST-INC: InstalledDir: [[INSTALLEDDIR:.+]]
 // CHECK-AARCH64-NO-HOST-INC: "-resource-dir" "[[RESOURCE:[^"]+]]"
-// CHECK-AARCH64-NO-HOST-INC-SAME: "-internal-isystem" "[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+}}aarch64-none-elf{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-AARCH64-NO-HOST-INC-SAME: "-internal-isystem" "[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECK-AARCH64-NO-HOST-INC-SAME: "-internal-isystem" "[[RESOURCE]]{{[/\\]+}}include"
-// CHECK-AARCH64-NO-HOST-INC-SAME: "-internal-isystem" "[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+}}aarch64-none-elf{{[/\\]+}}include"
+// CHECK-AARCH64-NO-HOST-INC-SAME: "-internal-isystem" "[[INSTALLEDDIR]]{{[/\\]+}}..{{[/\\]+}}lib{{[/\\]+}}clang-runtimes{{[/\\]+[^"]*}}include"
 
 // RUN: %clang %s -### --target=riscv64-unknown-elf -o %t.out -L some/directory/user/asked/for \
 // RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf 2>&1 \
Index: clang/test/Driver/baremetal-multilib.yaml
===
--- /dev/null
+++ clang/test/Driver/baremetal-multilib.yaml
@@ -0,0 +1,143 @@
+# REQUIRES: shell
+# UNSUPPORTED: system-windows
+
+# RUN: rm -rf %T/baremetal_multilib
+# RUN: mkdir -p %T/baremetal_multilib/bin
+# RUN: mkdir -p %T/baremetal_multilib/lib/clang-runtimes/arm-none-eabi/thumb/v8-m.main/fp/lib
+# RUN: touch %T/baremetal_multilib/lib/clang-runtimes/arm-none-eabi/thumb/v8-m.main/fp/lib/libclang_rt.builtins.a
+# RUN: ln -s %clang %T/baremetal_multilib/bin/clang
+# RUN: ln -s %s %T/baremetal_multilib/lib/clang-runtimes/multilib.yaml
+
+# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -x c++ %s -### -o %t.out 2>&1 \
+# RUN: --target=thumbv8m.main-none-eabihf --sysroot= \
+# RUN:   | FileCheck -DSYSROOT=%T/baremetal_multilib %s
+# CHECK:  "-cc1" "-triple" "thumbv8m.main-none-unknown-eabihf"
+# CHECK-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8-m.main/fp/include/c++/v1"
+# CHECK-SAME: "-internal-isystem" "[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8-m.main/fp/include"
+# CHECK-SAME: "-x" "c++" "{{.*}}baremetal-multilib.yaml"
+# CHECK-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+# CHECK-SAME: "-L[[SYSROOT]]/bin/../lib/clang-runtimes/arm-none-eabi/thumb/v8-m.main/fp/lib"
+# CHECK-SAME: "-lc" "-lm" "-lclang_rt.builtins"
+# CHECK-SAME: "-o" "{{.*}}.tmp.out"
+
+# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -print-multi-directory 2>&1 \
+# RUN: --target=thumbv8m.main-none-eabihf --sysroot= \
+# RUN:   | FileCheck --check-prefix=CHECK-PRINT-MULTI-DIRECTORY %s
+# CHECK-PRINT-MULTI-DIRECTORY: arm-none-eabi/thumb/v8-m.main/fp
+
+# RUN: %T/baremetal_multilib/bin/clang -no-canonical-prefixes -print-multi-lib 2>&1 \
+# RUN: --target=arm-none-eabi --sysroot= \
+# RUN:   | FileCheck --check-prefix=CHECK-PRINT-MULTI-LIB %s
+# CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v6-m/nofp;@-target=thumbv6m-none-eabi@mfloat-abi=soft
+# CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v7-m/nofp;@-target=thumbv7m-none-eabi@mfloat-abi=soft
+# CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v7e-m/nofp;@-target=thumbv7em-none-eabi@mfloat-abi=soft@mfpu=none
+# CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v8-m.main/nofp;@-target=arm-none-eabi@mfloat-abi=soft@march=armv8m.main+nofp
+# CHECK-PRINT-MULTI-LIB: arm-none-eabi/thumb/v8.1-m.main/nofp/nomve;@-target=arm-none-eabi@mfloat-abi=soft@march=armv8

[PATCH] D143524: Make the -Wunused-template default.

2023-02-23 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D143524#4148344 , @v.g.vassilev 
wrote:

> In D143524#4148271 , @philnik wrote:
>
>> It looks like this warning is incompatible with `-Wctad-maybe-unsupported`. 
>> It warns that the deduction guide is unused, but the deduction guide is 
>> required suppress `-Wctad-maybe-unsupported`. https://godbolt.org/z/G8bMjYsbn
>
> That should not be too hard to fix. It seems that just need to ignore 
> `CXXDeductionGuideDecl` in `Sema::ShouldRemoveFromUnused`. Is that blocking 
> you?

No, I just added a `[[maybe_unused]]`. D144667 
 should fix any libc++ problems.


Repository:
  rC Clang

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

https://reviews.llvm.org/D143524

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


[PATCH] D143524: Make the -Wunused-template default.

2023-02-23 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

In D143524#4148271 , @philnik wrote:

> It looks like this warning is incompatible with `-Wctad-maybe-unsupported`. 
> It warns that the deduction guide is unused, but the deduction guide is 
> required suppress `-Wctad-maybe-unsupported`. https://godbolt.org/z/G8bMjYsbn

That should not be too hard to fix. It seems that just need to ignore 
`CXXDeductionGuideDecl` in `Sema::ShouldRemoveFromUnused`. Is that blocking you?


Repository:
  rC Clang

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

https://reviews.llvm.org/D143524

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-23 Thread Chris Cotter via Phabricator via cfe-commits
ccotter added a comment.

> Imaginate that such trivial type could be for example 200KB in size

This should be passed by const ref then correct (listed under "Expensive to 
move (e.g. big BigPOD[]" in the parameter passing guidelines 
)
 ? Are there cases where a big pod type needs to be passed by rvalue ref, 
without std::move where const ref cannot be used instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D143996: [clang-tidy][doc] Remove unused variable

2023-02-23 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added a comment.

In D143996#4147759 , @bjosv wrote:

> @carlosgalvezp Sorry, I should have mentioned that I don't have push rights 
> and that this is my first contribution to llvm.
> My GitHub user is:  bjosv   and email:  bjorn.a.svens...@est.tech
> Thanks.

No problem, thanks for your first contribution! :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143996

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


[clang-tools-extra] 2928746 - [clang-tidy][doc] Remove unused variable

2023-02-23 Thread Carlos Galvez via cfe-commits

Author: Björn Svensson
Date: 2023-02-23T20:07:50Z
New Revision: 2928746ac3f1aabbecbe8da1525127443ebec2cf

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

LOG: [clang-tidy][doc] Remove unused variable

Remove mention of a variable that is not used in the example for checker:
cppcoreguidelines-avoid-non-const-global-variables

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

Added: 


Modified: 

clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst

Removed: 




diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
index 53dafc7f8b435..7d729f286d6c5 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
@@ -32,7 +32,7 @@ As `R.6 of C++ Core Guidelines 


[PATCH] D143996: [clang-tidy][doc] Remove unused variable

2023-02-23 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2928746ac3f1: [clang-tidy][doc] Remove unused variable 
(authored by bjosv, committed by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143996

Files:
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst


Index: 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
===
--- 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
+++ 
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
@@ -32,7 +32,7 @@
 char h = 0;
 };
 
-Variables: ``a``, ``c``, ``c_ptr1``, ``c_ptr2``, ``c_const_ptr`` and
-``c_reference``, will all generate warnings since they are either:
-a globally accessible variable and non-const, a pointer or reference providing
-global access to non-const data or both.
+The variables ``a``, ``c``, ``c_ptr1``, ``c_const_ptr`` and ``c_reference``
+will all generate warnings since they are either a non-const globally 
accessible
+variable, a pointer or a reference providing global access to non-const data
+or both.


Index: clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
+++ clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines/avoid-non-const-global-variables.rst
@@ -32,7 +32,7 @@
 char h = 0;
 };
 
-Variables: ``a``, ``c``, ``c_ptr1``, ``c_ptr2``, ``c_const_ptr`` and
-``c_reference``, will all generate warnings since they are either:
-a globally accessible variable and non-const, a pointer or reference providing
-global access to non-const data or both.
+The variables ``a``, ``c``, ``c_ptr1``, ``c_const_ptr`` and ``c_reference``
+will all generate warnings since they are either a non-const globally accessible
+variable, a pointer or a reference providing global access to non-const data
+or both.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143524: Make the -Wunused-template default.

2023-02-23 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

It looks like this warning is incompatible with `-Wctad-maybe-unsupported`. It 
warns that the deduction guide is unused, but the deduction guide is required 
suppress `-Wctad-maybe-unsupported`. https://godbolt.org/z/G8bMjYsbn


Repository:
  rC Clang

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

https://reviews.llvm.org/D143524

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


[PATCH] D144035: [SCEV] Ensure SCEV does not replace aliases with their aliasees

2023-02-23 Thread Leonard Chan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG608ee703e530: [SCEV] Ensure SCEV does not replace aliases 
with their aliasees (authored by leonardchan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144035

Files:
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/test/Analysis/ScalarEvolution/no-follow-alias.ll


Index: llvm/test/Analysis/ScalarEvolution/no-follow-alias.ll
===
--- /dev/null
+++ llvm/test/Analysis/ScalarEvolution/no-follow-alias.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by 
utils/update_analyze_test_checks.py
+; RUN: opt -passes='print' -disable-output %s 2>&1 | 
FileCheck %s
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-gnu"
+
+@glob.private = private constant [32 x i32] zeroinitializer
+@glob = linkonce_odr hidden alias [32 x i32], inttoptr (i64 add (i64 ptrtoint 
(ptr @glob.private to i64), i64 1234) to ptr)
+
+define hidden void @func(i64 %idx) local_unnamed_addr {
+; CHECK-LABEL: 'func'
+; CHECK-NEXT:  Classifying expressions for: @func
+; CHECK-NEXT:%arrayidx = getelementptr inbounds [32 x i32], ptr @glob, i64 
0, i64 %idx
+; CHECK-NEXT:--> ((4 * %idx) + @glob) U: [0,-1) S: 
[-9223372036854775808,9223372036854775807)
+; CHECK-NEXT:  Determining loop execution counts for: @func
+;
+  %arrayidx = getelementptr inbounds [32 x i32], ptr @glob, i64 0, i64 %idx
+  ret void
+}
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7429,10 +7429,6 @@
   } else if (ConstantInt *CI = dyn_cast(V))
 return getConstant(CI);
   else if (GlobalAlias *GA = dyn_cast(V)) {
-if (!GA->isInterposable()) {
-  Ops.push_back(GA->getAliasee());
-  return nullptr;
-}
 return getUnknown(V);
   } else if (!isa(V))
 return getUnknown(V);
@@ -7619,7 +7615,7 @@
   } else if (ConstantInt *CI = dyn_cast(V))
 return getConstant(CI);
   else if (GlobalAlias *GA = dyn_cast(V))
-return GA->isInterposable() ? getUnknown(V) : getSCEV(GA->getAliasee());
+return getUnknown(V);
   else if (!isa(V))
 return getUnknown(V);
 


Index: llvm/test/Analysis/ScalarEvolution/no-follow-alias.ll
===
--- /dev/null
+++ llvm/test/Analysis/ScalarEvolution/no-follow-alias.ll
@@ -0,0 +1,19 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
+; RUN: opt -passes='print' -disable-output %s 2>&1 | FileCheck %s
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+target triple = "aarch64-unknown-linux-gnu"
+
+@glob.private = private constant [32 x i32] zeroinitializer
+@glob = linkonce_odr hidden alias [32 x i32], inttoptr (i64 add (i64 ptrtoint (ptr @glob.private to i64), i64 1234) to ptr)
+
+define hidden void @func(i64 %idx) local_unnamed_addr {
+; CHECK-LABEL: 'func'
+; CHECK-NEXT:  Classifying expressions for: @func
+; CHECK-NEXT:%arrayidx = getelementptr inbounds [32 x i32], ptr @glob, i64 0, i64 %idx
+; CHECK-NEXT:--> ((4 * %idx) + @glob) U: [0,-1) S: [-9223372036854775808,9223372036854775807)
+; CHECK-NEXT:  Determining loop execution counts for: @func
+;
+  %arrayidx = getelementptr inbounds [32 x i32], ptr @glob, i64 0, i64 %idx
+  ret void
+}
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7429,10 +7429,6 @@
   } else if (ConstantInt *CI = dyn_cast(V))
 return getConstant(CI);
   else if (GlobalAlias *GA = dyn_cast(V)) {
-if (!GA->isInterposable()) {
-  Ops.push_back(GA->getAliasee());
-  return nullptr;
-}
 return getUnknown(V);
   } else if (!isa(V))
 return getUnknown(V);
@@ -7619,7 +7615,7 @@
   } else if (ConstantInt *CI = dyn_cast(V))
 return getConstant(CI);
   else if (GlobalAlias *GA = dyn_cast(V))
-return GA->isInterposable() ? getUnknown(V) : getSCEV(GA->getAliasee());
+return getUnknown(V);
   else if (!isa(V))
 return getUnknown(V);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131618: [clang][llvm][lld] FatLTO Prototype

2023-02-23 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: lld/test/ELF/fatlto/Inputs/a-fatLTO.yaml:23
+AddressAlign:0x1
+Content: 
4243C0DE35140500620C30244D59BE669DFBB44F1BC8244401320500210C7B020B022100020016000781239141C80449061032399201840C250508191E048B628010450242920B42841032143808184B0A3242884870C421234412878C1041920264C808B1142043468820C901324284182A282A90317CB05C9120C4C80089200D003222080920624600212B249810212524981019270C85A4906042645C2024648200A93902301801308198200602E608822900511881001B4823F801792883200C04C21CE4211CDAA11CDA001EDE211DDC811ECA411E807060077600887648077768037628877308077668037B288771A08777908736B8877420077A4007000E00C21DDEA10DE8411EC2011EE0211DDCE11CDAA01DC2811ED001A00779A88772008879A08770188775680378908777A0877218077A780779680371A80773308772908736988774D0877200F00020E8211CE4E11CCA811EDA601CE0A11E007CC0033B68033BA00380A0877090877328077A680373288770A0877A9087729807600DC6011FF0800DD6C01CF0611EE4810DD6A01DDA011FD8600DE6611ECA810DD6601EE6A11CE4800DD6001FF0E00E00821EEAC11DCAA10DC6011EEA013887727087729087741807604358083F10E6200FE1D00EE5D006F0F00EE9E00EF4500EF20084033BB00340B8C33BB4013DC84338C0033CA4833B9C431BB44338D0033A00F4200FF5500E00310FF4100EE3B00E6D000FF2F00EF4500EE3400FEF200F6D200EF5600EE6500EF2D006F3900EFA500E001E00043D84833C9C4339D0431B8C033CD403800F7860076D6007740010F4100EF2700EE5400F6D600EE5100EF4500FF2500EF300ACC138E0031EB0C11A98033ECC833CB0C11AB4433BE0031BACC13CCC4339B0C11ACCC33C94831CB0C11AE0031EDC0140D0433DB84339B4C138C0433D00E7500EEE500EF2900EE3004918020013826042200013307CC0033BF8053BA08336A807775808877B70873660877470877AC08736380777A8870DA6500E6DD00E7A500E6D000F72700770A0077320077A300772D006F020077710077A300772A0077320076D000F72700772A0077640077A600774D006E9600774A0077640076D600E7800077A10077280076DE00E78A0077160077A300772A0077640076D300B71200778A0F48010210964C8484023846107C017764C401008C6300401000CA90262200088802155411004001130A44A0802008602200086540D3100012480C40681C2780259200700321E981019114C908C092647C604438A1180122884722802B118A1003308801CC4E11C6614013D88433884C38C4280077978077398710CE6000FED100EF4800E330C421EC2C11DCEA11C6630053D88433884831BCC033DC8433D8C033DCC788C7470077B08077948877070077A700376788770208719CC110EEC900EE1300F6E300FE3F00EF0500E3310C41DDE211CD8211DC2611E6630893BBC833BD04339B4033CBC833C84033BCCF0147660077B680737688772680737808770908770600776280776F8057678877780875F08877118877298877998812CEEF0000EF5C00EEC300362C8A11CE4A11CCCA11CE4A11CDC611CCA211CC4811DCA6106D6904339C84339984339C84339B8C33894433888033B94C32FBC833CFC823BD4033BB0C30CC7698770588772708374680778608774188774A08719CE530FEE000FF2500EE4900EE3400FE1200EEC500E3320281DDCC11EC2411ED2211CDC811EDCE01CE4E11DEA011E66185138B0433A9C833BCC50247660077B6807376088077898514CF4900FF0500E331E6A1ECA611CE8211DDEC11D7E011EE4A11CCC211DF0610654858338CCC33BB0433DD04339FCC23CE4433B88C33BB0C38CC50A877998877718877408077A28077298815CE3100EECC00EE5500EF33023C1D2411EE4E117D8E11DDE011E6648193BB0833DB4831B84C3388C4339CCC33CB8C139C8C33BD4033CCC48B471080776600771088771588719DBC60EEC600FEDE006F0200FE5300FE5200FF6500E6E100EE3300EE5300FF3E006E9E00EE4500EF83023E2EC611CC2811DD8E117EC211DE6211DC4211DD8211DE8211F66209D3BBC433DB80339948339CC58BC707008077A08077A48808719CBE70EEF300FE1E00EE9400FE9A00FE530C3010373A8077718875F988770708774A08774D0877279204D00721E482043880C19097232482023818C9191D144A01028643C3132428E9021A3782072014A921C8D840E77636861725F73697A65504943204C6576656C504945204C6576656C75777461626C656672616D652D706F696E746572456E61626C6553706C69744C544F556E6974636C616E672076657273696F6E2031352E302E30202868747470733A2F2F6769746875622E636F6D2F6C6C766D2F6C6C766D2D70726F6A6563742E6769742031343639393432316364316430623637346131636131613464326639653964626562646231393463292308813182101C2308013282102423084131C38004C90C83222C330CCAB0CC3028C432C3A014CB0C0362303304878C042628233636BB3697B637B23AB6321733B6B0B3B9510CA6711E284A858DCDAECD258DACCC8D6E94400200A91825000B0A7228877780077A587098433DB8C338B04339D0C382E61CC6A10DE8411EC2C11DE6211DE8211DDEC11D1634E3600EE7500FE1200FE4400FE1200FE7500EF4B08081077928877060077678877108077A28077258709CC338B4013BA4833D94C3026B1CD8211CDCE11CDC201CE4611CDC201CE8811EC2611CD0A11CC8611CC2811DD861C1010FF4200FE1500FF4800ED110060007CC3CA4833B9C033B94033DA0833C94433890C3010061200B001304412C11001435C306C4120C80860301000200075010CD1461612020001304432C110014450500331141608CC2B00C03404C8CE18600418359864008460C080004C18058860D082218805902818818181820306C4018C10090116383702B00D63008CC730005D14C1176020652F8443318C4000C832D10033001177020853F1D44630E84002C0B61200B001304412C110014450100230604008260301C1B8403010200075010CD14610

[PATCH] D144634: [Clang][OpenMP] Support for Code Generation of loop bind clause

2023-02-23 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

We need tests.




Comment at: clang/lib/CodeGen/CGStmtOpenMP.cpp:7790
+  for (const auto *C : S.getClausesOfKind()) {
+OpenMPBindClauseKind bindParam = C->getBindKind();
+switch (bindParam) {

style, also below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144634

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


[PATCH] D144599: [clangd/index/remote]NFC: Adapt code to newer grpc/protobuf versions

2023-02-23 Thread Matthias Braun via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc21378f90a44: [clangd/index/remote]NFC: Adapt code to newer 
grpc/protobuf versions (authored by MatzeB).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144599

Files:
  clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp


Index: clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
===
--- clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
+++ clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
@@ -67,8 +67,9 @@
   google::protobuf::util::MessageToJsonString(Response, &Output, Options);
   if (!JsonStatus.ok()) {
 clang::clangd::elog("Can not convert response ({0}) to JSON ({1}): {2}\n",
-Response.DebugString(), JsonStatus.error_code(),
-JsonStatus.error_message().as_string());
+Response.DebugString(),
+static_cast(JsonStatus.code()),
+JsonStatus.message().as_string());
 return -1;
   }
   llvm::outs() << Output;


Index: clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
===
--- clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
+++ clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
@@ -67,8 +67,9 @@
   google::protobuf::util::MessageToJsonString(Response, &Output, Options);
   if (!JsonStatus.ok()) {
 clang::clangd::elog("Can not convert response ({0}) to JSON ({1}): {2}\n",
-Response.DebugString(), JsonStatus.error_code(),
-JsonStatus.error_message().as_string());
+Response.DebugString(),
+static_cast(JsonStatus.code()),
+JsonStatus.message().as_string());
 return -1;
   }
   llvm::outs() << Output;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] c21378f - [clangd/index/remote]NFC: Adapt code to newer grpc/protobuf versions

2023-02-23 Thread Matthias Braun via cfe-commits

Author: Matthias Braun
Date: 2023-02-23T11:26:41-08:00
New Revision: c21378f90a4442810adc4af924a83a9c222fdc51

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

LOG: [clangd/index/remote]NFC: Adapt code to newer grpc/protobuf versions

It seems newer grpc / protobuf versions renamed
`Status::error_message()` and `Status::error_code()` to `message()` and
`code()` to prepare for replacement with `absl::Status` with the same
names.

As far as I can tell the new names are already available in the
grpc-1.36 version mentioned in the `README` file.

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

Added: 


Modified: 
clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp 
b/clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
index 96451f7764675..9a58b5871bfce 100644
--- a/clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
+++ b/clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
@@ -67,8 +67,9 @@ int main(int argc, char *argv[]) {
   google::protobuf::util::MessageToJsonString(Response, &Output, Options);
   if (!JsonStatus.ok()) {
 clang::clangd::elog("Can not convert response ({0}) to JSON ({1}): {2}\n",
-Response.DebugString(), JsonStatus.error_code(),
-JsonStatus.error_message().as_string());
+Response.DebugString(),
+static_cast(JsonStatus.code()),
+JsonStatus.message().as_string());
 return -1;
   }
   llvm::outs() << Output;



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


[PATCH] D144218: [Clang] [AVR] Fix USHRT_MAX for 16-bit int.

2023-02-23 Thread Daniel Thornburgh via Phabricator via cfe-commits
mysterymath updated this revision to Diff 499922.
mysterymath added a comment.

Use #if to select between signed and unsigned USHRT_MAX.

Add tests for the types of limit macros specified by the standard.
Add tests that limit macros can be used in #if.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144218

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/limits.h
  clang/test/Headers/limits.cpp

Index: clang/test/Headers/limits.cpp
===
--- clang/test/Headers/limits.cpp
+++ clang/test/Headers/limits.cpp
@@ -3,14 +3,39 @@
 // RUN: %clang_cc1 -std=c++11 -ffreestanding -fsyntax-only -verify %s
 // RUN: %clang_cc1 -std=c17 -ffreestanding -fsyntax-only -verify -x c %s
 // RUN: %clang_cc1 -std=c2x -ffreestanding -fsyntax-only -verify -x c %s
+
+// Specifically test 16-bit int platforms.
+// RUN: %clang_cc1 -triple=avr -ffreestanding -fsyntax-only -verify -x c %s
+
 // expected-no-diagnostics
 
 #include 
 
+#if __cplusplus
+#define EXPR_TYPE_IS(EXPR, TYP) __is_same(__typeof(EXPR), TYP)
+#else
+#define EXPR_TYPE_IS(EXPR, TYP) _Generic(EXPR, TYP: 1, default: 0)
+#endif
+
 _Static_assert(SCHAR_MAX == -(SCHAR_MIN+1), "");
+_Static_assert(EXPR_TYPE_IS(SCHAR_MAX, int), "");
+#if SCHAR_MAX
+#endif
+
 _Static_assert(SHRT_MAX == -(SHRT_MIN+1), "");
+_Static_assert(EXPR_TYPE_IS(SHRT_MAX, int), "");
+#if SHRT_MAX
+#endif
+
 _Static_assert(INT_MAX == -(INT_MIN+1), "");
+_Static_assert(EXPR_TYPE_IS(INT_MAX, int), "");
+#if INT_MAX
+#endif
+
 _Static_assert(LONG_MAX == -(LONG_MIN+1L), "");
+_Static_assert(EXPR_TYPE_IS(LONG_MAX, long), "");
+#if LONG_MAX
+#endif
 
 _Static_assert(SCHAR_MAX == UCHAR_MAX/2, "");
 _Static_assert(SHRT_MAX == USHRT_MAX/2, "");
@@ -18,26 +43,84 @@
 _Static_assert(LONG_MAX == ULONG_MAX/2, "");
 
 _Static_assert(SCHAR_MIN == -SCHAR_MAX-1, "");
+_Static_assert(EXPR_TYPE_IS(SCHAR_MIN, int), "");
+#if SCHAR_MIN
+#endif
+
 _Static_assert(SHRT_MIN == -SHRT_MAX-1, "");
+_Static_assert(EXPR_TYPE_IS(SHRT_MIN, int), "");
+#if SHRT_MIN
+#endif
+
 _Static_assert(INT_MIN == -INT_MAX-1, "");
+_Static_assert(EXPR_TYPE_IS(INT_MIN, int), "");
+#if INT_MIN
+#endif
+
 _Static_assert(LONG_MIN == -LONG_MAX-1L, "");
+_Static_assert(EXPR_TYPE_IS(LONG_MIN, long), "");
+#if LONG_MIN
+#endif
 
 _Static_assert(UCHAR_MAX == (unsigned char)~0ULL, "");
+_Static_assert(UCHAR_MAX <= INT_MAX ?
+ EXPR_TYPE_IS(UCHAR_MAX, int) :
+ EXPR_TYPE_IS(UCHAR_MAX, unsigned int), "");
+#if UCHAR_MAX
+#endif
+
 _Static_assert(USHRT_MAX == (unsigned short)~0ULL, "");
+_Static_assert(USHRT_MAX <= INT_MAX ?
+ EXPR_TYPE_IS(USHRT_MAX, int) :
+ EXPR_TYPE_IS(USHRT_MAX, unsigned int), "");
+#if USHRT_MAX
+#endif
+
 _Static_assert(UINT_MAX == (unsigned int)~0ULL, "");
+_Static_assert(EXPR_TYPE_IS(UINT_MAX, unsigned int), "");
+#if UINT_MAX
+#endif
+
 _Static_assert(ULONG_MAX == (unsigned long)~0ULL, "");
+_Static_assert(EXPR_TYPE_IS(ULONG_MAX, unsigned long), "");
+#if ULONG_MAX
+#endif
 
 _Static_assert(MB_LEN_MAX >= 1, "");
+#if MB_LEN_MAX
+#endif
 
 _Static_assert(CHAR_BIT >= 8, "");
+#if CHAR_BIT
+#endif
 
 _Static_assert(CHAR_MIN == (((char)-1 < (char)0) ? -CHAR_MAX-1 : 0), "");
+_Static_assert(EXPR_TYPE_IS(CHAR_MIN, int), "");
+#if CHAR_MIN
+#endif
+
 _Static_assert(CHAR_MAX == (((char)-1 < (char)0) ? -(CHAR_MIN+1) : (char)~0ULL), "");
+_Static_assert(CHAR_MAX <= INT_MAX ?
+ EXPR_TYPE_IS(CHAR_MAX, int) :
+ EXPR_TYPE_IS(CHAR_MAX, unsigned int), "");
+#if CHAR_MAX
+#endif
 
 #if __STDC_VERSION__ >= 199901 || __cplusplus >= 201103L
 _Static_assert(LLONG_MAX == -(LLONG_MIN+1LL), "");
+_Static_assert(EXPR_TYPE_IS(LLONG_MAX, long long), "");
+#if LLONG_MAX
+#endif
+
 _Static_assert(LLONG_MIN == -LLONG_MAX-1LL, "");
+#if LLONG_MIN
+#endif
+_Static_assert(EXPR_TYPE_IS(LLONG_MIN, long long), "");
+
 _Static_assert(ULLONG_MAX == (unsigned long long)~0ULL, "");
+_Static_assert(EXPR_TYPE_IS(ULLONG_MAX, unsigned long long), "");
+#if ULLONG_MAX
+#endif
 #else
 int LLONG_MIN, LLONG_MAX, ULLONG_MAX; // Not defined.
 #endif
@@ -47,35 +130,61 @@
 #if __STDC_VERSION__ >= 202000L
 /* Validate the standard requirements. */
 _Static_assert(BOOL_WIDTH >= 1);
+#if BOOL_WIDTH
+#endif
 
 _Static_assert(CHAR_WIDTH == CHAR_BIT);
 _Static_assert(CHAR_WIDTH / CHAR_BIT == sizeof(char));
+#if CHAR_WIDTH
+#endif
 _Static_assert(SCHAR_WIDTH == CHAR_BIT);
 _Static_assert(SCHAR_WIDTH / CHAR_BIT == sizeof(signed char));
+#if SCHAR_WIDTH
+#endif
 _Static_assert(UCHAR_WIDTH == CHAR_BIT);
 _Static_assert(UCHAR_WIDTH / CHAR_BIT == sizeof(unsigned char));
+#if UCHAR_WIDTH
+#endif
 
 _Static_assert(USHRT_WIDTH >= 16);
 _Static_assert(USHRT_WIDTH / CHAR_BIT == sizeof(unsigned short));
+#if USHRT_WIDTH
+#endif
 _Static_assert(SHRT_WIDTH == USHRT_WIDTH);
 _Static_assert(SHRT_WIDTH / CHAR_BIT == sizeof(signed short));
+#if SHRT_WIDTH
+#endif
 
 _

[PATCH] D144620: [clang][driver] Handle '-mrelax' and '-mno-relax' for AVR

2023-02-23 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/ToolChains/AVR.cpp:548
 
+// '-mrelax' is default unless '-mno-relax' is specified.
+if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))

The comment just repeats what the code does. I think it can be dropped.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144620

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


[PATCH] D131618: [clang][llvm][lld] FatLTO Prototype

2023-02-23 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added inline comments.



Comment at: lld/test/ELF/fatlto/Inputs/a-fatLTO.yaml:23
+AddressAlign:0x1
+Content: 
4243C0DE35140500620C30244D59BE669DFBB44F1BC8244401320500210C7B020B022100020016000781239141C80449061032399201840C250508191E048B628010450242920B42841032143808184B0A3242884870C421234412878C1041920264C808B1142043468820C901324284182A282A90317CB05C9120C4C80089200D003222080920624600212B249810212524981019270C85A4906042645C2024648200A93902301801308198200602E608822900511881001B4823F801792883200C04C21CE4211CDAA11CDA001EDE211DDC811ECA411E807060077600887648077768037628877308077668037B288771A08777908736B8877420077A4007000E00C21DDEA10DE8411EC2011EE0211DDCE11CDAA01DC2811ED001A00779A88772008879A08770188775680378908777A0877218077A780779680371A80773308772908736988774D0877200F00020E8211CE4E11CCA811EDA601CE0A11E007CC0033B68033BA00380A0877090877328077A680373288770A0877A9087729807600DC6011FF0800DD6C01CF0611EE4810DD6A01DDA011FD8600DE6611ECA810DD6601EE6A11CE4800DD6001FF0E00E00821EEAC11DCAA10DC6011EEA013887727087729087741807604358083F10E6200FE1D00EE5D006F0F00EE9E00EF4500EF20084033BB00340B8C33BB4013DC84338C0033CA4833B9C431BB44338D0033A00F4200FF5500E00310FF4100EE3B00E6D000FF2F00EF4500EE3400FEF200F6D200EF5600EE6500EF2D006F3900EFA500E001E00043D84833C9C4339D0431B8C033CD403800F7860076D6007740010F4100EF2700EE5400F6D600EE5100EF4500FF2500EF300ACC138E0031EB0C11A98033ECC833CB0C11AB4433BE0031BACC13CCC4339B0C11ACCC33C94831CB0C11AE0031EDC0140D0433DB84339B4C138C0433D00E7500EEE500EF2900EE3004918020013826042200013307CC0033BF8053BA08336A807775808877B70873660877470877AC08736380777A8870DA6500E6DD00E7A500E6D000F72700770A0077320077A300772D006F020077710077A300772A0077320076D000F72700772A0077640077A600774D006E9600774A0077640076D600E7800077A10077280076DE00E78A0077160077A300772A0077640076D300B71200778A0F48010210964C8484023846107C017764C401008C6300401000CA90262200088802155411004001130A44A0802008602200086540D3100012480C40681C2780259200700321E981019114C908C092647C604438A1180122884722802B118A1003308801CC4E11C6614013D88433884C38C4280077978077398710CE6000FED100EF4800E330C421EC2C11DCEA11C6630053D88433884831BCC033DC8433D8C033DCC788C7470077B08077948877070077A700376788770208719CC110EEC900EE1300F6E300FE3F00EF0500E3310C41DDE211CD8211DC2611E6630893BBC833BD04339B4033CBC833C84033BCCF0147660077B680737688772680737808770908770600776280776F8057678877780875F08877118877298877998812CEEF0000EF5C00EEC300362C8A11CE4A11CCCA11CE4A11CDC611CCA211CC4811DCA6106D6904339C84339984339C84339B8C33894433888033B94C32FBC833CFC823BD4033BB0C30CC7698770588772708374680778608774188774A08719CE530FEE000FF2500EE4900EE3400FE1200EEC500E3320281DDCC11EC2411ED2211CDC811EDCE01CE4E11DEA011E66185138B0433A9C833BCC50247660077B6807376088077898514CF4900FF0500E331E6A1ECA611CE8211DDEC11D7E011EE4A11CCC211DF0610654858338CCC33BB0433DD04339FCC23CE4433B88C33BB0C38CC50A877998877718877408077A28077298815CE3100EECC00EE5500EF33023C1D2411EE4E117D8E11DDE011E6648193BB0833DB4831B84C3388C4339CCC33CB8C139C8C33BD4033CCC48B471080776600771088771588719DBC60EEC600FEDE006F0200FE5300FE5200FF6500E6E100EE3300EE5300FF3E006E9E00EE4500EF83023E2EC611CC2811DD8E117EC211DE6211DC4211DD8211DE8211F66209D3BBC433DB80339948339CC58BC707008077A08077A48808719CBE70EEF300FE1E00EE9400FE9A00FE530C3010373A8077718875F988770708774A08774D0877279204D00721E482043880C19097232482023818C9191D144A01028643C3132428E9021A3782072014A921C8D840E77636861725F73697A65504943204C6576656C504945204C6576656C75777461626C656672616D652D706F696E746572456E61626C6553706C69744C544F556E6974636C616E672076657273696F6E2031352E302E30202868747470733A2F2F6769746875622E636F6D2F6C6C766D2F6C6C766D2D70726F6A6563742E6769742031343639393432316364316430623637346131636131613464326639653964626562646231393463292308813182101C2308013282102423084131C38004C90C83222C330CCAB0CC3028C432C3A014CB0C0362303304878C042628233636BB3697B637B23AB6321733B6B0B3B9510CA6711E284A858DCDAECD258DACCC8D6E94400200A91825000B0A7228877780077A587098433DB8C338B04339D0C382E61CC6A10DE8411EC2C11DE6211DE8211DDEC11D1634E3600EE7500FE1200FE4400FE1200FE7500EF4B08081077928877060077678877108077A28077258709CC338B4013BA4833D94C3026B1CD8211CDCE11CDC201CE4611CDC201CE8811EC2611CD0A11CC8611CC2811DD861C1010FF4200FE1500FF4800ED110060007CC3CA4833B9C033B94033DA0833C94433890C3010061200B001304412C11001435C306C4120C80860301000200075010CD1461612020001304432C110014450500331141608CC2B00C03404C8CE18600418359864008460C080004C18058860D082218805902818818181820306C4018C10090116383702B00D63008CC730005D14C1176020652F8443318C4000C832D10033001177020853F1D44630E84002C0B61200B001304412C110014450100230604008260301C1B8403010200075010CD14

[PATCH] D143524: Make the -Wunused-template default.

2023-02-23 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev marked an inline comment as done.
v.g.vassilev added a comment.

In D143524#4148039 , @philnik wrote:

> In D143524#4148024 , @v.g.vassilev 
> wrote:
>
>> In D143524#4148006 , @philnik 
>> wrote:
>>
>>> The emitted warnings from the libc++ CI look like a false-positive to me. 
>>> While the functions are never called, they are used in an unevaluated 
>>> context. I would expect `-Wunused` warnings to only be emitted when I can 
>>> just remove the code without problems, which doesn't seem to be the case 
>>> here. It would probably just get turned off again by lots of people if 
>>> there are too many false-positives, which I don't think is the goal here.
>>
>> From what I see is that most of the templates are marked with static which 
>> means internal linkage. Entities with internal linkage in header files are 
>> essentially different across translation units which is an ODR violation. I 
>> believe the discussion here gives more insights of how this works: 
>> https://reviews.llvm.org/D29877
>>
>> Indeed the warning is noisy but it will potentially fix broken code which 
>> were unable to diagnose before. Especially that in some cases where static 
>> templates in header files are used as an idiom. In theory this approach can 
>> extend to cases described in https://wg21.link/p2691 where our inability to 
>> diagnose/fix these cases leads to some design decisions which may not be 
>> optimal.
>
> I missed the `static` at the beginning. That explains the warning, thanks! I 
> agree this should be fixed. I'll look into making a patch to enable 
> `-Wunused-template` and fix any problems. Hopefully there aren't too many.

This would be awesome as I don't have a lot of bandwidth right now and that 
potentially will have quite positive impact (once people understand what they 
need to do). I am not sure if we could somehow emit a fix-it suggestion. So far 
I have failed in figuring out what's a good suggestion when using this static 
template idiom...


Repository:
  rC Clang

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

https://reviews.llvm.org/D143524

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


[PATCH] D143524: Make the -Wunused-template default.

2023-02-23 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

In D143524#4148024 , @v.g.vassilev 
wrote:

> In D143524#4148006 , @philnik wrote:
>
>> The emitted warnings from the libc++ CI look like a false-positive to me. 
>> While the functions are never called, they are used in an unevaluated 
>> context. I would expect `-Wunused` warnings to only be emitted when I can 
>> just remove the code without problems, which doesn't seem to be the case 
>> here. It would probably just get turned off again by lots of people if there 
>> are too many false-positives, which I don't think is the goal here.
>
> From what I see is that most of the templates are marked with static which 
> means internal linkage. Entities with internal linkage in header files are 
> essentially different across translation units which is an ODR violation. I 
> believe the discussion here gives more insights of how this works: 
> https://reviews.llvm.org/D29877
>
> Indeed the warning is noisy but it will potentially fix broken code which 
> were unable to diagnose before. Especially that in some cases where static 
> templates in header files are used as an idiom. In theory this approach can 
> extend to cases described in https://wg21.link/p2691 where our inability to 
> diagnose/fix these cases leads to some design decisions which may not be 
> optimal.

I missed the `static` at the beginning. That explains the warning, thanks! I 
agree this should be fixed. I'll look into making a patch to enable 
`-Wunused-template` and fix any problems. Hopefully there aren't too many.


Repository:
  rC Clang

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

https://reviews.llvm.org/D143524

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


[PATCH] D143524: Make the -Wunused-template default.

2023-02-23 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev marked an inline comment as done.
v.g.vassilev added inline comments.



Comment at: clang/test/SemaCXX/warn-func-not-needed.cpp:13
 namespace test1_template {
-template  static void f() {}
+template  static void f() {} // expected-warning {{unused function 
template}}
 template <> void f() {} // expected-warning {{function 'f' is not 
needed and will not be emitted}}

aaron.ballman wrote:
> Why is this unused? `f()` in `foo()` should cause this to be used, 
> right?
> 
> How should a user silence this diagnostic without disabling it entirely?
Nobody uses `foo`.


Repository:
  rC Clang

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

https://reviews.llvm.org/D143524

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


[PATCH] D131618: [clang][llvm][lld] FatLTO Prototype

2023-02-23 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth updated this revision to Diff 499913.
paulkirth retitled this revision from "[WIP][Do NOT review] LLD related changes 
for -ffat-lto-objects support" to "[clang][llvm][lld] FatLTO Prototype".
paulkirth edited the summary of this revision.
paulkirth added a comment.

Rebase revision. Abandon parent revision on unified lto.

- Small changes to the LLD implementation were required.

Note: I've only rebased this change so far, I've made no attempt to improve its 
quality.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131618

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/embed-lto-fatlto.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Driver/fatlto-objects.c
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/Options.td
  lld/test/ELF/fatlto/Inputs/a-LTO.ll
  lld/test/ELF/fatlto/Inputs/a-fatLTO.yaml
  lld/test/ELF/fatlto/Inputs/a.c
  lld/test/ELF/fatlto/Inputs/a.h
  lld/test/ELF/fatlto/Inputs/a.yaml
  lld/test/ELF/fatlto/Inputs/main-LTO.ll
  lld/test/ELF/fatlto/Inputs/main-fatLTO.yaml
  lld/test/ELF/fatlto/Inputs/main.c
  lld/test/ELF/fatlto/Inputs/main.yaml
  lld/test/ELF/fatlto/fatlto.test
  llvm/include/llvm/Bitcode/EmbedBitcodePass.h
  llvm/lib/Bitcode/Writer/CMakeLists.txt
  llvm/lib/Bitcode/Writer/EmbedBitcodePass.cpp
  llvm/lib/Object/ObjectFile.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/test/Bitcode/embed-multiple.ll
  llvm/test/Bitcode/embed-unsupported-object-format.ll
  llvm/test/Bitcode/embed.ll

Index: llvm/test/Bitcode/embed.ll
===
--- /dev/null
+++ llvm/test/Bitcode/embed.ll
@@ -0,0 +1,7 @@
+; RUN: opt --mtriple x86_64-unknown-linux-gnu < %s -passes=embed-bitcode -S | FileCheck %s
+
+@a = global i32 1
+
+; CHECK: @a = global i32 1
+; CHECK: @llvm.embedded.module = private constant {{.*}}, section ".llvm.lto", align 1
+; CHECK: @llvm.compiler.used = appending global [1 x ptr] [ptr @llvm.embedded.module], section "llvm.metadata"
Index: llvm/test/Bitcode/embed-unsupported-object-format.ll
===
--- /dev/null
+++ llvm/test/Bitcode/embed-unsupported-object-format.ll
@@ -0,0 +1,5 @@
+; RUN: not --crash opt --mtriple powerpc64-unknown-aix < %s -passes=embed-bitcode -S 2>&1 | FileCheck %s
+
+@a = global i32 1
+
+; CHECK: LLVM ERROR: Embed bitcode pass currently only supports ELF object format
Index: llvm/test/Bitcode/embed-multiple.ll
===
--- /dev/null
+++ llvm/test/Bitcode/embed-multiple.ll
@@ -0,0 +1,6 @@
+; RUN: not --crash opt --mtriple x86_64-unknown-linux-gnu < %s -passes=embed-bitcode -S 2>&1 | FileCheck %s
+
+@a = global i32 1
+@llvm.embedded.module = private constant [4 x i8] c"BC\C0\DE"
+
+; CHECK: LLVM ERROR: Can only embed the module once.
Index: llvm/lib/Passes/PassRegistry.def
===
--- llvm/lib/Passes/PassRegistry.def
+++ llvm/lib/Passes/PassRegistry.def
@@ -58,6 +58,7 @@
 MODULE_PASS("dot-callgraph", CallGraphDOTPrinterPass())
 MODULE_PASS("elim-avail-extern", EliminateAvailableExternallyPass())
 MODULE_PASS("extract-blocks", BlockExtractorPass({}, false))
+MODULE_PASS("embed-bitcode", EmbedBitcodePass())
 MODULE_PASS("forceattrs", ForceFunctionAttrsPass())
 MODULE_PASS("function-import", FunctionImportPass())
 MODULE_PASS("globaldce", GlobalDCEPass())
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -73,6 +73,7 @@
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
 #include "llvm/Analysis/UniformityAnalysis.h"
+#include "llvm/Bitcode/EmbedBitcodePass.h"
 #include "llvm/CodeGen/HardwareLoops.h"
 #include "llvm/CodeGen/TypePromotion.h"
 #include "llvm/IR/DebugInfo.h"
Index: llvm/lib/Object/ObjectFile.cpp
===
--- llvm/lib/Object/ObjectFile.cpp
+++ llvm/lib/Object/ObjectFile.cpp
@@ -79,7 +79,7 @@
 bool ObjectFile::isSectionBitcode(DataRefImpl Sec) const {
   Expected NameOrErr = getSectionName(Sec);
   if (NameOrErr)
-return *NameOrErr == ".llvmbc";
+return *NameOrErr == ".llvmbc" || *NameOrErr == ".llvm.lto";
   consumeError(NameOrErr.takeError());
   return false;
 }
Index: llvm/lib/Bitcode/Writer/EmbedBitcodePass.cpp
===
--- /dev/null
+++ llvm/lib/Bitcode/Writer/EmbedBitcodePass.cpp
@@ -0,0 +1,52 @@
+//===- EmbedBitcodePass.cpp - Pass that embeds the bitcode into a global---===//
+//
+// Part of the LLVM Project, under the Apa

[PATCH] D144115: [clang] Extend pragma dump to support expressions

2023-02-23 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added a comment.

Thank you for reviewing this!

In D144115#4147440 , @aaron.ballman 
wrote:

> You should add test coverage for the changes, especially around things like 
> dependent expressions, ADL use, etc. Also, the changes need a release note 
> and the new functionality should be explicitly documented.

Despite having a dozen of `#pragma __debug` directives, none of them are tested 
neither mentioned in any kind of documentation, including release notes. Are 
you sure about this? If so, what is the right place to put them into?




Comment at: clang/lib/Parse/ParsePragma.cpp:724-728
+ExprResult E = ParseExpression();
+if (!E.isInvalid()) {
+  E.get()->dump();
+}
+SkipUntil(tok::eod, StopBeforeMatch);

aaron.ballman wrote:
> I think you should have another variant of `ActOnPragmaDump` that does the 
> actual dumping, instead of doing it from the parser. I think we should not 
> try to dump a dependent expression (to support those, I think we need to 
> create a new AST node for the pragma so that we can transform it from 
> TreeTransform.h and perform the dump on the non-dependent expression -- not 
> certain if we want to handle that now, or if we want it to be an error to use 
> this pragma with a dependent expression).
> I think you should have another variant of `ActOnPragmaDump` that does the 
> actual dumping, instead of doing it from the parser.

Would it be fine to do it like this: `Actions.ActOnPragmaDump(E)`, where `E` is 
the result of `ParseExpression()`?

> I think we should not try to dump a dependent expression (to support those, I 
> think we need to create a new AST node for the pragma so that we can 
> transform it from TreeTransform.h and perform the dump on the non-dependent 
> expression -- not certain if we want to handle that now, or if we want it to 
> be an error to use this pragma with a dependent expression).

As I mentioned in summary, dependent expressions are out of scope of this 
patch. How can I test whether expression is dependent?





Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144115

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


[PATCH] D143524: Make the -Wunused-template default.

2023-02-23 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

In D143524#4148006 , @philnik wrote:

> The emitted warnings from the libc++ CI look like a false-positive to me. 
> While the functions are never called, they are used in an unevaluated 
> context. I would expect `-Wunused` warnings to only be emitted when I can 
> just remove the code without problems, which doesn't seem to be the case 
> here. It would probably just get turned off again by lots of people if there 
> are too many false-positives, which I don't think is the goal here.

From what I see is that most of the templates are marked with static which 
means internal linkage. Entities with internal linkage in header files are 
essentially different across translation units which is an ODR violation. I 
believe the discussion here gives more insights of how this works: 
https://reviews.llvm.org/D29877

Indeed the warning is noisy but it will potentially fix broken code which were 
unable to diagnose before. Especially that in some cases where static templates 
in header files are used as an idiom. In theory this approach can extend to 
cases described in https://wg21.link/p2691 where our inability to diagnose/fix 
these cases leads to some design decisions which may not be optimal.


Repository:
  rC Clang

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

https://reviews.llvm.org/D143524

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


[PATCH] D144218: [Clang] [AVR] Fix USHRT_MAX for 16-bit int.

2023-02-23 Thread Daniel Thornburgh via Phabricator via cfe-commits
mysterymath marked an inline comment as done.
mysterymath added inline comments.



Comment at: clang/lib/Headers/limits.h:55
 #define UCHAR_MAX (__SCHAR_MAX__*2  +1)
-#define USHRT_MAX (__SHRT_MAX__ *2  +1)
+#define USHRT_MAX (__SHRT_MAX__ * 2U + 1U)
 #define UINT_MAX  (__INT_MAX__  *2U +1U)

aaron.ballman wrote:
> mysterymath wrote:
> > aaron.ballman wrote:
> > > It's worth double-checking that this still gives the correct type for the 
> > > macro:
> > > 
> > > C2x 5.2.4.2.1p2: For all unsigned integer types for which  or 
> > >  define a macro with suffix _WIDTH holding its width N, there 
> > > is a macro with suffix _MAX holding the maximal value 2N − 1 that is 
> > > representable by the type and that has the same type as would an 
> > > expression that is an object of the corresponding type converted 
> > > according to the integer promotions. ...
> > Ah, thanks; it hadn't occurred to me that the type of the expression would 
> > be specified in the standard. It could be either `unsigned int` or `int`, 
> > depending on the target.
> > 
> > The most straightforward approach I could think of to produce the right 
> > type is:
> > 1) Perform the arithmetic in `unsigned int` to produce the right value
> > 2) Cast to `unsigned short` to produce the right type
> > 3) Directly perform integer promotion using unary plus
> > 
> > The use of unary plus is a bit odd here, but it seems like the most direct 
> > way to express the logic, and the overall expression seems less fragile 
> > than the `#if` alternative. I've added a comment to explain this as well.
> Now the trouble is with the cast operation, because that runs afoul of 
> 5.2.4.2.1p1: The values given below shall be replaced by constant expressions 
> suitable for use in conditional expression inclusion preprocessing 
> directives. ...
> 
> https://godbolt.org/z/K9cs66sdK
> 
> I'm almost wondering if the most direct solution is for `__SHRT_MAX__` to be 
> generated with or without the `U` suffix depending on target.
> 
> We should probably use this as an opportunity to add more exhaustive testing 
> for all the _MIN and _MAX macros to ensure the type properties hold. I was 
> playing around with something like this: https://godbolt.org/z/o7KjY3asW
> Now the trouble is with the cast operation, because that runs afoul of 
> 5.2.4.2.1p1: The values given below shall be replaced by constant expressions 
> suitable for use in conditional expression inclusion preprocessing 
> directives. ...
> 
> https://godbolt.org/z/K9cs66sdK
> 
Sigh, it appears my standards-fu is not strong. I'm rather surprised to find 
that you can't cast to an integer type in `#if`; 6.10.1.6 claim they take a 
`constant-expression`, evaluated according to 6.6. But I can't find anything in 
6.6 that seems to exclude cast operators. The definition of integer constant 
expressions even specifically calls out casts to integer types, although it 
doesn't specifically say in 6.10.1.6 that it takes an integer constant 
expression.
Would you happen to know off-hand what my mistake is?

I think the `#if` version I had originally isn't subject to this; I'll switch 
back to that. 

> I'm almost wondering if the most direct solution is for `__SHRT_MAX__` to be 
> generated with or without the `U` suffix depending on target.
Seems like that wouldn't work for the more straightforward case of `#define 
SHRT_MAX __SHRT_MAX__`; the type of this must always be int, since SHRT_MAX is 
always representable in int, even on 16-bit targets.
 
> We should probably use this as an opportunity to add more exhaustive testing 
> for all the _MIN and _MAX macros to ensure the type properties hold. I was 
> playing around with something like this: https://godbolt.org/z/o7KjY3asW
Agree; I think a slight modification to the type test macros I added to the 
limits.cpp test can accomodate this. Seems like it would also be a good idea to 
verify 5.2.4.2.1p1 directly by using the values in the preprocessor.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144218

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


[PATCH] D131618: [WIP][Do NOT review] LLD related changes for -ffat-lto-objects support

2023-02-23 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth commandeered this revision.
paulkirth edited reviewers, added: arda; removed: paulkirth.
paulkirth added a comment.

I'll be updating this patch soon with a rebased version. Likely that will need 
to be split up into a series of smaller patches.

There is also some design work that needs to be addressed. Primarily around 
how/when bitcode sections are emitted and object code generated. It may also be 
necessary to revisit some of the details in its LLD support, given changes to 
the codebase since the original patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131618

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


[PATCH] D144599: [clangd/index/remote]NFC: Adapt code to newer grpc/protobuf versions

2023-02-23 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB updated this revision to Diff 499909.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144599

Files:
  clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp


Index: clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
===
--- clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
+++ clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
@@ -67,8 +67,9 @@
   google::protobuf::util::MessageToJsonString(Response, &Output, Options);
   if (!JsonStatus.ok()) {
 clang::clangd::elog("Can not convert response ({0}) to JSON ({1}): {2}\n",
-Response.DebugString(), JsonStatus.error_code(),
-JsonStatus.error_message().as_string());
+Response.DebugString(),
+static_cast(JsonStatus.code()),
+JsonStatus.message().as_string());
 return -1;
   }
   llvm::outs() << Output;


Index: clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
===
--- clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
+++ clang-tools-extra/clangd/index/remote/monitor/Monitor.cpp
@@ -67,8 +67,9 @@
   google::protobuf::util::MessageToJsonString(Response, &Output, Options);
   if (!JsonStatus.ok()) {
 clang::clangd::elog("Can not convert response ({0}) to JSON ({1}): {2}\n",
-Response.DebugString(), JsonStatus.error_code(),
-JsonStatus.error_message().as_string());
+Response.DebugString(),
+static_cast(JsonStatus.code()),
+JsonStatus.message().as_string());
 return -1;
   }
   llvm::outs() << Output;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D143524: Make the -Wunused-template default.

2023-02-23 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik added a comment.

The emitted warnings from the libc++ CI look like a false-positive to me. While 
the functions are never called, they are used in an unevaluated context. I 
would expect `-Wunused` warnings to only be emitted when I can just remove the 
code without problems, which doesn't seem to be the case here. It would 
probably just get turned off again by lots of people if there are too many 
false-positives, which I don't think is the goal here.


Repository:
  rC Clang

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

https://reviews.llvm.org/D143524

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


[PATCH] D143418: [libclang] Add API to set preferred temp dir path

2023-02-23 Thread Igor Kushnir via Phabricator via cfe-commits
vedgy added a comment.

In D143418#4147578 , @aaron.ballman 
wrote:

> In D143418#4131156 , @vedgy wrote:
>
>> On second thought, the proposed `clang_getDefaultGlobalOptions()` API 
>> already offers users a choice to either prefer or override each option value 
>> from the env. variables, just like the existing 
>> `clang_CXIndex_[gs]etGlobalOptions` API. The environment variables are 
>> binary options: an existence, not value, of an env. variable determines an 
>> initial option value. So I don't understand what are the two different ways 
>> to expose these options.
>
> I was thinking of the env variable as determining the initial option value, 
> so the two options I saw were "the the env variable provides the final 
> resulting value used by the program" and "the env variable provides the 
> default value used by the program". But you're right, the current behavior is 
> that the presence of the env variable determines the behavior, not the value 
> of the env variable.
>
> The question really boils down to: if the user passes in an option which says 
> "don't use thread background priority" to the call to create index, AND there 
> is an environment variable saying "use thread background priority", who 
> should win? And does the answer differ if the option says "use thread 
> background priority" and the environment variable does not exist?

The purpose of adding the `GlobalOptions` member to `CXIndexOptions` and 
deprecating `clang_CXIndex_setGlobalOptions` is to improve libclang's thread 
safety. The proposed approach keeps the meaning of the environment variables 
and enables straightforward porting of existing uses.

If someone decides to prioritize API users vs environment variables 
differently, then new 3-state (unset, disabled, enabled) environment variables 
could be introduced and (possibly) the existing ones deprecated. Such a change 
may require deprecating the proposed `clang_getDefaultGlobalOptions()` API 
addition and introducing a more informative replacement.

The question is whether such environment variable behavior changes are likely 
to be proposed any time soon and how important is this possibility compared to 
the potential thread safety improvement. I suppose if no one has proposed such 
environment variable changes yet, then the current behavior works well enough 
for all libclang users. Just searched for `LIBCLANG_BGPRIO_INDEX`, 
`LIBCLANG_BGPRIO_EDIT`, `CXGlobalOpt_ThreadBackgroundPriorityForIndexing`, 
`CXGlobalOpt_ThreadBackgroundPriorityForEditing`, 
`clang_CXIndex_setGlobalOptions` and `clang_CXIndex_getGlobalOptions` on the 
LLVM Project's issue tracker. Found no results for any of these strings.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143418

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


[PATCH] D144599: [clangd/index/remote]NFC: Adapt code to newer grpc/protobuf versions

2023-02-23 Thread Matthias Braun via Phabricator via cfe-commits
MatzeB added a comment.

> Asking as it'd be great to know that we've adoption here, outside of 
> ourselves.

I'm not involved in any of this myself. But @kuganv is :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144599

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


[PATCH] D143524: Make the -Wunused-template default.

2023-02-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: libc++.
aaron.ballman added a comment.

Precommit CI shows issues with the libc++ tests that need to be addressed. This 
should also come with a release note.




Comment at: clang/test/SemaCXX/warn-func-not-needed.cpp:13
 namespace test1_template {
-template  static void f() {}
+template  static void f() {} // expected-warning {{unused function 
template}}
 template <> void f() {} // expected-warning {{function 'f' is not 
needed and will not be emitted}}

Why is this unused? `f()` in `foo()` should cause this to be used, right?

How should a user silence this diagnostic without disabling it entirely?


Repository:
  rC Clang

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

https://reviews.llvm.org/D143524

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


[PATCH] D144616: Skip generating this[:1] map info for non-member variable.

2023-02-23 Thread Jennifer Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1b72a3276243: Skip using this[:1] map info for non-member 
variable. (authored by jyu2).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144616

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_map_member_expr_codegen.cpp
  openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Index: openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
===
--- openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
+++ openmp/libomptarget/test/mapping/target_map_for_member_data.cpp
@@ -55,6 +55,26 @@
 { res = A + B; }
   }
 };
+struct descriptor {
+  int A;
+  int C;
+};
+
+class BASE {};
+
+class C : public BASE {
+public:
+  void bar(descriptor &d) {
+auto Asize = 4;
+auto Csize = 4;
+
+#pragma omp target data map(to : d.A) map(from : d.C)
+{
+#pragma omp target teams firstprivate(Csize)
+  d.C = 1;
+}
+  }
+};
 
 int main(int argc, char *argv[]) {
   B b(2, 3);
@@ -65,4 +85,10 @@
   c.run();
   // CHECK: 5
   printf("c.res = %d \n", c.res);
+
+  descriptor d;
+  C z;
+  z.bar(d);
+  // CHECK 1
+  printf("%d\n", d.C);
 }
Index: clang/test/OpenMP/target_map_member_expr_codegen.cpp
===
--- clang/test/OpenMP/target_map_member_expr_codegen.cpp
+++ clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -1,20 +1,11 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex "__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" "pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
 // RUN:  -x c++ -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - \
 // RUN:   | FileCheck %s
 
 // expected-no-diagnostics
 
-// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
-// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
 
-// CHECK-LABEL: define {{[^@]+}}@_Z3foov(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
-// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
-// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
-// CHECK-NEXT:ret void
-//
 class A {
 protected:
   int X;
@@ -29,28 +20,91 @@
   using A::Y;
 public:
   int res;
-// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii(
+  B (int x, int y) : A(x,y), res{0} {}
+  void run (void) {
+  #pragma omp target
+ res = X + Y;
+  }
+};
+
+template
+struct descriptor
+{
+  T *A;
+  T *C;
+  T *C_ref;
+  unsigned M;
+  unsigned K;
+  unsigned N;
+};
+
+class BASE
+{
+};
+
+//template
+class C : public BASE
+{
+public:
+  void bar (descriptor &d)
+  {
+ auto Asize = d.M * d.K;
+ auto Csize = d.M * d.N;
+ #pragma omp target data map(to:d.A[0:Asize]) map(from:d.C[0:Csize])
+ {
+   #pragma omp target teams firstprivate(Csize)
+   for (int i = 0; i < Csize; ++i)
+  d.C[i] = 1;
+ }
+   }
+};
+
+void foo() {
+  B b(2, 3);
+  b.run();
+  C c;
+  descriptor d;
+  c.bar(d);
+}
+// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, i64 4, i64 4, i64 4]
+// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 0, i64 4, i64 4, i64 4]
+
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
+// CHECK-NEXT:[[C:%.*]] = alloca [[CLASS_C:%.*]], align 1
+// CHECK-NEXT:[[D:%.*]] = alloca [[STRUCT_DESCRIPTOR:%.*]], align 8
+// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
+// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 dereferenceable(12) [[B]])
+// CHECK-NEXT:call void @_ZN1C3barER10descriptorIfE(ptr noundef nonnull align 1 dereferenceable(1) [[C]], ptr noundef nonnull align 8 dereferenceable(40) [[D]])
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(12) [[THIS:%.*]], i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) unnamed_addr #[[ATTR1:[0-9]+]] comdat align 2 {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[THIS_ADDR:%.*]] = alloca ptr, align 8
 // CHECK-NEXT:[[X_ADDR:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[Y_ADDR:%.*]] = alloca i32, align 4
-// CHECK-NEXT:store ptr [[THIS:%.*]], ptr [[THIS_ADDR]], align 8
-// CHECK-NEXT:

[clang] 1b72a32 - Skip using this[:1] map info for non-member variable.

2023-02-23 Thread Jennifer Yu via cfe-commits

Author: Jennifer Yu
Date: 2023-02-23T09:27:56-08:00
New Revision: 1b72a32762436aad1b7064a8d44681300fd8e380

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

LOG: Skip using this[:1] map info for non-member variable.

This fix runtime problem due to generate this[:1] map info for non member
variable.
To fix this check VD, if VD is not null, it is not member from current
or base classes.

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/target_map_member_expr_codegen.cpp
openmp/libomptarget/test/mapping/target_map_for_member_data.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 2d762c6eb17c7..ff2e9423b6b2e 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -8455,7 +8455,8 @@ class MappableExprsHandler {
 const CXXMethodDecl *MD =
 CGF.CurFuncDecl ? dyn_cast(CGF.CurFuncDecl) : nullptr;
 const CXXRecordDecl *RD = MD ? MD->getParent() : nullptr;
-bool HasBaseClass = RD ? RD->getNumBases() > 0 : false;
+// When VD is not null, it is not field of class, skip generating this[:1].
+bool HasBaseClass = RD && !VD ? RD->getNumBases() > 0 : false;
 // There should not be a mapper for a combined entry.
 if (HasBaseClass) {
   // OpenMP 5.2 148:21:

diff  --git a/clang/test/OpenMP/target_map_member_expr_codegen.cpp 
b/clang/test/OpenMP/target_map_member_expr_codegen.cpp
index c4dace141fc4d..fa47fcee41a4c 100644
--- a/clang/test/OpenMP/target_map_member_expr_codegen.cpp
+++ b/clang/test/OpenMP/target_map_member_expr_codegen.cpp
@@ -1,20 +1,11 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --function-signature --include-generated-funcs --replace-value-regex 
"__omp_offloading_[0-9a-z]+_[0-9a-z]+" "reduction_size[.].+[.]" 
"pl_cond[.].+[.|,]" --prefix-filecheck-ir-name _
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-targets=x86_64-pc-linux-gnu  \
 // RUN:  -x c++ -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - \
 // RUN:   | FileCheck %s
 
 // expected-no-diagnostics
 
-// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, 
i64 4, i64 4, i64 4]
-// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 
0, i64 4, i64 4, i64 4]
 
-// CHECK-LABEL: define {{[^@]+}}@_Z3foov(
-// CHECK-NEXT:  entry:
-// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
-// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 
dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
-// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 
dereferenceable(12) [[B]])
-// CHECK-NEXT:ret void
-//
 class A {
 protected:
   int X;
@@ -29,28 +20,91 @@ class B : public A {
   using A::Y;
 public:
   int res;
-// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii(
+  B (int x, int y) : A(x,y), res{0} {}
+  void run (void) {
+  #pragma omp target
+ res = X + Y;
+  }
+};
+
+template
+struct descriptor
+{
+  T *A;
+  T *C;
+  T *C_ref;
+  unsigned M;
+  unsigned K;
+  unsigned N;
+};
+
+class BASE
+{
+};
+
+//template
+class C : public BASE
+{
+public:
+  void bar (descriptor &d)
+  {
+ auto Asize = d.M * d.K;
+ auto Csize = d.M * d.N;
+ #pragma omp target data map(to:d.A[0:Asize]) map(from:d.C[0:Csize])
+ {
+   #pragma omp target teams firstprivate(Csize)
+   for (int i = 0; i < Csize; ++i)
+  d.C[i] = 1;
+ }
+   }
+};
+
+void foo() {
+  B b(2, 3);
+  b.run();
+  C c;
+  descriptor d;
+  c.bar(d);
+}
+// CHECK: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 12, 
i64 4, i64 4, i64 4]
+// CHECK-NOT: @.offload_sizes = private unnamed_addr constant [4 x i64] [i64 
0, i64 4, i64 4, i64 4]
+
+// CHECK-LABEL: define {{[^@]+}}@_Z3foov
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[B:%.*]] = alloca [[CLASS_B:%.*]], align 4
+// CHECK-NEXT:[[C:%.*]] = alloca [[CLASS_C:%.*]], align 1
+// CHECK-NEXT:[[D:%.*]] = alloca [[STRUCT_DESCRIPTOR:%.*]], align 8
+// CHECK-NEXT:call void @_ZN1BC1Eii(ptr noundef nonnull align 4 
dereferenceable(12) [[B]], i32 noundef 2, i32 noundef 3)
+// CHECK-NEXT:call void @_ZN1B3runEv(ptr noundef nonnull align 4 
dereferenceable(12) [[B]])
+// CHECK-NEXT:call void @_ZN1C3barER10descriptorIfE(ptr noundef nonnull 
align 1 dereferenceable(1) [[C]], ptr noundef nonnull align 8 
dereferenceable(40) [[D]])
+// CHECK-NEXT:ret void
+//
+//
+// CHECK-LABEL: define {{[^@]+}}@_ZN1BC1Eii
+// CHECK-SAME: (ptr noundef nonnull align 4 dereferenceable(12) [[THIS:%.*]], 
i32 no

[PATCH] D143560: clang-format.el: fix warnings

2023-02-23 Thread Augustin Fabre via Phabricator via cfe-commits
augfab added a comment.

Hi @phst , is anything left for me to do before this patch is merged?
This is my first patch to LLVM so I'm not too familiar with the process.
Thanks for your help 🙂


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

https://reviews.llvm.org/D143560

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


[PATCH] D127910: [Clang][AArch64][SME] Add vector load/store (ld1/st1) intrinsics

2023-02-23 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin accepted this revision.
kmclaughlin added a comment.
This revision is now accepted and ready to land.

Thank you for checking and removing EltTypeBool128. I think you have addressed 
all of the other comments on this patch too, so it looks good to me!

Please can you update the commit message before landing, to change the 
reference to `arm_sme_experimental.h` with 
`arm_sme_draft_spec_subject_to_change.h`?




Comment at: clang/lib/CodeGen/CGBuiltin.cpp:8874
   case SVETypeFlags::EltTyBool64:
+  case SVETypeFlags::EltTyBool128:
 return Builder.getInt1Ty();

bryanpkc wrote:
> kmclaughlin wrote:
> > Is it necessary to add an `EltTypeBool128`? I think the 
> > EmitSVEPredicateCast call in EmitSMELd1St1 is creating a vector based on 
> > the memory element type and not the predicate type?
> You are right, `EltTypeBool128` is not used right now; I can remove it. When 
> we started working on the pre-ACLE intrinsics in our downstream compiler, we 
> were planning to add something like `svptrue_b128`, even though the hardware 
> `PTRUE` instruction doesn't support the Q size specifier. It is still not 
> clear to me how the ACLE wants users to create a predicate vector for a call 
> to a `_za128` intrinsic.
I think the reason why `svptrue_b128` wasn't added is because there is no 
`ptrue.q` instruction as you say, and it is possible to use any of the other 
forms (.b, .h, etc) with the 128 bit instructions since they only require every 
16th lane.
It would be possible for the user to create a 128 bit predicate with either 
svunpk or svzip of svbool_t with pfalse where necessary. Otherwise using the 
other forms, e.g `svptrue_b64()`, will achieve the same result and require 
fewer instructions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127910

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


[PATCH] D141569: [clang-tidy] Implement CppCoreGuideline F.18

2023-02-23 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

In D141569#4147268 , @ccotter wrote:

> Trivial types should not be passed by rvalue reference, but by value per the 
> diagram under 
> http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#fcall-parameter-passing.
>  I feel like adding an option to opt-out of this is missing the point of this 
> check, and rvalue references of trivial type should just be fixed rather than 
> adding an option to permit them.

Imaginate that such trivial type could be for example 200KB in size, copy to 
argument, and then from argument to for example class member could be costly. 
Using rvalue allows to pass non const object to some for example function.
I'm asking about option, just because other check also got such option, and if 
both will have one, then user can decide whatever he want to use std::move or 
not.
Still I agree that because we don't lose anything there, moving such trivial 
variable using std::move still would be fine, and at that point checking 
trivial variables in other check could be disabled, that's what I did in my 
project what I was fixing these issues.
So all is up to you.

If else, then maybe it would be good to deliver this check, if something happen 
then before end of release it still could be fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141569

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


[PATCH] D144285: [Clang] Implement CWG2518 - static_assert(false)

2023-02-23 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 499898.
cor3ntin added a comment.

I played with different diagnostics, we already specialize the
literal case, and I didn't find that not saying a static_assert
failed improved things.
Instead, printing, in addition of that diagnostic, an instantiation
stack provides additional useful information.
(The stack is only printed for the literal bool/integer case)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144285

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/drs/dr25xx.cpp
  clang/test/SemaCXX/access-base-class.cpp
  clang/test/SemaCXX/coroutines-exp-namespace.cpp
  clang/test/SemaCXX/coroutines.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/test/SemaTemplate/instantiate-var-template.cpp
  clang/test/SemaTemplate/instantiation-dependence.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -14915,7 +14915,7 @@
 https://wg21.link/cwg2518";>2518
 review
 Conformance requirements and #error/#warning
-Not resolved
+Clang 17
   
   
 https://wg21.link/cwg2519";>2519
Index: clang/test/SemaTemplate/instantiation-dependence.cpp
===
--- clang/test/SemaTemplate/instantiation-dependence.cpp
+++ clang/test/SemaTemplate/instantiation-dependence.cpp
@@ -37,8 +37,8 @@
   template using indirect_void_t = typename indirect_void_t_imp::type;
 
   template void foo() {
-static_assert(!__is_void(indirect_void_t)); // "ok", dependent
-static_assert(!__is_void(void_t)); // expected-error {{failed}}
+int check1[__is_void(indirect_void_t) == 0 ? 1 : -1]; // "ok", dependent
+int check2[__is_void(void_t) == 0 ? 1 : -1]; // expected-error {{array with a negative size}}
   }
 }
 
Index: clang/test/SemaTemplate/instantiate-var-template.cpp
===
--- clang/test/SemaTemplate/instantiate-var-template.cpp
+++ clang/test/SemaTemplate/instantiate-var-template.cpp
@@ -31,9 +31,9 @@
   static_assert(b == 1, ""); // expected-note {{in instantiation of}}
 
   template void f() {
-static_assert(a == 0, ""); // expected-error {{static assertion failed due to requirement 'a == 0'}} \
-   // expected-note {{evaluates to '1 == 0'}}
+int check[a == 0 ? 1 : -1]; // expected-error {{array with a negative size}}
   }
+
 }
 
 namespace PR24483 {
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -52,9 +52,11 @@
 
 template struct AlwaysFails {
   // Only give one error here.
-  static_assert(false, ""); // expected-error {{static assertion failed}}
+  static_assert(false, ""); // expected-error 2{{static assertion failed}}
 };
-AlwaysFails alwaysFails;
+AlwaysFails alwaysFails; // expected-note {{instantiation}}
+AlwaysFails alwaysFails2; // expected-note {{instantiation}}
+
 
 template struct StaticAssertProtected {
   static_assert(__is_literal(T), ""); // expected-error {{static assertion failed}}
@@ -217,6 +219,23 @@
 
 static_assert(1 , "") // expected-error {{expected ';' after 'static_assert'}}
 
+namespace DependentAlwaysFalse {
+template 
+struct S {
+  static_assert(false); // expected-error{{static assertion failed}} \
+// expected-warning {{C++17 extension}}
+};
+
+template 
+struct T {
+  static_assert(false, "test"); // expected-error{{static assertion failed: test}}
+};
+
+int f() {
+  S s; //expected-note{{in instantiation of template class 'DependentAlwaysFalse::S' requested here}}
+  T t; //expected-note{{in instantiation of template class 'DependentAlwaysFalse::T' requested here}}
+}
+}
 
 namespace Diagnostics {
   /// No notes for literals.
Index: clang/test/SemaCXX/coroutines.cpp
===
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -1309,7 +1309,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected-note 2{{requested here}}
 template CoroMemberTag DepTestType::test_member_template(long, const char *) const &&;
 
 template CoroMemberTag DepTestType::test_static_template(const char *volatile &, unsigned);
Index: clang/test/SemaCXX/coroutines-exp-namespace.cpp
===
--- clang/test/SemaCXX/coroutines-exp-namespace.cpp
+++ clang/test/SemaCXX/coroutines-exp-namespace.cpp
@@ -1288,7 +1288,7 @@
   }
 };
 
-template struct DepTestType; // expected-note {{requested here}}
+template struct DepTestType; // expected

[PATCH] D144654: [Lex] Warn when defining or undefining any builtin macro

2023-02-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: rsmith, jansvoboda11, rjmccall.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Currently we warn when MI->isBuiltinMacro, but this is only true for builtin 
macros that require processing when expanding. Checking 
SourceMgr.isWrittenInBuiltinFile in addition to this will mean that we catch 
all builtin macros.

As part of doing this I've also moved the handling of undefining from 
CheckMacroName to HandleUndefDirective, as it doesn't really make sense to 
handle undefining in CheckMacroName but defining in HandleDefineDirective. It 
would be nice to instead handle both in CheckMacroName, but that isn't possible 
as the handling of defines requires looking at what the name is being defined 
to.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144654

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/macro-reserved.c
  clang/test/Preprocessor/macro-reserved.cpp

Index: clang/test/Preprocessor/macro-reserved.cpp
===
--- clang/test/Preprocessor/macro-reserved.cpp
+++ clang/test/Preprocessor/macro-reserved.cpp
@@ -12,7 +12,7 @@
 #undef _HAVE_X
 #undef X__Y
 
-#undef __cplusplus
+#undef __cplusplus // expected-warning {{undefining builtin macro}}
 #define __cplusplus
 
 // allowlisted definitions
Index: clang/test/Preprocessor/macro-reserved.c
===
--- clang/test/Preprocessor/macro-reserved.c
+++ clang/test/Preprocessor/macro-reserved.c
@@ -6,6 +6,7 @@
 #define __cplusplus
 #define _HAVE_X 0
 #define X__Y
+#define __STDC__ 1 // expected-warning {{redefining builtin macro}}
 
 #undef for
 #undef final
@@ -13,6 +14,7 @@
 #undef __cplusplus
 #undef _HAVE_X
 #undef X__Y
+#undef __STDC_HOSTED__ // expected-warning {{undefining builtin macro}}
 
 // allowlisted definitions
 #define while while
Index: clang/lib/Lex/PPDirectives.cpp
===
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -319,15 +319,6 @@
 return Diag(MacroNameTok, diag::err_defined_macro_name);
   }
 
-  if (isDefineUndef == MU_Undef) {
-auto *MI = getMacroInfo(II);
-if (MI && MI->isBuiltinMacro()) {
-  // Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4
-  // and C++ [cpp.predefined]p4], but allow it as an extension.
-  Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);
-}
-  }
-
   // If defining/undefining reserved identifier or a keyword, we need to issue
   // a warning.
   SourceLocation MacroNameLoc = MacroNameTok.getLocation();
@@ -3004,6 +2995,14 @@
   MI->setTokens(Tokens, BP);
   return MI;
 }
+
+static bool isObjCProtectedMacro(const IdentifierInfo *II) {
+  return II->isStr("__strong") ||
+ II->isStr("__weak") ||
+ II->isStr("__unsafe_unretained") ||
+ II->isStr("__autoreleasing");
+}
+
 /// HandleDefineDirective - Implements \#define.  This consumes the entire macro
 /// line then lets the caller lex the next real token.
 void Preprocessor::HandleDefineDirective(
@@ -3075,13 +3074,7 @@
 // In Objective-C, ignore attempts to directly redefine the builtin
 // definitions of the ownership qualifiers.  It's still possible to
 // #undef them.
-auto isObjCProtectedMacro = [](const IdentifierInfo *II) -> bool {
-  return II->isStr("__strong") ||
- II->isStr("__weak") ||
- II->isStr("__unsafe_unretained") ||
- II->isStr("__autoreleasing");
-};
-   if (getLangOpts().ObjC &&
+if (getLangOpts().ObjC &&
 SourceMgr.getFileID(OtherMI->getDefinitionLoc())
   == getPredefinesFileID() &&
 isObjCProtectedMacro(MacroNameTok.getIdentifierInfo())) {
@@ -3107,7 +3100,8 @@
 
   // Warn if defining "__LINE__" and other builtins, per C99 6.10.8/4 and
   // C++ [cpp.predefined]p4, but allow it as an extension.
-  if (OtherMI->isBuiltinMacro())
+  if (OtherMI->isBuiltinMacro() ||
+  SourceMgr.isWrittenInBuiltinFile(OtherMI->getDefinitionLoc()))
 Diag(MacroNameTok, diag::ext_pp_redef_builtin_macro);
   // Macros must be identical.  This means all tokens and whitespace
   // separation must be the same.  C99 6.10.3p2.
@@ -3187,6 +3181,14 @@
 if (!MI->isUsed() && MI->isWarnIfUnused())
   Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
 
+// Warn if undefining "__LINE__" and other builtins, per C99 6.10.8/4 and
+// C++ [cpp.predefined]p4, but allow it as an extension. Don't warn if this
+// is an Objective-C builtin macro though.
+if ((MI->isBuiltinMacro() ||
+ SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) &&
+!(getLangOpts().ObjC && isObjCProtectedMacro(II)))
+  Diag(MacroNameTok, diag::ext_pp_undef_builtin_m

[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-23 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 499896.
VitaNuo added a comment.

Merge upstream changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143496

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/clangd/unittests/PreambleTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp

Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -49,8 +49,8 @@
   }
 }
 
-static std::string spellHeader(const Header &H, HeaderSearch &HS,
-   const FileEntry *Main) {
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main) {
   switch (H.kind()) {
   case Header::Physical: {
 bool IsSystem = false;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -73,6 +73,8 @@
 std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main);
 } // namespace include_cleaner
 } // namespace clang
 
Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -665,7 +665,7 @@
 TEST(PreamblePatch, DiagnosticsToPreamble) {
   Config Cfg;
   Cfg.Diagnostics.AllowStalePreamble = true;
-  Cfg.Diagnostics.UnusedIncludes = Config::UnusedIncludesPolicy::Strict;
+  Cfg.Diagnostics.UnusedIncludes = Config::IncludesPolicy::Strict;
   WithContextValue WithCfg(Config::Key, std::move(Cfg));
 
   llvm::StringMap AdditionalFiles;
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -8,26 +8,57 @@
 
 #include "Annotations.h"
 #include "Config.h"
+#include "Diagnostics.h"
 #include "IncludeCleaner.h"
+#include "ParsedAST.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "support/Context.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
 using ::testing::IsEmpty;
+using ::testing::Matcher;
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
+Matcher withFix(::testing::Matcher FixMatcher) {
+  return Field(&Diag::Fixes, ElementsAre(FixMatcher));
+}
+
+MATCHER_P2(Diag, Range, Message,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message + "]") {
+  return arg.Range == Range && arg.Message == Message;
+}
+
+MATCHER_P3(Fix, Range, Replacement, Message,
+   "Fix " + llvm::to_string(Range) + " => " +
+   ::testing::PrintToString(Replacement) + " = [" + Message + "]") {
+  return arg.Message == Message && arg.Edits.size() == 1 &&
+ arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
+}
+
 std::string guard(llvm::StringRef Code) {
   return "#pragma once\n" + Code.str();
 }
@@ -342,7 +373,8 @@
   auto AST = TU.build();
   EXPECT_THAT(computeUnusedIncludes(AST),
   ElementsAre(Pointee(writtenInclusion("";
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST),
+  IncludeCleanerFindings Findings = computeInclude

[PATCH] D143509: Move the BySpelling map to IncludeStructure.

2023-02-23 Thread Viktoriia Bakalova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
VitaNuo marked an inline comment as done.
Closed by commit rGe028c9742897: Move the BySpelling map to IncludeStructure. 
(authored by VitaNuo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143509

Files:
  clang-tools-extra/clangd/Headers.cpp
  clang-tools-extra/clangd/Headers.h
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/unittests/HeadersTests.cpp

Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -197,6 +197,36 @@
Distance(getID(BazHeader, Includes), 1u)));
 }
 
+TEST_F(HeadersTest, CacheBySpellingIsBuiltForMainInclusions) {
+  std::string FooHeader = testPath("foo.h");
+  FS.Files[FooHeader] = R"cpp(
+  void foo();
+)cpp";
+  std::string BarHeader = testPath("bar.h");
+  FS.Files[BarHeader] = R"cpp(
+  void bar();
+)cpp";
+  std::string BazHeader = testPath("baz.h");
+  FS.Files[BazHeader] = R"cpp(
+  void baz();
+)cpp";
+  FS.Files[MainFile] = R"cpp(
+#include "foo.h"
+#include "bar.h"
+#include "baz.h"
+)cpp";
+  auto Includes = collectIncludes();
+  EXPECT_THAT(Includes.MainFileIncludes,
+  UnorderedElementsAre(written("\"foo.h\""), written("\"bar.h\""),
+   written("\"baz.h\"")));
+  EXPECT_THAT(Includes.mainFileIncludesWithSpelling("\"foo.h\""),
+  UnorderedElementsAre(&Includes.MainFileIncludes[0]));
+  EXPECT_THAT(Includes.mainFileIncludesWithSpelling("\"bar.h\""),
+  UnorderedElementsAre(&Includes.MainFileIncludes[1]));
+  EXPECT_THAT(Includes.mainFileIncludesWithSpelling("\"baz.h\""),
+  UnorderedElementsAre(&Includes.MainFileIncludes[2]));
+}
+
 TEST_F(HeadersTest, PreambleIncludesPresentOnce) {
   // We use TestTU here, to ensure we use the preamble replay logic.
   // We're testing that the logic doesn't crash, and doesn't result in duplicate
Index: clang-tools-extra/clangd/IncludeCleaner.cpp
===
--- clang-tools-extra/clangd/IncludeCleaner.cpp
+++ clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -85,7 +85,7 @@
 // Using templateName case is handled by the override TraverseTemplateName.
 if (TST->getTemplateName().getKind() == TemplateName::UsingTemplate)
   return true;
-add(TST->getAsCXXRecordDecl());  // Specialization
+add(TST->getAsCXXRecordDecl()); // Specialization
 return true;
   }
 
@@ -474,22 +474,16 @@
   translateToHeaderIDs(ReferencedFiles, AST.getIncludeStructure(), SM);
   return getUnused(AST, ReferencedHeaders, ReferencedFiles.SpelledUmbrellas);
 }
-std::vector computeUnusedIncludesExperimental(ParsedAST &AST) {
-   const auto &SM = AST.getSourceManager();
-   const auto &Includes = AST.getIncludeStructure();
-   // FIXME: this map should probably be in IncludeStructure.
-   llvm::StringMap> BySpelling;
-   for (const auto &Inc : Includes.MainFileIncludes) {
-if (Inc.HeaderID)
-  BySpelling.try_emplace(Inc.Written)
-  .first->second.push_back(
-  static_cast(*Inc.HeaderID));
-   }
-   // FIXME: !!this is a hacky way to collect macro references.
-   std::vector Macros;
-auto& PP = AST.getPreprocessor();
-   for (const syntax::Token &Tok :
-AST.getTokens().spelledTokens(SM.getMainFileID())) {
+std::vector
+computeUnusedIncludesExperimental(ParsedAST &AST) {
+  const auto &SM = AST.getSourceManager();
+  const auto &Includes = AST.getIncludeStructure();
+
+  // FIXME: !!this is a hacky way to collect macro references.
+  std::vector Macros;
+  auto &PP = AST.getPreprocessor();
+  for (const syntax::Token &Tok :
+   AST.getTokens().spelledTokens(SM.getMainFileID())) {
 auto Macro = locateMacroAt(Tok, PP);
 if (!Macro)
   continue;
@@ -499,31 +493,37 @@
include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)),
   DefLoc},
include_cleaner::RefType::Explicit});
-   }
-   llvm::DenseSet Used;
-   include_cleaner::walkUsed(
-   AST.getLocalTopLevelDecls(), /*MacroRefs=*/Macros,
-   AST.getPragmaIncludes(), SM,
-   [&](const include_cleaner::SymbolReference &Ref,
-   llvm::ArrayRef Providers) {
- for (const auto &H : Providers) {
-   switch (H.kind()) {
-   case include_cleaner::Header::Physical:
- if (auto HeaderID = Includes.getID(H.physical()))
-   Used.insert(*HeaderID);
- break;
-   case include_cleaner::Header::Standard:
- for (auto HeaderID : Includes.StdlibHeaders.lookup(H.standard()))
-   Used.insert(HeaderID);
- break;
-   case incl

[clang-tools-extra] e028c97 - Move the BySpelling map to IncludeStructure.

2023-02-23 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-02-23T17:11:31Z
New Revision: e028c9742897cc14c47c426893fb40f571f6fad6

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

LOG: Move the BySpelling map to IncludeStructure.

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

Added: 


Modified: 
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/Headers.h
clang-tools-extra/clangd/IncludeCleaner.cpp
clang-tools-extra/clangd/unittests/HeadersTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Headers.cpp 
b/clang-tools-extra/clangd/Headers.cpp
index 3e5fefb07130..7000c1cbf451 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -16,6 +16,7 @@
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Tooling/Inclusions/HeaderAnalysis.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Path.h"
 #include 
@@ -73,6 +74,8 @@ class IncludeStructure::RecordHeaders : public PPCallbacks,
   IDs.push_back(HID);
   }
   }
+  Out->MainFileIncludesBySpelling.try_emplace(Inc.Written)
+  .first->second.push_back(Out->MainFileIncludes.size() - 1);
 }
 
 // Record include graph (not just for main-file includes)
@@ -294,6 +297,14 @@ IncludeStructure::includeDepth(HeaderID Root) const {
   return Result;
 }
 
+llvm::SmallVector
+IncludeStructure::mainFileIncludesWithSpelling(llvm::StringRef Spelling) const 
{
+  llvm::SmallVector Includes;
+  for (auto Idx : MainFileIncludesBySpelling.lookup(Spelling))
+Includes.push_back(&MainFileIncludes[Idx]);
+  return Includes;
+}
+
 void IncludeInserter::addExisting(const Inclusion &Inc) {
   IncludedHeaders.insert(Inc.Written);
   if (!Inc.Resolved.empty())

diff  --git a/clang-tools-extra/clangd/Headers.h 
b/clang-tools-extra/clangd/Headers.h
index 8a5b885a680e..a21ea851831a 100644
--- a/clang-tools-extra/clangd/Headers.h
+++ b/clang-tools-extra/clangd/Headers.h
@@ -155,13 +155,16 @@ class IncludeStructure {
 return !NonSelfContained.contains(ID);
   }
 
-  bool hasIWYUExport(HeaderID ID) const {
-return HasIWYUExport.contains(ID);
-  }
+  bool hasIWYUExport(HeaderID ID) const { return HasIWYUExport.contains(ID); }
 
   // Return all transitively reachable files.
   llvm::ArrayRef allHeaders() const { return RealPathNames; }
 
+  // Returns includes inside the main file with the given spelling.
+  // Spelling should include brackets or quotes, e.g. .
+  llvm::SmallVector
+  mainFileIncludesWithSpelling(llvm::StringRef Spelling) const;
+
   // Return all transitively reachable files, and their minimum include depth.
   // All transitive includes (absolute paths), with their minimum include 
depth.
   // Root --> 0, #included file --> 1, etc.
@@ -202,6 +205,10 @@ class IncludeStructure {
   // Contains a set of headers that have either "IWYU pragma: export" or "IWYU
   // pragma: begin_exports".
   llvm::DenseSet HasIWYUExport;
+
+  // Maps written includes to indices in MainFileInclude for easier lookup by
+  // spelling.
+  llvm::StringMap> MainFileIncludesBySpelling;
 };
 
 // Calculates insertion edit for including a new header in a file.

diff  --git a/clang-tools-extra/clangd/IncludeCleaner.cpp 
b/clang-tools-extra/clangd/IncludeCleaner.cpp
index 5a7df2fc33f6..d9804abd82ee 100644
--- a/clang-tools-extra/clangd/IncludeCleaner.cpp
+++ b/clang-tools-extra/clangd/IncludeCleaner.cpp
@@ -85,7 +85,7 @@ class ReferencedLocationCrawler
 // Using templateName case is handled by the override TraverseTemplateName.
 if (TST->getTemplateName().getKind() == TemplateName::UsingTemplate)
   return true;
-add(TST->getAsCXXRecordDecl());  // Specialization
+add(TST->getAsCXXRecordDecl()); // Specialization
 return true;
   }
 
@@ -474,22 +474,16 @@ std::vector 
computeUnusedIncludes(ParsedAST &AST) {
   translateToHeaderIDs(ReferencedFiles, AST.getIncludeStructure(), SM);
   return getUnused(AST, ReferencedHeaders, ReferencedFiles.SpelledUmbrellas);
 }
-std::vector computeUnusedIncludesExperimental(ParsedAST 
&AST) {
-   const auto &SM = AST.getSourceManager();
-   const auto &Includes = AST.getIncludeStructure();
-   // FIXME: this map should probably be in IncludeStructure.
-   llvm::StringMap> BySpelling;
-   for (const auto &Inc : Includes.MainFileIncludes) {
-if (Inc.HeaderID)
-  BySpelling.try_emplace(Inc.Written)
-  .first->second.push_back(
-  static_cast(*Inc.HeaderID));
-   }
-   // FIXME: !!this is a hacky way to collect macro references.
-   std::vector Macros;
-auto& PP = AST.getPreprocessor();
-   for (const syntax::Token &Tok :
-AST.getTokens().spelledTokens(SM.getMainFileID()))

[PATCH] D144626: [C++20] [Modules] Provide OriginalTrailingRequiresClause for serializer to perform ODR-Checking correctly

2023-02-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Woops, I just saw my fixme :D  I forgot we needed to do that for comparison of 
constraints.  That said I dont think you need to store it, I think we can just 
pick up the 'original' one from the primary template.  I did work at one point 
to make sure that the get-instantiated-from-template stuff worked correctly for 
friends like that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144626

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


[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-23 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 499886.
VitaNuo added a comment.

Upload once again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143496

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp

Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -49,8 +49,8 @@
   }
 }
 
-static std::string spellHeader(const Header &H, HeaderSearch &HS,
-   const FileEntry *Main) {
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main) {
   switch (H.kind()) {
   case Header::Physical: {
 bool IsSystem = false;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -73,6 +73,8 @@
 std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main);
 } // namespace include_cleaner
 } // namespace clang
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -8,26 +8,57 @@
 
 #include "Annotations.h"
 #include "Config.h"
+#include "Diagnostics.h"
 #include "IncludeCleaner.h"
+#include "ParsedAST.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "support/Context.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
 using ::testing::IsEmpty;
+using ::testing::Matcher;
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
+Matcher withFix(::testing::Matcher FixMatcher) {
+  return Field(&Diag::Fixes, ElementsAre(FixMatcher));
+}
+
+MATCHER_P2(Diag, Range, Message,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message + "]") {
+  return arg.Range == Range && arg.Message == Message;
+}
+
+MATCHER_P3(Fix, Range, Replacement, Message,
+   "Fix " + llvm::to_string(Range) + " => " +
+   ::testing::PrintToString(Replacement) + " = [" + Message + "]") {
+  return arg.Message == Message && arg.Edits.size() == 1 &&
+ arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
+}
+
 std::string guard(llvm::StringRef Code) {
   return "#pragma once\n" + Code.str();
 }
@@ -342,7 +373,8 @@
   auto AST = TU.build();
   EXPECT_THAT(computeUnusedIncludes(AST),
   ElementsAre(Pointee(writtenInclusion("";
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST),
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.UnusedIncludes,
   ElementsAre(Pointee(writtenInclusion("";
 }
 
@@ -379,12 +411,98 @@
   computeUnusedIncludes(AST),
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
+
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
   EXPECT_THAT(
-  computeUnusedIncludesExperimental(AST),
+  Findings.UnusedIncludes,
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
 }
 
+TEST(Includ

[PATCH] D144626: [C++20] [Modules] Provide OriginalTrailingRequiresClause for serializer to perform ODR-Checking correctly

2023-02-23 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I think the problem is more that we are modifying the expression in the AST.  I 
don't think now that we have the 'deferred concepts instantiation' that we 
should be storing/saving the updated requires clause back to the AST, right?  
We should be re-evaluating it (with a cache!).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144626

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


[PATCH] D144651: [Serialization] Place command line defines in the correct file

2023-02-23 Thread John Brawn via Phabricator via cfe-commits
john.brawn created this revision.
john.brawn added reviewers: mstorsjo, jansvoboda11, DHowett-MSFT, sammccall.
Herald added a project: All.
john.brawn requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix two problems happening during deserialization causing command line defines 
to be reported as being built-in defines:

- When deserializing SM_SLOC_BUFFER_ENTRY we need to call setHasLineDirectives 
in the same way as we do for SM_SLOC_FILE_ENTRY.
- When created suggested predefines based on the current command line options 
we need to add line markers in the same way that InitializePreprocessor does.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144651

Files:
  clang/lib/Serialization/ASTReader.cpp
  clang/test/PCH/macro-cmdline.c
  clang/test/PCH/ms-pch-macro.c


Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header 
('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd 
on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in 
precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in 
precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | 
FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -654,6 +654,10 @@
   SmallVector ExistingMacroNames;
   collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
 
+  // Use a line marker to enter the  file, as the defines and
+  // undefines here will have come from the command line.
+  SuggestedPredefines += "# 1 \"\" 1\n";
+
   for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) {
 // Dig out the macro definition in the existing preprocessor options.
 StringRef MacroName = ExistingMacroNames[I];
@@ -713,6 +717,10 @@
 }
 return true;
   }
+
+  // Leave the  file and return to .
+  SuggestedPredefines += "# 1 \"\" 2\n";
+
   if (Validation == OptionValidateStrictMatches) {
 // If strict matches are requested, don't tolerate any extra defines in
 // the AST file that are missing on the command line.
@@ -1579,8 +1587,13 @@
 auto Buffer = ReadBuffer(SLocEntryCursor, Name);
 if (!Buffer)
   return true;
-SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
-   BaseOffset + Offset, IncludeLoc);
+FileID FID = SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID,
+BaseOffset + Offset, IncludeLoc);
+if (Record[3]) {
+  SrcMgr::FileInfo &FileInfo =
+const_cast(SourceMgr.getSLocEntry(FID).getFile());
+  FileInfo.setHasLineDirectives();
+}
 break;
   }
 


Index: clang/test/PCH/ms-pch-macro.c
===
--- clang/test/PCH/ms-pch-macro.c
+++ clang/test/PCH/ms-pch-macro.c
@@ -36,4 +36,4 @@
 // CHECK-FOO: definition of macro 'FOO' differs between the precompiled header ('1') and the command line ('blah')
 // CHECK-NOFOO: macro 'FOO' was defined in the precompiled header but undef'd on the command line
 
-// expected-warning@1 {{definition of macro 'BAR' does not match definition in precompiled header}}
+// expected-warning@2 {{definition of macro 'BAR' does not match definition in precompiled header}}
Index: clang/test/PCH/macro-cmdline.c
===
--- /dev/null
+++ clang/test/PCH/macro-cmdline.c
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 %s -emit-pch -o %t1.pch -DMACRO1=1
+// RUN: %clang_cc1 -fsyntax-only %s -include-pch %t1.pch -DMACRO2=1 2>&1 | FileCheck %s
+
+#ifndef HEADER
+#define HEADER
+#else
+#define MACRO1 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO1' macro redefined
+// CHECK: {{.*}}previous definition is here
+#define MACRO2 2
+// CHECK: macro-cmdline.c{{.*}}'MACRO2' macro redefined
+// CHECK: {{.*}}previous definition is here
+#endif
Index: clang/lib/Serialization/ASTReader.cpp

[PATCH] D144447: [Clang] Teach buildFMulAdd to peek through fneg to find fmul.

2023-02-23 Thread Craig Topper 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 rG83cd4bea015f: [Clang] Teach buildFMulAdd to peek through 
fneg to find fmul. (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D17

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/constrained-math-builtins.c
  clang/test/CodeGen/fp-contract-pragma.cpp

Index: clang/test/CodeGen/fp-contract-pragma.cpp
===
--- clang/test/CodeGen/fp-contract-pragma.cpp
+++ clang/test/CodeGen/fp-contract-pragma.cpp
@@ -89,3 +89,54 @@
   #pragma STDC FP_CONTRACT ON
   return c - a * b;
 }
+
+float fp_contract_10(float a, float b, float c) {
+// CHECK: _Z14fp_contract_10fff
+// CHECK: fneg float %a
+// CHECK: tail call float @llvm.fmuladd
+  #pragma STDC FP_CONTRACT ON
+  return -(a * b) + c;
+}
+
+float fp_contract_11(float a, float b, float c) {
+// CHECK: _Z14fp_contract_11fff
+// CHECK: fneg float %a
+// CHECK: fneg float %c
+// CHECK: tail call float @llvm.fmuladd
+  #pragma STDC FP_CONTRACT ON
+  return -(a * b) - c;
+}
+
+float fp_contract_12(float a, float b, float c) {
+// CHECK: _Z14fp_contract_12fff
+// CHECK: fneg float %a
+// CHECK: tail call float @llvm.fmuladd
+  #pragma STDC FP_CONTRACT ON
+  return c + -(a * b);
+}
+
+float fp_contract_13(float a, float b, float c) {
+// CHECK: _Z14fp_contract_13fff
+// CHECK-NOT: fneg float %a
+// CHECK: tail call float @llvm.fmuladd
+  #pragma STDC FP_CONTRACT ON
+  return c - -(a * b);
+}
+
+float fp_contract_14(float a, float b, float c) {
+// CHECK: _Z14fp_contract_14fff
+// CHECK: %[[M:.+]] = fmul float %a, %b
+// CHECK-NEXT: %add = fsub float %c, %[[M]]
+  #pragma STDC FP_CONTRACT ON
+  float d;
+  return (d = -(a * b)) + c;
+}
+
+float fp_contract_15(float a, float b, float c) {
+// CHECK: _Z14fp_contract_15fff
+// CHECK: %[[M:.+]] = fmul float %a, %b
+// CHECK-NEXT: %add = fsub float %c, %[[M]]
+  #pragma STDC FP_CONTRACT ON
+  float d;
+  return -(d = (a * b)) + c;
+}
Index: clang/test/CodeGen/constrained-math-builtins.c
===
--- clang/test/CodeGen/constrained-math-builtins.c
+++ clang/test/CodeGen/constrained-math-builtins.c
@@ -300,10 +300,17 @@
   f * f + f;
   (double)f * f - f;
   (long double)-f * f + f;
+  -(f * f) - f;
+  f + -(f * f);
 
   // CHECK: call float @llvm.experimental.constrained.fmuladd.f32(float %{{.*}}, float %{{.*}}, float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
   // CHECK: fneg
   // CHECK: call double @llvm.experimental.constrained.fmuladd.f64(double %{{.*}}, double %{{.*}}, double %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
   // CHECK: fneg
   // CHECK: call x86_fp80 @llvm.experimental.constrained.fmuladd.f80(x86_fp80 %{{.*}}, x86_fp80 %{{.*}}, x86_fp80 %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // CHECK: fneg
+  // CHECK: fneg
+  // CHECK: call float @llvm.experimental.constrained.fmuladd.f32(float %{{.*}}, float %{{.*}}, float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
+  // CHECK: fneg
+  // CHECK: call float @llvm.experimental.constrained.fmuladd.f32(float %{{.*}}, float %{{.*}}, float %{{.*}}, metadata !"round.tonearest", metadata !"fpexcept.strict")
 };
Index: clang/lib/CodeGen/CGExprScalar.cpp
===
--- clang/lib/CodeGen/CGExprScalar.cpp
+++ clang/lib/CodeGen/CGExprScalar.cpp
@@ -3734,8 +3734,6 @@
 static Value* buildFMulAdd(llvm::Instruction *MulOp, Value *Addend,
const CodeGenFunction &CGF, CGBuilderTy &Builder,
bool negMul, bool negAdd) {
-  assert(!(negMul && negAdd) && "Only one of negMul and negAdd should be set.");
-
   Value *MulOp0 = MulOp->getOperand(0);
   Value *MulOp1 = MulOp->getOperand(1);
   if (negMul)
@@ -3780,31 +3778,70 @@
   if (!op.FPFeatures.allowFPContractWithinStatement())
 return nullptr;
 
+  Value *LHS = op.LHS;
+  Value *RHS = op.RHS;
+
+  // Peek through fneg to look for fmul. Make sure fneg has no users, and that
+  // it is the only use of its operand.
+  bool NegLHS = false;
+  if (auto *LHSUnOp = dyn_cast(LHS)) {
+if (LHSUnOp->getOpcode() == llvm::Instruction::FNeg &&
+LHSUnOp->use_empty() && LHSUnOp->getOperand(0)->hasOneUse()) {
+  LHS = LHSUnOp->getOperand(0);
+  NegLHS = true;
+}
+  }
+
+  bool NegRHS = false;
+  if (auto *RHSUnOp = dyn_cast(RHS)) {
+if (RHSUnOp->getOpcode() == llvm::Instruction::FNeg &&
+RHSUnOp->use_empty() && RHSUnOp->getOperand(0)->hasOneUse()) {
+  RHS = RHSUnOp->getOperand(0);
+  NegRHS = true;
+}
+  }
+
   // We have a potentially fusable op. Look for a mul on one of the operands.
   // Also, make sure that 

[clang] 83cd4be - [Clang] Teach buildFMulAdd to peek through fneg to find fmul.

2023-02-23 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-02-23T09:05:59-08:00
New Revision: 83cd4bea015feb5729871832784c424b0743a803

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

LOG: [Clang] Teach buildFMulAdd to peek through fneg to find fmul.

Allows us to handle expressions like -(a * b) + c

Based on the examples from D144366 that gcc seems to get.

Reviewed By: kpn

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

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGen/constrained-math-builtins.c
clang/test/CodeGen/fp-contract-pragma.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index a0dcb978b1ac..2243c75ed260 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -3734,8 +3734,6 @@ static Value *emitPointerArithmetic(CodeGenFunction &CGF,
 static Value* buildFMulAdd(llvm::Instruction *MulOp, Value *Addend,
const CodeGenFunction &CGF, CGBuilderTy &Builder,
bool negMul, bool negAdd) {
-  assert(!(negMul && negAdd) && "Only one of negMul and negAdd should be 
set.");
-
   Value *MulOp0 = MulOp->getOperand(0);
   Value *MulOp1 = MulOp->getOperand(1);
   if (negMul)
@@ -3780,31 +3778,70 @@ static Value* tryEmitFMulAdd(const BinOpInfo &op,
   if (!op.FPFeatures.allowFPContractWithinStatement())
 return nullptr;
 
+  Value *LHS = op.LHS;
+  Value *RHS = op.RHS;
+
+  // Peek through fneg to look for fmul. Make sure fneg has no users, and that
+  // it is the only use of its operand.
+  bool NegLHS = false;
+  if (auto *LHSUnOp = dyn_cast(LHS)) {
+if (LHSUnOp->getOpcode() == llvm::Instruction::FNeg &&
+LHSUnOp->use_empty() && LHSUnOp->getOperand(0)->hasOneUse()) {
+  LHS = LHSUnOp->getOperand(0);
+  NegLHS = true;
+}
+  }
+
+  bool NegRHS = false;
+  if (auto *RHSUnOp = dyn_cast(RHS)) {
+if (RHSUnOp->getOpcode() == llvm::Instruction::FNeg &&
+RHSUnOp->use_empty() && RHSUnOp->getOperand(0)->hasOneUse()) {
+  RHS = RHSUnOp->getOperand(0);
+  NegRHS = true;
+}
+  }
+
   // We have a potentially fusable op. Look for a mul on one of the operands.
   // Also, make sure that the mul result isn't used directly. In that case,
   // there's no point creating a muladd operation.
-  if (auto *LHSBinOp = dyn_cast(op.LHS)) {
+  if (auto *LHSBinOp = dyn_cast(LHS)) {
 if (LHSBinOp->getOpcode() == llvm::Instruction::FMul &&
-LHSBinOp->use_empty())
-  return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder, false, isSub);
+(LHSBinOp->use_empty() || NegLHS)) {
+  // If we looked through fneg, erase it.
+  if (NegLHS)
+cast(op.LHS)->eraseFromParent();
+  return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder, NegLHS, isSub);
+}
   }
-  if (auto *RHSBinOp = dyn_cast(op.RHS)) {
+  if (auto *RHSBinOp = dyn_cast(RHS)) {
 if (RHSBinOp->getOpcode() == llvm::Instruction::FMul &&
-RHSBinOp->use_empty())
-  return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub, false);
+(RHSBinOp->use_empty() || NegRHS)) {
+  // If we looked through fneg, erase it.
+  if (NegRHS)
+cast(op.RHS)->eraseFromParent();
+  return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub ^ NegRHS, 
false);
+}
   }
 
-  if (auto *LHSBinOp = dyn_cast(op.LHS)) {
+  if (auto *LHSBinOp = dyn_cast(LHS)) {
 if (LHSBinOp->getIntrinsicID() ==
 llvm::Intrinsic::experimental_constrained_fmul &&
-LHSBinOp->use_empty())
-  return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder, false, isSub);
+(LHSBinOp->use_empty() || NegLHS)) {
+  // If we looked through fneg, erase it.
+  if (NegLHS)
+cast(op.LHS)->eraseFromParent();
+  return buildFMulAdd(LHSBinOp, op.RHS, CGF, Builder, NegLHS, isSub);
+}
   }
-  if (auto *RHSBinOp = dyn_cast(op.RHS)) {
+  if (auto *RHSBinOp = dyn_cast(RHS)) {
 if (RHSBinOp->getIntrinsicID() ==
 llvm::Intrinsic::experimental_constrained_fmul &&
-RHSBinOp->use_empty())
-  return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub, false);
+(RHSBinOp->use_empty() || NegRHS)) {
+  // If we looked through fneg, erase it.
+  if (NegRHS)
+cast(op.RHS)->eraseFromParent();
+  return buildFMulAdd(RHSBinOp, op.LHS, CGF, Builder, isSub ^ NegRHS, 
false);
+}
   }
 
   return nullptr;

diff  --git a/clang/test/CodeGen/constrained-math-builtins.c 
b/clang/test/CodeGen/constrained-math-builtins.c
index d817cce33679..cccfd8bc7746 100644
--- a/clang/test/CodeGen/constrained-math-builtins.c
+++ b/clang/test/CodeGen/constrained-math-builtins.c
@@ -300,10 +300,17 @@ void bar(float f) {
   f * f + f;
   (double)f * f - f;
   (long dou

[PATCH] D144613: [RISCV] Properly diagnose mixing RVV scalable vectors with GNU vectors.

2023-02-23 Thread Craig Topper via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdbf149c91b7b: [RISCV] Properly diagnose mixing RVV scalable 
vectors with GNU vectors. (authored by craig.topper).

Changed prior to commit:
  https://reviews.llvm.org/D144613?vs=499711&id=499882#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144613

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/attr-riscv-rvv-vector-bits.c

Index: clang/test/Sema/attr-riscv-rvv-vector-bits.c
===
--- /dev/null
+++ clang/test/Sema/attr-riscv-rvv-vector-bits.c
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +zve64x -ffreestanding -fsyntax-only -verify %s
+
+// TODO: Support for a arm_sve_vector_bits like attribute will come in the future.
+
+#include 
+
+#define N 64
+
+typedef __rvv_int8m1_t vint8m1_t;
+typedef __rvv_uint8m1_t vuint8m1_t;
+typedef __rvv_int16m1_t vint16m1_t;
+typedef __rvv_uint16m1_t vuint16m1_t;
+typedef __rvv_int32m1_t vint32m1_t;
+typedef __rvv_uint32m1_t vuint32m1_t;
+typedef __rvv_int64m1_t vint64m1_t;
+typedef __rvv_uint64m1_t vuint64m1_t;
+typedef __rvv_float32m1_t vfloat32m1_t;
+typedef __rvv_float64m1_t vfloat64m1_t;
+
+// GNU vector types
+typedef int8_t gnu_int8_t __attribute__((vector_size(N / 8)));
+typedef int16_t gnu_int16_t __attribute__((vector_size(N / 8)));
+typedef int32_t gnu_int32_t __attribute__((vector_size(N / 8)));
+typedef int64_t gnu_int64_t __attribute__((vector_size(N / 8)));
+
+typedef uint8_t gnu_uint8_t __attribute__((vector_size(N / 8)));
+typedef uint16_t gnu_uint16_t __attribute__((vector_size(N / 8)));
+typedef uint32_t gnu_uint32_t __attribute__((vector_size(N / 8)));
+typedef uint64_t gnu_uint64_t __attribute__((vector_size(N / 8)));
+
+typedef float gnu_float32_t __attribute__((vector_size(N / 8)));
+typedef double gnu_float64_t __attribute__((vector_size(N / 8)));
+
+
+void f(int c) {
+  vint8m1_t ss8;
+  gnu_int8_t gs8;
+
+  // Check conditional expressions where the result is ambiguous are
+  // ill-formed.
+  void *sel __attribute__((unused));
+
+  sel = c ? gs8 : ss8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+  sel = c ? ss8 : gs8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  // Check binary expressions where the result is ambiguous are ill-formed.
+  ss8 = ss8 + gs8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  gs8 = gs8 + ss8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  ss8 += gs8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  gs8 += ss8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  ss8 = ss8 == gs8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  gs8 = gs8 == ss8; // expected-error {{cannot combine GNU and RVV vectors in expression, result is ambiguous}}
+
+  ss8 = ss8 & gs8; // expected-error {{invalid operands to binary expression ('vint8m1_t' (aka '__rvv_int8m1_t') and 'gnu_int8_t' (vector of 8 'int8_t' values))}}
+
+  gs8 = gs8 & ss8; // expected-error {{invalid operands to binary expression ('gnu_int8_t' (vector of 8 'int8_t' values) and 'vint8m1_t' (aka '__rvv_int8m1_t'))}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -10750,12 +10750,14 @@
 return QualType();
   }
 
-  // Expressions containing GNU and SVE (fixed or sizeless) vectors are invalid
-  // since the ambiguity can affect the ABI.
-  auto IsSveGnuConversion = [](QualType FirstType, QualType SecondType) {
+  // Expressions containing GNU and SVE or RVV (fixed or sizeless) vectors are
+  // invalid since the ambiguity can affect the ABI.
+  auto IsSveRVVGnuConversion = [](QualType FirstType, QualType SecondType,
+  unsigned &SVEorRVV) {
 const VectorType *FirstVecType = FirstType->getAs();
 const VectorType *SecondVecType = SecondType->getAs();
 
+SVEorRVV = 0;
 if (FirstVecType && SecondVecType)
   return FirstVecType->getVectorKind() == VectorType::GenericVector &&
  (SecondVecType->getVectorKind() ==
@@ -10763,13 +10765,24 @@
   SecondVecType->getVectorKind() ==
   VectorType::SveFixedLengthPredicateVector);
 
-return FirstType->isSizelessBuiltinType() && SecondVecType &&
-   SecondVecType->getVectorKind() == VectorType::GenericVector;
+if (SecondVecType &&
+SecondVecType->getVectorKind() == VectorType:

[clang] dbf149c - [RISCV] Properly diagnose mixing RVV scalable vectors with GNU vectors.

2023-02-23 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-02-23T09:00:32-08:00
New Revision: dbf149c91b7bdf08b2d4dd94ab76f3209af4c6d4

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

LOG: [RISCV] Properly diagnose mixing RVV scalable vectors with GNU vectors.

This case was being picked up by SVE code and printing an SVE
specific message.

This patch distinquishes RVV from SVE and provides a correct error
message for RVV.

The use of the generic isSizelessBuiltinType was also picking up
WebAssembly reference types which was probably an accident so I've
removed that.

I've named the test similar to SVE's test that contains this check.
Their test also tests the arm_sve_vector_bits attribute. I plan to
add something similar for RISC-V soon so I've adopted this naming.

Reviewed By: c-rhodes

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

Added: 
clang/test/Sema/attr-riscv-rvv-vector-bits.c

Modified: 
clang/include/clang/AST/Type.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 7dd058b9c53c..10cb4c819d7c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2029,6 +2029,9 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   /// Returns true for SVE scalable vector types.
   bool isSVESizelessBuiltinType() const;
 
+  /// Returns true for RVV scalable vector types.
+  bool isRVVSizelessBuiltinType() const;
+
   /// Check if this is a WebAssembly Reference Type.
   bool isWebAssemblyReferenceType() const;
   bool isWebAssemblyExternrefType() const;

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 86c5c4e288c9..81e3f5e2d062 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3165,8 +3165,8 @@ def err_attribute_zero_size : Error<"zero %0 size">;
 def err_attribute_size_too_large : Error<"%0 size too large">;
 def err_typecheck_sve_ambiguous : Error<
   "cannot combine fixed-length and sizeless SVE vectors in expression, result 
is ambiguous (%0 and %1)">;
-def err_typecheck_sve_gnu_ambiguous : Error<
-  "cannot combine GNU and SVE vectors in expression, result is ambiguous (%0 
and %1)">;
+def err_typecheck_sve_rvv_gnu_ambiguous : Error<
+  "cannot combine GNU and %select{SVE|RVV}0 vectors in expression, result is 
ambiguous (%1 and %2)">;
 def err_typecheck_vector_not_convertable_implict_truncation : Error<
"cannot convert between %select{scalar|vector}0 type %1 and vector type"
" %2 as implicit conversion would cause truncation">;

diff  --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 04359c7d82cb..7710adbb274a 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2372,6 +2372,19 @@ bool Type::isSVESizelessBuiltinType() const {
   return false;
 }
 
+bool Type::isRVVSizelessBuiltinType() const {
+  if (const BuiltinType *BT = getAs()) {
+switch (BT->getKind()) {
+#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/RISCVVTypes.def"
+  return true;
+default:
+  return false;
+}
+  }
+  return false;
+}
+
 bool Type::isVLSTBuiltinType() const {
   if (const BuiltinType *BT = getAs()) {
 switch (BT->getKind()) {

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3b8c8a4def51..817eed986e08 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -10750,12 +10750,14 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, 
ExprResult &RHS,
 return QualType();
   }
 
-  // Expressions containing GNU and SVE (fixed or sizeless) vectors are invalid
-  // since the ambiguity can affect the ABI.
-  auto IsSveGnuConversion = [](QualType FirstType, QualType SecondType) {
+  // Expressions containing GNU and SVE or RVV (fixed or sizeless) vectors are
+  // invalid since the ambiguity can affect the ABI.
+  auto IsSveRVVGnuConversion = [](QualType FirstType, QualType SecondType,
+  unsigned &SVEorRVV) {
 const VectorType *FirstVecType = FirstType->getAs();
 const VectorType *SecondVecType = SecondType->getAs();
 
+SVEorRVV = 0;
 if (FirstVecType && SecondVecType)
   return FirstVecType->getVectorKind() == VectorType::GenericVector &&
  (SecondVecType->getVectorKind() ==
@@ -10763,13 +10765,24 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, 
ExprResult &RHS,
   SecondVecType->getVectorKind() ==
   VectorType::SveFixedLengthPredicateVector);
 
-return FirstType->isSizelessBuiltinType() && SecondVecType &&
-   SecondVecType-

[PATCH] D143996: [clang-tidy][doc] Remove unused variable

2023-02-23 Thread Björn Svensson via Phabricator via cfe-commits
bjosv added a comment.

@carlosgalvezp Sorry, I should have mentioned that I don't have push rights and 
that this is my first contribution.
My GitHub user is:  bjosv   and email:  bjorn.a.svens...@est.tech
Thanks.


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

https://reviews.llvm.org/D143996

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


[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-23 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks for the comments!




Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:408
+
+bool isFilteredByConfig(const Config &Cfg, llvm::StringRef HeaderSpelling) {
+  for (auto &Filter : Cfg.Diagnostics.Includes.IgnoreHeader) {

kadircet wrote:
> this shouldn't be spelling, it should be the resolved path of the include.
Ok thanks.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:697
+(*SpelledForExpanded)[(*SpelledForExpanded).size() - 1]);
+std::string SymbolName;
+switch (Ref.Target.kind()) {

kadircet wrote:
> as mentioned elsewhere, i think we should delay this symbol name spelling to 
> diagnostic generation. to make sure core analysis we perform don't do work 
> that might not get re-used (e.g. if we're not going to diagnose missing 
> includes, or in the future when we don't care about spelling of all the 
> symbols)
Ok should be done now.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:712
+  getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});
+  return {std::move(UnusedIncludes), std::move(MissingIncludes)};
 }

kadircet wrote:
> nit: I think logically it makes more sense for us to return set of `Used` 
> includes here, and let the interaction that issues unused include diagnostics 
> to derive this information from the set of used includes, and change the the 
> missingincludes to a `vector< tuple >` (not only the 
> unsatisfied ones) would represent the analysis better and make it more usable 
> in the future (i.e. when we want to augment Hover responses, we can't re-use 
> all the logic in here, we really need to implement another call to `walkUsed` 
> because the analysis we get out of this call won't contain information for 
> `satisfied` symbols.
> 
> no need to do it now though, we can perform that kind of refactoring as we're 
> adding the features too (or maybe it'll actually look neater to just have 
> another call in those features rather than try and re-use the logic here)
Thanks. This might very well be the case, but this comment also seems to 
suggest some premature optimization (in a way). It totally makes sense to 
re-use what's re-usable, but this sort of refactoring really only makes sense 
once we have a clear use case (and get there :)



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:359
+TransformedInc.Angled = WrittenRef.starts_with("<");
+auto FE = SM.getFileManager().getFile(Inc.Resolved);
+if (!FE)

kadircet wrote:
> VitaNuo wrote:
> > kadircet wrote:
> > > unfortunately `getFile` returns an `llvm::Expected` which requires 
> > > explicit error handling (or it'll trigger a crash). you can simply `elog` 
> > > the issue:
> > > ```
> > > if (!FE) {
> > >   elog("IncludeCleaner: Failed to get an entry for resolved path {0}: 
> > > {1}", Inc.Resolved, FE.takeError());
> > >   continue;
> > > }
> > > ```
> > It returns `llvm::ErrorOr`, if I am not mistaken. There was explicit error 
> > handling already (`if (!FE) continue` below), just without the `elog`. Are 
> > you trying to say it will crash without the logging? Not sure that's 
> > feasible :)
> > Added the logging.
> > It returns llvm::ErrorOr, if I am not mistaken. 
> 
> Ah you're right, I confused it with `getFileRef`. So in theory `ErrorOr` 
> doesn't require explicit checking hence it won't trigger a crash if destroyed 
> while containing an error.
> 
> > Are you trying to say it will crash without the logging? Not sure that's 
> > feasible :)
> 
> Right, it isn't the logging that'll prevent the crash but rather a 
> combination of the call to `takeError` and the way `elog` consumes `Error` 
> objects. But it isn't relevant here, as `ErrorOr` doesn't require mandatory 
> handling.
thanks for the explanation.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:596
+generateUnusedIncludeDiagnostics(PathRef FileName,
+ std::vector UnusedIncludes,
+ llvm::StringRef Code) {

kadircet wrote:
> VitaNuo wrote:
> > kadircet wrote:
> > > no need to copy the vector by taking a `std::vector` here, you can take 
> > > an `llvm::ArrayRef` instead.
> > Oh this isn't even my code, but as long as it's a small change, sure :)
> well, this is `our` code in the end :D
Sorry, wrong wording. I meant to say that this is not the code that has been 
touched in this patch. It might sometimes get annoying when comments on the 
patch dig too deep into code that's not in the diff.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:691
+  getUnused(AST, Used, /*ReferencedPublicHeaders*/ {});
+  return {UnusedIncludes, MissingIncludes};
+}

kadircet wrote:
> kadircet wrote:
> > nit: you'd want `std::move`s here, around both of them
> oops, i forgot to put the surrounding 

[PATCH] D143496: [clangd] Add support for missing includes analysis.

2023-02-23 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 499879.
VitaNuo marked 18 inline comments as done.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143496

Files:
  clang-tools-extra/clangd/Config.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/ConfigFragment.h
  clang-tools-extra/clangd/ConfigYAML.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/Preamble.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp

Index: clang-tools-extra/include-cleaner/lib/Analysis.cpp
===
--- clang-tools-extra/include-cleaner/lib/Analysis.cpp
+++ clang-tools-extra/include-cleaner/lib/Analysis.cpp
@@ -49,8 +49,8 @@
   }
 }
 
-static std::string spellHeader(const Header &H, HeaderSearch &HS,
-   const FileEntry *Main) {
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main) {
   switch (H.kind()) {
   case Header::Physical: {
 bool IsSystem = false;
Index: clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
===
--- clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -73,6 +73,8 @@
 std::string fixIncludes(const AnalysisResults &Results, llvm::StringRef Code,
 const format::FormatStyle &IncludeStyle);
 
+std::string spellHeader(const Header &H, HeaderSearch &HS,
+const FileEntry *Main);
 } // namespace include_cleaner
 } // namespace clang
 
Index: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
===
--- clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
+++ clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp
@@ -8,26 +8,57 @@
 
 #include "Annotations.h"
 #include "Config.h"
+#include "Diagnostics.h"
 #include "IncludeCleaner.h"
+#include "ParsedAST.h"
 #include "SourceCode.h"
 #include "TestFS.h"
 #include "TestTU.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
 #include "support/Context.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Tooling/Syntax/Tokens.h"
 #include "llvm/ADT/ScopeExit.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Testing/Support/SupportHelpers.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
 namespace {
 
+using ::testing::AllOf;
 using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
 using ::testing::IsEmpty;
+using ::testing::Matcher;
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
+Matcher withFix(::testing::Matcher FixMatcher) {
+  return Field(&Diag::Fixes, ElementsAre(FixMatcher));
+}
+
+MATCHER_P2(Diag, Range, Message,
+   "Diag at " + llvm::to_string(Range) + " = [" + Message + "]") {
+  return arg.Range == Range && arg.Message == Message;
+}
+
+MATCHER_P3(Fix, Range, Replacement, Message,
+   "Fix " + llvm::to_string(Range) + " => " +
+   ::testing::PrintToString(Replacement) + " = [" + Message + "]") {
+  return arg.Message == Message && arg.Edits.size() == 1 &&
+ arg.Edits[0].range == Range && arg.Edits[0].newText == Replacement;
+}
+
 std::string guard(llvm::StringRef Code) {
   return "#pragma once\n" + Code.str();
 }
@@ -342,7 +373,8 @@
   auto AST = TU.build();
   EXPECT_THAT(computeUnusedIncludes(AST),
   ElementsAre(Pointee(writtenInclusion("";
-  EXPECT_THAT(computeUnusedIncludesExperimental(AST),
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
+  EXPECT_THAT(Findings.UnusedIncludes,
   ElementsAre(Pointee(writtenInclusion("";
 }
 
@@ -379,12 +411,98 @@
   computeUnusedIncludes(AST),
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenInclusion("\"dir/unused.h\"";
+
+  IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
   EXPECT_THAT(
-  computeUnusedIncludesExperimental(AST),
+  Findings.UnusedIncludes,
   UnorderedElementsAre(Pointee(writtenInclusion("\"unused.h\"")),
Pointee(writtenIn

[clang] 1812e13 - Revert "[clang] Add the check of membership for the issue #58674 and improve the lookup process"

2023-02-23 Thread Alexander Kornienko via cfe-commits

Author: Alexander Kornienko
Date: 2023-02-23T17:31:04+01:00
New Revision: 1812e13a3d6be9a838672ff74b3d9d383f5a83b5

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

LOG: Revert "[clang] Add the check of membership for the issue #58674 and 
improve the lookup process"

The commit causes clang to crash. See https://reviews.llvm.org/D143840#4147234

This reverts commit 8498ba6c2860c838183f9951b63df26ab5f02265.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/DeclCXX.h
clang/lib/AST/CXXInheritance.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/decltype.cpp

Removed: 
clang/test/CodeGenCXX/decl-ref-inheritance.cpp



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0c8d3d9411b12..2a636ebb00f79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -171,9 +171,6 @@ Bug Fixes to C++ Support
 - Fix crash when evaluating consteval constructor of derived class whose base
   has more than one field.
   (`#60166 `_)
-- Fix an issue about ``decltype`` in the members of class templates derived 
from
-  templates with related parameters.
-  (`#58674 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 8909acc71c0a3..11276c77490ce 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1546,11 +1546,8 @@ class CXXRecordDecl : public RecordDecl {
   ///
   /// \param Base the base class we are searching for.
   ///
-  /// \param LookupInDependentTypes whether to look up in dependent types.
-  ///
   /// \returns true if this class is derived from Base, false otherwise.
-  bool isDerivedFrom(const CXXRecordDecl *Base,
- bool LookupInDependentTypes = false) const;
+  bool isDerivedFrom(const CXXRecordDecl *Base) const;
 
   /// Determine whether this class is derived from the type \p Base.
   ///
@@ -1564,14 +1561,11 @@ class CXXRecordDecl : public RecordDecl {
   /// \param Paths will contain the paths taken from the current class to the
   /// given \p Base class.
   ///
-  /// \param LookupInDependentTypes whether to look up independent types.
-  ///
   /// \returns true if this class is derived from \p Base, false otherwise.
   ///
   /// \todo add a separate parameter to configure IsDerivedFrom, rather than
   /// tangling input and output in \p Paths
-  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths,
- bool LookupInDependentTypes = false) const;
+  bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
 
   /// Determine whether this class is virtually derived from
   /// the class \p Base.

diff  --git a/clang/lib/AST/CXXInheritance.cpp 
b/clang/lib/AST/CXXInheritance.cpp
index 32b17fc64a463..25de2a20a7f3b 100644
--- a/clang/lib/AST/CXXInheritance.cpp
+++ b/clang/lib/AST/CXXInheritance.cpp
@@ -64,16 +64,14 @@ void CXXBasePaths::swap(CXXBasePaths &Other) {
   std::swap(DetectedVirtual, Other.DetectedVirtual);
 }
 
-bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base,
-  bool LookupInDependentTypes) const {
+bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base) const {
   CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/false,
  /*DetectVirtual=*/false);
-  return isDerivedFrom(Base, Paths, LookupInDependentTypes);
+  return isDerivedFrom(Base, Paths);
 }
 
 bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base,
-  CXXBasePaths &Paths,
-  bool LookupInDependentTypes) const {
+  CXXBasePaths &Paths) const {
   if (getCanonicalDecl() == Base->getCanonicalDecl())
 return false;
 
@@ -85,7 +83,7 @@ bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base,
 return Specifier->getType()->getAsRecordDecl() &&
FindBaseClass(Specifier, Path, BaseDecl);
   },
-  Paths, LookupInDependentTypes);
+  Paths);
 }
 
 bool CXXRecordDecl::isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const {
@@ -248,16 +246,17 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context,
 } else if (VisitBase) {
   CXXRecordDecl *BaseRecord;
   if (LookupInDependent) {
-BaseRecord = cast_if_present(
-BaseSpec.getType()->getAsRecordDecl());
-if (!BaseRecord) {
-  if (const TemplateSpecializationType *TST =
-  BaseSpec.getType()->getAs()) {
-TemplateName TN = TST->getTemplateName();
-if (auto *TD =
-

[PATCH] D140992: clang: Add __builtin_elementwise_fma

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

LGTM!




Comment at: clang/lib/Sema/SemaChecking.cpp:17761-17766
+  for (int I = 0; I < 3; ++I) {
+ExprResult Converted = UsualUnaryConversions(TheCall->getArg(I));
+if (Converted.isInvalid())
+  return true;
+Args[I] = Converted.get();
+  }

arsenm wrote:
> aaron.ballman wrote:
> > This will cause conversions to happen *before* we check whether the types 
> > are the same; is that expected? e.g., it seems like this would allow you to 
> > pass a float and a double and thanks to the magic of usual unary 
> > conversions they both come out as double and thus don't get diagnosed.
> The tests say that isn't happening, e.g. here:
> 
> 
> ```
> 
>   f32 = __builtin_elementwise_fma(f64, f32, f32);
>   // expected-error@-1 {{arguments are of different types ('double' vs 
> 'float')}}
> 
>   f32 = __builtin_elementwise_fma(f32, f64, f32);
>   // expected-error@-1 {{arguments are of different types ('float' vs 
> 'double')}}
> 
> ```
Oh, excellent, thank you!


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

https://reviews.llvm.org/D140992

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


  1   2   >