[clang] 0df7d8b - [CMake][Fuchsia] Enable assertions and backtraces in stage 1 build

2022-07-25 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2022-07-26T06:09:38Z
New Revision: 0df7d8bc355dd506bb1a330b9f73e611f0deaf9f

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

LOG: [CMake][Fuchsia] Enable assertions and backtraces in stage 1 build

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index 73ef571507179..1978195c267d9 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -34,8 +34,8 @@ set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES ON CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")



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


[PATCH] D130514: [CMake][Fuchsia] Enable assertions and backtraces in stage 1 build

2022-07-25 Thread Alex Brachet 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 rG0df7d8bc355d: [CMake][Fuchsia] Enable assertions and 
backtraces in stage 1 build (authored by abrachet).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130514

Files:
  clang/cmake/caches/Fuchsia.cmake


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -34,8 +34,8 @@
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES ON CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -34,8 +34,8 @@
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES ON CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0ffb3dd - [clang-format] Fix a hang when formatting C# $@ string literals

2022-07-25 Thread via cfe-commits

Author: owenca
Date: 2022-07-25T23:17:54-07:00
New Revision: 0ffb3dd33ee1a50a6ab5db80bb8caee9133e66dc

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

LOG: [clang-format] Fix a hang when formatting C# $@ string literals

Fixes #56624.

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

Added: 


Modified: 
clang/lib/Format/FormatTokenLexer.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 66f03dcb53a12..3f9b68ccbb39f 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -239,55 +239,6 @@ bool FormatTokenLexer::tryMergeCSharpStringLiteral() {
   if (Tokens.size() < 2)
 return false;
 
-  // Interpolated strings could contain { } with " characters inside.
-  // $"{x ?? "null"}"
-  // should not be split into $"{x ?? ", null, "}" but should treated as a
-  // single string-literal.
-  //
-  // We opt not to try and format expressions inside {} within a C#
-  // interpolated string. Formatting expressions within an interpolated string
-  // would require similar work as that done for JavaScript template strings
-  // in `handleTemplateStrings()`.
-  auto &CSharpInterpolatedString = *(Tokens.end() - 2);
-  if (CSharpInterpolatedString->getType() == TT_CSharpStringLiteral &&
-  (CSharpInterpolatedString->TokenText.startswith(R"($")") ||
-   CSharpInterpolatedString->TokenText.startswith(R"($@")"))) {
-int UnmatchedOpeningBraceCount = 0;
-
-auto TokenTextSize = CSharpInterpolatedString->TokenText.size();
-for (size_t Index = 0; Index < TokenTextSize; ++Index) {
-  char C = CSharpInterpolatedString->TokenText[Index];
-  if (C == '{') {
-// "{{"  inside an interpolated string is an escaped '{' so skip it.
-if (Index + 1 < TokenTextSize &&
-CSharpInterpolatedString->TokenText[Index + 1] == '{') {
-  ++Index;
-  continue;
-}
-++UnmatchedOpeningBraceCount;
-  } else if (C == '}') {
-// "}}"  inside an interpolated string is an escaped '}' so skip it.
-if (Index + 1 < TokenTextSize &&
-CSharpInterpolatedString->TokenText[Index + 1] == '}') {
-  ++Index;
-  continue;
-}
---UnmatchedOpeningBraceCount;
-  }
-}
-
-if (UnmatchedOpeningBraceCount > 0) {
-  auto &NextToken = *(Tokens.end() - 1);
-  CSharpInterpolatedString->TokenText =
-  StringRef(CSharpInterpolatedString->TokenText.begin(),
-NextToken->TokenText.end() -
-CSharpInterpolatedString->TokenText.begin());
-  CSharpInterpolatedString->ColumnWidth += NextToken->ColumnWidth;
-  Tokens.erase(Tokens.end() - 1);
-  return true;
-}
-  }
-
   // Look for @"aa" or $"aa".
   auto &String = *(Tokens.end() - 1);
   if (!String->is(tok::string_literal))
@@ -571,45 +522,105 @@ void FormatTokenLexer::tryParseJSRegexLiteral() {
   resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset)));
 }
 
+static auto lexCSharpString(const char *Begin, const char *End, bool Verbatim,
+bool Interpolated) {
+  auto Repeated = [&Begin, End]() {
+return Begin + 1 < End && Begin[1] == Begin[0];
+  };
+
+  // Look for a terminating '"' in the current file buffer.
+  // Make no effort to format code within an interpolated or verbatim string.
+  //
+  // Interpolated strings could contain { } with " characters inside.
+  // $"{x ?? "null"}"
+  // should not be split into $"{x ?? ", null, "}" but should be treated as a
+  // single string-literal.
+  //
+  // We opt not to try and format expressions inside {} within a C#
+  // interpolated string. Formatting expressions within an interpolated string
+  // would require similar work as that done for JavaScript template strings
+  // in `handleTemplateStrings()`.
+  for (int UnmatchedOpeningBraceCount = 0; Begin < End; ++Begin) {
+switch (*Begin) {
+case '\\':
+  if (!Verbatim)
+++Begin;
+  break;
+case '{':
+  if (Interpolated) {
+// {{ inside an interpolated string is escaped, so skip it.
+if (Repeated())
+  ++Begin;
+else
+  ++UnmatchedOpeningBraceCount;
+  }
+  break;
+case '}':
+  if (Interpolated) {
+// }} inside an interpolated string is escaped, so skip it.
+if (Repeated())
+  ++Begin;
+else if (UnmatchedOpeningBraceCount > 0)
+  --UnmatchedOpeningBraceCount;
+else
+  return End;
+  }
+  break;
+case '"':
+  if (UnmatchedOpeningBraceCount > 0)
+break;
+  // "" within a verbatim string is an esc

[PATCH] D130331: [C++20] [Modules] Disable preferred_name when writing a C++20 Module interface

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Sorry for the frequent ping since 15.x is going to be branched. @aaron.ballman 
@tahonermann I know this might not look good to you. But I want to ask if there 
is any objection? Personally, the preferred_name attribute is not so important 
and it blocks something important. I really want to get this landed. And as 
@erichkeane said in D129748 , I'll take an 
eye on this.


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

https://reviews.llvm.org/D130331

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Roman Rusyaev via Phabricator via cfe-commits
rusyaev-roman added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

ChuanqiXu wrote:
> rusyaev-roman wrote:
> > ChuanqiXu wrote:
> > > What if NRVO contains a value already? It is possible due to the value of 
> > > NRVO could be set by its children.
> > Actually this is intention. If the parent has already NRVO candidate, then 
> > it should be invalidated (or not). Let's consider the following examples:
> > 
> > 
> > ```
> > X foo(bool b) {
> >X x;
> >X y;
> >if (b)
> >   return x;
> >else
> >   return y; // when we process this return statement, the parent has 
> > already NRVO and it will be invalidated (this is correct behavior)
> > }
> > ```
> > 
> > ```
> > X foo(bool b) {
> >X x;
> >if (b)
> >   return x;
> >
> >X y;
> >// when we process this return statement, the parent has already NRVO 
> > and it WON't be invalidated
> >//  (this is correct behavior), because a return slot will be available 
> > for it
> >return y;
> > }
> > ```
> > 
> > ```
> > X foo(bool b) {
> >X x;
> >if (b)
> >   return x;
> > 
> >// when we process this return statement, the parent has already NRVO 
> > and it WON't be invalidated (this is correct behavior)
> >return x;
> > }
> > ```
> > 
> > ```
> > X foo(bool b, X x) {
> >X y;
> >
> >if (b)
> >   return x;
> > 
> >// when we process this return statement, the parent contains nullptr 
> > (invalid candidate) and it will be invalidated (this is correct behavior)
> >return y;
> > }
> > ```
> > 
> > ```
> > X foo(bool b, X x) {
> >if (b)
> >   return x;
> > 
> >X y;
> >// when we process this return statement, the parent contains nullptr 
> > (invalid candidate) and it WON't be invalidated (this is correct behavior)
> >return y;
> > }
> > ```
> Oh, I see. Tricky. I don't find invalid cases now. But I recommend to comment 
> that the children would maintain the `ReturnSlots` of their parents. (This is 
> anti-intuition)
> 
> Have you tested any larger projects? Like libc++, libstdc++ or something like 
> folly. I feel we need to do such tests to avoid we get anything wrong.
I've already added a comment at the beginning of `updateNRVOCandidate` function 
where this point is mentioned: 
```
//  ... Therefore, we need to clear return slots for other
//  variables defined before the current return statement in the current
//  scope and in outer scopes.
```
If it's not enough, please let me know.


> Have you tested any larger projects?

Yes, I've built the `clang` itself and `compiler-rt` project. Then I've checked 
them to run 'check-all' (on built clang and compiler-rt). Everything  works.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D130411: [clang-format] Fix a hang when formatting C# $@ string literals

2022-07-25 Thread Owen Pan 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 rG0ffb3dd33ee1: [clang-format] Fix a hang when formatting C# 
$@ string literals (authored by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D130411?vs=447041&id=447575#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130411

Files:
  clang/lib/Format/FormatTokenLexer.cpp
  clang/unittests/Format/FormatTestCSharp.cpp

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -574,6 +574,7 @@
   verifyFormat(R"(string str = @;)", Style);
   verifyFormat(R"(string str = @"""Hello world""";)", Style);
   verifyFormat(R"(string str = $@"""Hello {friend}""";)", Style);
+  verifyFormat(R"(return $@"Foo ""/foo?f={Request.Query["f"]}""";)", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpQuotesInInterpolatedStrings) {
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -239,55 +239,6 @@
   if (Tokens.size() < 2)
 return false;
 
-  // Interpolated strings could contain { } with " characters inside.
-  // $"{x ?? "null"}"
-  // should not be split into $"{x ?? ", null, "}" but should treated as a
-  // single string-literal.
-  //
-  // We opt not to try and format expressions inside {} within a C#
-  // interpolated string. Formatting expressions within an interpolated string
-  // would require similar work as that done for JavaScript template strings
-  // in `handleTemplateStrings()`.
-  auto &CSharpInterpolatedString = *(Tokens.end() - 2);
-  if (CSharpInterpolatedString->getType() == TT_CSharpStringLiteral &&
-  (CSharpInterpolatedString->TokenText.startswith(R"($")") ||
-   CSharpInterpolatedString->TokenText.startswith(R"($@")"))) {
-int UnmatchedOpeningBraceCount = 0;
-
-auto TokenTextSize = CSharpInterpolatedString->TokenText.size();
-for (size_t Index = 0; Index < TokenTextSize; ++Index) {
-  char C = CSharpInterpolatedString->TokenText[Index];
-  if (C == '{') {
-// "{{"  inside an interpolated string is an escaped '{' so skip it.
-if (Index + 1 < TokenTextSize &&
-CSharpInterpolatedString->TokenText[Index + 1] == '{') {
-  ++Index;
-  continue;
-}
-++UnmatchedOpeningBraceCount;
-  } else if (C == '}') {
-// "}}"  inside an interpolated string is an escaped '}' so skip it.
-if (Index + 1 < TokenTextSize &&
-CSharpInterpolatedString->TokenText[Index + 1] == '}') {
-  ++Index;
-  continue;
-}
---UnmatchedOpeningBraceCount;
-  }
-}
-
-if (UnmatchedOpeningBraceCount > 0) {
-  auto &NextToken = *(Tokens.end() - 1);
-  CSharpInterpolatedString->TokenText =
-  StringRef(CSharpInterpolatedString->TokenText.begin(),
-NextToken->TokenText.end() -
-CSharpInterpolatedString->TokenText.begin());
-  CSharpInterpolatedString->ColumnWidth += NextToken->ColumnWidth;
-  Tokens.erase(Tokens.end() - 1);
-  return true;
-}
-  }
-
   // Look for @"aa" or $"aa".
   auto &String = *(Tokens.end() - 1);
   if (!String->is(tok::string_literal))
@@ -571,45 +522,105 @@
   resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset)));
 }
 
+static auto lexCSharpString(const char *Begin, const char *End, bool Verbatim,
+bool Interpolated) {
+  auto Repeated = [&Begin, End]() {
+return Begin + 1 < End && Begin[1] == Begin[0];
+  };
+
+  // Look for a terminating '"' in the current file buffer.
+  // Make no effort to format code within an interpolated or verbatim string.
+  //
+  // Interpolated strings could contain { } with " characters inside.
+  // $"{x ?? "null"}"
+  // should not be split into $"{x ?? ", null, "}" but should be treated as a
+  // single string-literal.
+  //
+  // We opt not to try and format expressions inside {} within a C#
+  // interpolated string. Formatting expressions within an interpolated string
+  // would require similar work as that done for JavaScript template strings
+  // in `handleTemplateStrings()`.
+  for (int UnmatchedOpeningBraceCount = 0; Begin < End; ++Begin) {
+switch (*Begin) {
+case '\\':
+  if (!Verbatim)
+++Begin;
+  break;
+case '{':
+  if (Interpolated) {
+// {{ inside an interpolated string is escaped, so skip it.
+if (Repeated())
+  ++Begin;
+else
+  ++UnmatchedOpeningBraceCount;
+  }
+  break;
+case '}':
+  if (Interpolated) {
+// }} inside an interpola

[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

rusyaev-roman wrote:
> ChuanqiXu wrote:
> > rusyaev-roman wrote:
> > > ChuanqiXu wrote:
> > > > What if NRVO contains a value already? It is possible due to the value 
> > > > of NRVO could be set by its children.
> > > Actually this is intention. If the parent has already NRVO candidate, 
> > > then it should be invalidated (or not). Let's consider the following 
> > > examples:
> > > 
> > > 
> > > ```
> > > X foo(bool b) {
> > >X x;
> > >X y;
> > >if (b)
> > >   return x;
> > >else
> > >   return y; // when we process this return statement, the parent has 
> > > already NRVO and it will be invalidated (this is correct behavior)
> > > }
> > > ```
> > > 
> > > ```
> > > X foo(bool b) {
> > >X x;
> > >if (b)
> > >   return x;
> > >
> > >X y;
> > >// when we process this return statement, the parent has already NRVO 
> > > and it WON't be invalidated
> > >//  (this is correct behavior), because a return slot will be 
> > > available for it
> > >return y;
> > > }
> > > ```
> > > 
> > > ```
> > > X foo(bool b) {
> > >X x;
> > >if (b)
> > >   return x;
> > > 
> > >// when we process this return statement, the parent has already NRVO 
> > > and it WON't be invalidated (this is correct behavior)
> > >return x;
> > > }
> > > ```
> > > 
> > > ```
> > > X foo(bool b, X x) {
> > >X y;
> > >
> > >if (b)
> > >   return x;
> > > 
> > >// when we process this return statement, the parent contains nullptr 
> > > (invalid candidate) and it will be invalidated (this is correct behavior)
> > >return y;
> > > }
> > > ```
> > > 
> > > ```
> > > X foo(bool b, X x) {
> > >if (b)
> > >   return x;
> > > 
> > >X y;
> > >// when we process this return statement, the parent contains nullptr 
> > > (invalid candidate) and it WON't be invalidated (this is correct behavior)
> > >return y;
> > > }
> > > ```
> > Oh, I see. Tricky. I don't find invalid cases now. But I recommend to 
> > comment that the children would maintain the `ReturnSlots` of their 
> > parents. (This is anti-intuition)
> > 
> > Have you tested any larger projects? Like libc++, libstdc++ or something 
> > like folly. I feel we need to do such tests to avoid we get anything wrong.
> I've already added a comment at the beginning of `updateNRVOCandidate` 
> function where this point is mentioned: 
> ```
> //  ... Therefore, we need to clear return slots for other
> //  variables defined before the current return statement in the current
> //  scope and in outer scopes.
> ```
> If it's not enough, please let me know.
> 
> 
> > Have you tested any larger projects?
> 
> Yes, I've built the `clang` itself and `compiler-rt` project. Then I've 
> checked them to run 'check-all' (on built clang and compiler-rt). Everything  
> works.
Great! Clang should be large enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Roman Rusyaev via Phabricator via cfe-commits
rusyaev-roman added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

ChuanqiXu wrote:
> rusyaev-roman wrote:
> > ChuanqiXu wrote:
> > > rusyaev-roman wrote:
> > > > ChuanqiXu wrote:
> > > > > What if NRVO contains a value already? It is possible due to the 
> > > > > value of NRVO could be set by its children.
> > > > Actually this is intention. If the parent has already NRVO candidate, 
> > > > then it should be invalidated (or not). Let's consider the following 
> > > > examples:
> > > > 
> > > > 
> > > > ```
> > > > X foo(bool b) {
> > > >X x;
> > > >X y;
> > > >if (b)
> > > >   return x;
> > > >else
> > > >   return y; // when we process this return statement, the parent 
> > > > has already NRVO and it will be invalidated (this is correct behavior)
> > > > }
> > > > ```
> > > > 
> > > > ```
> > > > X foo(bool b) {
> > > >X x;
> > > >if (b)
> > > >   return x;
> > > >
> > > >X y;
> > > >// when we process this return statement, the parent has already 
> > > > NRVO and it WON't be invalidated
> > > >//  (this is correct behavior), because a return slot will be 
> > > > available for it
> > > >return y;
> > > > }
> > > > ```
> > > > 
> > > > ```
> > > > X foo(bool b) {
> > > >X x;
> > > >if (b)
> > > >   return x;
> > > > 
> > > >// when we process this return statement, the parent has already 
> > > > NRVO and it WON't be invalidated (this is correct behavior)
> > > >return x;
> > > > }
> > > > ```
> > > > 
> > > > ```
> > > > X foo(bool b, X x) {
> > > >X y;
> > > >
> > > >if (b)
> > > >   return x;
> > > > 
> > > >// when we process this return statement, the parent contains 
> > > > nullptr (invalid candidate) and it will be invalidated (this is correct 
> > > > behavior)
> > > >return y;
> > > > }
> > > > ```
> > > > 
> > > > ```
> > > > X foo(bool b, X x) {
> > > >if (b)
> > > >   return x;
> > > > 
> > > >X y;
> > > >// when we process this return statement, the parent contains 
> > > > nullptr (invalid candidate) and it WON't be invalidated (this is 
> > > > correct behavior)
> > > >return y;
> > > > }
> > > > ```
> > > Oh, I see. Tricky. I don't find invalid cases now. But I recommend to 
> > > comment that the children would maintain the `ReturnSlots` of their 
> > > parents. (This is anti-intuition)
> > > 
> > > Have you tested any larger projects? Like libc++, libstdc++ or something 
> > > like folly. I feel we need to do such tests to avoid we get anything 
> > > wrong.
> > I've already added a comment at the beginning of `updateNRVOCandidate` 
> > function where this point is mentioned: 
> > ```
> > //  ... Therefore, we need to clear return slots for other
> > //  variables defined before the current return statement in the current
> > //  scope and in outer scopes.
> > ```
> > If it's not enough, please let me know.
> > 
> > 
> > > Have you tested any larger projects?
> > 
> > Yes, I've built the `clang` itself and `compiler-rt` project. Then I've 
> > checked them to run 'check-all' (on built clang and compiler-rt). 
> > Everything  works.
> Great! Clang should be large enough.
Thanks a lot for the careful review!

@ChuanqiXu  , could you land this patch please?

Many thanks to @Izaron for the original implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D130522: [clang][dataflow] Fix SAT solver crashes on `X ^ X` and `X v X`

2022-07-25 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev accepted this revision.
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:273
+
+// Visit a sub-value of `Val` (pick any, they are identical).
+  } else {

Let's visit `C->getLeftSubValue()` here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130522

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

rusyaev-roman wrote:
> ChuanqiXu wrote:
> > rusyaev-roman wrote:
> > > ChuanqiXu wrote:
> > > > rusyaev-roman wrote:
> > > > > ChuanqiXu wrote:
> > > > > > What if NRVO contains a value already? It is possible due to the 
> > > > > > value of NRVO could be set by its children.
> > > > > Actually this is intention. If the parent has already NRVO candidate, 
> > > > > then it should be invalidated (or not). Let's consider the following 
> > > > > examples:
> > > > > 
> > > > > 
> > > > > ```
> > > > > X foo(bool b) {
> > > > >X x;
> > > > >X y;
> > > > >if (b)
> > > > >   return x;
> > > > >else
> > > > >   return y; // when we process this return statement, the parent 
> > > > > has already NRVO and it will be invalidated (this is correct behavior)
> > > > > }
> > > > > ```
> > > > > 
> > > > > ```
> > > > > X foo(bool b) {
> > > > >X x;
> > > > >if (b)
> > > > >   return x;
> > > > >
> > > > >X y;
> > > > >// when we process this return statement, the parent has already 
> > > > > NRVO and it WON't be invalidated
> > > > >//  (this is correct behavior), because a return slot will be 
> > > > > available for it
> > > > >return y;
> > > > > }
> > > > > ```
> > > > > 
> > > > > ```
> > > > > X foo(bool b) {
> > > > >X x;
> > > > >if (b)
> > > > >   return x;
> > > > > 
> > > > >// when we process this return statement, the parent has already 
> > > > > NRVO and it WON't be invalidated (this is correct behavior)
> > > > >return x;
> > > > > }
> > > > > ```
> > > > > 
> > > > > ```
> > > > > X foo(bool b, X x) {
> > > > >X y;
> > > > >
> > > > >if (b)
> > > > >   return x;
> > > > > 
> > > > >// when we process this return statement, the parent contains 
> > > > > nullptr (invalid candidate) and it will be invalidated (this is 
> > > > > correct behavior)
> > > > >return y;
> > > > > }
> > > > > ```
> > > > > 
> > > > > ```
> > > > > X foo(bool b, X x) {
> > > > >if (b)
> > > > >   return x;
> > > > > 
> > > > >X y;
> > > > >// when we process this return statement, the parent contains 
> > > > > nullptr (invalid candidate) and it WON't be invalidated (this is 
> > > > > correct behavior)
> > > > >return y;
> > > > > }
> > > > > ```
> > > > Oh, I see. Tricky. I don't find invalid cases now. But I recommend to 
> > > > comment that the children would maintain the `ReturnSlots` of their 
> > > > parents. (This is anti-intuition)
> > > > 
> > > > Have you tested any larger projects? Like libc++, libstdc++ or 
> > > > something like folly. I feel we need to do such tests to avoid we get 
> > > > anything wrong.
> > > I've already added a comment at the beginning of `updateNRVOCandidate` 
> > > function where this point is mentioned: 
> > > ```
> > > //  ... Therefore, we need to clear return slots for other
> > > //  variables defined before the current return statement in the 
> > > current
> > > //  scope and in outer scopes.
> > > ```
> > > If it's not enough, please let me know.
> > > 
> > > 
> > > > Have you tested any larger projects?
> > > 
> > > Yes, I've built the `clang` itself and `compiler-rt` project. Then I've 
> > > checked them to run 'check-all' (on built clang and compiler-rt). 
> > > Everything  works.
> > Great! Clang should be large enough.
> Thanks a lot for the careful review!
> 
> @ChuanqiXu  , could you land this patch please?
> 
> Many thanks to @Izaron for the original implementation.
Sure. What's your prefer Name and Mail address?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Roman Rusyaev via Phabricator via cfe-commits
rusyaev-roman added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

ChuanqiXu wrote:
> rusyaev-roman wrote:
> > ChuanqiXu wrote:
> > > rusyaev-roman wrote:
> > > > ChuanqiXu wrote:
> > > > > rusyaev-roman wrote:
> > > > > > ChuanqiXu wrote:
> > > > > > > What if NRVO contains a value already? It is possible due to the 
> > > > > > > value of NRVO could be set by its children.
> > > > > > Actually this is intention. If the parent has already NRVO 
> > > > > > candidate, then it should be invalidated (or not). Let's consider 
> > > > > > the following examples:
> > > > > > 
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b) {
> > > > > >X x;
> > > > > >X y;
> > > > > >if (b)
> > > > > >   return x;
> > > > > >else
> > > > > >   return y; // when we process this return statement, the 
> > > > > > parent has already NRVO and it will be invalidated (this is correct 
> > > > > > behavior)
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b) {
> > > > > >X x;
> > > > > >if (b)
> > > > > >   return x;
> > > > > >
> > > > > >X y;
> > > > > >// when we process this return statement, the parent has already 
> > > > > > NRVO and it WON't be invalidated
> > > > > >//  (this is correct behavior), because a return slot will be 
> > > > > > available for it
> > > > > >return y;
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b) {
> > > > > >X x;
> > > > > >if (b)
> > > > > >   return x;
> > > > > > 
> > > > > >// when we process this return statement, the parent has already 
> > > > > > NRVO and it WON't be invalidated (this is correct behavior)
> > > > > >return x;
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b, X x) {
> > > > > >X y;
> > > > > >
> > > > > >if (b)
> > > > > >   return x;
> > > > > > 
> > > > > >// when we process this return statement, the parent contains 
> > > > > > nullptr (invalid candidate) and it will be invalidated (this is 
> > > > > > correct behavior)
> > > > > >return y;
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b, X x) {
> > > > > >if (b)
> > > > > >   return x;
> > > > > > 
> > > > > >X y;
> > > > > >// when we process this return statement, the parent contains 
> > > > > > nullptr (invalid candidate) and it WON't be invalidated (this is 
> > > > > > correct behavior)
> > > > > >return y;
> > > > > > }
> > > > > > ```
> > > > > Oh, I see. Tricky. I don't find invalid cases now. But I recommend to 
> > > > > comment that the children would maintain the `ReturnSlots` of their 
> > > > > parents. (This is anti-intuition)
> > > > > 
> > > > > Have you tested any larger projects? Like libc++, libstdc++ or 
> > > > > something like folly. I feel we need to do such tests to avoid we get 
> > > > > anything wrong.
> > > > I've already added a comment at the beginning of `updateNRVOCandidate` 
> > > > function where this point is mentioned: 
> > > > ```
> > > > //  ... Therefore, we need to clear return slots for other
> > > > //  variables defined before the current return statement in the 
> > > > current
> > > > //  scope and in outer scopes.
> > > > ```
> > > > If it's not enough, please let me know.
> > > > 
> > > > 
> > > > > Have you tested any larger projects?
> > > > 
> > > > Yes, I've built the `clang` itself and `compiler-rt` project. Then I've 
> > > > checked them to run 'check-all' (on built clang and compiler-rt). 
> > > > Everything  works.
> > > Great! Clang should be large enough.
> > Thanks a lot for the careful review!
> > 
> > @ChuanqiXu  , could you land this patch please?
> > 
> > Many thanks to @Izaron for the original implementation.
> Sure. What's your prefer Name and Mail address?
Thanks!

Roman Rusyaev 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

rusyaev-roman wrote:
> ChuanqiXu wrote:
> > rusyaev-roman wrote:
> > > ChuanqiXu wrote:
> > > > rusyaev-roman wrote:
> > > > > ChuanqiXu wrote:
> > > > > > rusyaev-roman wrote:
> > > > > > > ChuanqiXu wrote:
> > > > > > > > What if NRVO contains a value already? It is possible due to 
> > > > > > > > the value of NRVO could be set by its children.
> > > > > > > Actually this is intention. If the parent has already NRVO 
> > > > > > > candidate, then it should be invalidated (or not). Let's consider 
> > > > > > > the following examples:
> > > > > > > 
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b) {
> > > > > > >X x;
> > > > > > >X y;
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > >else
> > > > > > >   return y; // when we process this return statement, the 
> > > > > > > parent has already NRVO and it will be invalidated (this is 
> > > > > > > correct behavior)
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b) {
> > > > > > >X x;
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > >
> > > > > > >X y;
> > > > > > >// when we process this return statement, the parent has 
> > > > > > > already NRVO and it WON't be invalidated
> > > > > > >//  (this is correct behavior), because a return slot will be 
> > > > > > > available for it
> > > > > > >return y;
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b) {
> > > > > > >X x;
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > > 
> > > > > > >// when we process this return statement, the parent has 
> > > > > > > already NRVO and it WON't be invalidated (this is correct 
> > > > > > > behavior)
> > > > > > >return x;
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b, X x) {
> > > > > > >X y;
> > > > > > >
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > > 
> > > > > > >// when we process this return statement, the parent contains 
> > > > > > > nullptr (invalid candidate) and it will be invalidated (this is 
> > > > > > > correct behavior)
> > > > > > >return y;
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b, X x) {
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > > 
> > > > > > >X y;
> > > > > > >// when we process this return statement, the parent contains 
> > > > > > > nullptr (invalid candidate) and it WON't be invalidated (this is 
> > > > > > > correct behavior)
> > > > > > >return y;
> > > > > > > }
> > > > > > > ```
> > > > > > Oh, I see. Tricky. I don't find invalid cases now. But I recommend 
> > > > > > to comment that the children would maintain the `ReturnSlots` of 
> > > > > > their parents. (This is anti-intuition)
> > > > > > 
> > > > > > Have you tested any larger projects? Like libc++, libstdc++ or 
> > > > > > something like folly. I feel we need to do such tests to avoid we 
> > > > > > get anything wrong.
> > > > > I've already added a comment at the beginning of 
> > > > > `updateNRVOCandidate` function where this point is mentioned: 
> > > > > ```
> > > > > //  ... Therefore, we need to clear return slots for other
> > > > > //  variables defined before the current return statement in the 
> > > > > current
> > > > > //  scope and in outer scopes.
> > > > > ```
> > > > > If it's not enough, please let me know.
> > > > > 
> > > > > 
> > > > > > Have you tested any larger projects?
> > > > > 
> > > > > Yes, I've built the `clang` itself and `compiler-rt` project. Then 
> > > > > I've checked them to run 'check-all' (on built clang and 
> > > > > compiler-rt). Everything  works.
> > > > Great! Clang should be large enough.
> > > Thanks a lot for the careful review!
> > > 
> > > @ChuanqiXu  , could you land this patch please?
> > > 
> > > Many thanks to @Izaron for the original implementation.
> > Sure. What's your prefer Name and Mail address?
> Thanks!
> 
> Roman Rusyaev 
Oh, I forgot you need edit the ReleaseNotes at clang/docs/ReleaseNotes.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D130550: [pseudo] Start rules are `_ := start-symbol EOF`, improve recovery.

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

Previously we were calling glrRecover() ad-hoc at the end of input.
Two main problems with this:

- glrRecover() on two separate code paths is inelegant
- We may have to recover several times in succession (e.g. to exit from nested 
scopes), so we need a loop at end-of-file

Having an actual shift action for an EOF terminal allows us to handle
both concerns in the main shift/recover/reduce loop.

This revealed a recovery design bug where recovery could enter a loop by
repeatedly choosing the same parent to identically recover from.
Addressed this by allowing each node to be used as a recovery base once.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130550

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
  clang-tools-extra/pseudo/lib/Forest.cpp
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/cxx/cxx.bnf
  clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
  clang-tools-extra/pseudo/test/lr-build-basic.test
  clang-tools-extra/pseudo/test/lr-build-conflicts.test
  clang-tools-extra/pseudo/unittests/ForestTest.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp

Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -509,7 +509,7 @@
   // item `expr := • IDENTIFIER`, and both have different goto states on the
   // nonterminal `expr`.
   build(R"bnf(
-_ := test
+_ := test EOF
 
 test := { expr
 test := { IDENTIFIER
@@ -548,7 +548,7 @@
   // foo should be reduced first, so that in step 2 we have completed reduces
   // for test, and form an ambiguous forest node.
   build(R"bnf(
-_ := test
+_ := test EOF
 
 test := IDENTIFIER
 test := foo
@@ -575,7 +575,7 @@
   //  - multiple possible recovery rules
   //  - recovery from outer scopes is rejected
   build(R"bnf(
-_ := block
+_ := block EOF
 
 block := { block [recover=Braces] }
 block := { numbers [recover=Braces] }
@@ -604,9 +604,42 @@
 "[  5, end) └─} := tok[5]\n");
 }
 
+TEST_F(GLRTest, RepeatedRecovery) {
+  // We require multiple steps of recovery at eof and then a reduction in order
+  // to successfully parse.
+  build(R"bnf(
+_ := function EOF
+# FIXME: this forces EOF to be in follow(signature).
+# Remove it once we use unconstrained reduction for recovery.
+_ := signature EOF
+
+function := signature body [recover=Skip]
+signature := IDENTIFIER params [recover=Skip]
+params := ( )
+body := { }
+  )bnf");
+  TestLang.Table = LRTable::buildSLR(TestLang.G);
+  llvm::errs() << TestLang.Table.dumpForTests(TestLang.G);
+  TestLang.RecoveryStrategies.try_emplace(
+  extensionID("Skip"),
+  [](Token::Index Start, const TokenStream &) { return Start; });
+  clang::LangOptions LOptions;
+  TokenStream Tokens = cook(lex("main", LOptions), LOptions);
+
+  const ForestNode &Parsed =
+  glrParse({Tokens, Arena, GSStack}, id("function"), TestLang);
+  EXPECT_EQ(Parsed.dumpRecursive(TestLang.G),
+"[  0, end) function := signature body [recover=Skip]\n"
+"[  0,   1) ├─signature := IDENTIFIER params [recover=Skip]\n"
+"[  0,   1) │ ├─IDENTIFIER := tok[0]\n"
+"[  1,   1) │ └─params := \n"
+"[  1, end) └─body := \n");
+}
+
+
 TEST_F(GLRTest, NoExplicitAccept) {
   build(R"bnf(
-_ := test
+_ := test EOF
 
 test := IDENTIFIER test
 test := IDENTIFIER
@@ -629,7 +662,7 @@
 
 TEST_F(GLRTest, GuardExtension) {
   build(R"bnf(
-_ := start
+_ := start EOF
 
 start := IDENTIFIER [guard]
   )bnf");
Index: clang-tools-extra/pseudo/unittests/ForestTest.cpp
===
--- clang-tools-extra/pseudo/unittests/ForestTest.cpp
+++ clang-tools-extra/pseudo/unittests/ForestTest.cpp
@@ -54,7 +54,7 @@
 
 TEST_F(ForestTest, DumpBasic) {
   build(R"cpp(
-_ := add-expression
+_ := add-expression EOF
 add-expression := id-expression + id-expression
 id-expression := IDENTIFIER
   )cpp");
@@ -64,7 +64,7 @@
   cook(lex("a + b", clang::LangOptions()), clang::LangOptions());
 
   auto T = Arena.createTerminals(TS);
-  ASSERT_EQ(T.size(), 3u);
+  ASSERT_EQ(T.size(), 4u);
   const auto *Left = &Arena.createSequence(
   symbol("id-expression"), ruleFor("id-expression"), {&T.front()});
   const auto *Right = &Arena.createSequence(symbol("id-expression"),
@@ -89,9 +89,9 @@
 
 TEST_F(ForestTest, DumpAmbiguousAndRefs) {
   build(R"cpp(
-_ := type
-type := class-type # rule 3
-type := enum-type # rule 4
+_ := type EOF
+type := class-typ

[clang] 94ca2be - [clang][analyzer] Added partial wide character support to CStringChecker

2022-07-25 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2022-07-25T09:23:14+02:00
New Revision: 94ca2beccc595c89c37eb3e5215ac97c3d930c8f

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

LOG: [clang][analyzer] Added partial wide character support to CStringChecker

Support for functions wmemcpy, wcslen, wcsnlen is added to the checker.
Documentation and tests are updated and extended with the new functions.

Reviewed By: martong

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

Added: 
clang/test/Analysis/wstring.c

Modified: 
clang/docs/analyzer/checkers.rst
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp

Removed: 




diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index da53fad14bc57..81312a8fa229b 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -952,7 +952,7 @@ Check the size argument passed into C string functions for 
common erroneous patt
 unix.cstring.NullArg (C)
 "
 Check for null pointers being passed as arguments to C string functions:
-``strlen, strnlen, strcpy, strncpy, strcat, strncat, strcmp, strncmp, 
strcasecmp, strncasecmp``.
+``strlen, strnlen, strcpy, strncpy, strcat, strncat, strcmp, strncmp, 
strcasecmp, strncasecmp, wcslen, wcsnlen``.
 
 .. code-block:: c
 
@@ -2699,7 +2699,7 @@ Check stream handling functions: ``fopen, tmpfile, 
fclose, fread, fwrite, fseek,
 
 alpha.unix.cstring.BufferOverlap (C)
 
-Checks for overlap in two buffer arguments. Applies to:  ``memcpy, mempcpy``.
+Checks for overlap in two buffer arguments. Applies to:  ``memcpy, mempcpy, 
wmemcpy``.
 
 .. code-block:: c
 
@@ -2712,7 +2712,7 @@ Checks for overlap in two buffer arguments. Applies to:  
``memcpy, mempcpy``.
 
 alpha.unix.cstring.NotNullTerminated (C)
 
-Check for arguments which are not null-terminated strings; applies to: 
``strlen, strnlen, strcpy, strncpy, strcat, strncat``.
+Check for arguments which are not null-terminated strings; applies to: 
``strlen, strnlen, strcpy, strncpy, strcat, strncat, wcslen, wcsnlen``.
 
 .. code-block:: c
 
@@ -2724,15 +2724,24 @@ Check for arguments which are not null-terminated 
strings; applies to: ``strlen,
 
 alpha.unix.cstring.OutOfBounds (C)
 ""
-Check for out-of-bounds access in string functions; applies to:`` strncopy, 
strncat``.
+Check for out-of-bounds access in string functions, such as:
+``memcpy, bcopy, strcpy, strncpy, strcat, strncat, memmove, memcmp, memset`` 
and more.
 
-This check also applies to string literals, except there is a known bug in that
-the analyzer cannot detect embedded NULL characters.
+This check also works with string literals, except there is a known bug in that
+the analyzer cannot detect embedded NULL characters when determining the 
string length.
 
 .. code-block:: c
 
- void test() {
-   int y = strlen((char *)&test); // warn
+ void test1() {
+   const char str[] = "Hello world";
+   char buffer[] = "Hello world";
+   memcpy(buffer, str, sizeof(str) + 1); // warn
+ }
+
+ void test2() {
+   const char str[] = "Hello world";
+   char buffer[] = "Helloworld";
+   memcpy(buffer, str, sizeof(str)); // warn
  }
 
 .. _alpha-unix-cstring-UninitializedRead:

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 987cf65d6fec6..9a6c013bcf66a 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -26,9 +26,11 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 using namespace clang;
 using namespace ento;
+using namespace std::placeholders;
 
 namespace {
 struct AnyArgExpr {
@@ -118,10 +120,14 @@ class CStringChecker : public Checker< eval::Call,
const LocationContext *LCtx,
const CallEvent *Call) const;
 
-  typedef void (CStringChecker::*FnCheck)(CheckerContext &,
-  const CallExpr *) const;
+  using FnCheck = std::function;
+
   CallDescriptionMap Callbacks = {
-  {{CDF_MaybeBuiltin, "memcpy", 3}, &CStringChecker::evalMemcpy},
+  {{CDF_MaybeBuiltin, "memcpy", 3},
+   std::bind(&CStringChecker::evalMemcpy, _1, _2, _3, false)},
+  {{CDF_MaybeBuiltin, "wmemcpy", 3},
+   std::bind(&CStringChecker::evalMemcpy, _1, _2, _3, true)},
   {{CDF_MaybeBuiltin, "mempcpy", 3}, &CStringChecker::evalMempcpy},
   {{CDF_MaybeBuiltin, "memcmp", 3}, &CStringChecker::evalMemcmp},
   {{CDF_MaybeBuiltin, "memmove", 3}, &CStringChecker::evalMemmove},
@@ -135,7 +141,9 @@ class CStringChecker : public 

[PATCH] D130091: [clang][analyzer] Added partial wide character support to CStringChecker

2022-07-25 Thread Balázs Kéri via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG94ca2beccc59: [clang][analyzer] Added partial wide character 
support to CStringChecker (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130091

Files:
  clang/docs/analyzer/checkers.rst
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/wstring.c

Index: clang/test/Analysis/wstring.c
===
--- /dev/null
+++ clang/test/Analysis/wstring.c
@@ -0,0 +1,389 @@
+// RUN: %clang_analyze_cc1 -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix.cstring \
+// RUN:   -analyzer-checker=alpha.unix.cstring \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.UninitializedRead \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false  
+//
+// RUN: %clang_analyze_cc1 -verify %s -DUSE_BUILTINS \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix.cstring \
+// RUN:   -analyzer-checker=alpha.unix.cstring \
+// RUN:   -analyzer-disable-checker=alpha.unix.cstring.UninitializedRead \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false
+
+//===--===
+// Declarations
+//===--===
+
+// Some functions are implemented as builtins. These should be #defined as
+// BUILTIN(f), which will prepend "__builtin_" if USE_BUILTINS is defined.
+
+#ifdef USE_BUILTINS
+# define BUILTIN(f) __builtin_ ## f
+#else /* USE_BUILTINS */
+# define BUILTIN(f) f
+#endif /* USE_BUILTINS */
+
+typedef __SIZE_TYPE__ size_t;
+typedef __WCHAR_TYPE__ wchar_t;
+
+void clang_analyzer_eval(int);
+
+//===--===
+// wwmemcpy()
+//===--===
+
+#define wmemcpy BUILTIN(wmemcpy)
+wchar_t *wmemcpy(wchar_t *restrict s1, const wchar_t *restrict s2, size_t n);
+
+void wmemcpy0 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[4] = {0};
+
+  wmemcpy(dst, src, 4); // no-warning
+
+  clang_analyzer_eval(wmemcpy(dst, src, 4) == dst); // expected-warning{{TRUE}}
+
+  // If we actually model the copy, we can make this known.
+  // The important thing for now is that the old value has been invalidated.
+  clang_analyzer_eval(dst[0] != 0); // expected-warning{{UNKNOWN}}
+}
+
+void wmemcpy1 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[10];
+
+  wmemcpy(dst, src, 5); // expected-warning{{Memory copy function accesses out-of-bound array element}}
+}
+
+void wmemcpy2 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[1];
+
+  wmemcpy(dst, src, 4); // expected-warning {{Memory copy function overflows the destination buffer}}
+}
+
+void wmemcpy3 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[3];
+
+  wmemcpy(dst+1, src+2, 2); // no-warning
+}
+
+void wmemcpy4 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[10];
+
+  wmemcpy(dst+2, src+2, 3); // expected-warning{{Memory copy function accesses out-of-bound array element}}
+}
+
+void wmemcpy5(void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[3];
+
+  wmemcpy(dst + 2, src + 2, 2); // expected-warning{{Memory copy function overflows the destination buffer}}
+}
+
+void wmemcpy6(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a, a, 2); // expected-warning{{overlapping}}
+}
+
+void wmemcpy7(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a+2, a+1, 2); // expected-warning{{overlapping}}
+}
+
+void wmemcpy8(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a+1, a+2, 2); // expected-warning{{overlapping}}
+}
+
+void wmemcpy9(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a+2, a+1, 1); // no-warning
+  wmemcpy(a+1, a+2, 1); // no-warning
+}
+
+void wmemcpy10(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(0, a, 1); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
+}
+
+void wmemcpy11(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a, 0, 1); // expected-warning{{Null pointer passed as 2nd argument to memory copy function}}
+}
+
+void wmemcpy12(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(0, a, 0); // no-warning
+}
+
+void wmemcpy13(void) {
+  wchar_t a[4] = {0};
+  wmemcpy(a, 0, 0); // no-warning
+}
+
+void wmemcpy_unknown_size (size_t n) {
+  wchar_t a[4], b[4] = {1};
+  clang_analyzer_eval(wmemcpy(a, b, n) == a); // expected-warning{{TRUE}}
+}
+
+void wmemcpy_unknown_size_warn (size_t n) {
+  wchar_t a[4];
+  void *result = wmemcpy(a, 0, n); // expected-warning{{Null pointer passed as 2nd argument to memory copy function}}
+  clang_analyzer_eval(result == a); // no-warning (above is fatal)
+}
+
+//===--===
+// wcslen()
+//===

[PATCH] D130460: [pseudo] Add recovery for declarations

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This may well need refinement & more testing, interested in initial thoughts


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130460

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


[PATCH] D130460: [pseudo] Add recovery for declarations

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

- declaration recovery strategy: search for likely declaration boundaries
- change decl-sequence to right-recursive to simplify this
- also use for class members (already right-recursive)
- refactor recovery strategy to use struct parameter and expose cursor position


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130460

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Language.h
  clang-tools-extra/pseudo/include/clang-pseudo/Token.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/cxx/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/recovery-declarations.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp

Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -48,13 +48,13 @@
testing::UnorderedElementsAreArray(Parents));
 }
 
-Token::Index recoverBraces(Token::Index Begin, const TokenStream &Code) {
-  EXPECT_GT(Begin, 0u);
-  const Token &Left = Code.tokens()[Begin - 1];
+Token::Index recoverBraces(const RecoveryParams &P) {
+  EXPECT_GT(P.Begin, 0u);
+  const Token &Left = P.Tokens.tokens()[P.Begin - 1];
   EXPECT_EQ(Left.Kind, tok::l_brace);
   if (const auto* Right = Left.pair()) {
 EXPECT_EQ(Right->Kind, tok::r_brace);
-return Code.index(*Right);
+return P.Tokens.index(*Right);
   }
   return Token::Invalid;
 }
Index: clang-tools-extra/pseudo/test/cxx/recovery-declarations.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/recovery-declarations.cpp
@@ -0,0 +1,22 @@
+// RUN: clang-pseudo -grammar=cxx -source=%s --print-forest | FileCheck %s
+
+this is not a valid declaration;
+// CHECK: declaration := 
+
+int x[0];
+// CHECK:  simple-declaration := decl-specifier-seq init-declarator-list ;
+// CHECK-NEXT: ├─decl-specifier-seq~INT := tok[7]
+// CHECK-NEXT: ├─init-declarator-list~noptr-declarator := noptr-declarator [ constant-expression ]
+
+also_not_ok ??? @@@ (;
+// CHECK: declaration := 
+
+class Y{};
+// CHECK:  simple-declaration := decl-specifier-seq ;
+// CHECK-NEXT: ├─decl-specifier-seq~class-specifier := class-head { }
+
+// FIXME: support recovery of incomplete scopes
+// namespace foo {
+
+class class class class function
+// CHECK: declaration := 
Index: clang-tools-extra/pseudo/lib/cxx/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx/cxx.bnf
@@ -309,8 +309,7 @@
 declaration-statement := block-declaration
 
 # gram.dcl
-declaration-seq := declaration
-declaration-seq := declaration-seq declaration
+declaration-seq := declaration [recover=NextDeclaration] declaration-seq_opt
 declaration := block-declaration
 declaration := nodeclspec-function-declaration
 declaration := function-definition
@@ -535,13 +534,12 @@
 module-partition := : module-name-qualifier_opt IDENTIFIER
 module-name-qualifier := IDENTIFIER .
 module-name-qualifier := module-name-qualifier IDENTIFIER .
-export-declaration := EXPORT declaration
-export-declaration := EXPORT ( declaration-seq_opt )
+export-declaration := EXPORT { declaration-seq_opt }
 export-declaration := export-keyword module-import-declaration
-module-import-declaration := import-keyword module-name
-module-import-declaration := import-keyword module-partition
+module-import-declaration := import-keyword module-name ;
+module-import-declaration := import-keyword module-partition ;
 # FIXME: we don't have header-name in the grammar. Handle these in PP?
-# module-import-declaration := import-keyword header-name
+# module-import-declaration := import-keyword header-name ;
 global-module-fragment := module-keyword ; declaration-seq_opt
 private-module-fragment := module-keyword : PRIVATE ; declaration-seq_opt
 
@@ -554,7 +552,7 @@
 class-key := CLASS
 class-key := STRUCT
 class-key := UNION
-member-specification := member-declaration member-specification_opt
+member-specification := member-declaration [recover=NextDeclaration] member-specification_opt
 member-specification := access-specifier : member-specification_opt
 member-declaration := decl-specifier-seq_opt member-declarator-list_opt ;
 member-declaration := function-definition
Index: clang-tools-extra/pseudo/lib/cxx/CXX.cpp
===
--- clang-tools-extra/pseudo/lib/cxx/CXX.cpp
+++ clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -252,21 +252,122 @@
 #undef SYMBOL_GUARD
 }
 
-Token::Index recoverBrackets(Token::Index Begin

[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/include/clang/Sema/Scope.h:213-215
+  /// A single NRVO candidate variable in this scope, or nullptr if the
+  /// candidate is not available/allowed in this scope.
+  Optional NRVO;

Now NRVO has three states, None, nullptr and non-null value.But it doesn't show 
in comments and implementations.



Comment at: clang/lib/Sema/Scope.cpp:151
+void Scope::applyNRVOAndMergeItIntoParent() {
+  if (!NRVO.hasValue())
+// There is no NRVO candidate in the current scope.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D128695: [ODRHash diagnostics] Move `ODRDiagsEmitter` to libAST in separate files. NFC.

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

I see. It looks like the tricks in `.git-blame-ignore-revs` doesn't work for 
this kind of move. I admit I don't look these changes in details. But as long 
as it is helpful for future changes, I think it should be good.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128695

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


[PATCH] D111617: [RISCV] Lazily add RVV C intrinsics.

2022-07-25 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng added a comment.

@aaron.ballman do you mind give few more look on this patch, we would like 
gather LGTM from both RISC-V folks and clang folks, thanks :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111617

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


[clang-tools-extra] 661e0b6 - [pseudo] Fix minor errors in module grammar

2022-07-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-07-25T10:04:56+02:00
New Revision: 661e0b63f721832ab1015e32a4399470a625098f

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

LOG: [pseudo] Fix minor errors in module grammar

Added: 


Modified: 
clang-tools-extra/pseudo/lib/cxx/cxx.bnf

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx/cxx.bnf 
b/clang-tools-extra/pseudo/lib/cxx/cxx.bnf
index 8138d0fd481ed..ca8fc01b8f414 100644
--- a/clang-tools-extra/pseudo/lib/cxx/cxx.bnf
+++ b/clang-tools-extra/pseudo/lib/cxx/cxx.bnf
@@ -536,12 +536,12 @@ module-partition := : module-name-qualifier_opt IDENTIFIER
 module-name-qualifier := IDENTIFIER .
 module-name-qualifier := module-name-qualifier IDENTIFIER .
 export-declaration := EXPORT declaration
-export-declaration := EXPORT ( declaration-seq_opt )
+export-declaration := EXPORT { declaration-seq_opt }
 export-declaration := export-keyword module-import-declaration
-module-import-declaration := import-keyword module-name
-module-import-declaration := import-keyword module-partition
+module-import-declaration := import-keyword module-name ;
+module-import-declaration := import-keyword module-partition ;
 # FIXME: we don't have header-name in the grammar. Handle these in PP?
-# module-import-declaration := import-keyword header-name
+# module-import-declaration := import-keyword header-name ;
 global-module-fragment := module-keyword ; declaration-seq_opt
 private-module-fragment := module-keyword : PRIVATE ; declaration-seq_opt
 



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


[PATCH] D130414: [pseudo] Reorganize CXX.h enums

2022-07-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks for exploring the idea, this looks like a good start to me.




Comment at: clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h:54
+namespace rules {
+namespace dummy {
+enum Rule {

why there is a dummy namespace here?



Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:119
 
-switch ((cxx::Rule)Declarator->rule()) {
-case Rule::noptr_declarator_0declarator_id: // reached the bottom
+switch (Declarator->rule()) {
+case rule::noptr_declarator::declarator_id: // reached the bottom

The code of applying the pattern doesn't look much worse to me and it is easier 
to verify the exhaustiveness by human as well. We might loose some performance 
(I hope not a lot), but I think it is a good tradeoff (not saying we need do it 
in this patch).

```
switch (LHSNonterminal(Declarator->rule(), *G)) {
   case cxx::Symbol::noptr_declarator: {
  switch ((rule::noptr_declarator)Declarator->rule())  {
 case rule::noptr_declarator::declarator_id:
 
 case 
rule::noptr_declarator::noptr_declarator__parameters_and_qualifiers:
 
  }
   ...
   }
}
```



Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:175
   return {
-  {(RuleID)Rule::function_declarator_0declarator,
SYMBOL_GUARD(declarator, isFunctionDeclarator(&N))},

A nice improvement



Comment at: clang-tools-extra/pseudo/lib/grammar/Grammar.cpp:51
 #define TOK(X) #X,
-#define KEYWORD(X, Y) #X,
+#define KEYWORD(Keyword, Condition) llvm::StringRef(#Keyword).upper(),
 #include "clang/Basic/TokenKinds.def"

IMO, this improves the readability, and also aligns with the text in the 
cxx.grammar.



Comment at: clang-tools-extra/pseudo/lib/grammar/Grammar.cpp:62
 
 std::string Grammar::mangleRule(RuleID RID) const {
   const auto &R = lookupRule(RID);

nit: update the doc comment in .h file.



Comment at: clang-tools-extra/pseudo/lib/grammar/Grammar.cpp:64
   const auto &R = lookupRule(RID);
-  std::string MangleName = mangleSymbol(R.Target);
-  for (size_t I = 0; I < R.seq().size(); ++I)
-MangleName += llvm::formatv("_{0}{1}", I, mangleSymbol(R.seq()[I]));
+  std::string MangleName;
+  for (size_t I = 0; I < R.seq().size(); ++I) {

nit: we don't allow nullable nonterminals, so the RHS should never be empty. we 
could just initialize `MangleName` with `mangleSymbol(R.seq()[0])`, and iterate 
from 1 (then the trailing two `pop_back` is not needed).




Comment at: clang-tools-extra/pseudo/lib/grammar/Grammar.cpp:65
+  std::string MangleName;
+  for (size_t I = 0; I < R.seq().size(); ++I) {
+MangleName += mangleSymbol(R.seq()[I]);

ok, now we're dropping the index for all RHS symbols. Just want to know your 
thought about this. Personally, I'd like to keep this information 
(`noptr_declarator__l_square__constant_expression__r_square` vs 
`noptr_declarator0_l_square1_constant_expression2_r_square3`) though it makes 
the name a bit uglier.

> Change mangling of keywords to ALL_CAPS (needed to turn keywords that appear 
> alone on RHS into valid identifiers)

if we add index number to the name, then this change is not required.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130414

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


[PATCH] D130145: [AArch64] Simplify BTI/PAC-RET module flags

2022-07-25 Thread Daniel Kiss via Phabricator via cfe-commits
danielkiss added inline comments.



Comment at: llvm/lib/IR/AutoUpgrade.cpp:4415-4430
-// Upgrade branch protection and return address signing module flags. The
-// module flag behavior for these fields were Error and now they are Min.
-if (ID->getString() == "branch-target-enforcement" ||
-ID->getString().startswith("sign-return-address")) {
-  if (auto *Behavior =
-  mdconst::dyn_extract_or_null(Op->getOperand(0))) {
-if (Behavior->getLimitedValue() == Module::Error) {

MaskRay wrote:
> danielkiss wrote:
> > In a full LTO build the linker will complain about the mis match between 
> > the flags if one of the objects compiled with an older compiler that 
> > emitted `Module:Error` for these flags.
> The new approach doesnot emit a flag for 0 value, so there won't be an error 
> even with old bitcode files using `Error`.
older compiler could emit `Module:Error` with 0 and with this patch we emit 1 
with `min` so the linker will stop with 
`ld.lld: error: linking module flags 'branch-target-enforcement': IDs have 
conflicting behaviors in 'foo.o' and 'ld-temp.o'`

```
clang++-13 -flto=full -c foo.cpp -o foo.o
../build/bin/clang++ -flto=full -c main.cpp -o main.o 
-mbranch-protection=standard
../build/bin/clang++ -fuse-ld=lld main.o foo.o -o a.out
```



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130145

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


[clang] acd80a2 - [clang][ASTImporter] Improved handling of functions with auto return type.

2022-07-25 Thread Balázs Kéri via cfe-commits

Author: Balázs Kéri
Date: 2022-07-25T10:28:01+02:00
New Revision: acd80a29ae7dcffabcb41e8579ebf4f371f0ddd7

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

LOG: [clang][ASTImporter] Improved handling of functions with auto return type.

Avoid a crash if a function is imported that has auto return type that
references to a template with an expression-type of argument that
references into the function's body.
Fixes issue #56047

Reviewed By: martong

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index f7e7b73d12189..0273e50683716 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -12,9 +12,9 @@
 
//===--===//
 
 #include "clang/AST/ASTImporter.h"
-#include "clang/AST/ASTImporterSharedState.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTDiagnostic.h"
+#include "clang/AST/ASTImporterSharedState.h"
 #include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -34,6 +34,7 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -58,8 +59,8 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
-#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -3219,9 +3220,12 @@ Error 
ASTNodeImporter::ImportFunctionDeclBody(FunctionDecl *FromFD,
 }
 
 // Returns true if the given D has a DeclContext up to the TranslationUnitDecl
-// which is equal to the given DC.
+// which is equal to the given DC, or D is equal to DC.
 static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
-  const DeclContext *DCi = D->getDeclContext();
+  const DeclContext *DCi = dyn_cast(D);
+  if (!DCi)
+DCi = D->getDeclContext();
+  assert(DCi && "Declaration should have a context");
   while (DCi != D->getTranslationUnitDecl()) {
 if (DCi == DC)
   return true;
@@ -3230,9 +3234,36 @@ static bool isAncestorDeclContextOf(const DeclContext 
*DC, const Decl *D) {
   return false;
 }
 
+// Returns true if the statement S has a parent declaration that has a
+// DeclContext that is inside (or equal to) DC. In a specific use case if DC is
+// a FunctionDecl, check if statement S resides in the body of the function.
+static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
+  ParentMapContext &ParentC = DC->getParentASTContext().getParentMapContext();
+  DynTypedNodeList Parents = ParentC.getParents(*S);
+  while (!Parents.empty()) {
+if (const Decl *PD = Parents.begin()->get())
+  return isAncestorDeclContextOf(DC, PD);
+Parents = ParentC.getParents(*Parents.begin());
+  }
+  return false;
+}
+
 static bool hasTypeDeclaredInsideFunction(QualType T, const FunctionDecl *FD) {
   if (T.isNull())
 return false;
+
+  auto CheckTemplateArgument = [FD](const TemplateArgument &Arg) {
+switch (Arg.getKind()) {
+case TemplateArgument::Type:
+  return hasTypeDeclaredInsideFunction(Arg.getAsType(), FD);
+case TemplateArgument::Expression:
+  return isAncestorDeclContextOf(FD, Arg.getAsExpr());
+default:
+  // FIXME: Handle other argument kinds.
+  return false;
+}
+  };
+
   if (const auto *RecordT = T->getAs()) {
 const RecordDecl *RD = RecordT->getDecl();
 assert(RD);
@@ -3241,12 +3272,15 @@ static bool hasTypeDeclaredInsideFunction(QualType T, 
const FunctionDecl *FD) {
   return true;
 }
 if (const auto *RDTempl = dyn_cast(RD))
-  return llvm::count_if(RDTempl->getTemplateArgs().asArray(),
-[FD](const TemplateArgument &Arg) {
-  return hasTypeDeclaredInsideFunction(
-  Arg.getAsType(), FD);
-});
+  if (llvm::count_if(RDTempl->getTemplateArgs().asArray(),
+ CheckTemplateArgument))
+return true;
+// Note: It is possible that T can be get as both a RecordType and a
+// TemplateSpecializationType.
   }
+  if (const auto *TST = T->getAs())
+return llvm::count_if(TST->template_arguments(), CheckTemplateArgument);
+
   return false;
 }
 

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittes

[PATCH] D129640: [clang][ASTImporter] Improved handling of functions with auto return type.

2022-07-25 Thread Balázs Kéri 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 rGacd80a29ae7d: [clang][ASTImporter] Improved handling of 
functions with auto return type. (authored by balazske).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129640

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

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6320,6 +6320,24 @@
 
 struct ImportAutoFunctions : ASTImporterOptionSpecificTestBase {};
 
+TEST_P(ImportAutoFunctions, ReturnWithTemplateWithIntegerArgDeclaredInside) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template struct Tmpl {};
+  auto foo() {
+constexpr int X = 1;
+return Tmpl();
+  }
+  )",
+  Lang_CXX14, "input0.cc");
+  FunctionDecl *From = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("foo")));
+
+  FunctionDecl *To = Import(From, Lang_CXX14);
+  EXPECT_TRUE(To);
+  EXPECT_TRUE(isa(To->getReturnType()));
+}
+
 TEST_P(ImportAutoFunctions, ReturnWithTemplateWithStructDeclaredInside1) {
   Decl *FromTU = getTuDecl(
   R"(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -12,9 +12,9 @@
 //===--===//
 
 #include "clang/AST/ASTImporter.h"
-#include "clang/AST/ASTImporterSharedState.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ASTDiagnostic.h"
+#include "clang/AST/ASTImporterSharedState.h"
 #include "clang/AST/ASTStructuralEquivalence.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -34,6 +34,7 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -58,8 +59,8 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
-#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -3219,9 +3220,12 @@
 }
 
 // Returns true if the given D has a DeclContext up to the TranslationUnitDecl
-// which is equal to the given DC.
+// which is equal to the given DC, or D is equal to DC.
 static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
-  const DeclContext *DCi = D->getDeclContext();
+  const DeclContext *DCi = dyn_cast(D);
+  if (!DCi)
+DCi = D->getDeclContext();
+  assert(DCi && "Declaration should have a context");
   while (DCi != D->getTranslationUnitDecl()) {
 if (DCi == DC)
   return true;
@@ -3230,9 +3234,36 @@
   return false;
 }
 
+// Returns true if the statement S has a parent declaration that has a
+// DeclContext that is inside (or equal to) DC. In a specific use case if DC is
+// a FunctionDecl, check if statement S resides in the body of the function.
+static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
+  ParentMapContext &ParentC = DC->getParentASTContext().getParentMapContext();
+  DynTypedNodeList Parents = ParentC.getParents(*S);
+  while (!Parents.empty()) {
+if (const Decl *PD = Parents.begin()->get())
+  return isAncestorDeclContextOf(DC, PD);
+Parents = ParentC.getParents(*Parents.begin());
+  }
+  return false;
+}
+
 static bool hasTypeDeclaredInsideFunction(QualType T, const FunctionDecl *FD) {
   if (T.isNull())
 return false;
+
+  auto CheckTemplateArgument = [FD](const TemplateArgument &Arg) {
+switch (Arg.getKind()) {
+case TemplateArgument::Type:
+  return hasTypeDeclaredInsideFunction(Arg.getAsType(), FD);
+case TemplateArgument::Expression:
+  return isAncestorDeclContextOf(FD, Arg.getAsExpr());
+default:
+  // FIXME: Handle other argument kinds.
+  return false;
+}
+  };
+
   if (const auto *RecordT = T->getAs()) {
 const RecordDecl *RD = RecordT->getDecl();
 assert(RD);
@@ -3241,12 +3272,15 @@
   return true;
 }
 if (const auto *RDTempl = dyn_cast(RD))
-  return llvm::count_if(RDTempl->getTemplateArgs().asArray(),
-[FD](const TemplateArgument &Arg) {
-  return hasTypeDeclaredInsideFunction(
-  Arg.getAsType(), FD);
-});
+  if (llvm::count_if(RDTempl->getTemplateArgs().asArray(),
+ CheckTemplateArgument))
+return true;
+// Note: It is possible that

[PATCH] D130414: [pseudo] Reorganize CXX.h enums

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h:54
+namespace rules {
+namespace dummy {
+enum Rule {

hokein wrote:
> why there is a dummy namespace here?
for each NT, we close the previous ns+enum and open new ones.
For this to work for the first NT, we have to open an ns+enum.

I can add a comment, but would prefer to do this some other way?



Comment at: clang-tools-extra/pseudo/lib/cxx/CXX.cpp:119
 
-switch ((cxx::Rule)Declarator->rule()) {
-case Rule::noptr_declarator_0declarator_id: // reached the bottom
+switch (Declarator->rule()) {
+case rule::noptr_declarator::declarator_id: // reached the bottom

hokein wrote:
> The code of applying the pattern doesn't look much worse to me and it is 
> easier to verify the exhaustiveness by human as well. We might loose some 
> performance (I hope not a lot), but I think it is a good tradeoff (not saying 
> we need do it in this patch).
> 
> ```
> switch (LHSNonterminal(Declarator->rule(), *G)) {
>case cxx::Symbol::noptr_declarator: {
>   switch ((rule::noptr_declarator)Declarator->rule())  {
>  case rule::noptr_declarator::declarator_id:
>  
>  case 
> rule::noptr_declarator::noptr_declarator__parameters_and_qualifiers:
>  
>   }
>...
>}
> }
> ```
I guess this is a question of taste, but I find that style very hard to read.

(Note that it's incorrectly indented, and the indentation rules around 
switch/case are one of the main reasons I find nested switches confusing)



Comment at: clang-tools-extra/pseudo/lib/grammar/Grammar.cpp:51
 #define TOK(X) #X,
-#define KEYWORD(X, Y) #X,
+#define KEYWORD(Keyword, Condition) llvm::StringRef(#Keyword).upper(),
 #include "clang/Basic/TokenKinds.def"

hokein wrote:
> IMO, this improves the readability, and also aligns with the text in the 
> cxx.grammar.
Thanks. I like this change too. We still have `semi` vs `;` (should we use 
`SEMI`?) but it feels clearer



Comment at: clang-tools-extra/pseudo/lib/grammar/Grammar.cpp:62
 
 std::string Grammar::mangleRule(RuleID RID) const {
   const auto &R = lookupRule(RID);

hokein wrote:
> nit: update the doc comment in .h file.
Honestly I would rather just move the impl back into gen - this change seems to 
demonstrate why



Comment at: clang-tools-extra/pseudo/lib/grammar/Grammar.cpp:65
+  std::string MangleName;
+  for (size_t I = 0; I < R.seq().size(); ++I) {
+MangleName += mangleSymbol(R.seq()[I]);

hokein wrote:
> ok, now we're dropping the index for all RHS symbols. Just want to know your 
> thought about this. Personally, I'd like to keep this information 
> (`noptr_declarator__l_square__constant_expression__r_square` vs 
> `noptr_declarator0_l_square1_constant_expression2_r_square3`) though it makes 
> the name a bit uglier.
> 
> > Change mangling of keywords to ALL_CAPS (needed to turn keywords that 
> > appear alone on RHS into valid identifiers)
> 
> if we add index number to the name, then this change is not required.
Short version: I can deal with the numbers at the front (there's a *little* bit 
of value), but at the back of the symbol name there's no value, just noise. I 
find the double-underscore version much more readable (than either variant with 
numbers).

---

I always found the indexes aesthetically ugly but OK when you could read them as
```
lhs _   0 rhsa_ 1 rhsb
lhs := [0]rhsa [1]rhsb
```

But an identifier can't start with a number (`rule::empty_statement::0semi`) 
this isn't possible. I think you suggested shifting the numbers to the end, but 
I can't find a way to read that, it adds too much visual noise. (e.g. because 
the number "decorations" don't line up in a column in code completion or a 
switch statement).

I also think the double-underscore version is significantly less cryptic for 
new readers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130414

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


[PATCH] D130338: [CMake] Copy folder without permissions

2022-07-25 Thread Sebastian Neubauer 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 rGefe1527e28ca: [CMake] Copy folder without permissions 
(authored by sebastian-ne).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130338

Files:
  clang/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/CMakeLists.txt
  mlir/cmake/modules/CMakeLists.txt


Index: mlir/cmake/modules/CMakeLists.txt
===
--- mlir/cmake/modules/CMakeLists.txt
+++ mlir/cmake/modules/CMakeLists.txt
@@ -42,9 +42,12 @@
 
 # For compatibility with projects that include(MLIRConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
+# Copy without source permissions because the source could be read-only,
+# but we need to write into the copied folder.
 # This should be removed in the future.
 file(COPY .
   DESTINATION ${mlir_cmake_builddir}
+  NO_SOURCE_PERMISSIONS
   FILES_MATCHING PATTERN *.cmake
   PATTERN CMakeFiles EXCLUDE
   )
Index: llvm/cmake/modules/CMakeLists.txt
===
--- llvm/cmake/modules/CMakeLists.txt
+++ llvm/cmake/modules/CMakeLists.txt
@@ -99,9 +99,12 @@
 
 # For compatibility with projects that include(LLVMConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
+# Copy without source permissions because the source could be read-only,
+# but we need to write into the copied folder.
 # This should be removed in the future.
 file(COPY .
   DESTINATION ${llvm_cmake_builddir}
+  NO_SOURCE_PERMISSIONS
   FILES_MATCHING PATTERN *.cmake
   PATTERN CMakeFiles EXCLUDE
   )
Index: clang/cmake/modules/CMakeLists.txt
===
--- clang/cmake/modules/CMakeLists.txt
+++ clang/cmake/modules/CMakeLists.txt
@@ -32,7 +32,8 @@
 
 # For compatibility with projects that include(ClangConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
-# Copy without source permissions because the source could be read-only
+# Copy without source permissions because the source could be read-only,
+# but we need to write into the copied folder.
 file(COPY .
   DESTINATION ${clang_cmake_builddir}
   NO_SOURCE_PERMISSIONS


Index: mlir/cmake/modules/CMakeLists.txt
===
--- mlir/cmake/modules/CMakeLists.txt
+++ mlir/cmake/modules/CMakeLists.txt
@@ -42,9 +42,12 @@
 
 # For compatibility with projects that include(MLIRConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
+# Copy without source permissions because the source could be read-only,
+# but we need to write into the copied folder.
 # This should be removed in the future.
 file(COPY .
   DESTINATION ${mlir_cmake_builddir}
+  NO_SOURCE_PERMISSIONS
   FILES_MATCHING PATTERN *.cmake
   PATTERN CMakeFiles EXCLUDE
   )
Index: llvm/cmake/modules/CMakeLists.txt
===
--- llvm/cmake/modules/CMakeLists.txt
+++ llvm/cmake/modules/CMakeLists.txt
@@ -99,9 +99,12 @@
 
 # For compatibility with projects that include(LLVMConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
+# Copy without source permissions because the source could be read-only,
+# but we need to write into the copied folder.
 # This should be removed in the future.
 file(COPY .
   DESTINATION ${llvm_cmake_builddir}
+  NO_SOURCE_PERMISSIONS
   FILES_MATCHING PATTERN *.cmake
   PATTERN CMakeFiles EXCLUDE
   )
Index: clang/cmake/modules/CMakeLists.txt
===
--- clang/cmake/modules/CMakeLists.txt
+++ clang/cmake/modules/CMakeLists.txt
@@ -32,7 +32,8 @@
 
 # For compatibility with projects that include(ClangConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
-# Copy without source permissions because the source could be read-only
+# Copy without source permissions because the source could be read-only,
+# but we need to write into the copied folder.
 file(COPY .
   DESTINATION ${clang_cmake_builddir}
   NO_SOURCE_PERMISSIONS
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] efe1527 - [CMake] Copy folder without permissions

2022-07-25 Thread Sebastian Neubauer via cfe-commits

Author: Sebastian Neubauer
Date: 2022-07-25T10:47:04+02:00
New Revision: efe1527e28ca45d2217d874364a1197de6ec156d

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

LOG: [CMake] Copy folder without permissions

Copying the folder keeps the original permissions by default. This
creates problems when the source folder is read-only, e.g. in a
packaging environment.
Then, the copied folder in the build directory is read-only as well.
Later on, other files are copied into that directory (in the build
tree), failing when the directory is read-only.

Fix that problem by copying the folder without keeping the original
permissions.

Follow-up to D130254.

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

Added: 


Modified: 
clang/cmake/modules/CMakeLists.txt
llvm/cmake/modules/CMakeLists.txt
mlir/cmake/modules/CMakeLists.txt

Removed: 




diff  --git a/clang/cmake/modules/CMakeLists.txt 
b/clang/cmake/modules/CMakeLists.txt
index c6afdab40d65b..5d41661f03e83 100644
--- a/clang/cmake/modules/CMakeLists.txt
+++ b/clang/cmake/modules/CMakeLists.txt
@@ -32,7 +32,8 @@ set(CLANG_CONFIG_LLVM_CMAKE_DIR)
 
 # For compatibility with projects that include(ClangConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
-# Copy without source permissions because the source could be read-only
+# Copy without source permissions because the source could be read-only,
+# but we need to write into the copied folder.
 file(COPY .
   DESTINATION ${clang_cmake_builddir}
   NO_SOURCE_PERMISSIONS

diff  --git a/llvm/cmake/modules/CMakeLists.txt 
b/llvm/cmake/modules/CMakeLists.txt
index 42bf5bc0feeba..d4453f255f7da 100644
--- a/llvm/cmake/modules/CMakeLists.txt
+++ b/llvm/cmake/modules/CMakeLists.txt
@@ -99,9 +99,12 @@ set(llvm_config_include_buildtree_only_exports)
 
 # For compatibility with projects that include(LLVMConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
+# Copy without source permissions because the source could be read-only,
+# but we need to write into the copied folder.
 # This should be removed in the future.
 file(COPY .
   DESTINATION ${llvm_cmake_builddir}
+  NO_SOURCE_PERMISSIONS
   FILES_MATCHING PATTERN *.cmake
   PATTERN CMakeFiles EXCLUDE
   )

diff  --git a/mlir/cmake/modules/CMakeLists.txt 
b/mlir/cmake/modules/CMakeLists.txt
index c2407c04ae47a..139705593e720 100644
--- a/mlir/cmake/modules/CMakeLists.txt
+++ b/mlir/cmake/modules/CMakeLists.txt
@@ -42,9 +42,12 @@ set(MLIR_CONFIG_INCLUDE_DIRS)
 
 # For compatibility with projects that include(MLIRConfig)
 # via CMAKE_MODULE_PATH, place API modules next to it.
+# Copy without source permissions because the source could be read-only,
+# but we need to write into the copied folder.
 # This should be removed in the future.
 file(COPY .
   DESTINATION ${mlir_cmake_builddir}
+  NO_SOURCE_PERMISSIONS
   FILES_MATCHING PATTERN *.cmake
   PATTERN CMakeFiles EXCLUDE
   )



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


[PATCH] D130181: [clang-tidy] Add readability-use-early-exits check

2022-07-25 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 447236.
njames93 added a comment.

Add option `SplitConjunctions` to alter fix-it for `if` statements with `&&` in 
the condition.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130181

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/UseEarlyExitsCheck.cpp
  clang-tools-extra/clang-tidy/readability/UseEarlyExitsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/use-early-exits.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits-braces.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits-split.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits.cpp
@@ -0,0 +1,164 @@
+// RUN: %check_clang_tidy %s readability-use-early-exits -format-style=llvm %t -- \
+// RUN:   -config="{CheckOptions: {readability-use-early-exits.LineCountThreshold: 2}}"
+
+// Run the check with the braces around statements check also enabled, but
+// ShortStatementLines is set so that we shouldn't add braces.
+// RUN: %check_clang_tidy %s readability-use-early-exits,readability-braces-around-statements -format-style=llvm %t -- \
+// RUN:   -config="{CheckOptions: {readability-use-early-exits.LineCountThreshold: 2, \
+// RUN:readability-braces-around-statements.ShortStatementLines: 2}}"
+
+// Just to hit the threshold
+void padLines();
+
+void nomralFunc(int *A) {
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: use early exit
+  if (A) {
+*A = 10;
+  }
+  //   CHECK-FIXES: if (!A)
+  //  CHECK-FIXES-NEXT: return;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: *A = 10;
+}
+
+void funcWithTrailing(int *B) {
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: use early exit
+  if (B) {
+*B = 10;
+  }
+  return;
+  ;
+  //   CHECK-FIXES: if (!B)
+  //  CHECK-FIXES-NEXT: return;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: *B = 10;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: return;
+  //  CHECK-FIXES-NEXT: ;
+}
+
+void normal(int A, int B) {
+
+  while (true) { // CHECK-MESSAGES: [[@LINE+1]]:5: warning: use early exit
+if (A == B) {
+  padLines();
+}
+  }
+  //   CHECK-FIXES:  while (true) {
+  //  CHECK-FIXES-NEXT: if (A != B)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: padLines();
+  //  CHECK-FIXES-NEXT: }
+
+  // Eat continue and empty nulls
+  while (true) { // CHECK-MESSAGES: [[@LINE+1]]:5: warning: use early exit
+if (A != B) {
+  padLines();
+}
+continue;
+;
+continue;
+  }
+  //   CHECK-FIXES:  while (true) {
+  //  CHECK-FIXES-NEXT: if (A == B)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: padLines();
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT:   continue;
+  //  CHECK-FIXES-NEXT:   ;
+  //  CHECK-FIXES-NEXT:   continue;
+  //  CHECK-FIXES-NEXT: }
+}
+
+void toShort(int A, int B) {
+  while (true) {
+if (A == B) {
+}
+  }
+}
+
+void hasElse(int A, int B) {
+  while (true) {
+if (A == B) {
+
+} else {
+}
+  }
+}
+
+void hasTrailingStmt(int A, int B) {
+  while (true) {
+if (A == B) {
+}
+padLines();
+  }
+}
+
+void nested(int A, int B) {
+  // if (A > B) {
+  // CHECK-MESSAGES: [[@LINE+6]]:5: warning: use early exit
+  // if (B < A) {
+  // CHECK-MESSAGES: [[@LINE+5]]:7: warning: use early exit
+  // if (A == B) {
+  // CHECK-MESSAGES: [[@LINE+4]]:9: warning: use early exit
+  while (true) { // Nested
+if (A > B) {
+  if (B < A) {
+if (A != B) {
+  padLines();
+}
+  }
+}
+  } // EndLoop
+  //   CHECK-FIXES: while (true) { // Nested
+  //  CHECK-FIXES-NEXT: if (A <= B)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: if (B >= A)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: if (A == B)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: padLines();
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: } // EndLoop
+}
+
+void badNested(bool B) {
+  // Ensure check doesn't check for nested `if` if outer `if` has else.
+  while (true) {
+if (B) {
+  if (B) {
+  }
+} else {
+}
+  }
+}
+
+void semiNested(int A, int B) {
+  // CHECK-MESSAGES: [[@LINE+2]]:5: warning: use early exit
+  while (true) { // SemiNested
+if (A > B) {
+  if (B < A) {
+if (A != B) {
+  padLines()

[PATCH] D130181: [clang-tidy] Add readability-use-early-exits check

2022-07-25 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 447246.
njames93 added a comment.

NL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130181

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/UseEarlyExitsCheck.cpp
  clang-tools-extra/clang-tidy/readability/UseEarlyExitsCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability/use-early-exits.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits-braces.cpp
  
clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits-split.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability/use-early-exits.cpp
@@ -0,0 +1,164 @@
+// RUN: %check_clang_tidy %s readability-use-early-exits -format-style=llvm %t -- \
+// RUN:   -config="{CheckOptions: {readability-use-early-exits.LineCountThreshold: 2}}"
+
+// Run the check with the braces around statements check also enabled, but
+// ShortStatementLines is set so that we shouldn't add braces.
+// RUN: %check_clang_tidy %s readability-use-early-exits,readability-braces-around-statements -format-style=llvm %t -- \
+// RUN:   -config="{CheckOptions: {readability-use-early-exits.LineCountThreshold: 2, \
+// RUN:readability-braces-around-statements.ShortStatementLines: 2}}"
+
+// Just to hit the threshold
+void padLines();
+
+void nomralFunc(int *A) {
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: use early exit
+  if (A) {
+*A = 10;
+  }
+  //   CHECK-FIXES: if (!A)
+  //  CHECK-FIXES-NEXT: return;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: *A = 10;
+}
+
+void funcWithTrailing(int *B) {
+  // CHECK-MESSAGES: [[@LINE+1]]:3: warning: use early exit
+  if (B) {
+*B = 10;
+  }
+  return;
+  ;
+  //   CHECK-FIXES: if (!B)
+  //  CHECK-FIXES-NEXT: return;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: *B = 10;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: return;
+  //  CHECK-FIXES-NEXT: ;
+}
+
+void normal(int A, int B) {
+
+  while (true) { // CHECK-MESSAGES: [[@LINE+1]]:5: warning: use early exit
+if (A == B) {
+  padLines();
+}
+  }
+  //   CHECK-FIXES:  while (true) {
+  //  CHECK-FIXES-NEXT: if (A != B)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: padLines();
+  //  CHECK-FIXES-NEXT: }
+
+  // Eat continue and empty nulls
+  while (true) { // CHECK-MESSAGES: [[@LINE+1]]:5: warning: use early exit
+if (A != B) {
+  padLines();
+}
+continue;
+;
+continue;
+  }
+  //   CHECK-FIXES:  while (true) {
+  //  CHECK-FIXES-NEXT: if (A == B)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: padLines();
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT:   continue;
+  //  CHECK-FIXES-NEXT:   ;
+  //  CHECK-FIXES-NEXT:   continue;
+  //  CHECK-FIXES-NEXT: }
+}
+
+void toShort(int A, int B) {
+  while (true) {
+if (A == B) {
+}
+  }
+}
+
+void hasElse(int A, int B) {
+  while (true) {
+if (A == B) {
+
+} else {
+}
+  }
+}
+
+void hasTrailingStmt(int A, int B) {
+  while (true) {
+if (A == B) {
+}
+padLines();
+  }
+}
+
+void nested(int A, int B) {
+  // if (A > B) {
+  // CHECK-MESSAGES: [[@LINE+6]]:5: warning: use early exit
+  // if (B < A) {
+  // CHECK-MESSAGES: [[@LINE+5]]:7: warning: use early exit
+  // if (A == B) {
+  // CHECK-MESSAGES: [[@LINE+4]]:9: warning: use early exit
+  while (true) { // Nested
+if (A > B) {
+  if (B < A) {
+if (A != B) {
+  padLines();
+}
+  }
+}
+  } // EndLoop
+  //   CHECK-FIXES: while (true) { // Nested
+  //  CHECK-FIXES-NEXT: if (A <= B)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: if (B >= A)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: if (A == B)
+  //  CHECK-FIXES-NEXT:   continue;
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: padLines();
+  // CHECK-FIXES-EMPTY:
+  //  CHECK-FIXES-NEXT: } // EndLoop
+}
+
+void badNested(bool B) {
+  // Ensure check doesn't check for nested `if` if outer `if` has else.
+  while (true) {
+if (B) {
+  if (B) {
+  }
+} else {
+}
+  }
+}
+
+void semiNested(int A, int B) {
+  // CHECK-MESSAGES: [[@LINE+2]]:5: warning: use early exit
+  while (true) { // SemiNested
+if (A > B) {
+  if (B < A) {
+if (A != B) {
+  padLines();
+}
+  } else {
+  }
+}
+  }
+  //   CHECK-FIXES: while (true) { // 

[PATCH] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-07-25 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 447248.
SixWeining marked 5 inline comments as done.
SixWeining added a comment.

Continue to address @MaskRay's comments: LLVM_LIBRARY_VISIBILITY ...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130255

Files:
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/LoongArch.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/Arch/LoongArch.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Clang.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/bin/.keep
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/include/.keep
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/base/lp64d/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/base/lp64f/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/base/lp64s/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/loongarch64-unknown-linux-gnu/bin/ld
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/loongarch64-unknown-linux-gnu/lib/.keep
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/loongarch64-unknown-linux-gnu/lib64/.keep
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/sysroot/usr/lib/.keep
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/sysroot/usr/lib64/.keep
  clang/test/Driver/frame-pointer.c
  clang/test/Driver/loongarch-abi-error.c
  clang/test/Driver/loongarch-abi.c
  clang/test/Driver/loongarch-toolchain.c
  clang/test/Preprocessor/init-loongarch.c

Index: clang/test/Preprocessor/init-loongarch.c
===
--- /dev/null
+++ clang/test/Preprocessor/init-loongarch.c
@@ -0,0 +1,641 @@
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch32 /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefix=LA32 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch32-unknown-linux /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefixes=LA32,LA32-LINUX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch32 \
+// RUN: -fforce-enable-int128 /dev/null | FileCheck --match-full-lines \
+// RUN: --check-prefixes=LA32,LA32-INT128 %s
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch64 /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefix=LA64 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch64-unknown-linux /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefixes=LA64,LA64-LINUX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch64 \
+// RUN: -fforce-enable-int128 /dev/null | FileCheck --match-full-lines \
+// RUN: --check-prefixes=LA64,LA64-INT128 %s
+
+ Note that common macros are tested in init.c, such as __VERSION__. So they're not listed here.
+
+// LA32: #define _ILP32 1
+// LA32: #define __ATOMIC_ACQUIRE 2
+// LA32-NEXT: #define __ATOMIC_ACQ_REL 4
+// LA32-NEXT: #define __ATOMIC_CONSUME 1
+// LA32-NEXT: #define __ATOMIC_RELAXED 0
+// LA32-NEXT: #define __ATOMIC_RELEASE 3
+// LA32-NEXT: #define __ATOMIC_SEQ_CST 5
+// LA32: #define __BIGGEST_ALIGNMENT__ 16
+// LA32: #define __BITINT_MAXWIDTH__ 128
+// LA32: #define __BOOL_WIDTH__ 8
+// LA32: #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+// LA32: #define __CHAR16_TYPE__ unsigned short
+// LA32: #define __CHAR32_TYPE__ unsigned int
+// LA32: #define __CHAR_BIT__ 8
+// LA32: #define __CLANG_ATOMIC_BOOL_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_CHAR16_T_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_CHAR32_T_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_CHAR_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_INT_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_LLONG_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_LONG_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_POINTER_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_SHORT_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_WCHAR_T_LOCK_FREE 1
+// LA32: #define __DBL_DECIMAL_DIG__ 17
+// LA32: #define __DBL_DENORM_MIN__ 4.9406564584124654e-324
+// LA32: #define __DBL_DIG__ 15
+// LA32: #define __DBL_EPSILON__ 2.2204460492503131e-16
+// LA32: #define __DBL_HAS_DENORM__ 1
+// LA32: #define __DBL_HAS_INFINITY__ 1
+// LA32: #define __DBL_HAS_QUIET_NAN__ 1
+// LA32: #define __DBL_MANT_DIG__ 53
+// LA32: #define __DBL_MAX_10_EXP__ 308
+// LA32: #define __DBL_MAX_EXP__ 1024
+// LA32: #define __DBL_MAX__ 1

[PATCH] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-07-25 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2226
 
+  static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
+  static const char *const LoongArch64Triples[] = {

MaskRay wrote:
> I don't know which of /lib64, /lib has been used. For purity, I'd hope that 
> we just have /lib, no multilib style /lib64
I also don't know the actual usage of /lib64 but I just tried and it works fine 
if I remove /lib64.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2478
+  // TODO: Handle loongarch32.
+  case llvm::Triple::loongarch64:
+LibDirs.append(begin(LoongArch64LibDirs), end(LoongArch64LibDirs));

MaskRay wrote:
> Just add loongarch32 in this patch. It is trivial
But I don't know how to handle loongarch32 because there isn't a loongarch32 
gcc toolchain available yet.



Comment at: clang/test/Driver/loongarch64-toolchain.c:20
+// C-LA64-LINUX-MULTI-LP64D: "-dynamic-linker" 
"/lib64/ld-linux-loongarch-lp64d.so.1"
+// C-LA64-LINUX-MULTI-LP64D: 
"{{.*}}/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/crtbegin.o"
+// C-LA64-LINUX-MULTI-LP64D: 
"-L{{.*}}/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0"

MaskRay wrote:
> Not using NEXT is somewhat brittle.
> 
> Perhaps add `loongarch-toolchain.c` instead. `riscv*-toolchain.c` are not 
> good examples to follow. You may check out linux-cross.cpp
Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130255

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


[PATCH] D130078: [flang][nfc] Rename `AddOtherOptions` as `ForwardOptions`

2022-07-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In D130078#3673288 , @MaskRay wrote:

> In D130078#3669072 , @awarzynski 
> wrote:
>
>> In D130078#3667188 , @MaskRay 
>> wrote:
>>
>>> `forwardOptions` will be better if you are renaming it anyway.
>>
>> I'd rather create a separate patch and update all other methods to follow 
>> LLVM's style. Any idea why the style is not followed in Clang.h 
>> ?
>
> Clang is traditionally unfortunately very inconsistent in the code style 
> When you add new functions, you don't necessarily follow the Clang tradition 
> ;-)

That's a good point :) In fact, let me update other methods in this file as 
well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130078

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


[PATCH] D130078: [flang][nfc] Rename `AddOtherOptions` as `ForwardOptions`

2022-07-25 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski updated this revision to Diff 447250.
awarzynski added a comment.

Change from CamelCase to camelCase in Flang.h so that the function names adhere 
to LLVM's coding style.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130078

Files:
  clang/lib/Driver/ToolChains/Flang.cpp
  clang/lib/Driver/ToolChains/Flang.h


Index: clang/lib/Driver/ToolChains/Flang.h
===
--- clang/lib/Driver/ToolChains/Flang.h
+++ clang/lib/Driver/ToolChains/Flang.h
@@ -29,7 +29,7 @@
   ///
   /// \param [in] Args The list of input driver arguments
   /// \param [out] CmdArgs The list of output command arguments
-  void AddFortranDialectOptions(const llvm::opt::ArgList &Args,
+  void addFortranDialectOptions(const llvm::opt::ArgList &Args,
 llvm::opt::ArgStringList &CmdArgs) const;
 
   /// Extract preprocessing options from the driver arguments and add them to
@@ -37,15 +37,15 @@
   ///
   /// \param [in] Args The list of input driver arguments
   /// \param [out] CmdArgs The list of output command arguments
-  void AddPreprocessingOptions(const llvm::opt::ArgList &Args,
+  void addPreprocessingOptions(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;
-  /// Extract other compilation options from the driver arguments and add them
-  /// to the command arguments.
+
+  /// This method will effectively copy options from \a Args into \a CmdArgs.
   ///
   /// \param [in] Args The list of input driver arguments
   /// \param [out] CmdArgs The list of output command arguments
-  void AddOtherOptions(const llvm::opt::ArgList &Args,
-   llvm::opt::ArgStringList &CmdArgs) const;
+  void forwardOptions(const llvm::opt::ArgList &Args,
+  llvm::opt::ArgStringList &CmdArgs) const;
 
 public:
   Flang(const ToolChain &TC);
Index: clang/lib/Driver/ToolChains/Flang.cpp
===
--- clang/lib/Driver/ToolChains/Flang.cpp
+++ clang/lib/Driver/ToolChains/Flang.cpp
@@ -27,7 +27,7 @@
   CmdArgs.push_back(types::getTypeName(Input.getType()));
 }
 
-void Flang::AddFortranDialectOptions(const ArgList &Args,
+void Flang::addFortranDialectOptions(const ArgList &Args,
  ArgStringList &CmdArgs) const {
   Args.AddAllArgs(
   CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form,
@@ -44,14 +44,14 @@
 options::OPT_fno_automatic});
 }
 
-void Flang::AddPreprocessingOptions(const ArgList &Args,
+void Flang::addPreprocessingOptions(const ArgList &Args,
 ArgStringList &CmdArgs) const {
   Args.AddAllArgs(CmdArgs,
   {options::OPT_P, options::OPT_D, options::OPT_U,
options::OPT_I, options::OPT_cpp, options::OPT_nocpp});
 }
 
-void Flang::AddOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const 
{
+void Flang::forwardOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
   Args.AddAllArgs(CmdArgs,
   {options::OPT_module_dir, options::OPT_fdebug_module_writer,
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
@@ -105,9 +105,9 @@
   // Add preprocessing options like -I, -D, etc. if we are using the
   // preprocessor (i.e. skip when dealing with e.g. binary files).
   if (types::getPreprocessedType(InputType) != types::TY_INVALID)
-AddPreprocessingOptions(Args, CmdArgs);
+addPreprocessingOptions(Args, CmdArgs);
 
-  AddFortranDialectOptions(Args, CmdArgs);
+  addFortranDialectOptions(Args, CmdArgs);
 
   // Color diagnostics are parsed by the driver directly from argv and later
   // re-parsed to construct this job; claim any possible color diagnostic here
@@ -117,8 +117,8 @@
   if (D.getDiags().getDiagnosticOptions().ShowColors)
 CmdArgs.push_back("-fcolor-diagnostics");
 
-  // Add other compile options
-  AddOtherOptions(Args, CmdArgs);
+  // Handle options which are simply forwarded to -fc1.
+  forwardOptions(Args, CmdArgs);
 
   // Forward -Xflang arguments to -fc1
   Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);


Index: clang/lib/Driver/ToolChains/Flang.h
===
--- clang/lib/Driver/ToolChains/Flang.h
+++ clang/lib/Driver/ToolChains/Flang.h
@@ -29,7 +29,7 @@
   ///
   /// \param [in] Args The list of input driver arguments
   /// \param [out] CmdArgs The list of output command arguments
-  void AddFortranDialectOptions(const llvm::opt::ArgList &Args,
+  void addFortranDialectOptions(const llvm::opt::ArgList &Args,
 llvm::opt::ArgStringList &CmdArgs) const;
 
   /// Extract preprocessing options from the driver arguments and add them to
@@ -37,15 +37,15 @@
   ///
   /// \param [in] Args The list of input driver arguments

[PATCH] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-07-25 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2226
 
+  static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
+  static const char *const LoongArch64Triples[] = {

SixWeining wrote:
> MaskRay wrote:
> > I don't know which of /lib64, /lib has been used. For purity, I'd hope that 
> > we just have /lib, no multilib style /lib64
> I also don't know the actual usage of /lib64 but I just tried and it works 
> fine if I remove /lib64.
I don't like `lib64` too.  But for LoongArch LP64D, the path to ELF interpreter 
is hard coded `/lib64/ld-linux-loongarch-lp64d.so.1` and it seems too late to 
change it.  And LoongArch GCC installs libstdc++ etc. for LP64D into 
$PREFIX/lib64 by default (like x86_64).

As a distro (LFS) maintainer: we are already hacking GCC code to get rid of 
`/usr/lib64`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130255

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


[PATCH] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-07-25 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2226
 
+  static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
+  static const char *const LoongArch64Triples[] = {

xry111 wrote:
> SixWeining wrote:
> > MaskRay wrote:
> > > I don't know which of /lib64, /lib has been used. For purity, I'd hope 
> > > that we just have /lib, no multilib style /lib64
> > I also don't know the actual usage of /lib64 but I just tried and it works 
> > fine if I remove /lib64.
> I don't like `lib64` too.  But for LoongArch LP64D, the path to ELF 
> interpreter is hard coded `/lib64/ld-linux-loongarch-lp64d.so.1` and it seems 
> too late to change it.  And LoongArch GCC installs libstdc++ etc. for LP64D 
> into $PREFIX/lib64 by default (like x86_64).
> 
> As a distro (LFS) maintainer: we are already hacking GCC code to get rid of 
> `/usr/lib64`.
Thanks for the quick reply. So I should keep the /lib64 here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130255

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


[PATCH] D101070: [llvm][cmake] Make `install_symlink` robust to absolute dirs.

2022-07-25 Thread Sebastian Neubauer via Phabricator via cfe-commits
sebastian-ne added a comment.

Hi, not sure if you saw D130256 , but I 
needed to extend CMAKE_MODULE_PATH, otherwise the ExtendPath module was not 
found when running LLVMInstallSymlink.cmake.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

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


[PATCH] D130337: [pseudo] Eliminate multiple-specified-types ambiguities using guards

2022-07-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Feel free to land it. We have some number now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130337

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


[PATCH] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-07-25 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2226
 
+  static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
+  static const char *const LoongArch64Triples[] = {

SixWeining wrote:
> xry111 wrote:
> > SixWeining wrote:
> > > MaskRay wrote:
> > > > I don't know which of /lib64, /lib has been used. For purity, I'd hope 
> > > > that we just have /lib, no multilib style /lib64
> > > I also don't know the actual usage of /lib64 but I just tried and it 
> > > works fine if I remove /lib64.
> > I don't like `lib64` too.  But for LoongArch LP64D, the path to ELF 
> > interpreter is hard coded `/lib64/ld-linux-loongarch-lp64d.so.1` and it 
> > seems too late to change it.  And LoongArch GCC installs libstdc++ etc. for 
> > LP64D into $PREFIX/lib64 by default (like x86_64).
> > 
> > As a distro (LFS) maintainer: we are already hacking GCC code to get rid of 
> > `/usr/lib64`.
> Thanks for the quick reply. So I should keep the /lib64 here?
I think you should keep it.  A multilib distro may have `/usr/lib64`, 
`/usr/lib32`, and `/usr/lib32sf` (`sf` for soft float or whatever) and make 
`/usr/lib` a symlink.  A "mostly 32-bit distro" may have symlink `/usr/lib` -> 
`/usr/lib32`, but still capable to build & run LA64 programs with libraries in 
`/usr/lib64`.  Removing `lib64` will break clang on such distros with 
`-mabi=64`.

Personally, I don't like `lib64`.  But we can't really predict what the distro 
maintainers will do (unless you say something explicitly like "a LP64D capable 
distro SHALL have LP64D libraries in `/usr/lib`" in a spec).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130255

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


[PATCH] D130470: [clang][analyzer] Add more wide-character functions to CStringChecker

2022-07-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, gamesh411, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a reviewer: NoQ.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Support for functions wmempcpy, wmemmove, wmemcmp is added to the checker.
The same tests are copied that exist for the non-wide versions, with
non-wide functions and character types changed to the wide version.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130470

Files:
  clang/docs/analyzer/checkers.rst
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/wstring.c

Index: clang/test/Analysis/wstring.c
===
--- clang/test/Analysis/wstring.c
+++ clang/test/Analysis/wstring.c
@@ -33,7 +33,7 @@
 void clang_analyzer_eval(int);
 
 //===--===
-// wwmemcpy()
+// wmemcpy()
 //===--===
 
 #define wmemcpy BUILTIN(wmemcpy)
@@ -139,6 +139,255 @@
   clang_analyzer_eval(result == a); // no-warning (above is fatal)
 }
 
+//===--===
+// wmempcpy()
+//===--===
+
+wchar_t *wmempcpy(wchar_t *restrict s1, const wchar_t *restrict s2, size_t n);
+
+void wmempcpy0 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[5] = {0};
+
+  wmempcpy(dst, src, 4); // no-warning
+
+  clang_analyzer_eval(wmempcpy(dst, src, 4) == &dst[4]); // expected-warning{{TRUE}}
+
+  // If we actually model the copy, we can make this known.
+  // The important thing for now is that the old value has been invalidated.
+  clang_analyzer_eval(dst[0] != 0); // expected-warning{{UNKNOWN}}
+}
+
+void wmempcpy1 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[10];
+
+  wmempcpy(dst, src, 5); // expected-warning{{Memory copy function accesses out-of-bound array element}}
+}
+
+void wmempcpy2 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[1];
+
+  wmempcpy(dst, src, 4); // expected-warning{{Memory copy function overflows the destination buffer}}
+}
+
+void wmempcpy3 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[3];
+
+  wmempcpy(dst+1, src+2, 2); // no-warning
+}
+
+void wmempcpy4 (void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[10];
+
+  wmempcpy(dst+2, src+2, 3); // expected-warning{{Memory copy function accesses out-of-bound array element}}
+}
+
+void wmempcpy5(void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[3];
+
+  wmempcpy(dst + 2, src + 2, 2); // expected-warning{{Memory copy function overflows the destination buffer}}
+}
+
+void wmempcpy6(void) {
+  wchar_t a[4] = {0};
+  wmempcpy(a, a, 2); // expected-warning{{overlapping}}
+}
+
+void wmempcpy7(void) {
+  wchar_t a[4] = {0};
+  wmempcpy(a+2, a+1, 2); // expected-warning{{overlapping}}
+}
+
+void wmempcpy8(void) {
+  wchar_t a[4] = {0};
+  wmempcpy(a+1, a+2, 2); // expected-warning{{overlapping}}
+}
+
+void wmempcpy9(void) {
+  wchar_t a[4] = {0};
+  wmempcpy(a+2, a+1, 1); // no-warning
+  wmempcpy(a+1, a+2, 1); // no-warning
+}
+
+void wmempcpy10(void) {
+  wchar_t a[4] = {0};
+  wmempcpy(0, a, 1); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
+}
+
+void wmempcpy11(void) {
+  wchar_t a[4] = {0};
+  wmempcpy(a, 0, 1); // expected-warning{{Null pointer passed as 2nd argument to memory copy function}}
+}
+
+void wmempcpy12(void) {
+  wchar_t a[4] = {0};
+  wmempcpy(0, a, 0); // no-warning
+}
+
+void wmempcpy13(void) {
+  wchar_t a[4] = {0};
+  wmempcpy(a, 0, 0); // no-warning
+}
+
+void wmempcpy14(void) {
+  wchar_t src[] = {1, 2, 3, 4};
+  wchar_t dst[5] = {0};
+  wchar_t *p;
+
+  p = wmempcpy(dst, src, 4);
+
+  clang_analyzer_eval(p == &dst[4]); // expected-warning{{TRUE}}
+}
+
+struct st {
+  wchar_t i;
+  wchar_t j;
+};
+
+void wmempcpy15(void) {
+  struct st s1 = {0};
+  struct st s2;
+  struct st *p1;
+  struct st *p2;
+
+  p1 = (&s2) + 1;
+  p2 = (struct st *)wmempcpy((wchar_t *)&s2, (wchar_t *)&s1, 2);
+
+  clang_analyzer_eval(p1 == p2); // expected-warning{{TRUE}}
+}
+
+void wmempcpy16(void) {
+  struct st s1[10] = {{0}};
+  struct st s2[10];
+  struct st *p1;
+  struct st *p2;
+
+  p1 = (&s2[0]) + 5;
+  p2 = (struct st *)wmempcpy((wchar_t *)&s2[0], (wchar_t *)&s1[0], 5 * 2);
+
+  clang_analyzer_eval(p1 == p2); // expected-warning{{TRUE}}
+}
+
+void wmempcpy_unknown_size_warn (size_t n) {
+  wchar_t a[4];
+  void *result = wmempcpy(a, 0, n); // expected-warning{{Null pointer passed as 2nd argument to memory copy function}}
+  clang_analyzer_eval(result == a); // no-warning (above is fatal)
+}
+
+void wmempcpy_unknownable_size

[clang] d351344 - [C++20] [Modules] Make the linkage consistent for class template and its

2022-07-25 Thread Chuanqi Xu via cfe-commits

Author: Chuanqi Xu
Date: 2022-07-25T17:57:02+08:00
New Revision: d35134485a6cd1b0e25b5dccd330678b9e57919d

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

LOG: [C++20] [Modules] Make the linkage consistent for class template and its
specialization

Previously in D120397, we've handled the linkage for function template
and its specialization. But we forgot to handle it for class templates
and their specialization. So we make it in the patch with the similar
approach.

Added: 


Modified: 
clang/lib/AST/Decl.cpp
clang/unittests/AST/DeclTest.cpp

Removed: 




diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index f88a2e3fa2681..aaba4345587b2 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -394,7 +394,6 @@ void LinkageComputer::mergeTemplateLV(
 shouldConsiderTemplateVisibility(fn, specInfo);
 
   FunctionTemplateDecl *temp = specInfo->getTemplate();
-
   // Merge information from the template declaration.
   LinkageInfo tempLV = getLVForDecl(temp, computation);
   // The linkage of the specialization should be consistent with the
@@ -468,11 +467,16 @@ void LinkageComputer::mergeTemplateLV(
 
   // Merge information from the template parameters, but ignore
   // visibility if we're only considering template arguments.
-
   ClassTemplateDecl *temp = spec->getSpecializedTemplate();
-  LinkageInfo tempLV =
+  // Merge information from the template declaration.
+  LinkageInfo tempLV = getLVForDecl(temp, computation);
+  // The linkage of the specialization should be consistent with the
+  // template declaration.
+  LV.setLinkage(tempLV.getLinkage());
+
+  LinkageInfo paramsLV =
 getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
-  LV.mergeMaybeWithVisibility(tempLV,
+  LV.mergeMaybeWithVisibility(paramsLV,
considerVisibility && !hasExplicitVisibilityAlready(computation));
 
   // Merge information from the template arguments.  We ignore
@@ -520,7 +524,6 @@ void LinkageComputer::mergeTemplateLV(LinkageInfo &LV,
 
   // Merge information from the template parameters, but ignore
   // visibility if we're only considering template arguments.
-
   VarTemplateDecl *temp = spec->getSpecializedTemplate();
   LinkageInfo tempLV =
 getLVForTemplateParameterList(temp->getTemplateParameters(), computation);
@@ -1077,7 +1080,6 @@ LinkageComputer::getLVForClassMember(const NamedDecl *D,
 
   // Finally, merge in information from the class.
   LV.mergeMaybeWithVisibility(classLV, considerClassVisibility);
-
   return LV;
 }
 

diff  --git a/clang/unittests/AST/DeclTest.cpp 
b/clang/unittests/AST/DeclTest.cpp
index 560c6b3ddf434..71835a0508fda 100644
--- a/clang/unittests/AST/DeclTest.cpp
+++ b/clang/unittests/AST/DeclTest.cpp
@@ -179,7 +179,14 @@ TEST(Decl, InConsistLinkageForTemplates) {
 void f() {}
 
 template <>
-void f() {})");
+void f() {}
+
+export template 
+class C {};
+
+template<>
+class C {};
+)");
 
   auto AST =
   tooling::buildASTFromCodeWithArgs(Code.code(), /*Args=*/{"-std=c++20"});
@@ -193,6 +200,18 @@ TEST(Decl, InConsistLinkageForTemplates) {
   const FunctionDecl *SpecializedF = Funcs[1].getNodeAs("f");
   EXPECT_EQ(TemplateF->getLinkageInternal(),
 SpecializedF->getLinkageInternal());
+
+  llvm::SmallVector ClassTemplates =
+  match(classTemplateDecl().bind("C"), Ctx);
+  llvm::SmallVector ClassSpecializations =
+  match(classTemplateSpecializationDecl().bind("C"), Ctx);
+
+  EXPECT_EQ(ClassTemplates.size(), 1U);
+  EXPECT_EQ(ClassSpecializations.size(), 1U);
+  const NamedDecl *TemplatedC = ClassTemplates[0].getNodeAs("C");
+  const NamedDecl *SpecializedC = 
ClassSpecializations[0].getNodeAs("C");
+  EXPECT_EQ(TemplatedC->getLinkageInternal(),
+SpecializedC->getLinkageInternal());
 }
 
 TEST(Decl, ModuleAndInternalLinkage) {



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


[clang-tools-extra] b2b993a - [pseudo] Eliminate multiple-specified-types ambiguities using guards

2022-07-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-07-25T12:57:07+02:00
New Revision: b2b993a6ae675955b1112473c035ae6b4e3932a0

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

LOG: [pseudo] Eliminate multiple-specified-types ambiguities using guards

Motivating case: `foo bar;` is not a declaration of nothing with `foo` and `bar`
both types.

This is a common and critical ambiguity, clangd/AST.cpp has 20% fewer
ambiguous nodes (1674->1332) after this change.

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

Added: 
clang-tools-extra/pseudo/test/cxx/decl-specfier-seq.cpp

Modified: 
clang-tools-extra/pseudo/lib/cxx/CXX.cpp
clang-tools-extra/pseudo/lib/cxx/cxx.bnf
clang-tools-extra/pseudo/test/fuzzer.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/cxx/CXX.cpp 
b/clang-tools-extra/pseudo/lib/cxx/CXX.cpp
index 7fc3a48d63189..73af0a7a2d52a 100644
--- a/clang-tools-extra/pseudo/lib/cxx/CXX.cpp
+++ b/clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -14,7 +14,9 @@
 #include "clang/Basic/CharInfo.h"
 #include "clang/Basic/TokenKinds.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Debug.h"
 #include 
+#define DEBUG_TYPE "CXX.cpp"
 
 namespace clang {
 namespace pseudo {
@@ -160,7 +162,106 @@ bool guardNextTokenNotElse(const GuardParams &P) {
   return symbolToToken(P.Lookahead) != tok::kw_else;
 }
 
+// Whether this e.g. decl-specifier contains an "exclusive" type such as a 
class
+// name, and thus can't combine with a second exclusive type.
+//
+// Returns false for
+//  - non-types
+//  - "unsigned" etc that may suffice as types but may modify others
+//  - cases of uncertainty (e.g. due to ambiguity)
+bool hasExclusiveType(const ForestNode *N) {
+  // FIXME: every time we apply this check, we walk the whole subtree.
+  // Add per-node caching instead.
+  while (true) {
+assert(N->symbol() == (SymbolID)Symbol::decl_specifier_seq ||
+   N->symbol() == (SymbolID)Symbol::type_specifier_seq ||
+   N->symbol() == (SymbolID)Symbol::defining_type_specifier_seq ||
+   N->symbol() == (SymbolID)Symbol::decl_specifier ||
+   N->symbol() == (SymbolID)Symbol::type_specifier ||
+   N->symbol() == (SymbolID)Symbol::defining_type_specifier ||
+   N->symbol() == (SymbolID)Symbol::simple_type_specifier);
+if (N->kind() == ForestNode::Opaque)
+  return false; // conservative
+if (N->kind() == ForestNode::Ambiguous)
+  return llvm::all_of(N->alternatives(), hasExclusiveType); // conservative
+// All supported symbols are nonterminals.
+assert(N->kind() == ForestNode::Sequence);
+switch (N->rule()) {
+  // seq := element seq: check element then continue into seq
+  case 
(RuleID)Rule::decl_specifier_seq_0decl_specifier_1decl_specifier_seq:
+  case 
(RuleID)Rule::defining_type_specifier_seq_0defining_type_specifier_1defining_type_specifier_seq:
+  case 
(RuleID)Rule::type_specifier_seq_0type_specifier_1type_specifier_seq:
+if (hasExclusiveType(N->children()[0]))
+  return true;
+N = N->children()[1];
+continue;
+  // seq := element: continue into element
+  case (RuleID)Rule::decl_specifier_seq_0decl_specifier:
+  case (RuleID)Rule::type_specifier_seq_0type_specifier:
+  case (RuleID)Rule::defining_type_specifier_seq_0defining_type_specifier:
+N = N->children()[0];
+continue;
+
+  // defining-type-specifier
+  case (RuleID)Rule::defining_type_specifier_0type_specifier:
+N = N->children()[0];
+continue;
+  case (RuleID)Rule::defining_type_specifier_0class_specifier:
+  case (RuleID)Rule::defining_type_specifier_0enum_specifier:
+return true;
+
+  // decl-specifier
+  case (RuleID)Rule::decl_specifier_0defining_type_specifier:
+N = N->children()[0];
+continue;
+  case (RuleID)Rule::decl_specifier_0consteval:
+  case (RuleID)Rule::decl_specifier_0constexpr:
+  case (RuleID)Rule::decl_specifier_0constinit:
+  case (RuleID)Rule::decl_specifier_0inline:
+  case (RuleID)Rule::decl_specifier_0friend:
+  case (RuleID)Rule::decl_specifier_0storage_class_specifier:
+  case (RuleID)Rule::decl_specifier_0typedef:
+  case (RuleID)Rule::decl_specifier_0function_specifier:
+return false;
+
+  // type-specifier
+  case (RuleID)Rule::type_specifier_0elaborated_type_specifier:
+  case (RuleID)Rule::type_specifier_0typename_specifier:
+return true;
+  case (RuleID)Rule::type_specifier_0simple_type_specifier:
+N = N->children()[0];
+continue;
+  case (RuleID)Rule::type_specifier_0cv_qualifier:
+return false;
+
+  // simple-type-specifier
+  case (RuleID)Rule::simple_type_specifier_0type_na

[PATCH] D130337: [pseudo] Eliminate multiple-specified-types ambiguities using guards

2022-07-25 Thread Sam McCall 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 rGb2b993a6ae67: [pseudo] Eliminate multiple-specified-types 
ambiguities using guards (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D130337?vs=446753&id=447270#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130337

Files:
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/cxx/cxx.bnf
  clang-tools-extra/pseudo/test/cxx/decl-specfier-seq.cpp
  clang-tools-extra/pseudo/test/fuzzer.cpp

Index: clang-tools-extra/pseudo/test/fuzzer.cpp
===
--- clang-tools-extra/pseudo/test/fuzzer.cpp
+++ clang-tools-extra/pseudo/test/fuzzer.cpp
@@ -1,4 +1,4 @@
 // RUN: clang-pseudo-fuzzer -grammar=%cxx-bnf-file -print %s | FileCheck %s
 int x;
 // CHECK: translation-unit := declaration-seq
-// CHECK: simple-type-specifier := INT
+// CHECK: builtin-type := INT
Index: clang-tools-extra/pseudo/test/cxx/decl-specfier-seq.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/decl-specfier-seq.cpp
@@ -0,0 +1,27 @@
+// RUN: clang-pseudo -grammar=cxx -source=%s --print-forest | FileCheck %s
+
+// not parsed as Type{foo} Type{bar}
+foo bar;
+// CHECK-NOT: simple-declaration := decl-specifier-seq ;
+// CHECK:simple-declaration := decl-specifier-seq init-declarator-list ;
+// CHECK:├─decl-specifier-seq~simple-type-specifier
+// CHECK:├─init-declarator-list~IDENTIFIER
+// CHECK:└─;
+// CHECK-NOT: simple-declaration := decl-specifier-seq ;
+
+// not parsed as Type{std} Type{::string} Declarator{s};
+std::string s;
+// CHECK-NOT: nested-name-specifier := ::
+// CHECK: simple-declaration := decl-specifier-seq init-declarator-list ;
+// CHECK: ├─decl-specifier-seq~simple-type-specifier := 
+// CHECK: │ ├─simple-type-specifier := nested-name-specifier type-name
+// CHECK: │ │ ├─nested-name-specifier :=  #1
+// CHECK: │ │ │ ├─nested-name-specifier := type-name ::
+// CHECK: │ │ │ └─nested-name-specifier := namespace-name ::
+// CHECK: │ │ └─type-name
+// CHECK: │ └─simple-type-specifier := nested-name-specifier template-name
+// CHECK: │   ├─nested-name-specifier =#1
+// CHECK: │   └─template-name~IDENTIFIER
+// CHECK: ├─init-declarator-list~IDENTIFIER
+// CHECK: └─;
+// CHECK-NOT: nested-name-specifier := ::
Index: clang-tools-extra/pseudo/lib/cxx/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx/cxx.bnf
@@ -350,7 +350,7 @@
 decl-specifier := CONSTINIT
 decl-specifier := INLINE
 decl-specifier-seq := decl-specifier
-decl-specifier-seq := decl-specifier decl-specifier-seq
+decl-specifier-seq := decl-specifier decl-specifier-seq [guard]
 storage-class-specifier := STATIC
 storage-class-specifier := THREAD_LOCAL
 storage-class-specifier := EXTERN
@@ -364,31 +364,32 @@
 type-specifier := typename-specifier
 type-specifier := cv-qualifier
 type-specifier-seq := type-specifier
-type-specifier-seq := type-specifier type-specifier-seq
+type-specifier-seq := type-specifier type-specifier-seq [guard]
 defining-type-specifier := type-specifier
 defining-type-specifier := class-specifier
 defining-type-specifier := enum-specifier
 defining-type-specifier-seq := defining-type-specifier
-defining-type-specifier-seq := defining-type-specifier defining-type-specifier-seq
+defining-type-specifier-seq := defining-type-specifier defining-type-specifier-seq [guard]
 simple-type-specifier := nested-name-specifier_opt type-name
 simple-type-specifier := nested-name-specifier TEMPLATE simple-template-id
 simple-type-specifier := decltype-specifier
 simple-type-specifier := placeholder-type-specifier
 simple-type-specifier := nested-name-specifier_opt template-name
-simple-type-specifier := CHAR
-simple-type-specifier := CHAR8_T
-simple-type-specifier := CHAR16_T
-simple-type-specifier := CHAR32_T
-simple-type-specifier := WCHAR_T
-simple-type-specifier := BOOL
+simple-type-specifier := builtin-type
+builtin-type := CHAR
+builtin-type := CHAR8_T
+builtin-type := CHAR16_T
+builtin-type := CHAR32_T
+builtin-type := WCHAR_T
+builtin-type := BOOL
 simple-type-specifier := SHORT
-simple-type-specifier := INT
+builtin-type := INT
 simple-type-specifier := LONG
 simple-type-specifier := SIGNED
 simple-type-specifier := UNSIGNED
-simple-type-specifier := FLOAT
-simple-type-specifier := DOUBLE
-simple-type-specifier := VOID
+builtin-type := FLOAT
+builtin-type := DOUBLE
+builtin-type := VOID
 type-name := class-name
 type-name := enum-name
 type-name := typedef-name
Index: clang-tools-extra/pseudo/lib/cxx/CX

[clang] b826567 - [C++20][Modules] Add a testcase for [basic.link] p10 [NFC].

2022-07-25 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-07-25T12:20:02+01:00
New Revision: b826567136e391095b7731d5121e2be2a8fdc9ee

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

LOG: [C++20][Modules] Add a testcase for [basic.link] p10 [NFC].

This adds a testcase based on example 2 from the basic.link section of the
standard.

Added: 
clang/test/CXX/basic/basic.link/p10-ex2.cpp

Modified: 


Removed: 




diff  --git a/clang/test/CXX/basic/basic.link/p10-ex2.cpp 
b/clang/test/CXX/basic/basic.link/p10-ex2.cpp
new file mode 100644
index 0..322785ecbbf12
--- /dev/null
+++ b/clang/test/CXX/basic/basic.link/p10-ex2.cpp
@@ -0,0 +1,35 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 M.cpp -fsyntax-only -DTEST_INTERFACE -verify
+// RUN: %clang_cc1 -std=c++20 M.cpp -emit-module-interface -o M.pcm
+// RUN: %clang_cc1 -std=c++20 useM.cpp -fsyntax-only -fmodule-file=M.pcm 
-verify
+
+//--- decls.h
+int f(); // #1, attached to the global module
+int g(); // #2, attached to the global module
+
+//--- M.cpp
+module;
+#include "decls.h"
+export module M;
+export using ::f; // OK, does not declare an entity, exports #1
+#if TEST_INTERFACE
+// error: matches #2, but attached to M
+int g(); // expected-error {{declaration of 'g' in module M follows 
declaration in the global module}}
+// expected-note@decls.h:2 {{previous declaration is here}}
+#endif
+export int h(); // #3
+export int k(); // #4
+
+//--- useM.cpp
+import M;
+// error: matches #3
+static int h(); // expected-error {{static declaration of 'h' follows 
non-static declaration}}
+// expected-n...@m.cpp:10 {{previous declaration is here}}
+
+// error: matches #4
+int k(); // expected-error {{declaration of 'k' in the global module follows 
declaration in module M}}
+// expected-n...@m.cpp:11 {{previous declaration is here}}



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


[clang] 214a760 - Switch from XFAIL to UNSUPPORTED; NFC

2022-07-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-07-25T07:21:19-04:00
New Revision: 214a760a211606d14b3b2b852bd9d9a21149317e

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

LOG: Switch from XFAIL to UNSUPPORTED; NFC

This test is currently marked as XFAIL for Windows, but running the
test with a debug build of clang-repl.exe crashes with a modal system
dialog. This switches the test to UNSUPPORTED instead. This makes the
test behavior less onerous for those of us doing Debug builds, at the
expense of a minor bit of coverage if the test were ever to start
passing unexpectedly on Windows (which seems like an unlikely event).

Added: 


Modified: 
clang/test/Interpreter/execute-weak.cpp

Removed: 




diff  --git a/clang/test/Interpreter/execute-weak.cpp 
b/clang/test/Interpreter/execute-weak.cpp
index e4577e3ced6e9..7d0b7061e5019 100644
--- a/clang/test/Interpreter/execute-weak.cpp
+++ b/clang/test/Interpreter/execute-weak.cpp
@@ -2,9 +2,8 @@
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // REQUIRES: host-supports-jit
-// UNSUPPORTED: system-aix
-// XFAIL: system-windows
 // CHECK-DRIVER: i = 10
+// UNSUPPORTED: system-aix, system-windows
 // RUN: cat %s | clang-repl | FileCheck %s
 extern "C" int printf(const char *, ...);
 int __attribute__((weak)) bar() { return 42; }



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


[PATCH] D129048: Rewording the "static_assert" to static assertion

2022-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D129048#3674585 , @Codesbyusman 
wrote:

> In D129048#3674582 , @Mordante 
> wrote:
>
>> In D129048#3674500 , @Codesbyusman 
>> wrote:
>>
>>> updated the libcxx all files
>>
>> FYI for libcxx you can ignore the red format CI step. So the libcxx build is 
>> green :-)
>>
>> I had a look at your libc++ changes and they look good, thanks.
>> So LGTM for the libc++ part.
>
> That's great :)

Thank you everyone for the great collaboration on this! I just landed the 
changes and will watch the build bots for any surprise fallout.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129048

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


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

2022-07-25 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

Are there any problems with this revision?  The ones that depend on it are 
approved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126845

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


[PATCH] D130414: [pseudo] Reorganize CXX.h enums

2022-07-25 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 added inline comments.



Comment at: clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h:54-62
+namespace dummy {
+enum Rule {
+//clang-format off
+#define NONTERMINAL(NAME, ID) };} namespace NAME { enum Rule : RuleID {
+#define RULE(LHS, RHS, ID) RHS = ID,
 #include "CXXSymbols.inc"
+  //clang-format on

sammccall wrote:
> hokein wrote:
> > why there is a dummy namespace here?
> for each NT, we close the previous ns+enum and open new ones.
> For this to work for the first NT, we have to open an ns+enum.
> 
> I can add a comment, but would prefer to do this some other way?
I would include this block in the clang-format off block to show these are for 
the generated code.
```
//clang-format off
namespace dummy { enum Rule {
...
};}
//clang-format on
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130414

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


[PATCH] D130476: [NFC] Fix some C++20 warnings

2022-07-25 Thread Evgeny Mandrikov via Phabricator via cfe-commits
Godin created this revision.
Herald added a project: All.
Godin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Without this patch when using CMAKE_CXX_STANDARD=20 Microsoft compiler produces 
following warnings

clang\include\clang/Basic/DiagnosticIDs.h(48): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(49): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(50): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(51): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(52): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(53): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(54): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(55): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(56): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(57): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(58): warning C5054: operator '+': 
deprecated between enumerations of different types
clang\include\clang/Basic/DiagnosticIDs.h(59): warning C5054: operator '+': 
deprecated between enumerations of different types


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130476

Files:
  clang/include/clang/Basic/DiagnosticIDs.h


Index: clang/include/clang/Basic/DiagnosticIDs.h
===
--- clang/include/clang/Basic/DiagnosticIDs.h
+++ clang/include/clang/Basic/DiagnosticIDs.h
@@ -45,18 +45,18 @@
 // Start position for diagnostics.
 enum {
   DIAG_START_COMMON=  0,
-  DIAG_START_DRIVER= DIAG_START_COMMON+ DIAG_SIZE_COMMON,
-  DIAG_START_FRONTEND  = DIAG_START_DRIVER+ DIAG_SIZE_DRIVER,
-  DIAG_START_SERIALIZATION = DIAG_START_FRONTEND  + DIAG_SIZE_FRONTEND,
-  DIAG_START_LEX   = DIAG_START_SERIALIZATION + 
DIAG_SIZE_SERIALIZATION,
-  DIAG_START_PARSE = DIAG_START_LEX   + DIAG_SIZE_LEX,
-  DIAG_START_AST   = DIAG_START_PARSE + DIAG_SIZE_PARSE,
-  DIAG_START_COMMENT   = DIAG_START_AST   + DIAG_SIZE_AST,
-  DIAG_START_CROSSTU   = DIAG_START_COMMENT   + DIAG_SIZE_COMMENT,
-  DIAG_START_SEMA  = DIAG_START_CROSSTU   + DIAG_SIZE_CROSSTU,
-  DIAG_START_ANALYSIS  = DIAG_START_SEMA  + DIAG_SIZE_SEMA,
-  DIAG_START_REFACTORING   = DIAG_START_ANALYSIS  + DIAG_SIZE_ANALYSIS,
-  DIAG_UPPER_LIMIT = DIAG_START_REFACTORING   + 
DIAG_SIZE_REFACTORING
+  DIAG_START_DRIVER= DIAG_START_COMMON+ 
static_cast(DIAG_SIZE_COMMON),
+  DIAG_START_FRONTEND  = DIAG_START_DRIVER+ 
static_cast(DIAG_SIZE_DRIVER),
+  DIAG_START_SERIALIZATION = DIAG_START_FRONTEND  + 
static_cast(DIAG_SIZE_FRONTEND),
+  DIAG_START_LEX   = DIAG_START_SERIALIZATION + 
static_cast(DIAG_SIZE_SERIALIZATION),
+  DIAG_START_PARSE = DIAG_START_LEX   + 
static_cast(DIAG_SIZE_LEX),
+  DIAG_START_AST   = DIAG_START_PARSE + 
static_cast(DIAG_SIZE_PARSE),
+  DIAG_START_COMMENT   = DIAG_START_AST   + 
static_cast(DIAG_SIZE_AST),
+  DIAG_START_CROSSTU   = DIAG_START_COMMENT   + 
static_cast(DIAG_SIZE_COMMENT),
+  DIAG_START_SEMA  = DIAG_START_CROSSTU   + 
static_cast(DIAG_SIZE_CROSSTU),
+  DIAG_START_ANALYSIS  = DIAG_START_SEMA  + 
static_cast(DIAG_SIZE_SEMA),
+  DIAG_START_REFACTORING   = DIAG_START_ANALYSIS  + 
static_cast(DIAG_SIZE_ANALYSIS),
+  DIAG_UPPER_LIMIT = DIAG_START_REFACTORING   + 
static_cast(DIAG_SIZE_REFACTORING)
 };
 
 class CustomDiagInfo;


Index: clang/include/clang/Basic/DiagnosticIDs.h
===
--- clang/include/clang/Basic/DiagnosticIDs.h
+++ clang/include/clang/Basic/DiagnosticIDs.h
@@ -45,18 +45,18 @@
 // Start position for diagnostics.
 enum {
   DIAG_START_COMMON=  0,
-  DIAG_START_DRIVER= DIAG_START_COMMON+ DIAG_SIZE_COMMON,
-  DIAG_START_FRONTEND  = DIAG_START_DRIVER+ DIAG_SIZE_DRIVER,
-  DIAG_START_SERIALIZATION = DIAG_START_FRONTEND  + DIAG_SIZE_FRONTEND,
-  DIAG_START

[PATCH] D130414: [pseudo] Reorganize CXX.h enums

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 447286.
sammccall added a comment.

tweak formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130414

Files:
  clang-tools-extra/pseudo/gen/Main.cpp
  clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
  clang-tools-extra/pseudo/unittests/GrammarTest.cpp

Index: clang-tools-extra/pseudo/unittests/GrammarTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GrammarTest.cpp
+++ clang-tools-extra/pseudo/unittests/GrammarTest.cpp
@@ -113,15 +113,16 @@
   build(R"bnf(
 _ := declaration
 
-declaration := ptr-declarator ;
+declaration := cv-qualifier ptr-declarator ;
 ptr-declarator := * IDENTIFIER
+cv-qualifier := CONST
 
   )bnf");
   ASSERT_TRUE(Diags.empty());
   EXPECT_EQ(G.mangleRule(ruleFor("declaration")),
-"declaration_0ptr_declarator_1semi");
-  EXPECT_EQ(G.mangleRule(ruleFor("ptr-declarator")),
-"ptr_declarator_0star_1identifier");
+"cv_qualifier__ptr_declarator__semi");
+  EXPECT_EQ(G.mangleRule(ruleFor("ptr-declarator")), "star__identifier");
+  EXPECT_EQ(G.mangleRule(ruleFor("cv-qualifier")), "CONST");
 }
 
 TEST_F(GrammarTest, Diagnostics) {
Index: clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
+++ clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
@@ -46,11 +46,11 @@
 }
 
 std::string Grammar::mangleSymbol(SymbolID SID) const {
-  static const char *const TokNames[] = {
+  static std::string *TokNames = new std::string[]{
 #define TOK(X) #X,
-#define KEYWORD(X, Y) #X,
+#define KEYWORD(Keyword, Condition) llvm::StringRef(#Keyword).upper(),
 #include "clang/Basic/TokenKinds.def"
-  nullptr};
+  };
   if (clang::pseudo::isToken(SID))
 return TokNames[clang::pseudo::symbolToToken(SID)];
   std::string Name = symbolName(SID).str();
@@ -61,9 +61,13 @@
 
 std::string Grammar::mangleRule(RuleID RID) const {
   const auto &R = lookupRule(RID);
-  std::string MangleName = mangleSymbol(R.Target);
-  for (size_t I = 0; I < R.seq().size(); ++I)
-MangleName += llvm::formatv("_{0}{1}", I, mangleSymbol(R.seq()[I]));
+  std::string MangleName;
+  for (size_t I = 0; I < R.seq().size(); ++I) {
+MangleName += mangleSymbol(R.seq()[I]);
+MangleName.append("__");
+  }
+  MangleName.pop_back();
+  MangleName.pop_back();
   return MangleName;
 }
 
Index: clang-tools-extra/pseudo/lib/cxx/CXX.cpp
===
--- clang-tools-extra/pseudo/lib/cxx/CXX.cpp
+++ clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -111,40 +111,39 @@
 bool isFunctionDeclarator(const ForestNode *Declarator) {
   assert(Declarator->symbol() == (SymbolID)(cxx::Symbol::declarator));
   bool IsFunction = false;
-  using cxx::Rule;
   while (true) {
 // not well-formed code, return the best guess.
 if (Declarator->kind() != ForestNode::Sequence)
   return IsFunction;
 
-switch ((cxx::Rule)Declarator->rule()) {
-case Rule::noptr_declarator_0declarator_id: // reached the bottom
+switch (Declarator->rule()) {
+case rule::noptr_declarator::declarator_id: // reached the bottom
   return IsFunction;
 // *X is a nonfunction (unless X is a function).
-case Rule::ptr_declarator_0ptr_operator_1ptr_declarator:
+case rule::ptr_declarator::ptr_operator__ptr_declarator:
   Declarator = Declarator->elements()[1];
   IsFunction = false;
   continue;
 // X() is a function (unless X is a pointer or similar).
-case Rule::
-declarator_0noptr_declarator_1parameters_and_qualifiers_2trailing_return_type:
-case Rule::noptr_declarator_0noptr_declarator_1parameters_and_qualifiers:
+case rule::declarator::
+noptr_declarator__parameters_and_qualifiers__trailing_return_type:
+case rule::noptr_declarator::noptr_declarator__parameters_and_qualifiers:
   Declarator = Declarator->elements()[0];
   IsFunction = true;
   continue;
 // X[] is an array (unless X is a pointer or function).
-case Rule::
-noptr_declarator_0noptr_declarator_1l_square_2constant_expression_3r_square:
-case Rule::noptr_declarator_0noptr_declarator_1l_square_2r_square:
+case rule::noptr_declarator::
+noptr_declarator__l_square__constant_expression__r_square:
+case rule::noptr_declarator::noptr_declarator__l_square__r_square:
   Declarator = Declarator->elements()[0];
   IsFunction = false;
   continue;
 // (X) is whatever X is.
-case Rule::noptr_declarator_0l_paren_1ptr_declarator_2r_paren:
+case rule::noptr_declarator::l_paren__ptr_declarator__r_paren:
   Declarator = Declarator->elements()[1];
   continue;
-

[clang] 59179d7 - [Sema] Merge C++20 concept definitions from different modules in same TU

2022-07-25 Thread Ilya Biryukov via cfe-commits

Author: Ilya Biryukov
Date: 2022-07-25T14:43:38+02:00
New Revision: 59179d72b2e3d3b99ebc342374c9c797d526ac5d

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

LOG: [Sema] Merge C++20 concept definitions from different modules in same TU

Currently the C++20 concepts are only merged in `ASTReader`, i.e. when
coming from different TU. This can causes ambiguious reference errors when
trying to access the same concept that should otherwise be merged.

Please see the added test for an example.

Note that we currently use `ASTContext::isSameEntity` to check for ODR
violations. However, it will not check that concept requirements match.
The same issue holds for mering concepts from different TUs, I added a
FIXME and filed a GH issue to track this:
https://github.com/llvm/llvm-project/issues/56310

Reviewed By: ChuanqiXu

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

Added: 
clang/test/Modules/merge-concepts-cxx-modules.cpp
clang/test/Modules/merge-concepts-redefinition-error.cpp
clang/test/Modules/merge-concepts.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c2cabcb04f2f7..6ff5b8de57fd0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5774,6 +5774,8 @@ def warn_forward_class_redefinition : Warning<
 def err_redefinition_
diff erent_typedef : Error<
   "%select{typedef|type alias|type alias template}0 "
   "redefinition with 
diff erent types%
diff { ($ vs $)|}1,2">;
+def err_redefinition_
diff erent_concept : Error<
+  "redefinition of concept %0 with 
diff erent template parameters or requirements">;
 def err_tag_reference_non_tag : Error<
   "%select{non-struct type|non-class type|non-union type|non-enum "
   "type|typedef|type alias|template|type alias template|template "

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index de9bde6841f7d..b149c24dea7dc 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8260,6 +8260,9 @@ class Sema final {
   Scope *S, MultiTemplateParamsArg TemplateParameterLists,
   IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr);
 
+  void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous,
+bool &AddToScope);
+
   RequiresExprBodyDecl *
   ActOnStartRequiresExpr(SourceLocation RequiresKWLoc,
  ArrayRef LocalParameters,

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 95c83ebfaeab5..1542a07713fb7 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -20,6 +20,7 @@
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/TypeVisitor.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/DiagnosticSema.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/Stack.h"
@@ -8707,23 +8708,59 @@ Decl *Sema::ActOnConceptDefinition(Scope *S,
   // Check for conflicting previous declaration.
   DeclarationNameInfo NameInfo(NewDecl->getDeclName(), NameLoc);
   LookupResult Previous(*this, NameInfo, LookupOrdinaryName,
-ForVisibleRedeclaration);
+forRedeclarationInCurContext());
   LookupName(Previous, S);
-
   FilterLookupForScope(Previous, DC, S, /*ConsiderLinkage=*/false,
/*AllowInlineNamespace*/false);
-  if (!Previous.empty()) {
-auto *Old = Previous.getRepresentativeDecl();
-Diag(NameLoc, isa(Old) ? diag::err_redefinition :
- diag::err_redefinition_
diff erent_kind) << NewDecl->getDeclName();
-Diag(Old->getLocation(), diag::note_previous_definition);
-  }
+  bool AddToScope = true;
+  CheckConceptRedefinition(NewDecl, Previous, AddToScope);
 
   ActOnDocumentableDecl(NewDecl);
-  PushOnScopeChains(NewDecl, S);
+  if (AddToScope)
+PushOnScopeChains(NewDecl, S);
   return NewDecl;
 }
 
+void Sema::CheckConceptRedefinition(ConceptDecl *NewDecl,
+LookupResult &Previous, bool &AddToScope) {
+  AddToScope = true;
+
+  if (Previous.empty())
+return;
+
+  auto *OldConcept = dyn_cast(Previous.getRepresentativeDecl());
+  if (!OldConcept) {
+auto *Old = Previous.getRepresentativeDecl();
+Diag(NewDecl->getLocation(), diag::err_redefinition_
diff erent_kind)
+<< NewDecl->getDeclName();
+notePreviousDefinition(Old, NewDecl->getLocation());
+AddToScope = false;
+return;
+  }
+  // Check if we can merge with a concep

[PATCH] D128921: [Sema] Merge C++20 concept definitions from different modules in same TU

2022-07-25 Thread Ilya Biryukov 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 rG59179d72b2e3: [Sema] Merge C++20 concept definitions from 
different modules in same TU (authored by ilya-biryukov).

Changed prior to commit:
  https://reviews.llvm.org/D128921?vs=446883&id=447292#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128921

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/Modules/merge-concepts-cxx-modules.cpp
  clang/test/Modules/merge-concepts-redefinition-error.cpp
  clang/test/Modules/merge-concepts.cpp

Index: clang/test/Modules/merge-concepts.cpp
===
--- /dev/null
+++ clang/test/Modules/merge-concepts.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -xc++ -std=c++20 -fmodules -fmodule-name=library \
+// RUN: -emit-module %t/modules.map \
+// RUN: -o %t/module.pcm
+//
+//
+// RUN: %clang_cc1 -xc++ -std=c++20 -fmodules -fmodule-file=%t/module.pcm  \
+// RUN: -fmodule-map-file=%t/modules.map \
+// RUN: -fsyntax-only -verify %t/use.cpp
+//
+//--- use.cpp
+// expected-no-diagnostics
+
+#include "concepts.h"
+#include "format.h"
+
+template  void foo()
+  requires same_as
+{}
+
+//--- modules.map
+module "library" {
+	export *
+	module "concepts" {
+		export *
+		header "concepts.h"
+	}
+	module "format" {
+		export *
+		header "format.h"
+	}
+}
+
+//--- concepts.h
+#ifndef SAMEAS_CONCEPTS_H_
+#define SAMEAS_CONCEPTS_H_
+
+#include "same_as.h"
+
+#endif // SAMEAS_CONCEPTS_H
+
+//--- same_as.h
+#ifndef SAME_AS_H
+#define SAME_AS_H
+
+template 
+concept same_as = __is_same(T, U);
+
+#endif // SAME_AS_H
+
+//--- format.h
+#ifndef FORMAT_H
+#define FORMAT_H
+
+#include "concepts.h"
+#include "same_as.h"
+
+template  void foo()
+  requires same_as
+{}
+
+#endif // FORMAT_H
\ No newline at end of file
Index: clang/test/Modules/merge-concepts-redefinition-error.cpp
===
--- /dev/null
+++ clang/test/Modules/merge-concepts-redefinition-error.cpp
@@ -0,0 +1,57 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -xc++ -std=c++20 -fmodules -fmodule-name=library \
+// RUN: -emit-module %t/modules.map \
+// RUN: -o %t/module.pcm \
+// RUN: -verify
+//
+//--- modules.map
+module "library" {
+	export *
+	module "concepts" {
+		export *
+		header "concepts.h"
+	}
+	module "conflicting" {
+		export *
+		header "conflicting.h"
+	}
+}
+
+//--- concepts.h
+#ifndef CONCEPTS_H_
+#define CONCEPTS_H_
+
+template 
+concept ConflictingConcept = true;
+
+template 
+concept same_as = __is_same(T, U);
+
+template concept truec = true;
+
+int var;
+
+#endif // SAMEAS_CONCEPTS_H
+
+//--- conflicting.h
+#ifndef CONFLICTING_H
+#define CONFLICTING_H
+
+#include "concepts.h"
+
+template 
+concept ConflictingConcept = true; // expected-error {{redefinition of concept 'ConflictingConcept' with different template}}
+   // expected-note@* {{previous definition}}
+
+int same_as; // expected-error {{redefinition of 'same_as' as different kind of symbol}}
+ // expected-note@* {{previous definition}}
+
+template concept var = false; // expected-error {{redefinition of 'var' as different kind of symbol}}
+   // expected-note@* {{previous definition}}
+
+template concept truec = true; // expected-error {{redefinition of 'truec'}}
+// expected-note@* {{previous definition}}
+#endif // CONFLICTING_H
Index: clang/test/Modules/merge-concepts-cxx-modules.cpp
===
--- /dev/null
+++ clang/test/Modules/merge-concepts-cxx-modules.cpp
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/same_as.cppm -o %t/same_as.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -fprebuilt-module-path=%t %t/concepts.cppm -o %t/concepts.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface -fprebuilt-module-path=%t %t/format.cppm -o %t/format.pcm
+// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/conflicting.cppm -o %t/conflicting.pcm
+// RUN: %clang_cc1 -std=c++20 -fprebuilt-module-path=%t %t/Use.cppm -fsyntax-only -verify
+
+//--- same_as.cppm
+export module same_as;
+export template 
+concept same_as = __is_same(T, U);
+
+//--- concepts.cppm
+export module concepts;
+export import same_as;
+
+export template 
+concept ConflictingConcept = true;
+
+//--- format.cppm
+
+export module format;
+export import concepts;
+export import same_as;
+
+export template  void foo()
+  requires same_as
+{}
+

[PATCH] D117973: [cmake] Support custom package install paths

2022-07-25 Thread Sebastian Neubauer via Phabricator via cfe-commits
sebastian-ne added a comment.

Two comments inline, apart from that it looks good to me.




Comment at: cmake/Modules/FindPrefixFromConfig.cmake:30
+  if(IS_ABSOLUTE "${path_to_leave}")
+set(prefix_var
+  "# Installation prefix is fixed absolute path"

Shouldn’t this set `config_code` instead of `prefix_var`, which is the output 
variable in the generated code?



Comment at: cmake/Modules/FindPrefixFromConfig.cmake:32
+  "# Installation prefix is fixed absolute path"
+  "set(${prefix_var} \"${CMAKE_INSTALL_PREFIX}\"")
+  else()

This could use a comment to why it ignores `path_to_leave` and why 
`CMAKE_INSTALL_PREFIX` is the correct choice.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117973

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


[PATCH] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-07-25 Thread Lu Weining via Phabricator via cfe-commits
SixWeining updated this revision to Diff 447304.
SixWeining added a comment.

keep /lib64


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130255

Files:
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/LoongArch.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/Arch/LoongArch.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Clang.h
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/bin/.keep
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/include/.keep
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/base/lp64d/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/base/lp64f/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/base/lp64s/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/lib/gcc/loongarch64-unknown-linux-gnu/12.1.0/crtbegin.o
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/loongarch64-unknown-linux-gnu/bin/ld
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/loongarch64-unknown-linux-gnu/lib/.keep
  
clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/loongarch64-unknown-linux-gnu/lib64/.keep
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/sysroot/usr/lib/.keep
  clang/test/Driver/Inputs/multilib_loongarch_linux_sdk/sysroot/usr/lib64/.keep
  clang/test/Driver/frame-pointer.c
  clang/test/Driver/loongarch-abi-error.c
  clang/test/Driver/loongarch-abi.c
  clang/test/Driver/loongarch-toolchain.c
  clang/test/Preprocessor/init-loongarch.c

Index: clang/test/Preprocessor/init-loongarch.c
===
--- /dev/null
+++ clang/test/Preprocessor/init-loongarch.c
@@ -0,0 +1,641 @@
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch32 /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefix=LA32 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch32-unknown-linux /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefixes=LA32,LA32-LINUX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch32 \
+// RUN: -fforce-enable-int128 /dev/null | FileCheck --match-full-lines \
+// RUN: --check-prefixes=LA32,LA32-INT128 %s
+
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch64 /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefix=LA64 %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch64-unknown-linux /dev/null \
+// RUN:   | FileCheck --match-full-lines --check-prefixes=LA64,LA64-LINUX %s
+// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=loongarch64 \
+// RUN: -fforce-enable-int128 /dev/null | FileCheck --match-full-lines \
+// RUN: --check-prefixes=LA64,LA64-INT128 %s
+
+ Note that common macros are tested in init.c, such as __VERSION__. So they're not listed here.
+
+// LA32: #define _ILP32 1
+// LA32: #define __ATOMIC_ACQUIRE 2
+// LA32-NEXT: #define __ATOMIC_ACQ_REL 4
+// LA32-NEXT: #define __ATOMIC_CONSUME 1
+// LA32-NEXT: #define __ATOMIC_RELAXED 0
+// LA32-NEXT: #define __ATOMIC_RELEASE 3
+// LA32-NEXT: #define __ATOMIC_SEQ_CST 5
+// LA32: #define __BIGGEST_ALIGNMENT__ 16
+// LA32: #define __BITINT_MAXWIDTH__ 128
+// LA32: #define __BOOL_WIDTH__ 8
+// LA32: #define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+// LA32: #define __CHAR16_TYPE__ unsigned short
+// LA32: #define __CHAR32_TYPE__ unsigned int
+// LA32: #define __CHAR_BIT__ 8
+// LA32: #define __CLANG_ATOMIC_BOOL_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_CHAR16_T_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_CHAR32_T_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_CHAR_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_INT_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_LLONG_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_LONG_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_POINTER_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_SHORT_LOCK_FREE 1
+// LA32: #define __CLANG_ATOMIC_WCHAR_T_LOCK_FREE 1
+// LA32: #define __DBL_DECIMAL_DIG__ 17
+// LA32: #define __DBL_DENORM_MIN__ 4.9406564584124654e-324
+// LA32: #define __DBL_DIG__ 15
+// LA32: #define __DBL_EPSILON__ 2.2204460492503131e-16
+// LA32: #define __DBL_HAS_DENORM__ 1
+// LA32: #define __DBL_HAS_INFINITY__ 1
+// LA32: #define __DBL_HAS_QUIET_NAN__ 1
+// LA32: #define __DBL_MANT_DIG__ 53
+// LA32: #define __DBL_MAX_10_EXP__ 308
+// LA32: #define __DBL_MAX_EXP__ 1024
+// LA32: #define __DBL_MAX__ 1.7976931348623157e+308
+// LA32: #define __DBL_MIN_10_EXP__ (-307)
+// LA32: #define __DBL_MIN_EXP__ (

[PATCH] D101070: [llvm][cmake] Make `install_symlink` robust to absolute dirs.

2022-07-25 Thread Sebastian Neubauer via Phabricator via cfe-commits
sebastian-ne added a comment.

In D101070#3675462 , @sebastian-ne 
wrote:

> Hi, not sure if you saw D130256 , but I 
> needed to extend CMAKE_MODULE_PATH, otherwise the ExtendPath module was not 
> found when running LLVMInstallSymlink.cmake.

Just checked, if I run `ninja install` with this patch, it fails with

  CMake Error at /llvm-project/llvm/cmake/modules/LLVMInstallSymlink.cmake:5 
(include):
include could not find requested file:
  
  ExtendPath
  Call Stack (most recent call first):
tools/llvm-ar/cmake_install.cmake:56 (include)
tools/cmake_install.cmake:49 (include)
cmake_install.cmake:78 (include)
  
  
  FAILED: CMakeFiles/install.util


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

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


[PATCH] D49303: [CodeGen][ObjC] Treat non-escaping blocks as global blocks to make copy/dispose a no-op

2022-07-25 Thread Jake Li via Phabricator via cfe-commits
jajadude added a comment.
Herald added a project: All.

@ahatanak @rjmccall  What if a block is marked with `noescape` and captures 
some variables at the same time?  Wouldn't that cause problem If the compiler 
continues to optimize it to `NSConcreteGlobal` type anyway?


Repository:
  rL LLVM

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

https://reviews.llvm.org/D49303

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


[clang] 25558a1 - [C++20][Modules] Update ADL to handle basic.lookup.argdep p4 [P1815R2 part 1]

2022-07-25 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2022-07-25T14:28:59+01:00
New Revision: 25558a1bfd79e03bed74873ab83ccfc3650fb64f

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

LOG: [C++20][Modules] Update ADL to handle basic.lookup.argdep p4 [P1815R2 part 
1]

This includes the revised provisions of [basic.lookup.argdep] p4

1. ADL is amended to handle p 4.3 where functions in trasitively imported 
modules may
become visible when they are exported in the same namespace as a visible type.

2. If a function is in a different modular TU, and has internal-linkage, we 
invalidate
its entry in an overload set.

[basic.lookup.argdep] p5 ex 2 now passes.

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

Added: 
clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p5-ex2.cpp

Modified: 
clang/include/clang/Sema/Overload.h
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaOverload.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Overload.h 
b/clang/include/clang/Sema/Overload.h
index 48997e186ef69..fb4812675d9a3 100644
--- a/clang/include/clang/Sema/Overload.h
+++ b/clang/include/clang/Sema/Overload.h
@@ -795,6 +795,10 @@ class Sema;
 /// This candidate was not viable because its associated constraints were
 /// not satisfied.
 ovl_fail_constraints_not_satisfied,
+
+/// This candidate was not viable because it has internal linkage and is
+/// from a 
diff erent module unit than the use.
+ovl_fail_module_mismatched,
   };
 
   /// A list of implicit conversion sequences for the arguments of an

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 242e1f81d75c0..66e0efccb4b47 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -3838,6 +3838,12 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, 
SourceLocation Loc,
 //associated classes are visible within their respective
 //namespaces even if they are not visible during an ordinary
 //lookup (11.4).
+//
+// C++20 [basic.lookup.argdep] p4.3
+// -- are exported, are attached to a named module M, do not appear
+//in the translation unit containing the point of the lookup, and
+//have the same innermost enclosing non-inline namespace scope as
+//a declaration of an associated entity attached to M.
 DeclContext::lookup_result R = NS->lookup(Name);
 for (auto *D : R) {
   auto *Underlying = D;
@@ -3858,6 +3864,36 @@ void Sema::ArgumentDependentLookup(DeclarationName Name, 
SourceLocation Loc,
   if (isVisible(D)) {
 Visible = true;
 break;
+  } else if (getLangOpts().CPlusPlusModules &&
+ D->isInExportDeclContext()) {
+// C++20 [basic.lookup.argdep] p4.3 .. are exported ...
+Module *FM = D->getOwningModule();
+// exports are only valid in module purview and outside of any
+// PMF (although a PMF should not even be present in a module
+// with an import).
+assert(FM && FM->isModulePurview() && !FM->isPrivateModule() &&
+   "bad export context");
+// .. are attached to a named module M, do not appear in the
+// translation unit containing the point of the lookup..
+if (!isModuleUnitOfCurrentTU(FM) &&
+llvm::any_of(AssociatedClasses, [&](auto *E) {
+  // ... and have the same innermost enclosing non-inline
+  // namespace scope as a declaration of an associated entity
+  // attached to M
+  if (!E->hasOwningModule() ||
+  E->getOwningModule()->getTopLevelModuleName() !=
+  FM->getTopLevelModuleName())
+return false;
+  // TODO: maybe this could be cached when generating the
+  // associated namespaces / entities.
+  DeclContext *Ctx = E->getDeclContext();
+  while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
+Ctx = Ctx->getParent();
+  return Ctx == NS;
+})) {
+  Visible = true;
+  break;
+}
   }
 } else if (D->getFriendObjectKind()) {
   auto *RD = cast(D->getLexicalDeclContext());

diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index c226ed6254790..65dae00345f6d 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -6400,6 +6400,17 @@ void Sema::AddOverloadCandidate(
 return;
   }
 
+  // Functions with internal linkage are only viable in the same module unit.
+  if (auto *MF = Funct

[PATCH] D129174: [C++20][Modules] Update ADL to handle basic.lookup.argdep p4 [P1815R2 part 1]

2022-07-25 Thread Iain Sandoe 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 rG25558a1bfd79: [C++20][Modules] Update ADL to handle 
basic.lookup.argdep p4 [P1815R2 part 1] (authored by iains).

Changed prior to commit:
  https://reviews.llvm.org/D129174?vs=447046&id=447308#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129174

Files:
  clang/include/clang/Sema/Overload.h
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p5-ex2.cpp

Index: clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p5-ex2.cpp
===
--- /dev/null
+++ clang/test/CXX/basic/basic.lookup/basic.lookup.argdep/p5-ex2.cpp
@@ -0,0 +1,68 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 M.cpp -emit-module-interface -o M.pcm
+// RUN: %clang_cc1 -std=c++20 N.cpp -emit-module-interface -o N.pcm \
+// RUN:   -fmodule-file=M.pcm
+// RUN: %clang_cc1 -std=c++20 Q.cpp -emit-module-interface -o Q.pcm
+// RUN: %clang_cc1 -std=c++20 Q-impl.cpp -fsyntax-only -fmodule-file=Q.pcm \
+// RUN:   -fmodule-file=N.pcm -verify
+
+//--- M.cpp
+export module M;
+namespace R {
+export struct X {};
+export void f(X);
+} // namespace R
+namespace S {
+export void f(R::X, R::X);
+}
+
+//--- N.cpp
+export module N;
+import M;
+export R::X make();
+namespace R {
+static int g(X);
+}
+export template 
+void apply(T t, U u) {
+  f(t, u);
+  g(t);
+}
+
+//--- Q.cpp
+export module Q;
+
+//--- Q-impl.cpp
+module Q;
+import N;
+
+namespace S {
+struct Z {
+  template  operator T();
+};
+} // namespace S
+void test() {
+  // OK, decltype(x) is R::X in module M
+  auto x = make();
+
+  // error: R and R::f are not visible here
+  R::f(x); // expected-error {{declaration of 'R' must be imported from module 'N' before it is required}}
+  // expected-n...@n.cpp:4 {{declaration here is not visible}}
+  // expected-error@-2 {{no type named 'f' in namespace 'R'}}
+
+  f(x); // Found by [basic.lookup.argdep] / p4.3
+
+  // error: S::f in module M not considered even though S is an associated
+  // namespace, since the entity Z is in a different module from f.
+  f(x, S::Z()); // expected-error {{no matching function for call to 'f'}}
+  // expected-n...@m.cpp:4 {{candidate function not viable: requires 1 argument, but 2 were provided}}
+
+  // error: S::f is visible in instantiation context, but  R::g has internal
+  // linkage and cannot be used outside N.cpp
+  apply(x, S::Z()); // expected-er...@n.cpp:10 {{no matching function for call to 'g'}}
+// expected-note@-1 {{in instantiation of function template specialization 'apply' requested here}}
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -6400,6 +6400,17 @@
 return;
   }
 
+  // Functions with internal linkage are only viable in the same module unit.
+  if (auto *MF = Function->getOwningModule()) {
+if (getLangOpts().CPlusPlusModules && !MF->isModuleMapModule() &&
+Function->getFormalLinkage() <= Linkage::InternalLinkage &&
+!isModuleUnitOfCurrentTU(MF)) {
+  Candidate.Viable = false;
+  Candidate.FailureKind = ovl_fail_module_mismatched;
+  return;
+}
+  }
+
   if (Function->isMultiVersion() && Function->hasAttr() &&
   !Function->getAttr()->isDefaultVersion()) {
 Candidate.Viable = false;
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -3838,6 +3838,12 @@
 //associated classes are visible within their respective
 //namespaces even if they are not visible during an ordinary
 //lookup (11.4).
+//
+// C++20 [basic.lookup.argdep] p4.3
+// -- are exported, are attached to a named module M, do not appear
+//in the translation unit containing the point of the lookup, and
+//have the same innermost enclosing non-inline namespace scope as
+//a declaration of an associated entity attached to M.
 DeclContext::lookup_result R = NS->lookup(Name);
 for (auto *D : R) {
   auto *Underlying = D;
@@ -3858,6 +3864,36 @@
   if (isVisible(D)) {
 Visible = true;
 break;
+  } else if (getLangOpts().CPlusPlusModules &&
+ D->isInExportDeclContext()) {
+// C++20 [basic.lookup.argdep] p4.3 .. are exported ...
+Module *FM = D->getOwningModule();
+// exports are only valid in module purview and outside of any
+// PMF (although a PMF should not even be present in a mod

[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

1 more question, otherwise this looks right to me.




Comment at: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp:27
+  return ((int)e1 != -1) & ((int)e2 != -1) &
+ // CHECK: error: load of value , which is not a valid value 
for type 'enum EBool'
+ ((int)e3 != -1) & ((int)e4 == 1) &

What does THIS come from?  What value is unknown?  Shouldn't the -1 be fine?


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

https://reviews.llvm.org/D130301

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


[clang] 629903c - Reapply "[NFC] Add some additional features to MultiLevelTemplateArgumentList""

2022-07-25 Thread Erich Keane via cfe-commits

Author: Erich Keane
Date: 2022-07-25T06:57:23-07:00
New Revision: 629903c8a4440095ecb98c7095f029783255db11

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

LOG: Reapply "[NFC] Add some additional features to 
MultiLevelTemplateArgumentList""

This reverts commit 6a1ccf61cdf80c793f9c699ada33af5d85263b30.

A typo in an assert escaped my local testing thanks to being a release
build :/

Added: 


Modified: 
clang/include/clang/Sema/Template.h

Removed: 




diff  --git a/clang/include/clang/Sema/Template.h 
b/clang/include/clang/Sema/Template.h
index 5dcde77b5dd3..8df92b7000f3 100644
--- a/clang/include/clang/Sema/Template.h
+++ b/clang/include/clang/Sema/Template.h
@@ -75,6 +75,8 @@ enum class TemplateSubstitutionKind : char {
   class MultiLevelTemplateArgumentList {
 /// The template argument list at a certain template depth
 using ArgList = ArrayRef;
+using ArgListsIterator = SmallVector::iterator;
+using ConstArgListsIterator = SmallVector::const_iterator;
 
 /// The template argument lists, stored from the innermost template
 /// argument list (first) to the outermost template argument list (last).
@@ -121,6 +123,12 @@ enum class TemplateSubstitutionKind : char {
   return TemplateArgumentLists.size();
 }
 
+// Determine the number of substituted args at 'Depth'.
+unsigned getNumSubsitutedArgs(unsigned Depth) const {
+  assert(NumRetainedOuterLevels <= Depth && Depth < getNumLevels());
+  return TemplateArgumentLists[getNumLevels() - Depth - 1].size();
+}
+
 unsigned getNumRetainedOuterLevels() const {
   return NumRetainedOuterLevels;
 }
@@ -158,6 +166,14 @@ enum class TemplateSubstitutionKind : char {
   return !(*this)(Depth, Index).isNull();
 }
 
+bool isAnyArgInstantiationDependent() const {
+  for (ArgList List : TemplateArgumentLists)
+for (const TemplateArgument &TA : List)
+  if (TA.isInstantiationDependent())
+return true;
+  return false;
+}
+
 /// Clear out a specific template argument.
 void setArgument(unsigned Depth, unsigned Index,
  TemplateArgument Arg) {
@@ -183,6 +199,14 @@ enum class TemplateSubstitutionKind : char {
   TemplateArgumentLists.push_back(Args);
 }
 
+/// Replaces the current 'innermost' level with the provided argument list.
+/// This is useful for type deduction cases where we need to get the entire
+/// list from the AST, but then add the deduced innermost list.
+void replaceInnermostTemplateArguments(ArgList Args) {
+  assert(TemplateArgumentLists.size() > 0 && "Replacing in an empty 
list?");
+  TemplateArgumentLists[0] = Args;
+}
+
 /// Add an outermost level that we are not substituting. We have no
 /// arguments at this level, and do not remove it from the depth of inner
 /// template parameters that we instantiate.
@@ -197,6 +221,16 @@ enum class TemplateSubstitutionKind : char {
 const ArgList &getInnermost() const {
   return TemplateArgumentLists.front();
 }
+/// Retrieve the outermost template argument list.
+const ArgList &getOutermost() const {
+  return TemplateArgumentLists.back();
+}
+ArgListsIterator begin() { return TemplateArgumentLists.begin(); }
+ConstArgListsIterator begin() const {
+  return TemplateArgumentLists.begin();
+}
+ArgListsIterator end() { return TemplateArgumentLists.end(); }
+ConstArgListsIterator end() const { return TemplateArgumentLists.end(); }
   };
 
   /// The context in which partial ordering of function templates occurs.



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


[PATCH] D130362: Fix one stray `{LLVM -> CLANG}_TOOLS_INSTALL_DIR`

2022-07-25 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

Thanks for the fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130362

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


[PATCH] D111617: [RISCV] Lazily add RVV C intrinsics.

2022-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM, only minor nits found (feel free to ignore any that you disagree with).




Comment at: clang/include/clang/Support/RISCVVIntrinsicUtils.h:346
 
+// RVVRequire should be sync with target features, but only
+// required features used in riscv_vector.td.





Comment at: clang/include/clang/Support/RISCVVIntrinsicUtils.h:362
+
+  // Overloaded intrinsic name, could be empty if it can be computed from Name
+  // e.g. vadd





Comment at: clang/include/clang/Support/RISCVVIntrinsicUtils.h:400
+  // Number of fields, greater than 1 if it's segment load/store.
+  uint8_t NF;
+};





Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:32
+
+// Function definition of a RVV intrinsic
+struct RVVIntrinsicDef {





Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:40
+
+  /// Mapping to which clang built-in function, e.g. __builtin_rvv_vadd
+  std::string BuiltinName;





Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:131
+namespace {
+class RISCVIntrinsicManagerImpl : public clang::sema::RISCVIntrinsicManager {
+private:

You can drop all uses of `clang::` in this file.



Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:181-187
+auto ProtoSeq =
+ProtoSeq2ArrayRef(Record.PrototypeIndex, Record.PrototypeLength);
+auto ProtoMaskSeq = ProtoSeq2ArrayRef(Record.MaskedPrototypeIndex,
+  Record.MaskedPrototypeLength);
+auto SuffixProto =
+ProtoSeq2ArrayRef(Record.SuffixIndex, Record.SuffixLength);
+auto OverloadedSuffixProto = 
ProtoSeq2ArrayRef(Record.OverloadedSuffixIndex,

Please don't use `auto` when the type is not spelled out in the initialization.



Comment at: clang/lib/Sema/SemaRISCVVectorLookup.cpp:307-308
+  // Skip return type, and convert RVVType to QualType for arguments.
+  for (size_t i = 1; i < SigLength; ++i)
+ArgTypes.push_back(RVVType2Qual(Context, Sigs[i]));
+





Comment at: clang/utils/TableGen/RISCVVEmitter.cpp:63
+  // Number of field, large than 1 if it's segment load/store.
+  unsigned NF;
+};




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111617

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


[PATCH] D128955: [WPD] Use new llvm.public.type.test intrinsic for potentially publicly visible classes

2022-07-25 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a subscriber: fhahn.
tejohnson added a comment.

In D128955#3674787 , @aeubanks wrote:

> random question, if the old API is "legacy", are there any plans to remove it?

@fhahn started to work on this at some point (see 
https://bugs.llvm.org/show_bug.cgi?id=41541), but I'm not sure of the status. 
It is used by ld64 and I believe the sony toolchain too.




Comment at: lld/test/ELF/lto/update_public_type_test.ll:5
+
+; RUN: opt --thinlto-bc -o %t.o %s
+; RUN: ld.lld %t.o -o %t2.o --save-temps

Just realized there isn't any testing of the regular LTO handling with the new 
LTO API. Can you extend this test to check regular LTO as well?



Comment at: llvm/test/LTO/X86/public-type-test.ll:3
+
+; RUN: opt -module-summary %s -o %t.bc
+; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t.bc 
--thinlto-save-temps=%t2

aeubanks wrote:
> tejohnson wrote:
> > The new version switched this from a regular LTO to ThinLTO test. I think 
> > we need both. Can you move the new version into llvm/test/ThinLTO/X86 and 
> > make this version back to testing the regular LTO old API handling, but 
> > with checks?
> done, had to add a new flag to dump IR right before optimizations
I see, looks like llvm-lto has a thinlto-save-temps that is wired up to dump 
the same outputs as the new LTO API's save temps, but regular LTO didn't have 
the same support. I'd go ahead and use the same naming convention (0.preopt.bc) 
for compatibility with the new LTO API, in case that save temps handling is 
ever generalized to support both thin and regular LTO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128955

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


[PATCH] D129401: [libLTO] Set data-sections by default in libLTO.

2022-07-25 Thread Quinn Pham via Phabricator via cfe-commits
quinnp added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:579
+  else if (Args.hasArg(options::OPT_fno_data_sections))
+CmdArgs.push_back("-plugin-opt=-data-sections=0");
 

MaskRay wrote:
> Is -plugin-opt=-data-sections=0 a problem for `!UseSeparateSections` targets?
I don't think `-plugin-opt=-data-sections=0` is a problem for 
`!UseSeparateSections` targets because we only add 
`"-plugin-opt=-data-sections=0"` if the user explicitly specified 
`-fno-data-sections`.  
- If `UseSeparateSections` is `true`, we will enter the  `if` block unless 
`-fno-data-sections` is explicitly set.
- If `UseSeparateSections` is `false`, we will enter the `if` block only if  
`-fdata-sections` is explicitly set.

Then, if we did not enter the `if` block, we will only enter the `else if` 
block when `-fno-data-sections` is explicitly set.



Comment at: llvm/test/LTO/PowerPC/data-sections-linux.ll:20
+
+; CHECK-NO-DATA-SECTIONS-NOT: .var
+; CHECK-NO-DATA-SECTIONS:  g O .bss {{.*}} var

MaskRay wrote:
> What does this `...-NOT: .var` do?
The line `; CHECK-NO-DATA-SECTIONS-NOT: .var` is to ensure that `data-sections` 
is correctly turned off. On Linux, when `data-sections` is on each variable `X` 
will have its own section named `.bss.X`. Here, I am trying to make sure that 
the the `.X` part is not present since it may have been consumed by the 
`{{.*}}` after the check for `.bss` on the next line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129401

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


[PATCH] D129401: [libLTO] Set data-sections by default in libLTO.

2022-07-25 Thread Quinn Pham via Phabricator via cfe-commits
quinnp updated this revision to Diff 447336.
quinnp marked 3 inline comments as done.
quinnp added a comment.

Adressing review comments. Moving tests into `function-sections.c`, using `%s` 
instead of creating a new file with `touch`, and modifying some `CHECK` lines 
to simplify checks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129401

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/function-sections.c
  clang/test/Driver/gold-lto-sections.c
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/test/LTO/PowerPC/data-sections-aix.ll
  llvm/test/LTO/PowerPC/data-sections-linux.ll

Index: llvm/test/LTO/PowerPC/data-sections-linux.ll
===
--- /dev/null
+++ llvm/test/LTO/PowerPC/data-sections-linux.ll
@@ -0,0 +1,21 @@
+; RUN: rm -rf %t
+; RUN: mkdir %t
+; RUN: llvm-as %s -o %t/bc.bc
+; RUN: llvm-lto -exported-symbol var -O0 %t/bc.bc -o %t/default.o
+; RUN: llvm-lto -exported-symbol var -O0 --data-sections=1 %t/bc.bc -o \
+; RUN:   %t/data-sections.o
+; RUN: llvm-lto -exported-symbol var -O0 --data-sections=0 %t/bc.bc -o \
+; RUN:   %t/no-data-sections.o
+; RUN: llvm-objdump -t %t/default.o | FileCheck %s
+; RUN: llvm-objdump -t %t/data-sections.o | FileCheck %s
+; RUN: llvm-objdump -t %t/no-data-sections.o | FileCheck --check-prefix \
+; RUN:   CHECK-NO-DATA-SECTIONS %s
+
+target triple = "powerpc64le-unknown-linux-gnu"
+
+@var = global i32 0
+
+; CHECK:   g O .bss.var {{.*}} var
+
+; CHECK-NO-DATA-SECTIONS-NOT: .var
+; CHECK-NO-DATA-SECTIONS:  g O .bss {{.*}} var
Index: llvm/test/LTO/PowerPC/data-sections-aix.ll
===
--- /dev/null
+++ llvm/test/LTO/PowerPC/data-sections-aix.ll
@@ -0,0 +1,21 @@
+; RUN: rm -rf %t
+; RUN: mkdir %t
+; RUN: llvm-as %s -o %t/bc.bc
+; RUN: llvm-lto -exported-symbol var -O0 %t/bc.bc -o %t/default.o
+; RUN: llvm-lto -exported-symbol var -O0 --data-sections=1 %t/bc.bc -o \
+; RUN:   %t/data-sections.o
+; RUN: llvm-lto -exported-symbol var -O0 --data-sections=0 %t/bc.bc -o \
+; RUN:   %t/no-data-sections.o
+; RUN: llvm-objdump -t %t/default.o | FileCheck %s
+; RUN: llvm-objdump -t %t/data-sections.o | FileCheck %s
+; RUN: llvm-objdump -t %t/no-data-sections.o | FileCheck --check-prefix \
+; RUN:   CHECK-NO-DATA-SECTIONS %s
+
+target triple = "powerpc-ibm-aix7.2.0.0"
+
+@var = global i32 0
+
+; CHECK-NOT:  (csect: .data)
+; CHECK:   g O .data {{.*}} var
+
+; CHECK-NO-DATA-SECTIONS:  g O .data (csect: .data) {{.*}} var
Index: llvm/lib/LTO/LTOCodeGenerator.cpp
===
--- llvm/lib/LTO/LTOCodeGenerator.cpp
+++ llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -19,6 +19,7 @@
 #include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeWriter.h"
+#include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/CodeGen/ParallelCG.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/Config/config.h"
@@ -344,6 +345,11 @@
   Config.CPU = "cyclone";
   }
 
+  // If data-sections is not explicitly set or unset, set data-sections by
+  // default to match the behaviour of lld and gold plugin.
+  if (!codegen::getExplicitDataSections())
+Config.Options.DataSections = true;
+
   TargetMach = createTargetMachine();
   assert(TargetMach && "Unable to create target machine");
 
Index: clang/test/Driver/gold-lto-sections.c
===
--- clang/test/Driver/gold-lto-sections.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: touch %t.o
-//
-// RUN: %clang -target x86_64-unknown-linux -### %t.o -flto 2>&1 \
-// RUN: -Wl,-plugin-opt=foo -O3 \
-// RUN: -ffunction-sections -fdata-sections \
-// RUN: | FileCheck %s
-// CHECK: "-plugin-opt=-function-sections"
-// CHECK: "-plugin-opt=-data-sections"
Index: clang/test/Driver/function-sections.c
===
--- clang/test/Driver/function-sections.c
+++ clang/test/Driver/function-sections.c
@@ -6,6 +6,12 @@
 // CHECK-NODS-NOT: -fdata-sections
 // CHECK-US-NOT: -fno-unique-section-names
 // CHECK-NOUS: -fno-unique-section-names
+// CHECK-PLUGIN-DEFAULT-NOT: "-plugin-opt=-function-sections
+// CHECK-PLUGIN-DEFAULT-NOT: "-plugin-opt=-data-sections
+// CHECK-PLUGIN-SECTIONS: "-plugin-opt=-function-sections=1"
+// CHECK-PLUGIN-SECTIONS: "-plugin-opt=-data-sections=1"
+// CHECK-PLUGIN-NO-SECTIONS: "-plugin-opt=-function-sections=0"
+// CHECK-PLUGIN-NO-SECTIONS: "-plugin-opt=-data-sections=0"
 
 // RUN: %clang -### %s -fsyntax-only 2>&1   \
 // RUN: --target=i386-unknown-linux \
@@ -72,3 +78,18 @@
 // RUN: --target=i386-unknown-linux \
 // RUN: -fno-unique-section-names \
 // RUN:   | FileCheck --che

[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

Requesting changes until we have an answer for the testing situation.




Comment at: clang/lib/Sema/SemaDecl.cpp:18883-18884
+  // If the enumerator is zero that should still be counted as a positive
+  // bit since we need a bit to store the value zero
+  const unsigned ActiveBits = InitVal.getActiveBits();
+  NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});

Add trailing punctuation, removes top-level `const`.



Comment at: clang/lib/Sema/SemaDecl.cpp:18892
 
+  // If we have have a empty set of enumerators we still need one bit.
+  // From [dcl.enum]p8





Comment at: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp:27
+  return ((int)e1 != -1) & ((int)e2 != -1) &
+ // CHECK: error: load of value , which is not a valid value 
for type 'enum EBool'
+ ((int)e3 != -1) & ((int)e4 == 1) &

erichkeane wrote:
> What does THIS come from?  What value is unknown?  Shouldn't the -1 be fine?
+1, I'm surprised by the `` there, but also... neither `e1` nor `e2` 
are of type `enum EBool`!


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

https://reviews.llvm.org/D130301

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


[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Also, this could use a release note. :-)


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

https://reviews.llvm.org/D130301

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


[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

2022-07-25 Thread Sam Estep via Phabricator via cfe-commits
samestep added a comment.

In D130306#3673120 , @xazax.hun wrote:

> Thanks! I think this is a major design decision, and I'd love to see a 
> discussion about the alternatives considered before jumping to an 
> implementation. Specifically, I'd like to know if summaries are out of scope 
> or something you would consider in the future. Knowing this is useful because 
> this can influence how the code should be reviewed. E.g., if you plan to have 
> multiple ways to do context sensitive analysis in the future, we should make 
> sure that the current code will not lock us in in the inline substitution 
> approach. If summaries are not planned at all, this is not a concern.

This is a good question. I shared with you our design doc, which may help 
clarify somewhat; please let me know if you have further concerns.

> The Clang Static Analyzer is using this approach and it was a long way to 
> iron out all the corner cases where the performance was bad. It has many cuts 
> including maximum number of visits for a basic block, maximum call stack 
> depth, not inlining functions after a certain size threshold and so on. 
> Basically, it took some time to get the right performance and precision. But 
> overall, the inline substitution approach will never scale to large call 
> stacks/long calling contexts. On the other hand, a summary-based approach can 
> potentially find bugs across a really large number of function calls with 
> reasonable costs. Mainly because the same function is not reanalyzed for 
> every context.

That makes a lot of sense. From what you're saying, it sounds like we'll avoid 
that in our plan by keeping contexts small due to only context-sensitively 
analyzing simple models that we write ourselves.

> I see. This was not clear to me from the description of the patch notes. It 
> seems to me that the goal here is to simplify the modeling of certain types, 
> not general context-sensitive analysis. I reviewed this patch with the wrong 
> idea in mind. If that is the goal, the current approach makes sense. But I 
> think the comments should make clear what the intended use case and the 
> limitations of the current approach is.

Fair point. Hopefully the intended use case will become more clear in the code 
itself as I follow up with further patches; if not then I can modify the 
comments to clarify that. Are there any specific things you'd like to see 
written comments in this patch itself before landing?

> The main reason I wanted to call this out because it increasingly seems to be 
> whenever a decision needs to be made, the framework is getting less and less 
> sound. Basically, many design decisions here are very similar to what the 
> Clang Static Analyzer is doing.  Since Clang already has an analysis 
> framework for unsound analysis, I wanted to avoid you reinventing the wheel 
> and doing something similar to CSA instead of providing something new for the 
> use cases that cannot be covered by the CSA.

This makes sense; in this case, though, the unsoundness is already present 
(this patch does nothing to change the way we analyze calls to functions for 
which we can't see the body), so if anything, unsoundness is reduced here. I'll 
let @ymandel respond to this in more detail, though.

> Oh, my bad! I somehow blinked and totally skipped that comment.

No worries! This patch is a bit large so it's easy to miss. Thanks for taking 
the time to review in such detail!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130306

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


[PATCH] D130446: [apinotes] Upstream changes to `APINotesYAMLCompiler.cpp`.

2022-07-25 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd requested changes to this revision.
compnerd added a comment.
This revision now requires changes to proceed.

Can you please add a round trip test as well?  Additionally, please add a 
proper commit message to describe the change here.




Comment at: clang/lib/APINotes/APINotesYAMLCompiler.cpp:425
+  Optional ReleaseOp;
+  FunctionsSeq MemberFuncs;
 };

Any reason to shorten `Functions` to `Funcs`?  It seems that it would be a bit 
odd given the other members.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130446

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


[PATCH] D130419: Use `` with MSVC and C++

2022-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM (be sure to drop the dummy file before landing), but please add a release 
note mentioning the fix as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130419

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


[PATCH] D101070: [llvm][cmake] Make `install_symlink` robust to absolute dirs.

2022-07-25 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added a comment.

@sebastian-ne Thanks yes I was worried that might happen. I think I will just 
move the `extend_path` to the caller then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

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


[PATCH] D101070: [llvm][cmake] Make `install_symlink` robust to absolute dirs.

2022-07-25 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 447358.
Ericson2314 added a comment.

Rebase, make caller responsible for making paths absolute

This avoids module resolution issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/LLVMInstallSymlink.cmake


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -1,22 +1,26 @@
 # We need to execute this script at installation time because the
 # DESTDIR environment variable may be unset at configuration time.
 # See PR8397.
+#
+# `outdir` must be an absolute path. This module gets a very reduced
+# `CMAKE_MODULE_PATH` so it is easier to make the caller the responsible
+# for this.
 
 include(GNUInstallDirs)
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1950,7 +1950,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" 
"PARAMS;DEPENDS;ARGS" ${ARGN})
-
+
 if (NOT ARG_FOLDER)
   set(ARG_FOLDER "Test Subdirectories")
 endif()
@@ -2006,11 +2006,14 @@
 
   set(output_dir lib${LLVM_LIBDIR_SUFFIX})
   if(WIN32 AND "${type}" STREQUAL "SHARED")
-set(output_dir bin)
+set(output_dir "${CMAKE_INSTALL_BINDIR}")
   endif()
 
+  # `install_symlink` needs an absoute path.
+  extend_path(output_dir "${CMAKE_INSTALL_PREFIX}" "${output_dir}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
 endfunction()
@@ -2045,8 +2048,11 @@
 set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
   endif()
 
+  # `install_symlink` needs an absoute path.
+  extend_path(output_dir "${CMAKE_INSTALL_PREFIX}" 
"${${project}_TOOLS_INSTALL_DIR}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} 
${${project}_TOOLS_INSTALL_DIR})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
   if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -1,22 +1,26 @@
 # We need to execute this script at installation time because the
 # DESTDIR environment variable may be unset at configuration time.
 # See PR8397.
+#
+# `outdir` must be an absolute path. This module gets a very reduced
+# `CMAKE_MODULE_PATH` so it is easier to make the caller the responsible
+# for this.
 
 include(GNUInstallDirs)
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1950,7 +1950,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" "PARAMS;DEPENDS;ARGS" ${ARGN})
-
+
 if (NOT ARG_FOLDER)
   set(ARG_FOLDER "Test Subdirectories")
 endif()
@@ -2006,11 +2006,14 @@
 
   set(output_dir lib${LLVM_LIBDIR_SUFFIX})
   if(WIN32 AND "${type}" STREQ

[PATCH] D128955: [WPD] Use new llvm.public.type.test intrinsic for potentially publicly visible classes

2022-07-25 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks updated this revision to Diff 447359.
aeubanks added a comment.

update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128955

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cfi-mfcall.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/thinlto_public_type_test_distributed.ll
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/test/ELF/lto/update_public_type_test.ll
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Analysis/TypeMetadataUtils.cpp
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/IR/ModuleSummaryIndex.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/LTO/X86/public-type-test.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/ThinLTO/X86/public-type-test.ll
  llvm/tools/llvm-lto/llvm-lto.cpp

Index: llvm/tools/llvm-lto/llvm-lto.cpp
===
--- llvm/tools/llvm-lto/llvm-lto.cpp
+++ llvm/tools/llvm-lto/llvm-lto.cpp
@@ -261,6 +261,10 @@
  cl::desc("Print pass management debugging information"),
  cl::cat(LTOCategory));
 
+static cl::opt
+LTOSaveBeforeOpt("lto-save-before-opt", cl::init(false),
+ cl::desc("Save the IR before running optimizations"));
+
 namespace {
 
 struct ModuleInfo {
@@ -1069,6 +1073,9 @@
 CodeGen.setFileType(*FT);
 
   if (!OutputFilename.empty()) {
+if (LTOSaveBeforeOpt)
+  CodeGen.setSaveIRBeforeOptPath(OutputFilename + ".0.preopt.bc");
+
 if (SaveLinkedModuleFile) {
   std::string ModuleFilename = OutputFilename;
   ModuleFilename += ".linked.bc";
Index: llvm/test/ThinLTO/X86/public-type-test.ll
===
--- /dev/null
+++ llvm/test/ThinLTO/X86/public-type-test.ll
@@ -0,0 +1,25 @@
+; Test to ensure that the legacy LTO API lowers @llvm.public.type.test.
+
+; RUN: opt -module-summary %s -o %t.bc
+; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t.bc --thinlto-save-temps=%t2
+; RUN: llvm-dis -o - %t20.2.internalized.bc | FileCheck %s --check-prefix=PUBLIC
+; RUN: llvm-lto --thinlto-action=run -exported-symbol=_main %t.bc --thinlto-save-temps=%t2 --whole-program-visibility
+; RUN: llvm-dis -o - %t20.2.internalized.bc | FileCheck %s --check-prefix=HIDDEN
+
+; PUBLIC-NOT: call {{.*}}@llvm.public.type.test
+; PUBLIC-NOT: call {{.*}}@llvm.type.test
+; HIDDEN-NOT: call {{.*}}@llvm.public.type.test
+; HIDDEN: call {{.*}}@llvm.type.test
+
+target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.9"
+
+define i32 @main(ptr %vtable) {
+entry:
+  %p = call i1 @llvm.public.type.test(ptr %vtable, metadata !"_ZTS1A")
+  call void @llvm.assume(i1 %p)
+  ret i32 0
+}
+
+declare void @llvm.assume(i1)
+declare i1 @llvm.public.type.test(ptr, metadata)
Index: llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
===
--- llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
+++ llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
@@ -10,6 +10,7 @@
 ; RUN:   -whole-program-visibility \
 ; RUN:   -o %t3 \
 ; RUN:   -r=%t2.o,test,px \
+; RUN:   -r=%t2.o,test_public,px \
 ; RUN:   -r=%t2.o,_ZN1A1nEi,p \
 ; RUN:   -r=%t2.o,_ZN1B1fEi,p \
 ; RUN:   -r=%t2.o,_ZN1C1fEi,p \
@@ -17,6 +18,7 @@
 ; RUN:   -r=%t2.o,_ZTV1B,px \
 ; RUN:   -r=%t2.o,_ZTV1C,px \
 ; RUN:   -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK
+; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT
 ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ; Hybrid WPD
@@ -26,6 +28,7 @@
 ; RUN:   -whole-program-visibility \
 ; RUN:   -o %t3 \
 ; RUN:   -r=%t.o,test,px \
+; RUN:   -r=%t.o,test_public,px \
 ; RUN:   -r=%t.o,_ZN1A1nEi,p \
 ; RUN:   -r=%t.o,_ZN1B1fEi,p \
 ; RUN:   -r=%t.o,_ZN1C1fEi,p \
@@ -40,6 +43,7 @@
 ; RUN:   -r=%t.o,_ZTV1B,px \
 ; RUN:   -r=%t.o,_ZTV1C,px \
 ; RUN:   -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK --dump-input=fail
+; RUN: llvm-dis %t3.1.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT
 ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
 
 ; Regular LTO WPD
@@ -48,6 +52,7 @@
 ; RUN:   -whole-program-visibility \
 ; RUN:   -o %t5 \
 ; RUN:   -r=%t4.o,test,px \
+; RUN:   -r=%t4.o,test_public,px \
 ; RUN:   -r=%t4.o,_ZN1A1nEi,p \
 ; RUN:   -r=%t4.o,

[PATCH] D130493: Disable stack-sizes section by default for PS4.

2022-07-25 Thread Ying Yi via Phabricator via cfe-commits
MaggieYi created this revision.
MaggieYi added reviewers: probinson, wristow.
Herald added a project: All.
MaggieYi requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Change Clang's default so that -fstack-size-section is no longer enabled by 
default for PS4.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130493

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/stack-size-section.c


Index: clang/test/Driver/stack-size-section.c
===
--- clang/test/Driver/stack-size-section.c
+++ clang/test/Driver/stack-size-section.c
@@ -4,7 +4,7 @@
 // CHECK-ABSENT-NOT: -fstack-size-section
 
 // RUN: %clang -target x86_64-unknown -fstack-size-section -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-PRESENT
-// RUN: %clang -target x86_64-scei-ps4 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-PRESENT
+// RUN: %clang -target x86_64-scei-ps4 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-ABSENT
 // CHECK-PRESENT: -fstack-size-section
 
 // RUN: %clang -target x86_64-unknown -fstack-size-section 
-fno-stack-size-section %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5880,7 +5880,7 @@
   }
 
   if (Args.hasFlag(options::OPT_fstack_size_section,
-   options::OPT_fno_stack_size_section, RawTriple.isPS4()))
+   options::OPT_fno_stack_size_section, false))
 CmdArgs.push_back("-fstack-size-section");
 
   if (Args.hasArg(options::OPT_fstack_usage)) {


Index: clang/test/Driver/stack-size-section.c
===
--- clang/test/Driver/stack-size-section.c
+++ clang/test/Driver/stack-size-section.c
@@ -4,7 +4,7 @@
 // CHECK-ABSENT-NOT: -fstack-size-section
 
 // RUN: %clang -target x86_64-unknown -fstack-size-section -### 2>&1 | FileCheck %s --check-prefix=CHECK-PRESENT
-// RUN: %clang -target x86_64-scei-ps4 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-PRESENT
+// RUN: %clang -target x86_64-scei-ps4 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ABSENT
 // CHECK-PRESENT: -fstack-size-section
 
 // RUN: %clang -target x86_64-unknown -fstack-size-section -fno-stack-size-section %s -### 2>&1 \
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5880,7 +5880,7 @@
   }
 
   if (Args.hasFlag(options::OPT_fstack_size_section,
-   options::OPT_fno_stack_size_section, RawTriple.isPS4()))
+   options::OPT_fno_stack_size_section, false))
 CmdArgs.push_back("-fstack-size-section");
 
   if (Args.hasArg(options::OPT_fstack_usage)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

2022-07-25 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

In D130306#3676325 , @samestep wrote:

> 



>> The main reason I wanted to call this out because it increasingly seems to 
>> be whenever a decision needs to be made, the framework is getting less and 
>> less sound. Basically, many design decisions here are very similar to what 
>> the Clang Static Analyzer is doing.  Since Clang already has an analysis 
>> framework for unsound analysis, I wanted to avoid you reinventing the wheel 
>> and doing something similar to CSA instead of providing something new for 
>> the use cases that cannot be covered by the CSA.
>
> This makes sense; in this case, though, the unsoundness is already present 
> (this patch does nothing to change the way we analyze calls to functions for 
> which we can't see the body), so if anything, unsoundness is reduced here. 
> I'll let @ymandel respond to this in more detail, though.

Gabor, I fully agree. We need to start paying down the debt on the unsoundness, 
reducing it where possible and otherwise giving users control over whether to 
incur it.  However, as Sam wrote, we did not expect to be incurring any new 
unsoundness here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130306

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


[PATCH] D101070: [llvm][cmake] Make `install_symlink` workflow work with absolute install dirs

2022-07-25 Thread Sebastian Neubauer via Phabricator via cfe-commits
sebastian-ne added a comment.

I get a configure error with this version:

  CMake Error at cmake/modules/AddLLVM.cmake:2052 (extend_path):
Unknown CMake command "extend_path".
  Call Stack (most recent call first):
cmake/modules/AddLLVM.cmake:2148 (llvm_install_symlink)
cmake/modules/AddLLVM.cmake:2154 (llvm_add_tool_symlink)
tools/llvm-ar/CMakeLists.txt:22 (add_llvm_tool_symlink)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

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


[PATCH] D128955: [WPD] Use new llvm.public.type.test intrinsic for potentially publicly visible classes

2022-07-25 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks marked an inline comment as done.
aeubanks added a comment.

In D128955#3676198 , @tejohnson wrote:

> In D128955#3674787 , @aeubanks 
> wrote:
>
>> random question, if the old API is "legacy", are there any plans to remove 
>> it?
>
> @fhahn started to work on this at some point (see 
> https://bugs.llvm.org/show_bug.cgi?id=41541), but I'm not sure of the status. 
> It is used by ld64 and I believe the sony toolchain too.

if I'm seeing correctly, looks like there aren't any in-tree users of 
ThinLTOCodeGenerator/LTOCodeGenerator. are those out of tree?




Comment at: lld/test/ELF/lto/update_public_type_test.ll:5
+
+; RUN: opt --thinlto-bc -o %t.o %s
+; RUN: ld.lld %t.o -o %t2.o --save-temps

tejohnson wrote:
> Just realized there isn't any testing of the regular LTO handling with the 
> new LTO API. Can you extend this test to check regular LTO as well?
extended `llvm/test/LTO/X86/public-type-test.ll`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128955

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


[PATCH] D117973: [cmake] Support custom package install paths

2022-07-25 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 447361.
Ericson2314 added a comment.

Fix bug, and add comments to both branches for clarity


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117973

Files:
  clang/cmake/modules/CMakeLists.txt
  cmake/Modules/FindPrefixFromConfig.cmake
  cmake/Modules/GNUInstallPackageDir.cmake
  flang/cmake/modules/CMakeLists.txt
  lld/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/CMakeLists.txt
  mlir/cmake/modules/CMakeLists.txt
  polly/cmake/CMakeLists.txt

Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -1,10 +1,19 @@
 # Keep this in sync with llvm/cmake/CMakeLists.txt!
 
+include(GNUInstallPackageDir)
 include(ExtendPath)
 include(FindPrefixFromConfig)
 
-set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
-set(POLLY_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
+set(POLLY_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/polly" CACHE STRING
+  "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')")
+# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
+set(polly_cmake_builddir "${POLLY_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
+
+set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
+  "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
+# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
+set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
+
 if (CMAKE_CONFIGURATION_TYPES)
   set(POLLY_EXPORTS_FILE_NAME "PollyExports-$>.cmake")
 else()
@@ -28,9 +37,6 @@
   set(POLLY_CONFIG_TARGET_${tgt}_TYPE ${tgt_type})
 endforeach()
 
-set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
-
 # generate the import code for bundled/undbundled libisl versions
 if (NOT POLLY_BUNDLED_ISL)
   get_property(incl TARGET ISL PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
@@ -50,7 +56,8 @@
 
 # Generate PollyConfig.cmake for the build tree.
 set(POLLY_CONFIG_CODE "")
-set(POLLY_CONFIG_CMAKE_DIR "${CMAKE_BINARY_DIR}/${POLLY_INSTALL_PACKAGE_DIR}")
+set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
+set(POLLY_CONFIG_CMAKE_DIR "${polly_cmake_builddir}")
 set(POLLY_CONFIG_INCLUDE_DIRS
   ${POLLY_SOURCE_DIR}/include
   ${ISL_INCLUDE_DIRS}
@@ -73,11 +80,11 @@
 # the imported locations
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
-  ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake
+  ${polly_cmake_builddir}/PollyConfig.cmake
   @ONLY)
 
 file(GENERATE
-  OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME}
+  OUTPUT ${polly_cmake_builddir}/${POLLY_EXPORTS_FILE_NAME}
   CONTENT "${POLLY_EXPORTS}")
 
 
Index: mlir/cmake/modules/CMakeLists.txt
===
--- mlir/cmake/modules/CMakeLists.txt
+++ mlir/cmake/modules/CMakeLists.txt
@@ -1,3 +1,4 @@
+include(GNUInstallPackageDir)
 include(ExtendPath)
 include(LLVMDistributionSupport)
 include(FindPrefixFromConfig)
@@ -5,12 +6,16 @@
 # Generate a list of CMake library targets so that other CMake projects can
 # link against them. LLVM calls its version of this file LLVMExports.cmake, but
 # the usual CMake convention seems to be ${Project}Targets.cmake.
-set(MLIR_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir)
-set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/${MLIR_INSTALL_PACKAGE_DIR}")
+set(MLIR_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/mlir" CACHE STRING
+  "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')")
+# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
+set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir")
 
 # Keep this in sync with llvm/cmake/CMakeLists.txt!
-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
-set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
+set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
+  "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
+# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
+set(llvm_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
 
 get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS)
 export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake)
@@ -54,8 +59,8 @@
 
 # Generate MLIRConfig.cmake for the install tree.
 find_prefix_from_config(MLIR_CONFIG_CODE MLIR_INSTALL_PREFIX "${MLIR_INSTALL_PACKAGE_DIR}")
-set(MLIR_CONFIG_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${MLIR_INSTALL_PACKAGE_DIR}")
-set(MLIR_CONFIG_LLVM_CMAKE_DIR "\${MLIR_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE

[PATCH] D117973: [cmake] Support custom package install paths

2022-07-25 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 marked 2 inline comments as done.
Ericson2314 added inline comments.



Comment at: cmake/Modules/FindPrefixFromConfig.cmake:30
+  if(IS_ABSOLUTE "${path_to_leave}")
+set(prefix_var
+  "# Installation prefix is fixed absolute path"

sebastian-ne wrote:
> Shouldn’t this set `config_code` instead of `prefix_var`, which is the output 
> variable in the generated code?
Yes! Silly mistake me cleaning the code up for upstreaming but not yet testing 
it with our configuration again. Thanks for noticing.



Comment at: cmake/Modules/FindPrefixFromConfig.cmake:32
+  "# Installation prefix is fixed absolute path"
+  "set(${prefix_var} \"${CMAKE_INSTALL_PREFIX}\"")
+  else()

sebastian-ne wrote:
> This could use a comment to why it ignores `path_to_leave` and why 
> `CMAKE_INSTALL_PREFIX` is the correct choice.
Added comments to both branches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117973

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


[PATCH] D117973: [cmake] Support custom package install paths

2022-07-25 Thread Sebastian Neubauer via Phabricator via cfe-commits
sebastian-ne accepted this revision.
sebastian-ne added a comment.
This revision is now accepted and ready to land.

Thank you, the comments make it clearer what’s happening. LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117973

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


[PATCH] D130145: [AArch64] Simplify BTI/PAC-RET module flags

2022-07-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked an inline comment as done.
MaskRay added inline comments.



Comment at: llvm/lib/IR/AutoUpgrade.cpp:4415-4430
-// Upgrade branch protection and return address signing module flags. The
-// module flag behavior for these fields were Error and now they are Min.
-if (ID->getString() == "branch-target-enforcement" ||
-ID->getString().startswith("sign-return-address")) {
-  if (auto *Behavior =
-  mdconst::dyn_extract_or_null(Op->getOperand(0))) {
-if (Behavior->getLimitedValue() == Module::Error) {

danielkiss wrote:
> MaskRay wrote:
> > danielkiss wrote:
> > > In a full LTO build the linker will complain about the mis match between 
> > > the flags if one of the objects compiled with an older compiler that 
> > > emitted `Module:Error` for these flags.
> > The new approach doesnot emit a flag for 0 value, so there won't be an 
> > error even with old bitcode files using `Error`.
> older compiler could emit `Module:Error` with 0 and with this patch we emit 1 
> with `min` so the linker will stop with 
> `ld.lld: error: linking module flags 'branch-target-enforcement': IDs have 
> conflicting behaviors in 'foo.o' and 'ld-temp.o'`
> 
> ```
> clang++-13 -flto=full -c foo.cpp -o foo.o
> ../build/bin/clang++ -flto=full -c main.cpp -o main.o 
> -mbranch-protection=standard
> ../build/bin/clang++ -fuse-ld=lld main.o foo.o -o a.out
> ```
> 
Perhaps we should respect the Error for older llvm and not try fixing it for 
regular LTO? If you feel this is strongly needed, I'll have to restore this 
chunk. The main purpose is to remove the module flags for 0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130145

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


[PATCH] D129570: Add new clang-tidy check to find implicit conversions from enum to integer.

2022-07-25 Thread Artem Tamazov via Phabricator via cfe-commits
artem.tamazov requested changes to this revision.
artem.tamazov added a comment.
This revision now requires changes to proceed.

A typo in the doc, but otherwise LGTM.




Comment at: clang-tools-extra/docs/clang-tidy/checks/bugprone/enum-to-int.rst:8
+integer. In C++11, enums can be defined as ``enum class`` which will prevent
+such implicit conversion, however, ``enum`` provides no such guarantess to
+prevent bugs. There can be many reasons why ``enum`` cannot be replaced with




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129570

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


[PATCH] D130497: [clang][dataflow] Fix MapLattice::insert() to not drop return value

2022-07-25 Thread Eric Li via Phabricator via cfe-commits
li.zhe.hua created this revision.
li.zhe.hua added a reviewer: ymandel.
Herald added subscribers: martong, tschuett, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
li.zhe.hua requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix `MapLattice` API to return `std::pair`,
allowing users to detect when an element has been inserted without
performing a redundant map lookup.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130497

Files:
  clang/include/clang/Analysis/FlowSensitive/MapLattice.h
  clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp
@@ -50,13 +50,18 @@
 static constexpr int Key2 = 1;
 
 namespace {
+using ::testing::_;
 using ::testing::Pair;
 using ::testing::UnorderedElementsAre;
 
 TEST(MapLatticeTest, InsertWorks) {
   MapLattice Lattice;
-  Lattice.insert({Key1, BooleanLattice(false)});
-  Lattice.insert({Key2, BooleanLattice(false)});
+  EXPECT_THAT(Lattice.insert({Key1, BooleanLattice(false)}), Pair(_, true));
+  EXPECT_THAT(Lattice.insert({Key2, BooleanLattice(false)}), Pair(_, true));
+
+  // Insertion fails on collision.
+  EXPECT_THAT(Lattice.insert({Key1, BooleanLattice(false)}), Pair(_, false));
+  EXPECT_THAT(Lattice.insert({Key2, BooleanLattice(false)}), Pair(_, false));
 
   EXPECT_THAT(Lattice, UnorderedElementsAre(Pair(Key1, BooleanLattice(false)),
 Pair(Key2, 
BooleanLattice(false;
Index: clang/include/clang/Analysis/FlowSensitive/MapLattice.h
===
--- clang/include/clang/Analysis/FlowSensitive/MapLattice.h
+++ clang/include/clang/Analysis/FlowSensitive/MapLattice.h
@@ -54,10 +54,13 @@
   // The `bottom` element is the empty map.
   static MapLattice bottom() { return MapLattice(); }
 
-  void insert(const std::pair &P) { C.insert(P); }
+  std::pair
+  insert(const std::pair &P) {
+return C.insert(P);
+  }
 
-  void insert(std::pair &&P) {
-C.insert(std::move(P));
+  std::pair insert(std::pair &&P) 
{
+return C.insert(std::move(P));
   }
 
   unsigned size() const { return C.size(); }


Index: clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/MapLatticeTest.cpp
@@ -50,13 +50,18 @@
 static constexpr int Key2 = 1;
 
 namespace {
+using ::testing::_;
 using ::testing::Pair;
 using ::testing::UnorderedElementsAre;
 
 TEST(MapLatticeTest, InsertWorks) {
   MapLattice Lattice;
-  Lattice.insert({Key1, BooleanLattice(false)});
-  Lattice.insert({Key2, BooleanLattice(false)});
+  EXPECT_THAT(Lattice.insert({Key1, BooleanLattice(false)}), Pair(_, true));
+  EXPECT_THAT(Lattice.insert({Key2, BooleanLattice(false)}), Pair(_, true));
+
+  // Insertion fails on collision.
+  EXPECT_THAT(Lattice.insert({Key1, BooleanLattice(false)}), Pair(_, false));
+  EXPECT_THAT(Lattice.insert({Key2, BooleanLattice(false)}), Pair(_, false));
 
   EXPECT_THAT(Lattice, UnorderedElementsAre(Pair(Key1, BooleanLattice(false)),
 Pair(Key2, BooleanLattice(false;
Index: clang/include/clang/Analysis/FlowSensitive/MapLattice.h
===
--- clang/include/clang/Analysis/FlowSensitive/MapLattice.h
+++ clang/include/clang/Analysis/FlowSensitive/MapLattice.h
@@ -54,10 +54,13 @@
   // The `bottom` element is the empty map.
   static MapLattice bottom() { return MapLattice(); }
 
-  void insert(const std::pair &P) { C.insert(P); }
+  std::pair
+  insert(const std::pair &P) {
+return C.insert(P);
+  }
 
-  void insert(std::pair &&P) {
-C.insert(std::move(P));
+  std::pair insert(std::pair &&P) {
+return C.insert(std::move(P));
   }
 
   unsigned size() const { return C.size(); }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130446: [apinotes] Upstream changes to `APINotesYAMLCompiler.cpp`.

2022-07-25 Thread Zoe Carver via Phabricator via cfe-commits
zoecarver added a comment.

> Can you please add a round trip test as well?

There is no testing infrastructure for this upstream. I have tests downstream.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130446

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


[PATCH] D130419: Use `` with MSVC and C++

2022-07-25 Thread Igor Zhukov via Phabricator via cfe-commits
fsb4000 updated this revision to Diff 447377.
fsb4000 added a comment.

drop the dummy file and update the release notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130419

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/stdatomic.h


Index: clang/lib/Headers/stdatomic.h
===
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -17,7 +17,8 @@
  * explicitly disallows `stdatomic.h` in the C mode via an `#error`.  Fallback
  * to the clang resource header until that is fully supported.
  */
-#if __STDC_HOSTED__ && __has_include_next() && !defined(_MSC_VER)
+#if __STDC_HOSTED__ && 
\
+__has_include_next() && !(defined(_MSC_VER) && 
!defined(__cplusplus))
 # include_next 
 #else
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -194,6 +194,8 @@
   move assignment operator. Fixes `Issue 56456 
`_.
 - Fixed a crash when a variable with a bool enum type that has no definition
   used in comparison operators. Fixes `Issue 56560 
`_.
+- Fixed incompatibility of clang's `` with MSVC ``.
+  Fixes `MSVC STL Issue 2862 `_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/lib/Headers/stdatomic.h
===
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -17,7 +17,8 @@
  * explicitly disallows `stdatomic.h` in the C mode via an `#error`.  Fallback
  * to the clang resource header until that is fully supported.
  */
-#if __STDC_HOSTED__ && __has_include_next() && !defined(_MSC_VER)
+#if __STDC_HOSTED__ && \
+__has_include_next() && !(defined(_MSC_VER) && !defined(__cplusplus))
 # include_next 
 #else
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -194,6 +194,8 @@
   move assignment operator. Fixes `Issue 56456 `_.
 - Fixed a crash when a variable with a bool enum type that has no definition
   used in comparison operators. Fixes `Issue 56560 `_.
+- Fixed incompatibility of clang's `` with MSVC ``.
+  Fixes `MSVC STL Issue 2862 `_.
 
 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] D49303: [CodeGen][ObjC] Treat non-escaping blocks as global blocks to make copy/dispose a no-op

2022-07-25 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Blocks that don't capture anything have always been allocated globally.  This 
optimization is using the global ISA for blocks that do capture locals but 
which are known statically (on penalty of UB) to not escape the original scope 
of the block literal.  Using the global ISA causes attempts to copy these 
blocks to have no effect, in case the program attempts to do unnecessary copies 
despite the block being declared non-escaping.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D49303

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


[PATCH] D130419: Use `` with MSVC and C++

2022-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D130419#3676643 , @fsb4000 wrote:

> drop the dummy file and update the release notes.

Thanks! I forgot to ask -- do you need someone to commit on your behalf? If so, 
what name and email address would you like used for patch attribution?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130419

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


[PATCH] D129872: [clang][OpenMP] Fix runtime crash in the call to __kmp_alloc.

2022-07-25 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 447372.
jyu2 edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129872

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/omp_init_allocator.c
  openmp/runtime/test/api/omp_init_allocator.c

Index: openmp/runtime/test/api/omp_init_allocator.c
===
--- /dev/null
+++ openmp/runtime/test/api/omp_init_allocator.c
@@ -0,0 +1,20 @@
+// RUN: %libomp-compile-and-run
+
+#include 
+#include 
+
+void test_allocate_allocator() {
+  omp_alloctrait_t x_traits[1] = {{omp_atk_alignment, 64}};
+  omp_allocator_handle_t x_alloc =
+  omp_init_allocator(omp_default_mem_space, 1, x_traits);
+  {
+int x;
+#pragma omp allocate(x) allocator(x_alloc)
+  }
+  omp_destroy_allocator(x_alloc);
+}
+
+int main() {
+  test_allocate_allocator();
+  printf("passed\n");
+}
Index: clang/test/OpenMP/omp_init_allocator.c
===
--- /dev/null
+++ clang/test/OpenMP/omp_init_allocator.c
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -isystem %S/Inputs -emit-llvm -o - -fopenmp \
+// RUN: -fopenmp-version=50 -triple x86_64-unknown-linux-gnu %s | FileCheck %s
+
+typedef enum {
+  omp_atk_sync_hint = 1,
+  omp_atk_alignment = 2
+} omp_alloctrait_key_t;
+typedef unsigned long int uintptr_t;
+typedef uintptr_t omp_uintptr_t;
+typedef struct {
+  omp_alloctrait_key_t key;
+  omp_uintptr_t value;
+} omp_alloctrait_t;
+typedef enum omp_allocator_handle_t {
+  omp_null_allocator = 0,
+  omp_default_mem_alloc = 1,
+  omp_large_cap_mem_alloc = 2,
+  omp_const_mem_alloc = 3,
+  omp_high_bw_mem_alloc = 4,
+  omp_low_lat_mem_alloc = 5,
+  omp_cgroup_mem_alloc = 6,
+  omp_pteam_mem_alloc = 7,
+  omp_thread_mem_alloc = 8,
+
+  omp_target_host_mem_alloc = 100,
+  omp_target_shared_mem_alloc = 101,
+  omp_target_device_mem_alloc = 102,
+  KMP_ALLOCATOR_MAX_HANDLE = (18446744073709551615UL)
+} omp_allocator_handle_t;
+typedef enum omp_memspace_handle_t {
+  omp_default_mem_space = 0,
+  omp_large_cap_mem_space = 1,
+  omp_const_mem_space = 2,
+  omp_high_bw_mem_space = 3,
+  omp_low_lat_mem_space = 4,
+
+  omp_target_host_mem_space = 100,
+  omp_target_shared_mem_space = 101,
+  omp_target_device_mem_space = 102,
+  KMP_MEMSPACE_MAX_HANDLE = (18446744073709551615UL)
+} omp_memspace_handle_t;
+
+extern omp_allocator_handle_t omp_init_allocator(omp_memspace_handle_t m,
+ int ntraits,
+ omp_alloctrait_t traits[]);
+//CHECK-LABEL: test_allocate_allocator
+void test_allocate_allocator() {
+  omp_alloctrait_t x_traits[1] = {{omp_atk_alignment, 64}};
+  omp_allocator_handle_t x_alloc =
+  omp_init_allocator(omp_default_mem_space, 1, x_traits);
+  {
+int x;
+// CHECK: [[RET:%.+]] = call i64 @omp_init_allocator
+// CHECK-NEXT: store i64 [[RET]], ptr [[X_ALLOC:%x_alloc]]
+// CHECK: [[TMP:%.+]] = load i64, ptr [[X_ALLOC]]
+// CHECK-NEXT: [[CONV:%conv]] = inttoptr i64 [[TMP]] to ptr
+// CHECK-NEXT: call ptr @__kmpc_alloc(i32 %0, i64 4, ptr [[CONV]])
+// CHECK-NOT: trunc
+#pragma omp allocate(x) allocator(x_alloc)
+  }
+}
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -16372,8 +16372,12 @@
   ExprResult Allocator = DefaultLvalueConversion(A);
   if (Allocator.isInvalid())
 return nullptr;
-  Allocator = PerformImplicitConversion(Allocator.get(),
-DSAStack->getOMPAllocatorHandleT(),
+  QualType AllocatorHT = DSAStack->getOMPAllocatorHandleT();
+  if (!AllocatorHT->isEnumeralType() && AllocatorHT->isIntegerType())
+// allocator_handler_t is enum type.  For int type convert to
+// UnsignedPointerDiffType avoid truncate.
+AllocatorHT = Context.getUnsignedPointerDiffType();
+  Allocator = PerformImplicitConversion(Allocator.get(), AllocatorHT,
 Sema::AA_Initializing,
 /*AllowExplicit=*/true);
   if (Allocator.isInvalid())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130306: [clang][dataflow] Analyze calls to in-TU functions

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

Thanks! Knowing the context, I am much happier with the direction overall. Is 
the plan to analyze a mock of std::optional instead of the actual code in the 
STL? How will that mock be shipped? Would that be embedded in the binary?

In D130306#3676475 , @ymandel wrote:

> Gabor, I fully agree. We need to start paying down the debt on the 
> unsoundness, reducing it where possible and otherwise giving users control 
> over whether to incur it.

I'm glad that this is still on the roadmap. I am a bit worried about how hard 
it will be to make the current memory model sound. Generally, I saw some 
researchers arguing that the access path approach 
 approach is a better fit for 
dataflow analysis. See this paper  
as an example. Although admittedly, I do not fully agree with everything they 
claim, they focus on distributive problems in that paper, and I found that most 
actual problems that we want to solve are not distributive. But whatever model 
we end up using, to restore soundness we might need to introduce a way to 
summarize certain constructs in our memory model. There are some ideas in this 
 survey paper.

> However, as Sam wrote, we did not expect to be incurring any new unsoundness 
> here.

I fully agree that this patch itself will not introduce new unsoundness (after 
the fixme mentioned in the description is resolved). My main concerns were:

- The framework started to feel more similar to symbolic execution than 
abstract interpretation, see the answer to this 

 question on the differences.
- I was a bit worried that adding more features before fixing the soundness 
issues might make fixing those problems harder.
- I was not sure the current approach would scale to general context-sensitive 
analysis. But looks like that is a non-goal for now. Doing this to model 
certain types of interest makes sense to me and is a good first step.

Overall, I am excited for context-sensitive analysis, and some of my concerns 
are addressed. Looking forward to the follow-up patches :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130306

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


[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-25 Thread krishna chaitanya sankisa via Phabricator via cfe-commits
skc7 updated this revision to Diff 447383.
skc7 edited the summary of this revision.
skc7 added a comment.

Rebase. Ping.


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

https://reviews.llvm.org/D130224

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/attr-maybeundef.c
  clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
  clang/test/Misc/pragma-attribute-supported-attributes-list.test

Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -83,6 +83,7 @@
 // CHECK-NEXT: Lockable (SubjectMatchRule_record)
 // CHECK-NEXT: MIGServerRoutine (SubjectMatchRule_function, SubjectMatchRule_objc_method, SubjectMatchRule_block)
 // CHECK-NEXT: MSStruct (SubjectMatchRule_record)
+// CHECK-NEXT: MayBeUndef (SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: MicroMips (SubjectMatchRule_function)
 // CHECK-NEXT: MinSize (SubjectMatchRule_function, SubjectMatchRule_objc_method)
 // CHECK-NEXT: MinVectorWidth (SubjectMatchRule_function)
Index: clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
===
--- /dev/null
+++ clang/test/CodeGenHIP/maybe_undef-attr-verify.hip
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -no-opaque-pointers -triple amdgcn-amd-amdhsa -target-cpu gfx906 -x hip -fcuda-is-device -emit-llvm  %s \
+// RUN:   -o - | FileCheck %s
+
+#define __global__ __attribute__((global))
+#define __device__ __attribute__((device))
+#define __maybe_undef __attribute__((maybe_undef))
+#define WARP_SIZE 64
+
+static constexpr int warpSize = __AMDGCN_WAVEFRONT_SIZE;
+
+__device__ static inline unsigned int __lane_id() {
+return  __builtin_amdgcn_mbcnt_hi(
+-1, __builtin_amdgcn_mbcnt_lo(-1, 0));
+}
+
+__device__
+inline
+int __shfl_sync(int __maybe_undef var, int src_lane, int width = warpSize) {
+int self = __lane_id();
+int index = src_lane + (self & ~(width-1));
+return __builtin_amdgcn_ds_bpermute(index<<2, var);
+}
+
+__global__ void
+shufflekernel()
+{
+int t;
+int res;
+res = __shfl_sync(t, WARP_SIZE, 0);
+}
+
+// CHECK: define dso_local amdgpu_kernel void @_Z13shufflekernelv()
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP1:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[TMP2:%.*]] = alloca i32, align 4, addrspace(5)
+// CHECK-NEXT:[[TMP3:%.*]] = addrspacecast i32 addrspace(5)* [[TMP1:%.*]] to i32*
+// CHECK-NEXT:[[TMP4:%.*]] = addrspacecast i32 addrspace(5)* [[TMP2:%.*]] to i32*
+// CHECK-NEXT:[[TMP5:%.*]] = load i32, i32* [[TMP3:%.*]], align 4
+// CHECK-NEXT:[[TMP6:%.*]] = freeze i32 [[TMP5:%.*]]
+// CHECK-NEXT:%call = call noundef i32 @_Z11__shfl_synciii(i32 noundef [[TMP6:%.*]], i32 noundef 64, i32 noundef 0) #4
+// CHECK-NEXT:store i32 %call, i32* [[TMP4:%.*]], align 4
+// CHECK-NEXT:  ret void
+
+// CHECK: define linkonce_odr noundef i32 @_Z11__shfl_synciii(i32 noundef %var, i32 noundef %src_lane, i32 noundef %width)
Index: clang/test/CodeGen/attr-maybeundef.c
===
--- /dev/null
+++ clang/test/CodeGen/attr-maybeundef.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - | FileCheck %s
+
+#define __maybe_undef __attribute__((maybe_undef))
+
+// CHECK: define dso_local void @t1(i32 noundef %param1, i32 noundef %param2, float noundef %param3) #[[attr1:[0-9]+]]
+void t1(int param1, int __maybe_undef param2, float param3) {}
+
+// CHECK: define dso_local void @t2(i32 noundef %param1, i32 noundef %param2, float noundef %param3)
+// CHECK: [[TMP1:%.*]] = freeze i32 [[TMP2:%.*]]
+// CHECK: call void @t1(i32 noundef %0, i32 noundef [[TMP1:%.*]], float noundef %2)
+// expected-error {{'maybe_undef' attribute only applies to parameters [-Wignored-attributes]}}
+void __maybe_undef t2(int param1, int param2, float param3) {
+t1(param1, param2, param3);
+}
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -8634,6 +8634,9 @@
   case ParsedAttr::AT_NoEscape:
 handleNoEscapeAttr(S, D, AL);
 break;
+  case ParsedAttr::AT_MayBeUndef:
+handleSimpleAttribute(S, D, AL);
+break;
   case ParsedAttr::AT_AssumeAligned:
 handleAssumeAlignedAttr(S, D, AL);
 break;
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2046,6 +2046,25 @@
   return false;
 }
 
+/// Check if the argument of a function has maybe_undef attribute.
+static bool IsArgumentMayBeUndef(const Decl *TargetDecl, unsigned

[PATCH] D129872: [clang][OpenMP] Fix runtime crash in the call to __kmp_alloc.

2022-07-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:16379
+// UnsignedPointerDiffType avoid truncate.
+AllocatorHT = Context.getUnsignedPointerDiffType();
+  Allocator = PerformImplicitConversion(Allocator.get(), AllocatorHT,

It must be int type, no?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129872

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


[PATCH] D130419: Use `` with MSVC and C++

2022-07-25 Thread Mark de Wever via Phabricator via cfe-commits
Mordante accepted this revision.
Mordante added a comment.
This revision is now accepted and ready to land.

In D130419#3676654 , @aaron.ballman 
wrote:

> In D130419#3676643 , @fsb4000 wrote:
>
>> drop the dummy file and update the release notes.
>
> Thanks! I forgot to ask -- do you need someone to commit on your behalf? If 
> so, what name and email address would you like used for patch attribution?

Thanks for asking. I just discussed with fsb4000 and I'll land it after 
updating the backticks in the documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130419

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


[PATCH] D130145: [AArch64] Simplify BTI/PAC-RET module flags

2022-07-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 447387.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Keep AutoUpgrade.cpp code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130145

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/aarch64-ls64-inline-asm.c
  clang/test/CodeGen/aarch64-ls64.c
  clang/test/CodeGen/aarch64-sign-return-address.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_ld1.c
  clang/test/CodeGen/arm-branch-protection-attr-2.c
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/target_teams_distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/teams_distribute_parallel_for_simd_if_codegen.cpp

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


[PATCH] D130419: Use `` with MSVC and C++

2022-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D130419#3676736 , @Mordante wrote:

> In D130419#3676654 , @aaron.ballman 
> wrote:
>
>> In D130419#3676643 , @fsb4000 
>> wrote:
>>
>>> drop the dummy file and update the release notes.
>>
>> Thanks! I forgot to ask -- do you need someone to commit on your behalf? If 
>> so, what name and email address would you like used for patch attribution?
>
> Thanks for asking. I just discussed with fsb4000 and I'll land it after 
> updating the backticks in the documentation.

Fantastic, thank you! And thank you @fsb4000 for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130419

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


[PATCH] D130419: Use `` with MSVC and C++

2022-07-25 Thread Igor Zhukov via Phabricator via cfe-commits
fsb4000 updated this revision to Diff 447388.
fsb4000 added a comment.

Thanks. I already asked Mark de Wever.

My name, email: Igor Zhukov 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130419

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/stdatomic.h


Index: clang/lib/Headers/stdatomic.h
===
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -17,7 +17,8 @@
  * explicitly disallows `stdatomic.h` in the C mode via an `#error`.  Fallback
  * to the clang resource header until that is fully supported.
  */
-#if __STDC_HOSTED__ && __has_include_next() && !defined(_MSC_VER)
+#if __STDC_HOSTED__ && 
\
+__has_include_next() && !(defined(_MSC_VER) && 
!defined(__cplusplus))
 # include_next 
 #else
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -196,6 +196,8 @@
   used in comparison operators. Fixes `Issue 56560 
`_.
 - Fix that ``if consteval`` could evaluate to ``true`` at runtime because it 
was incorrectly
   constant folded. Fixes `Issue 55638 
`_.
+- Fixed incompatibility of clang's  with MSVC .
+  Fixes `MSVC STL Issue 2862 `_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/lib/Headers/stdatomic.h
===
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -17,7 +17,8 @@
  * explicitly disallows `stdatomic.h` in the C mode via an `#error`.  Fallback
  * to the clang resource header until that is fully supported.
  */
-#if __STDC_HOSTED__ && __has_include_next() && !defined(_MSC_VER)
+#if __STDC_HOSTED__ && \
+__has_include_next() && !(defined(_MSC_VER) && !defined(__cplusplus))
 # include_next 
 #else
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -196,6 +196,8 @@
   used in comparison operators. Fixes `Issue 56560 `_.
 - Fix that ``if consteval`` could evaluate to ``true`` at runtime because it was incorrectly
   constant folded. Fixes `Issue 55638 `_.
+- Fixed incompatibility of clang's  with MSVC .
+  Fixes `MSVC STL Issue 2862 `_.
 
 Improvements to Clang's diagnostics
 ^^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ba49d39 - Use `` with MSVC and C++

2022-07-25 Thread Mark de Wever via cfe-commits

Author: Igor Zhukov
Date: 2022-07-25T19:00:29+02:00
New Revision: ba49d39b20cc5358da28af2ac82bd336028780bc

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

LOG: Use `` with MSVC and C++

and use fallback only for C.

It fixes the isssue with clang-cl:

```
#include 
#include 
#ifdef __cplusplus
#include 
using namespace std;
#endif

int main() {
atomic_bool b = true;
}
```

```
$ clang-cl /TC main.cpp
# works
```
```
$ clang-cl /TP /std:c++20 main.cpp

stdatomic.h(70,6): error: conflicting types for 'atomic_thread_fence'
void atomic_thread_fence(memory_order);
 ^
atomic(166,24): note: previous definition is here
extern "C" inline void atomic_thread_fence(const memory_order _Order) noexcept {

...

fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
```
Many errors but
`` has many macros to built-in functions.
```
#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
```
and MSVC `` has real functions.
and the built-in functions are redefined.

Reviewed By: #libc, aaron.ballman, Mordante

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Headers/stdatomic.h

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 317fd250b1933..ab2f6387492b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -196,6 +196,8 @@ Bug Fixes
   used in comparison operators. Fixes `Issue 56560 
`_.
 - Fix that ``if consteval`` could evaluate to ``true`` at runtime because it 
was incorrectly
   constant folded. Fixes `Issue 55638 
`_.
+- Fixed incompatibility of Clang's  with MSVC .
+  Fixes `MSVC STL Issue 2862 `_.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Headers/stdatomic.h b/clang/lib/Headers/stdatomic.h
index 3a0b9cc056bef..318c7ca56e418 100644
--- a/clang/lib/Headers/stdatomic.h
+++ b/clang/lib/Headers/stdatomic.h
@@ -17,7 +17,8 @@
  * explicitly disallows `stdatomic.h` in the C mode via an `#error`.  Fallback
  * to the clang resource header until that is fully supported.
  */
-#if __STDC_HOSTED__ && __has_include_next() && !defined(_MSC_VER)
+#if __STDC_HOSTED__ && 
\
+__has_include_next() && !(defined(_MSC_VER) && 
!defined(__cplusplus))
 # include_next 
 #else
 



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


[PATCH] D130419: Use `` with MSVC and C++

2022-07-25 Thread Mark de Wever 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 rGba49d39b20cc: Use `` with MSVC and C++ 
(authored by fsb4000, committed by Mordante).

Changed prior to commit:
  https://reviews.llvm.org/D130419?vs=447388&id=447390#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130419

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Headers/stdatomic.h


Index: clang/lib/Headers/stdatomic.h
===
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -17,7 +17,8 @@
  * explicitly disallows `stdatomic.h` in the C mode via an `#error`.  Fallback
  * to the clang resource header until that is fully supported.
  */
-#if __STDC_HOSTED__ && __has_include_next() && !defined(_MSC_VER)
+#if __STDC_HOSTED__ && 
\
+__has_include_next() && !(defined(_MSC_VER) && 
!defined(__cplusplus))
 # include_next 
 #else
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -196,6 +196,8 @@
   used in comparison operators. Fixes `Issue 56560 
`_.
 - Fix that ``if consteval`` could evaluate to ``true`` at runtime because it 
was incorrectly
   constant folded. Fixes `Issue 55638 
`_.
+- Fixed incompatibility of Clang's  with MSVC .
+  Fixes `MSVC STL Issue 2862 `_.
 
 Improvements to Clang's diagnostics
 ^^^


Index: clang/lib/Headers/stdatomic.h
===
--- clang/lib/Headers/stdatomic.h
+++ clang/lib/Headers/stdatomic.h
@@ -17,7 +17,8 @@
  * explicitly disallows `stdatomic.h` in the C mode via an `#error`.  Fallback
  * to the clang resource header until that is fully supported.
  */
-#if __STDC_HOSTED__ && __has_include_next() && !defined(_MSC_VER)
+#if __STDC_HOSTED__ && \
+__has_include_next() && !(defined(_MSC_VER) && !defined(__cplusplus))
 # include_next 
 #else
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -196,6 +196,8 @@
   used in comparison operators. Fixes `Issue 56560 `_.
 - Fix that ``if consteval`` could evaluate to ``true`` at runtime because it was incorrectly
   constant folded. Fixes `Issue 55638 `_.
+- Fixed incompatibility of Clang's  with MSVC .
+  Fixes `MSVC STL Issue 2862 `_.
 
 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] D130443: [CGDebugInfo] Access the current working directory from the `VFS`

2022-07-25 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 accepted this revision.
jansvoboda11 added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130443

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


[PATCH] D101070: [llvm][cmake] Make `install_symlink` workflow work with absolute install dirs

2022-07-25 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 447391.
Ericson2314 added a comment.

Oops! `ExtendPath` was not already imported


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/LLVMInstallSymlink.cmake


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -1,22 +1,26 @@
 # We need to execute this script at installation time because the
 # DESTDIR environment variable may be unset at configuration time.
 # See PR8397.
+#
+# `outdir` must be an absolute path. This module gets a very reduced
+# `CMAKE_MODULE_PATH` so it is easier to make the caller the responsible
+# for this.
 
 include(GNUInstallDirs)
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1,4 +1,5 @@
 include(GNUInstallDirs)
+include(ExtendPath)
 include(LLVMDistributionSupport)
 include(LLVMProcessSources)
 include(LLVM-Config)
@@ -1950,7 +1951,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" 
"PARAMS;DEPENDS;ARGS" ${ARGN})
-
+
 if (NOT ARG_FOLDER)
   set(ARG_FOLDER "Test Subdirectories")
 endif()
@@ -2006,11 +2007,14 @@
 
   set(output_dir lib${LLVM_LIBDIR_SUFFIX})
   if(WIN32 AND "${type}" STREQUAL "SHARED")
-set(output_dir bin)
+set(output_dir "${CMAKE_INSTALL_BINDIR}")
   endif()
 
+  # `install_symlink` needs an absoute path.
+  extend_path(output_dir "${CMAKE_INSTALL_PREFIX}" "${output_dir}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
 endfunction()
@@ -2045,8 +2049,11 @@
 set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
   endif()
 
+  # `install_symlink` needs an absoute path.
+  extend_path(output_dir "${CMAKE_INSTALL_PREFIX}" 
"${${project}_TOOLS_INSTALL_DIR}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} 
${${project}_TOOLS_INSTALL_DIR})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
   if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -1,22 +1,26 @@
 # We need to execute this script at installation time because the
 # DESTDIR environment variable may be unset at configuration time.
 # See PR8397.
+#
+# `outdir` must be an absolute path. This module gets a very reduced
+# `CMAKE_MODULE_PATH` so it is easier to make the caller the responsible
+# for this.
 
 include(GNUInstallDirs)
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1,4 +1,5 @@
 include(GNUInstallDirs)
+include(ExtendPath)
 include(LLVMDistributionSupport)
 include(LLVMProcessSources)
 include(LLVM-Config)
@@ -1950,7 +1951,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
 cmake_parse_arguments(ARG "EXCLUDE_FROM_CH

[PATCH] D129872: [clang][OpenMP] Fix runtime crash in the call to __kmp_alloc.

2022-07-25 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:16379
+// UnsignedPointerDiffType avoid truncate.
+AllocatorHT = Context.getUnsignedPointerDiffType();
+  Allocator = PerformImplicitConversion(Allocator.get(), AllocatorHT,

ABataev wrote:
> It must be int type, no?
unsigned int?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129872

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


  1   2   3   >