[PATCH] D134902: [clang] Implement -fstrict-flex-arrays=3

2022-10-05 Thread serge via Phabricator via cfe-commits
serge-sans-paille added inline comments.



Comment at: clang/test/CodeGen/bounds-checking-fam.c:2
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fstrict-flex-arrays=0 
-fsanitize=array-bounds%s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-0
-// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fstrict-flex-arrays=0 
-fsanitize=array-bounds -x c++ %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-0,CXX,CXX-STRICT-0
-// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fstrict-flex-arrays=1 
-fsanitize=array-bounds%s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-1
-// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fstrict-flex-arrays=1 
-fsanitize=array-bounds -x c++ %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-1,CXX
-// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fstrict-flex-arrays=2 
-fsanitize=array-bounds%s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-2
-// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fstrict-flex-arrays=2 
-fsanitize=array-bounds -x c++ %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-2,CXX
+// RUN: %clang_cc1 -O2 -emit-llvm -triple x86_64 -fstrict-flex-arrays=0 
-fsanitize=array-bounds%s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-0
+// RUN: %clang_cc1 -O2 -emit-llvm -triple x86_64 -fstrict-flex-arrays=0 
-fsanitize=array-bounds -x c++ %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-0,CXX,CXX-STRICT-0

Why adding -02 here?



Comment at: clang/test/CodeGen/object-size-flex-array.c:45
+  // CHECK-STRICT-2: ret i32 -1
+  // CHECK-STRICT-3: ret i32 0
   return OBJECT_SIZE_BUILTIN(f->c, 1);

This one worries me a bit, as an array of size 0 is invalid C, unless you 
consider the extension of it being a FAM. Shouldn't we emit a warning or 
something here? @kees what meaning would you give to that construct under 
`-fstrict-flex-arrays=3` ?



Comment at: clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp:14
 
 // Under -fstrict-flex-arrays={1,2} `a` is not a flexible array
 struct t0 {

update the comment here and below?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134902

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


[PATCH] D135107: [clang][NFC] Use enum for -fstrict-flex-arrays

2022-10-05 Thread serge via Phabricator via cfe-commits
serge-sans-paille accepted this revision.
serge-sans-paille added a comment.

Thanks for the cleanup!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135107

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


[clang] 7cbc920 - [clang-format][NFC] Clean up class HeaderIncludes and Format.cpp

2022-10-05 Thread via cfe-commits

Author: owenca
Date: 2022-10-05T21:54:40-07:00
New Revision: 7cbc9206697e2e7ce0ae2c671c80133327631e7f

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

LOG: [clang-format][NFC] Clean up class HeaderIncludes and Format.cpp

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

Added: 


Modified: 
clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
clang/lib/Format/Format.cpp
clang/lib/Tooling/Inclusions/HeaderIncludes.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Inclusions/HeaderIncludes.h 
b/clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
index ea8ad896be89f..ecc07995bc3a6 100644
--- a/clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
+++ b/clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
@@ -79,6 +79,9 @@ class HeaderIncludes {
   /// exactly the same spelling.
   tooling::Replacements remove(llvm::StringRef Header, bool IsAngled) const;
 
+  // Matches a whole #include directive.
+  static const llvm::Regex IncludeRegex;
+
 private:
   struct Include {
 Include(StringRef Name, tooling::Range R) : Name(Name), R(R) {}
@@ -124,9 +127,6 @@ class HeaderIncludes {
 
   // All possible priorities.
   std::set Priorities;
-
-  // Matches a whole #include directive.
-  llvm::Regex IncludeRegex;
 };
 
 } // namespace tooling

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 67f6818bb7e02..5731ffeec014d 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -2769,13 +2769,6 @@ static void sortCppIncludes(const FormatStyle ,
   }
 }
 
-namespace {
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
-} // anonymous namespace
-
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
   ArrayRef Ranges,
   StringRef FileName,
@@ -2785,7 +2778,6 @@ tooling::Replacements sortCppIncludes(const FormatStyle 
, StringRef Code,
   .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM
   .Default(0);
   unsigned SearchFrom = 0;
-  llvm::Regex IncludeRegex(CppIncludeRegexPattern);
   SmallVector Matches;
   SmallVector IncludesInBlock;
 
@@ -2842,7 +2834,7 @@ tooling::Replacements sortCppIncludes(const FormatStyle 
, StringRef Code,
 
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
-  if (IncludeRegex.match(Line, )) {
+  if (tooling::HeaderIncludes::IncludeRegex.match(Line, )) {
 StringRef IncludeName = Matches[2];
 if (Line.contains("/*") && !Line.contains("*/")) {
   // #include with a start of a block comment, but without the end.
@@ -3120,8 +3112,8 @@ namespace {
 
 inline bool isHeaderInsertion(const tooling::Replacement ) {
   return Replace.getOffset() == UINT_MAX && Replace.getLength() == 0 &&
- llvm::Regex(CppIncludeRegexPattern)
- .match(Replace.getReplacementText());
+ tooling::HeaderIncludes::IncludeRegex.match(
+ Replace.getReplacementText());
 }
 
 inline bool isHeaderDeletion(const tooling::Replacement ) {
@@ -3173,11 +3165,11 @@ fixCppIncludeInsertions(StringRef Code, const 
tooling::Replacements ,
 }
   }
 
-  llvm::Regex IncludeRegex = llvm::Regex(CppIncludeRegexPattern);
   llvm::SmallVector Matches;
   for (const auto  : HeaderInsertions) {
 auto IncludeDirective = R.getReplacementText();
-bool Matched = IncludeRegex.match(IncludeDirective, );
+bool Matched =
+tooling::HeaderIncludes::IncludeRegex.match(IncludeDirective, 
);
 assert(Matched && "Header insertion replacement must have replacement text 
"
   "'#include ...'");
 (void)Matched;

diff  --git a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp 
b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
index fc8773e60c581..4d68f0f674f13 100644
--- a/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ b/clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -266,6 +266,8 @@ bool IncludeCategoryManager::isMainHeader(StringRef 
IncludeName) const {
   return false;
 }
 
+const llvm::Regex HeaderIncludes::IncludeRegex(IncludeRegexPattern);
+
 HeaderIncludes::HeaderIncludes(StringRef FileName, StringRef Code,
const IncludeStyle )
 : FileName(FileName), Code(Code), FirstIncludeOffset(-1),
@@ -274,8 +276,7 @@ HeaderIncludes::HeaderIncludes(StringRef FileName, 
StringRef Code,
   MaxInsertOffset(MinInsertOffset +
   getMaxHeaderInsertionOffset(
   FileName, Code.drop_front(MinInsertOffset), Style)),
-  Categories(Style, FileName),
-  IncludeRegex(llvm::Regex(IncludeRegexPattern)) {
+  

[PATCH] D134852: [clang-format][NFC] Clean up class HeaderIncludes and Format.cpp

2022-10-05 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 rG7cbc9206697e: [clang-format][NFC] Clean up class 
HeaderIncludes and Format.cpp (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134852

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp

Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -266,6 +266,8 @@
   return false;
 }
 
+const llvm::Regex HeaderIncludes::IncludeRegex(IncludeRegexPattern);
+
 HeaderIncludes::HeaderIncludes(StringRef FileName, StringRef Code,
const IncludeStyle )
 : FileName(FileName), Code(Code), FirstIncludeOffset(-1),
@@ -274,8 +276,7 @@
   MaxInsertOffset(MinInsertOffset +
   getMaxHeaderInsertionOffset(
   FileName, Code.drop_front(MinInsertOffset), Style)),
-  Categories(Style, FileName),
-  IncludeRegex(llvm::Regex(IncludeRegexPattern)) {
+  Categories(Style, FileName) {
   // Add 0 for main header and INT_MAX for headers that are not in any
   // category.
   Priorities = {0, INT_MAX};
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2769,13 +2769,6 @@
   }
 }
 
-namespace {
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
-} // anonymous namespace
-
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
   ArrayRef Ranges,
   StringRef FileName,
@@ -2785,7 +2778,6 @@
   .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM
   .Default(0);
   unsigned SearchFrom = 0;
-  llvm::Regex IncludeRegex(CppIncludeRegexPattern);
   SmallVector Matches;
   SmallVector IncludesInBlock;
 
@@ -2842,7 +2834,7 @@
 
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
-  if (IncludeRegex.match(Line, )) {
+  if (tooling::HeaderIncludes::IncludeRegex.match(Line, )) {
 StringRef IncludeName = Matches[2];
 if (Line.contains("/*") && !Line.contains("*/")) {
   // #include with a start of a block comment, but without the end.
@@ -3120,8 +3112,8 @@
 
 inline bool isHeaderInsertion(const tooling::Replacement ) {
   return Replace.getOffset() == UINT_MAX && Replace.getLength() == 0 &&
- llvm::Regex(CppIncludeRegexPattern)
- .match(Replace.getReplacementText());
+ tooling::HeaderIncludes::IncludeRegex.match(
+ Replace.getReplacementText());
 }
 
 inline bool isHeaderDeletion(const tooling::Replacement ) {
@@ -3173,11 +3165,11 @@
 }
   }
 
-  llvm::Regex IncludeRegex = llvm::Regex(CppIncludeRegexPattern);
   llvm::SmallVector Matches;
   for (const auto  : HeaderInsertions) {
 auto IncludeDirective = R.getReplacementText();
-bool Matched = IncludeRegex.match(IncludeDirective, );
+bool Matched =
+tooling::HeaderIncludes::IncludeRegex.match(IncludeDirective, );
 assert(Matched && "Header insertion replacement must have replacement text "
   "'#include ...'");
 (void)Matched;
Index: clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
===
--- clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
+++ clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
@@ -79,6 +79,9 @@
   /// exactly the same spelling.
   tooling::Replacements remove(llvm::StringRef Header, bool IsAngled) const;
 
+  // Matches a whole #include directive.
+  static const llvm::Regex IncludeRegex;
+
 private:
   struct Include {
 Include(StringRef Name, tooling::Range R) : Name(Name), R(R) {}
@@ -124,9 +127,6 @@
 
   // All possible priorities.
   std::set Priorities;
-
-  // Matches a whole #include directive.
-  llvm::Regex IncludeRegex;
 };
 
 } // namespace tooling
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132855: [OpenMP] Extend the lit test for uses_allocators in target region

2022-10-05 Thread Animesh Kumar via Phabricator via cfe-commits
animeshk-amd added inline comments.



Comment at: clang/test/OpenMP/target_map_codegen_10.cpp:19
+// RUN: %clang_cc1 -no-opaque-pointers -DCK11 -fopenmp 
-fopenmp-targets=i386-pc-linux-gnu -x c++ -std=c++11 -triple 
i386-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -no-opaque-pointers -fopenmp 
-fopenmp-targets=i386-pc-linux-gnu -x c++ -triple i386-unknown-unknown 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
-allow-deprecated-dag-overlap  %s  --check-prefixes CK11,CK11_5
 

jdoerfert wrote:
> What does this test?
This test was originally testing the respective directives only for the OpenMP 
version 4.5. I have updated new RUN lines for the default version(5.0 as of 
now) because there were differences in the generated IR in case of the default 
version.



Comment at: clang/test/OpenMP/target_uses_allocators.c:42
+  #pragma omp target uses_allocators(omp_thread_mem_alloc) 
allocate(omp_thread_mem_alloc: x) firstprivate(x) // expected-warning 
{{allocator with the 'thread' trait access has unspecified behavior on 'target' 
directive}}
+  {}
 }

jdoerfert wrote:
> This should go into the _messages test case
The code needs to be tested for the generated IR(but as a side effect it also 
generates a warning), that's why I had to put the expected-warning clause. 
Since I had to write CHECK lines, I didn't put this in the _messages test. That 
said, should I still put this into the _messages test along with the required 
CHECK lines?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132855

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


[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-10-05 Thread Liming Liu via Phabricator via cfe-commits
lime updated this revision to Diff 465652.
lime added a comment.

Thanks for the advice. I used `AdjustConstraintDepth` before `subsume`. The 
adjusted constraints are assigned to new addresses, but I think 
`MutableArrayRef` could be used here.

> what do you mean by 'tailing' here?

I wanted to express the require clauses, as they are stored in `TrailingObject`.

> What exactly is going on here? I would expect the 'AdjustConstraintDepth' 
> work to have already made these basically equal.

`AdjustConstraintDepth` works here, but I missed it before you mentioned it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

Files:
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
  clang/test/SemaTemplate/concepts.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -912,11 +912,7 @@
 

 https://wg21.link/p0857r0;>P0857R0
-
-  Partial
-Constraining template template parameters is not yet supported.
-  
-
+Clang 16
   

 https://wg21.link/p1084r2;>P1084R2
Index: clang/test/SemaTemplate/concepts.cpp
===
--- clang/test/SemaTemplate/concepts.cpp
+++ clang/test/SemaTemplate/concepts.cpp
@@ -59,11 +59,10 @@
 x.operator()(); // expected-error {{no matching member function}}
   }
 
-  // FIXME: This is valid under P0857R0.
   template concept C = true;
-  template requires C typename U> struct X {}; // expected-error {{requires 'class'}} expected-error 0+{{}}
+  template requires C typename U> struct X {};
   template requires C struct Y {};
-  X xy; // expected-error {{no template named 'X'}}
+  X xy;
 }
 
 namespace PR50306 {
Index: clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
===
--- clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
+++ clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
@@ -1,22 +1,27 @@
 // RUN:  %clang_cc1 -std=c++2a -frelaxed-template-template-args -verify %s
 
-template concept C = T::f();
-// expected-note@-1{{similar constraint}}
+template concept C = T::f(); // #C
 template concept D = C && T::g();
-template concept F = T::f();
-// expected-note@-1{{similar constraint expressions not considered equivalent}}
-template class P> struct S1 { }; // expected-note 2{{'P' declared here}}
+template concept F = T::f(); // #F
+template class P> struct S1 { }; // #S1
 
 template struct X { };
-
-template struct Y { }; // expected-note{{'Y' declared here}}
+template struct Y { }; // #Y
 template struct Z { };
-template struct W { }; // expected-note{{'W' declared here}}
+template struct W { }; // #W
 
 S1 s11;
-S1 s12; // expected-error{{template template argument 'Y' is more constrained than template template parameter 'P'}}
+S1 s12;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
 S1 s13;
-S1 s14; // expected-error{{template template argument 'W' is more constrained than template template parameter 'P'}}
+S1 s14;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S1 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F {{similar constraint expressions not considered equivalent}}
+// expected-note@#C {{similar constraint}}
 
 template class P> struct S2 { };
 
@@ -32,3 +37,27 @@
 
 using s31 = S3;
 using s32 = S3;
+
+template requires C class P> struct S4 { }; // #S4
+
+S4 s41;
+S4 s42;
+// expected-error@-1 {{template template argument 'Y' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#Y {{'Y' declared here}}
+S4 s43;
+S4 s44;
+// expected-error@-1 {{template template argument 'W' is more constrained than template template parameter 'P'}}
+// expected-note@#S4 {{'P' declared here}}
+// expected-note@#W {{'W' declared here}}
+// expected-note@#F {{similar constraint expressions not considered equivalent}}
+// expected-note@#C {{similar constraint}}
+
+template requires C typename U> struct S5 {
+  template static U V;
+};
+
+struct Nothing {};
+
+// FIXME: Wait the standard to clarify the intent.
+template<> template<> Z S5::V;
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -610,6 +610,30 @@
 NewTL.setNameLoc(TL.getNameLoc());
 return Result;
   }
+
+  static auto 

[PATCH] D135107: [clang][NFC] Use enum for -fstrict-flex-arrays

2022-10-05 Thread Kees Cook via Phabricator via cfe-commits
kees accepted this revision.
kees added a comment.
This revision is now accepted and ready to land.

L


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135107

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


[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

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



Comment at: clang/lib/Lex/PPMacroExpansion.cpp:1092
+TT = *PP.getPreprocessorOpts().SourceDateEpoch;
+TM = std::gmtime();
+  } else {

ychen wrote:
> MaskRay wrote:
> > ychen wrote:
> > > MaskRay wrote:
> > > > ychen wrote:
> > > > > Why not use localtime as the else branch?
> > > > > 
> > > > > As mentioned above, diagnose null TM here or when parsing the 
> > > > > user-specifed value. A small trade-off to make, up to you.
> > > > Can you elaborate? With the check in Frontend I think a check here is 
> > > > not necessary...
> > > Sorry I was not clear. The time_t value is not portable so it is hard to 
> > > diagnose in a target-independent way. For example, `253402300799` is too 
> > > big of a value for windows that `gmtime` returns null (causes crash at 
> > > `asctime` in the similar case below). We could diagnose when 
> > > gmtime/localtime returns null, which is portable.
> > I am still confused. In practice, a 64-bit `gmtime` implementation may 
> > returns null when `tm_year` would overflow while 32-bit `gmtime` can't. The 
> > way (with a more restricted upper bound) we check SOURCE_DATE_EPOCH in 
> > Frontend, `std::gmtime();` cannot return null. `localtime()` for 
> > `time(nullptr)` may overflow as where but that is an pre-existing issue.
> > std::gmtime(); cannot return null
> 
> I couldn't find good references for this. But on windows, it may return null 
> (as the premerge CI shows). https://godbolt.org/z/jfxdG3KrM
Thanks:) This is interesting. So Windows gmtime returns null when the year 
number is slightly larger than 3000 (I do not find the exact date...)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

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


[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

2022-10-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 465649.
MaskRay marked an inline comment as done.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Use `??? ?? ` or `??:??:??` is gmtime/localtime returns null


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/Preprocessor/SOURCE_DATE_EPOCH.c

Index: clang/test/Preprocessor/SOURCE_DATE_EPOCH.c
===
--- /dev/null
+++ clang/test/Preprocessor/SOURCE_DATE_EPOCH.c
@@ -0,0 +1,32 @@
+// RUN: env SOURCE_DATE_EPOCH=0 %clang_cc1 -E %s | FileCheck %s --check-prefix=19700101
+
+// 19700101:  const char date[] = "Jan  1 1970";
+// 19700101-NEXT: const char time[] = "00:00:00";
+// 19700101-NEXT: const char timestamp[] = "Thu Jan  1 00:00:00 1970";
+
+// RUN: env SOURCE_DATE_EPOCH=2147483647 %clang_cc1 -E -Wdate-time %s 2>&1 | FileCheck %s --check-prefix=Y2038
+
+// Y2038:  warning: expansion of date or time macro is not reproducible [-Wdate-time]
+// Y2038:  const char date[] = "Jan 19 2038";
+// Y2038-NEXT: const char time[] = "03:14:07";
+// Y2038-NEXT: const char timestamp[] = "Tue Jan 19 03:14:07 2038";
+
+/// Some 32-bits systems have time64 problems.
+// RUN: %if clang-target-64-bits %{ env SOURCE_DATE_EPOCH=253402300799 %clang_cc1 -E -Wdate-time %s 2>&1 | FileCheck %s --check-prefix=1231 %}
+
+// 1231:  warning: expansion of date or time macro is not reproducible [-Wdate-time]
+// 1231:  const char date[] = "Dec 31 ";
+// 1231-NEXT: const char time[] = "23:59:59";
+// 1231-NEXT: const char timestamp[] = "Fri Dec 31 23:59:59 ";
+
+// RUN: env SOURCE_DATE_EPOCH=253402300800 not %clang_cc1 -E %s 2>&1 | FileCheck %s --check-prefix=TOOBIG
+
+// TOOBIG: error: environment variable 'SOURCE_DATE_EPOCH' ('253402300800') must be a non-negative decimal integer <= {{(2147483647|253402300799)}}
+
+// RUN: env SOURCE_DATE_EPOCH=0x0 not %clang_cc1 -E %s 2>&1 | FileCheck %s --check-prefix=NOTDECIMAL
+
+// NOTDECIMAL: error: environment variable 'SOURCE_DATE_EPOCH' ('0x0') must be a non-negative decimal integer <= {{(2147483647|253402300799)}}
+
+const char date[] = __DATE__;
+const char time[] = __TIME__;
+const char timestamp[] = __TIMESTAMP__;
Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1085,8 +1085,15 @@
 /// the identifier tokens inserted.
 static void ComputeDATE_TIME(SourceLocation , SourceLocation ,
  Preprocessor ) {
-  time_t TT = time(nullptr);
-  struct tm *TM = localtime();
+  time_t TT;
+  std::tm *TM;
+  if (PP.getPreprocessorOpts().SourceDateEpoch) {
+TT = *PP.getPreprocessorOpts().SourceDateEpoch;
+TM = std::gmtime();
+  } else {
+TT = std::time(nullptr);
+TM = std::localtime();
+  }
 
   static const char * const Months[] = {
 "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
@@ -1095,8 +1102,11 @@
   {
 SmallString<32> TmpBuffer;
 llvm::raw_svector_ostream TmpStream(TmpBuffer);
-TmpStream << llvm::format("\"%s %2d %4d\"", Months[TM->tm_mon],
-  TM->tm_mday, TM->tm_year + 1900);
+if (TM)
+  TmpStream << llvm::format("\"%s %2d %4d\"", Months[TM->tm_mon],
+TM->tm_mday, TM->tm_year + 1900);
+else
+  TmpStream << "??? ?? ";
 Token TmpTok;
 TmpTok.startToken();
 PP.CreateString(TmpStream.str(), TmpTok);
@@ -1106,8 +1116,11 @@
   {
 SmallString<32> TmpBuffer;
 llvm::raw_svector_ostream TmpStream(TmpBuffer);
-TmpStream << llvm::format("\"%02d:%02d:%02d\"",
-  TM->tm_hour, TM->tm_min, TM->tm_sec);
+if (TM)
+  TmpStream << llvm::format("\"%02d:%02d:%02d\"", TM->tm_hour, TM->tm_min,
+TM->tm_sec);
+else
+  TmpStream << "??:??:??";
 Token TmpTok;
 TmpTok.startToken();
 PP.CreateString(TmpStream.str(), TmpTok);
@@ -1593,22 +1606,24 @@
 Diag(Tok.getLocation(), diag::warn_pp_date_time);
 // MSVC, ICC, GCC, VisualAge C++ extension.  The generated string should be
 // of the form "Ddd Mmm dd hh::mm::ss ", which is returned by asctime.
-
-// Get the file that we are lexing out of.  If we're currently lexing from
-// a macro, dig into the include stack.
-const FileEntry *CurFile = nullptr;
-PreprocessorLexer *TheLexer = getCurrentFileLexer();
-
-if (TheLexer)
-  CurFile = SourceMgr.getFileEntryForID(TheLexer->getFileID());
-
 const char *Result;
-if (CurFile) {
-  time_t 

[PATCH] D134478: BareMetal: detect usr/include/c++/v1 path in sysroot

2022-10-05 Thread Manoj Gupta via Phabricator via cfe-commits
manojgupta updated this revision to Diff 465647.
manojgupta added a comment.

address comments and check CI.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134478

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/test/Driver/baremetal.cpp


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -72,6 +72,22 @@
 // CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-LIBCXX-SAME: "-o" "{{.*}}.o"
 
+// RUN: rm -rf %T/baremetal_cxx_sysroot
+// RUN: mkdir -p %T/baremetal_cxx_sysroot/usr/include/c++/v1
+// RUN: %clangxx %s -### 2>&1 \
+// RUN: --target=armv6m-none-eabi \
+// RUN: --sysroot=%T/baremetal_cxx_sysroot \
+// RUN: -stdlib=libc++ \
+// RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBCXX-USR %s
+// CHECK-V6M-LIBCXX-USR: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-V6M-LIBCXX-USR-NOT: "-internal-isystem" 
"{{[^"]+}}baremetal_cxx_sysroot{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}{{[^v].*}}"
+// CHECK-V6M-LIBCXX-USR-SAME: "-internal-isystem" 
"{{[^"]+}}baremetal_cxx_sysroot{{[/\\]+}}usr{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-V6M-LIBCXX-USR: "{{[^"]*}}-Bstatic"
+// CHECK-V6M-LIBCXX-USR-SAME: 
"-L{{[^"]*}}{{[/\\]+}}baremetal_cxx_sysroot{{[/\\]+}}lib"
+// CHECK-V6M-LIBCXX-USR-SAME: 
"-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-LIBCXX-USR-SAME: "-lc++" "-lc++abi" "-lunwind"
+// CHECK-V6M-LIBCXX-USR-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -217,12 +217,21 @@
   DriverArgs.hasArg(options::OPT_nostdincxx))
 return;
 
+  const Driver  = getDriver();
   std::string SysRoot(computeSysRoot());
   if (SysRoot.empty())
 return;
 
   switch (GetCXXStdlibType(DriverArgs)) {
   case ToolChain::CST_Libcxx: {
+// First check sysroot/usr/include/c++/v1 if it exists.
+SmallString<128> TargetDir(SysRoot);
+llvm::sys::path::append(TargetDir, "usr", "include", "c++", "v1");
+if (D.getVFS().exists(TargetDir)) {
+  addSystemInclude(DriverArgs, CC1Args, TargetDir.str());
+  break;
+}
+// Add generic path if nothing else succeeded so far.
 SmallString<128> Dir(SysRoot);
 llvm::sys::path::append(Dir, "include", "c++", "v1");
 addSystemInclude(DriverArgs, CC1Args, Dir.str());
@@ -234,9 +243,8 @@
 std::error_code EC;
 Generic_GCC::GCCVersion Version = {"", -1, -1, -1, "", "", ""};
 // Walk the subdirs, and find the one with the newest gcc version:
-for (llvm::vfs::directory_iterator
- LI = getDriver().getVFS().dir_begin(Dir.str(), EC),
- LE;
+for (llvm::vfs::directory_iterator LI = D.getVFS().dir_begin(Dir.str(), 
EC),
+   LE;
  !EC && LI != LE; LI = LI.increment(EC)) {
   StringRef VersionText = llvm::sys::path::filename(LI->path());
   auto CandidateVersion = Generic_GCC::GCCVersion::Parse(VersionText);


Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -72,6 +72,22 @@
 // CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
 // CHECK-V6M-LIBCXX-SAME: "-o" "{{.*}}.o"
 
+// RUN: rm -rf %T/baremetal_cxx_sysroot
+// RUN: mkdir -p %T/baremetal_cxx_sysroot/usr/include/c++/v1
+// RUN: %clangxx %s -### 2>&1 \
+// RUN: --target=armv6m-none-eabi \
+// RUN: --sysroot=%T/baremetal_cxx_sysroot \
+// RUN: -stdlib=libc++ \
+// RUN:   | FileCheck --check-prefix=CHECK-V6M-LIBCXX-USR %s
+// CHECK-V6M-LIBCXX-USR: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK-V6M-LIBCXX-USR-NOT: "-internal-isystem" "{{[^"]+}}baremetal_cxx_sysroot{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}{{[^v].*}}"
+// CHECK-V6M-LIBCXX-USR-SAME: "-internal-isystem" "{{[^"]+}}baremetal_cxx_sysroot{{[/\\]+}}usr{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
+// CHECK-V6M-LIBCXX-USR: "{{[^"]*}}-Bstatic"
+// CHECK-V6M-LIBCXX-USR-SAME: "-L{{[^"]*}}{{[/\\]+}}baremetal_cxx_sysroot{{[/\\]+}}lib"
+// CHECK-V6M-LIBCXX-USR-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
+// CHECK-V6M-LIBCXX-USR-SAME: "-lc++" "-lc++abi" "-lunwind"
+// CHECK-V6M-LIBCXX-USR-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m"
+
 // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -target armv6m-none-eabi \
 // RUN: --sysroot=%S/Inputs/baremetal_arm \
Index: clang/lib/Driver/ToolChains/BareMetal.cpp

[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

2022-10-05 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/Lex/PPMacroExpansion.cpp:1092
+TT = *PP.getPreprocessorOpts().SourceDateEpoch;
+TM = std::gmtime();
+  } else {

MaskRay wrote:
> ychen wrote:
> > MaskRay wrote:
> > > ychen wrote:
> > > > Why not use localtime as the else branch?
> > > > 
> > > > As mentioned above, diagnose null TM here or when parsing the 
> > > > user-specifed value. A small trade-off to make, up to you.
> > > Can you elaborate? With the check in Frontend I think a check here is not 
> > > necessary...
> > Sorry I was not clear. The time_t value is not portable so it is hard to 
> > diagnose in a target-independent way. For example, `253402300799` is too 
> > big of a value for windows that `gmtime` returns null (causes crash at 
> > `asctime` in the similar case below). We could diagnose when 
> > gmtime/localtime returns null, which is portable.
> I am still confused. In practice, a 64-bit `gmtime` implementation may 
> returns null when `tm_year` would overflow while 32-bit `gmtime` can't. The 
> way (with a more restricted upper bound) we check SOURCE_DATE_EPOCH in 
> Frontend, `std::gmtime();` cannot return null. `localtime()` for 
> `time(nullptr)` may overflow as where but that is an pre-existing issue.
> std::gmtime(); cannot return null

I couldn't find good references for this. But on windows, it may return null 
(as the premerge CI shows). https://godbolt.org/z/jfxdG3KrM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

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


[PATCH] D135341: [clang] adds `__reference_constructs_from_temporary` and `__reference_converts_from_temporary`

2022-10-05 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: aaron.ballman, shafik, erichkeane, tcanens.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Depends on D135339 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135341

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/type-traits.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1417,16 +1417,7 @@
 
   Type trait to determine if a reference binds to a temporary
   https://wg21.link/P2255R2;>P2255R2
-  
-Partial
-  Clang provides a __reference_binds_to_temporary type trait
-  builtin, with which the library facility can be partially implemented.
-  Both __reference_constructs_from_temporary and
-  __reference_converts_from_temporary builtins should be
-  provided, following the normal cross-vendor convention to implement
-  traits requiring compiler support directly.
-
-  
+  Clang 16
 
 
 
Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -4704,6 +4704,92 @@
   { int arr[T((__reference_binds_to_temporary(const int &, long)))]; }
 }
 
+void reference_constructs_from_temporary_checks() {
+  static_assert(!__reference_constructs_from_temporary(int &, int &), "");
+  static_assert(!__reference_constructs_from_temporary(int &, int &&), "");
+
+  static_assert(!__reference_constructs_from_temporary(int const &, int &), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, int const &), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, int &&), "");
+
+  static_assert(!__reference_constructs_from_temporary(int &, long &), ""); // doesn't construct
+
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_constructs_from_temporary(int const &, long &), "");
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_constructs_from_temporary(int const &, long &&), "");
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_constructs_from_temporary(int &&, long &), "");
+
+  using LRef = ConvertsToRef;
+  using RRef = ConvertsToRef;
+  using CLRef = ConvertsToRef;
+  using LongRef = ConvertsToRef;
+  static_assert(__is_constructible(int &, LRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &, LRef), "");
+
+  static_assert(__is_constructible(int &&, RRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &&, RRef), "");
+
+  static_assert(__is_constructible(int const &, CLRef), "");
+  static_assert(!__reference_constructs_from_temporary(int &&, CLRef), "");
+
+  static_assert(__is_constructible(int const &, LongRef), "");
+  static_assert(!__reference_constructs_from_temporary(int const &, LongRef), "");
+
+  // Test that it doesn't accept non-reference types as input.
+  static_assert(!__reference_constructs_from_temporary(int, long), "");
+
+  static_assert(!__reference_constructs_from_temporary(const int &, long), "");
+
+  // Additional checks
+  static_assert(__reference_constructs_from_temporary(int&&, int), "");
+  static_assert(__reference_constructs_from_temporary(POD const&, Derives), "");
+}
+
+void reference_converts_from_temporary_checks() {
+  static_assert(!__reference_converts_from_temporary(int &, int &), "");
+  static_assert(!__reference_converts_from_temporary(int &, int &&), "");
+
+  static_assert(!__reference_converts_from_temporary(int const &, int &), "");
+  static_assert(!__reference_converts_from_temporary(int const &, int const &), "");
+  static_assert(!__reference_converts_from_temporary(int const &, int &&), "");
+
+  static_assert(!__reference_converts_from_temporary(int &, long &), ""); // doesn't construct
+
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_converts_from_temporary(int const &, long &), "");
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_converts_from_temporary(int const &, long &&), "");
+  // Diverges from __reference_binds_to_temporary
+  static_assert(!__reference_converts_from_temporary(int &&, long &), "");
+
+  using LRef = ConvertsToRef;
+  using RRef = ConvertsToRef;
+  using CLRef = ConvertsToRef;
+  using LongRef = 

[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

2022-10-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay marked 2 inline comments as done.
MaskRay added inline comments.



Comment at: clang/lib/Lex/PPMacroExpansion.cpp:1092
+TT = *PP.getPreprocessorOpts().SourceDateEpoch;
+TM = std::gmtime();
+  } else {

ychen wrote:
> MaskRay wrote:
> > ychen wrote:
> > > Why not use localtime as the else branch?
> > > 
> > > As mentioned above, diagnose null TM here or when parsing the 
> > > user-specifed value. A small trade-off to make, up to you.
> > Can you elaborate? With the check in Frontend I think a check here is not 
> > necessary...
> Sorry I was not clear. The time_t value is not portable so it is hard to 
> diagnose in a target-independent way. For example, `253402300799` is too big 
> of a value for windows that `gmtime` returns null (causes crash at `asctime` 
> in the similar case below). We could diagnose when gmtime/localtime returns 
> null, which is portable.
I am still confused. In practice, a 64-bit `gmtime` implementation may returns 
null when `tm_year` would overflow while 32-bit `gmtime` can't. The way (with a 
more restricted upper bound) we check SOURCE_DATE_EPOCH in Frontend, 
`std::gmtime();` cannot return null. `localtime()` for `time(nullptr)` 
may overflow as where but that is an pre-existing issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

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


[PATCH] D135339: [clang] makes `__is_destructible` KEYCXX instead of KEYMS

2022-10-05 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: aaron.ballman, shafik, erichkeane.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This makes it possible to be used in all modes, instead of just when
`-fms-extensions` is enabled. Also moves the `-fms-extensions`-exclusive
traits into their own file so we can check the others aren't dependent
on this flag.

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

This was originally a part of D116280 .

Depends on D135338 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135339

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/TokenKinds.def
  clang/test/SemaCXX/type-traits-ms-extensions.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++1z -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++1z -fblocks -Wno-deprecated-builtins %s
 
 #define T(b) (b) ? 1 : -1
 #define F(b) (b) ? -1 : 1
@@ -406,23 +406,12 @@
 template<>
 struct PotentiallyFinal final { };
 
-struct SealedClass sealed {
-};
 
-template
-struct PotentiallySealed { };
 
-template
-struct PotentiallySealed sealed { };
 
-template<>
-struct PotentiallySealed sealed { };
 
 void is_final()
 {
-	{ int arr[T(__is_final(SealedClass))]; }
-	{ int arr[T(__is_final(PotentiallySealed))]; }
-	{ int arr[T(__is_final(PotentiallySealed))]; }
 	{ int arr[T(__is_final(FinalClass))]; }
 	{ int arr[T(__is_final(PotentiallyFinal))]; }
 	{ int arr[T(__is_final(PotentiallyFinal))]; }
@@ -437,32 +426,8 @@
 	{ int arr[F(__is_final(cvoid))]; }
 	{ int arr[F(__is_final(IntArNB))]; }
 	{ int arr[F(__is_final(HasAnonymousUnion))]; }
-	{ int arr[F(__is_final(PotentiallyFinal))]; }
-	{ int arr[F(__is_final(PotentiallySealed))]; }
 }
 
-void is_sealed()
-{
-	{ int arr[T(__is_sealed(SealedClass))]; }
-	{ int arr[T(__is_sealed(PotentiallySealed))]; }
-	{ int arr[T(__is_sealed(PotentiallySealed))]; }
-	{ int arr[T(__is_sealed(FinalClass))]; }
-	{ int arr[T(__is_sealed(PotentiallyFinal))]; }
-	{ int arr[T(__is_sealed(PotentiallyFinal))]; }
-
-	{ int arr[F(__is_sealed(int))]; }
-	{ int arr[F(__is_sealed(Union))]; }
-	{ int arr[F(__is_sealed(Int))]; }
-	{ int arr[F(__is_sealed(IntAr))]; }
-	{ int arr[F(__is_sealed(UnionAr))]; }
-	{ int arr[F(__is_sealed(Derives))]; }
-	{ int arr[F(__is_sealed(ClassType))]; }
-	{ int arr[F(__is_sealed(cvoid))]; }
-	{ int arr[F(__is_sealed(IntArNB))]; }
-	{ int arr[F(__is_sealed(HasAnonymousUnion))]; }
-	{ int arr[F(__is_sealed(PotentiallyFinal))]; }
-	{ int arr[F(__is_sealed(PotentiallySealed))]; }
-}
 
 typedef HasVirt Polymorph;
 struct InheritPolymorph : Polymorph {};
Index: clang/test/SemaCXX/type-traits-ms-extensions.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/type-traits-ms-extensions.cpp
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft %s -Wno-c++17-extensions
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft %s -Wno-c++17-extensions
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++1z -fblocks -Wno-deprecated-builtins -fms-extensions -Wno-microsoft %s
+
+// expected-no-diagnostics
+
+using Int = int;
+
+struct NonPOD { NonPOD(int); };
+enum Enum { EV };
+struct POD { Enum e; int i; float f; NonPOD* p; };
+struct Derives : POD {};
+using ClassType = Derives;
+
+union Union { int i; float f; };
+
+struct HasAnonymousUnion {
+  union {
+int i;
+float f;
+  };
+};
+
+struct FinalClass final {
+};
+
+template
+struct PotentiallyFinal { };
+
+template
+struct PotentiallyFinal final { };
+
+template<>
+struct PotentiallyFinal final { };
+
+struct SealedClass sealed {
+};
+

[PATCH] D135338: [clang] adds move-assignable type-trait builtins

2022-10-05 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: aaron.ballman, shafik, erichkeane.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- `__is_move_assignable`
- `__is_nothrow_move_assignable`
- `__is_trivially_move_assignable`

This is information that the compiler already has, and should be exposed
so that the library doesn't need to reimplement the exact same
functionality.

Similarly to `__is_move_construcitble`, etc., these traits can't be
implemented using `__is_assignable`, etc., because we can't form
references to void, and references are a fundamental part of move
assignment.

This was originally a part of D116280 .

Depends on D135240 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135338

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/deprecated-builtins.cpp
  clang/test/SemaCXX/type-traits.cpp

Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -3937,6 +3937,732 @@
   static_assert(!__is_trivially_copy_assignable(const volatile CVCopyAssign_QualCV), "");
 }
 
+struct MoveAssign_QualNone {
+  MoveAssign_QualNone =(MoveAssign_QualNone &&);
+};
+struct MoveAssign_QualConst {
+  MoveAssign_QualConst =(MoveAssign_QualConst &&) const;
+};
+struct MoveAssign_QualVolatile {
+  MoveAssign_QualVolatile =(MoveAssign_QualVolatile &&) volatile;
+};
+struct MoveAssign_QualCV {
+  MoveAssign_QualCV =(MoveAssign_QualCV &&) const volatile;
+};
+struct MoveAssign_QualLvalue {
+  MoveAssign_QualLvalue =(MoveAssign_QualLvalue &&) &;
+};
+struct MoveAssign_QualConstLvalue {
+  MoveAssign_QualConstLvalue =(MoveAssign_QualConstLvalue &&) const &;
+};
+struct MoveAssign_QualVolatileLvalue {
+  MoveAssign_QualVolatileLvalue =(MoveAssign_QualVolatileLvalue &&) volatile &;
+};
+struct MoveAssign_QualCVLvalue {
+  MoveAssign_QualCVLvalue =(MoveAssign_QualCVLvalue &&) const volatile &;
+};
+struct MoveAssign_QualRvalue {
+  MoveAssign_QualRvalue =(MoveAssign_QualRvalue &&) &&;
+};
+struct MoveAssign_QualConstRvalue {
+  MoveAssign_QualConstRvalue =(MoveAssign_QualConstRvalue &&) const &&;
+};
+struct MoveAssign_QualVolatileRvalue {
+  MoveAssign_QualVolatileRvalue =(MoveAssign_QualVolatileRvalue &&) volatile &&;
+};
+struct MoveAssign_QualCVRvalue {
+  MoveAssign_QualCVRvalue =(MoveAssign_QualCVRvalue &&) const volatile &&;
+};
+
+struct ConstMoveAssign_QualNone {
+  ConstMoveAssign_QualNone =(const ConstMoveAssign_QualNone &&);
+};
+struct ConstMoveAssign_QualConst {
+  ConstMoveAssign_QualConst =(const ConstMoveAssign_QualConst &&) const;
+};
+struct ConstMoveAssign_QualVolatile {
+  ConstMoveAssign_QualVolatile =(const ConstMoveAssign_QualVolatile &&) volatile;
+};
+struct ConstMoveAssign_QualCV {
+  ConstMoveAssign_QualCV =(const ConstMoveAssign_QualCV &&) const volatile;
+};
+struct ConstMoveAssign_QualLvalue {
+  ConstMoveAssign_QualLvalue =(const ConstMoveAssign_QualLvalue &&) &;
+};
+struct ConstMoveAssign_QualConstLvalue {
+  ConstMoveAssign_QualConstLvalue =(const ConstMoveAssign_QualConstLvalue &&) const &;
+};
+struct ConstMoveAssign_QualVolatileLvalue {
+  ConstMoveAssign_QualVolatileLvalue =(const ConstMoveAssign_QualVolatileLvalue &&) volatile &;
+};
+struct ConstMoveAssign_QualCVLvalue {
+  ConstMoveAssign_QualCVLvalue =(const ConstMoveAssign_QualCVLvalue &&) const volatile &;
+};
+struct ConstMoveAssign_QualRvalue {
+  ConstMoveAssign_QualRvalue =(const ConstMoveAssign_QualRvalue &&) &&;
+};
+struct ConstMoveAssign_QualConstRvalue {
+  ConstMoveAssign_QualConstRvalue =(const ConstMoveAssign_QualConstRvalue &&) const &&;
+};
+struct ConstMoveAssign_QualVolatileRvalue {
+  ConstMoveAssign_QualVolatileRvalue =(const ConstMoveAssign_QualVolatileRvalue &&) volatile &&;
+};
+struct ConstMoveAssign_QualCVRvalue {
+  ConstMoveAssign_QualCVRvalue =(const ConstMoveAssign_QualCVRvalue &&) const volatile &&;
+};
+
+struct VolatileMoveAssign_QualNone {
+  VolatileMoveAssign_QualNone =(volatile VolatileMoveAssign_QualNone &&);
+};
+struct VolatileMoveAssign_QualConst {
+  VolatileMoveAssign_QualConst =(volatile VolatileMoveAssign_QualConst &&) const;
+};
+struct VolatileMoveAssign_QualVolatile {
+  VolatileMoveAssign_QualVolatile =(volatile VolatileMoveAssign_QualVolatile &&) volatile;
+};
+struct VolatileMoveAssign_QualCV {
+  VolatileMoveAssign_QualCV =(volatile VolatileMoveAssign_QualCV &&) const volatile;
+};
+struct VolatileMoveAssign_QualLvalue {
+  VolatileMoveAssign_QualLvalue =(volatile VolatileMoveAssign_QualLvalue &&) &;
+};
+struct VolatileMoveAssign_QualConstLvalue {
+  VolatileMoveAssign_QualConstLvalue =(volatile VolatileMoveAssign_QualConstLvalue &&) const &;
+};

[PATCH] D135060: [HLSL] Add groupshare address space.

2022-10-05 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 465628.
python3kgae added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135060

Files:
  clang/include/clang/Basic/AddressSpaces.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Basic/Targets/NVPTX.h
  clang/lib/Basic/Targets/SPIR.h
  clang/lib/Basic/Targets/TCE.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/HLSL/group_shared.hlsl
  clang/test/CodeGenHLSL/group_shared.hlsl
  clang/test/SemaHLSL/group_shared.hlsl

Index: clang/test/SemaHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/group_shared.hlsl
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -o - -fsyntax-only %s -verify
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+   // expected-error@+1 {{automatic variable qualified with an address space}}
+   groupshared float b;
+ }
+
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+ groupshared float foo() {
+  static groupshared float foo0;
+return 1;
+ }
+// expected-error@+1 {{function return type may not be qualified with an address space}}
+  groupshared void bar() {
+extern groupshared float bar0;
+  }
+ 
+  struct S {
+// expected-error@+1 {{field may not be qualified with an address space}}
+groupshared float f;
+static groupshared float g;
+  };
+
+  // expected-error@+1 {{parameter may not be qualified with an address space}}
+  float foo2(groupshared float a) {
+return a;
+  }
+
+// expected-note@+2 {{parameter may not be qualified with an address space}}
+template
+  T tfoo(T t) {
+ return t;
+  }
+  // expected-warning@+1 {{alias declarations are a C++11 extension}}
+ using GSF = groupshared float;
+ GSF gs;
+ // expected-error@+1 {{no matching function for call to 'tfoo'}}
+ GSF gs2 = tfoo(gs);
Index: clang/test/CodeGenHLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/group_shared.hlsl
@@ -0,0 +1,15 @@
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// Make sure groupshared translated into address space 3.
+// CHECK:@"?a@@3PAMA" = addrspace(3) global [10 x float]
+
+ groupshared float a[10];
+
+ [numthreads(8,8,1)]
+ void main() {
+   a[0] = 1;
+ }
+ 
\ No newline at end of file
Index: clang/test/AST/HLSL/group_shared.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/group_shared.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s | FileCheck %s
+
+//CHECK:VarDecl 0x[[A:[0-9a-f]+]] <{{.*}} col:24> col:20 used a 'groupshared float[10]'
+ groupshared float a[10];
+
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}} <{{.*}}> line:[[@LINE+2]]:7 main 'void ()'
+ [numthreads(8,8,1)]
+ void main() {
+// CHECK:BinaryOperator 0x{{[0-9a-f]+}} <{{.*}}> 'groupshared float' lvalue '='
+// CHECK:ArraySubscriptExpr 0x{{[0-9a-f]+}}  'groupshared float' lvalue
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'groupshared float *' 
+// CHECK:DeclRefExpr 0x{{[0-9a-f]+}}  'groupshared float[10]' lvalue Var 0x[[A]] 'a' 'groupshared float[10]'
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 0
+// CHECK:ImplicitCastExpr 0x{{[0-9a-f]+}}  'float' 
+// CHECK:IntegerLiteral 0x{{[0-9a-f]+}}  'int' 1
+   a[0] = 1;
+ }
+
+
+// CHECK:HLSLNumThreadsAttr 0x{{[0-9a-f]+}} <{{.*}}> 8 8 1
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -2898,6 +2898,8 @@
   if (T.isVolatileQualified() && getLangOpts().CPlusPlus20)
 Diag(Loc, diag::warn_deprecated_volatile_return) << T;
 
+  if (T.getAddressSpace() != LangAS::Default && getLangOpts().HLSL)
+return true;
   return false;
 }
 
@@ -6775,6 +6777,8 @@
 // The keyword-based type attributes imply which address space to use.
 ASIdx = S.getLangOpts().SYCLIsDevice ? Attr.asSYCLLangAS()
  : Attr.asOpenCLLangAS();
+if (S.getLangOpts().HLSL)
+  ASIdx = Attr.asHLSLLangAS();
 
 if (ASIdx == LangAS::Default)
   

[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

2022-10-05 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/Lex/PPMacroExpansion.cpp:1092
+TT = *PP.getPreprocessorOpts().SourceDateEpoch;
+TM = std::gmtime();
+  } else {

MaskRay wrote:
> ychen wrote:
> > Why not use localtime as the else branch?
> > 
> > As mentioned above, diagnose null TM here or when parsing the user-specifed 
> > value. A small trade-off to make, up to you.
> Can you elaborate? With the check in Frontend I think a check here is not 
> necessary...
Sorry I was not clear. The time_t value is not portable so it is hard to 
diagnose in a target-independent way. For example, `253402300799` is too big of 
a value for windows that `gmtime` returns null (causes crash at `asctime` in 
the similar case below). We could diagnose when gmtime/localtime returns null, 
which is portable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

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


[PATCH] D135305: [Clang] Fix using LTO with the new driver in RDC-mode

2022-10-05 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/test/Driver/hip-phases.hip:553
+//
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver 
-ccc-print-phases \
+// RUN:--offload-arch=gfx90a --offload-arch=gfx908 -foffload-lto 
-fgpu-rdc -c %s 2>&1 \

yaxunl wrote:
> do we need a test for -foffload-lto -fno-gpu-rdc ?
The test above still uses the bindings, all the matters for that one is that 
the jobs generated are legal and still the same.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135305

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


[PATCH] D135269: [AMDGPU] Disable bool range metadata to workaround backend issue

2022-10-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked an inline comment as done.
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:1792
 // attach range metadata to the load.
-  } else if (CGM.getCodeGenOpts().OptimizationLevel > 0)
+// TODO: Enable range metadata for AMDGCN after backend issue is fixed.
+  } else if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&

tra wrote:
> It would be great to open a github issue, if we don't have one yet, and 
> reference it here, so we can tell later what exactly it is we're working 
> around here and know for sure when/whether we can undo the change.
opened github issue:

https://github.com/llvm/llvm-project/issues/58176

will update the comments


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

https://reviews.llvm.org/D135269

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


[PATCH] D135335: [HLSL] Add Resource kind for HLSLResourceAttr.

2022-10-05 Thread Xiang Li via Phabricator via cfe-commits
python3kgae created this revision.
python3kgae added reviewers: beanz, pow2clk, bogner.
Herald added a reviewer: aaron.ballman.
Herald added a subscriber: Anastasia.
Herald added a project: All.
python3kgae requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

A new EnumArgument ResourceKind is added for HLSLResourceAttr.
This will be use to get resource kind instead of parse it from the type name.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135335

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/test/AST/HLSL/RWBuffer-AST.hlsl


Index: clang/test/AST/HLSL/RWBuffer-AST.hlsl
===
--- clang/test/AST/HLSL/RWBuffer-AST.hlsl
+++ clang/test/AST/HLSL/RWBuffer-AST.hlsl
@@ -38,7 +38,7 @@
 // CHECK-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit class RWBuffer definition
 
 // CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
-// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
UAV
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
UAV TypedBuffer
 // CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit h 'element_type *'
 
 // CHECK: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'element_type  (unsigned int) const'
@@ -66,5 +66,5 @@
 // CHECK: TemplateArgument type 'float'
 // CHECK-NEXT: BuiltinType 0x{{[0-9A-Fa-f]+}} 'float'
 // CHECK-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
-// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
UAV
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
UAV TypedBuffer
 // CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>   
implicit referenced h 'float *'
Index: clang/lib/Sema/HLSLExternalSemaSource.cpp
===
--- clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -116,11 +116,12 @@
   }
 
   BuiltinTypeDeclBuilder &
-  annotateResourceClass(HLSLResourceAttr::ResourceClass RC) {
+  annotateResourceClass(HLSLResourceAttr::ResourceClass RC,
+HLSLResourceAttr::ResourceKind RK) {
 if (Record->isCompleteDefinition())
   return *this;
 Record->addAttr(
-HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RC));
+HLSLResourceAttr::CreateImplicit(Record->getASTContext(), RC, RK));
 return *this;
   }
 
@@ -501,6 +502,7 @@
   .addHandleMember()
   .addDefaultHandleConstructor(*SemaPtr, ResourceClass::UAV)
   .addArraySubscriptOperators()
-  .annotateResourceClass(HLSLResourceAttr::UAV)
+  .annotateResourceClass(HLSLResourceAttr::UAV,
+ HLSLResourceAttr::TypedBuffer)
   .completeDefinition();
 }
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -4037,7 +4037,24 @@
   let Args = [EnumArgument<"ResourceType", "ResourceClass",
["SRV", "UAV", "CBuffer", "Sampler"],
["SRV", "UAV", "CBuffer", "Sampler"]
-   >];
+   >,
+  EnumArgument<"ResourceShape", "ResourceKind",
+   ["Texture1D", "Texture2D", "Texture2DMS",
+"Texture3D", "TextureCube", "Texture1DArray",
+"Texture2DArray", "Texture2DMSArray",
+"TextureCubeArray", "TypedBuffer", "RawBuffer",
+"StructuredBuffer", "CBufferKind", "SamplerKind",
+"TBuffer", "RTAccelerationStructure", 
"FeedbackTexture2D",
+"FeedbackTexture2DArray"],
+   ["Texture1D", "Texture2D", "Texture2DMS",
+"Texture3D", "TextureCube", "Texture1DArray",
+"Texture2DArray", "Texture2DMSArray",
+"TextureCubeArray", "TypedBuffer", "RawBuffer",
+"StructuredBuffer", "CBufferKind", "SamplerKind",
+"TBuffer", "RTAccelerationStructure", 
"FeedbackTexture2D",
+"FeedbackTexture2DArray"]
+>
+  ];
   let Documentation = [InternalOnly];
 }
 


Index: clang/test/AST/HLSL/RWBuffer-AST.hlsl
===
--- clang/test/AST/HLSL/RWBuffer-AST.hlsl
+++ clang/test/AST/HLSL/RWBuffer-AST.hlsl
@@ -38,7 +38,7 @@
 // CHECK-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit class RWBuffer definition
 
 // CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
-// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit UAV
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit UAV TypedBuffer
 // CHECK-NEXT: 

[PATCH] D135287: Disallow dereferencing of void* in C++.

2022-10-05 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision as: shafik.
shafik added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/docs/ReleaseNotes.rst:92
+  error so constraint checking and SFINAE checking can be compatible with other
+  compilers. It is likely that this will be made a perminent error in Clang 17.
+




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

https://reviews.llvm.org/D135287

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


[PATCH] D135306: [CUDA] Add support for CUDA-11.8 and sm_{87,89,90} GPUs.

2022-10-05 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:30-32
+#define SM_89 "sm_87|" SM_90
+#define SM_87 "sm_89|" SM_89
+#define SM_86 "sm_89|" SM_87

yaxunl wrote:
> typo?
Good catch. Fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135306

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


[PATCH] D135306: [CUDA] Add support for CUDA-11.8 and sm_{87,89,90} GPUs.

2022-10-05 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 465612.
tra added a comment.

fixed typos.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135306

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  llvm/lib/Target/NVPTX/NVPTX.td

Index: llvm/lib/Target/NVPTX/NVPTX.td
===
--- llvm/lib/Target/NVPTX/NVPTX.td
+++ llvm/lib/Target/NVPTX/NVPTX.td
@@ -59,6 +59,12 @@
  "Target SM 8.0">;
 def SM86 : SubtargetFeature<"sm_86", "SmVersion", "86",
  "Target SM 8.6">;
+def SM87 : SubtargetFeature<"sm_87", "SmVersion", "87",
+ "Target SM 8.7">;
+def SM89 : SubtargetFeature<"sm_89", "SmVersion", "89",
+ "Target SM 8.9">;
+def SM90 : SubtargetFeature<"sm_90", "SmVersion", "90",
+ "Target SM 9.0">;
 
 // PTX Versions
 def PTX32 : SubtargetFeature<"ptx32", "PTXVersion", "32",
@@ -95,6 +101,12 @@
  "Use PTX version 7.4">;
 def PTX75 : SubtargetFeature<"ptx75", "PTXVersion", "75",
  "Use PTX version 7.5">;
+def PTX76 : SubtargetFeature<"ptx76", "PTXVersion", "76",
+ "Use PTX version 7.6">;
+def PTX77 : SubtargetFeature<"ptx77", "PTXVersion", "77",
+ "Use PTX version 7.7">;
+def PTX78 : SubtargetFeature<"ptx78", "PTXVersion", "78",
+ "Use PTX version 7.8">;
 
 //===--===//
 // NVPTX supported processors.
@@ -120,6 +132,9 @@
 def : Proc<"sm_75", [SM75, PTX63]>;
 def : Proc<"sm_80", [SM80, PTX70]>;
 def : Proc<"sm_86", [SM86, PTX71]>;
+def : Proc<"sm_87", [SM87, PTX74]>;
+def : Proc<"sm_89", [SM89, PTX78]>;
+def : Proc<"sm_90", [SM90, PTX78]>;
 
 def NVPTXInstrInfo : InstrInfo {
 }
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -67,6 +67,12 @@
 return CudaVersion::CUDA_114;
   if (raw_version < 11060)
 return CudaVersion::CUDA_115;
+  if (raw_version < 11070)
+return CudaVersion::CUDA_116;
+  if (raw_version < 11080)
+return CudaVersion::CUDA_117;
+  if (raw_version < 11090)
+return CudaVersion::CUDA_118;
   return CudaVersion::NEW;
 }
 
@@ -572,6 +578,9 @@
   case CudaVersion::CUDA_##CUDA_VER:   \
 PtxFeature = "+ptx" #PTX_VER;  \
 break;
+CASE_CUDA_VERSION(118, 78);
+CASE_CUDA_VERSION(117, 77);
+CASE_CUDA_VERSION(116, 76);
 CASE_CUDA_VERSION(115, 75);
 CASE_CUDA_VERSION(114, 74);
 CASE_CUDA_VERSION(113, 73);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3634,6 +3634,9 @@
   case CudaArch::SM_75:
   case CudaArch::SM_80:
   case CudaArch::SM_86:
+  case CudaArch::SM_87:
+  case CudaArch::SM_89:
+  case CudaArch::SM_90:
   case CudaArch::GFX600:
   case CudaArch::GFX601:
   case CudaArch::GFX602:
Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -246,6 +246,12 @@
 return "800";
   case CudaArch::SM_86:
 return "860";
+  case CudaArch::SM_87:
+return "870";
+  case CudaArch::SM_89:
+return "890";
+  case CudaArch::SM_90:
+return "900";
   }
   llvm_unreachable("unhandled CudaArch");
 }();
Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -34,6 +34,9 @@
 CUDA_ENTRY(11, 3),
 CUDA_ENTRY(11, 4),
 CUDA_ENTRY(11, 5),
+CUDA_ENTRY(11, 6),
+CUDA_ENTRY(11, 7),
+CUDA_ENTRY(11, 8),
 {"", CudaVersion::NEW, std::numeric_limits::max()},
 {"unknown", CudaVersion::UNKNOWN, 0} // End of list tombstone.
 };
@@ -86,6 +89,9 @@
 SM(70), SM(72),  // Volta
 SM(75),  // Turing
 SM(80), SM(86),  // Ampere
+SM(87),  // Jetson/Drive AGX Orin
+SM(89),  // Ada Lovelace
+SM(90),  // Hopper
 GFX(600),  // gfx600
 GFX(601),  // gfx601
 GFX(602),  // gfx602
@@ -191,6 +197,11 @@
 return 

[PATCH] D135328: [CUDA] Refactored CUDA version housekeeping to use less boilerplate.

2022-10-05 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Basic/Cuda.cpp:59
+CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
+  int IVer = Version.getMajor() * 10 + Version.getMinor().value_or(0);
+  for (auto *I = CudaNameVersionMap; I->Version != CudaVersion::UNKNOWN; ++I)

yaxunl wrote:
> should we assert Version.getMinor().value_or(0)<10 ?
It's not an immediate issue, but you are correct that we may potentially have 
CUDA 12.34 and that will mess up the integer version encoding. 

In fact, NVIDIA hit exactly this kind of problem in CUDA-11.7 when they had to 
version some of the libraries as 11.10 and had to change the binary 
representation and break existing ABIs. Here we're only dealing with internal 
use, but I'll update the encoding to give us more wiggle room.



Comment at: clang/lib/Basic/Targets/NVPTX.cpp:45-46
+int PTXV;
+if (!Feature.startswith("+ptx") ||
+Feature.drop_front(4).getAsInteger(10, PTXV))
   continue;

yaxunl wrote:
> This behaves differently when seeing a +ptx value not listed in the original 
> code. Previously, it returns 32, now it will just return that value. Is this 
> intended?
Indeed, previously it would set PTXVersion=32 if the specific ptx feature was 
not listed. I believe it was a bug as it would clobber correctly parsed 
features before it.

Right now we will only update PTXVersion, if we did manage to parse the 
feature. The code looks a bit misleading. `getAsInteger()` returns `true` on 
failure and when that happens, we hit `continue` w/o setting PTXVersion.

I was considering erroring out here, but that would be a problem if we were to 
have another feature starting with `+ptx`.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135328

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


[PATCH] D135306: [CUDA] Add support for CUDA-11.8 and sm_{87,89,90} GPUs.

2022-10-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/include/clang/Basic/BuiltinsNVPTX.def:30-32
+#define SM_89 "sm_87|" SM_90
+#define SM_87 "sm_89|" SM_89
+#define SM_86 "sm_89|" SM_87

typo?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135306

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


[PATCH] D135305: [Clang] Fix using LTO with the new driver in RDC-mode

2022-10-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/test/Driver/hip-phases.hip:553
+//
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver 
-ccc-print-phases \
+// RUN:--offload-arch=gfx90a --offload-arch=gfx908 -foffload-lto 
-fgpu-rdc -c %s 2>&1 \

do we need a test for -foffload-lto -fno-gpu-rdc ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135305

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


[PATCH] D135170: [LLDB] Fix crash when printing a struct with a static signed char member

2022-10-05 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik added a comment.

LGTM




Comment at: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp:39
 
   const static auto char_min = std::numeric_limits::min();
   const static auto uchar_min = std::numeric_limits::min();

We use `signed char` for the max case but `char` for the min case. Maybe we 
need a max using `char` and a min using `signed char`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135170

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


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

2022-10-05 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 465606.
ayzhao added a comment.

implement union support

Unions actually work as-is - the only thing I had to do was to cap the number 
of parameters at 1

Also add some tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Sema/Initialization.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprCXX.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/CodeGen/P0960R3.cpp
  clang/test/SemaCXX/P0960R3.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp

Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify -Wno-c++2a-extensions
-// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only %s -verify=expected,pre20 -Wno-c++2a-extensions
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify=expected,pro20
 
 template  struct enable_ifv {};
 
@@ -20,7 +20,7 @@
 
 template
 struct A {
-// expected-note@-1+ {{candidate constructor}}
+// pre20-note@-1+ {{candidate constructor}}
   explicit(1 << a)
 // expected-note@-1 {{negative shift count -1}}
 // expected-error@-2 {{explicit specifier argument is not a constant expression}}
@@ -28,8 +28,9 @@
 };
 
 A<-1> a(0);
-// expected-error@-1 {{no matching constructor}}
-// expected-note@-2 {{in instantiation of template class}}
+// pre20-error@-1 {{no matching constructor}}
+// pro20-error@-2 {{excess elements in struct initializer}}
+// expected-note@-3 {{in instantiation of template class}}
 
 template
 struct B {
Index: clang/test/SemaCXX/P0960R3.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/P0960R3.cpp
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s -fsyntax-only
+
+struct A { // expected-note 4{{candidate constructor}}
+  char i;
+  double j;
+};
+
+struct B {
+  A a;
+  int b[20];
+  int & // expected-note {{reference member declared here}}
+};
+
+struct C { // expected-note 2{{candidate constructor}}
+  A a;
+  int b[20];
+};
+
+struct D : public C, public A {
+  int a;
+};
+
+union U {
+  int a;
+  char* b;
+};
+
+void foo() {
+  A a(1954, 9, 21);
+  // expected-error@-1 {{excess elements in struct initializer}}
+  A b(2.1);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A e(-1.2, 9.8);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A s = static_cast(1.1);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A h = (A)3.1;
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+  A i = A(8.7);
+  // expected-warning@-1 {{implicit conversion from 'double' to 'char'}}
+
+  B n(2022, {7, 8});
+  // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
+  B z(A(1), {}, 1);
+  // expected-error@-1 {{reference member 'c' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}}
+
+  C o(A(1), 1, 2, 3, 4);
+  // expected-error@-1 {{excess elements in struct initializer}}
+  D R(1);
+  // expected-error@-1 {{no viable conversion from 'int' to 'C'}}
+  D I(C(1));
+  // expected-error@-1 {{functional-style cast from 'int' to 'C' is not allowed}}
+  D P(C(A(1)), 1);
+  // expected-error@-1 {{no viable conversion from 'int' to 'A'}}
+
+  int arr1[](0, 1, 2, A(1));
+  // expected-error@-1 {{no viable conversion from 'A' to 'int'}}
+  int arr2[2](0, 1, 2);
+  // expected-error@-1 {{excess elements in array initializer}}
+
+  U u1("abcd");
+  // expected-error@-1 {{cannot initialize a member subobject of type 'int' with an lvalue of type 'const char[5]'}}
+  U u2(1, "efgh");
+  // expected-error@-1 {{excess elements in union initializer}}
+}
Index: clang/test/CodeGen/P0960R3.cpp
===
--- /dev/null
+++ clang/test/CodeGen/P0960R3.cpp
@@ -0,0 +1,81 @@
+// RUN: %clang_cc1 -std=c++20 

[PATCH] D135328: [CUDA] Refactored CUDA version housekeeping to use less boilerplate.

2022-10-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Basic/Cuda.cpp:59
+CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
+  int IVer = Version.getMajor() * 10 + Version.getMinor().value_or(0);
+  for (auto *I = CudaNameVersionMap; I->Version != CudaVersion::UNKNOWN; ++I)

should we assert Version.getMinor().value_or(0)<10 ?



Comment at: clang/lib/Basic/Targets/NVPTX.cpp:45-46
+int PTXV;
+if (!Feature.startswith("+ptx") ||
+Feature.drop_front(4).getAsInteger(10, PTXV))
   continue;

This behaves differently when seeing a +ptx value not listed in the original 
code. Previously, it returns 32, now it will just return that value. Is this 
intended?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135328

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


[PATCH] D135256: [clang] Add Create method for CXXBoolLiteralExpr

2022-10-05 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik accepted this revision.
shafik 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/D135256/new/

https://reviews.llvm.org/D135256

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


[PATCH] D135306: [CUDA] Add support for CUDA-11.8 and sm_{87,89,90} GPUs.

2022-10-05 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
Herald added subscribers: mattd, gchakrabarti, asavonic, bixia, hiraditya, 
yaxunl.
Herald added a project: All.
tra updated this revision to Diff 465512.
tra added a comment.
tra updated this revision to Diff 465557.
tra updated this revision to Diff 465577.
tra updated this revision to Diff 465599.
tra updated this revision to Diff 465602.
tra retitled this revision from "Add support for CUDA-11.8 and sm_{87,89,90} 
GPUs." to "[CUDA] Add support for CUDA-11.8 and sm_{87,89,90} GPUs.".
tra edited the summary of this revision.
tra added a reviewer: yaxunl.
Herald added a subscriber: carlosgalvezp.
tra published this revision for review.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay, jholewinski.
Herald added projects: clang, LLVM.

Fixed typos in builtinsnvptx.def.


tra added a comment.

Cleanup GPU arch descriptions.


tra added a comment.

rebased.


tra added a comment.

rebase.


tra added a comment.

rebase


Only enables recognition and targeting of the new CUDA/PTX/GPU variants, but 
the functionality is limited to the features supported by the older CUDA 
versions. More work needs to be done to support the new features.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135306

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/BuiltinsNVPTX.def
  clang/include/clang/Basic/Cuda.h
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  llvm/lib/Target/NVPTX/NVPTX.td

Index: llvm/lib/Target/NVPTX/NVPTX.td
===
--- llvm/lib/Target/NVPTX/NVPTX.td
+++ llvm/lib/Target/NVPTX/NVPTX.td
@@ -59,6 +59,12 @@
  "Target SM 8.0">;
 def SM86 : SubtargetFeature<"sm_86", "SmVersion", "86",
  "Target SM 8.6">;
+def SM87 : SubtargetFeature<"sm_87", "SmVersion", "87",
+ "Target SM 8.7">;
+def SM89 : SubtargetFeature<"sm_89", "SmVersion", "89",
+ "Target SM 8.9">;
+def SM90 : SubtargetFeature<"sm_90", "SmVersion", "90",
+ "Target SM 9.0">;
 
 // PTX Versions
 def PTX32 : SubtargetFeature<"ptx32", "PTXVersion", "32",
@@ -95,6 +101,12 @@
  "Use PTX version 7.4">;
 def PTX75 : SubtargetFeature<"ptx75", "PTXVersion", "75",
  "Use PTX version 7.5">;
+def PTX76 : SubtargetFeature<"ptx76", "PTXVersion", "76",
+ "Use PTX version 7.6">;
+def PTX77 : SubtargetFeature<"ptx77", "PTXVersion", "77",
+ "Use PTX version 7.7">;
+def PTX78 : SubtargetFeature<"ptx78", "PTXVersion", "78",
+ "Use PTX version 7.8">;
 
 //===--===//
 // NVPTX supported processors.
@@ -120,6 +132,9 @@
 def : Proc<"sm_75", [SM75, PTX63]>;
 def : Proc<"sm_80", [SM80, PTX70]>;
 def : Proc<"sm_86", [SM86, PTX71]>;
+def : Proc<"sm_87", [SM87, PTX74]>;
+def : Proc<"sm_89", [SM89, PTX78]>;
+def : Proc<"sm_90", [SM90, PTX78]>;
 
 def NVPTXInstrInfo : InstrInfo {
 }
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -67,6 +67,12 @@
 return CudaVersion::CUDA_114;
   if (raw_version < 11060)
 return CudaVersion::CUDA_115;
+  if (raw_version < 11070)
+return CudaVersion::CUDA_116;
+  if (raw_version < 11080)
+return CudaVersion::CUDA_117;
+  if (raw_version < 11090)
+return CudaVersion::CUDA_118;
   return CudaVersion::NEW;
 }
 
@@ -572,6 +578,9 @@
   case CudaVersion::CUDA_##CUDA_VER:   \
 PtxFeature = "+ptx" #PTX_VER;  \
 break;
+CASE_CUDA_VERSION(118, 78);
+CASE_CUDA_VERSION(117, 77);
+CASE_CUDA_VERSION(116, 76);
 CASE_CUDA_VERSION(115, 75);
 CASE_CUDA_VERSION(114, 74);
 CASE_CUDA_VERSION(113, 73);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -3634,6 +3634,9 @@
   case CudaArch::SM_75:
   case CudaArch::SM_80:
   case CudaArch::SM_86:
+  case CudaArch::SM_87:
+  case CudaArch::SM_89:
+  case CudaArch::SM_90:
   case CudaArch::GFX600:
   case CudaArch::GFX601:
   case CudaArch::GFX602:
Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -246,6 +246,12 @@
 return "800";
   case CudaArch::SM_86:
 return "860";
+  case CudaArch::SM_87:
+return "870";
+  case 

[PATCH] D134546: [clang-offload-bundler] extracting compatible bundle entry

2022-10-05 Thread Yaxun Liu 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 rG844b84af20c7: [clang-offload-bundler] extracting compatible 
bundle entry (authored by yaxunl).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134546

Files:
  clang/include/clang/Basic/TargetID.h
  clang/include/clang/Driver/OffloadBundler.h
  clang/lib/Basic/TargetID.cpp
  clang/lib/Driver/OffloadBundler.cpp
  clang/test/Driver/clang-offload-bundler.c
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -13,6 +13,7 @@
 //===--===//
 
 #include "clang/Basic/Cuda.h"
+#include "clang/Basic/TargetID.h"
 #include "clang/Basic/Version.h"
 #include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -46,6 +47,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -309,6 +311,8 @@
   unsigned HostTargetNum = 0u;
   bool HIPOnly = true;
   llvm::DenseSet ParsedTargets;
+  // Map {offload-kind}-{triple} to target IDs.
+  std::map> TargetIDs;
   for (StringRef Target : TargetNames) {
 if (ParsedTargets.contains(Target)) {
   reportError(createStringError(errc::invalid_argument,
@@ -331,6 +335,8 @@
   reportError(createStringError(errc::invalid_argument, Msg.str()));
 }
 
+TargetIDs[OffloadInfo.OffloadKind.str() + "-" + OffloadInfo.Triple.str()]
+.insert(OffloadInfo.TargetID);
 if (KindIsValid && OffloadInfo.hasHostKind()) {
   ++HostTargetNum;
   // Save the index of the input that refers to the host.
@@ -342,6 +348,17 @@
 
 ++Index;
   }
+  for (const auto  : TargetIDs) {
+if (auto ConflictingTID =
+clang::getConflictTargetIDCombination(TargetID.second)) {
+  SmallVector Buf;
+  raw_svector_ostream Msg(Buf);
+  Msg << "Cannot bundle inputs with conflicting targets: '"
+  << TargetID.first + "-" + ConflictingTID->first << "' and '"
+  << TargetID.first + "-" + ConflictingTID->second << "'";
+  reportError(createStringError(errc::invalid_argument, Msg.str()));
+}
+  }
 
   // HIP uses clang-offload-bundler to bundle device-only compilation results
   // for multiple GPU archs, therefore allow no host target if all entries
Index: clang/test/Driver/clang-offload-bundler.c
===
--- clang/test/Driver/clang-offload-bundler.c
+++ clang/test/Driver/clang-offload-bundler.c
@@ -224,7 +224,7 @@
 // RUN: diff %t.empty %t.res.tgt2
 
 // Check that bindler prints an error if given host bundle does not exist in the fat binary.
-// RUN: not clang-offload-bundler -type=s -targets=host-x86_64-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle -allow-missing-bundles 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
+// RUN: not clang-offload-bundler -type=s -targets=host-amdgcn-xxx-linux-gnu,openmp-powerpc64le-ibm-linux-gnu -output=%t.res.s -output=%t.res.tgt1 -input=%t.bundle3.s -unbundle -allow-missing-bundles 2>&1 | FileCheck %s --check-prefix CK-NO-HOST-BUNDLE
 // CK-NO-HOST-BUNDLE: error: Can't find bundle for the host target
 
 //
@@ -432,6 +432,41 @@
 // NOHOST-NOT: host-
 // NOHOST-DAG: hip-amdgcn-amd-amdhsa--gfx900
 // NOHOST-DAG: hip-amdgcn-amd-amdhsa--gfx906
+
+//
+// Check bundling ID compatibility for HIP.
+//
+// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack- \
+// RUN:   -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
+// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip.bundle.bc
+// RUN: not clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906 \
+// RUN:   -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
+// RUN:   -input=%t.tgt1 -input=%t.tgt2 -output=%t.hip.bundle.bc 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=CONFLICT-TID
+// CONFLICT-TID: error: Cannot bundle inputs with conflicting targets: 'hip-amdgcn-amd-amdhsa--gfx906' and 'hip-amdgcn-amd-amdhsa--gfx906:xnack+'
+
+//
+// Check extracting bundle entry with compatible target ID for HIP.
+//
+// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906 \
+// RUN:   -input=%t.tgt1 -output=%t.hip.bundle.bc
+// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack- \
+// RUN:   -output=%t.res.tgt1 -input=%t.hip.bundle.bc -unbundle
+// RUN: diff %t.tgt1 %t.res.tgt1
+// RUN: clang-offload-bundler -type=bc -targets=hip-amdgcn-amd-amdhsa--gfx906:xnack+ \
+// RUN:   -output=%t.res.tgt1 -input=%t.hip.bundle.bc 

[clang] 844b84a - [clang-offload-bundler] extracting compatible bundle entry

2022-10-05 Thread Yaxun Liu via cfe-commits

Author: Yaxun (Sam) Liu
Date: 2022-10-05T19:44:38-04:00
New Revision: 844b84af20c71482093995b1d64abc190eb5a5f9

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

LOG: [clang-offload-bundler] extracting compatible bundle entry

In HIP a library is usually compiled with default target ID e.g. gfx906 so that
it can be used in all GPU configurations. The bitcode is saved in bundled
bitcode with gfx906 in entry ID.

In runtime compilation, a HIP program is compiled with a target ID matching
the GPU configuration, e.g. gfx906:xnack-. This program needs to link with
a library bundled bitcode with target ID gfx906.

For example:

  clang --offload-arch=gfx906 -o lib.o lib.hip
  clang --offload-arch=gfx906:xnack- program.hip lib.o

This common use case requires that clang-offlod-bundler to be able to extract
entry with compatible target ID, e.g. extracting an gfx906 entry when requesting
gfx906:xnack-.

Currently clang-offload-bundler only allow extracting entry with exact match
of target ID. This patch relaxes that so that it can extract entries with 
compatible
target ID.

Reviewed by: Artem Belevich, Saiyedul Islam

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

Added: 


Modified: 
clang/include/clang/Basic/TargetID.h
clang/include/clang/Driver/OffloadBundler.h
clang/lib/Basic/TargetID.cpp
clang/lib/Driver/OffloadBundler.cpp
clang/test/Driver/clang-offload-bundler.c
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/TargetID.h 
b/clang/include/clang/Basic/TargetID.h
index 2579276fc0340..a34bebbae1ad4 100644
--- a/clang/include/clang/Basic/TargetID.h
+++ b/clang/include/clang/Basic/TargetID.h
@@ -51,6 +51,10 @@ std::string getCanonicalTargetID(llvm::StringRef Processor,
 /// returns None.
 llvm::Optional>
 getConflictTargetIDCombination(const std::set );
+
+/// Check whether the provided target ID is compatible with the requested
+/// target ID.
+bool isCompatibleTargetID(llvm::StringRef Provided, llvm::StringRef Requested);
 } // namespace clang
 
 #endif

diff  --git a/clang/include/clang/Driver/OffloadBundler.h 
b/clang/include/clang/Driver/OffloadBundler.h
index ea0631b0ddf7f..d7f927c223819 100644
--- a/clang/include/clang/Driver/OffloadBundler.h
+++ b/clang/include/clang/Driver/OffloadBundler.h
@@ -66,11 +66,11 @@ class OffloadBundler {
 /// Bundle Entry ID (or, Offload Target String) has following components:
 ///  * Offload Kind - Host, OpenMP, or HIP
 ///  * Triple - Standard LLVM Triple
-///  * GPUArch (Optional) - Processor name, like gfx906 or sm_30
+///  * TargetID (Optional) - target ID, like gfx906:xnack+ or sm_30
 struct OffloadTargetInfo {
   llvm::StringRef OffloadKind;
   llvm::Triple Triple;
-  llvm::StringRef GPUArch;
+  llvm::StringRef TargetID;
 
   const OffloadBundlerConfig 
 
@@ -81,7 +81,7 @@ struct OffloadTargetInfo {
   bool isOffloadKindCompatible(const llvm::StringRef TargetOffloadKind) const;
   bool isTripleValid() const;
   bool operator==(const OffloadTargetInfo ) const;
-  std::string str();
+  std::string str() const;
 };
 
 } // namespace clang

diff  --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index abfbe49e1a91a..6f583cb0c6e72 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -164,4 +164,25 @@ getConflictTargetIDCombination(const 
std::set ) {
   return llvm::None;
 }
 
+bool isCompatibleTargetID(llvm::StringRef Provided, llvm::StringRef Requested) 
{
+  llvm::StringMap ProvidedFeatures, RequestedFeatures;
+  llvm::StringRef ProvidedProc =
+  *parseTargetIDWithFormatCheckingOnly(Provided, );
+  llvm::StringRef RequestedProc =
+  *parseTargetIDWithFormatCheckingOnly(Requested, );
+  if (ProvidedProc != RequestedProc)
+return false;
+  for (const auto  : ProvidedFeatures) {
+auto Loc = RequestedFeatures.find(F.first());
+// The default (unspecified) value of a feature is 'All', which can match
+// either 'On' or 'Off'.
+if (Loc == RequestedFeatures.end())
+  return false;
+// If a feature is specified, it must have exact match.
+if (Loc->second != F.second)
+  return false;
+  }
+  return true;
+}
+
 } // namespace clang

diff  --git a/clang/lib/Driver/OffloadBundler.cpp 
b/clang/lib/Driver/OffloadBundler.cpp
index 4a87942934ff9..9e28cfbc319c3 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -15,6 +15,7 @@
 
//===--===//
 
 #include "clang/Basic/Cuda.h"
+#include "clang/Basic/TargetID.h"
 #include "clang/Basic/Version.h"
 #include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -73,12 +74,12 @@ 

[PATCH] D135328: [CUDA] Refactored CUDA version housekeeping to use less boilerplate.

2022-10-05 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 465601.
tra added a comment.

Use int max for the "new" CUDA version value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135328

Files:
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp

Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -41,27 +41,11 @@
 
   PTXVersion = 32;
   for (const StringRef Feature : Opts.FeaturesAsWritten) {
-if (!Feature.startswith("+ptx"))
+int PTXV;
+if (!Feature.startswith("+ptx") ||
+Feature.drop_front(4).getAsInteger(10, PTXV))
   continue;
-PTXVersion = llvm::StringSwitch(Feature)
- .Case("+ptx75", 75)
- .Case("+ptx74", 74)
- .Case("+ptx73", 73)
- .Case("+ptx72", 72)
- .Case("+ptx71", 71)
- .Case("+ptx70", 70)
- .Case("+ptx65", 65)
- .Case("+ptx64", 64)
- .Case("+ptx63", 63)
- .Case("+ptx61", 61)
- .Case("+ptx60", 60)
- .Case("+ptx50", 50)
- .Case("+ptx43", 43)
- .Case("+ptx42", 42)
- .Case("+ptx41", 41)
- .Case("+ptx40", 40)
- .Case("+ptx32", 32)
- .Default(32);
+PTXVersion = PTXV; // TODO: should it be max(PTXVersion, PTXV)?
   }
 
   TLSSupported = false;
Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -8,64 +8,59 @@
 
 namespace clang {
 
+struct CudaVersionMapEntry {
+  const char *Name;
+  CudaVersion Version;
+  int IVersion;
+};
+#define CUDA_ENTRY(major, minor)   \
+  {\
+#major "." #minor, CudaVersion::CUDA_##major##minor, major * 10 + minor\
+  }
+
+static const CudaVersionMapEntry CudaNameVersionMap[] = {
+CUDA_ENTRY(7, 0),
+CUDA_ENTRY(7, 5),
+CUDA_ENTRY(8, 0),
+CUDA_ENTRY(9, 0),
+CUDA_ENTRY(9, 1),
+CUDA_ENTRY(9, 2),
+CUDA_ENTRY(10, 0),
+CUDA_ENTRY(10, 1),
+CUDA_ENTRY(10, 2),
+CUDA_ENTRY(11, 0),
+CUDA_ENTRY(11, 1),
+CUDA_ENTRY(11, 2),
+CUDA_ENTRY(11, 3),
+CUDA_ENTRY(11, 4),
+CUDA_ENTRY(11, 5),
+{"", CudaVersion::NEW, std::numeric_limits::max()},
+{"unknown", CudaVersion::UNKNOWN, 0} // End of list tombstone.
+};
+#undef CUDA_ENTRY
+
 const char *CudaVersionToString(CudaVersion V) {
-  switch (V) {
-  case CudaVersion::UNKNOWN:
-return "unknown";
-  case CudaVersion::CUDA_70:
-return "7.0";
-  case CudaVersion::CUDA_75:
-return "7.5";
-  case CudaVersion::CUDA_80:
-return "8.0";
-  case CudaVersion::CUDA_90:
-return "9.0";
-  case CudaVersion::CUDA_91:
-return "9.1";
-  case CudaVersion::CUDA_92:
-return "9.2";
-  case CudaVersion::CUDA_100:
-return "10.0";
-  case CudaVersion::CUDA_101:
-return "10.1";
-  case CudaVersion::CUDA_102:
-return "10.2";
-  case CudaVersion::CUDA_110:
-return "11.0";
-  case CudaVersion::CUDA_111:
-return "11.1";
-  case CudaVersion::CUDA_112:
-return "11.2";
-  case CudaVersion::CUDA_113:
-return "11.3";
-  case CudaVersion::CUDA_114:
-return "11.4";
-  case CudaVersion::CUDA_115:
-return "11.5";
-  case CudaVersion::NEW:
-return "";
-  }
-  llvm_unreachable("invalid enum");
+  for (auto *I = CudaNameVersionMap; I->Version != CudaVersion::UNKNOWN; ++I)
+if (I->Version == V)
+  return I->Name;
+
+  return CudaVersionToString(CudaVersion::UNKNOWN);
 }
 
 CudaVersion CudaStringToVersion(const llvm::Twine ) {
-  return llvm::StringSwitch(S.str())
-  .Case("7.0", CudaVersion::CUDA_70)
-  .Case("7.5", CudaVersion::CUDA_75)
-  .Case("8.0", CudaVersion::CUDA_80)
-  .Case("9.0", CudaVersion::CUDA_90)
-  .Case("9.1", CudaVersion::CUDA_91)
-  .Case("9.2", CudaVersion::CUDA_92)
-  .Case("10.0", CudaVersion::CUDA_100)
-  .Case("10.1", CudaVersion::CUDA_101)
-  .Case("10.2", CudaVersion::CUDA_102)
-  .Case("11.0", CudaVersion::CUDA_110)
-  .Case("11.1", CudaVersion::CUDA_111)
-  .Case("11.2", CudaVersion::CUDA_112)
-  .Case("11.3", CudaVersion::CUDA_113)
-  .Case("11.4", CudaVersion::CUDA_114)
-  .Case("11.5", CudaVersion::CUDA_115)
-  .Default(CudaVersion::UNKNOWN);
+  std::string VS = S.str();
+  for (auto *I = CudaNameVersionMap; I->Version != CudaVersion::UNKNOWN; ++I)
+if (I->Name == VS)
+  return I->Version;
+  return CudaVersion::UNKNOWN;
+}
+
+CudaVersion ToCudaVersion(llvm::VersionTuple Version) {
+  int IVer = Version.getMajor() * 10 + 

[PATCH] D135328: [CUDA] Refactored CUDA version housekeeping to use less boilerplate.

2022-10-05 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
Herald added subscribers: mattd, gchakrabarti, asavonic, bixia, yaxunl.
Herald added a project: All.
tra updated this revision to Diff 465598.
tra added a comment.
tra retitled this revision from "Refactored CUDA version housekeeping to use 
less boilerplate." to "[CUDA] Refactored CUDA version housekeeping to use less 
boilerplate.".
tra added a reviewer: yaxunl.
tra added a project: clang.
tra published this revision for review.
Herald added subscribers: cfe-commits, jholewinski.

Fix handling unknown versions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135328

Files:
  clang/lib/Basic/Cuda.cpp
  clang/lib/Basic/Targets/NVPTX.cpp

Index: clang/lib/Basic/Targets/NVPTX.cpp
===
--- clang/lib/Basic/Targets/NVPTX.cpp
+++ clang/lib/Basic/Targets/NVPTX.cpp
@@ -41,27 +41,11 @@
 
   PTXVersion = 32;
   for (const StringRef Feature : Opts.FeaturesAsWritten) {
-if (!Feature.startswith("+ptx"))
+int PTXV;
+if (!Feature.startswith("+ptx") ||
+Feature.drop_front(4).getAsInteger(10, PTXV))
   continue;
-PTXVersion = llvm::StringSwitch(Feature)
- .Case("+ptx75", 75)
- .Case("+ptx74", 74)
- .Case("+ptx73", 73)
- .Case("+ptx72", 72)
- .Case("+ptx71", 71)
- .Case("+ptx70", 70)
- .Case("+ptx65", 65)
- .Case("+ptx64", 64)
- .Case("+ptx63", 63)
- .Case("+ptx61", 61)
- .Case("+ptx60", 60)
- .Case("+ptx50", 50)
- .Case("+ptx43", 43)
- .Case("+ptx42", 42)
- .Case("+ptx41", 41)
- .Case("+ptx40", 40)
- .Case("+ptx32", 32)
- .Default(32);
+PTXVersion = PTXV; // TODO: should it be max(PTXVersion, PTXV)?
   }
 
   TLSSupported = false;
Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -8,64 +8,59 @@
 
 namespace clang {
 
+struct CudaVersionMapEntry {
+  const char *Name;
+  CudaVersion Version;
+  int IVersion;
+};
+#define CUDA_ENTRY(major, minor)   \
+  {\
+#major "." #minor, CudaVersion::CUDA_##major##minor, major * 10 + minor\
+  }
+
+static const CudaVersionMapEntry CudaNameVersionMap[] = {
+CUDA_ENTRY(7, 0),
+CUDA_ENTRY(7, 5),
+CUDA_ENTRY(8, 0),
+CUDA_ENTRY(9, 0),
+CUDA_ENTRY(9, 1),
+CUDA_ENTRY(9, 2),
+CUDA_ENTRY(10, 0),
+CUDA_ENTRY(10, 1),
+CUDA_ENTRY(10, 2),
+CUDA_ENTRY(11, 0),
+CUDA_ENTRY(11, 1),
+CUDA_ENTRY(11, 2),
+CUDA_ENTRY(11, 3),
+CUDA_ENTRY(11, 4),
+CUDA_ENTRY(11, 5),
+{"", CudaVersion::NEW, 99},
+{"unknown", CudaVersion::UNKNOWN, 0} // End of list tombstone.
+};
+#undef CUDA_ENTRY
+
 const char *CudaVersionToString(CudaVersion V) {
-  switch (V) {
-  case CudaVersion::UNKNOWN:
-return "unknown";
-  case CudaVersion::CUDA_70:
-return "7.0";
-  case CudaVersion::CUDA_75:
-return "7.5";
-  case CudaVersion::CUDA_80:
-return "8.0";
-  case CudaVersion::CUDA_90:
-return "9.0";
-  case CudaVersion::CUDA_91:
-return "9.1";
-  case CudaVersion::CUDA_92:
-return "9.2";
-  case CudaVersion::CUDA_100:
-return "10.0";
-  case CudaVersion::CUDA_101:
-return "10.1";
-  case CudaVersion::CUDA_102:
-return "10.2";
-  case CudaVersion::CUDA_110:
-return "11.0";
-  case CudaVersion::CUDA_111:
-return "11.1";
-  case CudaVersion::CUDA_112:
-return "11.2";
-  case CudaVersion::CUDA_113:
-return "11.3";
-  case CudaVersion::CUDA_114:
-return "11.4";
-  case CudaVersion::CUDA_115:
-return "11.5";
-  case CudaVersion::NEW:
-return "";
-  }
-  llvm_unreachable("invalid enum");
+  for (auto *I = CudaNameVersionMap; I->Version != CudaVersion::UNKNOWN; ++I)
+if (I->Version == V)
+  return I->Name;
+
+  return CudaVersionToString(CudaVersion::UNKNOWN);
 }
 
 CudaVersion CudaStringToVersion(const llvm::Twine ) {
-  return llvm::StringSwitch(S.str())
-  .Case("7.0", CudaVersion::CUDA_70)
-  .Case("7.5", CudaVersion::CUDA_75)
-  .Case("8.0", CudaVersion::CUDA_80)
-  .Case("9.0", CudaVersion::CUDA_90)
-  .Case("9.1", CudaVersion::CUDA_91)
-  .Case("9.2", CudaVersion::CUDA_92)
-  .Case("10.0", CudaVersion::CUDA_100)
-  .Case("10.1", CudaVersion::CUDA_101)
-  .Case("10.2", CudaVersion::CUDA_102)
-  .Case("11.0", CudaVersion::CUDA_110)
-  .Case("11.1", CudaVersion::CUDA_111)
-  .Case("11.2", CudaVersion::CUDA_112)
-  .Case("11.3", CudaVersion::CUDA_113)
-  .Case("11.4", CudaVersion::CUDA_114)
-  .Case("11.5", 

[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

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



Comment at: clang/lib/Lex/PPMacroExpansion.cpp:1092
+TT = *PP.getPreprocessorOpts().SourceDateEpoch;
+TM = std::gmtime();
+  } else {

ychen wrote:
> Why not use localtime as the else branch?
> 
> As mentioned above, diagnose null TM here or when parsing the user-specifed 
> value. A small trade-off to make, up to you.
Can you elaborate? With the check in Frontend I think a check here is not 
necessary...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-10-05 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/lib/AST/DeclCXX.cpp:774-775
+if ((!Constructor->isDeleted() && !Constructor->isDefaulted()) ||
+(getLangOpts().getClangABICompat() <=
+ LangOptions::ClangABI::Ver15 || Target.isPS() || 
Target.isOSDarwin())) {
+  // C++ [class]p4:

dblaikie wrote:
> rnk wrote:
> > I think this ought to be factored into a TargetInfo method, so we can share 
> > the logic here and below somehow. Compare this for example with 
> > `TargetInfo::getCallingConvKind`, which has a similar purpose.
> Seems plausible - though the version is stored in LangOpts, which isn't 
> currently plumbed through into TargetInfo - should it be plumbed through, or 
> is there some layering thing there where targets shouldn't depend on lang 
> opts?
> 
> Looks like it'd mostly involve passing LangOpts down here: 
> https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/CompilerInstance.cpp#L107
>  and plumbing it through all the `TargetInfo` ctors, possibly either storing 
> `LangOpts&` in the `TargetInfo`, or computing the `DefaultedSMFArePOD` 
> property in the ctor and storing that as a `bool` member in `TargetInfo` to 
> return from some query function to be added to that hierarchy.
> 
> Or I guess like `getOSDefines` have `getDefaultedSMFArePOD` takes 
> `LangOptions` as a parameter?
My main concern is keeping complex target-specific conditions out of DeclCXX to 
improve readability. Any way to achieve that sounds good to me.

I think I'd lean towards passing LangOpts as a parameter. After that, storing 
`DefaultedSMFArePOD` on TargetInfo as a bool sounds good. You can set the field 
in `TargetInfo::adjust` to read LangOpts, and then override that in PS & Darwin 
specific ::adjust method overrides.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D135305: [Clang] Fix using LTO with the new driver in RDC-mode

2022-10-05 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 465584.
jhuber6 added a comment.

Changing two tests to use phases instead to illustrate the `lto-bc` usage.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135305

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cuda-bindings.cu
  clang/test/Driver/cuda-phases.cu
  clang/test/Driver/hip-binding.hip
  clang/test/Driver/hip-phases.hip

Index: clang/test/Driver/hip-phases.hip
===
--- clang/test/Driver/hip-phases.hip
+++ clang/test/Driver/hip-phases.hip
@@ -546,3 +546,27 @@
 
 // CHECK: [[L0:[0-9]+]]: linker, {[[A3]], [[B3]]}, ir, (device-hip, [[ARCH]])
 // CHECK: offload, "device-hip (amdgcn-amd-amdhsa:[[ARCH]])" {[[L0]]}, ir
+
+//
+// Test the bindings using the new driver in LTO-mode.
+//
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-phases \
+// RUN:--offload-arch=gfx90a --offload-arch=gfx908 -foffload-lto -fgpu-rdc -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LTO %s
+//  LTO: 0: input, "[[INPUT:.+]]", hip, (host-hip)
+// LTO-NEXT: 1: preprocessor, {0}, hip-cpp-output, (host-hip)
+// LTO-NEXT: 2: compiler, {1}, ir, (host-hip)
+// LTO-NEXT: 3: input, "[[INPUT]]", hip, (device-hip, gfx908)
+// LTO-NEXT: 4: preprocessor, {3}, hip-cpp-output, (device-hip, gfx908)
+// LTO-NEXT: 5: compiler, {4}, ir, (device-hip, gfx908)
+// LTO-NEXT: 6: backend, {5}, lto-bc, (device-hip, gfx908)
+// LTO-NEXT: 7: offload, "device-hip (amdgcn-amd-amdhsa:gfx908)" {6}, lto-bc
+// LTO-NEXT: 8: input, "[[INPUT]]", hip, (device-hip, gfx90a)
+// LTO-NEXT: 9: preprocessor, {8}, hip-cpp-output, (device-hip, gfx90a)
+// LTO-NEXT: 10: compiler, {9}, ir, (device-hip, gfx90a)
+// LTO-NEXT: 11: backend, {10}, lto-bc, (device-hip, gfx90a)
+// LTO-NEXT: 12: offload, "device-hip (amdgcn-amd-amdhsa:gfx90a)" {11}, lto-bc
+// LTO-NEXT: 13: clang-offload-packager, {7, 12}, image, (device-hip)
+// LTO-NEXT: 14: offload, "host-hip (x86_64-unknown-linux-gnu)" {2}, "device-hip (x86_64-unknown-linux-gnu)" {13}, ir
+// LTO-NEXT: 15: backend, {14}, assembler, (host-hip)
+// LTO-NEXT: 16: assembler, {15}, object, (host-hip)
Index: clang/test/Driver/hip-binding.hip
===
--- clang/test/Driver/hip-binding.hip
+++ clang/test/Driver/hip-binding.hip
@@ -79,3 +79,15 @@
 // SYNTAX-ONLY: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-fsyntax-only"
 // SYNTAX-ONLY: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-fsyntax-only"
 // SYNTAX-ONLY: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-fsyntax-only"
+
+//
+// Check to ensure that we can use '-foffload' when not operating in RDC-mode.
+//
+// RUN: %clang -### --target=x86_64-linux-gnu -fno-gpu-rdc --offload-new-driver -ccc-print-bindings \
+// RUN:-foffload-lto --offload-arch=gfx90a --offload-arch=gfx908 -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LTO-NO-RDC %s
+//  LTO-NO-RDC: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[LTO_908:.+]]"
+// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[LTO_908]]"], output: "[[OBJ_908:.+]]"
+// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[LTO_90A:.+]]"
+// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[LTO_90A]]"], output: "[[OBJ_90A:.+]]"
+// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[OBJ_908]]", "[[OBJ_90A]]"], output: "[[HIPFB:.+]]"
Index: clang/test/Driver/cuda-phases.cu
===
--- clang/test/Driver/cuda-phases.cu
+++ clang/test/Driver/cuda-phases.cu
@@ -294,3 +294,27 @@
 // NON-CUDA-INPUT-NEXT: 22: backend, {21}, assembler, (host-cuda)
 // NON-CUDA-INPUT-NEXT: 23: assembler, {22}, object, (host-cuda)
 // NON-CUDA-INPUT-NEXT: 24: clang-linker-wrapper, {18, 23}, image, (host-cuda)
+
+//
+// Test the phases using the new driver in LTO-mode.
+//
+// RUN: %clang -### -target powerpc64le-ibm-linux-gnu --offload-new-driver -ccc-print-phases \
+// RUN:--offload-arch=sm_70 --offload-arch=sm_52 -foffload-lto -fgpu-rdc -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LTO %s
+//  LTO: 0: input, "[[INPUT:.+]]", cuda, (host-cuda)
+// LTO-NEXT: 1: preprocessor, {0}, cuda-cpp-output, (host-cuda)
+// LTO-NEXT: 2: compiler, {1}, ir, (host-cuda)
+// LTO-NEXT: 3: input, "[[INPUT]]", cuda, (device-cuda, sm_52)
+// LTO-NEXT: 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_52)
+// LTO-NEXT: 5: compiler, {4}, ir, (device-cuda, sm_52)
+// LTO-NEXT: 6: backend, {5}, lto-bc, (device-cuda, sm_52)
+// LTO-NEXT: 7: offload, "device-cuda (nvptx64-nvidia-cuda:sm_52)" {6}, lto-bc
+// LTO-NEXT: 8: input, "[[INPUT]]", cuda, (device-cuda, sm_70)
+// LTO-NEXT: 9: preprocessor, {8}, cuda-cpp-output, (device-cuda, sm_70)
+// LTO-NEXT: 10: 

[PATCH] D135269: [AMDGPU] Disable bool range metadata to workaround backend issue

2022-10-05 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/CodeGen/CGExpr.cpp:1792
 // attach range metadata to the load.
-  } else if (CGM.getCodeGenOpts().OptimizationLevel > 0)
+// TODO: Enable range metadata for AMDGCN after backend issue is fixed.
+  } else if (CGM.getCodeGenOpts().OptimizationLevel > 0 &&

It would be great to open a github issue, if we don't have one yet, and 
reference it here, so we can tell later what exactly it is we're working around 
here and know for sure when/whether we can undo the change.



Comment at: clang/test/CodeGenCUDA/bool-range.cu:14
+// range metadata is not emitted.
+// TODO: Re-enable range metadata after backend issue is fixed.
+

Ditto, a bug reference would help.


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

https://reviews.llvm.org/D135269

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


[PATCH] D134923: [clang][deps] Canonicalize module map path

2022-10-05 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG074fcec1eabf: [clang][deps] Canonicalize module map path 
(authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134923

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-symlink-dir.c

Index: clang/test/ClangScanDeps/modules-symlink-dir.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-symlink-dir.c
@@ -0,0 +1,131 @@
+// Check that we canonicalize the module map path without changing the module
+// directory, which would break header lookup.
+
+// REQUIRES: shell
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
+// RUN: ln -s module %t/symlink-to-module
+// RUN: ln -s ../actual.modulemap %t/module/module.modulemap
+// RUN: ln -s A %t/module/F.framework/Versions/Current
+// RUN: ln -s Versions/Current/Modules %t/module/F.framework/Modules
+// RUN: ln -s Versions/Current/Headers %t/module/F.framework/Headers
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 \
+// RUN:   -format experimental-full  -mode=preprocess-dependency-directives \
+// RUN:   -optimize-args -module-files-dir %t/build > %t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// Check the module commands actually build.
+// RUN: %deps-to-rsp %t/deps.json --module-name=Mod > %t/Mod.rsp
+// RUN: %deps-to-rsp %t/deps.json --module-name=F > %t/F.rsp
+// RUN: %clang @%t/Mod.rsp
+// RUN: %clang @%t/F.rsp
+
+// CHECK:  "modules": [
+// CHECK:{
+// CHECK:  "clang-module-deps": [],
+// CHECK:  "clang-modulemap-file": "[[PREFIX]]/module/F.framework/Modules/module.modulemap"
+// CHECK:  "command-line": [
+// CHECK-NOT: symlink-to-module
+// CHECK:"[[PREFIX]]/module/F.framework/Modules/module.modulemap"
+// CHECK-NOT: symlink-to-module
+// CHECK:  ]
+// CHECK:  "context-hash": "[[F_CONTEXT_HASH:[A-Z0-9]+]]"
+// CHECK:  "name": "F"
+// CHECK-NEXT:   }
+// CHECK-NEXT:   {
+// CHECK:  "clang-modulemap-file": "[[PREFIX]]/module/module.modulemap"
+// CHECK:  "command-line": [
+// CHECK-NOT: symlink-to-module
+// CHECK:"[[PREFIX]]/module/module.modulemap"
+// CHECK-NOT: symlink-to-module
+// CHECK:  ]
+// CHECK:  "context-hash": "[[CONTEXT_HASH:[A-Z0-9]+]]"
+// CHECK:  "name": "Mod"
+// CHECK-NEXT:   }
+// CHECK-NEXT: ]
+// CHECK:  "translation-units": [
+// CHECK:  "clang-module-deps": [
+// CHECK:{
+// CHECK:  "context-hash": "[[CONTEXT_HASH]]"
+// CHECK:  "module-name": "Mod"
+// CHECK:}
+// CHECK-NEXT: ],
+// CHECK:  "command-line": [
+// CHECK:"-fmodule-map-file=[[PREFIX]]/module/module.modulemap"
+// CHECK:  ]
+// CHECK:  "clang-module-deps": [
+// CHECK:{
+// CHECK:  "context-hash": "[[CONTEXT_HASH]]"
+// CHECK:  "module-name": "Mod"
+// CHECK:}
+// CHECK-NEXT: ]
+// CHECK:  "command-line": [
+// CHECK:"-fmodule-map-file=[[PREFIX]]/module/module.modulemap"
+// CHECK:  ]
+// CHECK:  "clang-module-deps": [
+// CHECK:{
+// CHECK:  "context-hash": "[[F_CONTEXT_HASH]]"
+// CHECK:  "module-name": "F"
+// CHECK:}
+// CHECK-NEXT: ]
+// CHECK:  "command-line": [
+// CHECK:"-fmodule-map-file=[[PREFIX]]/module/F.framework/Modules/module.modulemap"
+// CHECK:  ]
+// CHECK:  "clang-module-deps": [
+// CHECK:{
+// CHECK:  "context-hash": "[[F_CONTEXT_HASH]]"
+// CHECK:  "module-name": "F"
+// CHECK:}
+// CHECK-NEXT: ]
+// CHECK:  "command-line": [
+// CHECK:"-fmodule-map-file=[[PREFIX]]/module/F.framework/Modules/module.modulemap"
+// CHECK:  ]
+
+//--- cdb.json.in
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/tu1.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
+"file": "DIR/tu1.c"
+  },
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/tu2.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
+"file": "DIR/tu2.c"
+  },
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only -F DIR/symlink-to-module DIR/tu3.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
+"file": "DIR/tu3.c"
+  },
+  {
+

[clang] 074fcec - [clang][deps] Canonicalize module map path

2022-10-05 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2022-10-05T15:42:38-07:00
New Revision: 074fcec1eabfc992c46c95df215b1caf5cf58970

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

LOG: [clang][deps] Canonicalize module map path

When dep-scanning, canonicalize the module map path as much as we can.
This avoids unnecessarily needing to build multiple versions of a module
due to symlinks or case-insensitive file paths.

Despite the name `tryGetRealPathName`, the previous implementation did
not actually return the realpath most of the time, and indeed it would
be incorrect to do so since the realpath could be outside the module
directory, which would have broken finding headers relative to the
module.

Instead, use a canonicalization that is specific to the needs of
modulemap files (canonicalize the directory separately from the
filename).

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

Added: 
clang/test/ClangScanDeps/modules-symlink-dir.c

Modified: 
clang/include/clang/Lex/ModuleMap.h
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/ModuleMap.h 
b/clang/include/clang/Lex/ModuleMap.h
index 1084b49b3534a..10c5dfc25d9ce 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -622,6 +622,15 @@ class ModuleMap {
 
   void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap);
 
+  /// Canonicalize \p Path in a manner suitable for a module map file. In
+  /// particular, this canonicalizes the parent directory separately from the
+  /// filename so that it does not affect header resolution relative to the
+  /// modulemap.
+  ///
+  /// \returns an error code if any filesystem operations failed. In this case
+  /// \p Path is not modified.
+  std::error_code canonicalizeModuleMapPath(SmallVectorImpl );
+
   /// Get any module map files other than getModuleMapFileForUniquing(M)
   /// that define submodules of a top-level module \p M. This is cheaper than
   /// getting the module map file for each submodule individually, since the

diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 99596b1378ba1..73f9678834969 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -255,18 +255,11 @@ std::string 
HeaderSearch::getCachedModuleFileNameImpl(StringRef ModuleName,
 //
 // To avoid false-negatives, we form as canonical a path as we can, and map
 // to lower-case in case we're on a case-insensitive file system.
-std::string Parent =
-std::string(llvm::sys::path::parent_path(ModuleMapPath));
-if (Parent.empty())
-  Parent = ".";
-auto Dir = FileMgr.getDirectory(Parent);
-if (!Dir)
+SmallString<128> CanonicalPath(ModuleMapPath);
+if (getModuleMap().canonicalizeModuleMapPath(CanonicalPath))
   return {};
-auto DirName = FileMgr.getCanonicalName(*Dir);
-auto FileName = llvm::sys::path::filename(ModuleMapPath);
 
-llvm::hash_code Hash =
-  llvm::hash_combine(DirName.lower(), FileName.lower());
+llvm::hash_code Hash = llvm::hash_combine(CanonicalPath.str().lower());
 
 SmallString<128> HashStr;
 llvm::APInt(64, size_t(Hash)).toStringUnsigned(HashStr, /*Radix*/36);

diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index dbb81dc0d1478..cbd3303f36636 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1303,6 +1303,42 @@ void ModuleMap::setInferredModuleAllowedBy(Module *M, 
const FileEntry *ModMap) {
   InferredModuleAllowedBy[M] = ModMap;
 }
 
+std::error_code
+ModuleMap::canonicalizeModuleMapPath(SmallVectorImpl ) {
+  StringRef Dir = llvm::sys::path::parent_path({Path.data(), Path.size()});
+
+  // Do not canonicalize within the framework; the module map parser expects
+  // Modules/ not Versions/A/Modules.
+  if (llvm::sys::path::filename(Dir) == "Modules") {
+StringRef Parent = llvm::sys::path::parent_path(Dir);
+if (Parent.endswith(".framework"))
+  Dir = Parent;
+  }
+
+  FileManager  = SourceMgr.getFileManager();
+  auto DirEntry = FM.getDirectory(Dir.empty() ? "." : Dir);
+  if (!DirEntry)
+return DirEntry.getError();
+
+  // Canonicalize the directory.
+  StringRef CanonicalDir = FM.getCanonicalName(*DirEntry);
+  if (CanonicalDir != Dir) {
+bool Done = llvm::sys::path::replace_path_prefix(Path, Dir, CanonicalDir);
+(void)Done;
+assert(Done && "Path should always start with Dir");
+  }
+
+  // In theory, the filename component should also be canonicalized if it
+  // on a case-insensitive filesystem. However, the extra canonicalization is
+  // expensive and if clang looked up the filename it will always be 

[PATCH] D135326: Half-done attempt to move tail padding callback from TargetCXXABI to TargetInfo

2022-10-05 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: clang/include/clang/Basic/TargetInfo.h:953
+  };
+  virtual TailPaddingUseRules getTailPaddingUseRules() const {
+return UseTailPaddingUnlessPOD03;

The virtual method works, but it does seem to have caused a behavior change. I 
would be fine with switches and conditionals on the LLVM triple, or a 
TargetInfo field set in the constructor. That's how a lot of these flag-like 
behaviors are controlled. Whatever makes things easy.

My concern was more that we should put the target's rules for tail padding next 
to the target's rules for what constitutes POD-ness.



Comment at: clang/lib/Basic/Targets/OSTargets.h:169
+if (T.getOS() == llvm::Triple::WatchOS ||
+this->getCXXABI().getKind() == TargetCXXABI::AppleARM64)
+  return TargetInfo::UseTailPaddingUnlessPOD11;

I think it would be equivalent to check `T.getArch() == llvm::Triple::AArch64`, 
that's probably what set the TargetCXXABI.



Comment at: clang/lib/Basic/Targets/OSTargets.h:858
+  TargetInfo::TailPaddingUseRules getTailPaddingUseRules() const override {
+return TargetInfo::AlwaysUseTailPadding;
+  }

WindowsTargetInfo seems shared with mingw which uses GCC rules, so this isn't 
quite right. You can check `getTriple().isWindowsMSVCEnvironment()` here to get 
equivalent behavior.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135326

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


[PATCH] D135269: [AMDGPU] Disable bool range metadata to workaround backend issue

2022-10-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D135269#3837394 , @tra wrote:

> Is there more info about the issue? What does AMDGPU currently emit for the 
> test case?
>
> AFAICT from running it on CE (https://godbolt.org/z/ccq3vnbrM) llvm optimizes 
> it to essentially `*y = *x` and generates a 1-byte load+store for both NVPTX 
> and AMDGPU.

The issue happens to more complicated test cases which I cannot reduce right 
now.

Basically 8018d6be3459780e81a5da128a9915eb27909902 
 caused 
regressions in some PyTorch tests. Investigation shows the propagation of range 
metadata for bool type triggered some optimizations which caused some bool 
values to be loaded incorrectly. I will continue investigating the issue. 
However, I need a workaround for now.


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

https://reviews.llvm.org/D135269

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


[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file,function}-list= to match gcc options.

2022-10-05 Thread Jessica Paquette via Phabricator via cfe-commits
paquette added a comment.

+1, someone just asked me if this feature exists and then found this patch. If 
this could be revived, I think it would help a lot of folks out. :)


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

https://reviews.llvm.org/D37624

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


[PATCH] D135305: [Clang] Fix using LTO with the new driver in RDC-mode

2022-10-05 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D135305#3838490 , @yaxunl wrote:

> In D135305#3838435 , @jhuber6 wrote:
>
>> In D135305#3838412 , @yaxunl wrote:
>>
>>> should we test with -ccc-print-phases instead? It is not clear what actions 
>>> are produced by driver.
>>
>> Ah, realized you meant with phases. This is good enough for NVPTX as there 
>> is no explicit `assembler` phase. LTO makes no difference for AMDGPU as it 
>> already outputs bitcode.
>
> It is not clear whether the driver respects -foffload-lto when -fno-gpu-rdc 
> is specified. -ccc-print-phases shows whether the driver generates bc or 
> object. -ccc-print-bindings does not because it does not show the file types.

There's an existing test in the OpenMP toolchain that uses phases I believe, 
using bindings was just easier for making the tests. If you think it's worth 
changing then I'll do it, but it was just easier this way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135305

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-10-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D119051#3834985 , @rnk wrote:

> Relatedly, if we put this POD behavior query on TargetInfo, I wonder if it 
> makes sense to move the tail padding predicate from TargetCXXABI to 
> TargetInfo:
> https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/TargetCXXABI.h#L282
>
> The switch there is basically a switch over architectures.

Hmm, looked into this - but isn't most of `TargetCXXABI` a switch over CXXABIs, 
which are almost architectures/operating systems? Why is tail padding predicate 
different than the other tests in TargetCXXABI?

But I took a look at changing this in D135326 
 in case you want to check if this is what 
you had in mind - I'm not entirely sure it's better. The OS seems not be quite 
1:1 with the CXXABI groupings we have in TargetCXXABI... so one end result 
could just be calling back into the ABI to get the CXXABI kind and then 
returning based on that, which doesn't seem to be better...




Comment at: clang/lib/AST/DeclCXX.cpp:774-775
+if ((!Constructor->isDeleted() && !Constructor->isDefaulted()) ||
+(getLangOpts().getClangABICompat() <=
+ LangOptions::ClangABI::Ver15 || Target.isPS() || 
Target.isOSDarwin())) {
+  // C++ [class]p4:

rnk wrote:
> I think this ought to be factored into a TargetInfo method, so we can share 
> the logic here and below somehow. Compare this for example with 
> `TargetInfo::getCallingConvKind`, which has a similar purpose.
Seems plausible - though the version is stored in LangOpts, which isn't 
currently plumbed through into TargetInfo - should it be plumbed through, or is 
there some layering thing there where targets shouldn't depend on lang opts?

Looks like it'd mostly involve passing LangOpts down here: 
https://github.com/llvm/llvm-project/blob/main/clang/lib/Frontend/CompilerInstance.cpp#L107
 and plumbing it through all the `TargetInfo` ctors, possibly either storing 
`LangOpts&` in the `TargetInfo`, or computing the `DefaultedSMFArePOD` property 
in the ctor and storing that as a `bool` member in `TargetInfo` to return from 
some query function to be added to that hierarchy.

Or I guess like `getOSDefines` have `getDefaultedSMFArePOD` takes `LangOptions` 
as a parameter?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D135305: [Clang] Fix using LTO with the new driver in RDC-mode

2022-10-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D135305#3838435 , @jhuber6 wrote:

> In D135305#3838412 , @yaxunl wrote:
>
>> should we test with -ccc-print-phases instead? It is not clear what actions 
>> are produced by driver.
>
> Ah, realized you meant with phases. This is good enough for NVPTX as there is 
> no explicit `assembler` phase. LTO makes no difference for AMDGPU as it 
> already outputs bitcode.

It is not clear whether the driver respects -foffload-lto when -fno-gpu-rdc is 
specified. -ccc-print-phases shows whether the driver generates bc or object. 
-ccc-print-bindings does not because it does not show the file types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135305

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


[PATCH] D135326: Half-done attempt to move tail padding callback from TargetCXXABI to TargetInfo

2022-10-05 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.
dblaikie added a reviewer: rnk.
Herald added subscribers: kristof.beyls, dschuff.
Herald added a project: All.
dblaikie requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

Spinoff from D119051  to experiment with 
moving properties from TargetCXXABI to TargetInfo.

This is incomplete as it fails a couple of clang tests at the moment:

  Clang :: CodeGenCXX/armv7k.cpp
  Clang :: Layout/watchos-standard-layout.cpp

Haven't looked into why those are failing, but posting the code to see if this 
is even in the right ballpark of what was being suggested


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135326

Files:
  clang/include/clang/Basic/TargetCXXABI.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/lib/Basic/Targets/OSTargets.h

Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -13,6 +13,7 @@
 #define LLVM_CLANG_LIB_BASIC_TARGETS_OSTARGETS_H
 
 #include "Targets.h"
+#include "llvm/ADT/Triple.h"
 
 namespace clang {
 namespace targets {
@@ -161,6 +162,14 @@
: TargetInfo::UnsignedLongLong)
: TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
   }
+
+  TargetInfo::TailPaddingUseRules getTailPaddingUseRules() const override {
+const llvm::Triple  = this->getTriple();
+if (T.getOS() == llvm::Triple::WatchOS ||
+this->getCXXABI().getKind() == TargetCXXABI::AppleARM64)
+  return TargetInfo::UseTailPaddingUnlessPOD11;
+return TargetInfo::UseTailPaddingUnlessPOD03;
+  }
 };
 
 // DragonFlyBSD Target
@@ -845,6 +854,9 @@
 this->WCharType = TargetInfo::UnsignedShort;
 this->WIntType = TargetInfo::UnsignedShort;
   }
+  TargetInfo::TailPaddingUseRules getTailPaddingUseRules() const override {
+return TargetInfo::AlwaysUseTailPadding;
+  }
 };
 
 template 
@@ -922,6 +934,9 @@
 this->MCountName = "__mcount";
 this->TheCXXABI.set(TargetCXXABI::Fuchsia);
   }
+  TargetInfo::TailPaddingUseRules getTailPaddingUseRules() const override {
+return TargetInfo::UseTailPaddingUnlessPOD11;
+  }
 };
 
 // WebAssembly target
@@ -949,6 +964,9 @@
 this->TheCXXABI.set(TargetCXXABI::WebAssembly);
 this->HasFloat128 = true;
   }
+  TargetInfo::TailPaddingUseRules getTailPaddingUseRules() const override {
+return TargetInfo::UseTailPaddingUnlessPOD11;
+  }
 };
 
 // WASI target
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2392,12 +2392,12 @@
 /// Does the target C++ ABI require us to skip over the tail-padding
 /// of the given class (considering it as a base class) when allocating
 /// objects?
-static bool mustSkipTailPadding(TargetCXXABI ABI, const CXXRecordDecl *RD) {
-  switch (ABI.getTailPaddingUseRules()) {
-  case TargetCXXABI::AlwaysUseTailPadding:
+static bool mustSkipTailPadding(const TargetInfo , const CXXRecordDecl *RD) {
+  switch (TI.getTailPaddingUseRules()) {
+  case TargetInfo::AlwaysUseTailPadding:
 return false;
 
-  case TargetCXXABI::UseTailPaddingUnlessPOD03:
+  case TargetInfo::UseTailPaddingUnlessPOD03:
 // FIXME: To the extent that this is meant to cover the Itanium ABI
 // rules, we should implement the restrictions about over-sized
 // bitfields:
@@ -2418,7 +2418,7 @@
 //   intended.
 return RD->isPOD();
 
-  case TargetCXXABI::UseTailPaddingUnlessPOD11:
+  case TargetInfo::UseTailPaddingUnlessPOD11:
 // This is equivalent to RD->getTypeForDecl().isCXX11PODType(),
 // but with a lot of abstraction penalty stripped off.  This does
 // assume that these properties are set correctly even in C++98
@@ -3319,7 +3319,7 @@
   // tail-padding of base classes.  This is ABI-dependent.
   // FIXME: this should be stored in the record layout.
   bool skipTailPadding =
-  mustSkipTailPadding(getTargetInfo().getCXXABI(), RD);
+  mustSkipTailPadding(getTargetInfo(), RD);
 
   // FIXME: This should be done in FinalizeLayout.
   CharUnits DataSize =
Index: clang/include/clang/Basic/TargetInfo.h
===
--- clang/include/clang/Basic/TargetInfo.h
+++ clang/include/clang/Basic/TargetInfo.h
@@ -945,6 +945,14 @@
   virtual void getTargetDefines(const LangOptions ,
 MacroBuilder ) const = 0;
 
+  enum TailPaddingUseRules {
+AlwaysUseTailPadding,
+UseTailPaddingUnlessPOD03,
+UseTailPaddingUnlessPOD11
+  };
+  virtual TailPaddingUseRules getTailPaddingUseRules() const {
+return UseTailPaddingUnlessPOD03;
+  }
 
   /// Return information about target-specific builtins for
  

[PATCH] D135305: [Clang] Fix using LTO with the new driver in RDC-mode

2022-10-05 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D135305#3838412 , @yaxunl wrote:

> should we test with -ccc-print-phases instead? It is not clear what actions 
> are produced by driver.

Ah, realized you meant with phases. This is good enough for NVPTX as there is 
no explicit `assembler` phase. LTO makes no difference for AMDGPU as it already 
outputs bitcode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135305

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


[PATCH] D135305: [Clang] Fix using LTO with the new driver in RDC-mode

2022-10-05 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

In D135305#3838412 , @yaxunl wrote:

> should we test with -ccc-print-phases instead? It is not clear what actions 
> are produced by driver.

Of the four run lines added, three use `-ccc-print-phases`. The last uses just 
`-###` because otherwise the error message would not be triggered as it would 
quit before trying to generate the Clang job.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135305

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


[PATCH] D135305: [Clang] Fix using LTO with the new driver in RDC-mode

2022-10-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

should we test with -ccc-print-phases instead? It is not clear what actions are 
produced by driver.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135305

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


[PATCH] D134831: [Clang][Sema] Add -Wcast-function-type-strict

2022-10-05 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added a comment.

In D134831#3838373 , @nickdesaulniers 
wrote:

> Please consider waiting until the warning flag has started propagating to 
> branches of stable, at least to whatever branch -Werror is first enabled in.

Yes, I'm planning to wait until the kernel patch lands in stable branches. Greg 
picked up the patch this morning, so it should be in the next batch of stable 
releases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134831

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


[PATCH] D134831: [Clang][Sema] Add -Wcast-function-type-strict

2022-10-05 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Please consider waiting until the warning flag has started propagating to 
branches of stable, at least to whatever branch -Werror is first enabled in.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134831

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


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

2022-10-05 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:4151
+  QualType T = Entity.getType();
+  // FIXME: Union is unsupported.
+  int InitKind = T->isArrayType() ? 0 : 4;

ayzhao wrote:
> ayzhao wrote:
> > Hmm...it seems like as is this patch generates the correct code for 
> > parentheses-initialized `union`s:
> > 
> > ```
> > % cat ~/src/tests/test-union.cc
> > union C {
> >   float a;
> >   double b;
> > };
> > 
> > 
> > C foo() {
> >   return C(1);
> > }
> > 
> > % bin/clang++ -std=c++20 -emit-llvm -S -c -o - ~/src/tests/test-union.cc
> > ; ModuleID = '/usr/local/google/home/ayzhao/src/tests/test-union.cc'
> > source_filename = "/usr/local/google/home/ayzhao/src/tests/test-union.cc"
> > target datalayout = 
> > "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
> > target triple = "x86_64-unknown-linux-gnu"
> > 
> > %union.C = type { double }
> > 
> > ; Function Attrs: mustprogress noinline nounwind optnone uwtable
> > define dso_local double @_Z3foov() #0 {
> > entry:
> >   %retval = alloca %union.C, align 8
> >   store float 1.00e+00, ptr %retval, align 8
> >   %coerce.dive = getelementptr inbounds %union.C, ptr %retval, i32 0, i32 0
> >   %0 = load double, ptr %coerce.dive, align 8
> >   ret double %0
> > }
> > 
> > attributes #0 = { mustprogress noinline nounwind optnone uwtable 
> > "frame-pointer"="all" "min-legal-vector-width"="0" 
> > "no-trapping-math"="true" "stack-protector-buffer-size"="8" 
> > "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" 
> > "tune-cpu"="generic" }
> > 
> > !llvm.linker.options = !{}
> > !llvm.module.flags = !{!0, !1, !2, !3, !4}
> > !llvm.ident = !{!5}
> > 
> > !0 = !{i32 1, !"wchar_size", i32 4}
> > !1 = !{i32 8, !"PIC Level", i32 2}
> > !2 = !{i32 7, !"PIE Level", i32 2}
> > !3 = !{i32 7, !"uwtable", i32 2}
> > !4 = !{i32 7, !"frame-pointer", i32 2}
> > !5 = !{!"clang version 16.0.0"}
> > ```
> > 
> > I'm guessing this comment is specific to error messages.
> OK, I see what's going on. The following program fails to build:
> 
> ```
> #include 
> 
> union C {
>   int a;
>   std::string b;
> };
> 
> 
> C foo() {
>   return C("Hello, World!");
> }
> ```
> 
Actually, it turns out that the above example program is ill-formed because in 
a non-designated brace initialization, the parameter initializes the first 
element.

OTOH, there is a bug where

```
C(1, "Hello, World!");
```

compiles without errors because we check that # of parameters <= # of fields.

There may also be issues with anonymous `union`s in `struct`s - I'll have to 
investigate this further.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

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


[clang-tools-extra] 60b4b39 - [clangd] Avoid lexicographic compare when sorting SymbolIDs. NFC

2022-10-05 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-10-05T23:02:28+02:00
New Revision: 60b4b39f5a78661e2b9d222cf6ba7d9d5d7511ed

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

LOG: [clangd] Avoid lexicographic compare when sorting SymbolIDs. NFC

These are 8 bytes and we don't care about the actual ordering, so use
integer compare.

The array generated code has some extra byte swaps (clang), calls memcmp (gcc)
or inlines a big chain of comparisons (MSVC): https://godbolt.org/z/e79r6jM6K

Added: 


Modified: 
clang-tools-extra/clangd/index/SymbolID.h

Removed: 




diff  --git a/clang-tools-extra/clangd/index/SymbolID.h 
b/clang-tools-extra/clangd/index/SymbolID.h
index d1512080edbfb..e8aa462e96c17 100644
--- a/clang-tools-extra/clangd/index/SymbolID.h
+++ b/clang-tools-extra/clangd/index/SymbolID.h
@@ -39,7 +39,9 @@ class SymbolID {
   }
   bool operator!=(const SymbolID ) const { return !(*this == Sym); }
   bool operator<(const SymbolID ) const {
-return HashValue < Sym.HashValue;
+// Avoid lexicographic compare which requires swapping bytes or even 
memcmp!
+return llvm::bit_cast(HashValue) <
+   llvm::bit_cast(Sym.HashValue);
   }
 
   // The stored hash is truncated to RawSize bytes.
@@ -56,6 +58,8 @@ class SymbolID {
   explicit operator bool() const { return !isNull(); }
 
 private:
+  using IntTy = uint64_t;
+  static_assert(sizeof(IntTy) == RawSize);
   std::array HashValue{};
 };
 



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


[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-10-05 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 465549.
ychen added a comment.

- rebased on D135088 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaConcept.h
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
  clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -963,7 +963,7 @@
   
   
 https://wg21.link/p2113r0;>P2113R0
-No
+Clang 16
   
 
 
Index: clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -1,10 +1,18 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
-struct A;
-struct B;
-
 template  constexpr bool True = true;
 template  concept C = True;
+template  concept D = C && sizeof(T) > 2;
+template  concept E = D && alignof(T) > 1;
+
+struct A {};
+template  struct S {};
+template  struct S2 {};
+template  struct X {};
+
+namespace p6 {
+
+struct B;
 
 void f(C auto &, auto &) = delete;
 template  void f(Q &, C auto &);
@@ -13,14 +21,120 @@
   f(*ap, *bp);
 }
 
-template  struct X {};
-
+#if 0
+// FIXME: [temp.func.order]p6.2.1 is not implemented, matching GCC.
 template  bool operator==(X, V) = delete;
 templatebool operator==(T, X);
 
 bool h() {
   return X{} == 0;
 }
+#endif
+
+template class U,
+ typename... Z>
+void foo(T, U) = delete;
+template class U,
+ typename... Z>
+void foo(T, U) = delete;
+template class U,
+ typename... Z>
+void foo(T, U);
+
+// check auto template parameter pack.
+template class U,
+ C auto... Z>
+void foo2(T, U) = delete;
+template class U,
+ D auto... Z>
+void foo2(T, U) = delete;
+template class U,
+ E auto... Z>
+void foo2(T, U);
+
+void bar(S s, S2 s2) {
+  foo(0, s);
+  foo2(0, s2);
+}
+
+template void bar2();
+template void bar2() = delete;
+
+} // namespace p6
+
+namespace TestConversionFunction {
+struct Y {
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+};
+
+X f() {
+  return Y{}; // expected-error {{conversion from 'Y' to 'X' is ambiguous}}
+}
+}
+
+namespace ClassPartialSpecPartialOrdering {
+template struct Y { Y()=delete; }; // expected-note {{template is declared here}}
+template struct Y {}; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct B{ B()=delete; };
+template struct B { B()=delete; };
+template struct B {};
+
+template class U, typename... Z>
+struct Some { Some()=delete; };
+template class U, typename... Z>
+struct Some { Some()=delete; };
+template class U, typename... Z>
+struct Some {};
+
+void f() {
+  B b;
+  Some c;
+}
+
+template struct Z; // expected-note {{template is declared here}}
+template struct Z; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct W1;
+template struct W1 {};
+
+template struct W2;
+template struct W2 {};
+
+template
+concept C1 = C && C;
+template
+concept D1 = D && C;
+
+template auto T> struct W3;
+template auto T> struct W3 {};
+
+template auto... T> struct W4;
+template auto... T> struct W4 {};
+
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// template struct W5;
+// template struct W5 {};
+
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// template struct W6;
+// template struct W6 {};
+
+struct W1<0> w1;
+struct W2<0> w2;
+struct W3<0> w3;
+struct W4<0> w4;
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// struct W5<(int*)nullptr> w5;
+// struct W6 w6;
+}
 
 namespace PR53640 {
 
Index: clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -98,26 +98,31 @@
   static_assert(is_same_v()), void>); // expected-error {{call to 'bar' is ambiguous}}
 
   template
-  constexpr int goo(int a) requires AtLeast2 && true {
+  constexpr int goo(int a) requires AtLeast2 && true { // expected-note {{candidate 

[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-10-05 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 465547.
ychen added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaConcept.h
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
  clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -963,7 +963,7 @@
   
   
 https://wg21.link/p2113r0;>P2113R0
-No
+Clang 16
   
 
 
Index: clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -1,10 +1,18 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
-struct A;
-struct B;
-
 template  constexpr bool True = true;
 template  concept C = True;
+template  concept D = C && sizeof(T) > 2;
+template  concept E = D && alignof(T) > 1;
+
+struct A {};
+template  struct S {};
+template  struct S2 {};
+template  struct X {};
+
+namespace p6 {
+
+struct B;
 
 void f(C auto &, auto &) = delete;
 template  void f(Q &, C auto &);
@@ -13,14 +21,120 @@
   f(*ap, *bp);
 }
 
-template  struct X {};
-
+#if 0
+// FIXME: [temp.func.order]p6.2.1 is not implemented, matching GCC.
 template  bool operator==(X, V) = delete;
 templatebool operator==(T, X);
 
 bool h() {
   return X{} == 0;
 }
+#endif
+
+template class U,
+ typename... Z>
+void foo(T, U) = delete;
+template class U,
+ typename... Z>
+void foo(T, U) = delete;
+template class U,
+ typename... Z>
+void foo(T, U);
+
+// check auto template parameter pack.
+template class U,
+ C auto... Z>
+void foo2(T, U) = delete;
+template class U,
+ D auto... Z>
+void foo2(T, U) = delete;
+template class U,
+ E auto... Z>
+void foo2(T, U);
+
+void bar(S s, S2 s2) {
+  foo(0, s);
+  foo2(0, s2);
+}
+
+template void bar2();
+template void bar2() = delete;
+
+} // namespace p6
+
+namespace TestConversionFunction {
+struct Y {
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+};
+
+X f() {
+  return Y{}; // expected-error {{conversion from 'Y' to 'X' is ambiguous}}
+}
+}
+
+namespace ClassPartialSpecPartialOrdering {
+template struct Y { Y()=delete; }; // expected-note {{template is declared here}}
+template struct Y {}; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct B{ B()=delete; };
+template struct B { B()=delete; };
+template struct B {};
+
+template class U, typename... Z>
+struct Some { Some()=delete; };
+template class U, typename... Z>
+struct Some { Some()=delete; };
+template class U, typename... Z>
+struct Some {};
+
+void f() {
+  B b;
+  Some c;
+}
+
+template struct Z; // expected-note {{template is declared here}}
+template struct Z; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct W1;
+template struct W1 {};
+
+template struct W2;
+template struct W2 {};
+
+template
+concept C1 = C && C;
+template
+concept D1 = D && C;
+
+template auto T> struct W3;
+template auto T> struct W3 {};
+
+template auto... T> struct W4;
+template auto... T> struct W4 {};
+
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// template struct W5;
+// template struct W5 {};
+
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// template struct W6;
+// template struct W6 {};
+
+struct W1<0> w1;
+struct W2<0> w2;
+struct W3<0> w3;
+struct W4<0> w4;
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// struct W5<(int*)nullptr> w5;
+// struct W6 w6;
+}
 
 namespace PR53640 {
 
Index: clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -98,26 +98,31 @@
   static_assert(is_same_v()), void>); // expected-error {{call to 'bar' is ambiguous}}
 
   template
-  constexpr int goo(int a) requires AtLeast2 && true {
+  constexpr int goo(int a) requires AtLeast2 && true { // expected-note {{candidate function}}
 return 1;
   }
 
   template
-  

[PATCH] D134923: [clang][deps] Canonicalize module map path

2022-10-05 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 465544.
benlangmuir added a comment.

Rebased after landing https://reviews.llvm.org/D135220, which should hopefully 
fix the Windows test failure (it fixed the path for me locally on Windows, but 
I had some python-related issues that prevented me from running the tests 
properly).


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

https://reviews.llvm.org/D134923

Files:
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-symlink-dir.c

Index: clang/test/ClangScanDeps/modules-symlink-dir.c
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-symlink-dir.c
@@ -0,0 +1,131 @@
+// Check that we canonicalize the module map path without changing the module
+// directory, which would break header lookup.
+
+// REQUIRES: shell
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
+// RUN: ln -s module %t/symlink-to-module
+// RUN: ln -s ../actual.modulemap %t/module/module.modulemap
+// RUN: ln -s A %t/module/F.framework/Versions/Current
+// RUN: ln -s Versions/Current/Modules %t/module/F.framework/Modules
+// RUN: ln -s Versions/Current/Headers %t/module/F.framework/Headers
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 \
+// RUN:   -format experimental-full  -mode=preprocess-dependency-directives \
+// RUN:   -optimize-args -module-files-dir %t/build > %t/deps.json
+
+// RUN: cat %t/deps.json | sed 's:\?:/:g' | FileCheck -DPREFIX=%/t %s
+
+// Check the module commands actually build.
+// RUN: %deps-to-rsp %t/deps.json --module-name=Mod > %t/Mod.rsp
+// RUN: %deps-to-rsp %t/deps.json --module-name=F > %t/F.rsp
+// RUN: %clang @%t/Mod.rsp
+// RUN: %clang @%t/F.rsp
+
+// CHECK:  "modules": [
+// CHECK:{
+// CHECK:  "clang-module-deps": [],
+// CHECK:  "clang-modulemap-file": "[[PREFIX]]/module/F.framework/Modules/module.modulemap"
+// CHECK:  "command-line": [
+// CHECK-NOT: symlink-to-module
+// CHECK:"[[PREFIX]]/module/F.framework/Modules/module.modulemap"
+// CHECK-NOT: symlink-to-module
+// CHECK:  ]
+// CHECK:  "context-hash": "[[F_CONTEXT_HASH:[A-Z0-9]+]]"
+// CHECK:  "name": "F"
+// CHECK-NEXT:   }
+// CHECK-NEXT:   {
+// CHECK:  "clang-modulemap-file": "[[PREFIX]]/module/module.modulemap"
+// CHECK:  "command-line": [
+// CHECK-NOT: symlink-to-module
+// CHECK:"[[PREFIX]]/module/module.modulemap"
+// CHECK-NOT: symlink-to-module
+// CHECK:  ]
+// CHECK:  "context-hash": "[[CONTEXT_HASH:[A-Z0-9]+]]"
+// CHECK:  "name": "Mod"
+// CHECK-NEXT:   }
+// CHECK-NEXT: ]
+// CHECK:  "translation-units": [
+// CHECK:  "clang-module-deps": [
+// CHECK:{
+// CHECK:  "context-hash": "[[CONTEXT_HASH]]"
+// CHECK:  "module-name": "Mod"
+// CHECK:}
+// CHECK-NEXT: ],
+// CHECK:  "command-line": [
+// CHECK:"-fmodule-map-file=[[PREFIX]]/module/module.modulemap"
+// CHECK:  ]
+// CHECK:  "clang-module-deps": [
+// CHECK:{
+// CHECK:  "context-hash": "[[CONTEXT_HASH]]"
+// CHECK:  "module-name": "Mod"
+// CHECK:}
+// CHECK-NEXT: ]
+// CHECK:  "command-line": [
+// CHECK:"-fmodule-map-file=[[PREFIX]]/module/module.modulemap"
+// CHECK:  ]
+// CHECK:  "clang-module-deps": [
+// CHECK:{
+// CHECK:  "context-hash": "[[F_CONTEXT_HASH]]"
+// CHECK:  "module-name": "F"
+// CHECK:}
+// CHECK-NEXT: ]
+// CHECK:  "command-line": [
+// CHECK:"-fmodule-map-file=[[PREFIX]]/module/F.framework/Modules/module.modulemap"
+// CHECK:  ]
+// CHECK:  "clang-module-deps": [
+// CHECK:{
+// CHECK:  "context-hash": "[[F_CONTEXT_HASH]]"
+// CHECK:  "module-name": "F"
+// CHECK:}
+// CHECK-NEXT: ]
+// CHECK:  "command-line": [
+// CHECK:"-fmodule-map-file=[[PREFIX]]/module/F.framework/Modules/module.modulemap"
+// CHECK:  ]
+
+//--- cdb.json.in
+[
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/tu1.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
+"file": "DIR/tu1.c"
+  },
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only DIR/tu2.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache",
+"file": "DIR/tu2.c"
+  },
+  {
+"directory": "DIR",
+"command": "clang -fsyntax-only -F DIR/symlink-to-module DIR/tu3.c 

[PATCH] D128750: [C++20] Implement P2113R0: Changes to the Partial Ordering of Constrained Functions

2022-10-05 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 465543.
ychen added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128750

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Sema/SemaConcept.h
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
  clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -963,7 +963,7 @@
   
   
 https://wg21.link/p2113r0;>P2113R0
-No
+Clang 16
   
 
 
Index: clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
===
--- clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
+++ clang/test/CXX/temp/temp.decls/temp.fct/temp.func.order/p6.cpp
@@ -1,10 +1,18 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 
-struct A;
-struct B;
-
 template  constexpr bool True = true;
 template  concept C = True;
+template  concept D = C && sizeof(T) > 2;
+template  concept E = D && alignof(T) > 1;
+
+struct A {};
+template  struct S {};
+template  struct S2 {};
+template  struct X {};
+
+namespace p6 {
+
+struct B;
 
 void f(C auto &, auto &) = delete;
 template  void f(Q &, C auto &);
@@ -13,14 +21,120 @@
   f(*ap, *bp);
 }
 
-template  struct X {};
-
+#if 0
+// FIXME: [temp.func.order]p6.2.1 is not implemented, matching GCC.
 template  bool operator==(X, V) = delete;
 templatebool operator==(T, X);
 
 bool h() {
   return X{} == 0;
 }
+#endif
+
+template class U,
+ typename... Z>
+void foo(T, U) = delete;
+template class U,
+ typename... Z>
+void foo(T, U) = delete;
+template class U,
+ typename... Z>
+void foo(T, U);
+
+// check auto template parameter pack.
+template class U,
+ C auto... Z>
+void foo2(T, U) = delete;
+template class U,
+ D auto... Z>
+void foo2(T, U) = delete;
+template class U,
+ E auto... Z>
+void foo2(T, U);
+
+void bar(S s, S2 s2) {
+  foo(0, s);
+  foo2(0, s2);
+}
+
+template void bar2();
+template void bar2() = delete;
+
+} // namespace p6
+
+namespace TestConversionFunction {
+struct Y {
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+  template operator X(); // expected-note {{candidate function [with T = int, U = int]}}
+};
+
+X f() {
+  return Y{}; // expected-error {{conversion from 'Y' to 'X' is ambiguous}}
+}
+}
+
+namespace ClassPartialSpecPartialOrdering {
+template struct Y { Y()=delete; }; // expected-note {{template is declared here}}
+template struct Y {}; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct B{ B()=delete; };
+template struct B { B()=delete; };
+template struct B {};
+
+template class U, typename... Z>
+struct Some { Some()=delete; };
+template class U, typename... Z>
+struct Some { Some()=delete; };
+template class U, typename... Z>
+struct Some {};
+
+void f() {
+  B b;
+  Some c;
+}
+
+template struct Z; // expected-note {{template is declared here}}
+template struct Z; // expected-error {{class template partial specialization is not more specialized than the primary template}}
+
+template struct W1;
+template struct W1 {};
+
+template struct W2;
+template struct W2 {};
+
+template
+concept C1 = C && C;
+template
+concept D1 = D && C;
+
+template auto T> struct W3;
+template auto T> struct W3 {};
+
+template auto... T> struct W4;
+template auto... T> struct W4 {};
+
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// template struct W5;
+// template struct W5 {};
+
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// template struct W6;
+// template struct W6 {};
+
+struct W1<0> w1;
+struct W2<0> w2;
+struct W3<0> w3;
+struct W4<0> w4;
+// FIXME: enable once Clang support non-trivial auto on NTTP.
+// struct W5<(int*)nullptr> w5;
+// struct W6 w6;
+}
 
 namespace PR53640 {
 
Index: clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
===
--- clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
+++ clang/test/CXX/over/over.match/over.match.best/p1-2a.cpp
@@ -98,26 +98,31 @@
   static_assert(is_same_v()), void>); // expected-error {{call to 'bar' is ambiguous}}
 
   template
-  constexpr int goo(int a) requires AtLeast2 && true {
+  constexpr int goo(int a) requires AtLeast2 && true { // expected-note {{candidate function}}
 return 1;
   }
 
   template
-  

[PATCH] D135314: [clangd] Avoid scanning up to end of file on each comment!

2022-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Assigning char* (pointing at comment start) to StringRef was causing us
to scan the rest of the source file looking for the null terminator.

This seems to be eating about 8% of our *total* CPU!

While fixing this, factor out the common bits from the two places we're
parsing IWYU pragmas.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135314

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

Index: clang-tools-extra/clangd/unittests/HeadersTests.cpp
===
--- clang-tools-extra/clangd/unittests/HeadersTests.cpp
+++ clang-tools-extra/clangd/unittests/HeadersTests.cpp
@@ -9,6 +9,7 @@
 #include "Headers.h"
 
 #include "Compiler.h"
+#include "Matchers.h"
 #include "TestFS.h"
 #include "TestTU.h"
 #include "clang/Basic/TokenKinds.h"
@@ -30,6 +31,7 @@
 using ::testing::AllOf;
 using ::testing::Contains;
 using ::testing::ElementsAre;
+using ::testing::Eq;
 using ::testing::IsEmpty;
 using ::testing::Not;
 using ::testing::UnorderedElementsAre;
@@ -445,6 +447,16 @@
   EXPECT_FALSE(Includes.hasIWYUExport(getID("none.h", Includes)));
 }
 
+TEST(Headers, ParseIWYUPragma) {
+  EXPECT_THAT(parseIWYUPragma("// IWYU pragma: keep"), HasValue(Eq("keep")));
+  EXPECT_THAT(parseIWYUPragma("// IWYU pragma: keep\netc"),
+  HasValue(Eq("keep")));
+  EXPECT_EQ(parseIWYUPragma("/* IWYU pragma: keep"), llvm::None)
+  << "Only // comments supported!";
+  EXPECT_EQ(parseIWYUPragma("//  IWYU pragma: keep"), llvm::None)
+  << "Sensitive to whitespace";
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clang-tools-extra/clangd/index/CanonicalIncludes.cpp
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -17,8 +17,6 @@
 namespace clang {
 namespace clangd {
 namespace {
-const char IWYUPragma[] = "// IWYU pragma: private, include ";
-
 const std::pair IncludeMappings[] = {
 {"include/__stddef_max_align_t.h", ""},
 {"include/__wmmintrin_aes.h", ""},
@@ -712,17 +710,17 @@
 PragmaCommentHandler(CanonicalIncludes *Includes) : Includes(Includes) {}
 
 bool HandleComment(Preprocessor , SourceRange Range) override {
-  llvm::StringRef Text =
-  Lexer::getSourceText(CharSourceRange::getCharRange(Range),
-   PP.getSourceManager(), PP.getLangOpts());
-  if (!Text.consume_front(IWYUPragma))
+  auto Pragma = parseIWYUPragma(
+  PP.getSourceManager().getCharacterData(Range.getBegin()));
+  if (!Pragma || !Pragma->consume_front("private, include "))
 return false;
   auto  = PP.getSourceManager();
   // We always insert using the spelling from the pragma.
   if (auto *FE = SM.getFileEntryForID(SM.getFileID(Range.getBegin(
-Includes->addMapping(
-FE->getLastRef(),
-isLiteralInclude(Text) ? Text.str() : ("\"" + Text + "\"").str());
+Includes->addMapping(FE->getLastRef(),
+ isLiteralInclude(*Pragma)
+ ? Pragma->str()
+ : ("\"" + *Pragma + "\"").str());
   return false;
 }
 
Index: clang-tools-extra/clangd/Headers.h
===
--- clang-tools-extra/clangd/Headers.h
+++ clang-tools-extra/clangd/Headers.h
@@ -35,6 +35,11 @@
 /// Returns true if \p Include is literal include like "path" or .
 bool isLiteralInclude(llvm::StringRef Include);
 
+/// If Text begins an Include-What-You-Use directive, returns it.
+/// Given "// IWYU pragma: keep", returns "keep".
+/// Input is a null-terminated char* as provided by SM.getCharacterData().
+llvm::Optional parseIWYUPragma(const char *Text);
+
 /// Represents a header file to be #include'd.
 struct HeaderFile {
   std::string File;
Index: clang-tools-extra/clangd/Headers.cpp
===
--- clang-tools-extra/clangd/Headers.cpp
+++ clang-tools-extra/clangd/Headers.cpp
@@ -22,9 +22,17 @@
 namespace clang {
 namespace clangd {
 
-const char IWYUPragmaKeep[] = "// IWYU pragma: keep";
-const char IWYUPragmaExport[] = "// IWYU pragma: export";
-const char IWYUPragmaBeginExports[] = "// IWYU pragma: begin_exports";
+llvm::Optional parseIWYUPragma(const char *Text) {
+  // This gets called for every comment seen in the preamble, so it's quite hot.
+  constexpr char IWYUPragma[] = "// IWYU pragma: ";

[clang] b61860e - Use inheriting ctors for OSTargetInfo

2022-10-05 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-10-05T20:22:19Z
New Revision: b61860e63e34d955a9841389583978af93c2b97a

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

LOG: Use inheriting ctors for OSTargetInfo

(& remove PSPTargetInfo because it's unused - it had the wrong ctor in
it anyway, so wouldn't've been able to be instantiated - must've
happened due to bitrot over the years)

Added: 


Modified: 
clang/lib/Basic/Targets/OSTargets.h

Removed: 




diff  --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index c75f7d9fbafeb..2d1a33ad9c0bc 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -50,8 +50,7 @@ class LLVM_LIBRARY_VISIBILITY CloudABITargetInfo : public 
OSTargetInfo {
   }
 
 public:
-  CloudABITargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 // Ananas target
@@ -66,8 +65,7 @@ class LLVM_LIBRARY_VISIBILITY AnanasTargetInfo : public 
OSTargetInfo {
   }
 
 public:
-  AnanasTargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 void getDarwinDefines(MacroBuilder , const LangOptions ,
@@ -280,8 +278,7 @@ class LLVM_LIBRARY_VISIBILITY KFreeBSDTargetInfo : public 
OSTargetInfo {
   }
 
 public:
-  KFreeBSDTargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 // Haiku Target
@@ -336,8 +333,7 @@ class LLVM_LIBRARY_VISIBILITY HurdTargetInfo : public 
OSTargetInfo {
   Builder.defineMacro("_GNU_SOURCE");
   }
 public:
-  HurdTargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 // Minix Target
@@ -360,8 +356,7 @@ class LLVM_LIBRARY_VISIBILITY MinixTargetInfo : public 
OSTargetInfo {
   }
 
 public:
-  MinixTargetInfo(const llvm::Triple , const TargetOptions )
-  : OSTargetInfo(Triple, Opts) {}
+  using OSTargetInfo::OSTargetInfo;
 };
 
 // Linux target
@@ -499,23 +494,6 @@ class LLVM_LIBRARY_VISIBILITY OpenBSDTargetInfo : public 
OSTargetInfo {
   }
 };
 
-// PSP Target
-template 
-class LLVM_LIBRARY_VISIBILITY PSPTargetInfo : public OSTargetInfo {
-protected:
-  void getOSDefines(const LangOptions , const llvm::Triple ,
-MacroBuilder ) const override {
-// PSP defines; list based on the output of the pspdev gcc toolchain.
-Builder.defineMacro("PSP");
-Builder.defineMacro("_PSP");
-Builder.defineMacro("__psp__");
-Builder.defineMacro("__ELF__");
-  }
-
-public:
-  PSPTargetInfo(const llvm::Triple ) : OSTargetInfo(Triple) {}
-};
-
 // PS3 PPU Target
 template 
 class LLVM_LIBRARY_VISIBILITY PS3PPUTargetInfo : public OSTargetInfo {
@@ -595,8 +573,7 @@ class LLVM_LIBRARY_VISIBILITY PS4OSTargetInfo : public 
PSOSTargetInfo {
   }
 
 public:
-  PS4OSTargetInfo(const llvm::Triple , const TargetOptions )
-  : PSOSTargetInfo(Triple, Opts) {}
+  using PSOSTargetInfo::PSOSTargetInfo;
 };
 
 // PS5 Target
@@ -612,8 +589,7 @@ class LLVM_LIBRARY_VISIBILITY PS5OSTargetInfo : public 
PSOSTargetInfo {
   }
 
 public:
-  PS5OSTargetInfo(const llvm::Triple , const TargetOptions )
-  : PSOSTargetInfo(Triple, Opts) {}
+  using PSOSTargetInfo::PSOSTargetInfo;
 };
 
 // RTEMS Target
@@ -986,8 +962,7 @@ class LLVM_LIBRARY_VISIBILITY WASITargetInfo
   }
 
 public:
-  explicit WASITargetInfo(const llvm::Triple , const TargetOptions 
)
-  : WebAssemblyOSTargetInfo(Triple, Opts) {}
+  using WebAssemblyOSTargetInfo::WebAssemblyOSTargetInfo;
 };
 
 // Emscripten target



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


[PATCH] D135107: [clang][NFC] Use enum for -fstrict-flex-arrays

2022-10-05 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 465526.
void added a comment.

Rebase with ToT.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135107

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp

Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -794,7 +794,11 @@
 if (Size.isZero())
   return true;
 
-if (getContext().getLangOpts().StrictFlexArrays >= 2)
+using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+const FAMKind StrictFlexArraysLevel =
+  Ctx.getLangOpts().getStrictFlexArraysLevel();
+if (StrictFlexArraysLevel == FAMKind::ZeroOrIncomplete ||
+StrictFlexArraysLevel == FAMKind::Incomplete)
   return false;
 
 const AnalyzerOptions  = SVB.getAnalyzerOptions();
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15915,7 +15915,8 @@
   const ConstantArrayType *ArrayTy =
   Context.getAsConstantArrayType(BaseExpr->getType());
 
-  unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+  LangOptions::StrictFlexArraysLevelKind
+StrictFlexArraysLevel = getLangOpts().getStrictFlexArraysLevel();
 
   const Type *BaseType =
   ArrayTy == nullptr ? nullptr : ArrayTy->getElementType().getTypePtr();
Index: clang/lib/CodeGen/CGExpr.cpp
===
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -919,7 +919,8 @@
 static llvm::Value *getArrayIndexingBound(CodeGenFunction ,
   const Expr *Base,
   QualType ,
-  unsigned StrictFlexArraysLevel) {
+  LangOptions::StrictFlexArraysLevelKind
+  StrictFlexArraysLevel) {
   // For the vector indexing extension, the bound is the number of elements.
   if (const VectorType *VT = Base->getType()->getAs()) {
 IndexedType = Base->getType();
@@ -958,7 +959,8 @@
  "should not be called unless adding bounds checks");
   SanitizerScope SanScope(this);
 
-  const unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+  const LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel =
+getLangOpts().getStrictFlexArraysLevel();
 
   QualType IndexedType;
   llvm::Value *Bound =
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -11613,15 +11613,17 @@
   //   conservative with the last element in structs (if it's an array), so our
   //   current behavior is more compatible than an explicit list approach would
   //   be.
-  int StrictFlexArraysLevel = Ctx.getLangOpts().StrictFlexArrays;
+  using FAMKind = LangOptions::StrictFlexArraysLevelKind;
+  FAMKind StrictFlexArraysLevel = Ctx.getLangOpts().getStrictFlexArraysLevel();
   return LVal.InvalidBase &&
  Designator.Entries.size() == Designator.MostDerivedPathLength &&
  Designator.MostDerivedIsArrayElement &&
  (Designator.isMostDerivedAnUnsizedArray() ||
   Designator.getMostDerivedArraySize() == 0 ||
   (Designator.getMostDerivedArraySize() == 1 &&
-   StrictFlexArraysLevel < 2) ||
-  StrictFlexArraysLevel == 0) &&
+   StrictFlexArraysLevel != FAMKind::Incomplete &&
+   StrictFlexArraysLevel != FAMKind::ZeroOrIncomplete) ||
+  StrictFlexArraysLevel == FAMKind::Default) &&
  isDesignatorAtObjectEnd(Ctx, LVal);
 }
 
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -204,7 +204,8 @@
 }
 
 bool Expr::isFlexibleArrayMemberLike(
-ASTContext , unsigned StrictFlexArraysLevel,
+ASTContext ,
+LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
 bool IgnoreTemplateOrMacroSubstitution) const {
 
   // For compatibility with existing code, we treat arrays of length 0 or
@@ -219,7 +220,8 @@
 // FIXME: While the default -fstrict-flex-arrays=0 permits Size>1 trailing
 // arrays to be treated as flexible-array-members, we still emit diagnostics
 // as if they are not. Pending further discussion...
-if (StrictFlexArraysLevel >= 2 || 

[PATCH] D135220: [clang] Update ModuleMap::getModuleMapFile* to use FileEntryRef

2022-10-05 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5ea78c4113f8: [clang] Update ModuleMap::getModuleMapFile* to 
use FileEntryRef (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135220

Files:
  clang/include/clang/Basic/FileEntry.h
  clang/include/clang/Basic/SourceManager.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Basic/SourceManager.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/Modules/malformed.cpp
  clang/tools/libclang/CIndexInclusionStack.cpp

Index: clang/tools/libclang/CIndexInclusionStack.cpp
===
--- clang/tools/libclang/CIndexInclusionStack.cpp
+++ clang/tools/libclang/CIndexInclusionStack.cpp
@@ -59,8 +59,8 @@
 
 // Callback to the client.
 // FIXME: We should have a function to construct CXFiles.
-CB(static_cast(
-   const_cast(FI.getContentCache().OrigEntry)),
+CB(static_cast(const_cast(
+   static_cast(FI.getContentCache().OrigEntry))),
InclusionStack.data(), InclusionStack.size(), clientData);
   }
 }
Index: clang/test/Modules/malformed.cpp
===
--- clang/test/Modules/malformed.cpp
+++ clang/test/Modules/malformed.cpp
@@ -3,9 +3,9 @@
 //
 // RUN: rm -rf %t
 // RUN: cd %S
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I Inputs/malformed -DHEADER="a1.h" %s 2>&1 | FileCheck %s --check-prefix=CHECK-A
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I Inputs/malformed -DHEADER="b1.h" %s 2>&1 | FileCheck %s --check-prefix=CHECK-B
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I Inputs/malformed -DHEADER="c.h" malformed.cpp 2>&1 | FileCheck %s --check-prefix=CHECK-C
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I Inputs/malformed -DHEADER="a1.h" %s 2>&1 | sed 's:\?:/:g' | FileCheck %s --check-prefix=CHECK-A
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I Inputs/malformed -DHEADER="b1.h" %s 2>&1 | sed 's:\?:/:g' | FileCheck %s --check-prefix=CHECK-B
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I Inputs/malformed -DHEADER="c.h" malformed.cpp 2>&1 | sed 's:\?:/:g' | FileCheck %s --check-prefix=CHECK-C
 
 #define STR2(x) #x
 #define STR(x) STR2(x)
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -227,7 +227,7 @@
   if (llvm::any_of(CI.getFrontendOpts().Inputs, needsModules)) {
 Preprocessor  = ScanInstance.getPreprocessor();
 if (Module *CurrentModule = PP.getCurrentModuleImplementation())
-  if (const FileEntry *CurrentModuleMap =
+  if (Optional CurrentModuleMap =
   PP.getHeaderSearchInfo()
   .getModuleMap()
   .getModuleMapFileForUniquing(CurrentModule))
@@ -406,13 +406,13 @@
   MD.ImplicitModulePCMPath = std::string(M->getASTFile()->getName());
   MD.IsSystem = M->IsSystem;
 
-  const FileEntry *ModuleMap = MDC.ScanInstance.getPreprocessor()
-   .getHeaderSearchInfo()
-   .getModuleMap()
-   .getModuleMapFileForUniquing(M);
+  Optional ModuleMap = MDC.ScanInstance.getPreprocessor()
+ .getHeaderSearchInfo()
+ .getModuleMap()
+ .getModuleMapFileForUniquing(M);
 
   if (ModuleMap) {
-StringRef Path = ModuleMap->tryGetRealPathName();
+StringRef Path = ModuleMap->getFileEntry().tryGetRealPathName();
 if (Path.empty())
   Path = ModuleMap->getName();
 MD.ClangModuleMapFile = std::string(Path);
Index: clang/lib/Serialization/ASTWriter.cpp
===
--- clang/lib/Serialization/ASTWriter.cpp
+++ clang/lib/Serialization/ASTWriter.cpp
@@ -193,13 +193,13 @@
 auto *CurrentModule = ModulesToProcess.pop_back_val();
 ProcessedModules.insert(CurrentModule);
 
-auto *ModuleMapFile =
+Optional ModuleMapFile =
 HS.getModuleMap().getModuleMapFileForUniquing(CurrentModule);
 if (!ModuleMapFile) {
   continue;
 }
 
-ModuleMaps.insert(ModuleMapFile);
+ModuleMaps.insert(*ModuleMapFile);
 
 for (auto *ImportedModule : (CurrentModule)->Imports) {
   if 

[clang] 5ea78c4 - [clang] Update ModuleMap::getModuleMapFile* to use FileEntryRef

2022-10-05 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2022-10-05T13:12:43-07:00
New Revision: 5ea78c4113f8d2c8be24152f2dd0cadaea352c9d

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

LOG: [clang] Update ModuleMap::getModuleMapFile* to use FileEntryRef

Update SourceManager::ContentCache::OrigEntry to keep the original
FileEntryRef, and use that to enable ModuleMap::getModuleMapFile* to
return the original FileEntryRef. This change should be NFC for
most users of SourceManager::ContentCache, but it could affect behaviour
for users of getNameAsRequested such as in compileModuleImpl. I have not
found a way to detect that difference without additional functional
changes, other than incidental cases like changes from / to \ on
Windows so there is no new test.

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

Added: 


Modified: 
clang/include/clang/Basic/FileEntry.h
clang/include/clang/Basic/SourceManager.h
clang/include/clang/Lex/ModuleMap.h
clang/lib/Basic/SourceManager.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/test/Modules/malformed.cpp
clang/tools/libclang/CIndexInclusionStack.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/FileEntry.h 
b/clang/include/clang/Basic/FileEntry.h
index d9b92a73a1d82..4f2d6436b333b 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -341,6 +341,23 @@ static_assert(
 OptionalFileEntryRefDegradesToFileEntryPtr>::value,
 "OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable");
 
+inline bool operator==(const FileEntry *LHS,
+   const Optional ) {
+  return LHS == (RHS ? >getFileEntry() : nullptr);
+}
+inline bool operator==(const Optional ,
+   const FileEntry *RHS) {
+  return (LHS ? >getFileEntry() : nullptr) == RHS;
+}
+inline bool operator!=(const FileEntry *LHS,
+   const Optional ) {
+  return !(LHS == RHS);
+}
+inline bool operator!=(const Optional ,
+   const FileEntry *RHS) {
+  return !(LHS == RHS);
+}
+
 /// Cached information about one file (either on disk
 /// or in the virtual file system).
 ///

diff  --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 8a737d6b4b398..1e0743ecd8b6c 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -139,8 +139,9 @@ class alignas(8) ContentCache {
   /// It is possible for this to be NULL if the ContentCache encapsulates
   /// an imaginary text buffer.
   ///
-  /// FIXME: Turn this into a FileEntryRef and remove Filename.
-  const FileEntry *OrigEntry;
+  /// FIXME: Make non-optional using a virtual file as needed, remove \c
+  /// Filename and use \c OrigEntry.getNameAsRequested() instead.
+  OptionalFileEntryRefDegradesToFileEntryPtr OrigEntry;
 
   /// References the file which the contents were actually loaded from.
   ///
@@ -177,9 +178,13 @@ class alignas(8) ContentCache {
 
   mutable unsigned IsBufferInvalid : 1;
 
-  ContentCache(const FileEntry *Ent = nullptr) : ContentCache(Ent, Ent) {}
+  ContentCache()
+  : OrigEntry(None), ContentsEntry(nullptr), BufferOverridden(false),
+IsFileVolatile(false), IsTransient(false), IsBufferInvalid(false) {}
+
+  ContentCache(FileEntryRef Ent) : ContentCache(Ent, Ent) {}
 
-  ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
+  ContentCache(FileEntryRef Ent, const FileEntry *contentEnt)
   : OrigEntry(Ent), ContentsEntry(contentEnt), BufferOverridden(false),
 IsFileVolatile(false), IsTransient(false), IsBufferInvalid(false) {}
 
@@ -660,7 +665,7 @@ class SourceManager : public RefCountedBase {
   struct OverriddenFilesInfoTy {
 /// Files that have been overridden with the contents from another
 /// file.
-llvm::DenseMap OverriddenFiles;
+llvm::DenseMap OverriddenFiles;
 
 /// Files that were overridden with a memory buffer.
 llvm::DenseSet OverriddenFilesWithBuffer;
@@ -978,8 +983,7 @@ class SourceManager : public RefCountedBase {
   ///
   /// \param NewFile the file whose contents will be used as the
   /// data instead of the contents of the given source file.
-  void overrideFileContents(const FileEntry *SourceFile,
-const FileEntry *NewFile);
+  void overrideFileContents(const FileEntry *SourceFile, FileEntryRef NewFile);
 
   /// Returns true if the file contents have been overridden.
   bool isFileOverridden(const FileEntry *File) const {
@@ -1044,8 +1048,8 @@ class 

[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang 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 rG5301826fa86a: [clang][ExtractAPI] Dont print locations 
for anonymous tags (authored by zixuw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135295

Files:
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,11 @@
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy = CI.getASTContext().getPrintingPolicy();
+  Policy.AnonymousTagLocations = false;
+  CI.getASTContext().setPrintingPolicy(Policy);
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,11 @@
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy = CI.getASTContext().getPrintingPolicy();
+  Policy.AnonymousTagLocations = false;
+  CI.getASTContext().setPrintingPolicy(Policy);
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5301826 - [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang via cfe-commits

Author: Zixu Wang
Date: 2022-10-05T13:11:21-07:00
New Revision: 5301826fa86aa520b65c86abbe3b3a7194849e27

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

LOG: [clang][ExtractAPI] Don't print locations for anonymous tags

ExtractAPI doesn't care about locations of anonymous TagDecls. Set the
printing policy to exclude that from anonymous decl names.

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

Added: 


Modified: 
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp

Removed: 




diff  --git a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp 
b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
index 969ee772fa063..4a97ee9922ddd 100644
--- a/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ b/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,11 @@ ExtractAPIAction::CreateASTConsumer(CompilerInstance , 
StringRef InFile) {
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy = CI.getASTContext().getPrintingPolicy();
+  Policy.AnonymousTagLocations = false;
+  CI.getASTContext().setPrintingPolicy(Policy);
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }



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


[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added a comment.

In D135295#3837895 , @zixuw wrote:

> In D135295#3837855 , @zixuw wrote:
>
>> In D135295#3837734 , @ributzka 
>> wrote:
>>
>>> This doesn't affect any tests?
>>
>> Just finished building locally, running tests to verify now
>
> Doesn't affect any test for this patch as expected. Still need to see how 
> does it interacts with https://reviews.llvm.org/D134813.

Interaction with D134813  looks good. Landing 
this


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135295

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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added a comment.

With the PrintingPolicy fix in https://reviews.llvm.org/D135295 and landed USR 
fix, the diff within ExtractAPI tests is only the wording with anonymous enums, 
and we can drop the lit change:

  658c658
  < "spelling": "(anonymous)"
  ---
  > "spelling": "enum (unnamed)"
  661c661
  < "title": "(anonymous)"
  ---
  > "title": "enum (unnamed)"
  664c664
  < "(anonymous)"
  ---
  > "enum (unnamed)"
  706c706
  < "(anonymous)",
  ---
  > "enum (unnamed)",
  746c746
  < "spelling": "(anonymous)"
  ---
  > "spelling": "enum (unnamed)"
  749c749
  < "title": "(anonymous)"
  ---
  > "title": "enum (unnamed)"
  752c752
  < "(anonymous)"
  ---
  > "enum (unnamed)"
  794c794
  < "(anonymous)",
  ---
  > "enum (unnamed)",

@dang @QuietMisdreavus for this change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D135118: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-05 Thread Argyrios Kyrtzidis 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 rG371883f46dc2: [clang/Sema] Fix non-deterministic order for 
certain kind of diagnostics (authored by akyrtzi).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135118

Files:
  clang/include/clang/AST/DeclObjC.h
  clang/include/clang/Sema/Scope.h
  clang/lib/AST/DeclObjC.cpp
  clang/lib/Sema/SemaObjCProperty.cpp
  clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
  clang/test/Sema/deterministic-diagnostics-order.m

Index: clang/test/Sema/deterministic-diagnostics-order.m
===
--- /dev/null
+++ clang/test/Sema/deterministic-diagnostics-order.m
@@ -0,0 +1,116 @@
+// RUN: %clang_cc1 %s -fsyntax-only -Wobjc-property-implementation -Watomic-property-with-user-defined-accessor -Wunused 2> %t.err
+// RUN: FileCheck -input-file=%t.err %s
+
+@interface I
+@end
+
+@interface I(cat)
+@property id prop1;
+@property id prop2;
+@property id prop3;
+@end
+
+@implementation I(cat)
+@end
+
+// CHECK: warning: property 'prop1' requires method
+// CHECK: warning: property 'prop2' requires method
+// CHECK: warning: property 'prop3' requires method
+
+@interface I2
+@property int prop1;
+@property int prop2;
+@property int prop3;
+@end
+
+@implementation I2
+@synthesize prop1, prop2, prop3;
+-(int) prop1 { return 0; }
+-(int) prop2 { return 0; }
+-(int) prop3 { return 0; }
+@end
+
+// CHECK: warning: writable atomic property 'prop1'
+// CHECK: warning: writable atomic property 'prop2'
+// CHECK: warning: writable atomic property 'prop3'
+
+void test_unused() {
+  // Add enough variables to exceed the small storage of Scope::DeclSetTy.
+  int v1;
+  int v2;
+  int v3;
+  int v4;
+  int v5;
+  int v6;
+  int v7;
+  int v8;
+  int v9;
+  int v10;
+  int v11;
+  int v12;
+  int v13;
+  int v14;
+  int v15;
+  int v16;
+  int v17;
+  int v18;
+  int v19;
+  int v20;
+  int v21;
+  int v22;
+  int v23;
+  int v24;
+  int v25;
+  int v26;
+  int v27;
+  int v28;
+  int v29;
+  int v30;
+  int v31;
+  int v32;
+  int v33;
+  int v34;
+  int v35;
+  int v36;
+  int v37;
+  int v38;
+}
+
+// CHECK: warning: unused variable 'v1'
+// CHECK: warning: unused variable 'v2'
+// CHECK: warning: unused variable 'v3'
+// CHECK: warning: unused variable 'v4'
+// CHECK: warning: unused variable 'v5'
+// CHECK: warning: unused variable 'v6'
+// CHECK: warning: unused variable 'v7'
+// CHECK: warning: unused variable 'v8'
+// CHECK: warning: unused variable 'v9'
+// CHECK: warning: unused variable 'v10'
+// CHECK: warning: unused variable 'v11'
+// CHECK: warning: unused variable 'v12'
+// CHECK: warning: unused variable 'v13'
+// CHECK: warning: unused variable 'v14'
+// CHECK: warning: unused variable 'v15'
+// CHECK: warning: unused variable 'v16'
+// CHECK: warning: unused variable 'v17'
+// CHECK: warning: unused variable 'v18'
+// CHECK: warning: unused variable 'v19'
+// CHECK: warning: unused variable 'v20'
+// CHECK: warning: unused variable 'v21'
+// CHECK: warning: unused variable 'v22'
+// CHECK: warning: unused variable 'v23'
+// CHECK: warning: unused variable 'v24'
+// CHECK: warning: unused variable 'v25'
+// CHECK: warning: unused variable 'v26'
+// CHECK: warning: unused variable 'v27'
+// CHECK: warning: unused variable 'v28'
+// CHECK: warning: unused variable 'v29'
+// CHECK: warning: unused variable 'v30'
+// CHECK: warning: unused variable 'v31'
+// CHECK: warning: unused variable 'v32'
+// CHECK: warning: unused variable 'v33'
+// CHECK: warning: unused variable 'v34'
+// CHECK: warning: unused variable 'v35'
+// CHECK: warning: unused variable 'v36'
+// CHECK: warning: unused variable 'v37'
+// CHECK: warning: unused variable 'v38'
Index: clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp
@@ -379,8 +379,7 @@
   IvarToPropMapTy IvarToPopertyMap;
 
   ObjCInterfaceDecl::PropertyMap PropMap;
-  ObjCInterfaceDecl::PropertyDeclOrder PropOrder;
-  InterfaceD->collectPropertiesToImplement(PropMap, PropOrder);
+  InterfaceD->collectPropertiesToImplement(PropMap);
 
   for (ObjCInterfaceDecl::PropertyMap::iterator
   I = PropMap.begin(), E = PropMap.end(); I != E; ++I) {
Index: clang/lib/Sema/SemaObjCProperty.cpp
===
--- clang/lib/Sema/SemaObjCProperty.cpp
+++ clang/lib/Sema/SemaObjCProperty.cpp
@@ -1822,9 +1822,8 @@
 static void CollectSuperClassPropertyImplementations(ObjCInterfaceDecl *CDecl,
 ObjCInterfaceDecl::PropertyMap ) {
   if (ObjCInterfaceDecl *SDecl = CDecl->getSuperClass()) {
-

[clang] 371883f - [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

2022-10-05 Thread Argyrios Kyrtzidis via cfe-commits

Author: Argyrios Kyrtzidis
Date: 2022-10-05T12:58:01-07:00
New Revision: 371883f46dc23f8464cbf578e2d12a4f92e61917

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

LOG: [clang/Sema] Fix non-deterministic order for certain kind of diagnostics

In the context of caching clang invocations it is important to emit diagnostics 
in deterministic order;
the same clang invocation should result in the same diagnostic output.

rdar://100336989

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

Added: 
clang/test/Sema/deterministic-diagnostics-order.m

Modified: 
clang/include/clang/AST/DeclObjC.h
clang/include/clang/Sema/Scope.h
clang/lib/AST/DeclObjC.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclObjC.h 
b/clang/include/clang/AST/DeclObjC.h
index 59a2cf5de234..210b7adebe4c 100644
--- a/clang/include/clang/AST/DeclObjC.h
+++ b/clang/include/clang/AST/DeclObjC.h
@@ -25,8 +25,8 @@
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/Specifiers.h"
 #include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/STLExtras.h"
@@ -1079,16 +1079,15 @@ class ObjCContainerDecl : public NamedDecl, public 
DeclContext {
   ObjCPropertyQueryKind QueryKind) const;
 
   using PropertyMap =
-  llvm::DenseMap,
- ObjCPropertyDecl *>;
+  llvm::MapVector,
+  ObjCPropertyDecl *>;
   using ProtocolPropertySet = llvm::SmallDenseSet;
   using PropertyDeclOrder = llvm::SmallVector;
 
   /// This routine collects list of properties to be implemented in the class.
   /// This includes, class's and its conforming protocols' properties.
   /// Note, the superclass's properties are not included in the list.
-  virtual void collectPropertiesToImplement(PropertyMap ,
-PropertyDeclOrder ) const {}
+  virtual void collectPropertiesToImplement(PropertyMap ) const {}
 
   SourceLocation getAtStartLoc() const { return ObjCContainerDeclBits.AtStart; 
}
 
@@ -1780,8 +1779,7 @@ class ObjCInterfaceDecl : public ObjCContainerDecl
 *FindPropertyVisibleInPrimaryClass(IdentifierInfo *PropertyId,
ObjCPropertyQueryKind QueryKind) const;
 
-  void collectPropertiesToImplement(PropertyMap ,
-PropertyDeclOrder ) const override;
+  void collectPropertiesToImplement(PropertyMap ) const override;
 
   /// isSuperClassOf - Return true if this class is the specified class or is a
   /// super class of the specified interface class.
@@ -2246,8 +2244,7 @@ class ObjCProtocolDecl : public ObjCContainerDecl,
   ObjCProtocolDecl *getCanonicalDecl() override { return getFirstDecl(); }
   const ObjCProtocolDecl *getCanonicalDecl() const { return getFirstDecl(); }
 
-  void collectPropertiesToImplement(PropertyMap ,
-PropertyDeclOrder ) const override;
+  void collectPropertiesToImplement(PropertyMap ) const override;
 
   void collectInheritedProtocolProperties(const ObjCPropertyDecl *Property,
   ProtocolPropertySet ,

diff  --git a/clang/include/clang/Sema/Scope.h 
b/clang/include/clang/Sema/Scope.h
index 3749d925b106..04ab416bf735 100644
--- a/clang/include/clang/Sema/Scope.h
+++ b/clang/include/clang/Sema/Scope.h
@@ -16,6 +16,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/Basic/Diagnostic.h"
 #include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/iterator_range.h"
@@ -196,7 +197,7 @@ class Scope {
   /// popped, these declarations are removed from the IdentifierTable's notion
   /// of current declaration.  It is up to the current Action implementation to
   /// implement these semantics.
-  using DeclSetTy = llvm::SmallPtrSet;
+  using DeclSetTy = llvm::SmallSetVector;
   DeclSetTy DeclsInScope;
 
   /// The DeclContext with which this scope is associated. For
@@ -321,9 +322,7 @@ class Scope {
 DeclsInScope.insert(D);
   }
 
-  void RemoveDecl(Decl *D) {
-DeclsInScope.erase(D);
-  }
+  void RemoveDecl(Decl *D) { DeclsInScope.remove(D); }
 
   void incrementMSManglingNumber() {
 if (Scope *MSLMP = getMSLastManglingParent()) {
@@ -351,7 +350,9 @@ class Scope {
 
   /// isDeclScope - Return true if this is the scope that the specified decl is
   /// declared in.
-  bool isDeclScope(const Decl *D) const { return DeclsInScope.contains(D); }
+  bool isDeclScope(const Decl 

[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added a comment.

I'm pulling this on top of https://reviews.llvm.org/D135295 to try locally now.




Comment at: clang/include/clang/AST/Decl.h:3647
 
+  void printName(raw_ostream , const PrintingPolicy ) const;
+

nit: missing an `override` here. (`warning: 'printName' overrides a member 
function but is not marked 'override' [-Winconsistent-missing-override]`)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D135285: [OpenMP] Make the exec_mode global have protected visibility

2022-10-05 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa8ec170e01dd: [OpenMP] Make the exec_mode global have 
protected visibility (authored by jhuber6).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135285

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp


Index: clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
===
--- clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
+++ clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
@@ -16,10 +16,10 @@
 #define HEADER
 
 // Check that the execution mode of all 2 target regions on the gpu is set to 
NonSPMD Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l37}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l43}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l48}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l53}}_exec_mode = weak constant i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l37}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l43}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l48}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l53}}_exec_mode = weak protected constant 
i8 2
 
 #define N 1000
 #define M 10
Index: clang/test/OpenMP/nvptx_target_simd_codegen.cpp
===
--- clang/test/OpenMP/nvptx_target_simd_codegen.cpp
+++ clang/test/OpenMP/nvptx_target_simd_codegen.cpp
@@ -16,10 +16,10 @@
 #define HEADER
 
 // Check that the execution mode of all 2 target regions on the gpu is set to 
NonSPMD Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l37}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l42}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l47}}_exec_mode = weak constant i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l37}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l42}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l47}}_exec_mode = weak protected constant 
i8 2
 
 #define N 1000
 
Index: clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
===
--- clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
+++ clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
@@ -12,9 +12,9 @@
 // CHECK-DAG: [[TRANSFER_STORAGE:@.+]] = weak 
addrspace([[SHARED_ADDRSPACE:[0-9]+]]) global [32 x i32]
 
 // Check that the execution mode of all 3 target regions is set to Spmd Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l27}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak constant i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l27}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak protected constant 
i8 2
 
 template
 tx ftemplate(int n) {
Index: clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
===
--- clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
+++ clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
@@ -16,9 +16,9 @@
 #define HEADER
 
 // Check that the execution mode of all 3 target regions on the gpu is set to 
SPMD Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l29}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l33}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak constant i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l29}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l33}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak protected constant 
i8 2
 
 template
 tx ftemplate(int n) {
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -836,6 +836,7 @@
   llvm::ConstantInt::get(CGM.Int8Ty, Mode ? OMP_TGT_EXEC_MODE_SPMD
   : OMP_TGT_EXEC_MODE_GENERIC),
   

[clang] a8ec170 - [OpenMP] Make the exec_mode global have protected visibility

2022-10-05 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-10-05T14:39:22-05:00
New Revision: a8ec170e01dd0d0cbf8c059aa7addaaf3d886876

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

LOG: [OpenMP] Make the exec_mode global have protected visibility

We use protected visibility for almost everything with offloading. This
is because it provides us with the ability to read things from the host
without the expectation that it will be preempted by a shared library
load, bugs related to this have happened when offloading to the host.
This patch just makes the `exec_mode` global generated for each plugin
have protected visibility.

Reviewed By: jdoerfert

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
clang/test/OpenMP/nvptx_target_simd_codegen.cpp
clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index a44d454f9f72..e3ef331e67ee 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -836,6 +836,7 @@ static void setPropertyExecutionMode(CodeGenModule , 
StringRef Name,
   llvm::ConstantInt::get(CGM.Int8Ty, Mode ? OMP_TGT_EXEC_MODE_SPMD
   : OMP_TGT_EXEC_MODE_GENERIC),
   Twine(Name, "_exec_mode"));
+  GVMode->setVisibility(llvm::GlobalVariable::ProtectedVisibility);
   CGM.addCompilerUsedGlobal(GVMode);
 }
 

diff  --git a/clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp 
b/clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
index 71d8d7757214..0f14d687bf79 100644
--- a/clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
+++ b/clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
@@ -16,9 +16,9 @@
 #define HEADER
 
 // Check that the execution mode of all 3 target regions on the gpu is set to 
SPMD Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l29}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l33}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak constant i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l29}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l33}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak protected constant 
i8 2
 
 template
 tx ftemplate(int n) {

diff  --git a/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp 
b/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
index 4bcf8063cadc..b103e21d01de 100644
--- a/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
+++ b/clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
@@ -12,9 +12,9 @@
 // CHECK-DAG: [[TRANSFER_STORAGE:@.+]] = weak 
addrspace([[SHARED_ADDRSPACE:[0-9]+]]) global [32 x i32]
 
 // Check that the execution mode of all 3 target regions is set to Spmd Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l27}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak constant i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l27}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak protected constant 
i8 2
 
 template
 tx ftemplate(int n) {

diff  --git a/clang/test/OpenMP/nvptx_target_simd_codegen.cpp 
b/clang/test/OpenMP/nvptx_target_simd_codegen.cpp
index fadfa7f1821e..435ff7babd6c 100644
--- a/clang/test/OpenMP/nvptx_target_simd_codegen.cpp
+++ b/clang/test/OpenMP/nvptx_target_simd_codegen.cpp
@@ -16,10 +16,10 @@
 #define HEADER
 
 // Check that the execution mode of all 2 target regions on the gpu is set to 
NonSPMD Mode.
-// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l37}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l42}}_exec_mode = weak constant i8 2
-// CHECK-DAG: {{@__omp_offloading_.+l47}}_exec_mode = weak constant i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l37}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l42}}_exec_mode = weak protected constant 
i8 2
+// CHECK-DAG: {{@__omp_offloading_.+l47}}_exec_mode = weak protected constant 
i8 2
 
 #define N 1000
 

diff  --git a/clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp 

[PATCH] D135305: [Clang] Fix using LTO with the new driver in RDC-mode

2022-10-05 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, tra, yaxunl.
Herald added a subscriber: inglorion.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

The new driver supports LTO for RDC-mode compilations. However, this was
not correctly handled for non-LTO compilations. HIP can handle this as
it is fed to `lld` which will perform the LTO itself. CUDA however would
require every work which is wholly useless in non-RDC mode so it should
report an error.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135305

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/cuda-bindings.cu
  clang/test/Driver/hip-binding.hip


Index: clang/test/Driver/hip-binding.hip
===
--- clang/test/Driver/hip-binding.hip
+++ clang/test/Driver/hip-binding.hip
@@ -79,3 +79,24 @@
 // SYNTAX-ONLY: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-fsyntax-only"
 // SYNTAX-ONLY: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-fsyntax-only"
 // SYNTAX-ONLY: "-cc1" "-triple" 
"x86_64-unknown-linux-gnu"{{.*}}"-fsyntax-only"
+
+//
+// Test the bindings using the new driver in LTO-mode.
+//
+// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver 
-ccc-print-bindings \
+// RUN:--offload-arch=gfx90a --offload-arch=gfx908 -foffload-lto 
-fgpu-rdc -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LTO %s
+//  LTO: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], 
output: "[[LTO_908:.+]]"
+// LTO-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: 
"[[LTO_90A:.+]]"
+
+//
+// Check to ensure that we can use '-foffload' when not operating in RDC-mode.
+//
+// RUN: %clang -### --target=x86_64-linux-gnu -fno-gpu-rdc 
--offload-new-driver -ccc-print-bindings \
+// RUN:-foffload-lto --offload-arch=gfx90a --offload-arch=gfx908 -c %s 
2>&1 \
+// RUN: | FileCheck -check-prefix=LTO-NO-RDC %s
+//  LTO-NO-RDC: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], 
output: "[[LTO_908:.+]]"
+// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: 
["[[LTO_908]]"], output: "[[OBJ_908:.+]]"
+// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], 
output: "[[LTO_90A:.+]]"
+// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: 
["[[LTO_90A]]"], output: "[[OBJ_90A:.+]]"
+// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: 
["[[OBJ_908]]", "[[OBJ_90A]]"], output: "[[HIPFB:.+]]"
Index: clang/test/Driver/cuda-bindings.cu
===
--- clang/test/Driver/cuda-bindings.cu
+++ clang/test/Driver/cuda-bindings.cu
@@ -234,3 +234,20 @@
 // SAVE-TEMPS: "-cc1" "-triple" "nvptx64-nvidia-cuda"{{.*}}"-target-cpu" 
"sm_52"
 // SAVE-TEMPS: "-cc1" "-triple" "nvptx64-nvidia-cuda"{{.*}}"-target-cpu" 
"sm_70"
 // SAVE-TEMPS: "-cc1" "-triple" "powerpc64le-ibm-linux-gnu"
+
+//
+// Test the bindings using the new driver in LTO-mode.
+//
+// RUN: %clang -### -target powerpc64le-ibm-linux-gnu --offload-new-driver 
-ccc-print-bindings \
+// RUN:--offload-arch=sm_70 --offload-arch=sm_52 -foffload-lto 
-fgpu-rdc -c %s 2>&1 \
+// RUN: | FileCheck -check-prefix=LTO %s
+//  LTO: # "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], 
output: "[[LTO_52:.+]]"
+// LTO-NEXT: # "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]"], output: 
"[[LTO_70:.+]]"
+
+//
+// Check to ensure that we cannot use '-foffload' when not operating in 
RDC-mode.
+//
+// RUN: %clang -### -target powerpc64le-ibm-linux-gnu -fno-gpu-rdc 
--offload-new-driver \
+// RUN:-foffload-lto --offload-arch=sm_70 --offload-arch=sm_52 -c %s 
2>&1 \
+// RUN: | FileCheck -check-prefix=LTO-NO-RDC %s
+// LTO-NO-RDC: error: unsupported option '-foffload-lto' for language mode 
'-fno-gpu-rdc'
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4842,7 +4842,6 @@
   CmdArgs.push_back("-emit-llvm-uselists");
 
 if (IsUsingLTO) {
-  // Only AMDGPU supports device-side LTO.
   if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) 
&&
   !Args.hasFlag(options::OPT_offload_new_driver,
 options::OPT_no_offload_new_driver, false) &&
@@ -4852,6 +4851,12 @@
options::OPT_foffload_lto_EQ)
->getAsString(Args)
 << Triple.getTriple();
+  } else if (Triple.isNVPTX() && !IsRDCMode) {
+D.Diag(diag::err_drv_unsupported_opt_for_language_mode)
+<< Args.getLastArg(options::OPT_foffload_lto,
+   options::OPT_foffload_lto_EQ)
+   ->getAsString(Args)
+

[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw marked an inline comment as done.
zixuw added a comment.

In D135295#3837855 , @zixuw wrote:

> In D135295#3837734 , @ributzka 
> wrote:
>
>> This doesn't affect any tests?
>
> Just finished building locally, running tests to verify now

Doesn't affect any test for this patch as expected. Still need to see how does 
it interacts with https://reviews.llvm.org/D134813.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135295

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


[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 465505.
zixuw added a comment.

Update on top of the existing PrintingPolicy in the ASTContext instead of 
creating a new default one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135295

Files:
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,11 @@
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy = CI.getASTContext().getPrintingPolicy();
+  Policy.AnonymousTagLocations = false;
+  CI.getASTContext().setPrintingPolicy(Policy);
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,11 @@
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy = CI.getASTContext().getPrintingPolicy();
+  Policy.AnonymousTagLocations = false;
+  CI.getASTContext().setPrintingPolicy(Policy);
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added inline comments.



Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:854
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy(CI.getASTContext().getLangOpts());
+  Policy.AnonymousTagLocations = false;

sammccall wrote:
> nit: this isn't *just* clearing AnonymousTagLocations, but also resetting any 
> other PP flags to defaults based on LangOpts. You could getPrintingPolicy() 
> instead if you didn't intend to do this.
Makes sense. Probably doesn't matter because I'm pretty sure `PrintingPolicy` 
for ExtractAPI is just the default now. Still, good to use `getPrintingPolicy` 
to be sure


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135295

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


[PATCH] D133415: [clangd] Fix non-idempotent cases of canonicalRenameDecl()

2022-10-05 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.
sammccall marked an inline comment as done.
Closed by commit rG5f7f4846e826: [clangd] Fix non-idempotent cases of 
canonicalRenameDecl() (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D133415?vs=458424=465504#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133415

Files:
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/clangd/unittests/RenameTests.cpp


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1515,17 +1515,22 @@
 }
   )cpp",
   },
-  // FIXME: triggers an assertion failure due to a bug in canonicalization.
-  // See https://reviews.llvm.org/D132797
-#if 0
   {
   // virtual templated method
   R"cpp(
 template  class Foo { virtual void [[m]](); };
 class Bar : Foo { void [[^m]]() override; };
-  )cpp", ""
+  )cpp",
+  R"cpp(
+  #include "foo.h"
+
+  template void Foo::[[m]]() {}
+  // FIXME: not renamed as the index doesn't see this as an override of
+  // the canonical Foo::m().
+  // https://github.com/clangd/clangd/issues/1325
+  class Baz : Foo { void m() override; };
+)cpp"
   },
-#endif
   {
   // rename on constructor and destructor.
   R"cpp(
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -100,14 +100,13 @@
   return canonicalRenameDecl(Method->getParent());
 if (const FunctionDecl *InstantiatedMethod =
 Method->getInstantiatedFromMemberFunction())
-  Method = cast(InstantiatedMethod);
+  return canonicalRenameDecl(InstantiatedMethod);
 // FIXME(kirillbobyrev): For virtual methods with
 // size_overridden_methods() > 1, this will not rename all functions it
 // overrides, because this code assumes there is a single canonical
 // declaration.
-while (Method->isVirtual() && Method->size_overridden_methods())
-  Method = *Method->overridden_methods().begin();
-return Method->getCanonicalDecl();
+if (Method->isVirtual() && Method->size_overridden_methods())
+  return canonicalRenameDecl(*Method->overridden_methods().begin());
   }
   if (const auto *Function = dyn_cast(D))
 if (const FunctionTemplateDecl *Template = Function->getPrimaryTemplate())
@@ -132,8 +131,7 @@
   }
   if (const auto *VD = dyn_cast(D)) {
 if (const VarDecl *OriginalVD = VD->getInstantiatedFromStaticDataMember())
-  VD = OriginalVD;
-return VD->getCanonicalDecl();
+  return canonicalRenameDecl(OriginalVD);
   }
   return dyn_cast(D->getCanonicalDecl());
 }


Index: clang-tools-extra/clangd/unittests/RenameTests.cpp
===
--- clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1515,17 +1515,22 @@
 }
   )cpp",
   },
-  // FIXME: triggers an assertion failure due to a bug in canonicalization.
-  // See https://reviews.llvm.org/D132797
-#if 0
   {
   // virtual templated method
   R"cpp(
 template  class Foo { virtual void [[m]](); };
 class Bar : Foo { void [[^m]]() override; };
-  )cpp", ""
+  )cpp",
+  R"cpp(
+  #include "foo.h"
+
+  template void Foo::[[m]]() {}
+  // FIXME: not renamed as the index doesn't see this as an override of
+  // the canonical Foo::m().
+  // https://github.com/clangd/clangd/issues/1325
+  class Baz : Foo { void m() override; };
+)cpp"
   },
-#endif
   {
   // rename on constructor and destructor.
   R"cpp(
Index: clang-tools-extra/clangd/refactor/Rename.cpp
===
--- clang-tools-extra/clangd/refactor/Rename.cpp
+++ clang-tools-extra/clangd/refactor/Rename.cpp
@@ -100,14 +100,13 @@
   return canonicalRenameDecl(Method->getParent());
 if (const FunctionDecl *InstantiatedMethod =
 Method->getInstantiatedFromMemberFunction())
-  Method = cast(InstantiatedMethod);
+  return canonicalRenameDecl(InstantiatedMethod);
 // FIXME(kirillbobyrev): For virtual methods with
 // size_overridden_methods() > 1, this will not rename all functions it
 // overrides, because this code assumes there is a single canonical
 // declaration.
-while (Method->isVirtual() && 

[clang-tools-extra] 5f7f484 - [clangd] Fix non-idempotent cases of canonicalRenameDecl()

2022-10-05 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-10-05T21:22:08+02:00
New Revision: 5f7f4846e826f97c7f298fe419c958398d5a0386

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

LOG: [clangd] Fix non-idempotent cases of canonicalRenameDecl()

The simplest way to ensure full canonicalization is to canonicalize
recursively in most cases.

This fixes an assertion failure and presumably correctness bugs.

It does show up that D132797's index-based virtual method renames doesn't handle
templates well (the AST behavior is different and IMO better).
We could choose to disable in this case or change the index behavior,
but this patch doesn't do either.

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

Added: 


Modified: 
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index 4e367898c6bfc..22c72d6a4a6a4 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -100,14 +100,13 @@ const NamedDecl *canonicalRenameDecl(const NamedDecl *D) {
   return canonicalRenameDecl(Method->getParent());
 if (const FunctionDecl *InstantiatedMethod =
 Method->getInstantiatedFromMemberFunction())
-  Method = cast(InstantiatedMethod);
+  return canonicalRenameDecl(InstantiatedMethod);
 // FIXME(kirillbobyrev): For virtual methods with
 // size_overridden_methods() > 1, this will not rename all functions it
 // overrides, because this code assumes there is a single canonical
 // declaration.
-while (Method->isVirtual() && Method->size_overridden_methods())
-  Method = *Method->overridden_methods().begin();
-return Method->getCanonicalDecl();
+if (Method->isVirtual() && Method->size_overridden_methods())
+  return canonicalRenameDecl(*Method->overridden_methods().begin());
   }
   if (const auto *Function = dyn_cast(D))
 if (const FunctionTemplateDecl *Template = Function->getPrimaryTemplate())
@@ -132,8 +131,7 @@ const NamedDecl *canonicalRenameDecl(const NamedDecl *D) {
   }
   if (const auto *VD = dyn_cast(D)) {
 if (const VarDecl *OriginalVD = VD->getInstantiatedFromStaticDataMember())
-  VD = OriginalVD;
-return VD->getCanonicalDecl();
+  return canonicalRenameDecl(OriginalVD);
   }
   return dyn_cast(D->getCanonicalDecl());
 }

diff  --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp 
b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index 451ec37234690..00104ff470e5d 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -1515,17 +1515,22 @@ TEST(CrossFileRenameTests, WithUpToDateIndex) {
 }
   )cpp",
   },
-  // FIXME: triggers an assertion failure due to a bug in canonicalization.
-  // See https://reviews.llvm.org/D132797
-#if 0
   {
   // virtual templated method
   R"cpp(
 template  class Foo { virtual void [[m]](); };
 class Bar : Foo { void [[^m]]() override; };
-  )cpp", ""
+  )cpp",
+  R"cpp(
+  #include "foo.h"
+
+  template void Foo::[[m]]() {}
+  // FIXME: not renamed as the index doesn't see this as an override of
+  // the canonical Foo::m().
+  // https://github.com/clangd/clangd/issues/1325
+  class Baz : Foo { void m() override; };
+)cpp"
   },
-#endif
   {
   // rename on constructor and destructor.
   R"cpp(



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


[PATCH] D133415: [clangd] Fix non-idempotent cases of canonicalRenameDecl()

2022-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall marked an inline comment as done.
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/unittests/RenameTests.cpp:1521
   R"cpp(
 template  class Foo { virtual void [[m]](); };
 class Bar : Foo { void [[^m]]() override; };

ilya-biryukov wrote:
> Quick question to help better understand our current behavior. Not requesting 
> to change anything here, just wanted to make sure what we're doing now.
> 
> If we run the rename inside the primary template itself, are we going to 
> rename the use in `Bar`?
> I suspect the answer is "yes" because it's in the same file, so we get it 
> from the AST and not from the index. Just to make sure.
> 
Yes, I just checked - this example works in both directions. And indeed it's 
because the index isn't involved.

Filed https://github.com/clangd/clangd/issues/1325 for the index issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133415

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


[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added a comment.

In D135295#3837734 , @ributzka wrote:

> This doesn't affect any tests?

Just finished building locally, running tests to verify now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135295

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


[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

2022-10-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay updated this revision to Diff 465501.
MaskRay marked an inline comment as done.
MaskRay added a comment.

Make error message precise


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/Preprocessor/SOURCE_DATE_EPOCH.c

Index: clang/test/Preprocessor/SOURCE_DATE_EPOCH.c
===
--- /dev/null
+++ clang/test/Preprocessor/SOURCE_DATE_EPOCH.c
@@ -0,0 +1,32 @@
+// RUN: env SOURCE_DATE_EPOCH=0 %clang_cc1 -E %s | FileCheck %s --check-prefix=19700101
+
+// 19700101:  const char date[] = "Jan  1 1970";
+// 19700101-NEXT: const char time[] = "00:00:00";
+// 19700101-NEXT: const char timestamp[] = "Thu Jan  1 00:00:00 1970";
+
+// RUN: env SOURCE_DATE_EPOCH=2147483647 %clang_cc1 -E -Wdate-time %s 2>&1 | FileCheck %s --check-prefix=Y2038
+
+// Y2038:  warning: expansion of date or time macro is not reproducible [-Wdate-time]
+// Y2038:  const char date[] = "Jan 19 2038";
+// Y2038-NEXT: const char time[] = "03:14:07";
+// Y2038-NEXT: const char timestamp[] = "Tue Jan 19 03:14:07 2038";
+
+/// Some 32-bits systems have time64 problems.
+// RUN: %if clang-target-64-bits %{ env SOURCE_DATE_EPOCH=253402300799 %clang_cc1 -E -Wdate-time %s 2>&1 | FileCheck %s --check-prefix=1231 %}
+
+// 1231:  warning: expansion of date or time macro is not reproducible [-Wdate-time]
+// 1231:  const char date[] = "Dec 31 ";
+// 1231-NEXT: const char time[] = "23:59:59";
+// 1231-NEXT: const char timestamp[] = "Fri Dec 31 23:59:59 ";
+
+// RUN: env SOURCE_DATE_EPOCH=253402300800 not %clang_cc1 -E %s 2>&1 | FileCheck %s --check-prefix=TOOBIG
+
+// TOOBIG: error: environment variable 'SOURCE_DATE_EPOCH' ('253402300800') must be a non-negative decimal integer <= {{(2147483647|253402300799)}}
+
+// RUN: env SOURCE_DATE_EPOCH=0x0 not %clang_cc1 -E %s 2>&1 | FileCheck %s --check-prefix=NOTDECIMAL
+
+// NOTDECIMAL: error: environment variable 'SOURCE_DATE_EPOCH' ('0x0') must be a non-negative decimal integer <= {{(2147483647|253402300799)}}
+
+const char date[] = __DATE__;
+const char time[] = __TIME__;
+const char timestamp[] = __TIMESTAMP__;
Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1085,8 +1085,15 @@
 /// the identifier tokens inserted.
 static void ComputeDATE_TIME(SourceLocation , SourceLocation ,
  Preprocessor ) {
-  time_t TT = time(nullptr);
-  struct tm *TM = localtime();
+  time_t TT;
+  std::tm *TM;
+  if (PP.getPreprocessorOpts().SourceDateEpoch) {
+TT = *PP.getPreprocessorOpts().SourceDateEpoch;
+TM = std::gmtime();
+  } else {
+TT = std::time(nullptr);
+TM = std::localtime();
+  }
 
   static const char * const Months[] = {
 "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"
@@ -1593,22 +1600,24 @@
 Diag(Tok.getLocation(), diag::warn_pp_date_time);
 // MSVC, ICC, GCC, VisualAge C++ extension.  The generated string should be
 // of the form "Ddd Mmm dd hh::mm::ss ", which is returned by asctime.
-
-// Get the file that we are lexing out of.  If we're currently lexing from
-// a macro, dig into the include stack.
-const FileEntry *CurFile = nullptr;
-PreprocessorLexer *TheLexer = getCurrentFileLexer();
-
-if (TheLexer)
-  CurFile = SourceMgr.getFileEntryForID(TheLexer->getFileID());
-
 const char *Result;
-if (CurFile) {
-  time_t TT = CurFile->getModificationTime();
-  struct tm *TM = localtime();
+if (getPreprocessorOpts().SourceDateEpoch) {
+  time_t TT = *getPreprocessorOpts().SourceDateEpoch;
+  std::tm *TM = std::gmtime();
   Result = asctime(TM);
 } else {
-  Result = "??? ??? ?? ??:??:?? \n";
+  // Get the file that we are lexing out of.  If we're currently lexing from
+  // a macro, dig into the include stack.
+  const FileEntry *CurFile = nullptr;
+  if (PreprocessorLexer *TheLexer = getCurrentFileLexer())
+CurFile = SourceMgr.getFileEntryForID(TheLexer->getFileID());
+  if (CurFile) {
+time_t TT = CurFile->getModificationTime();
+struct tm *TM = localtime();
+Result = asctime(TM);
+  } else {
+Result = "??? ??? ?? ??:??:?? \n";
+  }
 }
 // Surround the string with " and strip the trailing newline.
 OS << '"' << StringRef(Result).drop_back() << '"';
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ 

[PATCH] D135300: [PowerPC] Fix types for vcipher builtins.

2022-10-05 Thread Stefan Pintilie via Phabricator via cfe-commits
stefanp created this revision.
stefanp added reviewers: nemanjai, lei.
Herald added subscribers: shchenz, kbarton.
Herald added a project: All.
stefanp requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The documentation specifies that the parameters for the vcipher builtins are
vector unsigned char
The code used
vector unsigned long long

This patch fixes the types for the vcipher builtins.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135300

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c

Index: clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
===
--- clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
+++ clang/test/CodeGen/PowerPC/builtins-ppc-crypto.c
@@ -110,38 +110,38 @@
 // CHECK: @llvm.ppc.altivec.crypto.vpermxor.be
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vcipher
-vector unsigned long long test_vcipher(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vcipher
+vector unsigned char test_vcipher(void)
 {
-  vector unsigned long long a = D_INIT1
-  vector unsigned long long b = D_INIT2
+  vector unsigned char a = B_INIT1
+  vector unsigned char b = B_INIT2
   return __builtin_altivec_crypto_vcipher(a, b);
 // CHECK: @llvm.ppc.altivec.crypto.vcipher
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vcipherlast
-vector unsigned long long test_vcipherlast(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vcipherlast
+vector unsigned char test_vcipherlast(void)
 {
-  vector unsigned long long a = D_INIT1
-  vector unsigned long long b = D_INIT2
+  vector unsigned char a = B_INIT1
+  vector unsigned char b = B_INIT2
   return __builtin_altivec_crypto_vcipherlast(a, b);
 // CHECK: @llvm.ppc.altivec.crypto.vcipherlast
 }
 
 // CHECK-LABEL: @test_vncipher
-vector unsigned long long test_vncipher(void)
+vector unsigned char test_vncipher(void)
 {
-  vector unsigned long long a = D_INIT1
-  vector unsigned long long b = D_INIT2
+  vector unsigned char a = B_INIT1
+  vector unsigned char b = B_INIT2
   return __builtin_altivec_crypto_vncipher(a, b);
 // CHECK: @llvm.ppc.altivec.crypto.vncipher
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vncipherlast
-vector unsigned long long test_vncipherlast(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vncipherlast
+vector unsigned char test_vncipherlast(void)
 {
-  vector unsigned long long a = D_INIT1
-  vector unsigned long long b = D_INIT2
+  vector unsigned char a = B_INIT1
+  vector unsigned char b = B_INIT2
   return __builtin_altivec_crypto_vncipherlast(a, b);
 // CHECK: @llvm.ppc.altivec.crypto.vncipherlast
 }
@@ -248,20 +248,20 @@
 // CHECK: @llvm.ppc.altivec.crypto.vpermxor
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vcipher_e
-vector unsigned long long test_vcipher_e(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vcipher_e
+vector unsigned char test_vcipher_e(void)
 {
-  vector unsigned long long a = D_INIT1
-  vector unsigned long long b = D_INIT2
+  vector unsigned char a = B_INIT1
+  vector unsigned char b = B_INIT2
   return __builtin_crypto_vcipher(a, b);
 // CHECK: @llvm.ppc.altivec.crypto.vcipher
 }
 
-// CHECK-LABEL: define{{.*}} <2 x i64> @test_vcipherlast_e
-vector unsigned long long test_vcipherlast_e(void)
+// CHECK-LABEL: define{{.*}} <16 x i8> @test_vcipherlast_e
+vector unsigned char test_vcipherlast_e(void)
 {
-  vector unsigned long long a = D_INIT1
-  vector unsigned long long b = D_INIT2
+  vector unsigned char a = B_INIT1
+  vector unsigned char b = B_INIT2
   return __builtin_crypto_vcipherlast(a, b);
 // CHECK: @llvm.ppc.altivec.crypto.vcipherlast
 }
@@ -291,37 +291,37 @@
 }
 
 // CHECK-LABEL: @test_vec_cipher_be
-vector unsigned long long test_vec_cipher_be(void)
+vector unsigned char test_vec_cipher_be(void)
 {
-  vector unsigned long long a = D_INIT1
-  vector unsigned long long b = D_INIT2
+  vector unsigned char a = B_INIT1
+  vector unsigned char b = B_INIT2
   return vec_cipher_be(a, b);
 // CHECK: @llvm.ppc.altivec.crypto.vcipher
 }
 
 // CHECK-LABEL: @test_vec_cipherlast_be
-vector unsigned long long test_vec_cipherlast_be(void)
+vector unsigned char test_vec_cipherlast_be(void)
 {
-  vector unsigned long long a = D_INIT1
-  vector unsigned long long b = D_INIT2
+  vector unsigned char a = B_INIT1
+  vector unsigned char b = B_INIT2
   return vec_cipherlast_be(a, b);
 // CHECK: @llvm.ppc.altivec.crypto.vcipherlast
 }
 
 // CHECK-LABEL: @test_vec_ncipher_be
-vector unsigned long long test_vec_ncipher_be(void)
+vector unsigned char test_vec_ncipher_be(void)
 {
-  vector unsigned long long a = D_INIT1
-  vector unsigned long long b = D_INIT2
+  vector unsigned char a = B_INIT1
+  vector unsigned char b = B_INIT2
   return vec_ncipher_be(a, b);
 // CHECK: @llvm.ppc.altivec.crypto.vncipher
 }
 
 // CHECK-LABEL: @test_vec_ncipherlast_be
-vector unsigned long long 

[PATCH] D135231: [clangd] Don't clone SymbolSlab::Builder arenas when finalizing.

2022-10-05 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6ea83fc98fd1: [clangd] Dont clone SymbolSlab::Builder 
arenas when finalizing. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135231

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


Index: clang-tools-extra/clangd/index/Symbol.cpp
===
--- clang-tools-extra/clangd/index/Symbol.cpp
+++ clang-tools-extra/clangd/index/Symbol.cpp
@@ -61,12 +61,9 @@
 SortedSymbols.push_back(std::move(Entry.second));
   llvm::sort(SortedSymbols,
  [](const Symbol , const Symbol ) { return L.ID < R.ID; });
-  // We may have unused strings from overwritten symbols. Build a new arena.
-  llvm::BumpPtrAllocator NewArena;
-  llvm::UniqueStringSaver Strings(NewArena);
-  for (auto  : SortedSymbols)
-own(S, Strings);
-  return SymbolSlab(std::move(NewArena), std::move(SortedSymbols));
+  // We may have unused strings from overwritten symbols.
+  // In practice, these are extremely small, it's not worth compacting.
+  return SymbolSlab(std::move(Arena), std::move(SortedSymbols));
 }
 
 llvm::raw_ostream <<(llvm::raw_ostream , const SymbolSlab ) {


Index: clang-tools-extra/clangd/index/Symbol.cpp
===
--- clang-tools-extra/clangd/index/Symbol.cpp
+++ clang-tools-extra/clangd/index/Symbol.cpp
@@ -61,12 +61,9 @@
 SortedSymbols.push_back(std::move(Entry.second));
   llvm::sort(SortedSymbols,
  [](const Symbol , const Symbol ) { return L.ID < R.ID; });
-  // We may have unused strings from overwritten symbols. Build a new arena.
-  llvm::BumpPtrAllocator NewArena;
-  llvm::UniqueStringSaver Strings(NewArena);
-  for (auto  : SortedSymbols)
-own(S, Strings);
-  return SymbolSlab(std::move(NewArena), std::move(SortedSymbols));
+  // We may have unused strings from overwritten symbols.
+  // In practice, these are extremely small, it's not worth compacting.
+  return SymbolSlab(std::move(Arena), std::move(SortedSymbols));
 }
 
 llvm::raw_ostream <<(llvm::raw_ostream , const SymbolSlab ) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 6ea83fc - [clangd] Don't clone SymbolSlab::Builder arenas when finalizing.

2022-10-05 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-10-05T20:55:53+02:00
New Revision: 6ea83fc98fd120066c3c42d88c5517ab811152bc

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

LOG: [clangd] Don't clone SymbolSlab::Builder arenas when finalizing.

SymbolSlab::Builder has an arena to store strings of owned symbols, and
deduplicates them. build() copies all the strings and deduplicates them again!
This is potentially useful: we may have overwritten a symbol and
rendered some strings unreachable.

However in practice this is not the case. When testing on a variety of
files in LLVM (e.g. SemaExpr.cpp), the strings for the full preamble
index are 3MB and shrink by 0.4% (12KB). For comparison the serializde
preamble is >50MB.
There are also hundreds of smaller slabs (file sharding) that do not shrink at
all.

CPU time spent on this is significant (something like 3-5% of buildPreamble).
We're better off not bothering.

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

Added: 


Modified: 
clang-tools-extra/clangd/index/Symbol.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/Symbol.cpp 
b/clang-tools-extra/clangd/index/Symbol.cpp
index 365aceec51251..ac840a668ac2b 100644
--- a/clang-tools-extra/clangd/index/Symbol.cpp
+++ b/clang-tools-extra/clangd/index/Symbol.cpp
@@ -61,12 +61,9 @@ SymbolSlab SymbolSlab::Builder::build() && {
 SortedSymbols.push_back(std::move(Entry.second));
   llvm::sort(SortedSymbols,
  [](const Symbol , const Symbol ) { return L.ID < R.ID; });
-  // We may have unused strings from overwritten symbols. Build a new arena.
-  llvm::BumpPtrAllocator NewArena;
-  llvm::UniqueStringSaver Strings(NewArena);
-  for (auto  : SortedSymbols)
-own(S, Strings);
-  return SymbolSlab(std::move(NewArena), std::move(SortedSymbols));
+  // We may have unused strings from overwritten symbols.
+  // In practice, these are extremely small, it's not worth compacting.
+  return SymbolSlab(std::move(Arena), std::move(SortedSymbols));
 }
 
 llvm::raw_ostream <<(llvm::raw_ostream , const SymbolSlab ) {



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


[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

LG from my side assuming you're happy with the strings changing.

In D135295#3837734 , @ributzka wrote:

> This doesn't affect any tests?

This doesn't affect tests because anonymous decls currently print as the empty 
string, but will soon print as `(unnamed struct at /path/foo.cpp:4:1)` without 
this patch, or `(unnamed struct)` with this patch.




Comment at: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp:854
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy(CI.getASTContext().getLangOpts());
+  Policy.AnonymousTagLocations = false;

nit: this isn't *just* clearing AnonymousTagLocations, but also resetting any 
other PP flags to defaults based on LangOpts. You could getPrintingPolicy() 
instead if you didn't intend to do this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135295

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


[PATCH] D129156: Add -fpass-plugin option to Flang

2022-10-05 Thread Valentin Clement via Phabricator via cfe-commits
clementval added a comment.

As @awarzynski mentioned, it is likely a missing dependency on the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129156

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


[PATCH] D135226: [clangd] Optimize Dex::generateProximityURIs().

2022-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/index/dex/Dex.cpp:358
+// Returns^
+const char *findPathInURI(const char *S) {
+  // Skip over scheme.

adamcz wrote:
> Is there a reason why you're doing this with manual manipulation of C-strings 
> instead of StringRefs? I suspect passing StringRef here was not the problem, 
> turning it into an std::string, from another std::string inside ParsedURI was.
> 
> Something like:
> S = S.drop_while([](char c) { return c == ':'; });
> S.consume_front(":");
> if (S.consume_front("//")) {
>   S = S.drop_while([](char c) { return c == '/'; });
>   S.consume_front("/");
> }
> 
> return S;
> 
> would be a bit more readable and less likely to have an off-by-one somewhere, 
> imho.
I started with StringRef, and found it too awkward. I've changed it back, but I 
think it makes the main algorithm harder to understand (it's OK for 
findPathInURI, but mixing styles is more confusing for me).

StringRef is good at modelling range content or two pointers, but this 
algorithm is fundamentally about three pointers and uses (Begin, End) and 
(Path, End) equally. So you end up with too many degrees of freedom in the code 
and have to paper over with assertions.
And StringRef's API is mostly suited for manipulating content, not dealing with 
overlapping refs, so you end up with a mix of index+pointer+stringref that 
personally I find harder to understand.

I'm probably an outlier here, so converted it to use StringRef anyway


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135226

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


[PATCH] D135226: [clangd] Optimize Dex::generateProximityURIs().

2022-10-05 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 465492.
sammccall added a comment.

pointers -> StringRef


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135226

Files:
  clang-tools-extra/clangd/index/dex/Dex.cpp
  clang-tools-extra/clangd/index/dex/Dex.h

Index: clang-tools-extra/clangd/index/dex/Dex.h
===
--- clang-tools-extra/clangd/index/dex/Dex.h
+++ clang-tools-extra/clangd/index/dex/Dex.h
@@ -132,7 +132,7 @@
 /// Should be used within the index build process.
 ///
 /// This function is exposed for testing only.
-std::vector generateProximityURIs(llvm::StringRef URIPath);
+llvm::SmallVector generateProximityURIs(llvm::StringRef);
 
 } // namespace dex
 } // namespace clangd
Index: clang-tools-extra/clangd/index/dex/Dex.cpp
===
--- clang-tools-extra/clangd/index/dex/Dex.cpp
+++ clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -163,8 +163,8 @@
   llvm::StringMap Sources;
   for (const auto  : ProximityPaths) {
 Sources[Path] = SourceParams();
-auto PathURI = URI::create(Path);
-const auto PathProximityURIs = generateProximityURIs(PathURI.toString());
+auto PathURI = URI::create(Path).toString();
+const auto PathProximityURIs = generateProximityURIs(PathURI.c_str());
 for (const auto  : PathProximityURIs)
   ParentURIs.insert(ProximityURI);
   }
@@ -353,30 +353,49 @@
   return Bytes + BackingDataSize;
 }
 
-std::vector generateProximityURIs(llvm::StringRef URIPath) {
-  std::vector Result;
-  auto ParsedURI = URI::parse(URIPath);
-  assert(ParsedURI &&
- "Non-empty argument of generateProximityURIs() should be a valid "
- "URI.");
-  llvm::StringRef Body = ParsedURI->body();
-  // FIXME(kbobyrev): Currently, this is a heuristic which defines the maximum
-  // size of resulting vector. Some projects might want to have higher limit if
-  // the file hierarchy is deeper. For the generic case, it would be useful to
-  // calculate Limit in the index build stage by calculating the maximum depth
-  // of the project source tree at runtime.
-  size_t Limit = 5;
-  // Insert original URI before the loop: this would save a redundant iteration
-  // with a URI parse.
-  Result.emplace_back(ParsedURI->toString());
-  while (!Body.empty() && --Limit > 0) {
-// FIXME(kbobyrev): Parsing and encoding path to URIs is not necessary and
-// could be optimized.
-Body = llvm::sys::path::parent_path(Body, llvm::sys::path::Style::posix);
-if (!Body.empty())
-  Result.emplace_back(
-  URI(ParsedURI->scheme(), ParsedURI->authority(), Body).toString());
+// Given foo://bar/one/two
+// Returns  (or empty for bad URI)
+llvm::StringRef findPathInURI(llvm::StringRef S) {
+  S = S.split(':').second;   // Eat scheme.
+  if (S.consume_front("//")) // Eat authority.
+S = S.drop_until([](char C) { return C == '/'; });
+  return S;
+}
+
+// FIXME(kbobyrev): Currently, this is a heuristic which defines the maximum
+// size of resulting vector. Some projects might want to have higher limit if
+// the file hierarchy is deeper. For the generic case, it would be useful to
+// calculate Limit in the index build stage by calculating the maximum depth
+// of the project source tree at runtime.
+constexpr unsigned ProximityURILimit = 5;
+
+llvm::SmallVector
+generateProximityURIs(llvm::StringRef URI) {
+  // This function is hot when indexing, so don't parse/reserialize URIPath,
+  // just emit substrings of it instead.
+  //
+  // foo://bar/one/two
+  //  
+  //Path
+  llvm::StringRef Path = findPathInURI(URI);
+  if (Path.empty())
+return {}; // Bad URI.
+  assert(Path.begin() >= URI.begin() && Path.begin() < URI.end() &&
+ Path.end() == URI.end());
+
+  // The original is a proximity URI.
+  llvm::SmallVector Result = {URI};
+  // Form proximity URIs by chopping before each slash in the path part.
+  for (auto Slash = Path.rfind('/'); Slash > 0 && Slash != StringRef::npos;
+   Slash = Path.rfind('/')) {
+Path = Path.substr(0, Slash);
+Result.push_back(URI.substr(0, Path.end() - URI.data()));
+if (Result.size() == ProximityURILimit)
+  return Result;
   }
+  // The root foo://bar/ is a proximity URI.
+  if (Path.startswith("/"))
+Result.push_back(URI.substr(0, Path.begin() + 1 - URI.data()));
   return Result;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129156: Add -fpass-plugin option to Flang

2022-10-05 Thread Mats Petersson via Phabricator via cfe-commits
MatsPetersson added a comment.

In D129156#3837709 , @awarzynski 
wrote:

> I suspect that this fails when running `ninja check-flang`, right?
>
> Most likely `Bye` needs to be added as a dependency for Flang tests, 
> something akin to this 
> .
>   Alternatively, try adding `examples` to `! REQUIRES:` in pass-plugin.f90.

As this seems to be breaking the testing on the public servers, as well as 
locally on my machine, I've reverted the commit for now. Please feel free to 
submit an updated version, this is not a criticism of the work as such, just 
trying to keep the "build & test" green.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129156

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


[clang] 4d1460c - Revert "[flang] Add -fpass-plugin option to Flang frontend"

2022-10-05 Thread Mats Petersson via cfe-commits

Author: Mats Petersson
Date: 2022-10-05T19:43:02+01:00
New Revision: 4d1460c77d0095fb5eb974b42d96ca4f4567a7cd

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

LOG: Revert "[flang] Add -fpass-plugin option to Flang frontend"

This reverts commit 43fe6f7cc35ded691bbc2fa844086d321e705d46.

Reverting this as CI breaks.

To reproduce, run check-flang, and it will fail with an error saying
.../lib/Bye.so not found in pass-plugin.f90

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Flang.cpp
flang/docs/FlangDriver.md
flang/docs/ReleaseNotes.md
flang/include/flang/Frontend/CodeGenOptions.h
flang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/FrontendActions.cpp
flang/test/Driver/driver-help-hidden.f90
flang/test/Driver/driver-help.f90
flang/test/Driver/frontend-forwarding.f90

Removed: 
flang/test/Driver/pass-plugin-not-found.f90
flang/test/Driver/pass-plugin.f90



diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f09025d34346c..0b795184b7bd0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2710,7 +2710,7 @@ def fplugin_arg : Joined<["-"], "fplugin-arg-">,
   MetaVarName<"-">,
   HelpText<"Pass  to plugin ">;
 def fpass_plugin_EQ : Joined<["-"], "fpass-plugin=">,
-  Group, Flags<[CC1Option,FlangOption,FC1Option]>, 
MetaVarName<"">,
+  Group, Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Load pass plugin from a dynamic shared object file (only with new 
pass manager).">,
   MarshallingInfoStringVector>;
 defm preserve_as_comments : BoolFOption<"preserve-as-comments",

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 9fe83ed0886b4..b279529a33184 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -55,8 +55,7 @@ void Flang::AddOtherOptions(const ArgList , 
ArgStringList ) const {
   Args.AddAllArgs(CmdArgs,
   {options::OPT_module_dir, options::OPT_fdebug_module_writer,
options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
-   options::OPT_std_EQ, options::OPT_W_Joined,
-   options::OPT_fpass_plugin_EQ});
+   options::OPT_std_EQ, options::OPT_W_Joined});
 }
 
 void Flang::AddPicOptions(const ArgList , ArgStringList ) const {

diff  --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index b44f44efc93fa..af1fddc8f750a 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -507,28 +507,3 @@ Lastly, if `ParseTree` modifications are performed, then 
it might be necessary
 to re-analyze expressions and modify scope or symbols. You can check
 [Semantics.md](Semantics.md) for more details on how `ParseTree` is edited
 e.g. during the semantic checks.
-
-# LLVM Pass Plugins
-
-Pass plugins are dynamic shared objects that consist of one or more LLVM IR
-passes. The `-fpass-plugin` option enables these passes to be passed to the 
-middle-end where they are added to the optimization pass pipeline and run after
-lowering to LLVM IR.The exact position of the pass in the pipeline will depend 
-on how it has been registered with the `llvm::PassBuilder`. See the 
-documentation for 
-[`llvm::PassBuilder`](https://llvm.org/doxygen/classllvm_1_1PassBuilder.html)
-for details. 
-
-The framework to enable pass plugins in `flang-new` uses the exact same 
-machinery as that used by `clang` and thus has the same capabilities and
-limitations. 
-
-In order to use a pass plugin, the pass(es) must be compiled into a dynamic 
-shared object which is then loaded using the `-fpass-plugin` option. 
-
-```
-flang-new -fpass-plugin=/path/to/plugin.so 
-```
-
-This option is available in both the compiler driver and the frontend driver. 
-Note that LLVM plugins are not officially supported on Windows.

diff  --git a/flang/docs/ReleaseNotes.md b/flang/docs/ReleaseNotes.md
index 0cc85db9debc5..fd1db3b00eb83 100644
--- a/flang/docs/ReleaseNotes.md
+++ b/flang/docs/ReleaseNotes.md
@@ -24,10 +24,6 @@ page](https://llvm.org/releases/).
 
 ## Major New Features
 
-* Flang now supports loading LLVM pass plugins with the `-fpass-plugin` option
-  which is also available in clang. The option mimics the behavior of the
-  corresponding option in clang and has the same capabilities and limitations.
-
 ## Bug Fixes
 
 ## Non-comprehensive list of changes in this release

diff  --git a/flang/include/flang/Frontend/CodeGenOptions.h 
b/flang/include/flang/Frontend/CodeGenOptions.h
index 7bb10d4b0f3c8..025f67cd8e177 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.h
+++ b/flang/include/flang/Frontend/CodeGenOptions.h
@@ -46,9 

[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Juergen Ributzka via Phabricator via cfe-commits
ributzka added a comment.

This doesn't affect any tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135295

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


[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw updated this revision to Diff 465486.
zixuw added a comment.

Set PrintingPolicy properly


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135295

Files:
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,11 @@
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy(CI.getASTContext().getLangOpts());
+  Policy.AnonymousTagLocations = false;
+  CI.getASTContext().setPrintingPolicy(Policy);
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,11 @@
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  PrintingPolicy Policy(CI.getASTContext().getLangOpts());
+  Policy.AnonymousTagLocations = false;
+  CI.getASTContext().setPrintingPolicy(Policy);
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129156: Add -fpass-plugin option to Flang

2022-10-05 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

I suspect that this fails when running `ninja check-flang`, right?

Most likely `Bye` needs to be added as a dependency for Flang tests, something 
akin to this 
.
  Alternatively, try adding `examples` to `! REQUIRES:` in pass-plugin.f90.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129156

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


[PATCH] D135045: [Frontend] Recognize environment variable SOURCE_DATE_EPOCH

2022-10-05 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4313
+// 253402300799 is the UNIX timestamp of -12-31T23:59:59Z.
+if (StringRef(Epoch).getAsInteger(10, V) || V > 253402300799)
+  Diags.Report(diag::err_fe_invalid_source_date_epoch) << Epoch;

The time_t value may be negative and its value range is platform-dependent. It 
is better to be as transparent as possible. gmtime/localtime should be able to 
do the check by returning nullptr.

getAsInteger could handle V as time_t directly.



Comment at: clang/lib/Lex/PPMacroExpansion.cpp:1092
+TT = *PP.getPreprocessorOpts().SourceDateEpoch;
+TM = std::gmtime();
+  } else {

Why not use localtime as the else branch?

As mentioned above, diagnose null TM here or when parsing the user-specifed 
value. A small trade-off to make, up to you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135045

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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw added a comment.

Setting `PrintingPolicy::AnonymousTagLocations` to `false` in 
https://reviews.llvm.org/D135295


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D135295: [clang][ExtractAPI] Don't print locations for anonymous tags

2022-10-05 Thread Zixu Wang via Phabricator via cfe-commits
zixuw created this revision.
Herald added a subscriber: ributzka.
Herald added a reviewer: dang.
Herald added a reviewer: ributzka.
Herald added a project: All.
zixuw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

ExtractAPI doesn't care about locations of anonymous TagDecls. Set the
printing policy to exclude that from anonymous decl names.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135295

Files:
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,9 @@
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  CI.getASTContext().getPrintingPolicy().AnonymousTagLocations = false;
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }


Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -850,6 +850,9 @@
   CI.getPreprocessor().addPPCallbacks(std::make_unique(
   CI.getSourceManager(), *LCF, *API, CI.getPreprocessor()));
 
+  // Do not include location in anonymous decls.
+  CI.getASTContext().getPrintingPolicy().AnonymousTagLocations = false;
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135287: Disallow dereferencing of void* in C++.

2022-10-05 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D135287#3837584 , @jrtc27 wrote:

> What about `__typeof__(*p)`?

Yes, that would also be an error in C++, as it is on all other compilers.


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

https://reviews.llvm.org/D135287

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


[PATCH] D129156: Add -fpass-plugin option to Flang

2022-10-05 Thread David Truby via Phabricator via cfe-commits
DavidTruby added a comment.

This is also causing phabricator's pre-commit CI builds to fail, for example 
this build for my patch: 
https://buildkite.com/llvm-project/premerge-checks/builds/115370#0183a8a5-6684-4602-952f-81bde55220ea
Could we revert this until it is fixed? I think the CI passing is quite 
important.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129156

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


[PATCH] D129156: Add -fpass-plugin option to Flang

2022-10-05 Thread Mats Petersson via Phabricator via cfe-commits
MatsPetersson added a comment.

In D129156#3836895 , @tarunprabhu 
wrote:

> In D129156#3836838 , @clementval 
> wrote:
>
>> I probably didn't copy the error correctly .. this is the correct libs that 
>> is not found `llvm-project/build/lib/Bye.so`
>
> I need some help with this.
>
> The failing build is building flang out-of-tree. It looks like %llvmshlibdir/ 
> does not get set correctly in this case. Bye.so is located in %llvmshlibdir 
> which is within the LLVM build directory.
>
> Do you know if there is a way to tell the test-suite about %llvmshlibdir?

I'm fairly sure it is not a "out of tree" build, I'm seeing the same problem 
building in tree.
As far as I can see, there's nothing creatubg a "Bye.so" plugin. Maybe I'm 
missing something tho'


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129156

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


  1   2   3   >