[PATCH] D133634: [clang] Allow vector of BitInt

2022-09-16 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

In D133634#3795044 , @erichkeane 
wrote:

> The CFE Changes look correct, but @eli.friedman/@craig.topper should comment 
> as to whether this is acceptable.

This is acceptable to me.




Comment at: clang/lib/AST/MicrosoftMangle.cpp:3111
 Extra.mangleSourceName("__vector");
-Extra.mangleType(QualType(ET, 0), Range, QMM_Escape);
+Extra.mangleType(QualType(ET ? static_cast(ET) : BitIntTy, 
0),
+ Range, QMM_Escape);

Why is an explicit cast needed here?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133634

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


[PATCH] D134103: [clang-format] Skip token annotation in passes that don't need it

2022-09-16 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, curdeius.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134103

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnalyzer.cpp
  clang/lib/Format/TokenAnalyzer.h


Index: clang/lib/Format/TokenAnalyzer.h
===
--- clang/lib/Format/TokenAnalyzer.h
+++ clang/lib/Format/TokenAnalyzer.h
@@ -89,7 +89,8 @@
 public:
   TokenAnalyzer(const Environment , const FormatStyle );
 
-  std::pair process();
+  std::pair
+  process(bool SkipAnnotation = false);
 
 protected:
   virtual std::pair
Index: clang/lib/Format/TokenAnalyzer.cpp
===
--- clang/lib/Format/TokenAnalyzer.cpp
+++ clang/lib/Format/TokenAnalyzer.cpp
@@ -97,7 +97,8 @@
   << "\n");
 }
 
-std::pair TokenAnalyzer::process() {
+std::pair
+TokenAnalyzer::process(bool SkipAnnotation) {
   tooling::Replacements Result;
   llvm::SpecificBumpPtrAllocator Allocator;
   IdentifierTable IdentTable(getFormattingLangOpts(Style));
@@ -121,7 +122,8 @@
 TokenAnnotator Annotator(Style, Lex.getKeywords());
 for (const UnwrappedLine  : Lines) {
   AnnotatedLines.push_back(new AnnotatedLine(Line));
-  Annotator.annotate(*AnnotatedLines.back());
+  if (!SkipAnnotation)
+Annotator.annotate(*AnnotatedLines.back());
 }
 
 std::pair RunResult =
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3273,13 +3273,13 @@
 
 if (Style.InsertBraces) {
   Passes.emplace_back([&](const Environment ) {
-return BracesInserter(Env, Expanded).process();
+return BracesInserter(Env, Expanded).process(/*SkipsAnnotation=*/true);
   });
 }
 
 if (Style.RemoveBracesLLVM) {
   Passes.emplace_back([&](const Environment ) {
-return BracesRemover(Env, Expanded).process();
+return BracesRemover(Env, Expanded).process(/*SkipsAnnotation=*/true);
   });
 }
 
@@ -3305,7 +3305,8 @@
   if (Style.isJavaScript() &&
   Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) {
 Passes.emplace_back([&](const Environment ) {
-  return JavaScriptRequoter(Env, Expanded).process();
+  return JavaScriptRequoter(Env, Expanded)
+  .process(/*SkipsAnnotation=*/true);
 });
   }
 


Index: clang/lib/Format/TokenAnalyzer.h
===
--- clang/lib/Format/TokenAnalyzer.h
+++ clang/lib/Format/TokenAnalyzer.h
@@ -89,7 +89,8 @@
 public:
   TokenAnalyzer(const Environment , const FormatStyle );
 
-  std::pair process();
+  std::pair
+  process(bool SkipAnnotation = false);
 
 protected:
   virtual std::pair
Index: clang/lib/Format/TokenAnalyzer.cpp
===
--- clang/lib/Format/TokenAnalyzer.cpp
+++ clang/lib/Format/TokenAnalyzer.cpp
@@ -97,7 +97,8 @@
   << "\n");
 }
 
-std::pair TokenAnalyzer::process() {
+std::pair
+TokenAnalyzer::process(bool SkipAnnotation) {
   tooling::Replacements Result;
   llvm::SpecificBumpPtrAllocator Allocator;
   IdentifierTable IdentTable(getFormattingLangOpts(Style));
@@ -121,7 +122,8 @@
 TokenAnnotator Annotator(Style, Lex.getKeywords());
 for (const UnwrappedLine  : Lines) {
   AnnotatedLines.push_back(new AnnotatedLine(Line));
-  Annotator.annotate(*AnnotatedLines.back());
+  if (!SkipAnnotation)
+Annotator.annotate(*AnnotatedLines.back());
 }
 
 std::pair RunResult =
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -3273,13 +3273,13 @@
 
 if (Style.InsertBraces) {
   Passes.emplace_back([&](const Environment ) {
-return BracesInserter(Env, Expanded).process();
+return BracesInserter(Env, Expanded).process(/*SkipsAnnotation=*/true);
   });
 }
 
 if (Style.RemoveBracesLLVM) {
   Passes.emplace_back([&](const Environment ) {
-return BracesRemover(Env, Expanded).process();
+return BracesRemover(Env, Expanded).process(/*SkipsAnnotation=*/true);
   });
 }
 
@@ -3305,7 +3305,8 @@
   if (Style.isJavaScript() &&
   Style.JavaScriptQuotes != FormatStyle::JSQS_Leave) {
 Passes.emplace_back([&](const Environment ) {
-  return JavaScriptRequoter(Env, Expanded).process();
+  return JavaScriptRequoter(Env, Expanded)
+  .process(/*SkipsAnnotation=*/true);
 });
   }
 
___
cfe-commits mailing list

[PATCH] D134077: [RISCV] Support -mno-implicit-float.

2022-09-16 Thread Rui Zhang via Phabricator via cfe-commits
rui.zhang accepted this revision.
rui.zhang added a comment.
This revision is now accepted and ready to land.

Thanks for fixing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134077

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


[PATCH] D133634: [clang] Allow vector of BitInt

2022-09-16 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 460958.
python3kgae added a comment.

Allow BitInt vector for Microsoftmangle and add codeGen tests for BitInt vector.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133634

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/ext-int-vector-abi.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/Sema/builtin-classify-type.c
  clang/test/SemaCXX/ext-int.cpp

Index: clang/test/SemaCXX/ext-int.cpp
===
--- clang/test/SemaCXX/ext-int.cpp
+++ clang/test/SemaCXX/ext-int.cpp
@@ -84,10 +84,22 @@
 };
 
 // Reject vector types:
-// expected-error@+1{{invalid vector element type '_BitInt(32)'}}
-typedef _BitInt(32) __attribute__((vector_size(16))) VecTy;
-// expected-error@+1{{invalid vector element type '_BitInt(32)'}}
-typedef _BitInt(32) __attribute__((ext_vector_type(32))) OtherVecTy;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(2) __attribute__((vector_size(16))) VecTy;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(2) __attribute__((ext_vector_type(32))) OtherVecTy;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(4) __attribute__((vector_size(16))) VecTy2;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(4) __attribute__((ext_vector_type(32))) OtherVecTy2;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(5) __attribute__((vector_size(16))) VecTy3;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(5) __attribute__((ext_vector_type(32))) OtherVecTy3;
+// expected-error@+1{{'_BitInt' vector element width must be a power of 2}}
+typedef _BitInt(37) __attribute__((vector_size(16))) VecTy4;
+// expected-error@+1{{'_BitInt' vector element width must be a power of 2}}
+typedef _BitInt(37) __attribute__((ext_vector_type(32))) OtherVecTy4;
 
 // Allow _Complex:
 _Complex _BitInt(3) Cmplx;
Index: clang/test/Sema/builtin-classify-type.c
===
--- clang/test/Sema/builtin-classify-type.c
+++ clang/test/Sema/builtin-classify-type.c
@@ -29,6 +29,23 @@
   __attribute__((vector_size(16))) int vec;
   typedef __attribute__((ext_vector_type(4))) int evec_t;
   evec_t evec;
+  typedef _BitInt(8) int8_t3 __attribute__((ext_vector_type(3)));
+  int8_t3 t3;
+  typedef _BitInt(16) int16_t3 __attribute__((ext_vector_type(4)));
+  int16_t3 t4;
+  typedef _BitInt(32) int32_t3 __attribute__((ext_vector_type(5)));
+  int32_t3 t5;
+  typedef _BitInt(64) int64_t3 __attribute__((ext_vector_type(6)));
+  int64_t3 t6;
+  typedef _BitInt(8) vint8_t3 __attribute__((vector_size(3)));
+  vint8_t3 vt3;
+  typedef _BitInt(16) vint16_t3 __attribute__((vector_size(4)));
+  vint16_t3 vt4;
+  typedef _BitInt(32) vint32_t3 __attribute__((vector_size(8)));
+  vint32_t3 vt5;
+  typedef _BitInt(64) vint64_t3 __attribute__((vector_size(16)));
+  vint64_t3 vt6;
+
   _Atomic int atomic_i;
   _Atomic double atomic_d;
   _Complex int complex_i;
Index: clang/test/CodeGenCXX/ext-int.cpp
===
--- clang/test/CodeGenCXX/ext-int.cpp
+++ clang/test/CodeGenCXX/ext-int.cpp
@@ -129,6 +129,9 @@
   return 0;
 }
 
+typedef unsigned _BitInt(16) uint16_t4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(32) vint32_t8 __attribute__((vector_size(32)));
+
 template
 void ManglingTestTemplateParam(T&);
 template<_BitInt(99) T>
@@ -136,7 +139,6 @@
 template 
 auto ManglingDependent() -> decltype(_BitInt(N){});
 
-
 void ManglingInstantiator() {
   // LIN: define{{.*}} void @_Z20ManglingInstantiatorv()
   // WIN: define dso_local void @"?ManglingInstantiator@@YAXXZ"()
@@ -156,6 +158,12 @@
   // LIN: call signext i4 @_Z17ManglingDependentILi4EEDTtlDBT__EEv()
   // WIN64: call i4 @"??$ManglingDependent@$03@@YAU?$_BitInt@$03@__clang@@XZ"()
   // WIN32: call signext i4 @"??$ManglingDependent@$03@@YAU?$_BitInt@$03@__clang@@XZ"()
+  uint16_t4 V;
+  ManglingTestTemplateParam(V);
+  // LIN: call void @_Z25ManglingTestTemplateParamIDv4_DU16_EvRT_(<4 x i16>*
+  // WIN64: call void @"??$ManglingTestTemplateParam@T?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clangYAXAEAT?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clang@@@Z"(<4 x i16>*
+  // WIN32: call void @"??$ManglingTestTemplateParam@T?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clangYAXAAT?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clang@@@Z"(<4 x i16>*
+
 }
 
 void TakesVarargs(int i, ...) {
@@ -272,6 +280,65 @@
   

[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-09-16 Thread Peixin Qiao via Phabricator via cfe-commits
peixin added inline comments.



Comment at: flang/runtime/environment.cpp:77
+#else
+  envp = environ;
+#endif

jpenix-quic wrote:
> peixin wrote:
> > What is `environ` used for? Should we try to keep as less extern variable 
> > as possible in runtime for security.
> I think `setenv` is only required to make sure that the `environ` pointer 
> points to the correct copy of the environment variables. So, as long as we 
> are storing a copy of the environment pointer in `ExecutionEnvironment` and 
> potentially making changes to the environment via `setenv`, I think we need 
> to base it off the `environ` pointer after `setenv` has been called rather 
> than the `envp` from `main`.
> 
> That said, I don't think the `envp` variable we are storing is being used for 
> anything at the moment (reading environment variables was changed to use 
> `getenv` rather than `envp` in the commit [[ 
> https://github.com/llvm/llvm-project/commit/824bf908194c9267f1f09065ba8e41d7969006ab
>  | here]]). If removing the usage of `environ` is preferable, we could maybe 
> remove the usage of `envp` altogether (in a separate patch)--does this sound 
> like a good idea or would it be better to just leave in the `environ` usage 
> for now?
Thanks for the explanations. The current fix makes sense to me.



Comment at: flang/test/Driver/emit-mlir.f90:16
 ! CHECK-NEXT: }
+! CHECK-NEXT: fir.global @_QQEnvironmentDefaults constant : 
!fir.ref, 
!fir.ref> {
+! CHECK-NEXT:  %[[VAL_0:.*]] = fir.zero_bits !fir.ref, !fir.ref>

jpenix-quic wrote:
> peixin wrote:
> > jpenix-quic wrote:
> > > peixin wrote:
> > > > Is it possible not to generated this global variable if `fconvert=` is 
> > > > not specified?
> > > I'm not entirely sure--the issue I was running into was how to handle 
> > > this in Fortran_main.c in a way which worked for all of GCC/Clang/Visual 
> > > Studio (and maybe others?). I was originally thinking of doing this by 
> > > using a weak definition of _QQEnvironmentDefaults set to nullptr so 
> > > fconvert, etc. could override this definition without explicitly 
> > > generating the fallback case. For GCC/clang, I think I could use 
> > > __attribute__((weak)), but I wasn't sure how to handle this if someone 
> > > tried to build with Visual Studio (or maybe another toolchain). I saw a 
> > > few workarounds (ex: 
> > > https://devblogs.microsoft.com/oldnewthing/20200731-00/?p=104024) but I 
> > > shied away from this since it seems to be an undocumented feature (and 
> > > presumably only helps with Visual Studio). 
> > > 
> > > Do you know of a better or more general way I could do this? (Or, is 
> > > there non-weak symbol approach that might be better that I'm missing?)
> > How about generate one runtime function with the argument of 
> > `EnvironmentDefaultList`? This will avoid this and using one extern 
> > variable?
> > 
> > If users use one variable with bind C name `_QQEnvironmentDefaults` in 
> > fortran or one variable with name `_QQEnvironmentDefaults` in C, it is 
> > risky. Would using the runtime function and static variable with the type 
> > `EnvironmentDefaultList` in runtime be safer?
> Agreed that there are potential risks with the current approach (although, 
> are the `_Q*` names considered reserved?). Unfortunately, I think generating 
> a call to set the environment defaults requires somewhat significant changes 
> to the runtime. The runtime reads environment variables during initialization 
> in `ExecutionEnvironment::Configure` which is ultimately called from the 
> "hardcoded" `Fortran_main.c` and I need to set the defaults before this 
> happens. So, I believe I'd either have to move the initialization to 
> `_QQmain`  or make it so that `main` isn't hardcoded so that I could insert 
> the appropriate runtime function.
> 
> @klausler I think I asked you about this when I was first trying to figure 
> out how to implement the environment defaults and you suggested I try the 
> extern approach--please let me know if you have thoughts/suggestions around 
> this!
This is what @klausler suggested:
```
Instead of adding new custom APIs that let command-line options control 
behavior in a way that is redundant with the runtime environment, I suggest 
that you try a more general runtime library API by which the main program can 
specify a default environment variable setting, or a set of them. Then turn the 
command-line options into the equivalent environment settings and pass them as 
default settings that could be overridden by the actual environment.
```
If I understand correctly, what I am suggesting match his comments. The "main 
program" he means should be fortran main program, not the 
`RTNAME(ProgramStart`. In your initial patch, you add the runtime specified for 
"convert option". I think @klausler suggest you making the runtime argument 
more general used for a set of runtime environment variable settings, not 

[PATCH] D134049: [clang-format] Disallow trailing return arrows to be operators

2022-09-16 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel updated this revision to Diff 460947.
rymiel added a comment.

Address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134049

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -440,6 +440,15 @@
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause);
 
+  Tokens = annotate("template \n"
+"requires Bar || Baz\n"
+"auto foo(T) -> int;");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+  EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+  EXPECT_TRUE(Tokens[14]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow);
+
   Tokens = annotate("template \n"
 "struct S {\n"
 "  void foo() const requires Bar;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2611,8 +2611,10 @@
   }
   if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
 return Current->getPrecedence();
-  if (Current->isOneOf(tok::period, tok::arrow))
+  if (Current->isOneOf(tok::period, tok::arrow) &&
+  Current->isNot(TT_TrailingReturnArrow)) {
 return PrecedenceArrowAndPeriod;
+  }
   if ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) &&
   Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
Keywords.kw_throws)) {


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -440,6 +440,15 @@
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause);
 
+  Tokens = annotate("template \n"
+"requires Bar || Baz\n"
+"auto foo(T) -> int;");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+  EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+  EXPECT_TRUE(Tokens[14]->ClosesRequiresClause);
+  EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow);
+
   Tokens = annotate("template \n"
 "struct S {\n"
 "  void foo() const requires Bar;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2611,8 +2611,10 @@
   }
   if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
 return Current->getPrecedence();
-  if (Current->isOneOf(tok::period, tok::arrow))
+  if (Current->isOneOf(tok::period, tok::arrow) &&
+  Current->isNot(TT_TrailingReturnArrow)) {
 return PrecedenceArrowAndPeriod;
+  }
   if ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) &&
   Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
Keywords.kw_throws)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132990: [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

Oh by the way, it's missing the Release notes, but otherwise LGTM.


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

https://reviews.llvm.org/D132990

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


[PATCH] D132990: [Clang] Fix compat diagnostic to detect a nontype template parameter has a placeholder type using getContainedAutoType()

2022-09-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

ping,


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

https://reviews.llvm.org/D132990

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


[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2022-09-16 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:3377-3379
   // FIXME: This is not quite correct recovery as we don't transform SS
   // into the corresponding dependent form (and we don't diagnose missing
   // 'template' keywords within SS as a result).

Rakete wrote:
> rsmith wrote:
> > Rakete wrote:
> > > Rakete wrote:
> > > > rsmith wrote:
> > > > > This FIXME is concerning. Is this a problem with this patch? (Is the 
> > > > > FIXME wrong now?)
> > > > Yes you're right, I believe it not longer applies due to the change in 
> > > > ParseDecl.cpp in ParseDeclarationSpecifiers.
> > > Although I'm not that sure I fully understand what that comments alludes 
> > > to.
> > The example would be something like this:
> > 
> > ```
> > template struct X {
> >   template struct Y { Y(); using V = int; };
> >   template typename Y::V f();
> > };
> > template template
> > X::Y::V X::f() {} 
> > ```
> > 
> > Clang trunk today points out that the `typename` keyword is missing on the 
> > final line, but fails to point out that the `template` keyword is also 
> > missing. The reason is that in the case where that construct is valid:
> > 
> > ```
> > template template
> > X::Y::Y() {}
> > ```
> > 
> > ... we are "entering the context" of the //nested-name-specifier//, which 
> > means we don't need a `template` keyword.
> > 
> > If the FIXME is fixed, then we should diagnose the missing `template` in 
> > the above program.
> > 
> > Also, because we don't rebuild the //nested-name-specifier// as a dependent 
> > nested name specifier in this case, we fail to match it against the 
> > declaration in the class, so in my example above, we also produce an 
> > "out-of-line definition does not match" error.
> > 
> > 
> > A closely-related issue can be seen in an example such as:
> > 
> > ```
> > template struct X {
> >   template struct Y { Y(); typedef void V; }; 
> >   template typename Y::V::W f();
> > };
> > template template
> > X::template Y::V::W X::f() { return 0; } 
> > ```
> > 
> > Here, we produce a completely bogus error:
> > 
> > ```
> > :6:13: error: 'X::Y::V' (aka 'void') is not a class, namespace, or 
> > enumeration
> > X::template Y::V::W X::f() { return 0; } 
> > ^
> > ```
> > 
> > ... because we parse this in "entering context" mode and so resolve 
> > `X::Y::V` to the type in the primary template (that is, `void`). 
> > That's wrong: we should defer resolving this name to a type until we know 
> > what `T` and `U` are, or until we know that we're *actually* entering the 
> > context. Specifically, the above program can be extended as follows:
> > 
> > ```
> > template<> template<> struct X::Y {
> >   struct V { using W = int; };
> > };
> > void call(X x) { x.f(); } // OK, f returns int
> > ```
> > 
> > The above program should be accepted by this patch, if the FIXME is indeed 
> > now fixed. Please add it as a testcase :)
> Oh ok, got it thanks. So no, the program is still not accepted in clang, and 
> a pretty dumb side effect of it is that 
> 
> ```
> template struct X {
>   template struct Y { Y(); using V = int; };
>   template typename Y::V f();
> };
> template template
> X::Y::V X::f() {}
> ```
> 
> is accepted without the diagnostic for the missing `template`. :(
Currently looking into this.

It is interesting to note that for the following example in one of the parent 
comments:

```
template struct X {
  template struct Y { Y(); typedef void V; }; 
  template typename Y::V::W f();
};
template template
X::template Y::V::W X::f() { return 0; }
```

GCC doesn't like the fact that the `template` keyword is on the final line if 
compiled with `-pedantic` [0]:

```
:6:16: warning: keyword 'template' not allowed in declarator-id 
[-Wpedantic]
6 | X::template Y::V::W X::f() { return 0; }
  |^~~~
Compiler returned: 0
```

[0]: https://godbolt.org/z/dYddW3ErY


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

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


[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG52dce8900c46: [clang] Fix AST representation of expanded 
template arguments. (authored by mizvekov).

Changed prior to commit:
  https://reviews.llvm.org/D128113?vs=460907=460941#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/SemaTemplate/type_pack_element.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4793,6 +4793,44 @@
   ToD2->getDeclContext(), ToD2->getTemplateParameters()->getParam(0)));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportSubstTemplateTypeParmType) {
+  constexpr auto Code = R"(
+template  struct A {
+  using B = A1(A2...);
+};
+template struct A;
+)";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cpp");
+  auto *FromClass = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+
+  auto testType = [&](ASTContext , const char *Name,
+  llvm::Optional PackIndex) {
+const auto *Subst = selectFirst(
+"sttp", match(substTemplateTypeParmType(
+  hasReplacementType(hasCanonicalType(asString(Name
+  .bind("sttp"),
+  Ctx));
+const char *ExpectedTemplateParamName = PackIndex ? "A2" : "A1";
+ASSERT_TRUE(Subst);
+ASSERT_EQ(Subst->getReplacedParameter()->getIdentifier()->getName(),
+  ExpectedTemplateParamName);
+ASSERT_EQ(Subst->getPackIndex(), PackIndex);
+  };
+  auto tests = [&](ASTContext ) {
+testType(Ctx, "void", None);
+testType(Ctx, "char", 3);
+testType(Ctx, "float", 2);
+testType(Ctx, "int", 1);
+testType(Ctx, "short", 0);
+  };
+
+  tests(FromTU->getASTContext());
+
+  ClassTemplateSpecializationDecl *ToClass = Import(FromClass, Lang_CXX11);
+  tests(ToClass->getASTContext());
+}
+
 const AstTypeMatcher
 substTemplateTypeParmPackType;
 
Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- clang/test/SemaTemplate/type_pack_element.cpp
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -11,7 +11,7 @@
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT:   |-TemplateArgument type 'int'
 // CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
-// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
+// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar pack_index 0
 // CHECK-NEXT: |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
 // CHECK-NEXT: | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
 // CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -136,13 +136,13 @@
 };
 using t1 = foo::bind;
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar pack_index 3
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent contains_unexpanded_pack depth 0 index 0 pack
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar pack_index 2
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent contains_unexpanded_pack depth 0 index 0 pack
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar pack_index 1
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent contains_unexpanded_pack depth 0 index 0 pack
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar pack_index 0
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent contains_unexpanded_pack depth 0 index 0 pack
 

[clang] 52dce89 - [clang] Fix AST representation of expanded template arguments.

2022-09-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-17T01:24:46+02:00
New Revision: 52dce8900c46d5842a021619537ede598983dfde

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

LOG: [clang] Fix AST representation of expanded template arguments.

Extend clang's SubstTemplateTypeParm to represent the pack substitution index.

Fixes PR56099.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/JSONNodeDumper.h
clang/include/clang/AST/TextNodeDumper.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/test/AST/ast-dump-template-decls.cpp
clang/test/SemaTemplate/type_pack_element.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1ec21a7b3acec..ccc3204edd2d2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -125,6 +125,9 @@ Bug Fixes
 - Fixes to builtin template emulation of regular templates.
   `Issue 42102 `_
   `Issue 51928 `_
+- A SubstTemplateTypeParmType can now represent the pack index for a
+  substitution from an expanded pack.
+  `Issue 56099 `_
 
 
 Improvements to Clang's diagnostics

diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 14661ecc0c09c..399724159a289 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1617,10 +1617,11 @@ class ASTContext : public RefCountedBase {
QualType Wrapped);
 
   QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
-QualType Replacement) const;
-  QualType getSubstTemplateTypeParmPackType(
-  const TemplateTypeParmType *Replaced,
-const TemplateArgument );
+QualType Replacement,
+Optional PackIndex) const;
+  QualType
+  getSubstTemplateTypeParmPackType(const TemplateTypeParmType *Replaced,
+   const TemplateArgument );
 
   QualType
   getTemplateTypeParmType(unsigned Depth, unsigned Index,

diff  --git a/clang/include/clang/AST/JSONNodeDumper.h 
b/clang/include/clang/AST/JSONNodeDumper.h
index a5575d7fd441e..3597903695797 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -220,6 +220,7 @@ class JSONNodeDumper
   void VisitUnaryTransformType(const UnaryTransformType *UTT);
   void VisitTagType(const TagType *TT);
   void VisitTemplateTypeParmType(const TemplateTypeParmType *TTPT);
+  void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *STTPT);
   void VisitAutoType(const AutoType *AT);
   void VisitTemplateSpecializationType(const TemplateSpecializationType *TST);
   void VisitInjectedClassNameType(const InjectedClassNameType *ICNT);

diff  --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 2e4bcdd27a8ab..e6853b12ae7e5 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -317,6 +317,7 @@ class TextNodeDumper
   void VisitUnaryTransformType(const UnaryTransformType *T);
   void VisitTagType(const TagType *T);
   void VisitTemplateTypeParmType(const TemplateTypeParmType *T);
+  void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T);
   void VisitAutoType(const AutoType *T);
   void VisitDeducedTemplateSpecializationType(
   const DeducedTemplateSpecializationType *T);

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 5897453280729..9d3aea0a3acda 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1793,6 +1793,19 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
 unsigned NumArgs;
   };
 
+  class SubstTemplateTypeParmTypeBitfields {
+friend class SubstTemplateTypeParmType;
+
+unsigned : NumTypeBits;
+
+/// Represents the index within a pack if this represents a substitution
+/// from a pack 

[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

The reverse indexing worked great for that problem, the patch has no perf 
impact now on that `reproduction.cpp`.

That doesn't mean it doesn't have any impact in general, or that it can't be 
further improved, but other solutions will take more time to develop and we can 
revisit this later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

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


[PATCH] D134055: [clang-doc] Export enum type and value information.

2022-09-16 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

I think maybe you made the title the first line of the summary instead of the 
other way around.  I was looking for this as the title: `[clang-doc] Add 
support for explicitly typed enums`




Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:71
+
+  llvm::SmallVector AsWords;
+  AsWords.resize(WordWidth);

You can avoid the resize w/ SmallVector(Size) constructor, right?



Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:53
 
+llvm::Error decodeRecord(const Record , llvm::APSInt , llvm::StringRef 
Blob) {
+  auto ByteWidth = R[0];

brettw wrote:
> paulkirth wrote:
> > do you need to do all of this? APSInt already supports to/from string 
> > methods, as well as converting to/from integers. can you use that here and 
> > in the writer to avoid some complexity?
> I don't think converting to an integer is a good idea because people 
> sometimes use min/max values for enum values and since this could be signed 
> or unsigned, it gets kind of complicated.
> 
> Serializing a number as a string to bitcode also seemed wrong to me.
> 
> The simplest thing would be to store the value as a string in the 
> EnumValueInfo and then always treat this as a string from then on. If you 
> want it simplified, I think that's the thing to do. But I thought you would 
> want the numeric value stored in clang-doc's "ast" because some backends may 
> want to treat this as a number, check its signed/unsignedness, etc. I happy 
> to change this if you want.
Those are fair points, and I think I misread/misunderstood a bit of what's 
going on here.

As for encoding/decoding integers,  BitcodeWriter already has integer support, 
so if you need to convert to/from those, it should already work, right?

Regardless, you may want to look at the bitcode reader/writer in llvm to see 
how they serialize/deserialize APInt, as their implementation seems a bit more 
straightforward IMO.

https://github.com/llvm/llvm-project/blob/9050a59c6678789831b7286b8b68d18b966c4694/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L1636
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L2520
https://github.com/llvm/llvm-project/blob/9050a59c6678789831b7286b8b68d18b966c4694/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L2843
https://github.com/llvm/llvm-project/blob/9050a59c6678789831b7286b8b68d18b966c4694/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L2743



Comment at: clang-tools-extra/clang-doc/Representation.h:425
+  // constant. This will be empty for implicit enumeration values.
+  std::string ValueExpr;
+};

Sorry to nitpick, but SmallString was the correct choice to use in this type. 
We avoid its use as a return value, because it tends to be brittle, and stops 
us from assigning into arbitrary sized SmallStrings.  In the struct, it's a 
reasonable choice, especially if you expect most uses to be small.  for these 
expressions, I expect most to either be the number itself, or some shift 
operation, so SmallString<16> was probably more than sufficient.



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:316
+  for (const EnumConstantDecl *E : D->enumerators()) {
+SmallString<128> ValueExpr;
+if (const Expr* InitExpr = E->getInitExpr())

brettw wrote:
> paulkirth wrote:
> > why was 128 chosen? Aren't we storing it into a `SmallString<16>` in 
> > `EnumValueInfo`? is there some external reason that we expect this to be 
> > the right size? 
> > 
> > Do you have an idea for how long these are likely to be? if we expect them 
> > to be large or completely unpredictable, it may make more sense to use a 
> > `std::string` and avoid wasting stack space.
> > 
> >  
> I changed this and the EnumValueInfo struct to std::string. I think the usage 
> of SmallString in these records is over the top but I was trying to copy the 
> existing style.
small buffer optimizations significantly improve performance in the compiler 
and related tools. switching to a default string implementation that can use 
those optimizations reduced the total number of heap allocations in a normal 
run of clang by almost half. 

That's why LLVM's programmer's manual and contribution guidelines suggest using 
those whenever possible. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134055

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


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-09-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9468
+  // Control constants for math operations.
+  AddGlobal("__oclc_wavefrontsize64", Wavefront64, /*Size=*/8);
+  AddGlobal("__oclc_daz_opt", DenormAreZero, /*Size=*/8);

jhuber6 wrote:
> yaxunl wrote:
> > jhuber6 wrote:
> > > arsenm wrote:
> > > > yaxunl wrote:
> > > > > we need to disable emitting these variables for HIP -fgpu-rdc mode 
> > > > > and OpenCL since they will break per-TU control variable. Other cases 
> > > > > are OK.
> > > > wavefrontsize belongs with the system ones
> > > But the code would still depend on these and they wouldn't be present 
> > > right
> > > wavefrontsize belongs with the system ones
> > 
> > You are right. `__oclc_wavefrontsize64` should always be emitted with 
> > linkonce_odr linkage since they need to be consistent among TU's. Therefore 
> > they should always be emitted.
> > 
> > `__oclc_daz_opt`, `__oclc_finite_only_opt`, `__oclc_unsafe_math_opt`, and 
> > `__oclc_correctly_rounded_sqrt32` can be different per TU, therefore they 
> > should not be emitted for HIP `-fgpu-rdc` and OpenCL.
> I'm still unsure, if we do not emit any of those control variables how will 
> we use the device libraries for those builds.
> I'm still unsure, if we do not emit any of those control variables how will 
> we use the device libraries for those builds.

In those cases, we will use -mlink-builtin-bitcode to get those variables from 
device libs, as we did before. They will have internal linkage after linking, 
therefore are per-TU.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D133930: [clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.

2022-09-16 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 460928.
wyt added a comment.
Herald added a subscriber: carlosgalvezp.
Herald added a project: clang-tools-extra.

Update UncheckedOptionalAccessCheck.cpp.
Remove deprecated `runDataflowAnalysis`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133930

Files:
  clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -14,10 +14,8 @@
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Tooling.h"
-#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -1248,13 +1246,9 @@
  Diagnoser = UncheckedOptionalAccessDiagnoser(Options)](
 ASTContext , const CFGElement ,
 const TypeErasedDataflowAnalysisState ) mutable {
-  auto Stmt = Elt.getAs();
-  if (!Stmt) {
-return;
-  }
-  auto StmtDiagnostics =
-  Diagnoser.diagnose(Ctx, Stmt->getStmt(), State.Env);
-  llvm::move(StmtDiagnostics, std::back_inserter(Diagnostics));
+  auto EltDiagnostics =
+  Diagnoser.diagnose(Ctx, , State.Env);
+  llvm::move(EltDiagnostics, std::back_inserter(Diagnostics));
 })
 .withASTBuildArgs(
 {"-fsyntax-only", "-std=c++17", "-Wno-undefined-inline"})
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -18,8 +18,9 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
-#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Basic/SourceLocation.h"
@@ -559,41 +560,42 @@
   // lot of duplicated work (e.g. string comparisons), consider providing APIs
   // that avoid it through memoization.
   auto IgnorableOptional = ignorableOptional(Options);
-  return MatchSwitchBuilder()
+  return CFGMatchSwitchBuilder()
   // Attach a symbolic "has_value" state to optional values that we see for
   // the first time.
-  .CaseOf(
+  .CaseOfCFGStmt(
   expr(anyOf(declRefExpr(), memberExpr()), hasOptionalType()),
   initializeOptionalReference)
 
   // make_optional
-  .CaseOf(isMakeOptionalCall(), transferMakeOptionalCall)
+  .CaseOfCFGStmt(isMakeOptionalCall(), transferMakeOptionalCall)
 
   // optional::optional
-  .CaseOf(
+  .CaseOfCFGStmt(
   isOptionalInPlaceConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState ) {
 assignOptionalValue(*E, State, State.Env.getBoolLiteralValue(true));
   })
-  .CaseOf(
+  .CaseOfCFGStmt(
   isOptionalNulloptConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState ) {
 assignOptionalValue(*E, State,
 State.Env.getBoolLiteralValue(false));
   })
-  .CaseOf(isOptionalValueOrConversionConstructor(),
-transferValueOrConversionConstructor)
+  .CaseOfCFGStmt(isOptionalValueOrConversionConstructor(),
+   transferValueOrConversionConstructor)
 
   // optional::operator=
-  .CaseOf(isOptionalValueOrConversionAssignment(),
-   transferValueOrConversionAssignment)
-  .CaseOf(isOptionalNulloptAssignment(),
-   transferNulloptAssignment)
+  .CaseOfCFGStmt(
+  

[PATCH] D134089: [clang] Mention vector in the description for -mno-implict-float.

2022-09-16 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: efriedma, reames.
Herald added a subscriber: StephenFan.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As far as I understand, this disables all integer vectors too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134089

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3819,7 +3819,7 @@
 def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, 
Group, Flags<[CC1Option]>,
   HelpText<"Don't generate local calls to out-of-line atomic operations">;
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
-  HelpText<"Don't generate implicit floating point instructions">;
+  HelpText<"Don't generate implicit floating point or vector instructions">;
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, 
Flags<[CC1Option]>,
@@ -5354,7 +5354,7 @@
   HelpText<"Emit an error if a C++ static local initializer would need a guard 
variable">,
   MarshallingInfoFlag>;
 def no_implicit_float : Flag<["-"], "no-implicit-float">,
-  HelpText<"Don't generate implicit floating point instructions">,
+  HelpText<"Don't generate implicit floating point or vector instructions">,
   MarshallingInfoFlag>;
 def fdump_vtable_layouts : Flag<["-"], "fdump-vtable-layouts">,
   HelpText<"Dump the layouts of all vtables that will be emitted in a 
translation unit">,


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3819,7 +3819,7 @@
 def mno_outline_atomics : Flag<["-"], "mno-outline-atomics">, Group, Flags<[CC1Option]>,
   HelpText<"Don't generate local calls to out-of-line atomic operations">;
 def mno_implicit_float : Flag<["-"], "mno-implicit-float">, Group,
-  HelpText<"Don't generate implicit floating point instructions">;
+  HelpText<"Don't generate implicit floating point or vector instructions">;
 def mimplicit_float : Flag<["-"], "mimplicit-float">, Group;
 def mrecip : Flag<["-"], "mrecip">, Group;
 def mrecip_EQ : CommaJoined<["-"], "mrecip=">, Group, Flags<[CC1Option]>,
@@ -5354,7 +5354,7 @@
   HelpText<"Emit an error if a C++ static local initializer would need a guard variable">,
   MarshallingInfoFlag>;
 def no_implicit_float : Flag<["-"], "no-implicit-float">,
-  HelpText<"Don't generate implicit floating point instructions">,
+  HelpText<"Don't generate implicit floating point or vector instructions">,
   MarshallingInfoFlag>;
 def fdump_vtable_layouts : Flag<["-"], "fdump-vtable-layouts">,
   HelpText<"Dump the layouts of all vtables that will be emitted in a translation unit">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129755: Thread safety analysis: Support copy-elided production of scoped capabilities through arbitrary calls

2022-09-16 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D129755#3779997 , @aaron.ballman 
wrote:

> Please be sure to add a release note for the changes!

Any opinion as to what the release note might say? I'm asking since we dropped 
the documentation changes.

Perhaps I should add them back in, but without function bodies (thus 
eliminating the need to add `NO_THREAD_SAFETY_ANALYSIS`)? Something like this:

  // Same as constructors, but without tag types. (Requires C++17 copy elision.)
  static MutexLocker Lock(Mutex *mu) ACQUIRE(mu);
  static MutexLocker Adopt(Mutex *mu) REQUIRES(mu);
  static MutexLocker ReaderLock(Mutex *mu) ACQUIRE_SHARED(mu);
  static MutexLocker AdoptReaderLock(Mutex *mu) REQUIRES_SHARED(mu);
  static MutexLocker DeferLock(Mutex *mu) EXCLUDES(mu);

Then I could write in the note that this is now possible, and annotations on 
move constructors are without effect.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129755

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


[PATCH] D134081: [clang][dataflow] Remove deprecated overloads of `checkDataflow` in `TestingSupport.h`.

2022-09-16 Thread weiyi via Phabricator via cfe-commits
wyt created this revision.
Herald added subscribers: martong, mgrang, xazax.hun.
Herald added a project: All.
wyt requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134081

Files:
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -356,97 +356,6 @@
   });
 }
 
-// Deprecated.
-// FIXME: Remove this function after usage has been updated to the overload
-// which uses the `AnalysisInputs` struct.
-//
-/// Runs dataflow specified from `MakeAnalysis` on the body of the function that
-/// matches `TargetFuncMatcher` in `Code`. Given the state computed at each
-/// annotated statement, `VerifyResults` checks that the results from the
-/// analysis are correct.
-///
-/// Requirements:
-///
-///   `AnalysisT` contains a type `Lattice`.
-///
-///   `Code`, `TargetFuncMatcher`, `MakeAnalysis` and `VerifyResults` must be
-///   provided.
-///
-///   Any annotations appearing in `Code` must come after a statement.
-///
-///   There can be at most one annotation attached per statement.
-///
-///   Annotations must not be repeated.
-template 
-llvm::Error checkDataflow(
-llvm::StringRef Code,
-ast_matchers::internal::Matcher TargetFuncMatcher,
-std::function MakeAnalysis,
-std::function>>,
-ASTContext &)>
-VerifyResults,
-ArrayRef Args,
-const tooling::FileContentMappings  = {}) {
-  return checkDataflow(
-  AnalysisInputs(Code, std::move(TargetFuncMatcher),
-std::move(MakeAnalysis))
-  .withASTBuildArgs(std::move(Args))
-  .withASTBuildVirtualMappedFiles(std::move(VirtualMappedFiles)),
-  [](const llvm::StringMap> ,
-   const AnalysisOutputs ) {
-std::vector>>
-AnnotationStatesAsVector;
-for (const auto  : AnnotationStates) {
-  AnnotationStatesAsVector.push_back(
-  std::make_pair(P.first().str(), std::move(P.second)));
-}
-llvm::sort(AnnotationStatesAsVector,
-   [](auto a, auto b) { return a.first < b.first; });
-
-VerifyResults(AnnotationStatesAsVector, AO.ASTCtx);
-  });
-}
-
-// Deprecated.
-// FIXME: Remove this function after usage has been updated to the overload
-// which uses the `AnalysisInputs` struct.
-//
-/// Runs dataflow specified from `MakeAnalysis` on the body of the function
-/// named `TargetFun` in `Code`. Given the state computed at each annotated
-/// statement, `VerifyResults` checks that the results from the analysis are
-/// correct.
-///
-/// Requirements:
-///
-///   `AnalysisT` contains a type `Lattice`.
-///
-///   Any annotations appearing in `Code` must come after a statement.
-///
-///   `Code`, `TargetFun`, `MakeAnalysis` and `VerifyResults` must be provided.
-///
-///   There can be at most one annotation attached per statement.
-///
-///   Annotations must not be repeated.
-template 
-llvm::Error checkDataflow(
-llvm::StringRef Code, llvm::StringRef TargetFun,
-std::function MakeAnalysis,
-std::function>>,
-ASTContext &)>
-VerifyResults,
-ArrayRef Args,
-const tooling::FileContentMappings  = {}) {
-  return checkDataflow(
-  Code, ast_matchers::hasName(TargetFun), std::move(MakeAnalysis),
-  std::move(VerifyResults), Args, VirtualMappedFiles);
-}
-
 /// Returns the `ValueDecl` for the given identifier.
 ///
 /// Requirements:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133468: [clang] Implement divergence for TypedefType and UsingType

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 460910.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133468

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/sugar-common-types.cpp

Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -112,3 +112,22 @@
 C2 auto t26_3 = (::SB1){};
 N t26 = 0 ? t26_1 : t26_2; // expected-error {{from 'SB1' (aka 'SS1')}}
 N t27 = 0 ? t26_1 : t26_3; // expected-error {{from 'SB1' (aka 'SS1')}}
+
+using RPB1 = X1*;
+using RPX1 = RPB1;
+using RPB1 = Y1*; // redeclared
+using RPY1 = RPB1;
+N t28 = *(RPB1){}; // expected-error {{lvalue of type 'Y1' (aka 'int')}}
+auto t29 = 0 ? (RPX1){} : (RPY1){};
+N t30 = t29;  // expected-error {{lvalue of type 'RPB1' (aka 'int *')}}
+N t31 = *t29; // expected-error {{lvalue of type 'B1' (aka 'int')}}
+
+namespace A { using type1 = X1*; };
+namespace C { using A::type1; };
+using UPX1 = C::type1;
+namespace A { using type1 = Y1*; };  // redeclared
+namespace C { using A::type1; }; // redeclared
+using UPY1 = C::type1;
+auto t32 = 0 ? (UPX1){} : (UPY1){};
+N t33 = t32;  // expected-error {{lvalue of type 'C::type1' (aka 'int *')}}
+N t34 = *t32; // expected-error {{lvalue of type 'B1' (aka 'int')}}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3435,25 +3435,34 @@
 }
 
 TypedefType::TypedefType(TypeClass tc, const TypedefNameDecl *D,
- QualType underlying, QualType can)
-: Type(tc, can, toSemanticDependence(underlying->getDependence())),
+ QualType Underlying, QualType can)
+: Type(tc, can, toSemanticDependence(can->getDependence())),
   Decl(const_cast(D)) {
   assert(!isa(can) && "Invalid canonical type");
+  TypedefBits.isDivergent = !Underlying.isNull();
+  if (isDivergent())
+*reinterpret_cast(this + 1) = Underlying;
 }
 
 QualType TypedefType::desugar() const {
-  return getDecl()->getUnderlyingType();
+  return isDivergent() ? *getTrailingObjects()
+   : Decl->getUnderlyingType();
 }
 
 UsingType::UsingType(const UsingShadowDecl *Found, QualType Underlying,
  QualType Canon)
-: Type(Using, Canon, toSemanticDependence(Underlying->getDependence())),
+: Type(Using, Canon, toSemanticDependence(Canon->getDependence())),
   Found(const_cast(Found)) {
-  assert(Underlying == getUnderlyingType());
+  UsingBits.isDivergent = !Underlying.isNull();
+  if (isDivergent())
+*reinterpret_cast(this + 1) = Underlying;
 }
 
 QualType UsingType::getUnderlyingType() const {
-  return QualType(cast(Found->getTargetDecl())->getTypeForDecl(), 0);
+  return isDivergent()
+ ? *getTrailingObjects()
+ : QualType(
+   cast(Found->getTargetDecl())->getTypeForDecl(), 0);
 }
 
 QualType MacroQualifiedType::desugar() const { return getUnderlyingType(); }
Index: clang/lib/AST/TextNodeDumper.cpp
===
--- clang/lib/AST/TextNodeDumper.cpp
+++ clang/lib/AST/TextNodeDumper.cpp
@@ -1543,10 +1543,14 @@
 
 void TextNodeDumper::VisitUsingType(const UsingType *T) {
   dumpDeclRef(T->getFoundDecl());
+  if (T->isDivergent())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitTypedefType(const TypedefType *T) {
   dumpDeclRef(T->getDecl());
+  if (T->isDivergent())
+OS << " divergent";
 }
 
 void TextNodeDumper::VisitUnaryTransformType(const UnaryTransformType *T) {
Index: clang/lib/AST/JSONNodeDumper.cpp
===
--- clang/lib/AST/JSONNodeDumper.cpp
+++ clang/lib/AST/JSONNodeDumper.cpp
@@ -531,6 +531,14 @@
 
 void JSONNodeDumper::VisitTypedefType(const TypedefType *TT) {
   JOS.attribute("decl", createBareDeclRef(TT->getDecl()));
+  if (TT->isDivergent())
+JOS.attribute("type", createQualType(TT->desugar()));
+}
+
+void JSONNodeDumper::VisitUsingType(const UsingType *TT) {
+  JOS.attribute("decl", createBareDeclRef(TT->getFoundDecl()));
+  if (TT->isDivergent())
+JOS.attribute("type", createQualType(TT->desugar()));
 }
 
 void JSONNodeDumper::VisitFunctionType(const FunctionType *T) {
Index: clang/lib/AST/ASTStructuralEquivalence.cpp
===
--- clang/lib/AST/ASTStructuralEquivalence.cpp
+++ clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -957,11 

[PATCH] D132816: [clang] AST: SubstTemplateTypeParmType support for non-canonical underlying type

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 460909.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132816

Files:
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaTemplate.cpp

Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -3508,7 +3508,7 @@
   auto getSubstType = [&](QualType Replacement, unsigned IndexReplaced,
   Optional PackIndexReplaced) {
 return SemaRef.Context.getSubstTemplateTypeParmType(
-Replacement.getCanonicalType(), BTD, IndexReplaced, PackIndexReplaced);
+Replacement, BTD, IndexReplaced, PackIndexReplaced);
   };
 
   switch (BTD->getBuiltinTemplateKind()) {
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -3719,6 +3719,11 @@
 : Type(SubstTemplateTypeParm, Replacement.getCanonicalType(),
Replacement->getDependence()),
   ReplacedDecl(ReplacedDecl) {
+  SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType =
+  Replacement != getCanonicalTypeInternal();
+  if (SubstTemplateTypeParmTypeBits.HasNonCanonicalUnderlyingType)
+*getTrailingObjects() = Replacement;
+
   SubstTemplateTypeParmTypeBits.Index = Index;
   SubstTemplateTypeParmTypeBits.PackIndex = PackIndex ? *PackIndex + 1 : 0;
   assert(ReplacedDecl != nullptr);
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1529,7 +1529,7 @@
 return ToReplacementTypeOrErr.takeError();
 
   return Importer.getToContext().getSubstTemplateTypeParmType(
-  ToReplacementTypeOrErr->getCanonicalType(), *ReplacedOrErr, T->getIndex(),
+  *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(),
   T->getPackIndex());
 }
 
Index: clang/lib/AST/ASTContext.cpp
===
--- clang/lib/AST/ASTContext.cpp
+++ clang/lib/AST/ASTContext.cpp
@@ -4756,9 +4756,6 @@
 ASTContext::getSubstTemplateTypeParmType(QualType Replacement,
  Decl *ReplacedDecl, unsigned Index,
  Optional PackIndex) const {
-  assert(Replacement.isCanonical()
- && "replacement types must always be canonical");
-
   llvm::FoldingSetNodeID ID;
   SubstTemplateTypeParmType::Profile(ID, Replacement, ReplacedDecl, Index,
  PackIndex);
@@ -4767,7 +4764,10 @@
   SubstTemplateTypeParmTypes.FindNodeOrInsertPos(ID, InsertPos);
 
   if (!SubstParm) {
-SubstParm = new (*this, TypeAlignment)
+void *Mem = Allocate(SubstTemplateTypeParmType::totalSizeToAlloc(
+ !Replacement.isCanonical()),
+ TypeAlignment);
+SubstParm = new (Mem)
 SubstTemplateTypeParmType(Replacement, ReplacedDecl, Index, PackIndex);
 Types.push_back(SubstParm);
 SubstTemplateTypeParmTypes.InsertNode(SubstParm, InsertPos);
Index: clang/include/clang/AST/TypeProperties.td
===
--- clang/include/clang/AST/TypeProperties.td
+++ clang/include/clang/AST/TypeProperties.td
@@ -744,7 +744,7 @@
   // The call to getCanonicalType here existed in ASTReader.cpp, too.
   def : Creator<[{
 return ctx.getSubstTemplateTypeParmType(
-ctx.getCanonicalType(replacementType), replacedDecl, Index, PackIndex);
+replacementType, replacedDecl, Index, PackIndex);
   }]>;
 }
 
Index: clang/include/clang/AST/Type.h
===
--- clang/include/clang/AST/Type.h
+++ clang/include/clang/AST/Type.h
@@ -1798,8 +1798,10 @@
 
 unsigned : NumTypeBits;
 
+unsigned HasNonCanonicalUnderlyingType : 1;
+
 // The index of the template parameter this substitution represents.
-unsigned Index : 16;
+unsigned Index : 15;
 
 /// Represents the index within a pack if this represents a substitution
 /// from a pack expansion. This index starts at the end of the pack and
@@ -4988,8 +4990,12 @@
 /// been replaced with these.  They are used solely to record that a
 /// type was originally written as a template type parameter;
 /// therefore they are never canonical.
-class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode {
+class SubstTemplateTypeParmType final
+: public Type,
+  public llvm::FoldingSetNode,
+  private llvm::TrailingObjects {
   friend class ASTContext;
+  friend class llvm::TrailingObjects;
 
   Decl *ReplacedDecl;
 
@@ -4999,7 +5005,11 @@
 public:
   /// 

[PATCH] D131858: [clang] Track the templated entity in type substitution.

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov updated this revision to Diff 460908.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131858

Files:
  clang-tools-extra/clang-tidy/hicpp/ExceptionBaseclassCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tools-extra/clangd/AST.cpp
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Sema/Template.h
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/ODRHash.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Sema/SemaTemplateVariadic.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/lib/StaticAnalyzer/Checkers/MismatchedIteratorChecker.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant_reference.cpp
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/AST/deduction-guides.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/make_integer_seq.cpp
  clang/test/SemaTemplate/type_pack_element.cpp
  libcxx/DELETE.ME

Index: libcxx/DELETE.ME
===
--- /dev/null
+++ libcxx/DELETE.ME
@@ -0,0 +1 @@
+D131858
Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- clang/test/SemaTemplate/type_pack_element.cpp
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -11,14 +11,13 @@
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT:   |-TemplateArgument type 'int'
 // CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
-// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar pack_index 0
-// CHECK-NEXT: |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
-// CHECK-NEXT: | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
+// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar typename depth 0 index 1 ... pack_index 0
+// CHECK-NEXT: |-BuiltinTemplate 0x{{[0-9A-Fa-f]+}} '__type_pack_element'
 // CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
 
 template struct A {
   using test2 = __type_pack_element;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test2 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -38,7 +37,7 @@
 // CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test3 = __type_pack_element<0, Ts...>;
-//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, type-parameter-0-1...>'
+//  CHECK: |-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test3 '__type_pack_element<0, Ts...>':'__type_pack_element<0, type-parameter-0-1...>'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element<0, Ts...>' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
@@ -58,7 +57,7 @@
 // CHECK-NEXT:   `-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
 
   using test4 = __type_pack_element;
-//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
+//  CHECK: `-TypeAliasDecl 0x{{[0-9A-Fa-f]+}}  col:9 test4 '__type_pack_element':'__type_pack_element'
 // CHECK-NEXT:   `-ElaboratedType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent
 // CHECK-NEXT: `-TemplateSpecializationType 0x{{[0-9A-Fa-f]+}} '__type_pack_element' sugar dependent alias __type_pack_element
 // CHECK-NEXT:   |-TemplateArgument expr
Index: clang/test/SemaTemplate/make_integer_seq.cpp
===
--- 

[PATCH] D128113: Clang: fix AST representation of expanded template arguments.

2022-09-16 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov edited the summary of this revision.
mizvekov updated this revision to Diff 460907.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128113

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/JSONNodeDumper.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/AST/Type.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/AST/ast-dump-template-decls.cpp
  clang/test/SemaTemplate/type_pack_element.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4793,6 +4793,44 @@
   ToD2->getDeclContext(), ToD2->getTemplateParameters()->getParam(0)));
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportSubstTemplateTypeParmType) {
+  constexpr auto Code = R"(
+template  struct A {
+  using B = A1(A2...);
+};
+template struct A;
+)";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cpp");
+  auto *FromClass = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+
+  auto testType = [&](ASTContext , const char *Name,
+  llvm::Optional PackIndex) {
+const auto *Subst = selectFirst(
+"sttp", match(substTemplateTypeParmType(
+  hasReplacementType(hasCanonicalType(asString(Name
+  .bind("sttp"),
+  Ctx));
+const char *ExpectedTemplateParamName = PackIndex ? "A2" : "A1";
+ASSERT_TRUE(Subst);
+ASSERT_EQ(Subst->getReplacedParameter()->getIdentifier()->getName(),
+  ExpectedTemplateParamName);
+ASSERT_EQ(Subst->getPackIndex(), PackIndex);
+  };
+  auto tests = [&](ASTContext ) {
+testType(Ctx, "void", None);
+testType(Ctx, "char", 3);
+testType(Ctx, "float", 2);
+testType(Ctx, "int", 1);
+testType(Ctx, "short", 0);
+  };
+
+  tests(FromTU->getASTContext());
+
+  ClassTemplateSpecializationDecl *ToClass = Import(FromClass, Lang_CXX11);
+  tests(ToClass->getASTContext());
+}
+
 const AstTypeMatcher
 substTemplateTypeParmPackType;
 
Index: clang/test/SemaTemplate/type_pack_element.cpp
===
--- clang/test/SemaTemplate/type_pack_element.cpp
+++ clang/test/SemaTemplate/type_pack_element.cpp
@@ -11,7 +11,7 @@
 // CHECK-NEXT:   | `-IntegerLiteral 0x{{[0-9A-Fa-f]+}}  'int' 0
 // CHECK-NEXT:   |-TemplateArgument type 'int'
 // CHECK-NEXT:   | `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
-// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar
+// CHECK-NEXT:   `-SubstTemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'int' sugar pack_index 0
 // CHECK-NEXT: |-TemplateTypeParmType 0x{{[0-9A-Fa-f]+}} 'auto' dependent depth 0 index 1
 // CHECK-NEXT: | `-TemplateTypeParm 0x{{[0-9A-Fa-f]+}} ''
 // CHECK-NEXT: `-BuiltinType 0x{{[0-9A-Fa-f]+}} 'int'
Index: clang/test/AST/ast-dump-template-decls.cpp
===
--- clang/test/AST/ast-dump-template-decls.cpp
+++ clang/test/AST/ast-dump-template-decls.cpp
@@ -136,13 +136,13 @@
 };
 using t1 = foo::bind;
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar pack_index 3
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent contains_unexpanded_pack depth 0 index 0 pack
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar pack_index 2
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent contains_unexpanded_pack depth 0 index 0 pack
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar pack_index 1
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent contains_unexpanded_pack depth 0 index 0 pack
-// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar pack_index 0
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent contains_unexpanded_pack depth 0 index 0 pack
 
 template  struct D {
@@ -152,13 +152,13 @@
 // CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'B' sugar alias B
 // CHECK:  FunctionProtoType 0x{{[^ ]*}} 'int (int (*)(float, int), int (*)(char, short))' 

[PATCH] D133108: [clang] Rework IsTailPaddedMemberArray into isFlexibleArrayMemberExpr

2022-09-16 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 460899.
serge-sans-paille edited the summary of this revision.
serge-sans-paille added a comment.

Address minor nits, plus add a test case that showcases the extra (legitimate!) 
warning we now get when accessing a "struct hack" field with an index that 
cannot be represented in associated address space.

Kudos to @aaron.ballman for spotting this one!

As a comparison, current behavior for the same test case: 
https://godbolt.org/z/86Wcbrz5q (only the flexible array member is flagged with 
a warning, the struct hacks are ignored)


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

https://reviews.llvm.org/D133108

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/unbounded-array-bounds.c

Index: clang/test/Sema/unbounded-array-bounds.c
===
--- clang/test/Sema/unbounded-array-bounds.c
+++ clang/test/Sema/unbounded-array-bounds.c
@@ -84,3 +84,33 @@
 void func() {
   func + 0xdeadUL; // no crash
 }
+
+struct {
+  int _;
+  char tail[];  // addr16-note {{declared here}} addr32-note {{declared here}}
+} fam;
+
+struct {
+  int _;
+  char tail[0];  // addr16-note {{declared here}} addr32-note {{declared here}}
+} fam0;
+
+struct {
+  int _;
+  char tail[1];  // addr16-note {{declared here}} addr32-note {{declared here}}
+} fam1;
+
+void fam_ily() {
+  ++fam.tail[7073650413200313099];
+  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 8-bit (1-byte) elements (max possible 65536 elements)}}
+  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 8-bit (1-byte) elements (max possible 4294967296 elements)}}
+  // No warning for addr64 because the array index is inbound in that case.
+  ++fam0.tail[7073650413200313099];
+  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 8-bit (1-byte) elements (max possible 65536 elements)}}
+  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 8-bit (1-byte) elements (max possible 4294967296 elements)}}
+  // No warning for addr64 because the array index is inbound in that case.
+  ++fam1.tail[7073650413200313099];
+  // addr16-warning@-1 {{array index 7073650413200313099 refers past the last possible element for an array in 16-bit address space containing 8-bit (1-byte) elements (max possible 65536 elements)}}
+  // addr32-warning@-2 {{array index 7073650413200313099 refers past the last possible element for an array in 32-bit address space containing 8-bit (1-byte) elements (max possible 4294967296 elements)}}
+  // No warning for addr64 because the array index is inbound in that case.
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15891,17 +15891,24 @@
 << TRange << Op->getSourceRange();
 }
 
-/// Check whether this array fits the idiom of a size-one tail padded
-/// array member of a struct.
+/// Check whether this array fits the idiom of a flexible array member,
+/// depending on the value of -fstrict-flex-array.
 ///
-/// We avoid emitting out-of-bounds access warnings for such arrays as they are
-/// commonly used to emulate flexible arrays in C89 code.
-static bool IsTailPaddedMemberArray(Sema , const llvm::APInt ,
-const NamedDecl *ND,
-unsigned StrictFlexArraysLevel) {
+/// We avoid emitting out-of-bounds access warnings for such arrays.
+static bool isFlexibleArrayMemberExpr(Sema , const Expr *E,
+  const NamedDecl *ND,
+  unsigned StrictFlexArraysLevel) {
+
   if (!ND)
 return false;
 
+  const ConstantArrayType *ArrayTy =
+  S.Context.getAsConstantArrayType(E->getType());
+  llvm::APInt Size = ArrayTy->getSize();
+
+  if (Size == 0)
+return true;
+
   // 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...
@@ -15967,9 +15974,19 @@
   const ConstantArrayType *ArrayTy =
   Context.getAsConstantArrayType(BaseExpr->getType());
 
+  unsigned StrictFlexArraysLevel = getLangOpts().StrictFlexArrays;
+
+  const NamedDecl *ND = nullptr;
+  if (const auto *DRE = dyn_cast(BaseExpr))
+ND = DRE->getDecl();
+  else if (const auto *ME = dyn_cast(BaseExpr))
+ND = ME->getMemberDecl();
+
   const Type *BaseType =
   ArrayTy == nullptr ? nullptr : ArrayTy->getElementType().getTypePtr();
-  bool IsUnboundedArray = (BaseType 

[PATCH] D134077: [RISCV] Support -mno-implicit-float.

2022-09-16 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: asb, reames, compnerd, rui.zhang.
Herald added subscribers: sunshaoce, VincentWu, StephenFan, vkmr, evandro, 
luismarques, sameer.abuasal, s.egerton, Jim, benna, psnobl, PkmX, rogfer01, 
shiva0217, kito-cheng, simoncook, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: cfe-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.

This can be used to disable vectorization and memcpy/memset
expansion for things like OS kernels. It also disables implicit
uses of scalar FP, but I don't know if we have any of those for
RISC-V.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134077

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/flags.c


Index: clang/test/Driver/flags.c
===
--- clang/test/Driver/flags.c
+++ clang/test/Driver/flags.c
@@ -27,3 +27,9 @@
 
 // RUN: %clang -target x86_64-linux-gnu -### -c -fclang-abi-compat=3.2 %s 2>&1 
| FileCheck -check-prefix=TEST9 %s
 // TEST9: "-fclang-abi-compat=3.2"
+//
+// RUN: %clang -target riscv32 -### -S -mno-implicit-float %s 2>&1 | FileCheck 
-check-prefix=TEST10 %s
+// TEST10: "-no-implicit-float"
+//
+// RUN: %clang -target riscv64 -### -S -mno-implicit-float %s 2>&1 | FileCheck 
-check-prefix=TEST11 %s
+// TEST11: "-no-implicit-float"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2194,6 +2194,10 @@
 
   SetRISCVSmallDataLimit(getToolChain(), Args, CmdArgs);
 
+  if (!Args.hasFlag(options::OPT_mimplicit_float,
+options::OPT_mno_implicit_float, true))
+CmdArgs.push_back("-no-implicit-float");
+
   if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
 CmdArgs.push_back("-tune-cpu");
 CmdArgs.push_back(A->getValue());


Index: clang/test/Driver/flags.c
===
--- clang/test/Driver/flags.c
+++ clang/test/Driver/flags.c
@@ -27,3 +27,9 @@
 
 // RUN: %clang -target x86_64-linux-gnu -### -c -fclang-abi-compat=3.2 %s 2>&1 | FileCheck -check-prefix=TEST9 %s
 // TEST9: "-fclang-abi-compat=3.2"
+//
+// RUN: %clang -target riscv32 -### -S -mno-implicit-float %s 2>&1 | FileCheck -check-prefix=TEST10 %s
+// TEST10: "-no-implicit-float"
+//
+// RUN: %clang -target riscv64 -### -S -mno-implicit-float %s 2>&1 | FileCheck -check-prefix=TEST11 %s
+// TEST11: "-no-implicit-float"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2194,6 +2194,10 @@
 
   SetRISCVSmallDataLimit(getToolChain(), Args, CmdArgs);
 
+  if (!Args.hasFlag(options::OPT_mimplicit_float,
+options::OPT_mno_implicit_float, true))
+CmdArgs.push_back("-no-implicit-float");
+
   if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
 CmdArgs.push_back("-tune-cpu");
 CmdArgs.push_back(A->getValue());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134067: [HLSL] Enable availability attribute

2022-09-16 Thread Chris Bieneman via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG10378c45055f: [HLSL] Enable availability attribute (authored 
by beanz).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134067

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/lib/Sema/SemaAvailability.cpp
  clang/test/SemaHLSL/AvailabilityMarkup.hlsl
  clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl

Index: clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel5.0-library -verify %s
+// WaveActiveCountBits is unavailable before ShaderModel 6.0.
+
+unsigned foo(bool b) {
+// expected-warning@#site {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}}
+// expected-note@hlsl/hlsl_intrinsics.h:* {{'WaveActiveCountBits' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
+// expected-note@#site {{enclose 'WaveActiveCountBits' in a __builtin_available check to silence this warning}}
+return WaveActiveCountBits(b); // #site
+}
Index: clang/test/SemaHLSL/AvailabilityMarkup.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/AvailabilityMarkup.hlsl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-library -verify %s
+
+__attribute__((availability(shadermodel, introduced = 6.0)))
+unsigned fn6_0(); // #fn6_0
+
+__attribute__((availability(shadermodel, introduced = 5.1)))
+unsigned fn5_1(); // #fn5_1
+
+__attribute__((availability(shadermodel, introduced = 5.0)))
+unsigned fn5_0();
+
+void fn() {
+// expected-warning@#fn6_0_site {{'fn6_0' is only available on HLSL ShaderModel 6.0 or newer}}
+// expected-note@#fn6_0 {{'fn6_0' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
+// expected-note@#fn6_0_site {{enclose 'fn6_0' in a __builtin_available check to silence this warning}}
+unsigned A = fn6_0(); // #fn6_0_site
+
+// expected-warning@#fn5_1_site {{'fn5_1' is only available on HLSL ShaderModel 5.1 or newer}}
+// expected-note@#fn5_1 {{'fn5_1' has been marked as being introduced in HLSL ShaderModel 5.1 here, but the deployment target is HLSL ShaderModel 5.0}}
+// expected-note@#fn5_1_site {{enclose 'fn5_1' in a __builtin_available check to silence this warning}}
+unsigned B = fn5_1(); // #fn5_1_site
+
+unsigned C = fn5_0();
+}
+
Index: clang/lib/Sema/SemaAvailability.cpp
===
--- clang/lib/Sema/SemaAvailability.cpp
+++ clang/lib/Sema/SemaAvailability.cpp
@@ -192,6 +192,9 @@
   case llvm::Triple::MacOSX:
 ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13);
 break;
+  case llvm::Triple::ShaderModel:
+// Always enable availability diagnostics for shader models.
+return true;
   default:
 // New targets should always warn about availability.
 return Triple.getVendor() == llvm::Triple::Apple;
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,7 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+__attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
 WaveActiveCountBits(bool bBit);
 
Index: clang/lib/Basic/Targets/DirectX.h
===
--- clang/lib/Basic/Targets/DirectX.h
+++ clang/lib/Basic/Targets/DirectX.h
@@ -55,6 +55,8 @@
 HasLegalHalfType = true;
 HasFloat16 = true;
 NoAsmVariants = true;
+PlatformMinVersion = Triple.getOSVersion();
+PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
 resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
 "32-f64:64-n8:16:32:64");
 TheCXXABI.set(TargetCXXABI::Microsoft);
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -908,6 +908,7 @@
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
  .Case("swift", "Swift")
+ .Case("shadermodel", "HLSL ShaderModel")
  .Default(llvm::StringRef());
 }
 static llvm::StringRef 

[clang] 10378c4 - [HLSL] Enable availability attribute

2022-09-16 Thread Chris Bieneman via cfe-commits

Author: Chris Bieneman
Date: 2022-09-16T16:04:27-05:00
New Revision: 10378c45055fabe291138a93d79f287586948e91

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

LOG: [HLSL] Enable availability attribute

Some HLSL functionality is gated on the target shader model version.
Enabling the use of availability markup allows us to diagnose
availability issues easily in the frontend.

Reviewed By: erichkeane

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

Added: 
clang/test/SemaHLSL/AvailabilityMarkup.hlsl
clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl

Modified: 
clang/include/clang/Basic/Attr.td
clang/lib/Basic/Targets/DirectX.h
clang/lib/Headers/hlsl/hlsl_intrinsics.h
clang/lib/Sema/SemaAvailability.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index b68f3e6217694..155b87f47194c 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -908,6 +908,7 @@ def Availability : InheritableAttr {
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
  .Case("swift", "Swift")
+ .Case("shadermodel", "HLSL ShaderModel")
  .Default(llvm::StringRef());
 }
 static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) 
{
@@ -923,6 +924,7 @@ static llvm::StringRef 
getPlatformNameSourceSpelling(llvm::StringRef Platform) {
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", 
"macCatalystApplicationExtension")
  .Case("zos", "z/OS")
+ .Case("shadermodel", "ShaderModel")
  .Default(Platform);
 }
 static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
@@ -937,6 +939,7 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("watchOSApplicationExtension", "watchos_app_extension")
  .Case("macCatalyst", "maccatalyst")
  .Case("macCatalystApplicationExtension", 
"maccatalyst_app_extension")
+ .Case("ShaderModel", "shadermodel")
  .Default(Platform);
 } }];
   let HasCustomParsing = 1;

diff  --git a/clang/lib/Basic/Targets/DirectX.h 
b/clang/lib/Basic/Targets/DirectX.h
index a773090b413f7..785104373e0ad 100644
--- a/clang/lib/Basic/Targets/DirectX.h
+++ b/clang/lib/Basic/Targets/DirectX.h
@@ -55,6 +55,8 @@ class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public 
TargetInfo {
 HasLegalHalfType = true;
 HasFloat16 = true;
 NoAsmVariants = true;
+PlatformMinVersion = Triple.getOSVersion();
+PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
 resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
 "32-f64:64-n8:16:32:64");
 TheCXXABI.set(TargetCXXABI::Microsoft);

diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index f43a6ad4779a9..ab1aa74a4c5de 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,7 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+__attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) 
uint
 WaveActiveCountBits(bool bBit);
 

diff  --git a/clang/lib/Sema/SemaAvailability.cpp 
b/clang/lib/Sema/SemaAvailability.cpp
index bf4a226668f73..9ba434945e96f 100644
--- a/clang/lib/Sema/SemaAvailability.cpp
+++ b/clang/lib/Sema/SemaAvailability.cpp
@@ -192,6 +192,9 @@ shouldDiagnoseAvailabilityByDefault(const ASTContext 
,
   case llvm::Triple::MacOSX:
 ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13);
 break;
+  case llvm::Triple::ShaderModel:
+// Always enable availability diagnostics for shader models.
+return true;
   default:
 // New targets should always warn about availability.
 return Triple.getVendor() == llvm::Triple::Apple;

diff  --git a/clang/test/SemaHLSL/AvailabilityMarkup.hlsl 
b/clang/test/SemaHLSL/AvailabilityMarkup.hlsl
new file mode 100644
index 0..b883957af0871
--- /dev/null
+++ b/clang/test/SemaHLSL/AvailabilityMarkup.hlsl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-library -verify %s
+
+__attribute__((availability(shadermodel, introduced = 6.0)))
+unsigned fn6_0(); // #fn6_0
+
+__attribute__((availability(shadermodel, introduced = 5.1)))
+unsigned fn5_1(); // #fn5_1
+
+__attribute__((availability(shadermodel, introduced = 5.0)))
+unsigned fn5_0();
+
+void fn() {
+// expected-warning@#fn6_0_site {{'fn6_0' is only available on HLSL 
ShaderModel 6.0 or newer}}
+// 

[PATCH] D134042: [clang-format] Fix alignment in #else preprocessor blocks

2022-09-16 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar updated this revision to Diff 460890.
mitchell-stellar added a comment.

Added context and use verifyFormat().


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

https://reviews.llvm.org/D134042

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5743,6 +5743,69 @@
Style);
 }
 
+TEST_F(FormatTest, FormatAlignInsidePreprocessorElseBlock) {
+  FormatStyle Style = getLLVMStyleWithColumns(40);
+  Style.AlignConsecutiveAssignments.Enabled = true;
+  Style.AlignConsecutiveDeclarations.Enabled = true;
+
+  // Test with just #if blocks.
+  verifyFormat("void f1() {\n"
+   "#if 1\n"
+   "  int foo= 1;\n"
+   "  int foobar = 2;\n"
+   "#endif\n"
+   "}\n"
+   "#if 1\n"
+   "int baz = 3;\n"
+   "#endif\n"
+   "void f2() {\n"
+   "#if 1\n"
+   "  char *foobarbaz = \"foobarbaz\";\n"
+   "  int   quux  = 4;\n"
+   "}",
+   Style);
+
+  // Test with just #else blocks.
+  verifyFormat("void f1() {\n"
+   "#if 1\n"
+   "#else\n"
+   "  int foo= 1;\n"
+   "  int foobar = 2;\n"
+   "#endif\n"
+   "}\n"
+   "#if 1\n"
+   "#else\n"
+   "int baz = 3;\n"
+   "#endif\n"
+   "void f2() {\n"
+   "#if 1\n"
+   "#else\n"
+   "  char *foobarbaz = \"foobarbaz\";\n"
+   "  int   quux  = 4;\n"
+   "}",
+   Style);
+
+  // Test with a mix of #if and #else blocks.
+  verifyFormat("void f1() {\n"
+   "#if 1\n"
+   "#else\n"
+   "  int foo= 1;\n"
+   "  int foobar = 2;\n"
+   "#endif\n"
+   "}\n"
+   "#if 1\n"
+   "int baz = 3;\n"
+   "#endif\n"
+   "void f2() {\n"
+   "#if 1\n"
+   "#else\n"
+   "  // prevent alignment with #else in f1\n"
+   "  char *foobarbaz = \"foobarbaz\";\n"
+   "  int   quux  = 4;\n"
+   "}",
+   Style);
+}
+
 TEST_F(FormatTest, FormatHashIfNotAtStartOfLine) {
   verifyFormat("{\n  { a #c; }\n}");
 }
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -522,6 +522,13 @@
? Changes[StartAt].indentAndNestingLevel()
: std::tuple();
 
+  // Keep track if the first token has a non-zero indent and nesting level.
+  // This can happen when aligning the contents of "#else" preprocessor blocks,
+  // which is done separately.
+  bool HasInitialIndentAndNesting =
+  StartAt == 0 &&
+  IndentAndNestingLevel > std::tuple();
+
   // Keep track of the number of commas before the matching tokens, we will only
   // align a sequence of matching tokens if they are preceded by the same number
   // of commas.
@@ -556,8 +563,19 @@
 
   unsigned i = StartAt;
   for (unsigned e = Changes.size(); i != e; ++i) {
-if (Changes[i].indentAndNestingLevel() < IndentAndNestingLevel)
-  break;
+if (Changes[i].indentAndNestingLevel() < IndentAndNestingLevel) {
+  if (!HasInitialIndentAndNesting)
+break;
+  // The contents of preprocessor blocks are aligned separately.
+  // If the initial preprocessor block is indented or nested (e.g. it's in
+  // a function), do not align and exit after finishing this scope block.
+  // Instead, align, and then lower the baseline indent and nesting level
+  // in order to continue aligning subsequent blocks.
+  EndOfSequence = i;
+  AlignCurrentSequence();
+  IndentAndNestingLevel =
+  Changes[i].indentAndNestingLevel(); // new baseline
+}
 
 if (Changes[i].NewlinesBefore != 0) {
   CommasBeforeMatch = 0;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134055: [clang-doc] Export enum type and value information.

2022-09-16 Thread Brett Wilson via Phabricator via cfe-commits
brettw added inline comments.



Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:53
 
+llvm::Error decodeRecord(const Record , llvm::APSInt , llvm::StringRef 
Blob) {
+  auto ByteWidth = R[0];

paulkirth wrote:
> do you need to do all of this? APSInt already supports to/from string 
> methods, as well as converting to/from integers. can you use that here and in 
> the writer to avoid some complexity?
I don't think converting to an integer is a good idea because people sometimes 
use min/max values for enum values and since this could be signed or unsigned, 
it gets kind of complicated.

Serializing a number as a string to bitcode also seemed wrong to me.

The simplest thing would be to store the value as a string in the EnumValueInfo 
and then always treat this as a string from then on. If you want it simplified, 
I think that's the thing to do. But I thought you would want the numeric value 
stored in clang-doc's "ast" because some backends may want to treat this as a 
number, check its signed/unsignedness, etc. I happy to change this if you want.



Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:221
 return decodeRecord(R, I->Loc, Blob);
-  case ENUM_MEMBER:
-return decodeRecord(R, I->Members, Blob);

paulkirth wrote:
> Don't you still need this? if it's now unused, we should probably remove it 
> from the RecordId enum too.
I think this is only used for properties and not the child members, so it isn't 
used. I removed the enum.



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:185
 
+SmallString<128> getSourceCode(const Decl* D, const SourceRange& R) {
+  return Lexer::getSourceText(

paulkirth wrote:
> We normally try to avoid returning small string by value. see 
> https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallstring-h
> 
> Normally in the case that we need to return a string from a method, we just 
> use std::string. In other cases, it may be more appropriate to use an output 
> parameter instead of a return.
I was just copying some other code in this file, I changed this to std::string.



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:316
+  for (const EnumConstantDecl *E : D->enumerators()) {
+SmallString<128> ValueExpr;
+if (const Expr* InitExpr = E->getInitExpr())

paulkirth wrote:
> why was 128 chosen? Aren't we storing it into a `SmallString<16>` in 
> `EnumValueInfo`? is there some external reason that we expect this to be the 
> right size? 
> 
> Do you have an idea for how long these are likely to be? if we expect them to 
> be large or completely unpredictable, it may make more sense to use a 
> `std::string` and avoid wasting stack space.
> 
>  
I changed this and the EnumValueInfo struct to std::string. I think the usage 
of SmallString in these records is over the top but I was trying to copy the 
existing style.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134055

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


[PATCH] D134055: [clang-doc] Export enum type and value information.

2022-09-16 Thread Brett Wilson via Phabricator via cfe-commits
brettw updated this revision to Diff 460882.
brettw marked 2 inline comments as done.
brettw retitled this revision from "[clang-doc] Export more enum information" 
to "[clang-doc] Export enum type and value information.".
brettw edited the summary of this revision.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134055

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -256,7 +256,11 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
-TEST(YAMLGeneratorTest, emitEnumYAML) {
+// Tests the equivalent of:
+// namespace A {
+// enum e { X };
+// }
+TEST(YAMLGeneratorTest, emitSimpleEnumYAML) {
   EnumInfo I;
   I.Name = "e";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -265,7 +269,7 @@
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   I.Members.emplace_back("X");
-  I.Scoped = true;
+  I.Scoped = false;
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -286,9 +290,42 @@
 Location:
   - LineNumber:  12
 Filename:'test.cpp'
+Members:
+  - Name:'X'
+Value:   '0'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+// Tests the equivalent of:
+// enum class e : short { X = FOO_BAR + 2 };
+TEST(YAMLGeneratorTest, enumTypedScopedEnumYAML) {
+  EnumInfo I;
+  I.Name = "e";
+
+  I.Members.emplace_back("X", llvm::APSInt::get(-9876), "FOO_BAR + 2");
+  I.Scoped = true;
+  I.BaseType = TypeInfo("short");
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'e'
 Scoped:  true
+BaseType:
+  Type:
+Name:'short'
 Members:
-  - 'X'
+  - Name:'X'
+Value:   '-9876'
+Expr:'FOO_BAR + 2'
 ...
 )raw";
   EXPECT_EQ(Expected, Actual.str());
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -266,8 +266,8 @@
   EnumInfo E;
   E.Name = "E";
   E.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  E.Members.emplace_back("X");
-  E.Members.emplace_back("Y");
+  E.Members.emplace_back("X", llvm::APSInt::get(0));
+  E.Members.emplace_back("Y", llvm::APSInt::get(1));
   ExpectedNamespaceWithEnum.ChildEnums.emplace_back(std::move(E));
   CheckNamespaceInfo(, NamespaceWithEnum);
 
@@ -277,8 +277,8 @@
   G.Name = "G";
   G.Scoped = true;
   G.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  G.Members.emplace_back("A");
-  G.Members.emplace_back("B");
+  G.Members.emplace_back("A", llvm::APSInt::get(0));
+  G.Members.emplace_back("B", llvm::APSInt::get(1));
   ExpectedNamespaceWithScopedEnum.ChildEnums.emplace_back(std::move(G));
   CheckNamespaceInfo(, NamespaceWithScopedEnum);
 }
Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -14,6 +14,7 @@
 
 using namespace clang::doc;
 
+// These define YAML traits for decoding the listed values within a vector.
 LLVM_YAML_IS_SEQUENCE_VECTOR(FieldTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(MemberTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(Reference)
@@ -21,6 +22,7 @@
 LLVM_YAML_IS_SEQUENCE_VECTOR(CommentInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(EnumInfo)
+LLVM_YAML_IS_SEQUENCE_VECTOR(EnumValueInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(BaseRecordInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr)
 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::SmallString<16>)
@@ -226,10 +228,22 @@
   }
 };
 
+template <> struct MappingTraits {
+  static void mapping(IO , EnumValueInfo ) {
+IO.mapOptional("Name", I.Name);
+
+SmallString<16> ValueStr;
+I.Value.toString(ValueStr);
+IO.mapOptional("Value", ValueStr);
+IO.mapOptional("Expr", I.ValueExpr, std::string());
+  }
+};
+
 template <> struct 

[PATCH] D134067: [HLSL] Enable availability attribute

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Still looks good to me, no nits.  As far as using the bookmarks, I tend to use 
them for things that are 'far away' instead of 'right here', and stick to the 
@+/@- bits for 'local' ones.




Comment at: clang/test/SemaHLSL/AvailabilityMarkup.hlsl:13
+void fn() {
+// expected-warning@#fn6_0_site {{'fn6_0' is only available on HLSL 
ShaderModel 6.0 or newer}}
+// expected-note@#fn6_0 {{'fn6_0' has been marked as being introduced in 
HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}

Your preference here, but the `@+3` here is acceptable when they are 'local'.  
I have no preference either way.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134067

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


[PATCH] D134067: [HLSL] Enable availability attribute

2022-09-16 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 460879.
beanz added a comment.

Updating test cases to use labels and sort the matches.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134067

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/lib/Sema/SemaAvailability.cpp
  clang/test/SemaHLSL/AvailabilityMarkup.hlsl
  clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl

Index: clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel5.0-library -verify %s
+// WaveActiveCountBits is unavailable before ShaderModel 6.0.
+
+unsigned foo(bool b) {
+// expected-warning@#site {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}}
+// expected-note@hlsl/hlsl_intrinsics.h:* {{'WaveActiveCountBits' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
+// expected-note@#site {{enclose 'WaveActiveCountBits' in a __builtin_available check to silence this warning}}
+return WaveActiveCountBits(b); // #site
+}
Index: clang/test/SemaHLSL/AvailabilityMarkup.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/AvailabilityMarkup.hlsl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-library -verify %s
+
+__attribute__((availability(shadermodel, introduced = 6.0)))
+unsigned fn6_0(); // #fn6_0
+
+__attribute__((availability(shadermodel, introduced = 5.1)))
+unsigned fn5_1(); // #fn5_1
+
+__attribute__((availability(shadermodel, introduced = 5.0)))
+unsigned fn5_0();
+
+void fn() {
+// expected-warning@#fn6_0_site {{'fn6_0' is only available on HLSL ShaderModel 6.0 or newer}}
+// expected-note@#fn6_0 {{'fn6_0' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
+// expected-note@#fn6_0_site {{enclose 'fn6_0' in a __builtin_available check to silence this warning}}
+unsigned A = fn6_0(); // #fn6_0_site
+
+// expected-warning@#fn5_1_site {{'fn5_1' is only available on HLSL ShaderModel 5.1 or newer}}
+// expected-note@#fn5_1 {{'fn5_1' has been marked as being introduced in HLSL ShaderModel 5.1 here, but the deployment target is HLSL ShaderModel 5.0}}
+// expected-note@#fn5_1_site {{enclose 'fn5_1' in a __builtin_available check to silence this warning}}
+unsigned B = fn5_1(); // #fn5_1_site
+
+unsigned C = fn5_0();
+}
+
Index: clang/lib/Sema/SemaAvailability.cpp
===
--- clang/lib/Sema/SemaAvailability.cpp
+++ clang/lib/Sema/SemaAvailability.cpp
@@ -192,6 +192,9 @@
   case llvm::Triple::MacOSX:
 ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13);
 break;
+  case llvm::Triple::ShaderModel:
+// Always enable availability diagnostics for shader models.
+return true;
   default:
 // New targets should always warn about availability.
 return Triple.getVendor() == llvm::Triple::Apple;
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,7 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+__attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
 WaveActiveCountBits(bool bBit);
 
Index: clang/lib/Basic/Targets/DirectX.h
===
--- clang/lib/Basic/Targets/DirectX.h
+++ clang/lib/Basic/Targets/DirectX.h
@@ -55,6 +55,8 @@
 HasLegalHalfType = true;
 HasFloat16 = true;
 NoAsmVariants = true;
+PlatformMinVersion = Triple.getOSVersion();
+PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
 resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
 "32-f64:64-n8:16:32:64");
 TheCXXABI.set(TargetCXXABI::Microsoft);
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -908,6 +908,7 @@
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
  .Case("swift", "Swift")
+ .Case("shadermodel", "HLSL ShaderModel")
  .Default(llvm::StringRef());
 }
 static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
@@ -923,6 +924,7 @@
  

[PATCH] D134049: [clang-format] Disallow trailing return arrows to be operators

2022-09-16 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/TokenAnnotator.cpp:2615
+  if (Current->isOneOf(tok::period, tok::arrow) &&
+  !Current->is(TT_TrailingReturnArrow)) {
 return PrecedenceArrowAndPeriod;





Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:448
+  EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+

rymiel wrote:
> MyDeveloperDay wrote:
> > should you not check that Tokens[21] is a TT_TrailingReturnArrow?
> That's probably a good idea, thank you! (though the bug wasn't that `->` was 
> misannotated, it was still a trailing return arrow, it just caused fake 
> parentheses to be inserted earlier on)
Can you add the test for `ClosesRequiresClause`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134049

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


[PATCH] D109621: [clang] [Driver] Fall back to default.cfg when calling clang w/o prefix

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny added inline comments.



Comment at: clang/docs/UsersManual.rst:878
 Another way to specify a configuration file is to encode it in executable name.
 For example, if the Clang executable is named `armv7l-clang` (it may be a
+symbolic link to `clang`), then Clang will search for file `armv7l-clang.cfg` 
in

MaskRay wrote:
> These single backsticks probably should be double backsticks.
To be honest, I was wondering why it was done like that.


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

https://reviews.llvm.org/D109621

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


[PATCH] D109621: [clang] [Driver] Fall back to default.cfg when calling clang w/o prefix

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny updated this revision to Diff 460877.
mgorny retitled this revision from "[clang][Driver] Default to loading 
clang.cfg if config file not specified" to "[clang] [Driver] Fall back to 
default.cfg when calling clang w/o prefix".
mgorny edited the summary of this revision.
mgorny added a comment.

Changed the base config filename to `default.cfg`, and included looking up 
`default-.cfg` first. Added tests.


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

https://reviews.llvm.org/D109621

Files:
  clang/docs/UsersManual.rst
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/config-file3.c


Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -21,6 +21,10 @@
 // RUN: ln -s %clang %t/testdmode/qqq-clang-g++
 // RUN: echo "-Wundefined-func-template" > %t/testdmode/qqq-clang-g++.cfg
 // RUN: echo "-Werror" > %t/testdmode/qqq.cfg
+// RUN: ln -s %clang %t/testdmode/clang-g++
+// RUN: ln -s %clang %t/testdmode/clang
+// RUN: : > %t/testdmode/default-clang.cfg
+// RUN: : > %t/testdmode/default.cfg
 // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir= -c 
-no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix FULL-NAME
 //
 // FULL-NAME: Configuration file: {{.*}}/testdmode/qqq-clang-g++.cfg
@@ -41,6 +45,16 @@
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
 
+//--- Invoking clang falls back to default-clang.cfg.
+// RUN: %t/testdmode/clang --config-system-dir= --config-user-dir= -c 
-no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix DEFAULT-CLANG
+//
+// DEFAULT-CLANG: Configuration file: {{.*}}/testdmode/default-clang.cfg
+
+//--- Invoking clang-g++ falls back to default.cfg.
+// RUN: %t/testdmode/clang-g++ --config-system-dir= --config-user-dir= -c 
-no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix DEFAULT
+//
+// DEFAULT: Configuration file: {{.*}}/testdmode/default.cfg
+
 //--- --no-default-config disables config search.
 //
 // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= 
--config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck 
%s -check-prefix NO-DEFAULT-CONFIG
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1024,18 +1024,21 @@
 }
   }
 
-  if (!(CLOptions && CLOptions->hasArg(options::OPT_no_default_config))) {
+  if (CfgFileName.empty()) {
+if (CLOptions && CLOptions->hasArg(options::OPT_no_default_config))
+  return false;
+
 // If config file is not specified explicitly, try to deduce configuration
 // from executable name. For instance, an executable 'armv7l-clang' will
-// search for config file 'armv7l-clang.cfg'.
-if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
+// search for config file 'armv7l-clang.cfg'. If we are called without
+// a specific prefix, use e.g. 'default-clang.cfg' instead.
+if (!ClangNameParts.TargetPrefix.empty())
   CfgFileName =
   ClangNameParts.TargetPrefix + '-' + ClangNameParts.ModeSuffix;
+else
+  CfgFileName = "default-" + ClangNameParts.ModeSuffix;
   }
 
-  if (CfgFileName.empty())
-return false;
-
   // Determine architecture part of the file name, if it is present.
   StringRef CfgFileArch = CfgFileName;
   size_t ArchPrefixLen = CfgFileArch.find('-');
@@ -1093,9 +1096,9 @@
 return readConfigFile(CfgFilePath);
 
   // Finally try removing driver mode part: 'x86_64-clang.cfg' -> 'x86_64.cfg'.
-  if (!ClangNameParts.ModeSuffix.empty() &&
-  !ClangNameParts.TargetPrefix.empty()) {
-CfgFileName.assign(ClangNameParts.TargetPrefix);
+  if (!FileSpecifiedExplicitly && !ClangNameParts.ModeSuffix.empty()) {
+CfgFileName.resize(CfgFileName.size() - ClangNameParts.ModeSuffix.size() -
+   5);
 CfgFileName.append(".cfg");
 if (searchForFile(CfgFilePath, CfgFileSearchDirs, CfgFileName, getVFS()))
   return readConfigFile(CfgFilePath);
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -911,12 +911,14 @@
 Another way to specify a configuration file is to encode it in executable name.
 For example, if the Clang executable is named `armv7l-clang` (it may be a
 symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the
-directory where Clang resides.
+directory where Clang resides. If Clang is started via an executable without
+target prefix, Clang will use `default.cfg` instead.
 
 If a driver mode is specified in invocation, Clang tries to find a file 
specific
 for the specified mode. For example, if the executable file is named
 `x86_64-clang-cl`, Clang first looks for `x86_64-cl.cfg` and if it is not 
found,
-looks for 

[PATCH] D134067: [HLSL] Enable availability attribute

2022-09-16 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/test/SemaHLSL/AvailabilityMarkup.hlsl:15
+void fn() {
+// expected-warning@+2 {{'fn6_0' is only available on HLSL ShaderModel 6.0 
or newer}}
+// expected-note@+1 {{enclose 'fn6_0' in a __builtin_available check to 
silence this warning}}

erichkeane wrote:
> So minor thing, and one that I am going to start pushing for more, is better 
> organization of 'expected-diagnostics'.  I think they should better reflect 
> the order and 'cause' of the diagnostic, particularly with notes.  So 
> something like:
> 
> ``` 
>   // expected-warning@+3 {{... only available ...}}
>   // expected-note@#FN60_LOC {{ marked as being introduced...}}
>   // expected-note@+1{{enclose...}}
> ```
> 
> Then on line 5, add the comment: `// FN60`
> 
> I have this preference because it makes it more clear to the reader where the 
> notes come from.  I realize this is a new direction, and perhaps pushing my 
> ability to request, but I'd still appreciate it happening here (I WILL be 
> pushing for it on template reviews, where I think it is even MORE beneficial, 
> thanks to 'instantiation of' diagnostics, and I have the authority to demand 
> it :) ).
I was completely unaware of the ability to create labels like that. That's 
awesome. I'll update the tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134067

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


[PATCH] D134042: [clang-format] Fix alignment in #else preprocessor blocks

2022-09-16 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Please reupload the diff with the context.




Comment at: clang/unittests/Format/FormatTest.cpp:5785
+   "}";
+EXPECT_EQ(Expected, format(ToFormat, Style));
+EXPECT_EQ(Expected, format(Expected, Style));

There should be a `verifyFormat` variant fitting for you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134042

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


[PATCH] D109621: [clang][Driver] Default to loading clang.cfg if config file not specified

2022-09-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a subscriber: joerg.
MaskRay added a comment.

Thanks for taking over the patch!

I've CCed (in 
https://discourse.llvm.org/t/rfc-adding-a-default-file-location-to-config-file-support/63606/33)
 some folks who had strong opinions in the initial support patch.
(Cc @joerg manually whom I cannot find a discourse username for)


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

https://reviews.llvm.org/D109621

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


[PATCH] D134063: [clang] Make --ld-path= work with -fuse-ld=lld

2022-09-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Looks great!


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

https://reviews.llvm.org/D134063

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


[PATCH] D134067: [HLSL] Enable availability attribute

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

Besides the request for re-organizing the the test files, LGTM.




Comment at: clang/test/SemaHLSL/AvailabilityMarkup.hlsl:15
+void fn() {
+// expected-warning@+2 {{'fn6_0' is only available on HLSL ShaderModel 6.0 
or newer}}
+// expected-note@+1 {{enclose 'fn6_0' in a __builtin_available check to 
silence this warning}}

So minor thing, and one that I am going to start pushing for more, is better 
organization of 'expected-diagnostics'.  I think they should better reflect the 
order and 'cause' of the diagnostic, particularly with notes.  So something 
like:

``` 
  // expected-warning@+3 {{... only available ...}}
  // expected-note@#FN60_LOC {{ marked as being introduced...}}
  // expected-note@+1{{enclose...}}
```

Then on line 5, add the comment: `// FN60`

I have this preference because it makes it more clear to the reader where the 
notes come from.  I realize this is a new direction, and perhaps pushing my 
ability to request, but I'd still appreciate it happening here (I WILL be 
pushing for it on template reviews, where I think it is even MORE beneficial, 
thanks to 'instantiation of' diagnostics, and I have the authority to demand it 
:) ).



Comment at: clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl:10
+
+// expected-note@* {{'WaveActiveCountBits' has been marked as being introduced 
in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 
5.0}}

Same here, though perhaps less-so.  You can use `@hlsl_intrinsics.h:14` I 
believe to specify the line as well (which would be nice!) but keeping the 
diagnostics in 'emitted order' is more important to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134067

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


[PATCH] D133583: [clang][ubsan] Fix __builtin_assume_aligned incorrect type descriptor and C++ object polymorphic address

2022-09-16 Thread Lin Yurong via Phabricator via cfe-commits
yronglin added a comment.

Thanks for your suggestion @aaron.ballman , also I have added a new test case 
for C++ polymorphism classes




Comment at: clang/test/Sema/builtin-redecl.cpp:5-6
 
+#include 
+
 // Redeclaring library builtins is OK.

aaron.ballman wrote:
> yronglin wrote:
> > aaron.ballman wrote:
> > > We can be tricky instead of including a header file.
> > Use `decltype` not works in C , can we use `typedef unsigned long size_t 
> > `instead? 
> Oh good catch, I had missed the `-x c` on a RUN line and was looking at the 
> file extension alone. :-) We can't use that typedef because there are some 
> platforms where that type is wrong, but we can be tricky in a different way: 
> `typedef __typeof__(sizeof(0)) size_t;`
+1


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133583

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


[PATCH] D133583: [clang][ubsan] Fix __builtin_assume_aligned incorrect type descriptor and C++ object polymorphic address

2022-09-16 Thread Lin Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 460870.
yronglin added a comment.

Add test case for C++ polymorphism class
Use `typedef __typeof__(sizeof(0)) size_t;` instead of `#include `


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133583

Files:
  clang/include/clang/Basic/Builtins.def
  clang/lib/Basic/Builtins.cpp
  clang/lib/Sema/SemaChecking.cpp
  
clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-polymorphism.cpp
  clang/test/Sema/builtin-redecl.cpp

Index: clang/test/Sema/builtin-redecl.cpp
===
--- clang/test/Sema/builtin-redecl.cpp
+++ clang/test/Sema/builtin-redecl.cpp
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify -x c
 // RUN: %clang_cc1 %s -fsyntax-only -verify -fms-compatibility
 
+typedef __typeof__(sizeof(0)) size_t;
+
 // Redeclaring library builtins is OK.
 void exit(int);
 
@@ -16,3 +18,9 @@
 // RUN: %clang_cc1 %s -fsyntax-only -verify -x c
 
 void __va_start(__builtin_va_list*, ...);
+
+#ifdef __cplusplus
+void *__builtin_assume_aligned(const void *, size_t, ...) noexcept;
+#else
+void *__builtin_assume_aligned(const void *, size_t, ...);
+#endif
Index: clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-polymorphism.cpp
===
--- /dev/null
+++ clang/test/CodeGen/catch-alignment-assumption-builtin_assume_aligned-polymorphism.cpp
@@ -0,0 +1,64 @@
+// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fno-sanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-NORECOVER,CHECK-SANITIZE-UNREACHABLE
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-recover=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-ANYRECOVER,CHECK-SANITIZE-RECOVER
+// RUN: %clang_cc1 -no-opaque-pointers -fsanitize=alignment -fsanitize-trap=alignment -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s -implicit-check-not="call void @__ubsan_handle_alignment_assumption" --check-prefixes=CHECK,CHECK-SANITIZE,CHECK-SANITIZE-TRAP,CHECK-SANITIZE-UNREACHABLE
+
+// CHECK-SANITIZE-ANYRECOVER: @[[CHAR:.*]] = {{.*}} c"'B *'\00" }
+// CHECK-SANITIZE-ANYRECOVER: @[[LINE_100_ALIGNMENT_ASSUMPTION:.*]] = {{.*}}, i32 100, i32 35 }, {{.*}}* @[[CHAR]] }
+
+struct A { int n; };
+struct B { int n; };
+struct C : A, B {};
+
+void *f(C *c) {
+  // CHECK: define {{.*}} i8* @{{.*}}(%struct.C* noundef %[[C:.*]]) {{.*}} {
+  // CHECK-NEXT:[[ENTRY:.*]]:
+  // CHECK-NEXT:  %[[C_ADDR:.*]] = alloca %struct.C*
+  // CHECK-NEXT:  store %struct.C* %[[C]], %struct.C** %[[C_ADDR]]
+  // CHECK-NEXT:  %[[C_RELOAD:.*]] = load %struct.C*, %struct.C** %[[C_ADDR]]
+  // CHECK-NEXT:  %[[IS_NULL:.*]] = icmp eq %struct.C* %[[C_RELOAD]], null
+  // CHECK-NEXT:  br i1 %[[IS_NULL]], label %[[CAST_END:[^,]+]], label %[[CAST_NOT_NULL:[^,]+]]
+  // CHECK: [[CAST_NOT_NULL]]:
+  // CHECK-NOSANITIZE-NEXT:   %[[BITCAST:.*]] = bitcast %struct.C* %[[C_RELOAD]] to i8*
+  // CHECK-NOSANITIZE-NEXT:   %[[ADD_PTR:.*]] = getelementptr inbounds i8, i8* %[[BITCAST]], i64 4
+  // CHECK-NOSANITIZE-NEXT:   %[[BITCAST2:.*]] = bitcast i8* %[[ADD_PTR]] to %struct.B*
+  // CHECK-NOSANITIZE-NEXT:   br label %[[CAST_END]]
+  // CHECK-SANITIZE-NEXT: %[[PTRTOINT:.*]] = ptrtoint %struct.C* %[[C_RELOAD]] to i64, !nosanitize
+  // CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRTOINT]], 3, !nosanitize
+  // CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0, !nosanitize
+  // CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:[^,]+]], label %[[HANDLER_TYPE_MISMATCH:[^,]+]]
+  // CHECK-SANITIZE:[[HANDLER_TYPE_MISMATCH]]:
+  // CHECK-SANITIZE-NORECOVER-NEXT:   call void @__ubsan_handle_type_mismatch_v1_abort(
+  // CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_type_mismatch_v1(
+  // CHECK-SANITIZE-TRAP-NEXT:call void @llvm.ubsantrap(
+  // CHECK-SANITIZE-UNREACHABLE-NEXT: unreachable, !nosanitize
+  // CHECK-SANITIZE:[[CONT]]:
+  // CHECK-SANITIZE-NEXT: %[[BITCAST:.*]] = bitcast %struct.C* %[[C_RELOAD]] to i8*
+  // CHECK-SANITIZE-NEXT: %[[ADD_PTR:.*]] 

[PATCH] D134067: [HLSL] Enable availability attribute

2022-09-16 Thread Chris Bieneman via Phabricator via cfe-commits
beanz updated this revision to Diff 460869.
beanz added a comment.

Updating based on feedback from @erichkeane. Thank you for the fast feedback!

- Moved ShaderModel check into a switch case.
- Added additional self-contained test case with more variations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134067

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/lib/Sema/SemaAvailability.cpp
  clang/test/SemaHLSL/AvailabilityMarkup.hlsl
  clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl

Index: clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/WaveBuiltinAvailability.hlsl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel5.0-library -verify %s
+// WaveActiveCountBits is unavailable before ShaderModel 6.0.
+
+unsigned foo(bool b) {
+// expected-warning@+2 {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}}
+// expected-note@+1 {{enclose 'WaveActiveCountBits' in a __builtin_available check to silence this warning}}
+return WaveActiveCountBits(b);
+}
+
+// expected-note@* {{'WaveActiveCountBits' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
Index: clang/test/SemaHLSL/AvailabilityMarkup.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/AvailabilityMarkup.hlsl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel5.0-library -verify %s
+
+// expected-note@+2 {{'fn6_0' has been marked as being introduced in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 5.0}}
+__attribute__((availability(shadermodel, introduced = 6.0)))
+unsigned fn6_0();
+
+// expected-note@+2 {{'fn5_1' has been marked as being introduced in HLSL ShaderModel 5.1 here, but the deployment target is HLSL ShaderModel 5.0}}
+__attribute__((availability(shadermodel, introduced = 5.1)))
+unsigned fn5_1();
+
+__attribute__((availability(shadermodel, introduced = 5.0)))
+unsigned fn5_0();
+
+void fn() {
+// expected-warning@+2 {{'fn6_0' is only available on HLSL ShaderModel 6.0 or newer}}
+// expected-note@+1 {{enclose 'fn6_0' in a __builtin_available check to silence this warning}}
+unsigned A = fn6_0();
+
+// expected-warning@+2 {{'fn5_1' is only available on HLSL ShaderModel 5.1 or newer}}
+// expected-note@+1 {{enclose 'fn5_1' in a __builtin_available check to silence this warning}}
+unsigned B = fn5_1();
+
+unsigned C = fn5_0();
+}
+
Index: clang/lib/Sema/SemaAvailability.cpp
===
--- clang/lib/Sema/SemaAvailability.cpp
+++ clang/lib/Sema/SemaAvailability.cpp
@@ -192,6 +192,9 @@
   case llvm::Triple::MacOSX:
 ForceAvailabilityFromVersion = VersionTuple(/*Major=*/10, /*Minor=*/13);
 break;
+  case llvm::Triple::ShaderModel:
+// Always enable availability diagnostics for shader models.
+return true;
   default:
 // New targets should always warn about availability.
 return Triple.getVendor() == llvm::Triple::Apple;
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,7 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+__attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) uint
 WaveActiveCountBits(bool bBit);
 
Index: clang/lib/Basic/Targets/DirectX.h
===
--- clang/lib/Basic/Targets/DirectX.h
+++ clang/lib/Basic/Targets/DirectX.h
@@ -55,6 +55,8 @@
 HasLegalHalfType = true;
 HasFloat16 = true;
 NoAsmVariants = true;
+PlatformMinVersion = Triple.getOSVersion();
+PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
 resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
 "32-f64:64-n8:16:32:64");
 TheCXXABI.set(TargetCXXABI::Microsoft);
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -908,6 +908,7 @@
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
  .Case("swift", "Swift")
+ .Case("shadermodel", "HLSL ShaderModel")
  .Default(llvm::StringRef());
 }
 static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
@@ -923,6 +924,7 @@
  

[PATCH] D109621: [clang][Driver] Default to loading clang.cfg if config file not specified

2022-09-16 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/docs/UsersManual.rst:878
 Another way to specify a configuration file is to encode it in executable name.
 For example, if the Clang executable is named `armv7l-clang` (it may be a
+symbolic link to `clang`), then Clang will search for file `armv7l-clang.cfg` 
in

These single backsticks probably should be double backsticks.


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

https://reviews.llvm.org/D109621

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


[PATCH] D133924: add clang_CXXMethod_isDeleted function

2022-09-16 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands added a comment.

Yes it's probably safest if someone commits on my behalf, unless someone's got 
time to walk me through it. Just use Anders Langlands anderslanga...@gmail.com 
for attribution please.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133924

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


[PATCH] D133924: add clang_CXXMethod_isDeleted function

2022-09-16 Thread Anders Langlands via Phabricator via cfe-commits
anderslanglands updated this revision to Diff 460865.
anderslanglands added a comment.

Adding missing backtick


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133924

Files:
  clang/bindings/python/clang/cindex.py
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/test/Index/availability.cpp
  clang/test/Index/deletion.cpp
  clang/tools/c-index-test/c-index-test.c
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/libclang.map

Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ clang/tools/libclang/libclang.map
@@ -409,6 +409,7 @@
   global:
 clang_getUnqualifiedType;
 clang_getNonReferenceType;
+clang_CXXMethod_isDeleted;
 };
 
 # Example of how to add a new symbol version entry.  If you do add a new symbol
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8861,6 +8861,16 @@
   return (Method && Method->isDefaulted()) ? 1 : 0;
 }
 
+unsigned clang_CXXMethod_isDeleted(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+return 0;
+
+  const Decl *D = cxcursor::getCursorDecl(C);
+  const CXXMethodDecl *Method =
+  D ? dyn_cast_if_present(D->getAsFunction()) : nullptr;
+  return (Method && Method->isDeleted()) ? 1 : 0;
+}
+
 unsigned clang_CXXMethod_isStatic(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
 return 0;
Index: clang/tools/c-index-test/c-index-test.c
===
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -900,6 +900,8 @@
   printf(" (mutable)");
 if (clang_CXXMethod_isDefaulted(Cursor))
   printf(" (defaulted)");
+if (clang_CXXMethod_isDeleted(Cursor))
+  printf(" (deleted)");
 if (clang_CXXMethod_isStatic(Cursor))
   printf(" (static)");
 if (clang_CXXMethod_isVirtual(Cursor))
Index: clang/test/Index/deletion.cpp
===
--- /dev/null
+++ clang/test/Index/deletion.cpp
@@ -0,0 +1,14 @@
+struct Foo {
+  int foo() = delete;
+  int bar();
+  Foo() = delete;
+  Foo(int);
+};
+
+
+// RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
+// CHECK: StructDecl=Foo:1:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
+// CHECK: CXXMethod=foo:2:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXMethod=bar:3:7 [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXConstructor=Foo:4:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
+// CHECK: CXXConstructor=Foo:5:3 (converting constructor) [type=void (int){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [args= [int] [Int]] [isPOD=0]
Index: clang/test/Index/availability.cpp
===
--- clang/test/Index/availability.cpp
+++ clang/test/Index/availability.cpp
@@ -9,5 +9,5 @@
 // RUN: c-index-test -test-print-type --std=c++11 %s | FileCheck %s
 // CHECK: FunctionDecl=foo:1:6 (unavailable) [type=void ()] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
 // CHECK: StructDecl=Foo:3:8 (Definition) [type=Foo] [typekind=Record] [isPOD=1]
-// CHECK: CXXMethod=foo:4:7 (unavailable) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
-// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
+// CHECK: CXXMethod=foo:4:7 (unavailable) (deleted) [type=int (){{.*}}] [typekind=FunctionProto] [resulttype=int] [resulttypekind=Int] [isPOD=0]
+// CHECK: CXXConstructor=Foo:5:3 (unavailable) (default constructor) (deleted) [type=void (){{.*}}] [typekind=FunctionProto] [resulttype=void] [resulttypekind=Void] [isPOD=0]
Index: clang/include/clang-c/Index.h
===
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -4924,6 +4924,11 @@
  */
 CINDEX_LINKAGE unsigned clang_CXXMethod_isDefaulted(CXCursor C);
 
+/**
+ * Determine if a C++ method is declared '= delete'.
+ */
+CINDEX_LINKAGE unsigned clang_CXXMethod_isDeleted(CXCursor C);
+
 /**
  * Determine if a C++ member function or member function template is
  * pure virtual.
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -319,6 +319,8 @@
   the behavior of `QualType::getUnqualifiedType` 

[PATCH] D134067: [HLSL] Enable availability attribute

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaAvailability.cpp:198
+return Triple.getVendor() == llvm::Triple::Apple ||
+   Triple.getOS() == llvm::Triple::ShaderModel;
   }

This should jsut be a 'case' label added above, we are already switching on 
getOS.



Comment at: clang/test/SemaHLSL/AvailabilityMarkup.hlsl:10
+
+// expected-note@* {{'WaveActiveCountBits' has been marked as being introduced 
in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 
5.0}}

Not sure how I feel about us testing the headers AND functionality in the same 
place.   @aaron.ballman : Does this seem inappropriate to you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134067

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


[PATCH] D134067: [HLSL] Enable availability attribute

2022-09-16 Thread Chris Bieneman via Phabricator via cfe-commits
beanz created this revision.
beanz added reviewers: MaskRay, erichkeane, rnk, arphaman, python3kgae, 
pow2clk, tex3d.
Herald added a reviewer: aaron.ballman.
Herald added subscribers: Anastasia, StephenFan.
Herald added a project: All.
beanz requested review of this revision.
Herald added a project: clang.

Some HLSL functionality is gated on the target shader model version.
Enabling the use of availability markup allows us to diagnose
availability issues easily in the frontend.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134067

Files:
  clang/include/clang/Basic/Attr.td
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Headers/hlsl/hlsl_intrinsics.h
  clang/lib/Sema/SemaAvailability.cpp
  clang/test/SemaHLSL/AvailabilityMarkup.hlsl


Index: clang/test/SemaHLSL/AvailabilityMarkup.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/AvailabilityMarkup.hlsl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel5.0-library -verify %s
+// WaveActiveCountBits is unavailable before ShaderModel 6.0.
+
+unsigned foo(bool b) {
+// expected-warning@+2 {{'WaveActiveCountBits' is only available on HLSL 
ShaderModel 6.0 or newer}}
+// expected-note@+1 {{enclose 'WaveActiveCountBits' in a 
__builtin_available check to silence this warning}}
+return WaveActiveCountBits(b);
+}
+
+// expected-note@* {{'WaveActiveCountBits' has been marked as being introduced 
in HLSL ShaderModel 6.0 here, but the deployment target is HLSL ShaderModel 
5.0}}
Index: clang/lib/Sema/SemaAvailability.cpp
===
--- clang/lib/Sema/SemaAvailability.cpp
+++ clang/lib/Sema/SemaAvailability.cpp
@@ -194,7 +194,8 @@
 break;
   default:
 // New targets should always warn about availability.
-return Triple.getVendor() == llvm::Triple::Apple;
+return Triple.getVendor() == llvm::Triple::Apple ||
+   Triple.getOS() == llvm::Triple::ShaderModel;
   }
   return DeploymentVersion >= ForceAvailabilityFromVersion ||
  DeclVersion >= ForceAvailabilityFromVersion;
Index: clang/lib/Headers/hlsl/hlsl_intrinsics.h
===
--- clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -9,6 +9,7 @@
 #ifndef _HLSL_HLSL_INTRINSICS_H_
 #define _HLSL_HLSL_INTRINSICS_H_
 
+__attribute__((availability(shadermodel, introduced = 6.0)))
 __attribute__((clang_builtin_alias(__builtin_hlsl_wave_active_count_bits))) 
uint
 WaveActiveCountBits(bool bBit);
 
Index: clang/lib/Basic/Targets/DirectX.h
===
--- clang/lib/Basic/Targets/DirectX.h
+++ clang/lib/Basic/Targets/DirectX.h
@@ -55,6 +55,8 @@
 HasLegalHalfType = true;
 HasFloat16 = true;
 NoAsmVariants = true;
+PlatformMinVersion = Triple.getOSVersion();
+PlatformName = llvm::Triple::getOSTypeName(Triple.getOS());
 resetDataLayout("e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:"
 "32-f64:64-n8:16:32:64");
 TheCXXABI.set(TargetCXXABI::Microsoft);
Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -908,6 +908,7 @@
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", "macCatalyst (App Extension)")
  .Case("swift", "Swift")
+ .Case("shadermodel", "HLSL ShaderModel")
  .Default(llvm::StringRef());
 }
 static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) 
{
@@ -923,6 +924,7 @@
  .Case("maccatalyst", "macCatalyst")
  .Case("maccatalyst_app_extension", 
"macCatalystApplicationExtension")
  .Case("zos", "z/OS")
+ .Case("shadermodel", "ShaderModel")
  .Default(Platform);
 }
 static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
@@ -937,6 +939,7 @@
  .Case("watchOSApplicationExtension", "watchos_app_extension")
  .Case("macCatalyst", "maccatalyst")
  .Case("macCatalystApplicationExtension", 
"maccatalyst_app_extension")
+ .Case("ShaderModel", "shadermodel")
  .Default(Platform);
 } }];
   let HasCustomParsing = 1;


Index: clang/test/SemaHLSL/AvailabilityMarkup.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/AvailabilityMarkup.hlsl
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel5.0-library -verify %s
+// WaveActiveCountBits is unavailable before ShaderModel 6.0.
+
+unsigned foo(bool b) {
+// expected-warning@+2 {{'WaveActiveCountBits' is only available on HLSL ShaderModel 6.0 or newer}}
+// expected-note@+1 {{enclose 

[clang] c0bc461 - [Clang] Give error message for invalid profile path when compiling IR

2022-09-16 Thread Aiden Grossman via cfe-commits

Author: Aiden Grossman
Date: 2022-09-16T19:45:57Z
New Revision: c0bc461999fdac918dd26867947c24eb6235c8d0

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

LOG: [Clang] Give error message for invalid profile path when compiling IR

Before this patch, when compiling an IR file (eg the .llvmbc section
from an object file compiled with -Xclang -fembed-bitcode=all) and
profile data was passed in using the -fprofile-instrument-use-path
flag, there would be no error printed (as the previous implementation
relied on the error getting caught again in the constructor of
CodeGenModule which isn't called when -x ir is set). This patch
moves the error checking directly to where the error is caught
originally rather than failing silently in setPGOUseInstrumentor and
waiting to catch it in CodeGenModule to print diagnostic information to
the user.

Regression test added.

Reviewed By: xur, mtrofin

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

Added: 
clang/test/Profile/profile-does-not-exist-ir.c

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Profile/profile-does-not-exist.c

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index bbd42956a4b0..06ad67a492a1 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -182,15 +182,11 @@ CodeGenModule::CodeGenModule(ASTContext ,
   if (CodeGenOpts.hasProfileClangUse()) {
 auto ReaderOrErr = llvm::IndexedInstrProfReader::create(
 CodeGenOpts.ProfileInstrumentUsePath, 
CodeGenOpts.ProfileRemappingFile);
-if (auto E = ReaderOrErr.takeError()) {
-  unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
-  "Could not read profile %0: %1");
-  llvm::handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase ) {
-getDiags().Report(DiagID) << CodeGenOpts.ProfileInstrumentUsePath
-  << EI.message();
-  });
-} else
-  PGOReader = std::move(ReaderOrErr.get());
+// We're checking for profile read errors in CompilerInvocation, so if
+// there was an error it should've already been caught. If it hasn't been
+// somehow, trip an assertion.
+assert(ReaderOrErr);
+PGOReader = std::move(ReaderOrErr.get());
   }
 
   // If coverage mapping generation is enabled, create the

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index f42bf3058d1a..9f9241054b1e 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1293,12 +1293,15 @@ static std::string 
serializeXRayInstrumentationBundle(const XRayInstrSet ) {
 
 // Set the profile kind using fprofile-instrument-use-path.
 static void setPGOUseInstrumentor(CodeGenOptions ,
-  const Twine ) {
+  const Twine ,
+  DiagnosticsEngine ) {
   auto ReaderOrErr = llvm::IndexedInstrProfReader::create(ProfileName);
-  // In error, return silently and let Clang PGOUse report the error message.
   if (auto E = ReaderOrErr.takeError()) {
-llvm::consumeError(std::move(E));
-Opts.setProfileUse(CodeGenOptions::ProfileClangInstr);
+unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
+"Error in reading profile %0: %1");
+llvm::handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase ) {
+  Diags.Report(DiagID) << ProfileName.str() << EI.message();
+});
 return;
   }
   std::unique_ptr PGOReader =
@@ -1712,7 +1715,7 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions 
, ArgList ,
   }
 
   if (!Opts.ProfileInstrumentUsePath.empty())
-setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath);
+setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath, Diags);
 
   if (const Arg *A = Args.getLastArg(OPT_ftime_report, OPT_ftime_report_EQ)) {
 Opts.TimePasses = true;

diff  --git a/clang/test/Profile/profile-does-not-exist-ir.c 
b/clang/test/Profile/profile-does-not-exist-ir.c
new file mode 100644
index ..842a3d44a387
--- /dev/null
+++ b/clang/test/Profile/profile-does-not-exist-ir.c
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 -emit-llvm -x ir %s -o - 
-fprofile-instrument-use-path=%t.nonexistent.profdata 2>&1 | FileCheck %s
+
+// CHECK: error: Error in reading profile {{.*}}.nonexistent.profdata:
+// CHECK-NOT: Assertion failed

diff  --git a/clang/test/Profile/profile-does-not-exist.c 
b/clang/test/Profile/profile-does-not-exist.c
index 5725f76eb80c..88d55d8668ef 100644
--- a/clang/test/Profile/profile-does-not-exist.c

[PATCH] D132991: [Clang] Give error message for invalid profile path when compiling IR

2022-09-16 Thread Aiden Grossman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc0bc461999fd: [Clang] Give error message for invalid profile 
path when compiling IR (authored by aidengrossman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132991

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Profile/profile-does-not-exist-ir.c
  clang/test/Profile/profile-does-not-exist.c


Index: clang/test/Profile/profile-does-not-exist.c
===
--- clang/test/Profile/profile-does-not-exist.c
+++ clang/test/Profile/profile-does-not-exist.c
@@ -1,4 +1,4 @@
 // RUN: not %clang_cc1 -emit-llvm %s -o - 
-fprofile-instrument-use-path=%t.nonexistent.profdata 2>&1 | FileCheck %s
 
-// CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
+// CHECK: error: Error in reading profile {{.*}}.nonexistent.profdata:
 // CHECK-NOT: Assertion failed
Index: clang/test/Profile/profile-does-not-exist-ir.c
===
--- /dev/null
+++ clang/test/Profile/profile-does-not-exist-ir.c
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 -emit-llvm -x ir %s -o - 
-fprofile-instrument-use-path=%t.nonexistent.profdata 2>&1 | FileCheck %s
+
+// CHECK: error: Error in reading profile {{.*}}.nonexistent.profdata:
+// CHECK-NOT: Assertion failed
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1293,12 +1293,15 @@
 
 // Set the profile kind using fprofile-instrument-use-path.
 static void setPGOUseInstrumentor(CodeGenOptions ,
-  const Twine ) {
+  const Twine ,
+  DiagnosticsEngine ) {
   auto ReaderOrErr = llvm::IndexedInstrProfReader::create(ProfileName);
-  // In error, return silently and let Clang PGOUse report the error message.
   if (auto E = ReaderOrErr.takeError()) {
-llvm::consumeError(std::move(E));
-Opts.setProfileUse(CodeGenOptions::ProfileClangInstr);
+unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
+"Error in reading profile %0: %1");
+llvm::handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase ) {
+  Diags.Report(DiagID) << ProfileName.str() << EI.message();
+});
 return;
   }
   std::unique_ptr PGOReader =
@@ -1712,7 +1715,7 @@
   }
 
   if (!Opts.ProfileInstrumentUsePath.empty())
-setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath);
+setPGOUseInstrumentor(Opts, Opts.ProfileInstrumentUsePath, Diags);
 
   if (const Arg *A = Args.getLastArg(OPT_ftime_report, OPT_ftime_report_EQ)) {
 Opts.TimePasses = true;
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -182,15 +182,11 @@
   if (CodeGenOpts.hasProfileClangUse()) {
 auto ReaderOrErr = llvm::IndexedInstrProfReader::create(
 CodeGenOpts.ProfileInstrumentUsePath, 
CodeGenOpts.ProfileRemappingFile);
-if (auto E = ReaderOrErr.takeError()) {
-  unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
-  "Could not read profile %0: %1");
-  llvm::handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase ) {
-getDiags().Report(DiagID) << CodeGenOpts.ProfileInstrumentUsePath
-  << EI.message();
-  });
-} else
-  PGOReader = std::move(ReaderOrErr.get());
+// We're checking for profile read errors in CompilerInvocation, so if
+// there was an error it should've already been caught. If it hasn't been
+// somehow, trip an assertion.
+assert(ReaderOrErr);
+PGOReader = std::move(ReaderOrErr.get());
   }
 
   // If coverage mapping generation is enabled, create the


Index: clang/test/Profile/profile-does-not-exist.c
===
--- clang/test/Profile/profile-does-not-exist.c
+++ clang/test/Profile/profile-does-not-exist.c
@@ -1,4 +1,4 @@
 // RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-use-path=%t.nonexistent.profdata 2>&1 | FileCheck %s
 
-// CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
+// CHECK: error: Error in reading profile {{.*}}.nonexistent.profdata:
 // CHECK-NOT: Assertion failed
Index: clang/test/Profile/profile-does-not-exist-ir.c
===
--- /dev/null
+++ clang/test/Profile/profile-does-not-exist-ir.c
@@ -0,0 +1,4 @@
+// RUN: not %clang_cc1 -emit-llvm -x ir %s -o - 

[clang] 8a868d8 - Revert "Revert "[clang, llvm] Add __declspec(safebuffers), support it in CodeView""

2022-09-16 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2022-09-16T19:39:48Z
New Revision: 8a868d8859f9da23ee051848863045208c17ab47

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

LOG: Revert "Revert "[clang, llvm] Add __declspec(safebuffers), support it in 
CodeView""

This reverts commit cd20a1828605887699579789b5433111d5bc0319 and adds a
"let Heading" to NoStackProtectorDocs.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/Parser/MicrosoftExtensions.c
llvm/include/llvm/BinaryFormat/COFF.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/X86/X86AsmPrinter.cpp
llvm/test/DebugInfo/COFF/frameproc-flags.ll
llvm/test/DebugInfo/COFF/multifunction.ll
llvm/test/DebugInfo/COFF/simple.ll
llvm/test/DebugInfo/COFF/vframe-fpo.ll

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 2e3297b72a8c..b68f3e621769 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2080,12 +2080,19 @@ def NotTailCalled : InheritableAttr {
 def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
 
 def NoStackProtector : InheritableAttr {
-  let Spellings = [Clang<"no_stack_protector">];
+  let Spellings = [Clang<"no_stack_protector">, Declspec<"safebuffers">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [NoStackProtectorDocs];
   let SimpleHandler = 1;
 }
 
+def StrictGuardStackCheck : InheritableAttr {
+  let Spellings = [Declspec<"strict_gs_check">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [StrictGuardStackCheckDocs];
+  let SimpleHandler = 1;
+}
+
 def NoThrow : InheritableAttr {
   let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
   let Subjects = SubjectList<[FunctionLike]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 68f1268ed7da..ee9deef0dde1 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4452,8 +4452,10 @@ spelled "XYZ" in the `OpenMP 5.1 Standard`_).
 
 def NoStackProtectorDocs : Documentation {
   let Category = DocCatFunction;
+  let Heading = "no_stack_protector, safebuffers";
   let Content = [{
-Clang supports the ``__attribute__((no_stack_protector))`` attribute which 
disables
+Clang supports the ``__attribute__((no_stack_protector))`` and Microsoft style
+``__declspec(safebuffers)`` attribute which disables
 the stack protector on the specified function. This attribute is useful for
 selectively disabling the stack protector on some functions when building with
 ``-fstack-protector`` compiler option.
@@ -4472,6 +4474,27 @@ option.
 }];
 }
 
+def StrictGuardStackCheckDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Clang supports the Microsoft style ``__declspec((strict_gs_check))`` attribute
+which upgrades the stack protector check from ``-fstack-protector`` to
+``-fstack-protector-strong``.
+
+For example, it upgrades the stack protector for the function ``foo`` to
+``-fstack-protector-strong`` but function ``bar`` will still be built with the
+stack protector with the ``-fstack-protector`` option.
+
+.. code-block:: c
+
+__declspec((strict_gs_check))
+int foo(int x); // stack protection will be upgraded for foo.
+
+int bar(int y); // bar can be built with the standard stack protector 
checks.
+
+}];
+}
+
 def NotTailCalledDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 9edd618d359b..bbd42956a4b0 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1970,14 +1970,17 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
   if (!hasUnwindExceptions(LangOpts))
 B.addAttribute(llvm::Attribute::NoUnwind);
 
-  if (!D || !D->hasAttr()) {
-if (LangOpts.getStackProtector() == LangOptions::SSPOn)
-  B.addAttribute(llvm::Attribute::StackProtect);
-else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
-  B.addAttribute(llvm::Attribute::StackProtectStrong);
-else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
-  B.addAttribute(llvm::Attribute::StackProtectReq);
-  }
+  if (D && D->hasAttr())
+; // Do nothing.
+  else if (D && D->hasAttr() &&
+   LangOpts.getStackProtector() == LangOptions::SSPOn)
+B.addAttribute(llvm::Attribute::StackProtectStrong);
+  else if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+B.addAttribute(llvm::Attribute::StackProtect);
+  else if 

[PATCH] D134055: [clang-doc] Export more enum information

2022-09-16 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

Can you make the first line of the summary the commit title? It's a bit more 
descriptive.




Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:53
 
+llvm::Error decodeRecord(const Record , llvm::APSInt , llvm::StringRef 
Blob) {
+  auto ByteWidth = R[0];

do you need to do all of this? APSInt already supports to/from string methods, 
as well as converting to/from integers. can you use that here and in the writer 
to avoid some complexity?



Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:221
 return decodeRecord(R, I->Loc, Blob);
-  case ENUM_MEMBER:
-return decodeRecord(R, I->Members, Blob);

Don't you still need this? if it's now unused, we should probably remove it 
from the RecordId enum too.



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:185
 
+SmallString<128> getSourceCode(const Decl* D, const SourceRange& R) {
+  return Lexer::getSourceText(

We normally try to avoid returning small string by value. see 
https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallstring-h

Normally in the case that we need to return a string from a method, we just use 
std::string. In other cases, it may be more appropriate to use an output 
parameter instead of a return.



Comment at: clang-tools-extra/clang-doc/Serialize.cpp:316
+  for (const EnumConstantDecl *E : D->enumerators()) {
+SmallString<128> ValueExpr;
+if (const Expr* InitExpr = E->getInitExpr())

why was 128 chosen? Aren't we storing it into a `SmallString<16>` in 
`EnumValueInfo`? is there some external reason that we expect this to be the 
right size? 

Do you have an idea for how long these are likely to be? if we expect them to 
be large or completely unpredictable, it may make more sense to use a 
`std::string` and avoid wasting stack space.

 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134055

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


[PATCH] D83015: [Driver] Add --ld-path= and deprecate -fuse-ld=/abs/path and -fuse-ld=rel/path

2022-09-16 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

> Yes, specify both options. -fuse-ld= specifies the flavor while --ld-path= 
> specifies a path the Clang Driver does not want to detect.

Thanks, made D134063  for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D83015

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


[PATCH] D134063: [clang] Make --ld-path= work with -fuse-ld=lld

2022-09-16 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: MaskRay.
Herald added a subscriber: StephenFan.
Herald added a project: All.
thakis requested review of this revision.

This allows using --ld-path= to set a custom linker path, while
still informing clang that the binary at that path is an lld built
at the same revision as clang, so that clang can make assumptions
about the flags it supports, its output format, etc.

This currently only has an observable effect on Darwin.


https://reviews.llvm.org/D134063

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/darwin-ld-demangle-lld.c


Index: clang/test/Driver/darwin-ld-demangle-lld.c
===
--- clang/test/Driver/darwin-ld-demangle-lld.c
+++ clang/test/Driver/darwin-ld-demangle-lld.c
@@ -1,8 +1,12 @@
 // With -fuse-ld=lld, -demangle is always passed to the linker on Darwin.
 // REQUIRES: shell
 
-// RUN: %clang --target=x86_64-apple-darwin -### \
-// RUN:   -fuse-ld=lld -B%S/Inputs/lld -mlinker-version=0 %s 2>&1 \
+// RUN: %clang --target=x86_64-apple-darwin -### -fuse-ld=lld \
+// RUN:   -B%S/Inputs/lld -mlinker-version=0 %s 2>&1 \
+// RUN:   | FileCheck %s
+
+// RUN: %clang --target=x86_64-apple-darwin -### -fuse-ld=lld \
+// RUN:   --ld-path=%S/Inputs/lld/ld64.lld -mlinker-version=0 %s 2>&1 \
 // RUN:   | FileCheck %s
 
 // CHECK: "-demangle"
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -620,13 +620,18 @@
   // --ld-path= takes precedence over -fuse-ld= and specifies the executable
   // name. -B, COMPILER_PATH and PATH and consulted if the value does not
   // contain a path component separator.
+  // -fuse-ld=lld can be used with --ld-path= to inform clang that the binary
+  // that --ld-path= points to is lld.
   if (const Arg *A = Args.getLastArg(options::OPT_ld_path_EQ)) {
 std::string Path(A->getValue());
 if (!Path.empty()) {
   if (llvm::sys::path::parent_path(Path).empty())
 Path = GetProgramPath(A->getValue());
-  if (llvm::sys::fs::can_execute(Path))
+  if (llvm::sys::fs::can_execute(Path)) {
+if (LinkerIsLLD)
+  *LinkerIsLLD = UseLinker == "lld";
 return std::string(Path);
+  }
 }
 getDriver().Diag(diag::err_drv_invalid_linker_name) << 
A->getAsString(Args);
 return GetProgramPath(getDefaultLinker());


Index: clang/test/Driver/darwin-ld-demangle-lld.c
===
--- clang/test/Driver/darwin-ld-demangle-lld.c
+++ clang/test/Driver/darwin-ld-demangle-lld.c
@@ -1,8 +1,12 @@
 // With -fuse-ld=lld, -demangle is always passed to the linker on Darwin.
 // REQUIRES: shell
 
-// RUN: %clang --target=x86_64-apple-darwin -### \
-// RUN:   -fuse-ld=lld -B%S/Inputs/lld -mlinker-version=0 %s 2>&1 \
+// RUN: %clang --target=x86_64-apple-darwin -### -fuse-ld=lld \
+// RUN:   -B%S/Inputs/lld -mlinker-version=0 %s 2>&1 \
+// RUN:   | FileCheck %s
+
+// RUN: %clang --target=x86_64-apple-darwin -### -fuse-ld=lld \
+// RUN:   --ld-path=%S/Inputs/lld/ld64.lld -mlinker-version=0 %s 2>&1 \
 // RUN:   | FileCheck %s
 
 // CHECK: "-demangle"
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -620,13 +620,18 @@
   // --ld-path= takes precedence over -fuse-ld= and specifies the executable
   // name. -B, COMPILER_PATH and PATH and consulted if the value does not
   // contain a path component separator.
+  // -fuse-ld=lld can be used with --ld-path= to inform clang that the binary
+  // that --ld-path= points to is lld.
   if (const Arg *A = Args.getLastArg(options::OPT_ld_path_EQ)) {
 std::string Path(A->getValue());
 if (!Path.empty()) {
   if (llvm::sys::path::parent_path(Path).empty())
 Path = GetProgramPath(A->getValue());
-  if (llvm::sys::fs::can_execute(Path))
+  if (llvm::sys::fs::can_execute(Path)) {
+if (LinkerIsLLD)
+  *LinkerIsLLD = UseLinker == "lld";
 return std::string(Path);
+  }
 }
 getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
 return GetProgramPath(getDefaultLinker());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134057: [clang][Interp] Start implementing record types

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:316
+  // Base above gives us a pointer on the stack.
+  const auto *FD = dyn_cast(Member);
+  assert(FD);

erichkeane wrote:
> I THINK Member is a ValueDecl because it could be a member function, right?  
> So forcing it to be a FieldDecl here is likely not valid.  Perhaps in the 
> 'non-FieldDecl' case we could jsut return false for now?
> 
> ALSO, don't do a dyn_cast followed by an assert, `cast` will do the assert 
> for you.
Right, I was just trying to limit the code to the subset I've implemented for 
now. I can try to make it more defensive.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:659
+
+// FIXME
+const Stmt *Body = Ctor->getBody();

erichkeane wrote:
> Eh?
As far as I understand, actually visiting the body of the constructor will 
require a bit more setup work of `this` pointers and such. So for now, not 
implemented and a FIXME.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134057

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


[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/Interp/Boolean.h:50
 
   explicit operator unsigned() const { return V; }
+  explicit operator int8_t() const { return V; }

tbaeder wrote:
> aaron.ballman wrote:
> > At some point, do we want to rename this (and int) to use uint32_t/int32_t?
> I can do that as a follow-up commit if you want.
Please do, while we don't currently compile on any platforms with non-32 bit 
int/unsigned, if we ever tried to this would fail with multiple definitions 
somewhere.


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

https://reviews.llvm.org/D133934

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


[PATCH] D134020: [clang][Interp] Handle enums

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:861
+
+return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
+   E);

shafik wrote:
> If I check out `IntExprEvaluator::CheckReferenceDecl(...)` it is checking the 
> sign and width match between the expression and the `EnumConstantDecl`. I am 
> guessing we need to do that here as well?
I'm having a hard time trying to cause that code to trigger.  e.g. in

```
enum Foo : unsigned int {
  A = -1,
};
static_assert(A == -1);
```
Both with the new and current interpreter, I get a`-Wc++11-narrowing` error by 
default, and the assertion works if I pass `-Wno-c++11-narrowing`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

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


[PATCH] D133934: [clang][Interp] Handle sizeof() expressions

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Boolean.h:50
 
   explicit operator unsigned() const { return V; }
+  explicit operator int8_t() const { return V; }

aaron.ballman wrote:
> At some point, do we want to rename this (and int) to use uint32_t/int32_t?
I can do that as a follow-up commit if you want.


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

https://reviews.llvm.org/D133934

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


[PATCH] D134034: [test] Use host platform specific error message substitution

2022-09-16 Thread Abhina Sree via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGce193431141d: [test] Use host platform specific error 
message substitution (authored by abhina.sreeskantharajan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134034

Files:
  clang/test/Format/style-on-command-line.cpp
  llvm/test/tools/llvm-dis/errors.test
  llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
  llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
  llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test


Index: llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test
===
--- llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test
+++ llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test
@@ -1,3 +1,3 @@
-; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck 
%s
+; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck 
-DMSG=%errc_ENOENT %s
 
-; CHECK: error: {{.*}}v4.tbd' {{[Nn]}}o such file or directory
+; CHECK: error: {{.*}}v4.tbd' [[MSG]]
Index: llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
===
--- llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
+++ llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
@@ -1,4 +1,4 @@
 # REQUIRES: amdgpu-registered-target
-# RUN: not llvm-reduce -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg 
%s --test-arg --input-file does-not-exist.mir 2>&1 | FileCheck 
-check-prefix=ERR %s
+# RUN: not llvm-reduce -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg 
%s --test-arg --input-file does-not-exist.mir 2>&1 | FileCheck 
-DMSG=%errc_ENOENT -check-prefix=ERR %s
 
-# ERR: {{.*}}llvm-reduce{{.*}}: {{[Nn]}}o such file or directory
+# ERR: {{.*}}llvm-reduce{{.*}}: [[MSG]]
Index: llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
===
--- llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
+++ llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
@@ -3,11 +3,11 @@
 RUN: cd %t
 RUN: cp %p/../Inputs/dwos_list_from_exec/b.dwo b.dwo
 RUN: cp %p/../Inputs/dwos_list_from_exec/main main
-RUN: not llvm-dwp -e binary -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-BIN
-RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-1ST-DWO
+RUN: not llvm-dwp -e binary -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT 
%s --check-prefix=CHECK-BIN
+RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=CHECK-1ST-DWO
 RUN: cp %p/../Inputs/dwos_list_from_exec/a.dwo a.dwo
 RUN: rm b.dwo
-RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-2ND-DWO
+RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=CHECK-2ND-DWO
 
 Build commands for the test binaries:
 
@@ -23,6 +23,6 @@
  return 0;
   }
 
-CHECK-BIN: error: 'binary': {{[Nn]}}o such file or directory
-CHECK-1ST-DWO: error: './a.dwo': {{[Nn]}}o such file or directory
-CHECK-2ND-DWO: error: './b.dwo': {{[Nn]}}o such file or directory
+CHECK-BIN: error: 'binary': [[MSG]]
+CHECK-1ST-DWO: error: './a.dwo': [[MSG]]
+CHECK-2ND-DWO: error: './b.dwo': [[MSG]]
Index: llvm/test/tools/llvm-dis/errors.test
===
--- llvm/test/tools/llvm-dis/errors.test
+++ llvm/test/tools/llvm-dis/errors.test
@@ -1,3 +1,3 @@
-# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck %s 
--check-prefix=MISSING --ignore-case
+# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=MISSING --ignore-case
 
-# MISSING: error: missing-file-path: no such file or directory
+# MISSING: error: missing-file-path: [[MSG]]
Index: clang/test/Format/style-on-command-line.cpp
===
--- clang/test/Format/style-on-command-line.cpp
+++ clang/test/Format/style-on-command-line.cpp
@@ -6,7 +6,7 @@
 // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %t/.clang-format
 // RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck 
-strict-whitespace -check-prefix=CHECK5 %s
 // RUN: printf "Invalid:\n" > %t/.clang-format
-// RUN: not clang-format -style=file -fallback-style=webkit 
-assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace 
-check-prefix=CHECK6 %s
+// RUN: not clang-format -style=file -fallback-style=webkit 
-assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -DMSG=%errc_EINVAL 
-strict-whitespace -check-prefix=CHECK6 %s
 // RUN: rm %t/.clang-format
 // RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %t/_clang-format
 // RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck 
-strict-whitespace -check-prefix=CHECK7 %s
@@ -35,7 +35,7 @@
 // CHECK4: Error 

[clang] ce19343 - [test] Use host platform specific error message substitution

2022-09-16 Thread Abhina Sreeskantharajan via cfe-commits

Author: Abhina Sreeskantharajan
Date: 2022-09-16T15:13:45-04:00
New Revision: ce193431141d8f16d6b511a9114879105b0739e1

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

LOG: [test] Use host platform specific error message substitution

This patch modifies the testcase to use error substitution so it will pass on 
all platforms.

Reviewed By: fanbo-meng, zibi

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

Added: 


Modified: 
clang/test/Format/style-on-command-line.cpp
llvm/test/tools/llvm-dis/errors.test
llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test

Removed: 




diff  --git a/clang/test/Format/style-on-command-line.cpp 
b/clang/test/Format/style-on-command-line.cpp
index 9825269ef0715..ce2577beec86a 100644
--- a/clang/test/Format/style-on-command-line.cpp
+++ b/clang/test/Format/style-on-command-line.cpp
@@ -6,7 +6,7 @@
 // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %t/.clang-format
 // RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck 
-strict-whitespace -check-prefix=CHECK5 %s
 // RUN: printf "Invalid:\n" > %t/.clang-format
-// RUN: not clang-format -style=file -fallback-style=webkit 
-assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace 
-check-prefix=CHECK6 %s
+// RUN: not clang-format -style=file -fallback-style=webkit 
-assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -DMSG=%errc_EINVAL 
-strict-whitespace -check-prefix=CHECK6 %s
 // RUN: rm %t/.clang-format
 // RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %t/_clang-format
 // RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck 
-strict-whitespace -check-prefix=CHECK7 %s
@@ -35,7 +35,7 @@ void f() {
 // CHECK4: Error parsing -style: [[MSG]]
 // CHECK5: {{^ int\* i;$}}
 // CHECK6: unknown key 'Invalid'
-// CHECK6: {{^Error reading .*\.clang-format: (I|i)nvalid argument}}
+// CHECK6: {{^Error reading .*\.clang-format:}} [[MSG]]
 // CHECK7: {{^  int\* i;$}}
 // CHECK8: {{^  int\* i;$}}
 // CHECK9: {{^int \*i;$}}

diff  --git a/llvm/test/tools/llvm-dis/errors.test 
b/llvm/test/tools/llvm-dis/errors.test
index 27c37b2186a32..4e4b60f72dfd0 100644
--- a/llvm/test/tools/llvm-dis/errors.test
+++ b/llvm/test/tools/llvm-dis/errors.test
@@ -1,3 +1,3 @@
-# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck %s 
--check-prefix=MISSING --ignore-case
+# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=MISSING --ignore-case
 
-# MISSING: error: missing-file-path: no such file or directory
+# MISSING: error: missing-file-path: [[MSG]]

diff  --git a/llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test 
b/llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
index 8d71cf5d5c301..961ea8675d23e 100644
--- a/llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
+++ b/llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
@@ -3,11 +3,11 @@ RUN: mkdir %t
 RUN: cd %t
 RUN: cp %p/../Inputs/dwos_list_from_exec/b.dwo b.dwo
 RUN: cp %p/../Inputs/dwos_list_from_exec/main main
-RUN: not llvm-dwp -e binary -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-BIN
-RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-1ST-DWO
+RUN: not llvm-dwp -e binary -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT 
%s --check-prefix=CHECK-BIN
+RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=CHECK-1ST-DWO
 RUN: cp %p/../Inputs/dwos_list_from_exec/a.dwo a.dwo
 RUN: rm b.dwo
-RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-2ND-DWO
+RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=CHECK-2ND-DWO
 
 Build commands for the test binaries:
 
@@ -23,6 +23,6 @@ b.cpp:
  return 0;
   }
 
-CHECK-BIN: error: 'binary': {{[Nn]}}o such file or directory
-CHECK-1ST-DWO: error: './a.dwo': {{[Nn]}}o such file or directory
-CHECK-2ND-DWO: error: './b.dwo': {{[Nn]}}o such file or directory
+CHECK-BIN: error: 'binary': [[MSG]]
+CHECK-1ST-DWO: error: './a.dwo': [[MSG]]
+CHECK-2ND-DWO: error: './b.dwo': [[MSG]]

diff  --git a/llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir 
b/llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
index 9147bf9dac99d..4e39948a2ecb1 100644
--- a/llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
+++ b/llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
@@ -1,4 +1,4 @@
 # REQUIRES: amdgpu-registered-target
-# RUN: not llvm-reduce -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg 
%s --test-arg --input-file does-not-exist.mir 2>&1 | FileCheck 
-check-prefix=ERR %s
+# 

[PATCH] D132913: [HLSL] Preserve vec3 for HLSL.

2022-09-16 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added inline comments.



Comment at: clang/test/CodeGenHLSL/float3.hlsl:1
+// RUN: %clang --driver-mode=dxc -Tlib_6_7 -fcgl  -Fo - %s | FileCheck %s
+

Does this need to use driver mode? That is odd for a code gen test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132913

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-09-16 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic marked 2 inline comments as done.
jpenix-quic added inline comments.



Comment at: flang/runtime/environment.cpp:77
+#else
+  envp = environ;
+#endif

peixin wrote:
> What is `environ` used for? Should we try to keep as less extern variable as 
> possible in runtime for security.
I think `setenv` is only required to make sure that the `environ` pointer 
points to the correct copy of the environment variables. So, as long as we are 
storing a copy of the environment pointer in `ExecutionEnvironment` and 
potentially making changes to the environment via `setenv`, I think we need to 
base it off the `environ` pointer after `setenv` has been called rather than 
the `envp` from `main`.

That said, I don't think the `envp` variable we are storing is being used for 
anything at the moment (reading environment variables was changed to use 
`getenv` rather than `envp` in the commit [[ 
https://github.com/llvm/llvm-project/commit/824bf908194c9267f1f09065ba8e41d7969006ab
 | here]]). If removing the usage of `environ` is preferable, we could maybe 
remove the usage of `envp` altogether (in a separate patch)--does this sound 
like a good idea or would it be better to just leave in the `environ` usage for 
now?



Comment at: flang/test/Driver/emit-mlir.f90:16
 ! CHECK-NEXT: }
+! CHECK-NEXT: fir.global @_QQEnvironmentDefaults constant : 
!fir.ref, 
!fir.ref> {
+! CHECK-NEXT:  %[[VAL_0:.*]] = fir.zero_bits !fir.ref, !fir.ref>

peixin wrote:
> jpenix-quic wrote:
> > peixin wrote:
> > > Is it possible not to generated this global variable if `fconvert=` is 
> > > not specified?
> > I'm not entirely sure--the issue I was running into was how to handle this 
> > in Fortran_main.c in a way which worked for all of GCC/Clang/Visual Studio 
> > (and maybe others?). I was originally thinking of doing this by using a 
> > weak definition of _QQEnvironmentDefaults set to nullptr so fconvert, etc. 
> > could override this definition without explicitly generating the fallback 
> > case. For GCC/clang, I think I could use __attribute__((weak)), but I 
> > wasn't sure how to handle this if someone tried to build with Visual Studio 
> > (or maybe another toolchain). I saw a few workarounds (ex: 
> > https://devblogs.microsoft.com/oldnewthing/20200731-00/?p=104024) but I 
> > shied away from this since it seems to be an undocumented feature (and 
> > presumably only helps with Visual Studio). 
> > 
> > Do you know of a better or more general way I could do this? (Or, is there 
> > non-weak symbol approach that might be better that I'm missing?)
> How about generate one runtime function with the argument of 
> `EnvironmentDefaultList`? This will avoid this and using one extern variable?
> 
> If users use one variable with bind C name `_QQEnvironmentDefaults` in 
> fortran or one variable with name `_QQEnvironmentDefaults` in C, it is risky. 
> Would using the runtime function and static variable with the type 
> `EnvironmentDefaultList` in runtime be safer?
Agreed that there are potential risks with the current approach (although, are 
the `_Q*` names considered reserved?). Unfortunately, I think generating a call 
to set the environment defaults requires somewhat significant changes to the 
runtime. The runtime reads environment variables during initialization in 
`ExecutionEnvironment::Configure` which is ultimately called from the 
"hardcoded" `Fortran_main.c` and I need to set the defaults before this 
happens. So, I believe I'd either have to move the initialization to `_QQmain`  
or make it so that `main` isn't hardcoded so that I could insert the 
appropriate runtime function.

@klausler I think I asked you about this when I was first trying to figure out 
how to implement the environment defaults and you suggested I try the extern 
approach--please let me know if you have thoughts/suggestions around this!


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

https://reviews.llvm.org/D130513

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


[PATCH] D134020: [clang][Interp] Handle enums

2022-09-16 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:861
+
+return this->emitConst(T, getIntWidth(ECD->getType()), ECD->getInitVal(),
+   E);

If I check out `IntExprEvaluator::CheckReferenceDecl(...)` it is checking the 
sign and width match between the expression and the `EnumConstantDecl`. I am 
guessing we need to do that here as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134020

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


[PATCH] D134034: [test] Use host platform specific error message substitution

2022-09-16 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan updated this revision to Diff 460828.
abhina.sreeskantharajan added a comment.

Move subsitution outside regex


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134034

Files:
  clang/test/Format/style-on-command-line.cpp
  llvm/test/tools/llvm-dis/errors.test
  llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
  llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
  llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test


Index: llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test
===
--- llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test
+++ llvm/test/tools/llvm-tapi-diff/misspelled-tbd.test
@@ -1,3 +1,3 @@
-; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck 
%s
+; RUN: not llvm-tapi-diff %S/Inputs/v4A.tbd %S/Inputs/v4.tbd 2>&1 | FileCheck 
-DMSG=%errc_ENOENT %s
 
-; CHECK: error: {{.*}}v4.tbd' {{[Nn]}}o such file or directory
+; CHECK: error: {{.*}}v4.tbd' [[MSG]]
Index: llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
===
--- llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
+++ llvm/test/tools/llvm-reduce/mir/input-file-does-not-exist.mir
@@ -1,4 +1,4 @@
 # REQUIRES: amdgpu-registered-target
-# RUN: not llvm-reduce -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg 
%s --test-arg --input-file does-not-exist.mir 2>&1 | FileCheck 
-check-prefix=ERR %s
+# RUN: not llvm-reduce -mtriple=amdgcn-amd-amdhsa --test FileCheck --test-arg 
%s --test-arg --input-file does-not-exist.mir 2>&1 | FileCheck 
-DMSG=%errc_ENOENT -check-prefix=ERR %s
 
-# ERR: {{.*}}llvm-reduce{{.*}}: {{[Nn]}}o such file or directory
+# ERR: {{.*}}llvm-reduce{{.*}}: [[MSG]]
Index: llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
===
--- llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
+++ llvm/test/tools/llvm-dwp/X86/diagnose_missing_dwos.test
@@ -3,11 +3,11 @@
 RUN: cd %t
 RUN: cp %p/../Inputs/dwos_list_from_exec/b.dwo b.dwo
 RUN: cp %p/../Inputs/dwos_list_from_exec/main main
-RUN: not llvm-dwp -e binary -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-BIN
-RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-1ST-DWO
+RUN: not llvm-dwp -e binary -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT 
%s --check-prefix=CHECK-BIN
+RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=CHECK-1ST-DWO
 RUN: cp %p/../Inputs/dwos_list_from_exec/a.dwo a.dwo
 RUN: rm b.dwo
-RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck %s 
--check-prefix=CHECK-2ND-DWO
+RUN: not llvm-dwp -e main -o /dev/null 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=CHECK-2ND-DWO
 
 Build commands for the test binaries:
 
@@ -23,6 +23,6 @@
  return 0;
   }
 
-CHECK-BIN: error: 'binary': {{[Nn]}}o such file or directory
-CHECK-1ST-DWO: error: './a.dwo': {{[Nn]}}o such file or directory
-CHECK-2ND-DWO: error: './b.dwo': {{[Nn]}}o such file or directory
+CHECK-BIN: error: 'binary': [[MSG]]
+CHECK-1ST-DWO: error: './a.dwo': [[MSG]]
+CHECK-2ND-DWO: error: './b.dwo': [[MSG]]
Index: llvm/test/tools/llvm-dis/errors.test
===
--- llvm/test/tools/llvm-dis/errors.test
+++ llvm/test/tools/llvm-dis/errors.test
@@ -1,3 +1,3 @@
-# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck %s 
--check-prefix=MISSING --ignore-case
+# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck -DMSG=%errc_ENOENT %s 
--check-prefix=MISSING --ignore-case
 
-# MISSING: error: missing-file-path: no such file or directory
+# MISSING: error: missing-file-path: [[MSG]]
Index: clang/test/Format/style-on-command-line.cpp
===
--- clang/test/Format/style-on-command-line.cpp
+++ clang/test/Format/style-on-command-line.cpp
@@ -6,7 +6,7 @@
 // RUN: printf "BasedOnStyle: google\nIndentWidth: 5\n" > %t/.clang-format
 // RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck 
-strict-whitespace -check-prefix=CHECK5 %s
 // RUN: printf "Invalid:\n" > %t/.clang-format
-// RUN: not clang-format -style=file -fallback-style=webkit 
-assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -strict-whitespace 
-check-prefix=CHECK6 %s
+// RUN: not clang-format -style=file -fallback-style=webkit 
-assume-filename=%t/foo.cpp < %s 2>&1 | FileCheck -DMSG=%errc_EINVAL 
-strict-whitespace -check-prefix=CHECK6 %s
 // RUN: rm %t/.clang-format
 // RUN: printf "BasedOnStyle: google\nIndentWidth: 6\n" > %t/_clang-format
 // RUN: clang-format -style=file -assume-filename=%t/foo.cpp < %s | FileCheck 
-strict-whitespace -check-prefix=CHECK7 %s
@@ -35,7 +35,7 @@
 // CHECK4: Error parsing -style: [[MSG]]
 // CHECK5: {{^ int\* i;$}}
 // CHECK6: 

[PATCH] D133249: [libc++] Documents details of the pre-commit CI.

2022-09-16 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 460827.
Mordante marked 2 inline comments as done.
Mordante added a comment.

Addresses review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133249

Files:
  clang/www/hacking.html
  libcxx/docs/Contributing.rst
  libcxx/docs/index.rst

Index: libcxx/docs/index.rst
===
--- libcxx/docs/index.rst
+++ libcxx/docs/index.rst
@@ -93,6 +93,7 @@
   Further, both projects are apparently abandoned: STLport 5.2.1 was
   released in Oct'08, and STDCXX 4.2.1 in May'08.
 
+.. _SupportedPlatforms:
 
 Platform and Compiler Support
 =
Index: libcxx/docs/Contributing.rst
===
--- libcxx/docs/Contributing.rst
+++ libcxx/docs/Contributing.rst
@@ -84,5 +84,136 @@
 Look for the failed build and select the ``artifacts`` tab. There, download the
 abilist for the platform, e.g.:
 
-* C++20 for the Linux platform.
-* MacOS C++20 for the Apple platform.
+* C++.
+* MacOS X86_64 and MacOS arm64 for the Apple platform.
+
+
+Pre-commit CI
+=
+
+Introduction
+
+
+Unlike most parts of the LLVM project, libc++ uses a pre-commit CI [#]_. This
+CI is hosted on `Buildkite `__ and
+the build results are visible in the review on Phabricator. Please make sure
+the CI is green before committing a patch.
+
+The CI tests libc++ for all :ref:`supported platforms `.
+The build is started for every diff uploaded. A complete CI run takes
+approximately one hour. To reduce the load:
+
+* The build is cancelled when a new diff for the same revision is uploaded.
+* The build is done in several stages and cancelled when a stage fails.
+
+Typically, the libc++ jobs use a Ubuntu Docker image. This image contains
+recent `nightly builds `__ of all supported versions of
+Clang and the current version of the ``main`` branch. These versions of Clang
+are used to build libc++ and execute its tests.
+
+Unless specified otherwise, the configurations:
+
+* use a nightly build of the ``main`` branch of Clang,
+* execute the tests using the language C++. This is the version
+  "developed" by the C++ committee.
+
+.. note:: Updating the Clang nightly builds in the Docker image is a manual
+   process and is done at an irregular interval on purpose. When you need to
+   have the latest nightly build to test recent Clang changes, ask in the
+   ``#libcxx`` channel on `LLVM's Discord server
+   `__.
+
+.. [#] There's `LLVM Dev Meeting talk `__
+   explaining the benefits of libc++'s pre-commit CI.
+
+Builds
+--
+
+Below is a short description of the most interesting CI builds [#]_:
+
+* ``Format`` runs ``clang-format`` and uploads its output as an artifact. At the
+  moment this build is a soft error and doesn't fail the build.
+* ``Generated output`` runs the ``libcxx-generate-files`` build target and
+  tests for non-ASCII characters in libcxx. Some files are excluded since they
+  use Unicode, mainly tests. The output of these commands are uploaded as
+  artifact.
+* ``Documentation`` builds the documentation. (This is done early in the build
+  process since it is cheap to run.)
+* ``C++`` these build steps test the various C++ versions, making sure all
+  C++ language versions work with the changes made.
+* ``Clang `` these build steps test whether the changes work with all
+  supported Clang versions.
+* ``Booststrapping build`` builds Clang using the revision of the patch and
+  uses that Clang version to build and test libc++. This validates the current
+  Clang and lib++ are compatible.
+
+  When a crash occurs in this build, the crash reproducer is available as an
+  artifact.
+
+* ``Modular build`` tests libc++ using Clang modules [#]_.
+* ``GCC `` tests libc++ with the latest stable GCC version. Only C++11
+  and the latest C++ version are tested.
+* ``Santitizers`` tests libc++ using the Clang sanitizers.
+* ``Parts disabled`` tests libc++ with certain libc++ features disabled.
+* ``Windows`` tests libc++ using MinGW and clang-cl.
+* ``Apple`` tests libc++ on MacOS.
+* ``ARM`` tests libc++ on various Linux ARM platforms.
+* ``AIX`` tests libc++ on AIX.
+
+.. [#] Not all all steps are listed: steps are added and removed when the need
+   arises.
+.. [#] Clang modules are not the same as C++20's modules.
+
+Infrastructure
+--
+
+All files of the CI infrastructure are in the directory ``libcxx/utils/ci``.
+Note that quite a bit of this infrastructure is heavily Linux focused. This is
+the platform used by most of libc++'s Buildkite runners and developers.
+
+Dockerfile
+~~
+
+Contains the Docker image for the Ubuntu CI. Because the same Docker image is
+used for the ``main`` and 

[PATCH] D133249: [libc++] Documents details of the pre-commit CI.

2022-09-16 Thread Mark de Wever via Phabricator via cfe-commits
Mordante marked 24 inline comments as done.
Mordante added inline comments.



Comment at: clang/www/hacking.html:295-296
+  directory will cause the update of the diff to start a CI run. This dummy
+  file will also add the libc++ group to the list of reviewers. The status of
+  the build will be available in Phabricator.
+

zero9178 wrote:
> tahonermann wrote:
> > ldionne wrote:
> > > Mordante wrote:
> > > > philnik wrote:
> > > > > aaron.ballman wrote:
> > > > > > I am guessing the dummy file should then be removed before landing 
> > > > > > the commit and we should document that?
> > > > > > 
> > > > > > (FWIW, adding a dummy file feels really unclean as a design -- it's 
> > > > > > mysterious behavior for new contributors, which the documentation 
> > > > > > helps with a bit, but also it's a risk for checking in files that 
> > > > > > are never intended to be in the tree. If there's a way to improve 
> > > > > > this somehow so we don't need to trick the precommit CI into 
> > > > > > running, that would be really nice and totally outside of the scope 
> > > > > > of this review.)
> > > > > It would be great if just the bootstrapping build could be run on all 
> > > > > clang reviews. That should show most problems with changes in clang. 
> > > > > If there are any problems in libc++, fixing them would result in a 
> > > > > full CI run. Having libc++ run against the patch would probably also 
> > > > > be awesome as a smoke test for any clang changes.
> > > > +1 to what @ldionne said.
> > > > 
> > > > One of the advantages would be that it's possible to test Clang against 
> > > > the libc++ code base using different language versions, by defining 
> > > > multiple test runs using different language versions. (Slightly related 
> > > > to 
> > > > https://discourse.llvm.org/t/lit-run-a-run-line-multiple-times-with-different-replacements/64932)
> > > >  @aaron.ballman is looking at extending the Clang pre-commit CI 
> > > > something worth looking into?
> > > > 
> > > > 
> > > I agree. Let's:
> > > 
> > > 1. Setup a `buildkite-pipeline.yml` file that controls the jobs done for 
> > > Clang. I think right now this is hardcoded somewhere in 
> > > https://github.com/google/llvm-premerge-checks
> > > 2. Simply add `LLVM_ENABLE_RUNTIMES=libcxx` to the config that Clang uses 
> > > so they'll automatically build libc++ with the Clang that was just built 
> > > anyway. That would run on Clang's own agents that are used for Clang 
> > > tests, not on the libc++ CI agents. We can adjust if running the libc++ 
> > > tests causes too much strain on the infrastructure running Clang CI.
> > > 
> > > That way, a basic bootstrapping build of libc++ will be run on every 
> > > Clang change, and TBH I think all of this added documentation for Clang 
> > > folks to test libc++ changes can simply go away. There really wouldn't be 
> > > a reason to ever add a `.DELETE_ME` file to libc++ for a Clang patch 
> > > anymore.
> > This sounds like a good approach to me. This might be a bit tangential, but 
> > if `libcxx` is present in `LLVM_ENABLE_RUNTIMES`, could we also have the 
> > `check-all` target depend on `check-libcxx`? That would help ensure that 
> > developers run libc++ tests locally before they hit the CI infrastructure. 
> > Likewise for `compiler-rt` and `libcxxabi` and the `check-runtimes` target.
> This is currently being implemented by https://reviews.llvm.org/D132438 and 
> landed before but had to be reverted unfortunately.
I removed the part of the dummy file.

Having a `check-all` indeed sounds very nice to have.



Comment at: clang/www/hacking.html:311-312
+  Unlike Clang, libc++ supports multiple versions of Clang. Therefore when a
+  patch changes the diagnostics it might be required to use a regex in the
+  expected tests to make it pass the CI.
+

Mordante wrote:
> philnik wrote:
> > aaron.ballman wrote:
> > > Should we document the expectation that breaking libc++ due to conforming 
> > > changes in Clang (in terms of diagnostics and bug fixes, not so much in 
> > > terms of introducing new language extensions) are generally the 
> > > responsibility of libc++ maintainers to address, but Clang contributors 
> > > should attempt to reduce disruptions as much as possible by collaborating 
> > > with libc++ maintainers when this situation comes up?
> > That's definitely a good idea. Maybe mention that clang contributors should 
> > ping the #libc group to get the attention of libc++ contributors so we can 
> > prepare a follow-up patch or, if the author is comfortable with it, also 
> > fix libc++ in the same patch (and hopefully get fast approval). Most 
> > breakages should be relatively simple to fix.
> I like the idea to collaborate more.
> 
> I want to give this some thought and especially how to word it. I want to 
> avoid that it's seen as a carte blanche to commit Clang changes which break 
> libc++. This would mean HEAD 

[clang] a4f8e3d - Revert "[clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`."

2022-09-16 Thread Wei Yi Tee via cfe-commits

Author: Wei Yi Tee
Date: 2022-09-16T18:07:35Z
New Revision: a4f8e3d24087356ba75eb6f3bd4e1af436c83270

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

LOG: Revert "[clang][dataflow] Replace `transfer(const Stmt *, ...)` with 
`transfer(const CFGElement *, ...)` in 
`Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`."

This reverts commit 41f235d26887946f472d71a8417507c35d5f9074.

Details at https://lab.llvm.org/buildbot#builders/139/builds/28171.
Breakage due to API change.

Added: 


Modified: 

clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
index 66aabb531a213..25054deaf8afc 100644
--- 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
+++ 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
@@ -15,10 +15,10 @@
 #define CLANG_ANALYSIS_FLOWSENSITIVE_MODELS_UNCHECKEDOPTIONALACCESSMODEL_H
 
 #include "clang/AST/ASTContext.h"
-#include "clang/Analysis/CFG.h"
-#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
+#include "clang/AST/Stmt.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
 #include "clang/Basic/SourceLocation.h"
 #include 
@@ -45,14 +45,14 @@ class UncheckedOptionalAccessModel
 : public DataflowAnalysis {
 public:
   UncheckedOptionalAccessModel(
-  ASTContext , UncheckedOptionalAccessModelOptions Options = {});
+  ASTContext , UncheckedOptionalAccessModelOptions Options = 
{});
 
   /// Returns a matcher for the optional classes covered by this model.
   static ast_matchers::DeclarationMatcher optionalClassDecl();
 
   static NoopLattice initialElement() { return {}; }
 
-  void transfer(const CFGElement *Elt, NoopLattice , Environment );
+  void transfer(const Stmt *Stmt, NoopLattice , Environment );
 
   bool compareEquivalent(QualType Type, const Value ,
  const Environment , const Value ,
@@ -63,7 +63,7 @@ class UncheckedOptionalAccessModel
  Environment ) override;
 
 private:
-  CFGMatchSwitch> TransferMatchSwitch;
+  MatchSwitch> TransferMatchSwitch;
 };
 
 class UncheckedOptionalAccessDiagnoser {
@@ -71,11 +71,11 @@ class UncheckedOptionalAccessDiagnoser {
   UncheckedOptionalAccessDiagnoser(
   UncheckedOptionalAccessModelOptions Options = {});
 
-  std::vector diagnose(ASTContext , const CFGElement *Elt,
+  std::vector diagnose(ASTContext , const Stmt *Stmt,
const Environment );
 
 private:
-  CFGMatchSwitch>
+  MatchSwitch>
   DiagnoseMatchSwitch;
 };
 

diff  --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index 1ffd88697f3a7..eef3cc813a4ac 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -18,9 +18,8 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Analysis/CFG.h"
-#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Basic/SourceLocation.h"
@@ -560,42 +559,41 @@ auto buildTransferMatchSwitch(
   // lot of duplicated work (e.g. string comparisons), consider providing APIs
   // that avoid it through memoization.
   auto IgnorableOptional = ignorableOptional(Options);
-  return CFGMatchSwitchBuilder()
+  return MatchSwitchBuilder()
   // Attach a symbolic "has_value" state to optional values that we see for
   // the first time.
-  .CaseOfCFGStmt(
+  .CaseOf(
   expr(anyOf(declRefExpr(), memberExpr()), hasOptionalType()),
   initializeOptionalReference)
 
   // make_optional
-  .CaseOfCFGStmt(isMakeOptionalCall(), transferMakeOptionalCall)
+  .CaseOf(isMakeOptionalCall(), transferMakeOptionalCall)
 
   // optional::optional
-  .CaseOfCFGStmt(
+  .CaseOf(
   isOptionalInPlaceConstructor(),
   [](const 

[clang] 41f235d - [clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.

2022-09-16 Thread Wei Yi Tee via cfe-commits

Author: Wei Yi Tee
Date: 2022-09-16T17:54:12Z
New Revision: 41f235d26887946f472d71a8417507c35d5f9074

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

LOG: [clang][dataflow] Replace `transfer(const Stmt *, ...)` with 
`transfer(const CFGElement *, ...)` in 
`Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.

Reviewed By: gribozavr2, sgatev

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

Added: 


Modified: 

clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
index 25054deaf8afc..66aabb531a213 100644
--- 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
+++ 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
@@ -15,10 +15,10 @@
 #define CLANG_ANALYSIS_FLOWSENSITIVE_MODELS_UNCHECKEDOPTIONALACCESSMODEL_H
 
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/Stmt.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
-#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
 #include "clang/Basic/SourceLocation.h"
 #include 
@@ -45,14 +45,14 @@ class UncheckedOptionalAccessModel
 : public DataflowAnalysis {
 public:
   UncheckedOptionalAccessModel(
-  ASTContext , UncheckedOptionalAccessModelOptions Options = 
{});
+  ASTContext , UncheckedOptionalAccessModelOptions Options = {});
 
   /// Returns a matcher for the optional classes covered by this model.
   static ast_matchers::DeclarationMatcher optionalClassDecl();
 
   static NoopLattice initialElement() { return {}; }
 
-  void transfer(const Stmt *Stmt, NoopLattice , Environment );
+  void transfer(const CFGElement *Elt, NoopLattice , Environment );
 
   bool compareEquivalent(QualType Type, const Value ,
  const Environment , const Value ,
@@ -63,7 +63,7 @@ class UncheckedOptionalAccessModel
  Environment ) override;
 
 private:
-  MatchSwitch> TransferMatchSwitch;
+  CFGMatchSwitch> TransferMatchSwitch;
 };
 
 class UncheckedOptionalAccessDiagnoser {
@@ -71,11 +71,11 @@ class UncheckedOptionalAccessDiagnoser {
   UncheckedOptionalAccessDiagnoser(
   UncheckedOptionalAccessModelOptions Options = {});
 
-  std::vector diagnose(ASTContext , const Stmt *Stmt,
+  std::vector diagnose(ASTContext , const CFGElement *Elt,
const Environment );
 
 private:
-  MatchSwitch>
+  CFGMatchSwitch>
   DiagnoseMatchSwitch;
 };
 

diff  --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index eef3cc813a4ac..1ffd88697f3a7 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -18,8 +18,9 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
-#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Basic/SourceLocation.h"
@@ -559,41 +560,42 @@ auto buildTransferMatchSwitch(
   // lot of duplicated work (e.g. string comparisons), consider providing APIs
   // that avoid it through memoization.
   auto IgnorableOptional = ignorableOptional(Options);
-  return MatchSwitchBuilder()
+  return CFGMatchSwitchBuilder()
   // Attach a symbolic "has_value" state to optional values that we see for
   // the first time.
-  .CaseOf(
+  .CaseOfCFGStmt(
   expr(anyOf(declRefExpr(), memberExpr()), hasOptionalType()),
   initializeOptionalReference)
 
   // make_optional
-  .CaseOf(isMakeOptionalCall(), transferMakeOptionalCall)
+  .CaseOfCFGStmt(isMakeOptionalCall(), transferMakeOptionalCall)
 
   // optional::optional
-  .CaseOf(
+  .CaseOfCFGStmt(
   isOptionalInPlaceConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState ) 

[PATCH] D133930: [clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.

2022-09-16 Thread weiyi 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 rG41f235d26887: [clang][dataflow] Replace `transfer(const Stmt 
*, ...)` with `transfer(const… (authored by wyt).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133930

Files:
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -14,10 +14,8 @@
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Tooling.h"
-#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -1248,13 +1246,9 @@
  Diagnoser = UncheckedOptionalAccessDiagnoser(Options)](
 ASTContext , const CFGElement ,
 const TypeErasedDataflowAnalysisState ) mutable {
-  auto Stmt = Elt.getAs();
-  if (!Stmt) {
-return;
-  }
-  auto StmtDiagnostics =
-  Diagnoser.diagnose(Ctx, Stmt->getStmt(), State.Env);
-  llvm::move(StmtDiagnostics, std::back_inserter(Diagnostics));
+  auto EltDiagnostics =
+  Diagnoser.diagnose(Ctx, , State.Env);
+  llvm::move(EltDiagnostics, std::back_inserter(Diagnostics));
 })
 .withASTBuildArgs(
 {"-fsyntax-only", "-std=c++17", "-Wno-undefined-inline"})
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -18,8 +18,9 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
-#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Basic/SourceLocation.h"
@@ -559,41 +560,42 @@
   // lot of duplicated work (e.g. string comparisons), consider providing APIs
   // that avoid it through memoization.
   auto IgnorableOptional = ignorableOptional(Options);
-  return MatchSwitchBuilder()
+  return CFGMatchSwitchBuilder()
   // Attach a symbolic "has_value" state to optional values that we see for
   // the first time.
-  .CaseOf(
+  .CaseOfCFGStmt(
   expr(anyOf(declRefExpr(), memberExpr()), hasOptionalType()),
   initializeOptionalReference)
 
   // make_optional
-  .CaseOf(isMakeOptionalCall(), transferMakeOptionalCall)
+  .CaseOfCFGStmt(isMakeOptionalCall(), transferMakeOptionalCall)
 
   // optional::optional
-  .CaseOf(
+  .CaseOfCFGStmt(
   isOptionalInPlaceConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState ) {
 assignOptionalValue(*E, State, State.Env.getBoolLiteralValue(true));
   })
-  .CaseOf(
+  .CaseOfCFGStmt(
   isOptionalNulloptConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState ) {
 assignOptionalValue(*E, State,
 State.Env.getBoolLiteralValue(false));
   })
-  .CaseOf(isOptionalValueOrConversionConstructor(),
-transferValueOrConversionConstructor)
+  .CaseOfCFGStmt(isOptionalValueOrConversionConstructor(),
+   transferValueOrConversionConstructor)
 
   // optional::operator=
-  .CaseOf(isOptionalValueOrConversionAssignment(),
-   transferValueOrConversionAssignment)
-  .CaseOf(isOptionalNulloptAssignment(),
-   transferNulloptAssignment)
+  .CaseOfCFGStmt(
+  isOptionalValueOrConversionAssignment(),
+  transferValueOrConversionAssignment)
+  

[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-09-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9468
+  // Control constants for math operations.
+  AddGlobal("__oclc_wavefrontsize64", Wavefront64, /*Size=*/8);
+  AddGlobal("__oclc_daz_opt", DenormAreZero, /*Size=*/8);

yaxunl wrote:
> jhuber6 wrote:
> > arsenm wrote:
> > > yaxunl wrote:
> > > > we need to disable emitting these variables for HIP -fgpu-rdc mode and 
> > > > OpenCL since they will break per-TU control variable. Other cases are 
> > > > OK.
> > > wavefrontsize belongs with the system ones
> > But the code would still depend on these and they wouldn't be present right
> > wavefrontsize belongs with the system ones
> 
> You are right. `__oclc_wavefrontsize64` should always be emitted with 
> linkonce_odr linkage since they need to be consistent among TU's. Therefore 
> they should always be emitted.
> 
> `__oclc_daz_opt`, `__oclc_finite_only_opt`, `__oclc_unsafe_math_opt`, and 
> `__oclc_correctly_rounded_sqrt32` can be different per TU, therefore they 
> should not be emitted for HIP `-fgpu-rdc` and OpenCL.
I'm still unsure, if we do not emit any of those control variables how will we 
use the device libraries for those builds.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D128372: [Clang-Tidy] Empty Check

2022-09-16 Thread Denis Nikitin via Phabricator via cfe-commits
denik added a comment.

Any updates from the reviewers?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

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


[PATCH] D134057: [clang][Interp] Start implementing record types

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:316
+  // Base above gives us a pointer on the stack.
+  const auto *FD = dyn_cast(Member);
+  assert(FD);

I THINK Member is a ValueDecl because it could be a member function, right?  So 
forcing it to be a FieldDecl here is likely not valid.  Perhaps in the 
'non-FieldDecl' case we could jsut return false for now?

ALSO, don't do a dyn_cast followed by an assert, `cast` will do the assert for 
you.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:659
+
+// FIXME
+const Stmt *Body = Ctor->getBody();

Eh?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134057

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


[PATCH] D134018: [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG587729c3ad78: [clang] [Driver] Add an option to disable 
default config filenames (authored by mgorny).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D134018?vs=460665=460822#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134018

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/config-file3.c


Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -40,7 +40,13 @@
 // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config 
--config-user-dir= --config i386-qqq -c -no-canonical-prefixes -### %s 2>&1 | 
FileCheck %s -check-prefix CHECK-EXPLICIT
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
+
+//--- --no-default-config disables config search.
+//
+// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= 
--config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck 
%s -check-prefix NO-DEFAULT-CONFIG
 //
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if 
qqq-clang-g++.cfg is not found.
 //
 // RUN: rm %t/testdmode/qqq-clang-g++.cfg
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1024,11 +1024,14 @@
 }
   }
 
-  // If config file is not specified explicitly, try to deduce configuration
-  // from executable name. For instance, an executable 'armv7l-clang' will
-  // search for config file 'armv7l-clang.cfg'.
-  if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
-CfgFileName = ClangNameParts.TargetPrefix + '-' + 
ClangNameParts.ModeSuffix;
+  if (!(CLOptions && CLOptions->hasArg(options::OPT_no_default_config))) {
+// If config file is not specified explicitly, try to deduce configuration
+// from executable name. For instance, an executable 'armv7l-clang' will
+// search for config file 'armv7l-clang.cfg'.
+if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
+  CfgFileName =
+  ClangNameParts.TargetPrefix + '-' + ClangNameParts.ModeSuffix;
+  }
 
   if (CfgFileName.empty())
 return false;
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -901,6 +901,8 @@
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
 def config : Separate<["--"], "config">, Flags<[NoXarchOption]>,
   HelpText<"Specifies configuration file">;
+def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption]>,
+  HelpText<"Disable loading default configuration files">;
 def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
   HelpText<"System directory for configuration files">;
 def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -904,6 +904,10 @@
 CLANG_CONFIG_FILE_SYSTEM_DIR respectively. The first file found is used. It is
 an error if the required file cannot be found.
 
+If no explicit configuration file is specified, Clang searches for a default
+configuration file following the rules described in the next paragraphs.
+To disable this behavior, `--no-default-config` flag can be used.
+
 Another way to specify a configuration file is to encode it in executable name.
 For example, if the Clang executable is named `armv7l-clang` (it may be a
 symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the


Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -40,7 +40,13 @@
 // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config i386-qqq -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-EXPLICIT
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
+
+//--- --no-default-config disables config search.
+//
+// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= --config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck %s -check-prefix NO-DEFAULT-CONFIG
 //
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if qqq-clang-g++.cfg is not 

[clang] 587729c - [clang] [Driver] Add an option to disable default config filenames

2022-09-16 Thread Michał Górny via cfe-commits

Author: Michał Górny
Date: 2022-09-16T19:38:11+02:00
New Revision: 587729c3ad78aec6ec5a295331b16f21e340feb1

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

LOG: [clang] [Driver] Add an option to disable default config filenames

Add a `--no-default-config` option that disables the search for default
set of config filenames (based on the compiler executable name).

Suggested in 
https://discourse.llvm.org/t/rfc-adding-a-default-file-location-to-config-file-support/63606.

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

Added: 


Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/config-file3.c

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index bc107be41fab8..9eb2e0dbb1e2e 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -904,6 +904,10 @@ clang build using CMake parameters, 
CLANG_CONFIG_FILE_USER_DIR and
 CLANG_CONFIG_FILE_SYSTEM_DIR respectively. The first file found is used. It is
 an error if the required file cannot be found.
 
+If no explicit configuration file is specified, Clang searches for a default
+configuration file following the rules described in the next paragraphs.
+To disable this behavior, `--no-default-config` flag can be used.
+
 Another way to specify a configuration file is to encode it in executable name.
 For example, if the Clang executable is named `armv7l-clang` (it may be a
 symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a1071294ff6f5..8dea1a01c1f89 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -901,6 +901,8 @@ def combine : Flag<["-", "--"], "combine">, 
Flags<[NoXarchOption, Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
 def config : Separate<["--"], "config">, Flags<[NoXarchOption]>,
   HelpText<"Specifies configuration file">;
+def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption]>,
+  HelpText<"Disable loading default configuration files">;
 def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
   HelpText<"System directory for configuration files">;
 def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 217236f459a50..d8b13730f5885 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1024,11 +1024,14 @@ bool Driver::loadConfigFile() {
 }
   }
 
-  // If config file is not specified explicitly, try to deduce configuration
-  // from executable name. For instance, an executable 'armv7l-clang' will
-  // search for config file 'armv7l-clang.cfg'.
-  if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
-CfgFileName = ClangNameParts.TargetPrefix + '-' + 
ClangNameParts.ModeSuffix;
+  if (!(CLOptions && CLOptions->hasArg(options::OPT_no_default_config))) {
+// If config file is not specified explicitly, try to deduce configuration
+// from executable name. For instance, an executable 'armv7l-clang' will
+// search for config file 'armv7l-clang.cfg'.
+if (CfgFileName.empty() && !ClangNameParts.TargetPrefix.empty())
+  CfgFileName =
+  ClangNameParts.TargetPrefix + '-' + ClangNameParts.ModeSuffix;
+  }
 
   if (CfgFileName.empty())
 return false;

diff  --git a/clang/test/Driver/config-file3.c 
b/clang/test/Driver/config-file3.c
index 8efe1e555a3c8..7fdc2a59133a8 100644
--- a/clang/test/Driver/config-file3.c
+++ b/clang/test/Driver/config-file3.c
@@ -40,7 +40,13 @@
 // RUN: %t/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config 
--config-user-dir= --config i386-qqq -c -no-canonical-prefixes -### %s 2>&1 | 
FileCheck %s -check-prefix CHECK-EXPLICIT
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
+
+//--- --no-default-config disables config search.
+//
+// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir= 
--config-user-dir=%t/testdmode --no-default-config -c -### %s 2>&1 | FileCheck 
%s -check-prefix NO-DEFAULT-CONFIG
 //
+// NO-DEFAULT-CONFIG-NOT: Configuration file:
+
 //--- Invocation qqq-clang-g++ tries to find config file qqq.cfg if 
qqq-clang-g++.cfg is not found.
 //
 // RUN: rm %t/testdmode/qqq-clang-g++.cfg



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


[PATCH] D134054: [clang][Interp] Properly destruct allocated Records

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/AST/Interp/Program.h:48
+// here manually so they are properly freeing their resources.
+for (auto It : Records)
+  It.second->~Record();

tbaeder wrote:
> erichkeane wrote:
> > I SUSPECT that by a reading of our rules here, we aren't allowed to use 
> > `auto` here.  That said, I'm sure I don't want to have you spell out the 
> > whole LHS.  
> > 
> > THOUGH the name "It" is a little misleading, as this is NOT an iterator, it 
> > ends up being a std::pair or something I think... 
> Would `RecordPair` be better?
Sure, good enough.

Feel free to come up with whatever and commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134054

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


[PATCH] D134054: [clang][Interp] Properly destruct allocated Records

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Program.h:48
+// here manually so they are properly freeing their resources.
+for (auto It : Records)
+  It.second->~Record();

erichkeane wrote:
> I SUSPECT that by a reading of our rules here, we aren't allowed to use 
> `auto` here.  That said, I'm sure I don't want to have you spell out the 
> whole LHS.  
> 
> THOUGH the name "It" is a little misleading, as this is NOT an iterator, it 
> ends up being a std::pair or something I think... 
Would `RecordPair` be better?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134054

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-09-16 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic updated this revision to Diff 460819.
jpenix-quic added a comment.

Remove unneeded braces and unnecessary changes to NameUniquer.


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

https://reviews.llvm.org/D130513

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/examples/external-hello.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/include/flang/Lower/Bridge.h
  flang/include/flang/Optimizer/Builder/Runtime/EnvironmentDefaults.h
  flang/include/flang/Runtime/environment-defaults.h
  flang/include/flang/Runtime/main.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Lower/Bridge.cpp
  flang/lib/Optimizer/Builder/CMakeLists.txt
  flang/lib/Optimizer/Builder/Runtime/EnvironmentDefaults.cpp
  flang/runtime/FortranMain/Fortran_main.c
  flang/runtime/environment-default-list.h
  flang/runtime/environment.cpp
  flang/runtime/environment.h
  flang/runtime/main.cpp
  flang/test/Driver/convert.f90
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/emit-mlir.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Lower/convert.f90
  flang/test/Lower/environment-defaults.f90
  flang/test/Runtime/no-cpp-dep.c
  flang/tools/bbc/bbc.cpp
  flang/unittests/Runtime/CommandTest.cpp
  flang/unittests/Runtime/Stop.cpp

Index: flang/unittests/Runtime/Stop.cpp
===
--- flang/unittests/Runtime/Stop.cpp
+++ flang/unittests/Runtime/Stop.cpp
@@ -26,7 +26,8 @@
 
 TEST(TestProgramEnd, StopTestNoStopMessage) {
   putenv(const_cast("NO_STOP_MESSAGE=1"));
-  Fortran::runtime::executionEnvironment.Configure(0, nullptr, nullptr);
+  Fortran::runtime::executionEnvironment.Configure(
+  0, nullptr, nullptr, nullptr);
   EXPECT_EXIT(
   RTNAME(StopStatement)(), testing::ExitedWithCode(EXIT_SUCCESS), "");
 }
@@ -52,7 +53,8 @@
 
 TEST(TestProgramEnd, NoStopMessageTest) {
   putenv(const_cast("NO_STOP_MESSAGE=1"));
-  Fortran::runtime::executionEnvironment.Configure(0, nullptr, nullptr);
+  Fortran::runtime::executionEnvironment.Configure(
+  0, nullptr, nullptr, nullptr);
   static const char *message{"bye bye"};
   EXPECT_EXIT(RTNAME(StopStatementText)(message, std::strlen(message),
   /*isErrorStop=*/false, /*quiet=*/false),
Index: flang/unittests/Runtime/CommandTest.cpp
===
--- flang/unittests/Runtime/CommandTest.cpp
+++ flang/unittests/Runtime/CommandTest.cpp
@@ -49,7 +49,7 @@
 class CommandFixture : public ::testing::Test {
 protected:
   CommandFixture(int argc, const char *argv[]) {
-RTNAME(ProgramStart)(argc, argv, {});
+RTNAME(ProgramStart)(argc, argv, {}, {});
   }
 
   std::string GetPaddedStr(const char *text, std::size_t len) const {
Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -222,7 +222,7 @@
   auto burnside = Fortran::lower::LoweringBridge::create(
   ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
   semanticsContext.targetCharacteristics(), parsing.allCooked(), "",
-  kindMap, loweringOptions);
+  kindMap, loweringOptions, {});
   burnside.lower(parseTree, semanticsContext);
   mlir::ModuleOp mlirModule = burnside.getModule();
   std::error_code ec;
Index: flang/test/Runtime/no-cpp-dep.c
===
--- flang/test/Runtime/no-cpp-dep.c
+++ flang/test/Runtime/no-cpp-dep.c
@@ -16,18 +16,20 @@
 we're testing. We can't include any headers directly since they likely contain
 C++ code that would explode here.
 */
+struct EnvironmentDefaultList;
 struct Descriptor;
 
 double RTNAME(CpuTime)();
 
-void RTNAME(ProgramStart)(int, const char *[], const char *[]);
+void RTNAME(ProgramStart)(
+int, const char *[], const char *[], const struct EnvironmentDefaultList *);
 int32_t RTNAME(ArgumentCount)();
 int32_t RTNAME(GetCommandArgument)(int32_t, const struct Descriptor *,
 const struct Descriptor *, const struct Descriptor *);
 
 int main() {
   double x = RTNAME(CpuTime)();
-  RTNAME(ProgramStart)(0, 0, 0);
+  RTNAME(ProgramStart)(0, 0, 0, 0);
   int32_t c = RTNAME(ArgumentCount)();
   int32_t v = RTNAME(GetCommandArgument)(0, 0, 0, 0);
   return x + c + v;
Index: flang/test/Lower/environment-defaults.f90
===
--- /dev/null
+++ flang/test/Lower/environment-defaults.f90
@@ -0,0 +1,11 @@
+! RUN: bbc -emit-fir -o - %s | FileCheck %s
+
+program test
+  continue
+end
+
+! Test that a null pointer is generated for environment defaults if nothing is specified
+
+! CHECK: fir.global @_QQEnvironmentDefaults constant : !fir.ref, !fir.ref> {
+! CHECK:  %[[VAL_0:.*]] = fir.zero_bits !fir.ref, !fir.ref>
+! CHECK: 

[PATCH] D134057: [clang][Interp] Start implementing record types

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is just a humble beginning of course.

Posting this now for your weekend reading. And also to keep the individual 
patches small.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134057

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/records.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify %s
+// RUN: %clang_cc1 -verify=ref %s
+
+// expected-no-diagnostics
+// ref-no-diagnostics
+
+struct Ints {
+  int a = 20;
+  int b = 30;
+  bool c = true;
+};
+
+constexpr Ints ints;
+static_assert(ints.a == 20, "");
+static_assert(ints.b == 30, "");
+static_assert(ints.c, "");
+
+struct Ints2 {
+  int a = 10;
+  int b;
+};
+// FIXME: Broken in the new constant interpreter.
+//constexpr Ints2 ints2;
+
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -492,6 +492,9 @@
   return true;
 }
 
+/// 1) Pops the value from the stack
+/// 2) Pops a pointer from the stack
+/// 3) Writes the value to field I of the pointer
 template ::T>
 bool InitField(InterpState , CodePtr OpPC, uint32_t I) {
   const T  = S.Stk.pop();
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -71,6 +71,7 @@
   bool VisitBinaryOperator(const BinaryOperator *E);
   bool VisitCXXDefaultArgExpr(const CXXDefaultArgExpr *E);
   bool VisitCallExpr(const CallExpr *E);
+  bool VisitCXXDefaultInitExpr(const CXXDefaultInitExpr *E);
   bool VisitCXXBoolLiteralExpr(const CXXBoolLiteralExpr *E);
   bool VisitCXXNullPtrLiteralExpr(const CXXNullPtrLiteralExpr *E);
   bool VisitUnaryOperator(const UnaryOperator *E);
@@ -81,6 +82,7 @@
   bool VisitInitListExpr(const InitListExpr *E);
   bool VisitConstantExpr(const ConstantExpr *E);
   bool VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
+  bool VisitMemberExpr(const MemberExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -138,6 +140,8 @@
   bool visitInitializer(const Expr *E);
   /// Compiles an array initializer.
   bool visitArrayInitializer(const Expr *Initializer);
+  /// Compiles a record initializer.
+  bool visitRecordInitializer(const Expr *Initializer);
 
   /// Visits an expression and converts it to a boolean.
   bool visitBool(const Expr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -303,6 +303,26 @@
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitMemberExpr(const MemberExpr *E) {
+  // 'Base.Member'
+  const Expr *Base = E->getBase();
+  const ValueDecl *Member = E->getMemberDecl();
+
+  if (!this->visit(Base))
+return false;
+
+  // Base above gives us a pointer on the stack.
+  const auto *FD = dyn_cast(Member);
+  assert(FD);
+  const RecordDecl *RD = FD->getParent();
+  assert(RD);
+  const Record *R = P.getOrCreateRecord(RD);
+  const Record::Field *F = R->getField(FD);
+  // Leave a pointer to the field on the stack.
+  return this->emitGetPtrField(F->Offset, E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) {
   OptionScope Scope(this, /*NewDiscardResult=*/true);
   return this->Visit(E);
@@ -607,6 +627,44 @@
   return true;
 }
 
+template 
+bool ByteCodeExprGen::visitRecordInitializer(const Expr *Initializer) {
+  assert(Initializer->getType()->isRecordType());
+
+  if (const auto CtorExpr = dyn_cast(Initializer)) {
+const CXXConstructorDecl *Ctor = CtorExpr->getConstructor();
+const RecordDecl *RD = Ctor->getParent();
+const Record *R = P.getOrCreateRecord(RD);
+
+for (const auto *Init : Ctor->inits()) {
+  const FieldDecl *Member = Init->getMember();
+  const Expr *InitExpr = Init->getInit();
+
+  if (Optional T = classify(InitExpr->getType())) {
+const Record::Field *F = R->getField(Member);
+
+if (!this->emitDupPtr(Initializer))
+  return false;
+
+if (!this->visit(InitExpr))
+  return false;
+
+if (!this->emitInitField(*T, F->Offset, Initializer))
+  return false;
+  } else {
+assert(false && "Handle initializer for non-primitive values");
+  }
+}
+
+// FIXME
+const Stmt *Body = Ctor->getBody();
+(void)Body;
+ 

[PATCH] D133732: [clang-doc] Support default args for functions.

2022-09-16 Thread Paul Kirth via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe191086bfcb7: [clang-doc] Support default args for 
functions. (authored by brettw, committed by paulkirth).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133732

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.h
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -209,6 +209,8 @@
   I.ReturnType =
   TypeInfo(EmptySID, "void", InfoType::IT_default, "path/to/void");
   I.Params.emplace_back("int", "path/to/int", "P");
+  I.Params.emplace_back("double", "path/to/double", "D");
+  I.Params.back().DefaultValue = "2.0 * M_PI";
   I.IsMethod = true;
   I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
 
@@ -240,6 +242,11 @@
   Name:'int'
   Path:'path/to/int'
 Name:'P'
+  - Type:
+  Name:'double'
+  Path:'path/to/double'
+Name:'D'
+DefaultValue:'2.0 * M_PI'
 ReturnType:
   Type:
 Name:'void'
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -511,7 +511,7 @@
   std::vector Args;
   Args.push_back("-fmodules-ts");
   ExtractInfosFromCodeWithArgs(R"raw(export module M;
-int moduleFunction(int x);
+int moduleFunction(int x, double d = 3.2 - 1.0);
 static int staticModuleFunction(int x);
 export double exportedModuleFunction(double y);)raw",
2, /*Public=*/true, Infos, Args);
@@ -523,6 +523,8 @@
   F.ReturnType = TypeInfo(EmptySID, "int", InfoType::IT_default);
   F.Loc.emplace_back(0, llvm::SmallString<16>{"test.cpp"});
   F.Params.emplace_back("int", "x");
+  F.Params.emplace_back("double", "d");
+  F.Params.back().DefaultValue = "3.2 - 1.0";
   F.Access = AccessSpecifier::AS_none;
   ExpectedBWithFunction.ChildFunctions.emplace_back(std::move(F));
   CheckNamespaceInfo(, BWithFunction);
Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -109,6 +109,7 @@
 static void FieldTypeInfoMapping(IO , FieldTypeInfo ) {
   TypeInfoMapping(IO, I);
   IO.mapOptional("Name", I.Name, SmallString<16>());
+  IO.mapOptional("DefaultValue", I.DefaultValue, SmallString<16>());
 }
 
 static void InfoMapping(IO , Info ) {
@@ -183,6 +184,7 @@
   static void mapping(IO , FieldTypeInfo ) {
 TypeInfoMapping(IO, I);
 IO.mapOptional("Name", I.Name, SmallString<16>());
+IO.mapOptional("DefaultValue", I.DefaultValue, SmallString<16>());
   }
 };
 
Index: clang-tools-extra/clang-doc/Serialize.cpp
===
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -10,6 +10,7 @@
 #include "BitcodeWriter.h"
 #include "clang/AST/Comment.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/SHA1.h"
@@ -310,21 +311,31 @@
 
 static void parseParameters(FunctionInfo , const FunctionDecl *D) {
   for (const ParmVarDecl *P : D->parameters()) {
+FieldTypeInfo *FieldInfo = nullptr;
 if (const auto *T = getDeclForType(P->getOriginalType())) {
   if (const auto *N = dyn_cast(T)) {
-I.Params.emplace_back(getUSRForDecl(N), N->getNameAsString(),
-  InfoType::IT_enum, getInfoRelativePath(N),
-  P->getNameAsString());
-continue;
+FieldInfo = _back(
+getUSRForDecl(N), N->getNameAsString(), InfoType::IT_enum,
+getInfoRelativePath(N), P->getNameAsString());
   } else if (const auto *N = dyn_cast(T)) {
-I.Params.emplace_back(getUSRForDecl(N), N->getNameAsString(),
-  InfoType::IT_record, getInfoRelativePath(N),
-  P->getNameAsString());
-continue;
+FieldInfo = _back(
+getUSRForDecl(N), N->getNameAsString(), InfoType::IT_record,
+getInfoRelativePath(N), 

[clang-tools-extra] e191086 - [clang-doc] Support default args for functions.

2022-09-16 Thread Paul Kirth via cfe-commits

Author: Brett Wilson
Date: 2022-09-16T17:26:07Z
New Revision: e191086bfcb72a98a9e299fd30dd3f69c5de5b64

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

LOG: [clang-doc] Support default args for functions.

Adds support for default arguments in the internal representation and reads 
these values from the source. Implements writing these values to YAML but does 
not implement this for the HTML or markdown outputs.

Reviewed By: paulkirth

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

Added: 


Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/BitcodeWriter.h
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-doc/YAMLGenerator.cpp
clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 35e3aef091a29..7736e3d14516e 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -259,6 +259,8 @@ llvm::Error parseRecord(const Record , unsigned ID, 
llvm::StringRef Blob,
   switch (ID) {
   case FIELD_TYPE_NAME:
 return decodeRecord(R, I->Name, Blob);
+  case FIELD_DEFAULT_VALUE:
+return decodeRecord(R, I->DefaultValue, Blob);
   default:
 return llvm::createStringError(llvm::inconvertibleErrorCode(),
"invalid field for TypeInfo");

diff  --git a/clang-tools-extra/clang-doc/BitcodeWriter.cpp 
b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
index 3daeb8076c42f..7e231706a9b0a 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.cpp
@@ -148,6 +148,7 @@ static const llvm::IndexedMap
   {COMMENT_ATTRVAL, {"AttrVal", }},
   {COMMENT_ARG, {"Arg", }},
   {FIELD_TYPE_NAME, {"Name", }},
+  {FIELD_DEFAULT_VALUE, {"DefaultValue", }},
   {MEMBER_TYPE_NAME, {"Name", }},
   {MEMBER_TYPE_ACCESS, {"Access", }},
   {NAMESPACE_USR, {"USR", }},
@@ -207,7 +208,7 @@ static const std::vector>>
 // Type Block
 {BI_TYPE_BLOCK_ID, {}},
 // FieldType Block
-{BI_FIELD_TYPE_BLOCK_ID, {FIELD_TYPE_NAME}},
+{BI_FIELD_TYPE_BLOCK_ID, {FIELD_TYPE_NAME, FIELD_DEFAULT_VALUE}},
 // MemberType Block
 {BI_MEMBER_TYPE_BLOCK_ID, {MEMBER_TYPE_NAME, MEMBER_TYPE_ACCESS}},
 // Enum Block
@@ -419,6 +420,7 @@ void ClangDocBitcodeWriter::emitBlock(const FieldTypeInfo 
) {
   StreamSubBlockGuard Block(Stream, BI_FIELD_TYPE_BLOCK_ID);
   emitBlock(T.Type, FieldId::F_type);
   emitRecord(T.Name, FIELD_TYPE_NAME);
+  emitRecord(T.DefaultValue, FIELD_DEFAULT_VALUE);
 }
 
 void ClangDocBitcodeWriter::emitBlock(const MemberTypeInfo ) {

diff  --git a/clang-tools-extra/clang-doc/BitcodeWriter.h 
b/clang-tools-extra/clang-doc/BitcodeWriter.h
index 7deda2ed39ee7..cc51eb5a65d6b 100644
--- a/clang-tools-extra/clang-doc/BitcodeWriter.h
+++ b/clang-tools-extra/clang-doc/BitcodeWriter.h
@@ -88,6 +88,7 @@ enum RecordId {
   COMMENT_ATTRVAL,
   COMMENT_ARG,
   FIELD_TYPE_NAME,
+  FIELD_DEFAULT_VALUE,
   MEMBER_TYPE_NAME,
   MEMBER_TYPE_ACCESS,
   NAMESPACE_USR,

diff  --git a/clang-tools-extra/clang-doc/Representation.h 
b/clang-tools-extra/clang-doc/Representation.h
index 2738b6f5ca63a..65a0ae8f110fe 100644
--- a/clang-tools-extra/clang-doc/Representation.h
+++ b/clang-tools-extra/clang-doc/Representation.h
@@ -181,10 +181,15 @@ struct FieldTypeInfo : public TypeInfo {
   : TypeInfo(RefName, Path), Name(Name) {}
 
   bool operator==(const FieldTypeInfo ) const {
-return std::tie(Type, Name) == std::tie(Other.Type, Other.Name);
+return std::tie(Type, Name, DefaultValue) ==
+   std::tie(Other.Type, Other.Name, Other.DefaultValue);
   }
 
   SmallString<16> Name; // Name associated with this info.
+
+  // When used for function parameters, contains the string representing the
+  // expression of the default value, if any.
+  SmallString<16> DefaultValue;
 };
 
 // Info for member types.

diff  --git a/clang-tools-extra/clang-doc/Serialize.cpp 
b/clang-tools-extra/clang-doc/Serialize.cpp
index 6e6308d6c7a8d..cb1b81deeaf7a 100644
--- a/clang-tools-extra/clang-doc/Serialize.cpp
+++ b/clang-tools-extra/clang-doc/Serialize.cpp
@@ -10,6 +10,7 @@
 #include "BitcodeWriter.h"
 #include "clang/AST/Comment.h"
 #include "clang/Index/USRGeneration.h"
+#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/Hashing.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/SHA1.h"
@@ -310,21 +311,31 @@ static void 

[PATCH] D132608: [CMake] Clean up CMake binary dir handling

2022-09-16 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

I agree with @tianshilei1992, I think we should avoid introducing new `CMAKE_` 
variables to avoid confusion. The same applies to module names, for example I 
don't think we should be introducing `GNUBinaryDirs` which can be easily 
confused for `GNUInstallDirs`.

I would personally go with the `LLVM_` prefix, I agree that this can lead to 
some confusion given that LLVM is both the name of the top-level project as 
well as one of the subprojects, but I think that ship has already sailed we 
already have proliferation of `LLVM_` named variables throughout the codebase.

Regarding `GNUBinaryDirs`, it seems like we always use the following pattern:

  # Must go before the first `include(GNUInstallDirs)`.
  include(LLVMLibdirSuffix)
  
  # Must go below project(..)
  include(GNUInstallDirs)
  include(GNUBinaryDirs)

That introduces a lot of duplication and is potentially error-prone since we 
rely on particular include order. Could we instead introduce a single 
`LLVMInstallDirs` module which would contain the content of  `LLVMLibdirSuffix` 
and `GNUBinaryDirs` and would also include `GNUInstallDirs`, so 
`LLVMInstallDirs` is all you would need to include in individual subprojects?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132608

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


[PATCH] D109621: [clang][Driver] Default to loading clang.cfg if config file not specified

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny planned changes to this revision.
mgorny added a reviewer: MaskRay.
mgorny added a comment.
Herald added a subscriber: StephenFan.

So far my plan is to go for `default-{ModeSuffix}.cfg` instead (e.g. 
`default-clang.cfg`, `default-clang++.cfg`, etc.). If I'm not mistaken, this 
will trigger the existing fallback logic stripping mode suffix and trying 
`default.cfg` if suffixed config is not found. Also add tests ;-).


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

https://reviews.llvm.org/D109621

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


[PATCH] D109621: [clang][Driver] Default to loading clang.cfg if config file not specified

2022-09-16 Thread Michał Górny via Phabricator via cfe-commits
mgorny commandeered this revision.
mgorny added a reviewer: asymptotically.
mgorny added a comment.

After discussing privately with @asymptotically, I'm going to try to finish 
this.


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

https://reviews.llvm.org/D109621

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


[PATCH] D134054: [clang][Interp] Properly destruct allocated Records

2022-09-16 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Other than the pedantry above, LGTM.




Comment at: clang/lib/AST/Interp/Program.h:48
+// here manually so they are properly freeing their resources.
+for (auto It : Records)
+  It.second->~Record();

I SUSPECT that by a reading of our rules here, we aren't allowed to use `auto` 
here.  That said, I'm sure I don't want to have you spell out the whole LHS.  

THOUGH the name "It" is a little misleading, as this is NOT an iterator, it 
ends up being a std::pair or something I think... 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134054

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


[PATCH] D134055: [clang-doc] Export more enum information

2022-09-16 Thread Brett Wilson via Phabricator via cfe-commits
brettw created this revision.
brettw added a reviewer: paulkirth.
brettw added a project: clang-tools-extra.
Herald added a project: All.
brettw requested review of this revision.
Herald added a subscriber: cfe-commits.

Add support for explicitly typed enums:

  enum Foo : unsigned { ... };

to the internal representation and to the YAML output.

  

Add support for getting the value of an enum constant, as well as accessing the 
original expression that produced it. This changes the YAML output of enums 
from an array of strings for the enum members to an array of dictionaries. 
These dictionaries now report the name, value, and original expression.

  

The markdown and HTML outputs are unchanged, they still output the name from 
the new enhanced internal schema.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134055

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -256,7 +256,11 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
-TEST(YAMLGeneratorTest, emitEnumYAML) {
+// Tests the equivalent of:
+// namespace A {
+// enum e { X };
+// }
+TEST(YAMLGeneratorTest, emitSimpleEnumYAML) {
   EnumInfo I;
   I.Name = "e";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -265,7 +269,7 @@
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   I.Members.emplace_back("X");
-  I.Scoped = true;
+  I.Scoped = false;
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -286,9 +290,42 @@
 Location:
   - LineNumber:  12
 Filename:'test.cpp'
+Members:
+  - Name:'X'
+Value:   '0'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+// Tests the equivalent of:
+// enum class e : short { X = FOO_BAR + 2 };
+TEST(YAMLGeneratorTest, enumTypedScopedEnumYAML) {
+  EnumInfo I;
+  I.Name = "e";
+
+  I.Members.emplace_back("X", llvm::APSInt::get(-9876), "FOO_BAR + 2");
+  I.Scoped = true;
+  I.BaseType = TypeInfo("short");
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(, Actual, ClangDocContext());
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'e'
 Scoped:  true
+BaseType:
+  Type:
+Name:'short'
 Members:
-  - 'X'
+  - Name:'X'
+Value:   '-9876'
+Expr:'FOO_BAR + 2'
 ...
 )raw";
   EXPECT_EQ(Expected, Actual.str());
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -266,8 +266,8 @@
   EnumInfo E;
   E.Name = "E";
   E.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  E.Members.emplace_back("X");
-  E.Members.emplace_back("Y");
+  E.Members.emplace_back("X", llvm::APSInt::get(0));
+  E.Members.emplace_back("Y", llvm::APSInt::get(1));
   ExpectedNamespaceWithEnum.ChildEnums.emplace_back(std::move(E));
   CheckNamespaceInfo(, NamespaceWithEnum);
 
@@ -277,8 +277,8 @@
   G.Name = "G";
   G.Scoped = true;
   G.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  G.Members.emplace_back("A");
-  G.Members.emplace_back("B");
+  G.Members.emplace_back("A", llvm::APSInt::get(0));
+  G.Members.emplace_back("B", llvm::APSInt::get(1));
   ExpectedNamespaceWithScopedEnum.ChildEnums.emplace_back(std::move(G));
   CheckNamespaceInfo(, NamespaceWithScopedEnum);
 }
Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -14,6 +14,7 @@
 
 using namespace clang::doc;
 
+// These define YAML traits for decoding the listed values within a vector.
 LLVM_YAML_IS_SEQUENCE_VECTOR(FieldTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(MemberTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(Reference)
@@ -21,6 +22,7 @@
 LLVM_YAML_IS_SEQUENCE_VECTOR(CommentInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(EnumInfo)
+LLVM_YAML_IS_SEQUENCE_VECTOR(EnumValueInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(BaseRecordInfo)
 

[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-09-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9468
+  // Control constants for math operations.
+  AddGlobal("__oclc_wavefrontsize64", Wavefront64, /*Size=*/8);
+  AddGlobal("__oclc_daz_opt", DenormAreZero, /*Size=*/8);

jhuber6 wrote:
> arsenm wrote:
> > yaxunl wrote:
> > > we need to disable emitting these variables for HIP -fgpu-rdc mode and 
> > > OpenCL since they will break per-TU control variable. Other cases are OK.
> > wavefrontsize belongs with the system ones
> But the code would still depend on these and they wouldn't be present right
> wavefrontsize belongs with the system ones

You are right. `__oclc_wavefrontsize64` should always be emitted with 
linkonce_odr linkage since they need to be consistent among TU's. Therefore 
they should always be emitted.

`__oclc_daz_opt`, `__oclc_finite_only_opt`, `__oclc_unsafe_math_opt`, and 
`__oclc_correctly_rounded_sqrt32` can be different per TU, therefore they 
should not be emitted for HIP `-fgpu-rdc` and OpenCL.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-09-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9468-9472
+  AddGlobal("__oclc_wavefrontsize64", Wavefront64, /*Size=*/8);
+  AddGlobal("__oclc_daz_opt", DenormAreZero, /*Size=*/8);
+  AddGlobal("__oclc_finite_only_opt", FiniteOnly || RelaxedMath, /*Size=*/8);
+  AddGlobal("__oclc_unsafe_math_opt", UnsafeMath || RelaxedMath, /*Size=*/8);
+  AddGlobal("__oclc_correctly_rounded_sqrt32", CorrectSqrt, /*Size=*/8);

arsenm wrote:
> yaxunl wrote:
> > we need to disable emitting these variables for HIP -fgpu-rdc mode and 
> > OpenCL since they will break per-TU control variable. Other cases are OK.
> wavefrontsize belongs with the system ones
But the code would still depend on these and they wouldn't be present right


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-09-16 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9468
+  // Control constants for math operations.
+  AddGlobal("__oclc_wavefrontsize64", Wavefront64, /*Size=*/8);
+  AddGlobal("__oclc_daz_opt", DenormAreZero, /*Size=*/8);

yaxunl wrote:
> we need to disable emitting these variables for HIP -fgpu-rdc mode and OpenCL 
> since they will break per-TU control variable. Other cases are OK.
wavefrontsize belongs with the system ones


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-09-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9468-9472
+  AddGlobal("__oclc_wavefrontsize64", Wavefront64, /*Size=*/8);
+  AddGlobal("__oclc_daz_opt", DenormAreZero, /*Size=*/8);
+  AddGlobal("__oclc_finite_only_opt", FiniteOnly || RelaxedMath, /*Size=*/8);
+  AddGlobal("__oclc_unsafe_math_opt", UnsafeMath || RelaxedMath, /*Size=*/8);
+  AddGlobal("__oclc_correctly_rounded_sqrt32", CorrectSqrt, /*Size=*/8);

we need to disable emitting these variables for HIP -fgpu-rdc mode and OpenCL 
since they will break per-TU control variable. Other cases are OK.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D134054: [clang][Interp] Properly destruct allocated Records

2022-09-16 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As discussed with @aaron.ballman on IRC.

This reverts https://reviews.llvm.org/rGa8843643cd75d0e93ebcf3f30b470d2b8e59868d

I have ASan enabled locally and with this patch, the test suite now works fine.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134054

Files:
  clang/lib/AST/Interp/Program.h
  clang/test/AST/Interp/references.cpp


Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -75,7 +75,6 @@
 constexpr const int  = 1; // expected-error{{must be initialized by a 
constant expression}}
 
 
-#if 0
 struct S {
   int i, j;
 };
@@ -89,5 +88,4 @@
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, "");
-#endif
+static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an 
integral constant expression}}
Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -41,6 +41,14 @@
 public:
   Program(Context ) : Ctx(Ctx) {}
 
+  ~Program() {
+// Records might actually allocate memory themselves, but they
+// are allocated using a BumpPtrAllocator. Call their desctructors
+// here manually so they are properly freeing their resources.
+for (auto It : Records)
+  It.second->~Record();
+  }
+
   /// Marshals a native pointer to an ID for embedding in bytecode.
   unsigned getOrCreateNativePointer(const void *Ptr);
 


Index: clang/test/AST/Interp/references.cpp
===
--- clang/test/AST/Interp/references.cpp
+++ clang/test/AST/Interp/references.cpp
@@ -75,7 +75,6 @@
 constexpr const int  = 1; // expected-error{{must be initialized by a constant expression}}
 
 
-#if 0
 struct S {
   int i, j;
 };
@@ -89,5 +88,4 @@
   return j;
 }
 // FIXME: Should be accepted.
-static_assert(RefToMemberExpr() == 11, "");
-#endif
+static_assert(RefToMemberExpr() == 11, ""); // expected-error {{not an integral constant expression}}
Index: clang/lib/AST/Interp/Program.h
===
--- clang/lib/AST/Interp/Program.h
+++ clang/lib/AST/Interp/Program.h
@@ -41,6 +41,14 @@
 public:
   Program(Context ) : Ctx(Ctx) {}
 
+  ~Program() {
+// Records might actually allocate memory themselves, but they
+// are allocated using a BumpPtrAllocator. Call their desctructors
+// here manually so they are properly freeing their resources.
+for (auto It : Records)
+  It.second->~Record();
+  }
+
   /// Marshals a native pointer to an ID for embedding in bytecode.
   unsigned getOrCreateNativePointer(const void *Ptr);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-09-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 460812.
jhuber6 added a comment.

Addressing comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/test/CodeGen/amdgcn-control-constants.c

Index: clang/test/CodeGen/amdgcn-control-constants.c
===
--- /dev/null
+++ clang/test/CodeGen/amdgcn-control-constants.c
@@ -0,0 +1,49 @@
+// Check that we generate all the expected default features for the target.
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx90a -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GFX90A
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx1030 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=GFX1030
+
+// GFX90A: @__oclc_wavefrontsize64 = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
+// GFX90A: @__oclc_daz_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX90A: @__oclc_finite_only_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX90A: @__oclc_unsafe_math_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX90A: @__oclc_correctly_rounded_sqrt32 = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
+// GFX90A: @__oclc_ISA_version = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i32 9010
+// GFX90A: @__oclc_ABI_version = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i32 400
+
+// GFX1030: @__oclc_wavefrontsize64 = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX1030: @__oclc_daz_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX1030: @__oclc_finite_only_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX1030: @__oclc_unsafe_math_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// GFX1030: @__oclc_correctly_rounded_sqrt32 = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
+// GFX1030: @__oclc_ISA_version = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i32 10048
+// GFX1030: @__oclc_ABI_version = linkonce_odr hidden local_unnamed_addr addrspace(4) constant i32 400
+
+// Check that we can override the wavefront features.
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx1030 -target-feature +wavefrontsize64 \
+// RUN:   -S -emit-llvm -o - %s | FileCheck %s --check-prefix=WAVEFRONT
+// WAVEFRONT: @__oclc_wavefrontsize64 = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
+
+// Check that we can enable denormalization at zero.
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx90a -fdenormal-fp-math-f32=preserve-sign,preserve-sign \
+// RUN:   -S -emit-llvm -o - %s | FileCheck %s --check-prefix=DENORM-AT-ZERO
+// DENORM-AT-ZERO: @__oclc_daz_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
+
+// Check that we can enable finite math.
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx90a -ffinite-math-only \
+// RUN:   -S -emit-llvm -o - %s | FileCheck %s --check-prefix=FINITE-MATH
+// FINITE-MATH: @__oclc_finite_only_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
+// FINITE-MATH: @__oclc_unsafe_math_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+
+// Check that we can enable unsafe math.
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx90a -menable-unsafe-fp-math \
+// RUN:   -S -emit-llvm -o - %s | FileCheck %s --check-prefix=UNSAFE-MATH
+// UNSAFE-MATH: @__oclc_finite_only_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// UNSAFE-MATH: @__oclc_unsafe_math_opt = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
+
+// Check that we can disable/enable correctly rounded square roots.
+// RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -target-cpu gfx90a -fno-hip-fp32-correctly-rounded-divide-sqrt \
+// RUN:   -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CORRECT-SQRT
+// CORRECT-SQRT: @__oclc_correctly_rounded_sqrt32 = linkonce hidden local_unnamed_addr addrspace(4) constant i8 0
+// RUN: %clang_cc1 -x cl -triple amdgcn-amd-amdhsa -target-cpu gfx90a -cl-fp32-correctly-rounded-divide-sqrt \
+// RUN:   -disable-llvm-optzns -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CL-CORRECT-SQRT
+// CL-CORRECT-SQRT: @__oclc_correctly_rounded_sqrt32 = linkonce hidden local_unnamed_addr addrspace(4) constant i8 1
Index: clang/lib/CodeGen/TargetInfo.h
===
--- clang/lib/CodeGen/TargetInfo.h
+++ clang/lib/CodeGen/TargetInfo.h
@@ -76,6 +76,9 @@
   CodeGen::CodeGenModule ,
   const llvm::MapVector ) const {}
 
+  /// Provides a convenient hook to handle extra target-specific globals.
+  virtual void 

[PATCH] D134049: [clang-format] Disallow trailing return arrows to be operators

2022-09-16 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel updated this revision to Diff 460810.
rymiel added a comment.

Also test the annotated value of the arrow


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134049

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -440,6 +440,14 @@
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause);
 
+  Tokens = annotate("template \n"
+"requires Bar || Baz\n"
+"auto foo(T) -> int;");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow);
+
   Tokens = annotate("template \n"
 "struct S {\n"
 "  void foo() const requires Bar;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2611,8 +2611,10 @@
   }
   if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
 return Current->getPrecedence();
-  if (Current->isOneOf(tok::period, tok::arrow))
+  if (Current->isOneOf(tok::period, tok::arrow) &&
+  !Current->is(TT_TrailingReturnArrow)) {
 return PrecedenceArrowAndPeriod;
+  }
   if ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) &&
   Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
Keywords.kw_throws)) {


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -440,6 +440,14 @@
   ASSERT_EQ(Tokens.size(), 18u) << Tokens;
   EXPECT_TOKEN(Tokens[11], tok::kw_requires, TT_RequiresClause);
 
+  Tokens = annotate("template \n"
+"requires Bar || Baz\n"
+"auto foo(T) -> int;");
+  ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+  EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[20], tok::arrow, TT_TrailingReturnArrow);
+
   Tokens = annotate("template \n"
 "struct S {\n"
 "  void foo() const requires Bar;\n"
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2611,8 +2611,10 @@
   }
   if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
 return Current->getPrecedence();
-  if (Current->isOneOf(tok::period, tok::arrow))
+  if (Current->isOneOf(tok::period, tok::arrow) &&
+  !Current->is(TT_TrailingReturnArrow)) {
 return PrecedenceArrowAndPeriod;
+  }
   if ((Style.Language == FormatStyle::LK_Java || Style.isJavaScript()) &&
   Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
Keywords.kw_throws)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134049: [clang-format] Disallow trailing return arrows to be operators

2022-09-16 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added inline comments.



Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:448
+  EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+

MyDeveloperDay wrote:
> should you not check that Tokens[21] is a TT_TrailingReturnArrow?
That's probably a good idea, thank you! (though the bug wasn't that `->` was 
misannotated, it was still a trailing return arrow, it just caused fake 
parentheses to be inserted earlier on)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134049

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


[PATCH] D133988: [clang][deps] Make sure ScanInstance outlives collector

2022-09-16 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4e637fcb2550: [clang][deps] Make sure ScanInstance outlives 
collector (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133988

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -174,7 +174,8 @@
 Scanned = true;
 
 // Create a compiler instance to handle the actual work.
-CompilerInstance ScanInstance(std::move(PCHContainerOps));
+ScanInstanceStorage.emplace(std::move(PCHContainerOps));
+CompilerInstance  = *ScanInstanceStorage;
 ScanInstance.setInvocation(std::move(Invocation));
 
 // Create the compiler's actual diagnostics engine.
@@ -304,7 +305,8 @@
   bool OptimizeArgs;
   bool EagerLoadModules;
   bool DisableFree;
-  llvm::Optional ModuleName;
+  Optional ModuleName;
+  Optional ScanInstanceStorage;
   std::shared_ptr MDC;
   std::vector LastCC1Arguments;
   bool Scanned = false;


Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -174,7 +174,8 @@
 Scanned = true;
 
 // Create a compiler instance to handle the actual work.
-CompilerInstance ScanInstance(std::move(PCHContainerOps));
+ScanInstanceStorage.emplace(std::move(PCHContainerOps));
+CompilerInstance  = *ScanInstanceStorage;
 ScanInstance.setInvocation(std::move(Invocation));
 
 // Create the compiler's actual diagnostics engine.
@@ -304,7 +305,8 @@
   bool OptimizeArgs;
   bool EagerLoadModules;
   bool DisableFree;
-  llvm::Optional ModuleName;
+  Optional ModuleName;
+  Optional ScanInstanceStorage;
   std::shared_ptr MDC;
   std::vector LastCC1Arguments;
   bool Scanned = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4e637fc - [clang][deps] Make sure ScanInstance outlives collector

2022-09-16 Thread Jan Svoboda via cfe-commits

Author: Jan Svoboda
Date: 2022-09-16T09:44:12-07:00
New Revision: 4e637fcb25503cc9b3bb9af54453ac2ebc7299b1

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

LOG: [clang][deps] Make sure ScanInstance outlives collector

The `ScanInstance` is a local variable in 
`DependencyScanningAction::runInvocation()` that is referenced by 
`ModuleDepCollector`. Since D132405, `ModuleDepCollector` can escape the 
function and can outlive its `ScanInstance`. This patch fixes that.

Reviewed By: benlangmuir

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

Added: 


Modified: 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp

Removed: 




diff  --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp 
b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
index 3968656f4632b..7474e0272505e 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -174,7 +174,8 @@ class DependencyScanningAction : public tooling::ToolAction 
{
 Scanned = true;
 
 // Create a compiler instance to handle the actual work.
-CompilerInstance ScanInstance(std::move(PCHContainerOps));
+ScanInstanceStorage.emplace(std::move(PCHContainerOps));
+CompilerInstance  = *ScanInstanceStorage;
 ScanInstance.setInvocation(std::move(Invocation));
 
 // Create the compiler's actual diagnostics engine.
@@ -304,7 +305,8 @@ class DependencyScanningAction : public tooling::ToolAction 
{
   bool OptimizeArgs;
   bool EagerLoadModules;
   bool DisableFree;
-  llvm::Optional ModuleName;
+  Optional ModuleName;
+  Optional ScanInstanceStorage;
   std::shared_ptr MDC;
   std::vector LastCC1Arguments;
   bool Scanned = false;



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


[PATCH] D134049: [clang-format] Disallow trailing return arrows to be operators

2022-09-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:448
+  EXPECT_EQ(Tokens[11]->FakeLParens.size(), 0u);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+

should you not check that Tokens[21] is a TT_TrailingReturnArrow?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134049

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


[PATCH] D133945: [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails

2022-09-16 Thread Michael Buch via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe456d2ba8bca: [clang][ASTImporter] 
DeclContext::localUncachedLookup: Continue lookup into… (authored by 
Michael137).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133945

Files:
  clang/lib/AST/DeclBase.cpp
  clang/unittests/AST/ASTImporterTest.cpp
  
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py


Index: 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
===
--- 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
+++ 
lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
@@ -34,7 +34,6 @@
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_template_arg(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 
@@ -51,7 +50,6 @@
 ])
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_duplicate_decls(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.


Index: lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
===
--- lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
+++ lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
@@ -34,7 +34,6 @@
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_template_arg(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)
 
@@ -51,7 +50,6 @@
 ])
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_duplicate_decls(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)
 
Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);
Index: clang/lib/AST/DeclBase.cpp
===
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e456d2b - [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails

2022-09-16 Thread Michael Buch via cfe-commits

Author: Michael Buch
Date: 2022-09-16T12:38:50-04:00
New Revision: e456d2ba8bcadaa63386b339a4f2abcb39505502

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

LOG: [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup 
into decl chain when regular lookup fails

The uncached lookup is mainly used in the ASTImporter/LLDB code-path
where we're not allowed to load from external storage. When importing
a FieldDecl with a DeclContext that had no external visible storage
(but came from a Clang module or PCH) the above call to `lookup(Name)`
the regular `DeclContext::lookup` fails because:
1. `DeclContext::buildLookup` doesn't set `LookupPtr` for decls
   that came from a module
2. LLDB doesn't use the `SharedImporterState`

In such a case we would never continue with the "slow" path of iterating
through the decl chain on the DeclContext. In some cases this means that
ASTNodeImporter::VisitFieldDecl ends up importing a decl into the
DeclContext a second time.

The patch removes the short-circuit in the case where we don't find
any decls via the regular lookup.

**Tests**

* Un-skip the failing LLDB API tests

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

Added: 


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

lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py

Removed: 




diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index f22bf6b0937ee..837ff90d6e34f 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1771,7 +1771,8 @@ void DeclContext::localUncachedLookup(DeclarationName 
Name,
   if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
 lookup_result LookupResults = lookup(Name);
 Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
-return;
+if (!Results.empty())
+  return;
   }
 
   // If we have a lookup table, check there first. Maybe we'll get lucky.

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index d9b7883119345..86a96305bed11 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -4924,9 +4924,9 @@ TEST_P(ASTImporterLookupTableTest,
   FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
   EXPECT_EQ(FoundDecls.size(), 0u);
 
-  // Cannot find in the LookupTable of its LexicalDC (A).
+  // Finds via linear search of its LexicalDC (A).
   FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
-  EXPECT_EQ(FoundDecls.size(), 0u);
+  EXPECT_EQ(FoundDecls.size(), 1u);
 
   // Can't find in the list of Decls of the DC.
   EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);

diff  --git 
a/lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
 
b/lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
index 0ad4603651a18..b4aec8ff95e4b 100644
--- 
a/lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
+++ 
b/lldb/test/API/lang/cpp/gmodules/template-with-same-arg/TestTemplateWithSameArg.py
@@ -34,7 +34,6 @@ def setUp(self):
 self.main_source_file = lldb.SBFileSpec("main.cpp")
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_same_template_arg(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 
@@ -51,7 +50,6 @@ def test_same_template_arg(self):
 ])
 
 @add_test_categories(["gmodules"])
-@skipIf(bugnumber='rdar://96581048')
 def test_duplicate_decls(self):
 lldbutil.run_to_source_breakpoint(self, "Break here", 
self.main_source_file)
 



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


[PATCH] D133931: [clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `clang/Analysis/FlowSensitive`.

2022-09-16 Thread weiyi via Phabricator via cfe-commits
wyt added inline comments.



Comment at: 
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp:137-140
+auto CS = E->getAs();
+if (!CS)
+  return;
+auto S = CS->getStmt();

martong wrote:
> This is exactly the same code that you have in 
> `SingleVarConstantPropagationTest.cpp` and in the rest of the files. I think 
> this could be hoisted into a common function declared in 
> `FlowSensitive/DataflowAnalysis.h`.
> 
> By the way, wouldn't it be more convenient for the client to provide a 
> `transferStmt` function if the they are interested only in `Stmt`s? (Defining 
> both `transferStmt` and `transfer` should be a compile time error)
Thanks for the comment!

For now, I decided not to pull this out into a common function. This seems more 
like a utility function that does not quite belong DataflowAnalysis.h - it 
would be nice to keep the code there dedicated to analysis logic. Besides, I 
don't think we save much since the boilerplate is just a few lines.

Also, about having another `transferStmt` function, at this stage I feel that 
it's best if we keep things compact and have just one way of doing things - the 
framework is constantly evolving and having multiple implementations of the 
same concept can be distracting. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133931

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


[PATCH] D130096: [Clang][AMDGPU] Emit AMDGPU library control constants in clang

2022-09-16 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 marked 3 inline comments as done.
jhuber6 added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:9449-9450
+  !(Features & llvm::AMDGPU::FEATURE_WAVE32) ||
+  llvm::is_contained(CGM.getTarget().getTargetOpts().FeaturesAsWritten,
+ "+wavefrontsize64");
+

arsenm wrote:
> Do we really have to scan through the features too? This seems broken
@yaxunl wanted this so we didn't emit the global if the user manually overrode 
the features via `-Xclang` or similar.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130096

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


[PATCH] D128462: [HLSL] add -I option for dxc mode.

2022-09-16 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added a comment.

I understand your frustration with the regression, but let’s try to 
constructive. We all care about quality and we’re all working hard to do the 
best we can.

In D128462#3794868 , @kadircet wrote:

> My main complaint here's around **breaking** functionality for existing 
> driver-modes/toolchains, and I am asking either getting OWNERS approvals 
> going forward or being more through with the changes or changing the design 
> overall to make these less complicated.

Regressions happen. There are things we can do to avoid them (code review being 
one), but the most fool-proof way to avoid regressions is test coverage. Here 
we had a gap in test coverage of existing functionality. A new change went in, 
all the tests passed, but an important usage regression occurred. It is 
unfortunate, but it happened.

Getting owner approval before commit has never been required by our developer 
policy. In fact, the wording of the policy puts the onus on the owner for 
post-commit review. In this case we had a fairly innocuous seeming change by a 
relatively new contributor and I reviewed and approved it because it seemed 
fairly innocuous. This said, hopefully the recent changes in Clang code 
ownership will help here too.

This change was tested, and introduces a new test in accordance with our 
community standards and policy.

I don’t think it is fair to say this change contributed to a complicated design 
other than that llvm’s libOption is pretty complicated and has lots of 
difficult to see edge cases, and the tools that share option parsing logic 
often have disparate and duplicated logic for handing those options which can 
cause a variety of issues.

In terms of your other complaints around bug handling; I also understand 
frustration there. Unfortunately, clangd has a separate bug reporting and 
tracking process from the rest of the LLVM and Clang code it depends on. I’m 
sure it is frustrating to get bug reports that relate to code you didn’t write 
or design, but I think that is a reality of the process and complexity of the 
software that we have today. It is incredibly common in LLVM for bugs to get 
routed to the wrong area and need to be rerouted. Sometimes this is because 
users reporting issues don’t understand the architecture of the code base well 
enough to route to the right place, other times it is because the cultural 
boundaries of responsibility in LLVM aren’t well codified.

In order to support the incremental implementation process that LLVM has always 
used we need a way to be able to add driver and language modes incrementally. 
If there’s a gap in the Tooling testing or architecture we can change to make 
that better, let’s please discuss that, rather than trying to apply additional 
hurdles to a review process because a regression was introduced.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128462

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


  1   2   3   >