[PATCH] D146101: [clang-format] Add DesignatedInitializerIndentWidth option.

2023-03-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

In D146101#4204653 , @jp4a50 wrote:

>>> I think it's also worth noting that the google style guide gives an example 
>>> of designated initializers indented at 2 spaces (whereas their 
>>> "continuation indent" for wrapped function parameters is 4).
>>
>> It's likely an error that the designated initializer example there shows 
>> 2-space indents as clang-format uses the 4-space continuation indent width:
>
> This is possible, but isn't it also possible that they would prefer 
> designated initializers to be indented at 2 spaces but don't have the option 
> with clang-format currently?

I really doubt it as the creators of clang-format and a number of 
reviewers/contributors/maintainers from the recent past were Google engineers, 
I believe.

> The only general information supplied in the google style guide about 
> indentation is as follows:
>
>> - Default indentation is 2 spaces.
>> - Wrapped parameters have a 4 space indent.
>
> If we are taking a strict definition of parameters, the above suggests to me 
> that designated initializers would fall under the default indentation of 2 
> spaces.

IMO it's clear that in Google style IndentWidth = 2 and ContinuationIndentWidth 
= 4. I think in general IndentWidth is for block indent and 
ContinuationIndentWidth is for everything else.




Comment at: clang/include/clang/Format/Format.h:2037
+  /// \endcode
+  int DesignatedInitializerIndentWidth;
+





Comment at: clang/lib/Format/ContinuationIndenter.cpp:1659
   opensProtoMessageField(Current, Style)) {
+const FormatToken *NextNoComment = Current.getNextNonComment();
 if (Current.opensBlockOrBlockTypeList(Style)) {

Can you also move it into the `else if` below to reduce the scope of the 
pointer? Please note the typo `NextNoComment`.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1665-1669
+  const auto DesignatedInitializerIndentWidth =
+  Style.DesignatedInitializerIndentWidth < 0
+  ? Style.ContinuationIndentWidth
+  : Style.DesignatedInitializerIndentWidth;
+  NewIndent = CurrentState.LastSpace + DesignatedInitializerIndentWidth;

Using -1 to mean `ContinuationIndentWidth` is unnecessary and somewhat 
confusing IMO.



Comment at: clang/lib/Format/Format.cpp:1372
   LLVMStyle.DerivePointerAlignment = false;
+  LLVMStyle.DesignatedInitializerIndentWidth = -1;
   LLVMStyle.DisableFormat = false;





Comment at: clang/unittests/Format/ConfigParseTest.cpp:250-251
+  DesignatedInitializerIndentWidth, 34);
+  CHECK_PARSE("DesignatedInitializerIndentWidth: -1",
+  DesignatedInitializerIndentWidth, -1);
   CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");

Delete.



Comment at: clang/unittests/Format/FormatTest.cpp:4845
+  Style.ContinuationIndentWidth = 8;
+  Style.DesignatedInitializerIndentWidth = -1; // Use ContinuationIndentWidth.
+  verifyFormat("auto s = SomeStruct{\n"

Delete it and rearrange the tests so that the unspecified (default) 
`DesignatedInitializerIndentWidth` is tested first.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 507975.
tomasz-kaminski-sonarsource added a comment.

Adding tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp


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
@@ -196,8 +196,7 @@
 
 template<>
 float unTempl = 1;
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

@@ -242,8 +241,7 @@
 
 template<>
 float binTempl = 1;
-// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: |-TemplateArgument type 'float'
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 
//===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 
//===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),


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
@@ -196,8 +196,7 @@
 
 template<>
 float unTempl = 1;
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
@@ -242,8 +241,7 @@
 
 template<>
 float binTempl = 1;
-/

[PATCH] D145965: [C++20][Modules] Fix incorrect visibilities in implementation units.

2023-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains updated this revision to Diff 507977.
iains edited the summary of this revision.
iains added a comment.

rebased, split the changes to module and private linkage out,

this needs to be refactored to collect the test functions into either
module.h and / or sema.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145965

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaLookup.cpp
  clang/test/CXX/basic/basic.scope/basic.scope.namespace/p2.cpp
  clang/test/CXX/module/basic/basic.def.odr/p4.cppm
  clang/test/CXX/module/basic/basic.link/p2.cppm
  clang/test/CXX/module/module.import/p2.cpp
  clang/test/CXX/module/module.interface/p2.cpp
  clang/test/CXX/module/module.interface/p7.cpp
  clang/test/CXX/module/module.reach/ex1.cpp
  clang/test/CXX/module/module.reach/p2.cpp
  clang/test/CXX/module/module.reach/p5.cpp
  clang/test/Modules/Reachability-template-default-arg.cpp
  clang/test/Modules/cxx20-10-1-ex2.cpp
  clang/test/Modules/deduction-guide3.cppm
  clang/test/Modules/diagnose-missing-import.m

Index: clang/test/Modules/diagnose-missing-import.m
===
--- clang/test/Modules/diagnose-missing-import.m
+++ clang/test/Modules/diagnose-missing-import.m
@@ -6,9 +6,9 @@
 
 void foo(void) {
   XYZLogEvent(xyzRiskyCloseOpenParam, xyzRiskyCloseOpenParam); // expected-error {{call to undeclared function 'XYZLogEvent'; ISO C99 and later do not support implicit function declarations}} \
-  expected-error {{declaration of 'XYZLogEvent' must be imported}} \
-  expected-error {{declaration of 'xyzRiskyCloseOpenParam' must be imported from module 'NCI.A'}} \
-  expected-error {{declaration of 'xyzRiskyCloseOpenParam' must be imported from module 'NCI.A'}}
+  expected-error {{declaration of 'XYZLogEvent' is internal to 'NCI.A'}} \
+  expected-error {{declaration of 'xyzRiskyCloseOpenParam' is internal to 'NCI.A'}} \
+  expected-error {{declaration of 'xyzRiskyCloseOpenParam' is internal to 'NCI.A'}}
 }
 
 // expected-note@Inputs/diagnose-missing-import/a.h:5 {{declaration here is not visible}}
Index: clang/test/Modules/deduction-guide3.cppm
===
--- clang/test/Modules/deduction-guide3.cppm
+++ clang/test/Modules/deduction-guide3.cppm
@@ -19,8 +19,8 @@
 //--- Use.cpp
 import Templ;
 void func() {
-Templ t(5); // expected-error {{declaration of 'Templ' must be imported from module 'Templ' before it is required}}
+Templ t(5); // expected-error {{declaration of 'Templ' is private to module 'Templ'}}
 // expected-error@-1 {{unknown type name 'Templ'}}
-// expected-n...@templ.cppm:3 {{declaration here is not visible}}
+// expected-n...@templ.cppm:3 {{export the declaration to make it available}}
 }
 
Index: clang/test/Modules/cxx20-10-1-ex2.cpp
===
--- clang/test/Modules/cxx20-10-1-ex2.cpp
+++ clang/test/Modules/cxx20-10-1-ex2.cpp
@@ -53,8 +53,8 @@
 //--- std10-1-ex2-tu6.cpp
 import B;
 // error, n is module-local and this is not a module.
-int &c = n; // expected-error {{declaration of 'n' must be imported}}
-// expected-note@* {{declaration here is not visible}}
+int &c = n; // expected-error {{declaration of 'n' is private to module 'B'}}
+// expected-note@* {{export the declaration to make it available}}
 
 //--- std10-1-ex2-tu7.cpp
 // expected-no-diagnostics
Index: clang/test/Modules/Reachability-template-default-arg.cpp
===
--- clang/test/Modules/Reachability-template-default-arg.cpp
+++ clang/test/Modules/Reachability-template-default-arg.cpp
@@ -18,6 +18,6 @@
 import template_default_arg;
 void bar() {
   A<> a0;
-  A a1; // expected-error {{declaration of 't' must be imported from module 'template_default_arg' before it is required}}
-   // expected-note@* {{declaration here is not visible}}
+  A a1; // expected-error {{declaration of 't' is private to module 'template_default_arg'}}
+   // expected-note@* {{export the declaration to make it available}}
 }
Index: clang/test/CXX/module/module.reach/p5.cpp
===
--- clang/test/CXX/module/module.reach/p5.cpp
+++ clang/test/CXX/module/module.reach/p5.cpp
@@ -14,5 +14,5 @@
 export module B;
 import A;
 Y y; /

[PATCH] D145965: [C++20][Modules] Fix incorrect visibilities in implementation units.

2023-03-24 Thread Iain Sandoe via Phabricator via cfe-commits
iains planned changes to this revision.
iains added a comment.

although this patch does handle the cases needed, it really needs refactoring.
posting here since we are both working in this area and this might be useful 
input.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145965

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


[clang-tools-extra] f957b8f - [clang-tidy][NFC] Improve naming convention in google-readability-avoid-underscore-in-googletest-name

2023-03-24 Thread Carlos Galvez via cfe-commits

Author: Carlos Galvez
Date: 2023-03-24T07:22:04Z
New Revision: f957b8fe1efe34ac04d1b2e6381e44edcef056b3

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

LOG: [clang-tidy][NFC] Improve naming convention in 
google-readability-avoid-underscore-in-googletest-name

According to the Google docs, the convention is
TEST(TestSuiteName, TestName). Apply that convention to the
source code, test and documentation of the check.

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp

clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst

clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
index b903f2552b7e..d522d6760af1 100644
--- 
a/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
@@ -47,18 +47,19 @@ class AvoidUnderscoreInGoogletestNameCallback : public 
PPCallbacks {
 if (!isGoogletestTestMacro(MacroName) || !Args ||
 Args->getNumMacroArguments() < 2)
   return;
-const Token *TestCaseNameToken = Args->getUnexpArgument(0);
+const Token *TestSuiteNameToken = Args->getUnexpArgument(0);
 const Token *TestNameToken = Args->getUnexpArgument(1);
-if (!TestCaseNameToken || !TestNameToken)
+if (!TestSuiteNameToken || !TestNameToken)
   return;
-std::string TestCaseNameMaybeDisabled = 
PP->getSpelling(*TestCaseNameToken);
-StringRef TestCaseName = TestCaseNameMaybeDisabled;
-TestCaseName.consume_front(KDisabledTestPrefix);
-if (TestCaseName.contains('_'))
-  Check->diag(TestCaseNameToken->getLocation(),
-  "avoid using \"_\" in test case name \"%0\" according to "
+std::string TestSuiteNameMaybeDisabled =
+PP->getSpelling(*TestSuiteNameToken);
+StringRef TestSuiteName = TestSuiteNameMaybeDisabled;
+TestSuiteName.consume_front(KDisabledTestPrefix);
+if (TestSuiteName.contains('_'))
+  Check->diag(TestSuiteNameToken->getLocation(),
+  "avoid using \"_\" in test suite name \"%0\" according to "
   "Googletest FAQ")
-  << TestCaseName;
+  << TestSuiteName;
 
 std::string TestNameMaybeDisabled = PP->getSpelling(*TestNameToken);
 StringRef TestName = TestNameMaybeDisabled;

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
index f2053b4d2fcd..e667fd1b 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
@@ -3,8 +3,8 @@
 google-readability-avoid-underscore-in-googletest-name
 ==
 
-Checks whether there are underscores in googletest test and test case names in
-test macros:
+Checks whether there are underscores in googletest test suite names and test
+names in test macros:
 
 - ``TEST``
 - ``TEST_F``
@@ -18,17 +18,17 @@ For example:
 
 .. code-block:: c++
 
-  TEST(TestCaseName, Illegal_TestName) {}
-  TEST(Illegal_TestCaseName, TestName) {}
+  TEST(TestSuiteName, Illegal_TestName) {}
+  TEST(Illegal_TestSuiteName, TestName) {}
 
-would trigger the check. `Underscores are not allowed`_ in test names nor test
-case names.
+would trigger the check. `Underscores are not allowed`_ in test suite name nor
+test names.
 
-The ``DISABLED_`` prefix, which may be used to `disable individual tests`_, is
-ignored when checking test names, but the rest of the rest of the test name is
-still checked.
+The ``DISABLED_`` prefix, which may be used to
+`disable test suites and individual tests`_, is removed from the test suite 
name
+and test name before checking for underscores.
 
 This check does not propose any fixes.
 
 .. _Underscores are not allowed: 
https://google.github.io/googletest/faq.html#why-should-test-suite-names-and-test-names-not-contain-underscore
-.. _disable individual tests: 
https://google.github.io/googletest/advanced.html#temporarily-disabling-tests
+.. _disable test suites and individual tests: 
https://google.github.io/googletest/advanced.html#temporarily-disabling-tests

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-nam

[PATCH] D146713: [clang-tidy][NFC] Improve naming convention in google-readability-avoid-underscore-in-googletest-name

2023-03-24 Thread Carlos Galvez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
carlosgalvezp marked an inline comment as done.
Closed by commit rGf957b8fe1efe: [clang-tidy][NFC] Improve naming convention in 
google-readability-avoid… (authored by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146713

Files:
  clang-tools-extra/clang-tidy/google/AvoidUnderscoreInGoogletestNameCheck.cpp
  
clang-tools-extra/docs/clang-tidy/checks/google/readability-avoid-underscore-in-googletest-name.rst
  
clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/google/avoid-underscore-in-googletest-name.cpp
@@ -1,118 +1,118 @@
 // RUN: %check_clang_tidy %s google-readability-avoid-underscore-in-googletest-name %t
 
-#define TEST(test_case_name, test_name) void test_case_name##test_name()
-#define TEST_F(test_case_name, test_name) void test_case_name##test_name()
-#define TEST_P(test_case_name, test_name) void test_case_name##test_name()
-#define TYPED_TEST(test_case_name, test_name) void test_case_name##test_name()
-#define TYPED_TEST_P(test_case_name, test_name) void test_case_name##test_name()
-#define FRIEND_TEST(test_case_name, test_name) void test_case_name##test_name()
-
-TEST(TestCaseName, Illegal_TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-
-TEST(TestCaseName, DISABLED_Illegal_TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-TEST(TestCaseName, Illegal_Test_Name) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:20: warning: avoid using "_" in test name "Illegal_Test_Name" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-TEST(Illegal_TestCaseName, TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: avoid using "_" in test case name "Illegal_TestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-TEST(Illegal_Test_CaseName, TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: avoid using "_" in test case name "Illegal_Test_CaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-TEST(Illegal_TestCaseName, Illegal_TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: avoid using "_" in test case name "Illegal_TestCaseName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-// CHECK-MESSAGES: :[[@LINE-2]]:28: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-
-TEST_F(TestCaseFixtureName, Illegal_TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-TEST_F(TestCaseFixtureName, DISABLED_Illegal_Test_Name) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: avoid using "_" in test name "Illegal_Test_Name" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-TEST_F(TestCaseFixtureName, Illegal_Test_Name) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: avoid using "_" in test name "Illegal_Test_Name" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-
-TEST_F(Illegal_TestCaseFixtureName, TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: avoid using "_" in test case name "Illegal_TestCaseFixtureName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-TEST_F(Illegal_TestCaseFixtureName, Illegal_TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: avoid using "_" in test case name "Illegal_TestCaseFixtureName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-// CHECK-MESSAGES: :[[@LINE-2]]:37: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-
-TEST_F(Illegal_Test_CaseFixtureName, TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: avoid using "_" in test case name "Illegal_Test_CaseFixtureName" according to Googletest FAQ [google-readability-avoid-underscore-in-googletest-name]
-
-TEST_P(ParameterizedTestCaseFixtureName, Illegal_TestName) {}
-// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: avoid using "_" in test name "Illegal_TestName" according to Googletest FAQ [google-readability-avo

[PATCH] D146655: [clang-tidy] Ignore DISABLED_ in test suite name in google-avoid-underscore-in-googletest-name

2023-03-24 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:237
 
+- Fixed an issue in :doc:`google-avoid-underscore-in-googletest-name
+  ` when using

Eugene.Zelenko wrote:
> carlosgalvezp wrote:
> > Eugene.Zelenko wrote:
> > > Eugene.Zelenko wrote:
> > > > carlosgalvezp wrote:
> > > > > PiotrZSL wrote:
> > > > > > carlosgalvezp wrote:
> > > > > > > Eugene.Zelenko wrote:
> > > > > > > > Please keep alphabetical order (by check name) in this section.
> > > > > > > I was planning to do that but noticed that the alphabetical order 
> > > > > > > is already broken. It seems to be a source of friction and 
> > > > > > > there's no official documentation that states it should be done 
> > > > > > > like that, so I can understand if it gets broken often. Do you 
> > > > > > > know if this is documented somewhere? If not, do we see value in 
> > > > > > > keeping this convention? I suppose now we would need an NFC patch 
> > > > > > > to fix the order again, causing churn.
> > > > > > I run into same issue also. I would say, let leave it as it is, and 
> > > > > > fix it with one commit at the end of release.
> > > > > Good idea, let's do that!
> > > > Often it's also broken after rebases which may be automatic.
> > > Anyway, some kind of order is much better than disorder.
> > Definitely. Could we stick to some simple convention? For example always 
> > append or prepend to the list of modifications to checks. Then before 
> > release we put up a patch for reordering.
> I think it will be harder to reader. Sorting by check name is much better in 
> this respect. And this was used in many releases.
To clarify, what I mean is:

- Apply a simple convention (e.g. append or prepend to the list) //while 
developing//.
- Right before creating a release, put up a patch to sort alphabetically. Then 
it will be easy to read for users when it's released.

Or do you mean that the list shall be alphabetically sorted at all times?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146655

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


[PATCH] D146788: [clang][Interp] Fix zero-initializing of floating types

2023-03-24 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.

After the discussion in https://reviews.llvm.org/D141472, this fixes 
zero-initializing members of floating type


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146788

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/floats.cpp


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -78,3 +78,17 @@
   }
   static_assert(f2() == __FLT_MAX__, "");
 }
+
+namespace ZeroInit {
+  template
+  struct A {
+int a;
+FloatT f;
+  };
+
+  constexpr A a{12};
+  static_assert(a.f == 0.0f);
+
+  constexpr A b{12};
+  static_assert(a.f == 0.0);
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1073,8 +1073,12 @@
 return this->emitNullPtr(E);
   case PT_FnPtr:
 return this->emitNullFnPtr(E);
-  case PT_Float:
-assert(false);
+  case PT_Float: {
+const auto &Sem = Ctx.getASTContext().getFloatTypeSemantics(E->getType());
+
+APFloat Val(Sem);
+return this->emitConstFloat(Val, E);
+  }
   }
   llvm_unreachable("unknown primitive type");
 }


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -78,3 +78,17 @@
   }
   static_assert(f2() == __FLT_MAX__, "");
 }
+
+namespace ZeroInit {
+  template
+  struct A {
+int a;
+FloatT f;
+  };
+
+  constexpr A a{12};
+  static_assert(a.f == 0.0f);
+
+  constexpr A b{12};
+  static_assert(a.f == 0.0);
+};
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1073,8 +1073,12 @@
 return this->emitNullPtr(E);
   case PT_FnPtr:
 return this->emitNullFnPtr(E);
-  case PT_Float:
-assert(false);
+  case PT_Float: {
+const auto &Sem = Ctx.getASTContext().getFloatTypeSemantics(E->getType());
+
+APFloat Val(Sem);
+return this->emitConstFloat(Val, E);
+  }
   }
   llvm_unreachable("unknown primitive type");
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D145584: [libc] Add support for setjmp and longjmp in riscv

2023-03-24 Thread Siva Chandra via Phabricator via cfe-commits
sivachandra accepted this revision.
sivachandra added inline comments.
This revision is now accepted and ready to land.



Comment at: libc/src/setjmp/riscv64/longjmp.cpp:54-55
+
+  LIBC_INLINE_ASM("seqz %0, %1" : "+r"(buf) : "r"(val) :);
+  LIBC_INLINE_ASM("add %0, %0, %1" : "+r"(buf) : "r"(val), "r"(buf) :);
+}

Your comment is in the previous diff but thanks for the explanation. I think we 
have missed the `val` check for zero in the x86_64 case and should be fixed 
separately.

For the above two instructions, in the interest of reducing the amount of logic 
in inline assembly, can we do:

```
  val = val == 0 ? 1 : val;
  LIBC_INLINE_ASM("add a0, %0, zero\n\t" : : "r"(val) :);
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145584

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


[PATCH] D146408: [clang][Interp] Start supporting complex types

2023-03-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Context.cpp:84-85
 
+  if (T->isAnyComplexType())
+return std::nullopt;
+

aaron.ballman wrote:
> Hmmm, this seems surprising to me, I would have assumed that _Complex needed 
> to be a primitive type so that we could perform typical math on it rather 
> than treat it as a pair of values.
I was going to add special opcodes for this case (or add //one// opcode for 
complex/vector/bitint/... things to do everything?). 

If we don't do it this way we'd have to add `isAnyComplexType()` checks 
everywhere so we can figure out if we need to look at one or two values, don't 
we?



Comment at: clang/test/AST/Interp/complex.cpp:7
+
+constexpr _Complex double z1 = {1.0, 2.0};
+static_assert(__real(z1) == 1.0);

aaron.ballman wrote:
> Can you add tests for `_Complex int` as well? (That's also covered by 
> `isAnyComplexType()`)
There's a `FIXME` comment above in `EvalEmitter.cpp` so returning those doesn't 
work yet (but is otherwise not problematic I think.)


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

https://reviews.llvm.org/D146408

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


[clang] 3048c9e - Revert "Recommit [Modules] Remove unnecessary check when generating name lookup table in ASTWriter"

2023-03-24 Thread Dmitry Chernenkov via cfe-commits

Author: Dmitry Chernenkov
Date: 2023-03-24T07:59:04Z
New Revision: 3048c9e15498161572483e3d4b81c9c37bf2770f

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

LOG: Revert "Recommit [Modules] Remove unnecessary check when generating name 
lookup table in ASTWriter"

This reverts commit 25557aa38a0dab76f5b7a4518942f69d879693c0.

Added: 


Modified: 
clang/include/clang/Serialization/ASTWriter.h
clang/lib/Serialization/ASTWriter.cpp

Removed: 
clang/test/Modules/pr61065.cppm



diff  --git a/clang/include/clang/Serialization/ASTWriter.h 
b/clang/include/clang/Serialization/ASTWriter.h
index d31fa38b93825..09ee1744e8945 100644
--- a/clang/include/clang/Serialization/ASTWriter.h
+++ b/clang/include/clang/Serialization/ASTWriter.h
@@ -514,6 +514,7 @@ class ASTWriter : public ASTDeserializationListener,
   void WriteTypeAbbrevs();
   void WriteType(QualType T);
 
+  bool isLookupResultExternal(StoredDeclsList &Result, DeclContext *DC);
   bool isLookupResultEntirelyExternal(StoredDeclsList &Result, DeclContext 
*DC);
 
   void GenerateNameLookupTable(const DeclContext *DC,

diff  --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 3e40812a9a0ba..31e44b52929f4 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -3849,6 +3849,12 @@ class ASTDeclContextNameLookupTrait {
 
 } // namespace
 
+bool ASTWriter::isLookupResultExternal(StoredDeclsList &Result,
+   DeclContext *DC) {
+  return Result.hasExternalDecls() &&
+ DC->hasNeedToReconcileExternalVisibleStorage();
+}
+
 bool ASTWriter::isLookupResultEntirelyExternal(StoredDeclsList &Result,
DeclContext *DC) {
   for (auto *D : Result.getLookupResult())
@@ -3891,7 +3897,8 @@ ASTWriter::GenerateNameLookupTable(const DeclContext 
*ConstDC,
 // don't need to write an entry for the name at all. If we can't
 // write out a lookup set without performing more deserialization,
 // just skip this entry.
-if (isLookupResultEntirelyExternal(Result, DC))
+if (isLookupResultExternal(Result, DC) &&
+isLookupResultEntirelyExternal(Result, DC))
   continue;
 
 // We also skip empty results. If any of the results could be external and

diff  --git a/clang/test/Modules/pr61065.cppm b/clang/test/Modules/pr61065.cppm
deleted file mode 100644
index 44fa3679974ad..0
--- a/clang/test/Modules/pr61065.cppm
+++ /dev/null
@@ -1,55 +0,0 @@
-// From https://github.com/llvm/llvm-project/issues/61065
-// RUN: rm -rf %t
-// RUN: mkdir -p %t
-// RUN: split-file %s %t
-//
-// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm
-// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -o %t/b.pcm \
-// RUN: -fprebuilt-module-path=%t
-// RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-module-interface -o %t/c.pcm \
-// RUN: -fprebuilt-module-path=%t
-// RUN: %clang_cc1 -std=c++20 %t/d.cpp -fsyntax-only -verify 
-fprebuilt-module-path=%t
-
-//--- a.cppm
-export module a;
-
-struct base {
-   base(int) {}
-};
-
-export struct a : base {
-   using base::base;
-};
-
-//--- b.cppm
-export module b;
-
-import a;
-
-a b() {
-   return a(1);
-}
-
-//--- c.cppm
-export module c;
-
-import a;
-import b;
-
-struct noncopyable {
-   noncopyable(noncopyable const &) = delete;
-noncopyable() = default;
-};
-
-export struct c {
-   noncopyable c0;
-   a c1 = 43;
-c() = default;
-};
-
-//--- d.cpp
-// expected-no-diagnostics
-import c;
-void d() {
-c _;
-}



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


[PATCH] D141497: [clang][Interp] Record initialization via conditional operator

2023-03-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.h:182-183
 
+  template 
+  bool visitConditional(const AbstractConditionalOperator *E, VisitFn V);
+

aaron.ballman wrote:
> The template definition isn't available within the header file, so this is 
> fragile (impossible to instantiate from anything but ByteCodeExprGen.cpp).
What's the alternative? If I make it a static function in 
`ByteCodeExprGen.cpp`, I'd have to make a lot of members of `ByteCodeEmitter` 
etc. public which  is not a very clean solution. Moving the definition into the 
header file isn't very nice either, all the others are in the source file.


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

https://reviews.llvm.org/D141497

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


[PATCH] D146727: [clangd] Use expansion location for missing include diagnostics.

2023-03-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/IncludeCleaner.cpp:382
 
-auto &Tokens = AST.getTokens();
-auto SpelledForExpanded =
-Tokens.spelledForExpanded(Tokens.expandedTokens(Ref.RefLocation));
-if (!SpelledForExpanded)
+auto ExpansionLoc = SM.getExpansionLoc(Ref.RefLocation);
+const auto *Token = AST.getTokens().spelledTokenAt(ExpansionLoc);

can you actually get the spelling location first and use expansion location 
only when it isn't inside the main file?
that way we get to preserve the behaviour for macro arguments, which warrants a 
test like:
```
#define FOO(X) const X x

FOO([[Foo]]); // we should have a missing include for symbol Foo here
```

and can we have a comment about reasons and implications, e.g. something like:
```
Spelling locations can point into preamble section at times. We don't want to 
emit diagnostics there as the offsets might be off when preamble is stale.
In such cases we fallback to expansion locations, as they're always in the main 
file. This means we fail to attach diagnostics to spelling of symbol names 
inside macro bodies.
// FIXME: Use presumed locations to make sure we can correctly generate 
diagnostics even in such cases.
```



Comment at: clang-tools-extra/clangd/unittests/IncludeCleanerTests.cpp:236
+  TU.AdditionalFiles["foo.h"] = guard(R"cpp(
+#define FOO 1
+struct Foo{}; 

can you also put a `#define BAR(x) Foo *x` here and a usage like `BAR(b);` 
inside the main file and check that we only get include for symbol for `BAR` 
inside the main file at that location?



Comment at: clang-tools-extra/include-cleaner/lib/Analysis.cpp:36
 walkAST(*Root, [&](SourceLocation Loc, NamedDecl &ND, RefType RT) {
-  if (!SM.isWrittenInMainFile(SM.getSpellingLoc(Loc)))
+  if (!SM.isWrittenInMainFile(SM.getSpellingLoc(Loc)) &&
+  SM.getDecomposedLoc(SM.getSpellingLoc(Loc)).first !=

you can directly use expansion location instead of checking both and mentioning 
preamble file id here, eg: `!SM.isWrittenInMainFile(SM.getExpansionLoc(Loc))`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146727

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


[PATCH] D146244: [clangd] Show used symbols on #include line hover.

2023-03-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

thanks, the implementation looks good. I left some comments around the test.




Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:2984
 
+TEST(Hover, UsedSymbols) {
+  struct {

Can you add a test in the existing `TEST(Hover, Present)` to verify the 
`present()` method work as expected when the number provided symbols `<= 5`/ `> 
5`?



Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:2990
+  #inclu^de "foo.h"
+  int var = foo();
+)cpp",

can you add a macro `FOO` to the test?



Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:2993
+[](HoverInfo &HI) { HI.UsedSymbolNames = {"foo"}; }},
+   {"[[#incl^ude \"foo.h\"]]",
+[](HoverInfo &HI) { HI.UsedSymbolNames = {}; }},

nit: remove the unused `[[]]`.



Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:2996
+   {R"cpp(
+  #include "foo.h"  
+  #include ^"bar.h"

IIUC, this test is to test multiple symbols provided by a header, I would 
suggest removing the `foo.h`, and just keep `bar.h` (to reduce the noise from 
the test).






Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:3000
+  int barVar = bar();
+  int foobarVar = foobar();
+  X x;

It is not quite obvious to readers that `foobar`, and `X` is from the `bar.h`, 
maybe use some more obvious name (e.g. defining classes named `Bar1`, `Bar2` 
etc).



Comment at: clang-tools-extra/clangd/unittests/HoverTests.cpp:3007
+   {R"cpp(
+  #in^clude 
+  int fooVar = foo();

This test is to test the system header, I'd simulate it more further to reflect 
the reality. Let's use ``, and a `system/vector` file with the dummy 
content `namespace std { template class vector {}; }`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146244

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


[PATCH] D146732: [include-cleaner] Attribute references to explicit specializations

2023-03-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:81
+// specializaiton using the exported name, but that's rare.
+if (llvm::isa(ND) || !RD)
+  return ND;

I think we should be careful about the case where `ND == nullptr`, `isa` will 
trigger an assertion, use `isa_and_present`.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:82
+if (llvm::isa(ND) || !RD)
+  return ND;
+return RD;

We seem to miss a testcase for `TypeAliasTemplateDecl`, add one?



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:119
+  testWalk(R"cpp(
+  template struct Foo {};
+  template<> struct $explicit^Foo {};)cpp",

nit: The indentation looks weird, the `template...` should not align with the 
above `testWalk` text, would be better to add 4 space indentation. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146732

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


[PATCH] D146101: [clang-format] Add DesignatedInitializerIndentWidth option.

2023-03-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/include/clang/Format/Format.h:2037
+  /// \endcode
+  int DesignatedInitializerIndentWidth;
+

owenpan wrote:
> 
Please disregard my comment above.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1665-1669
+  const auto DesignatedInitializerIndentWidth =
+  Style.DesignatedInitializerIndentWidth < 0
+  ? Style.ContinuationIndentWidth
+  : Style.DesignatedInitializerIndentWidth;
+  NewIndent = CurrentState.LastSpace + DesignatedInitializerIndentWidth;

owenpan wrote:
> Using -1 to mean `ContinuationIndentWidth` is unnecessary and somewhat 
> confusing IMO.
Please disregard my comment above.



Comment at: clang/lib/Format/Format.cpp:1372
   LLVMStyle.DerivePointerAlignment = false;
+  LLVMStyle.DesignatedInitializerIndentWidth = -1;
   LLVMStyle.DisableFormat = false;

owenpan wrote:
> 
Please disregard my comment above.



Comment at: clang/unittests/Format/ConfigParseTest.cpp:250-251
+  DesignatedInitializerIndentWidth, 34);
+  CHECK_PARSE("DesignatedInitializerIndentWidth: -1",
+  DesignatedInitializerIndentWidth, -1);
   CHECK_PARSE("CommentPragmas: '// abc$'", CommentPragmas, "// abc$");

owenpan wrote:
> Delete.
Please disregard my comment above.



Comment at: clang/unittests/Format/FormatTest.cpp:4845
+  Style.ContinuationIndentWidth = 8;
+  Style.DesignatedInitializerIndentWidth = -1; // Use ContinuationIndentWidth.
+  verifyFormat("auto s = SomeStruct{\n"

owenpan wrote:
> Delete it and rearrange the tests so that the unspecified (default) 
> `DesignatedInitializerIndentWidth` is tested first.
Please disregard my comment above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[clang] b94175b - [clang-format] NFC Format.h and ClangFormatStyleOptions.rst are out of date

2023-03-24 Thread via cfe-commits

Author: mydeveloperday
Date: 2023-03-24T09:27:23Z
New Revision: b94175b0ee5712cab8302ac62854106b82d3be08

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

LOG: [clang-format] NFC Format.h and ClangFormatStyleOptions.rst are out of date

Regenerate the style documentation, requires some minor sphinx changes to avoid 
warnings

Reviewed By: klimek

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index fd8f2bbb54322..24ae02a2eddb2 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -3642,6 +3642,49 @@ the configuration (without a prefix: ``Auto``).
 **MacroBlockEnd** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ 
`
   A regular expression matching macros that end a block.
 
+.. _Macros:
+
+**Macros** (``List of Strings``) :versionbadge:`clang-format 17.0` :ref:`¶ 
`
+  A list of macros of the form ``=`` .
+
+  Code will be parsed with macros expanded, in order to determine how to
+  interpret and format the macro arguments.
+
+  For example, the code:
+
+  .. code-block:: c++
+
+A(a*b);
+
+  will usually be interpreted as a call to a function A, and the
+  multiplication expression will be formatted as `a * b`.
+
+  If we specify the macro definition:
+
+  .. code-block:: yaml
+
+Macros:
+- A(x)=x
+
+  the code will now be parsed as a declaration of the variable b of type a*,
+  and formatted as `a* b` (depending on pointer-binding rules).
+
+  Features and restrictions:
+   * Both function-like macros and object-like macros are supported.
+   * Macro arguments must be used exactly once in the expansion.
+   * No recursive expansion; macros referencing other macros will be
+ ignored.
+   * Overloading by arity is supported: for example, given the macro
+ definitions A=x, A()=y, A(a)=a
+
+
+  .. code-block:: c++
+
+ A; -> x;
+ A(); -> y;
+ A(z); -> z;
+ A(a, b); // will not be expanded.
+
 .. _MaxEmptyLinesToKeep:
 
 **MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7` 
:ref:`¶ `

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 66904a6a11232..a55cd76d149ca 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2754,28 +2754,35 @@ struct FormatStyle {
   /// \code
   ///   A(a*b);
   /// \endcode
+  ///
   /// will usually be interpreted as a call to a function A, and the
   /// multiplication expression will be formatted as `a * b`.
   ///
   /// If we specify the macro definition:
-  /// \code
+  /// \code{.yaml}
   ///   Macros:
   ///   - A(x)=x
   /// \endcode
+  ///
   /// the code will now be parsed as a declaration of the variable b of type 
a*,
   /// and formatted as `a* b` (depending on pointer-binding rules).
   ///
   /// Features and restrictions:
-  /// *  Both function-like macros and object-like macros are supported.
-  /// *  Macro arguments must be used exactly once in the expansion.
-  /// *  No recursive expansion; macros referencing other macros will be
+  ///  * Both function-like macros and object-like macros are supported.
+  ///  * Macro arguments must be used exactly once in the expansion.
+  ///  * No recursive expansion; macros referencing other macros will be
   ///ignored.
-  /// *  Overloading by arity is supported: for example, given the macro
-  ///definitions A=x, A()=y, A(a)=a,
-  ///'A;' -> 'x;'
-  ///'A();' -> 'y;'
-  ///'A(z);' -> 'z;'
-  ///'A(a, b) will not be expanded.
+  ///  * Overloading by arity is supported: for example, given the macro
+  ///definitions A=x, A()=y, A(a)=a
+  ///
+  /// \code
+  ///A; -> x;
+  ///A(); -> y;
+  ///A(z); -> z;
+  ///A(a, b); // will not be expanded.
+  /// \endcode
+  ///
+  /// \version 17.0
   std::vector Macros;
 
   /// The maximum number of consecutive empty lines to keep.



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


[PATCH] D146704: [clang-format] NFC Format.h and ClangFormatStyleOptions.rst are out of date

2023-03-24 Thread MyDeveloperDay 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 rGb94175b0ee57: [clang-format] NFC Format.h and 
ClangFormatStyleOptions.rst are out of date (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146704

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -2754,28 +2754,35 @@
   /// \code
   ///   A(a*b);
   /// \endcode
+  ///
   /// will usually be interpreted as a call to a function A, and the
   /// multiplication expression will be formatted as `a * b`.
   ///
   /// If we specify the macro definition:
-  /// \code
+  /// \code{.yaml}
   ///   Macros:
   ///   - A(x)=x
   /// \endcode
+  ///
   /// the code will now be parsed as a declaration of the variable b of type a*,
   /// and formatted as `a* b` (depending on pointer-binding rules).
   ///
   /// Features and restrictions:
-  /// *  Both function-like macros and object-like macros are supported.
-  /// *  Macro arguments must be used exactly once in the expansion.
-  /// *  No recursive expansion; macros referencing other macros will be
+  ///  * Both function-like macros and object-like macros are supported.
+  ///  * Macro arguments must be used exactly once in the expansion.
+  ///  * No recursive expansion; macros referencing other macros will be
   ///ignored.
-  /// *  Overloading by arity is supported: for example, given the macro
-  ///definitions A=x, A()=y, A(a)=a,
-  ///'A;' -> 'x;'
-  ///'A();' -> 'y;'
-  ///'A(z);' -> 'z;'
-  ///'A(a, b) will not be expanded.
+  ///  * Overloading by arity is supported: for example, given the macro
+  ///definitions A=x, A()=y, A(a)=a
+  ///
+  /// \code
+  ///A; -> x;
+  ///A(); -> y;
+  ///A(z); -> z;
+  ///A(a, b); // will not be expanded.
+  /// \endcode
+  ///
+  /// \version 17.0
   std::vector Macros;
 
   /// The maximum number of consecutive empty lines to keep.
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -3642,6 +3642,49 @@
 **MacroBlockEnd** (``String``) :versionbadge:`clang-format 3.7` :ref:`¶ `
   A regular expression matching macros that end a block.
 
+.. _Macros:
+
+**Macros** (``List of Strings``) :versionbadge:`clang-format 17.0` :ref:`¶ `
+  A list of macros of the form ``=`` .
+
+  Code will be parsed with macros expanded, in order to determine how to
+  interpret and format the macro arguments.
+
+  For example, the code:
+
+  .. code-block:: c++
+
+A(a*b);
+
+  will usually be interpreted as a call to a function A, and the
+  multiplication expression will be formatted as `a * b`.
+
+  If we specify the macro definition:
+
+  .. code-block:: yaml
+
+Macros:
+- A(x)=x
+
+  the code will now be parsed as a declaration of the variable b of type a*,
+  and formatted as `a* b` (depending on pointer-binding rules).
+
+  Features and restrictions:
+   * Both function-like macros and object-like macros are supported.
+   * Macro arguments must be used exactly once in the expansion.
+   * No recursive expansion; macros referencing other macros will be
+ ignored.
+   * Overloading by arity is supported: for example, given the macro
+ definitions A=x, A()=y, A(a)=a
+
+
+  .. code-block:: c++
+
+ A; -> x;
+ A(); -> y;
+ A(z); -> z;
+ A(a, b); // will not be expanded.
+
 .. _MaxEmptyLinesToKeep:
 
 **MaxEmptyLinesToKeep** (``Unsigned``) :versionbadge:`clang-format 3.7` :ref:`¶ `
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146101: [clang-format] Add DesignatedInitializerIndentWidth option.

2023-03-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/include/clang/Format/Format.h:2025
+  /// on a new line. When set to -1 (default), ``ContinuationIndentWidth`` is
+  /// used. \code
+  ///   AlignAfterOpenBracket: AlwaysBreak





Comment at: clang/include/clang/Format/Format.h:2037
+  /// \endcode
+  int DesignatedInitializerIndentWidth;
+

owenpan wrote:
> owenpan wrote:
> > 
> Please disregard my comment above.
Please add `\version 17`.



Comment at: clang/lib/Format/ContinuationIndenter.cpp:1659
   opensProtoMessageField(Current, Style)) {
+const FormatToken *NextNoComment = Current.getNextNonComment();
 if (Current.opensBlockOrBlockTypeList(Style)) {

owenpan wrote:
> Can you also move it into the `else if` below to reduce the scope of the 
> pointer? Please note the typo `NextNoComment`.
Please ignore my comment above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146101

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


[PATCH] D146732: [include-cleaner] Attribute references to explicit specializations

2023-03-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet marked 3 inline comments as done.
kadircet added inline comments.



Comment at: clang-tools-extra/include-cleaner/lib/WalkAST.cpp:82
+if (llvm::isa(ND) || !RD)
+  return ND;
+return RD;

hokein wrote:
> We seem to miss a testcase for `TypeAliasTemplateDecl`, add one?
we already have one, pointed it there



Comment at: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp:206
   template  struct S {};
   template  $explicit^using foo = S;)cpp",
"^foo x;");

this is where we have the template alias type test already


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146732

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


[PATCH] D146732: [include-cleaner] Attribute references to explicit specializations

2023-03-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 508025.
kadircet marked an inline comment as done.
kadircet added a comment.

- use isa_and_present
- indentation for tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146732

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -114,6 +114,25 @@
   // One explicit call from the TypeLoc in constructor spelling, another
   // implicit reference through the constructor call.
   testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = ^S();");
+  testWalk("template struct $explicit^Foo {};", "^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template<> struct $explicit^Foo {};)cpp",
+   "^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template struct $explicit^Foo { void x(); };)cpp",
+   "^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template struct $explicit^Foo;)cpp",
+   "^Foo x;");
+  // FIXME: This is broken due to
+  // https://github.com/llvm/llvm-project/issues/42259.
+  testWalk(R"cpp(
+template struct $explicit^Foo { Foo(T); };
+template<> struct Foo { void get(); Foo(int); };)cpp",
+   "^Foo x(3);");
 }
 
 TEST(WalkAST, Alias) {
@@ -124,6 +143,25 @@
"int y = ^x;");
   testWalk("using $explicit^foo = int;", "^foo x;");
   testWalk("struct S {}; using $explicit^foo = S;", "^foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template<> struct Foo {};
+namespace ns { using ::$explicit^Foo; })cpp",
+   "ns::^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+namespace ns { using ::Foo; }
+template<> struct ns::$explicit^Foo {};)cpp",
+   "^Foo x;");
+  // AST doesn't have enough information to figure out whether specialization
+  // happened through an exported type or not. So err towards attributing use to
+  // the using-decl, specializations on the exported type should be rare and
+  // they're not permitted on type-aliases.
+  testWalk(R"cpp(
+template struct Foo {};
+namespace ns { using ::$explicit^Foo; }
+template<> struct ns::Foo {};)cpp",
+   "ns::^Foo x;");
 }
 
 TEST(WalkAST, Using) {
@@ -183,10 +221,6 @@
   template  typename> struct X {};
   X<^S> x;)cpp");
   testWalk("template struct $explicit^S { S(T); };", "^S s(42);");
-  // Should we mark the specialization instead?
-  testWalk(
-  "template struct $explicit^S {}; template <> struct S {};",
-  "^S s;");
 }
 
 TEST(WalkAST, MemberExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -7,16 +7,19 @@
 //===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/Support/Casting.h"
 
 namespace clang::include_cleaner {
@@ -62,6 +65,24 @@
   return resolveTemplateName(TST->getTemplateName());
 return Base->getAsRecordDecl();
   }
+  // Templated as TemplateSpecializationType and
+  // DeducedTemplateSpecializationType doesn't share a common base.
+  template 
+  // Picks the most specific specialization for a
+  // (Deduced)TemplateSpecializationType, while prioritizing using-decls.
+  NamedDecl *getMostRelevantTemplatePattern(const T *TST) {
+// This is the underlying decl used by TemplateSpecializationType, can be
+// null when type is dependent.
+auto *RD = TST->getAsTagDecl();
+auto *ND = resolveTemplateName(TST->getTemplateName());
+// In case of exported template names always prefer the using-decl. This
+// implies we'll point at the using-decl even when there's an explicit
+// specializaiton using the exported name, but that's rare.
+if (llvm::isa_and_present(ND))
+  return ND;
+// Fallback to primary template for dependent instantiations.
+return RD ? RD : ND;
+  }
 
 public:
   ASTWalker(DeclCallback Callback) : Callback(Callback) {}
@@ -161,17 +182,15 @@
   }
 
   bool VisitTemplateSpecializationTypeLoc(TemplateSpecialization

[PATCH] D146385: [clang][ExtractAPI] Complete declaration fragments for TagDecl types defined in a typedef

2023-03-24 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added inline comments.



Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:342
+  // Add the notion of typedef for tag type (struct or enum) of the same name.
+  if (const ElaboratedType *ET =
+  dyn_cast(Decl->getUnderlyingType())) {

This doesn't quite produce the output we want, this would generate `typedef 
struct Foo;` instead of the expected `typedef struct Foo { ... } Bar;` where 
Foo is the name of the struct and Bar is the name of the typedef. This should 
be easy enough to fix.



Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:347
+if (TagTy->getDecl()->isStruct()) {
+  for (const auto &Struct : API.getStructs()) {
+if (Decl->getName() == Struct.second.get()->Name) {

What happens if the visitation hasn't already encountered the definition of the 
struct? We wouldn't find it in the the APISet and this doesn't work. The 
approach I would suggest here is to generate the fragments for the underlying 
Decl directly. For example what happens for the following code:

```c
struct Foo;
typedef struct Foo TypedefedFoo;
struct Foo {
int bar;
};
```



Comment at: clang/lib/ExtractAPI/ExtractAPIVisitor.cpp:349-354
+  Struct.second.get()
+  ->Declaration
+  .appendFront(" ", DeclarationFragments::FragmentKind::Text)
+  .appendFront("typedef",
+   DeclarationFragments::FragmentKind::Keyword, "",
+   nullptr);

This logic is very similar to the one below we could use the same code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146385

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


[clang-tools-extra] 03101e1 - [include-cleaner] Attribute references to explicit specializations

2023-03-24 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2023-03-24T11:39:21+01:00
New Revision: 03101e141bf745f036be604e2a5a7c085eb02f5e

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

LOG: [include-cleaner] Attribute references to explicit specializations

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

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index 0ca84145721a6..e70a24367d6a9 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -7,16 +7,19 @@
 
//===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/Support/Casting.h"
 
 namespace clang::include_cleaner {
@@ -62,6 +65,24 @@ class ASTWalker : public RecursiveASTVisitor {
   return resolveTemplateName(TST->getTemplateName());
 return Base->getAsRecordDecl();
   }
+  // Templated as TemplateSpecializationType and
+  // DeducedTemplateSpecializationType doesn't share a common base.
+  template 
+  // Picks the most specific specialization for a
+  // (Deduced)TemplateSpecializationType, while prioritizing using-decls.
+  NamedDecl *getMostRelevantTemplatePattern(const T *TST) {
+// This is the underlying decl used by TemplateSpecializationType, can be
+// null when type is dependent.
+auto *RD = TST->getAsTagDecl();
+auto *ND = resolveTemplateName(TST->getTemplateName());
+// In case of exported template names always prefer the using-decl. This
+// implies we'll point at the using-decl even when there's an explicit
+// specializaiton using the exported name, but that's rare.
+if (llvm::isa_and_present(ND))
+  return ND;
+// Fallback to primary template for dependent instantiations.
+return RD ? RD : ND;
+  }
 
 public:
   ASTWalker(DeclCallback Callback) : Callback(Callback) {}
@@ -161,17 +182,15 @@ class ASTWalker : public RecursiveASTVisitor {
   }
 
   bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) {
-// FIXME: Handle explicit specializations.
 report(TL.getTemplateNameLoc(),
-   resolveTemplateName(TL.getTypePtr()->getTemplateName()));
+   getMostRelevantTemplatePattern(TL.getTypePtr()));
 return true;
   }
 
   bool VisitDeducedTemplateSpecializationTypeLoc(
   DeducedTemplateSpecializationTypeLoc TL) {
-// FIXME: Handle specializations.
 report(TL.getTemplateNameLoc(),
-   resolveTemplateName(TL.getTypePtr()->getTemplateName()));
+   getMostRelevantTemplatePattern(TL.getTypePtr()));
 return true;
   }
 

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index 68b6b217a2e01..8fcc2b5886ae4 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -114,6 +114,25 @@ TEST(WalkAST, TagType) {
   // One explicit call from the TypeLoc in constructor spelling, another
   // implicit reference through the constructor call.
   testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = 
^S();");
+  testWalk("template struct $explicit^Foo {};", "^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template<> struct $explicit^Foo {};)cpp",
+   "^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template struct $explicit^Foo { void x(); };)cpp",
+   "^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template struct $explicit^Foo;)cpp",
+   "^Foo x;");
+  // FIXME: This is broken due to
+  // https://github.com/llvm/llvm-project/issues/42259.
+  testWalk(R"cpp(
+template struct $explicit^Foo { Foo(T); };
+template<> struct Foo { void get(); Foo(int); };)cpp",
+   "^Foo x(3);");
 }
 
 TEST(WalkAST, Alias) {
@@ -124,6 +143,25 @@ TEST(WalkAST, Alias) {
"int y = ^x;");
   testWalk("using $explicit^foo = int;", "^foo x;");
   testWalk("struct S {}; using $explicit^foo = S;", "^foo x;");

[PATCH] D146732: [include-cleaner] Attribute references to explicit specializations

2023-03-24 Thread Kadir Cetinkaya 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 rG03101e141bf7: [include-cleaner] Attribute references to 
explicit specializations (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146732

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -114,6 +114,25 @@
   // One explicit call from the TypeLoc in constructor spelling, another
   // implicit reference through the constructor call.
   testWalk("struct $explicit^$implicit^S { static int x; };", "auto y = ^S();");
+  testWalk("template struct $explicit^Foo {};", "^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template<> struct $explicit^Foo {};)cpp",
+   "^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template struct $explicit^Foo { void x(); };)cpp",
+   "^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template struct $explicit^Foo;)cpp",
+   "^Foo x;");
+  // FIXME: This is broken due to
+  // https://github.com/llvm/llvm-project/issues/42259.
+  testWalk(R"cpp(
+template struct $explicit^Foo { Foo(T); };
+template<> struct Foo { void get(); Foo(int); };)cpp",
+   "^Foo x(3);");
 }
 
 TEST(WalkAST, Alias) {
@@ -124,6 +143,25 @@
"int y = ^x;");
   testWalk("using $explicit^foo = int;", "^foo x;");
   testWalk("struct S {}; using $explicit^foo = S;", "^foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+template<> struct Foo {};
+namespace ns { using ::$explicit^Foo; })cpp",
+   "ns::^Foo x;");
+  testWalk(R"cpp(
+template struct Foo {};
+namespace ns { using ::Foo; }
+template<> struct ns::$explicit^Foo {};)cpp",
+   "^Foo x;");
+  // AST doesn't have enough information to figure out whether specialization
+  // happened through an exported type or not. So err towards attributing use to
+  // the using-decl, specializations on the exported type should be rare and
+  // they're not permitted on type-aliases.
+  testWalk(R"cpp(
+template struct Foo {};
+namespace ns { using ::$explicit^Foo; }
+template<> struct ns::Foo {};)cpp",
+   "ns::^Foo x;");
 }
 
 TEST(WalkAST, Using) {
@@ -183,10 +221,6 @@
   template  typename> struct X {};
   X<^S> x;)cpp");
   testWalk("template struct $explicit^S { S(T); };", "^S s(42);");
-  // Should we mark the specialization instead?
-  testWalk(
-  "template struct $explicit^S {}; template <> struct S {};",
-  "^S s;");
 }
 
 TEST(WalkAST, MemberExprs) {
Index: clang-tools-extra/include-cleaner/lib/WalkAST.cpp
===
--- clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -7,16 +7,19 @@
 //===--===//
 
 #include "AnalysisInternal.h"
+#include "clang-include-cleaner/Types.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TemplateBase.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/Support/Casting.h"
 
 namespace clang::include_cleaner {
@@ -62,6 +65,24 @@
   return resolveTemplateName(TST->getTemplateName());
 return Base->getAsRecordDecl();
   }
+  // Templated as TemplateSpecializationType and
+  // DeducedTemplateSpecializationType doesn't share a common base.
+  template 
+  // Picks the most specific specialization for a
+  // (Deduced)TemplateSpecializationType, while prioritizing using-decls.
+  NamedDecl *getMostRelevantTemplatePattern(const T *TST) {
+// This is the underlying decl used by TemplateSpecializationType, can be
+// null when type is dependent.
+auto *RD = TST->getAsTagDecl();
+auto *ND = resolveTemplateName(TST->getTemplateName());
+// In case of exported template names always prefer the using-decl. This
+// implies we'll point at the using-decl even when there's an explicit
+// specializaiton using the exported name, but that's rare.
+if (llvm::isa_and_present(ND))
+  return ND;
+// Fallback to primary template for dependent instantiations.
+return RD ? RD : ND;
+  }
 
 public:
   ASTWalker(DeclCallback Callback) : Callback(Callback) {}
@@ 

[PATCH] D146701: [AMDGPU] Create Subtarget Features for some of 16 bits atomic fadd instructions

2023-03-24 Thread Jay Foad via Phabricator via cfe-commits
foad accepted this revision.
foad added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!

If you want to remove some of the other unnecessary predicates from Real 
instructions you could do that in a separate NFC patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146701

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


[PATCH] D142932: Multilib YAML parsing

2023-03-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 508036.
michaelplatings added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142932

Files:
  clang/include/clang/Driver/Multilib.h
  clang/lib/Driver/Multilib.cpp
  clang/unittests/Driver/MultilibTest.cpp

Index: clang/unittests/Driver/MultilibTest.cpp
===
--- clang/unittests/Driver/MultilibTest.cpp
+++ clang/unittests/Driver/MultilibTest.cpp
@@ -13,6 +13,7 @@
 #include "clang/Driver/Multilib.h"
 #include "../../lib/Driver/ToolChains/CommonArgs.h"
 #include "clang/Basic/LLVM.h"
+#include "clang/Basic/Version.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -203,3 +204,392 @@
   Multilib({}, {}, {}, {"+x"}, Multilib::PrintOptionsType::List, {"-y"})
   .getPrintOptions());
 }
+
+static void diagnosticCallback(const llvm::SMDiagnostic &D, void *Out) {
+  *reinterpret_cast(Out) = D.getMessage();
+}
+
+static bool parseYaml(MultilibSet &MS, std::string &Diagnostic,
+  const char *Data) {
+  return MS.parseYaml(llvm::MemoryBufferRef(Data, "TEST"), diagnosticCallback,
+  &Diagnostic);
+}
+
+static bool parseYaml(MultilibSet &MS, const char *Data) {
+  return MS.parseYaml(llvm::MemoryBufferRef(Data, "TEST"));
+}
+
+// When updating this version also update MultilibVersionCurrent in Multilib.cpp
+#define YAML_PREAMBLE "MultilibVersion: 1.0\n"
+
+TEST(MultilibTest, ParseInvalid) {
+  std::string Diagnostic;
+
+  MultilibSet MS;
+
+  EXPECT_FALSE(parseYaml(MS, Diagnostic, R"(
+Variants: []
+)"));
+  EXPECT_TRUE(
+  StringRef(Diagnostic).contains("missing required key 'MultilibVersion'"))
+  << Diagnostic;
+
+  // Reject files with a different major version
+  EXPECT_FALSE(parseYaml(MS, Diagnostic,
+ R"(
+MultilibVersion: 2.0
+Variants: []
+)"));
+  EXPECT_TRUE(
+  StringRef(Diagnostic).contains("Multilib version 2.0 is unsupported"))
+  << Diagnostic;
+  EXPECT_FALSE(parseYaml(MS, Diagnostic,
+ R"(
+MultilibVersion: 0.1
+Variants: []
+)"));
+  EXPECT_TRUE(
+  StringRef(Diagnostic).contains("Multilib version 0.1 is unsupported"))
+  << Diagnostic;
+
+  // Reject files with a later minor version
+  EXPECT_FALSE(parseYaml(MS, Diagnostic,
+ R"(
+MultilibVersion: 1.9
+Variants: []
+)"));
+  EXPECT_TRUE(
+  StringRef(Diagnostic).contains("Multilib version 1.9 is unsupported"))
+  << Diagnostic;
+
+  // Accept files with the same major version and the same or earlier minor
+  // version
+  EXPECT_TRUE(parseYaml(MS, Diagnostic, R"(
+MultilibVersion: 1.0
+Variants: []
+)")) << Diagnostic;
+
+  EXPECT_FALSE(parseYaml(MS, Diagnostic, YAML_PREAMBLE));
+  EXPECT_TRUE(StringRef(Diagnostic).contains("missing required key 'Variants'"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parseYaml(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants:
+- Dir: /abc
+  Flags: []
+  PrintOptions: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic).contains("paths must be relative"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parseYaml(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants:
+- Flags: []
+  PrintOptions: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic).contains("missing required key 'Dir'"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parseYaml(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants:
+- Dir: .
+  PrintOptions: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic).contains("missing required key 'Flags'"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parseYaml(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants:
+- Dir: .
+  Flags: []
+)"));
+  EXPECT_TRUE(
+  StringRef(Diagnostic).contains("missing required key 'PrintOptions'"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parseYaml(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants: []
+FlagMap:
+- Regex: abc
+)"));
+  EXPECT_TRUE(
+  StringRef(Diagnostic)
+  .contains("value required for 'MatchFlags' or 'NoMatchFlags'"))
+  << Diagnostic;
+
+  EXPECT_FALSE(parseYaml(MS, Diagnostic, YAML_PREAMBLE R"(
+Variants: []
+FlagMap:
+- Dir: .
+  Regex: '('
+  PrintOptions: []
+)"));
+  EXPECT_TRUE(StringRef(Diagnostic).contains("parentheses not balanced"))
+  << Diagnostic;
+}
+
+TEST(MultilibTest, Parse) {
+  MultilibSet MS;
+  EXPECT_TRUE(parseYaml(MS, YAML_PREAMBLE R"(
+Variants:
+- Dir: .
+  Flags: []
+  PrintOptions: []
+)"));
+  EXPECT_EQ(1U, MS.size());
+  EXPECT_EQ("", MS.begin()->gccSuffix());
+
+  EXPECT_TRUE(parseYaml(MS, YAML_PREAMBLE R"(
+Variants:
+- Dir: abc
+  Flags: []
+  PrintOptions: []
+)"));
+  EXPECT_EQ(1U, MS.size());
+  EXPECT_EQ("/abc", MS.begin()->gccSuffix());
+
+  EXPECT_TRUE(parseYaml(MS, YAML_PREAMBLE R"(
+Variants:
+- Dir: pqr
+  Flags: []
+  PrintOptions: [-mfloat-abi=soft]
+)"));
+  EXPECT_EQ(1U, MS.size());
+  EXPECT_EQ("/pqr", MS.begin()->gccSuffix());
+  EXPECT_EQ(std::ve

[PATCH] D142933: Add -print-multi-selection-flags-experimental option

2023-03-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 508037.
michaelplatings added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142933

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.h
  clang/test/Driver/print-multi-selection-flags.c

Index: clang/test/Driver/print-multi-selection-flags.c
===
--- /dev/null
+++ clang/test/Driver/print-multi-selection-flags.c
@@ -0,0 +1,54 @@
+// RUN: %clang -print-multi-selection-flags-experimental --target=aarch64-linux -fc++-abi=itanium -fsanitize=address | FileCheck --check-prefix=CHECK-LINUX %s
+// CHECK-LINUX: fc++-abi=itanium
+// CHECK-LINUX: fexceptions
+// CHECK-LINUX: frtti
+// CHECK-LINUX: fsanitize=address
+// CHECK-LINUX: target=aarch64-unknown-linux
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=aarch64-fuchsia -fsanitize=hwaddress | FileCheck --check-prefix=CHECK-FUCHSIA %s
+// CHECK-FUCHSIA: fsanitize=hwaddress
+// CHECK-FUCHSIA: target=aarch64-unknown-fuchsia
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabi -mfloat-abi=soft -fno-exceptions -fno-rtti | FileCheck --check-prefix=CHECK-ARMV4T %s
+// CHECK-ARMV4T: fno-exceptions
+// CHECK-ARMV4T: fno-rtti
+// CHECK-ARMV4T: mfloat-abi=soft
+// CHECK-ARMV4T: mfpu=none
+// CHECK-ARMV4T: target=armv4t-none-unknown-eabi
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=armv7em-none-eabi -mfloat-abi=softfp | FileCheck --check-prefix=CHECK-SOFTFP %s
+// CHECK-SOFTFP: mfloat-abi=softfp
+// CHECK-SOFTFP: mfpu=fpv4-sp-d16
+// CHECK-SOFTFP: target=thumbv7em-none-unknown-eabi
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabihf -march=armv7em -mfpu=fpv5-d16 | FileCheck --check-prefix=CHECK-HARD %s
+// CHECK-HARD: mfloat-abi=hard
+// CHECK-HARD: mfpu=fpv5-d16
+// CHECK-HARD: target=thumbv7em-none-unknown-eabihf
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabi -mfloat-abi=soft -march=armv8-m.main+nofp | FileCheck --check-prefix=CHECK-V8MMAIN-NOFP %s
+// CHECK-V8MMAIN-NOFP: mfloat-abi=soft
+// CHECK-V8MMAIN-NOFP: mfpu=none
+// CHECK-V8MMAIN-NOFP: target=thumbv8m.main-none-unknown-eabi
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabi -mfloat-abi=hard -march=armv8.1m.main+mve.fp | FileCheck --check-prefix=CHECK-MVE %s
+// CHECK-MVE: march=+mve
+// CHECK-MVE: march=+mve.fp
+// CHECK-MVE: mfloat-abi=hard
+// CHECK-MVE: mfpu=fp-armv8-fullfp16-sp-d16
+// CHECK-MVE: target=thumbv8.1m.main-none-unknown-eabihf
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=arm-none-eabi -march=armv8.1m.main+mve+nofp | FileCheck --check-prefix=CHECK-MVENOFP %s
+// CHECK-MVENOFP: march=+mve
+// CHECK-MVENOFP-NOT: march=+mve.fp
+// CHECK-MVENOFP: mfpu=none
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=aarch64-none-elf -march=armv8-a+lse | FileCheck --check-prefix=CHECK-LSE %s
+// CHECK-LSE: march=+lse
+
+// RUN: %clang -print-multi-selection-flags-experimental --target=aarch64-none-elf -march=armv8.5-a+sve+sve2 | FileCheck --check-prefix=CHECK-SVE2 %s
+// RUN: %clang -print-multi-selection-flags-experimental --target=aarch64-none-elf -march=armv9-a| FileCheck --check-prefix=CHECK-SVE2 %s
+// CHECK-SVE2: march=+simd
+// CHECK-SVE2: march=+sve
+// CHECK-SVE2: march=+sve2
+// CHECK-SVE2: target=aarch64-none-unknown-elf
Index: clang/lib/Driver/ToolChains/Arch/ARM.h
===
--- clang/lib/Driver/ToolChains/Arch/ARM.h
+++ clang/lib/Driver/ToolChains/Arch/ARM.h
@@ -63,9 +63,11 @@
 void getARMArchCPUFromArgs(const llvm::opt::ArgList &Args,
llvm::StringRef &Arch, llvm::StringRef &CPU,
bool FromAs = false);
-void getARMTargetFeatures(const Driver &D, const llvm::Triple &Triple,
-  const llvm::opt::ArgList &Args,
-  std::vector &Features, bool ForAS);
+llvm::ARM::FPUKind getARMTargetFeatures(const Driver &D,
+const llvm::Triple &Triple,
+const llvm::opt::ArgList &Args,
+std::vector &Features,
+bool ForAS);
 int getARMSubArchVersionNumber(const llvm::Triple &Triple);
 bool isARMMProfile(const llvm::Triple &Triple);
 bool isARMAProfile(const llvm::Triple &Triple);
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -447,9 +44

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

2023-03-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 508038.
michaelplatings added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142986

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

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

[PATCH] D143059: [Driver] Enable selecting multiple multilibs

2023-03-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 508039.
michaelplatings added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143059

Files:
  clang/include/clang/Driver/Multilib.h
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/Multilib.cpp
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/CSKYToolChain.cpp
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/Hexagon.cpp
  clang/lib/Driver/ToolChains/Hurd.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/MipsLinux.cpp
  clang/lib/Driver/ToolChains/OHOS.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/test/Driver/fuchsia.cpp
  clang/unittests/Driver/MultilibBuilderTest.cpp
  clang/unittests/Driver/MultilibTest.cpp

Index: clang/unittests/Driver/MultilibTest.cpp
===
--- clang/unittests/Driver/MultilibTest.cpp
+++ clang/unittests/Driver/MultilibTest.cpp
@@ -154,18 +154,18 @@
   Multilib("/bar", {}, {}, {"+bar"}),
   });
   Multilib::flags_list Flags1 = {"+foo", "-bar"};
-  Multilib Selection1;
+  llvm::SmallVector Selection1;
   ASSERT_TRUE(MS.select(Flags1, Selection1))
   << "Flag set was {\"+foo\"}, but selection not found";
-  ASSERT_TRUE(Selection1.gccSuffix() == "/foo")
-  << "Selection picked " << Selection1 << " which was not expected";
+  ASSERT_TRUE(Selection1.back().gccSuffix() == "/foo")
+  << "Selection picked " << Selection1.back() << " which was not expected";
 
   Multilib::flags_list Flags2 = {"+foo", "+bar"};
-  Multilib Selection2;
+  llvm::SmallVector Selection2;
   ASSERT_TRUE(MS.select(Flags2, Selection2))
   << "Flag set was {\"+bar\"}, but selection not found";
-  ASSERT_TRUE(Selection2.gccSuffix() == "/bar")
-  << "Selection picked " << Selection2 << " which was not expected";
+  ASSERT_TRUE(Selection2.back().gccSuffix() == "/bar")
+  << "Selection picked " << Selection2.back() << " which was not expected";
 }
 
 TEST(MultilibTest, SelectMultiple) {
@@ -173,17 +173,17 @@
   Multilib("/a", {}, {}, {"x"}),
   Multilib("/b", {}, {}, {"y"}),
   });
-  std::vector Selection;
+  llvm::SmallVector Selection;
 
-  Selection = MS.select({"x"});
+  ASSERT_TRUE(MS.select({"x"}, Selection));
   ASSERT_EQ(1u, Selection.size());
   EXPECT_EQ("/a", Selection[0].gccSuffix());
 
-  Selection = MS.select({"y"});
+  ASSERT_TRUE(MS.select({"y"}, Selection));
   ASSERT_EQ(1u, Selection.size());
   EXPECT_EQ("/b", Selection[0].gccSuffix());
 
-  Selection = MS.select({"y", "x"});
+  ASSERT_TRUE(MS.select({"y", "x"}, Selection));
   ASSERT_EQ(2u, Selection.size());
   EXPECT_EQ("/a", Selection[0].gccSuffix());
   EXPECT_EQ("/b", Selection[1].gccSuffix());
@@ -383,7 +383,7 @@
 
 TEST(MultilibTest, SelectSoft) {
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parseYaml(MS, YAML_PREAMBLE R"(
 Variants:
 - Dir: s
@@ -402,7 +402,7 @@
 
 TEST(MultilibTest, SelectSoftFP) {
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parseYaml(MS, YAML_PREAMBLE R"(
 Variants:
 - Dir: f
@@ -418,7 +418,7 @@
   // If hard float is all that's available then select that only if compiling
   // with hard float.
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parseYaml(MS, YAML_PREAMBLE R"(
 Variants:
 - Dir: h
@@ -432,7 +432,7 @@
 
 TEST(MultilibTest, SelectFloatABI) {
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parseYaml(MS, YAML_PREAMBLE R"(
 Variants:
 - Dir: s
@@ -453,18 +453,18 @@
   NoMatchFlags: [hasfp]
 )"));
   MS.select({"mfloat-abi=soft"}, Selected);
-  EXPECT_EQ("/s", Selected.gccSuffix());
+  EXPECT_EQ("/s", Selected.back().gccSuffix());
   MS.select({"mfloat-abi=softfp"}, Selected);
-  EXPECT_EQ("/f", Selected.gccSuffix());
+  EXPECT_EQ("/f", Selected.back().gccSuffix());
   MS.select({"mfloat-abi=hard"}, Selected);
-  EXPECT_EQ("/h", Selected.gccSuffix());
+  EXPECT_EQ("/h", Selected.back().gccSuffix());
 }
 
 TEST(MultilibTest, SelectFloatABIReversed) {
   // If soft is specified after softfp then softfp will never be
   // selected because soft is compatible with softfp and last wins.
   MultilibSet MS;
-  Multilib Selected;
+  llvm::SmallVector Selected;
   ASSERT_TRUE(parseYaml(MS, YAML_PREAMBLE R"(
 Variants:
 - Dir: h
@@ -485,11 +485,11 @@
   NoMatchFlags: [hasfp]
 )"));
   MS.select({"mfloat-abi=soft"}, Selected);
-  EXPECT_EQ("/s", Selected.gccSuffix());
+  EXPECT_EQ("/s", Selected.back().gccSuffix());
   MS.select({"mfloat-abi=softfp"}, Selected);
-  EXPECT_EQ("/s", Selected.gccSuffix());
+  EXPECT_EQ("/s", Selected.back().gccSuffix());
   MS.select({"mfloat-abi=hard"}, Selected)

[PATCH] D143075: BareMetal ToolChain multilib layering

2023-03-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 508040.
michaelplatings added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143075

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

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

[PATCH] D143587: [Docs] Multilib design

2023-03-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings updated this revision to Diff 508041.
michaelplatings added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143587

Files:
  clang/docs/Multilib.rst
  clang/docs/index.rst
  clang/include/clang/Driver/Multilib.h

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

[clang] f454a7c - [OpenCL] Emit EOL at end of generated header

2023-03-24 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-03-24T11:03:10Z
New Revision: f454a7c6853def66c4f3a68bd2a0520489f6833c

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

LOG: [OpenCL] Emit EOL at end of generated header

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 79022ce67232a..1c3b7e4398a8c 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -1328,7 +1328,7 @@ void OpenCLBuiltinHeaderEmitter::emit() {
   }
 
   OS << "\n// Disable any extensions we may have enabled previously.\n"
-"#pragma OPENCL EXTENSION all : disable";
+"#pragma OPENCL EXTENSION all : disable\n";
 }
 
 void clang::EmitClangOpenCLBuiltins(RecordKeeper &Records, raw_ostream &OS) {



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


[PATCH] D146801: [clang] Fix consteval initializers of temporaries

2023-03-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When a potential immediate invocation is met, it is immediately wrapped by a
`ConstantExpr`. There is also a TreeTransform that removes this `ConstantExpr`
wrapper when corresponding expression evaluation context is popped.
So, in case initializer was an immediate invocation, `CXXTemporaryObjectExpr`
was wrapped by a `ConstantExpr`, and that caused additional unnecessary
`CXXFunctionalCastExpr` to be added, which later confused the TreeTransform
that rebuilds immediate invocations, so it was adding unnecessary
constructor call.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146801

Files:
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1050,3 +1050,18 @@
 
 }
 }
+
+namespace GH60286 {
+
+struct A {
+  int i = 0;
+
+  consteval A() {}
+  A(const A&) { i = 1; }
+  consteval int f() { return i; }
+};
+
+constexpr auto B = A{A{}}.f();
+static_assert(B == 0);
+
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1590,6 +1590,9 @@
   Expr *Inner = Result.get();
   if (CXXBindTemporaryExpr *BTE = 
dyn_cast_or_null(Inner))
 Inner = BTE->getSubExpr();
+  if (ConstantExpr *CE = dyn_cast_or_null(Inner))
+if (CE->isImmediateInvocation())
+  Inner = CE->getSubExpr();
   if (!isa(Inner) &&
   !isa(Inner)) {
 // If we created a CXXTemporaryObjectExpr, that node also represents the


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1050,3 +1050,18 @@
 
 }
 }
+
+namespace GH60286 {
+
+struct A {
+  int i = 0;
+
+  consteval A() {}
+  A(const A&) { i = 1; }
+  consteval int f() { return i; }
+};
+
+constexpr auto B = A{A{}}.f();
+static_assert(B == 0);
+
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1590,6 +1590,9 @@
   Expr *Inner = Result.get();
   if (CXXBindTemporaryExpr *BTE = dyn_cast_or_null(Inner))
 Inner = BTE->getSubExpr();
+  if (ConstantExpr *CE = dyn_cast_or_null(Inner))
+if (CE->isImmediateInvocation())
+  Inner = CE->getSubExpr();
   if (!isa(Inner) &&
   !isa(Inner)) {
 // If we created a CXXTemporaryObjectExpr, that node also represents the
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146802: [Documentation] improved documentation of diagnostic messages by explaining thier syntax and test of clang by telling which subobject is uninitialized

2023-03-24 Thread suman meena via Phabricator via cfe-commits
simideveloper created this revision.
Herald added a project: All.
simideveloper requested review of this revision.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146802

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/Interp/Interp.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
  clang/test/SemaCXX/attr-require-constant-initialization.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -761,7 +761,7 @@
 };
 
 S s1; // expected-error {{call to consteval function 'NamespaceScopeConsteval::S::S' is not a constant expression}} \
- expected-note {{subobject of type 'int' is not initialized}}
+ expected-note {{subobject Val is not initialized}}
 
 template 
 struct T {
@@ -770,7 +770,7 @@
 };
 
 T t; // expected-error {{call to consteval function 'NamespaceScopeConsteval::T::T' is not a constant expression}} \
- expected-note {{subobject of type 'int' is not initialized}}
+ expected-note {{subobject Val is not initialized}}
 
 } // namespace NamespaceScopeConsteval
 
Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -409,12 +409,12 @@
 b.a.x = 2;
 return b;
   }
-  constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr B uninit = return_uninit(); // expected-error {{constant expression}} expected-note {{subobject  arr and p or q  is not initialized}}
   static_assert(return_uninit().a.x == 2);
   constexpr A return_uninit_struct() {
 B b = {.b = 1};
 b.a.x = 2;
-return b.a; // expected-note {{in call to 'A(b.a)'}} expected-note {{subobject of type 'int' is not initialized}}
+return b.a; // expected-note {{in call to 'A(b.a)'}} expected-note {{subobject arr and p or q is not initialized}}
   }
   // Note that this is rejected even though return_uninit() is accepted, and
   // return_uninit() copies the same stuff wrapped in a union.
@@ -558,7 +558,7 @@
 }
   };
   constinit X x1(true);
-  constinit X x2(false); // expected-error {{constant initializer}} expected-note {{constinit}} expected-note {{subobject of type 'int' is not initialized}}
+  constinit X x2(false); // expected-error {{constant initializer}} expected-note {{constinit}} expected-note {{subobject n is not initialized}}
 
   struct Y {
 struct Z { int n; }; // expected-note {{here}}
@@ -577,7 +577,7 @@
   };
   // FIXME: This is working around clang not implementing DR2026. With that
   // fixed, we should be able to test this without the injected copy.
-  constexpr Y copy(Y y) { return y; } // expected-note {{in call to 'Y(y)'}} expected-note {{subobject of type 'int' is not initialized}}
+  constexpr Y copy(Y y) { return y; } // expected-note {{in call to 'Y(y)'}} expected-note {{subobject z1.n is not initialized}}
   constexpr Y y1 = copy(Y());
   static_assert(y1.z1.n == 1 && y1.z2.n == 2 && y1.z3.n == 3);
 
Index: clang/test/SemaCXX/attr-require-constant-initialization.cpp
===
--- clang/test/SemaCXX/attr-require-constant-initialization.cpp
+++ clang/test/SemaCXX/attr-require-constant-initialization.cpp
@@ -152,7 +152,7 @@
 #else
   ATTR static PODType pod; // expected-error {{variable does not have a constant initializer}}
 // expected-note@-1 {{required by 'require_constant_initialization' attribute here}}
-// expected-note-re@-2 non-constexpr constructor|subobject of type 'int' is not initialized
+// expected-note-re@-2 non-constexpr constructor|subobject value and value2 is not initialized
 #endif
   ATTR static PODType pot2 = {ReturnInt()}; // expected-error {{variable does not have a constant initializer}}
 // expected-note@-1 {{required by 'require_constant_initialization' attribute here}}
@@ -191,7 +191,7 @@
 PODType TT2::pod_noinit; // expected-note 0+ {{declared here}}
 #if __cplusplus >= 201103L
 // expected-error@-2 {{variable does not have a constant initializer}}
-// expected-note-re@-3 non-constexpr constructor|subobject of type 'int' is not initialized
+// expected-note-re@-3 non-constexpr constructor|subobject value and value2 is not initialized
 #endif
 PODType TT2::pod_copy_init(TT2::pod_noinit); // expected-error {{variable does not have a constant initializer}}
 #if __cplusplus >= 201103L
Index: clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
===

[PATCH] D142410: [AArch64] ARMv8.5-A implies both FEAT_SB and FEAT_SSBS

2023-03-24 Thread Sam Elliott via Phabricator via cfe-commits
lenary added a comment.

@philipp.tomsich Reverse Ping. What are your plans for this change?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142410

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


[clang] ef310c6 - Fix Clang sphinx build

2023-03-24 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-03-24T07:27:07-04:00
New Revision: ef310c6d498098f86095cd09ea89088c10e90fc3

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

LOG: Fix Clang sphinx build

This addresses the issues found in:
https://lab.llvm.org/buildbot/#/builders/92/builds/41772

Added: 


Modified: 
clang/docs/LanguageExtensions.rst

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index a9bdc83c53e7..b68d44e75e9b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -2361,7 +2361,7 @@ Query for this feature with 
``__has_builtin(__builtin_assume)``.
 .. _langext-__builtin_assume_separate_storage:
 
 ``__builtin_assume_separate_storage``
-
+-
 
 ``__builtin_assume_separate_storage`` is used to provide the optimizer with the
 knowledge that its two arguments point to separately allocated objects.



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


[PATCH] D146715: [NVPTX] Enforce half type support is present for builtins

2023-03-24 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda updated this revision to Diff 508046.
jchlanda added a comment.

Remove duplicated switch over builtins.


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

https://reviews.llvm.org/D146715

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-nvptx-native-half-type-err.c
  llvm/include/llvm/IR/IntrinsicsNVVM.td

Index: llvm/include/llvm/IR/IntrinsicsNVVM.td
===
--- llvm/include/llvm/IR/IntrinsicsNVVM.td
+++ llvm/include/llvm/IR/IntrinsicsNVVM.td
@@ -583,7 +583,6 @@
   "_xorsign_abs_f16", "_ftz_xorsign_abs_f16", "_nan_xorsign_abs_f16",
   "_ftz_nan_xorsign_abs_f16"] in {
   def int_nvvm_f # operation # variant :
-ClangBuiltin,
 DefaultAttrsIntrinsic<[llvm_half_ty], [llvm_half_ty, llvm_half_ty],
   [IntrNoMem, IntrSpeculatable, Commutative]>;
 }
@@ -592,7 +591,6 @@
   "_ftz_nan_f16x2", "_xorsign_abs_f16x2", "_ftz_xorsign_abs_f16x2",
   "_nan_xorsign_abs_f16x2", "_ftz_nan_xorsign_abs_f16x2"] in {
   def int_nvvm_f # operation # variant :
-ClangBuiltin,
 DefaultAttrsIntrinsic<[llvm_v2f16_ty], [llvm_v2f16_ty, llvm_v2f16_ty],
   [IntrNoMem, IntrSpeculatable, Commutative]>;
 }
@@ -828,9 +826,9 @@
   DefaultAttrsIntrinsic<[llvm_float_ty], [llvm_float_ty], [IntrNoMem]>;
   def int_nvvm_ex2_approx_d : ClangBuiltin<"__nvvm_ex2_approx_d">,
   DefaultAttrsIntrinsic<[llvm_double_ty], [llvm_double_ty], [IntrNoMem]>;
-  def int_nvvm_ex2_approx_f16 : ClangBuiltin<"__nvvm_ex2_approx_f16">,
+  def int_nvvm_ex2_approx_f16 :
   DefaultAttrsIntrinsic<[llvm_half_ty], [llvm_half_ty], [IntrNoMem]>;
-  def int_nvvm_ex2_approx_f16x2 : ClangBuiltin<"__nvvm_ex2_approx_f16x2">,
+  def int_nvvm_ex2_approx_f16x2 :
   DefaultAttrsIntrinsic<[llvm_v2f16_ty], [llvm_v2f16_ty], [IntrNoMem]>;
 
   def int_nvvm_lg2_approx_ftz_f : ClangBuiltin<"__nvvm_lg2_approx_ftz_f">,
@@ -860,18 +858,16 @@
 
   foreach variant = ["_rn_f16", "_rn_ftz_f16", "_rn_sat_f16",
 "_rn_ftz_sat_f16", "_rn_relu_f16", "_rn_ftz_relu_f16"] in {
-def int_nvvm_fma # variant : ClangBuiltin,
-DefaultAttrsIntrinsic<[llvm_half_ty],
-  [llvm_half_ty, llvm_half_ty, llvm_half_ty],
-  [IntrNoMem, IntrSpeculatable]>;
+def int_nvvm_fma # variant : DefaultAttrsIntrinsic<[llvm_half_ty],
+  [llvm_half_ty, llvm_half_ty, llvm_half_ty],
+  [IntrNoMem, IntrSpeculatable]>;
   }
 
   foreach variant = ["_rn_f16x2", "_rn_ftz_f16x2", "_rn_sat_f16x2",
 "_rn_ftz_sat_f16x2", "_rn_relu_f16x2", "_rn_ftz_relu_f16x2"] in {
-def int_nvvm_fma # variant : ClangBuiltin,
-  DefaultAttrsIntrinsic<[llvm_v2f16_ty],
-[llvm_v2f16_ty, llvm_v2f16_ty, llvm_v2f16_ty],
-[IntrNoMem, IntrSpeculatable]>;
+def int_nvvm_fma # variant : DefaultAttrsIntrinsic<[llvm_v2f16_ty],
+  [llvm_v2f16_ty, llvm_v2f16_ty, llvm_v2f16_ty],
+  [IntrNoMem, IntrSpeculatable]>;
   }
 
   foreach variant = ["_rn_bf16", "_rn_relu_bf16"] in {
Index: clang/test/CodeGen/builtins-nvptx-native-half-type-err.c
===
--- clang/test/CodeGen/builtins-nvptx-native-half-type-err.c
+++ clang/test/CodeGen/builtins-nvptx-native-half-type-err.c
@@ -1,21 +1,119 @@
 // REQUIRES: nvptx-registered-target
 //
 // RUN: not %clang_cc1 -fsyntax-only -ffp-contract=off -triple nvptx-unknown-unknown -target-cpu \
-// RUN:   sm_75 -target-feature +ptx70 -fcuda-is-device -x cuda -emit-llvm -o - %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK-ERROR %s
+// RUN:   sm_86 -target-feature +ptx72 -fcuda-is-device -x cuda -emit-llvm -o - %s 2>&1 \
+// RUN:   | FileCheck -check-prefix=CHECK_ERROR %s
 
 #define __device__ __attribute__((device))
 typedef __fp16 __fp16v2 __attribute__((ext_vector_type(2)));
 
-__device__ void nvvm_ldg_ldu_native_half_types(const void *p) {
-  __nvvm_ldg_h((const __fp16 *)p);
-  __nvvm_ldg_h2((const __fp16v2 *)p);
+__device__ void nvvm_native_half_types(void *a, void*b, void*c, __fp16* out) {
+  __fp16v2 resv2 = {0, 0};
+  *out += __nvvm_ex2_approx_f16(*(__fp16 *)a);
+  resv2 = __nvvm_ex2_approx_f16x2(*(__fp16v2*)a);
 
-  __nvvm_ldu_h((const __fp16 *)p);
-  __nvvm_ldu_h2((const __fp16v2 *)p);
+  *out += __nvvm_fma_rn_relu_f16(*(__fp16*)a, *(__fp16*)b, *(__fp16*)c);
+  *out += __nvvm_fma_rn_ftz_relu_f16(*(__fp16*)a, *(__fp16*)b, *(__fp16 *)c);
+  resv2 += __nvvm_fma_rn_relu_f16x2(*(__fp16v2*)a, *(__fp16v2*)b, *(__fp16v2*)c);
+  resv2 += __nvvm_fma_rn_ftz_relu_f16x2(*(__fp16v2*)a, *(__fp16v2*)b, *(__fp16v2*)c);
+  *out += __nvvm_fma_rn_ftz_f16(*(__fp16*)a, *(__fp16*)b, *(__fp16*)c);
+  *out += __nvvm_fma_rn_sat_f16(*(__fp16*)a, *(__fp16*)b, *(__fp16*)c);
+  *out += __nvvm_fma_rn_ftz_sat_f16(*(__fp16*)a, *(__fp16*)b, *(__fp16*)c);
+  resv2 += __nvvm_fma_rn_f16x2(*(__fp16v2*)a, *(__fp16v2*)b, *(__fp16v2*)c);
+  resv2 += __nvvm_fma_rn_ftz_f16x2(*(__fp16v2*)a, *(__fp16v2*)b, *(__fp16v2*)c);
+  resv2 += __nvvm

[PATCH] D146715: [NVPTX] Enforce half type support is present for builtins

2023-03-24 Thread Jakub Chlanda via Phabricator via cfe-commits
jchlanda added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:18912
+  case NVPTX::BI__nvvm_ldu_h2: {
+return MakeHalfType(BuiltinID, E, *this);
+  }

tra wrote:
> We seem to be checking builtin IDs twice. Once here and then in MakeHalfType 
> where we need to map them to intrinsics.
> I think the approach used for atomics above would work better here, too -- 
> just pass appropriate Intrinsic as a parameter to MakeHalfType and remove the 
> switch there.
> 
> Another option you may consider is that if the availability is only dependent 
> on PTX or SM version, then we may get by with declaring the builtins as 
> TARGET_BUILTIN with appropriate constraints and let the standard enforcement 
> machinery to handle diags.
I've refactored those switches and passed intrinsic ID to `MakeHalfType` helper.


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

https://reviews.llvm.org/D146715

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


[PATCH] D146644: [documentation]Fixed Random Typos

2023-03-24 Thread Sam Tebbs via Phabricator via cfe-commits
samtebbs accepted this revision.
samtebbs added a comment.
This revision is now accepted and ready to land.

Thank you for this, it looks like it fixes all of the typos reported in the 
issue. If you don't have commit access yet I can commit this with you as the 
author.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146644

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


[PATCH] D146644: [documentation]Fixed Random Typos

2023-03-24 Thread Priyanshi Agarwal via Phabricator via cfe-commits
ipriyanshi1708 added a comment.

Greetings Sir,

Thank you for accepting my revision. Please do commit it as I am
contributing for the first time and I don't have commit access.

Thanks & Regards
Priyanshi Agarwal


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146644

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


[PATCH] D140722: [OpenMP] Prefix outlined and reduction func names with original func's name

2023-03-24 Thread Itay Bookstein via Phabricator via cfe-commits
nextsilicon-itay-bookstein updated this revision to Diff 508054.
nextsilicon-itay-bookstein added a comment.

Minor fix to the clang/CodeGen/ppc64le-varargs-f128.c test.

@jdoerfert Does the PR CI run these, or are there build bots that cover the 
different target-offloading variants? Can I somehow check this prior to merging 
without having all hardware variants on-hand?


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

https://reviews.llvm.org/D140722

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/CodeGen/PowerPC/ppc64le-varargs-f128.c
  clang/test/CoverageMapping/openmp.c
  clang/test/OpenMP/amdgpu_target_with_aligned_attribute.c
  clang/test/OpenMP/bug54082.c
  clang/test/OpenMP/bug60602.cpp
  clang/test/OpenMP/cancel_codegen.cpp
  clang/test/OpenMP/cancellation_point_codegen.cpp
  clang/test/OpenMP/debug-info-complex-byval.cpp
  clang/test/OpenMP/debug-info-openmp-array.cpp
  clang/test/OpenMP/debug_threadprivate_copyin.c
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/for_firstprivate_codegen.cpp
  clang/test/OpenMP/for_lastprivate_codegen.cpp
  clang/test/OpenMP/for_linear_codegen.cpp
  clang/test/OpenMP/for_private_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen_UDR.cpp
  clang/test/OpenMP/for_reduction_task_codegen.cpp
  clang/test/OpenMP/function-attr.cpp
  clang/test/OpenMP/master_taskloop_in_reduction_codegen.cpp
  clang/test/OpenMP/master_taskloop_simd_in_reduction_codegen.cpp
  clang/test/OpenMP/metadirective_device_arch_codegen.cpp
  clang/test/OpenMP/metadirective_device_isa_codegen.cpp
  clang/test/OpenMP/metadirective_implementation_codegen.c
  clang/test/OpenMP/nested_loop_codegen.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_allocate_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/omp_with_loop_pragma_instr_profile.c
  clang/test/OpenMP/openmp_win_codegen.cpp
  clang/test/OpenMP/outlined_artificial.c
  clang/test/OpenMP/parallel_codegen.cpp
  clang/test/OpenMP/parallel_copyin_codegen.cpp
  clang/tes

[clang] ea064ee - [AMDGPU] Create Subtarget Features for some of 16 bits atomic fadd instructions

2023-03-24 Thread Mariusz Sikora via cfe-commits

Author: Mariusz Sikora
Date: 2023-03-24T13:10:40+01:00
New Revision: ea064ee2a3bd22f5598d0eb76a1bbc3bf293b063

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

LOG: [AMDGPU] Create Subtarget Features for some of 16 bits atomic fadd 
instructions

Introducing Subtarget Features for instructions:
- ds_pk_add_bf16
- ds_pk_add_f16
- ds_pk_add_rtn_bf16
- ds_pk_add_rtn_f16
- flat_atomic_pk_add_f16
- flat_atomic_pk_add_bf16
- global_atomic_pk_add_f16
- global_atomic_pk_add_bf16
- buffer_atomic_pk_add_f16

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

Added: 
clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl

Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/lib/Basic/Targets/AMDGPU.cpp
clang/test/CodeGenOpenCL/amdgpu-features.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
llvm/lib/Target/AMDGPU/AMDGPU.td
llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
llvm/lib/Target/AMDGPU/BUFInstructions.td
llvm/lib/Target/AMDGPU/DSInstructions.td
llvm/lib/Target/AMDGPU/FLATInstructions.td
llvm/lib/Target/AMDGPU/GCNSubtarget.h

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 8e7449d426bff..ed75b58ddbf96 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -215,7 +215,7 @@ TARGET_BUILTIN(__builtin_amdgcn_fmed3h, "", "nc", 
"gfx9-insts")
 
 TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fadd_f64, "dd*1d", "t", 
"gfx90a-insts")
 TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fadd_f32, "ff*1f", "t", 
"gfx90a-insts")
-TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fadd_v2f16, "V2hV2h*1V2h", "t", 
"gfx90a-insts")
+TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fadd_v2f16, "V2hV2h*1V2h", "t", 
"atomic-buffer-global-pk-add-f16-insts")
 TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fmin_f64, "dd*1d", "t", 
"gfx90a-insts")
 TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fmax_f64, "dd*1d", "t", 
"gfx90a-insts")
 
@@ -227,10 +227,10 @@ TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_f64, 
"dd*3d", "t", "gfx90a-insts"
 TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_f32, "ff*3f", "t", "gfx8-insts")
 
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_f32, "ff*0f", "t", 
"gfx940-insts")
-TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_v2f16, "V2hV2h*0V2h", "t", 
"gfx940-insts")
-TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_v2bf16, "V2sV2s*0V2s", "t", 
"gfx940-insts")
-TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fadd_v2bf16, "V2sV2s*1V2s", "t", 
"gfx940-insts")
-TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_v2bf16, "V2sV2s*3V2s", "t", 
"gfx940-insts")
+TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_v2f16, "V2hV2h*0V2h", "t", 
"atomic-flat-pk-add-16-insts")
+TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_v2bf16, "V2sV2s*0V2s", "t", 
"atomic-flat-pk-add-16-insts")
+TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fadd_v2bf16, "V2sV2s*1V2s", "t", 
"atomic-global-pk-add-bf16-inst")
+TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_v2bf16, "V2sV2s*3V2s", "t", 
"atomic-ds-pk-add-16-insts")
 
 
//===--===//
 // Deep learning builtins.

diff  --git a/clang/lib/Basic/Targets/AMDGPU.cpp 
b/clang/lib/Basic/Targets/AMDGPU.cpp
index 8dd27670d1c18..72dfb07804dff 100644
--- a/clang/lib/Basic/Targets/AMDGPU.cpp
+++ b/clang/lib/Basic/Targets/AMDGPU.cpp
@@ -257,9 +257,13 @@ bool AMDGPUTargetInfo::initFeatureMap(
 case GK_GFX940:
   Features["gfx940-insts"] = true;
   Features["fp8-insts"] = true;
+  Features["atomic-ds-pk-add-16-insts"] = true;
+  Features["atomic-flat-pk-add-16-insts"] = true;
+  Features["atomic-global-pk-add-bf16-inst"] = true;
   [[fallthrough]];
 case GK_GFX90A:
   Features["gfx90a-insts"] = true;
+  Features["atomic-buffer-global-pk-add-f16-insts"] = true;
   [[fallthrough]];
 case GK_GFX908:
   Features["dot3-insts"] = true;

diff  --git a/clang/test/CodeGenOpenCL/amdgpu-features.cl 
b/clang/test/CodeGenOpenCL/amdgpu-features.cl
index 9e24290668d92..4a4da6b270b9a 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-features.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-features.cl
@@ -72,9 +72,9 @@
 // GFX906: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 // GFX908: 
"target-features"="+16-bit-insts,+ci-insts,+dl-insts,+dot1-insts,+dot10-insts,+dot2-insts,+dot3-insts,+dot4-insts,+dot5-insts,+dot6-insts,+dot7-insts,+dpp,+gfx8-insts,+gfx9-insts,+mai-insts,+s-memrealtime,+

[PATCH] D146701: [AMDGPU] Create Subtarget Features for some of 16 bits atomic fadd instructions

2023-03-24 Thread Mariusz Sikora 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 rGea064ee2a3bd: [AMDGPU] Create Subtarget Features for some of 
16 bits atomic fadd instructions (authored by mariusz-sikora-at-amd).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146701

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/Basic/Targets/AMDGPU.cpp
  clang/test/CodeGenOpenCL/amdgpu-features.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
  llvm/lib/Target/AMDGPU/AMDGPU.td
  llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
  llvm/lib/Target/AMDGPU/BUFInstructions.td
  llvm/lib/Target/AMDGPU/DSInstructions.td
  llvm/lib/Target/AMDGPU/FLATInstructions.td
  llvm/lib/Target/AMDGPU/GCNSubtarget.h

Index: llvm/lib/Target/AMDGPU/GCNSubtarget.h
===
--- llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -152,9 +152,13 @@
   bool HasMAIInsts = false;
   bool HasFP8Insts = false;
   bool HasPkFmacF16Inst = false;
+  bool HasAtomicDsPkAdd16Insts = false;
+  bool HasAtomicFlatPkAdd16Insts = false;
   bool HasAtomicFaddRtnInsts = false;
   bool HasAtomicFaddNoRtnInsts = false;
-  bool HasAtomicPkFaddNoRtnInsts = false;
+  bool HasAtomicBufferGlobalPkAddF16NoRtnInsts = false;
+  bool HasAtomicBufferGlobalPkAddF16Insts = false;
+  bool HasAtomicGlobalPkAddBF16Inst = false;
   bool HasFlatAtomicFaddF32Inst = false;
   bool SupportsSRAMECC = false;
 
@@ -758,6 +762,10 @@
 return HasPkFmacF16Inst;
   }
 
+  bool hasAtomicDsPkAdd16Insts() const { return HasAtomicDsPkAdd16Insts; }
+
+  bool hasAtomicFlatPkAdd16Insts() const { return HasAtomicFlatPkAdd16Insts; }
+
   bool hasAtomicFaddInsts() const {
 return HasAtomicFaddRtnInsts || HasAtomicFaddNoRtnInsts;
   }
@@ -766,7 +774,17 @@
 
   bool hasAtomicFaddNoRtnInsts() const { return HasAtomicFaddNoRtnInsts; }
 
-  bool hasAtomicPkFaddNoRtnInsts() const { return HasAtomicPkFaddNoRtnInsts; }
+  bool hasAtomicBufferGlobalPkAddF16NoRtnInsts() const {
+return HasAtomicBufferGlobalPkAddF16NoRtnInsts;
+  }
+
+  bool hasAtomicBufferGlobalPkAddF16Insts() const {
+return HasAtomicBufferGlobalPkAddF16Insts;
+  }
+
+  bool hasAtomicGlobalPkAddBF16Inst() const {
+return HasAtomicGlobalPkAddBF16Inst;
+  }
 
   bool hasFlatAtomicFaddF32Inst() const { return HasFlatAtomicFaddF32Inst; }
 
Index: llvm/lib/Target/AMDGPU/FLATInstructions.td
===
--- llvm/lib/Target/AMDGPU/FLATInstructions.td
+++ llvm/lib/Target/AMDGPU/FLATInstructions.td
@@ -730,11 +730,13 @@
   defm GLOBAL_ATOMIC_MAX_F64 : FLAT_Global_Atomic_Pseudo<"global_atomic_max_f64", VReg_64, f64>;
 } // End SubtargetPredicate = isGFX90APlus
 
-let SubtargetPredicate = isGFX940Plus in {
+let SubtargetPredicate = HasAtomicFlatPkAdd16Insts in {
   defm FLAT_ATOMIC_PK_ADD_F16: FLAT_Atomic_Pseudo<"flat_atomic_pk_add_f16",  VGPR_32, v2f16>;
   defm FLAT_ATOMIC_PK_ADD_BF16   : FLAT_Atomic_Pseudo<"flat_atomic_pk_add_bf16", VGPR_32, v2f16>;
+} // End SubtargetPredicate = HasAtomicFlatPkAdd16Insts
+
+let SubtargetPredicate = HasAtomicGlobalPkAddBF16Inst in
   defm GLOBAL_ATOMIC_PK_ADD_BF16 : FLAT_Global_Atomic_Pseudo<"global_atomic_pk_add_bf16", VGPR_32, v2f16>;
-} // End SubtargetPredicate = isGFX940Plus
 
 // GFX7-, GFX10-, GFX11-only flat instructions.
 let SubtargetPredicate = isGFX7GFX10GFX11 in {
@@ -938,7 +940,7 @@
   defm GLOBAL_ATOMIC_ADD_F32 : FLAT_Global_Atomic_Pseudo_NO_RTN <
 "global_atomic_add_f32", VGPR_32, f32
   >;
-let OtherPredicates = [HasAtomicPkFaddNoRtnInsts] in
+let OtherPredicates = [HasAtomicBufferGlobalPkAddF16NoRtnInsts] in
   defm GLOBAL_ATOMIC_PK_ADD_F16 : FLAT_Global_Atomic_Pseudo_NO_RTN <
 "global_atomic_pk_add_f16", VGPR_32, v2f16
   >;
@@ -946,7 +948,7 @@
   defm GLOBAL_ATOMIC_ADD_F32 : FLAT_Global_Atomic_Pseudo_RTN <
 "global_atomic_add_f32", VGPR_32, f32
   >;
-let OtherPredicates = [isGFX90APlus] in
+let OtherPredicates = [HasAtomicBufferGlobalPkAddF16Insts] in
   defm GLOBAL_ATOMIC_PK_ADD_F16 : FLAT_Global_Atomic_Pseudo_RTN <
 "global_atomic_pk_add_f16", VGPR_32, v2f16
   >;
@@ -1505,7 +1507,7 @@
 defm : GlobalFLATAtomicPatsNoRtnWithAddrSpace <"GLOBAL_ATOMIC_ADD_F32", "int_amdgcn_global_atomic_fadd", "global_addrspace", f32>;
 }
 
-let OtherPredicates = [HasAtomicPkFaddNoRtnInsts] in {
+let OtherPredicates = [HasAtomicBufferGlobalPkAddF16NoRtnInsts] in {
 defm : GlobalFLATAtomicPatsNoRtnWithAddrSpace <"GLOBAL_ATOMIC_PK_ADD_F16", "int_amdgcn_flat_atomic_fadd", "global_addrspace", v2f16>;
 defm : GlobalFLATAtomicPatsNoRtnWithAddrSpace <"GLOBAL_ATOMIC_PK_ADD_F16", "int_amdgcn_global_atomic_fadd", "global_addr

[PATCH] D140722: [OpenMP] Prefix outlined and reduction func names with original func's name

2023-03-24 Thread Itay Bookstein via Phabricator via cfe-commits
nextsilicon-itay-bookstein updated this revision to Diff 508059.
nextsilicon-itay-bookstein added a comment.

Retry, wrong patch uploaded last time.


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

https://reviews.llvm.org/D140722

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/CodeGen/PowerPC/ppc64le-varargs-f128.c
  clang/test/CoverageMapping/openmp.c
  clang/test/OpenMP/amdgpu_target_with_aligned_attribute.c
  clang/test/OpenMP/bug54082.c
  clang/test/OpenMP/bug60602.cpp
  clang/test/OpenMP/cancel_codegen.cpp
  clang/test/OpenMP/cancellation_point_codegen.cpp
  clang/test/OpenMP/debug-info-complex-byval.cpp
  clang/test/OpenMP/debug-info-openmp-array.cpp
  clang/test/OpenMP/debug_threadprivate_copyin.c
  clang/test/OpenMP/declare_target_codegen_globalization.cpp
  clang/test/OpenMP/distribute_codegen.cpp
  clang/test/OpenMP/distribute_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_reduction_task_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_if_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_parallel_for_simd_proc_bind_codegen.cpp
  clang/test/OpenMP/distribute_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_codegen.cpp
  clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp
  clang/test/OpenMP/distribute_simd_private_codegen.cpp
  clang/test/OpenMP/distribute_simd_reduction_codegen.cpp
  clang/test/OpenMP/for_firstprivate_codegen.cpp
  clang/test/OpenMP/for_lastprivate_codegen.cpp
  clang/test/OpenMP/for_linear_codegen.cpp
  clang/test/OpenMP/for_private_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen.cpp
  clang/test/OpenMP/for_reduction_codegen_UDR.cpp
  clang/test/OpenMP/for_reduction_task_codegen.cpp
  clang/test/OpenMP/function-attr.cpp
  clang/test/OpenMP/master_taskloop_in_reduction_codegen.cpp
  clang/test/OpenMP/master_taskloop_simd_in_reduction_codegen.cpp
  clang/test/OpenMP/metadirective_device_arch_codegen.cpp
  clang/test/OpenMP/metadirective_device_isa_codegen.cpp
  clang/test/OpenMP/metadirective_implementation_codegen.c
  clang/test/OpenMP/nested_loop_codegen.cpp
  clang/test/OpenMP/nvptx_SPMD_codegen.cpp
  clang/test/OpenMP/nvptx_allocate_codegen.cpp
  clang/test/OpenMP/nvptx_data_sharing.cpp
  clang/test/OpenMP/nvptx_distribute_parallel_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_lambda_capturing.cpp
  clang/test/OpenMP/nvptx_multi_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_nested_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_parallel_for_codegen.cpp
  clang/test/OpenMP/nvptx_target_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_num_threads_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_proc_bind_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
  clang/test/OpenMP/nvptx_target_parallel_reduction_codegen_tbaa_PR46146.cpp
  clang/test/OpenMP/nvptx_target_teams_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_codegen.cpp
  
clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_generic_mode_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_parallel_for_simd_codegen.cpp
  clang/test/OpenMP/nvptx_target_teams_distribute_simd_codegen.cpp
  clang/test/OpenMP/nvptx_teams_codegen.cpp
  clang/test/OpenMP/nvptx_teams_reduction_codegen.cpp
  clang/test/OpenMP/omp_with_loop_pragma_instr_profile.c
  clang/test/OpenMP/openmp_win_codegen.cpp
  clang/test/OpenMP/outlined_artificial.c
  clang/test/OpenMP/parallel_codegen.cpp
  clang/test/OpenMP/parallel_copyin_codegen.cpp
  clang/test/OpenMP/parallel_copyin_combined_codegen.c
  clang/test/OpenMP/parallel_firstprivate_codegen.cpp
  clang/test/OpenMP/parallel_for_codegen.cpp
  clang/test/OpenMP/parallel_for_lastprivate_conditional.cpp
  clang/test/OpenMP/pa

[PATCH] D146503: Fix highlighting issue with _complex and initialization list with more than 2 items

2023-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D146503#4217541 , @chaitanyav 
wrote:

> Thank you, I will commit myself. Should i wait for the build to finish?. this 
> will be my first direct commit to repo.

Sorry for not getting back to you sooner. In general it's good to wait for 
precommit CI to finish just to be sure.  Congrats on your first direct commit! 
:-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146503

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


[PATCH] D146808: [AMDGPU] Add clang builtin for __builtin_amdgcn_ds_atomic_fadd_v2f16

2023-03-24 Thread Mariusz Sikora via Phabricator via cfe-commits
mariusz-sikora-at-amd created this revision.
Herald added subscribers: kosarev, kerbowa, tpr, dstuttard, yaxunl, jvesely, 
kzhuravl.
Herald added a project: All.
mariusz-sikora-at-amd requested review of this revision.
Herald added subscribers: cfe-commits, wdng.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146808

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx940.cl

Index: clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx940.cl
===
--- clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx940.cl
+++ clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx940.cl
@@ -48,3 +48,19 @@
 short2 test_local_add_2bf16(__local short2 *addr, short2 x) {
   return __builtin_amdgcn_ds_atomic_fadd_v2bf16(addr, x);
 }
+
+// CHECK-LABEL: test_local_add_2f16
+// CHECK: call <2 x half> @llvm.amdgcn.ds.fadd.v2f16(ptr addrspace(3) %{{.*}}, <2 x half> %
+// GFX940-LABEL:  test_local_add_2f16
+// GFX940: ds_pk_add_rtn_f16
+half2 test_local_add_2f16(__local half2 *addr, half2 x) {
+  return __builtin_amdgcn_ds_atomic_fadd_v2f16(addr, x);
+}
+
+// CHECK-LABEL: test_local_add_2f16_noret
+// CHECK: call <2 x half> @llvm.amdgcn.ds.fadd.v2f16(ptr addrspace(3) %{{.*}}, <2 x half> %
+// GFX940-LABEL:  test_local_add_2f16_noret
+// GFX940: ds_pk_add_f16
+void test_local_add_2f16_noret(__local half2 *addr, half2 x) {
+  __builtin_amdgcn_ds_atomic_fadd_v2f16(addr, x);
+}
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
@@ -6,7 +6,7 @@
 typedef half  __attribute__((ext_vector_type(2))) half2;
 typedef short __attribute__((ext_vector_type(2))) short2;
 
-void test_atomic_fadd(__global half2 *addrh2, half2 xh2,
+void test_atomic_fadd(__global half2 *addrh2, __local half2 *addrh2l, half2 xh2,
   __global short2 *addrs2, __local short2 *addrs2l, short2 xs2,
   __global float *addrf, float xf) {
   __builtin_amdgcn_flat_atomic_fadd_f32(addrf, xf); // expected-error{{'__builtin_amdgcn_flat_atomic_fadd_f32' needs target feature gfx940-insts}}
@@ -14,4 +14,5 @@
   __builtin_amdgcn_flat_atomic_fadd_v2bf16(addrs2, xs2); // expected-error{{'__builtin_amdgcn_flat_atomic_fadd_v2bf16' needs target feature atomic-flat-pk-add-16-insts}}
   __builtin_amdgcn_global_atomic_fadd_v2bf16(addrs2, xs2); // expected-error{{'__builtin_amdgcn_global_atomic_fadd_v2bf16' needs target feature atomic-global-pk-add-bf16-inst}}
   __builtin_amdgcn_ds_atomic_fadd_v2bf16(addrs2l, xs2); // expected-error{{'__builtin_amdgcn_ds_atomic_fadd_v2bf16' needs target feature atomic-ds-pk-add-16-insts}}
+  __builtin_amdgcn_ds_atomic_fadd_v2f16(addrh2l, xh2); // expected-error{{'__builtin_amdgcn_ds_atomic_fadd_v2f16' needs target feature atomic-ds-pk-add-16-insts}}
 }
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
@@ -4,9 +4,9 @@
 
 typedef half __attribute__((ext_vector_type(2))) half2;
 
-void test_global_add_2f16(__global half2 *addrh2, half2 xh2,
-  __global float *addrf, float xf,
-  __global double *addr, double x) {
+void test_global_fadd(__global half2 *addrh2, __local half2 *addrh2l, half2 xh2,
+  __global float *addrf, float xf,
+  __global double *addr, double x) {
   half2 *half_rtn;
   float *fp_rtn;
   double *rtn;
@@ -18,4 +18,5 @@
   *rtn = __builtin_amdgcn_flat_atomic_fadd_f64(addr, x); // expected-error{{'__builtin_amdgcn_flat_atomic_fadd_f64' needs target feature gfx90a-insts}}
   *rtn = __builtin_amdgcn_flat_atomic_fmin_f64(addr, x); // expected-error{{'__builtin_amdgcn_flat_atomic_fmin_f64' needs target feature gfx90a-insts}}
   *rtn = __builtin_amdgcn_flat_atomic_fmax_f64(addr, x); // expected-error{{'__builtin_amdgcn_flat_atomic_fmax_f64' needs target feature gfx90a-insts}}
+  __builtin_amdgcn_ds_atomic_fadd_v2f16(addrh2l, xh2); // expected-error{{'__builtin_amdgcn_ds_atomic_fadd_v2f16' needs target feature atomic-ds-pk-add-16-insts}}
 }
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-fp-a

[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-03-24 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a reviewer: mstorsjo.
hans added a comment.

+mstorsjo is this okay for mingw mode too?




Comment at: clang/lib/Sema/SemaExpr.cpp:3558
+return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL);
+  } else {
 // Pre-defined identifiers are of type char[x], where x is the length of

Since this becomes an "else after return" it could be dropped.



Comment at: clang/test/CodeGen/predefined-expr.c:4
+
+// ITANIUM: @__func__.plainFunction = private unnamed_addr constant [14 x i8] 
c"plainFunction\00"
+// ITANIUM: @__PRETTY_FUNCTION__.plainFunction = private unnamed_addr constant 
[25 x i8] c"void plainFunction(void)\00"

Both invocations use the Itanium abi, so the check prefix is a bit confusing. 
How about DEFAULT and MS?



Comment at: clang/test/Sema/ms_predefined_expr.cpp:4
+
+void f(void) {
+ const char a[] = __FUNCTION__;

ultra nit: the 'void' param makes this look like c code. Should it go in a .c 
file instead of .cpp?



Comment at: clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp:1062
+  // Predefined expressions are string literals under Microsoft extensions.
+  if (GetParam().isWin32())
+return;

Could the same check be used in ASTImporterTest.cpp?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman requested changes to this revision.
aaron.ballman added a comment.
This revision now requires changes to proceed.

This should also have a release note, eventually.




Comment at: clang/lib/Sema/SemaExpr.cpp:3586-3591
+  // MSVC treats all predefined expressions as string literals rather than char
+  // arrays.
+  if (LangOpts.MicrosoftExt)
+return SL;
+
   return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL);

This is incorrect -- these are still predefined expressions even if they're a 
string literal. Otherwise, we lose AST fidelity and things like the 
`predefinedExpr()` AST matcher don't work 
(https://github.com/llvm/llvm-project/blob/main/clang/include/clang/ASTMatchers/ASTMatchers.h#L2697),
 and `-ast-print` will print the wrong thing 
(https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/StmtPrinter.cpp#L1248).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


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

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144115

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

Test looks fine, still need a release note.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146784: [clang] Test for AST Dumping of the template variables

2023-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/AST/ast-dump-template-decls.cpp:193
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'

Hmm... thats curious.  We shouldn't commit this unless there is a 'fixme' on it 
showing we don't really mean it, but in reality, this just deserves a Github 
bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

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


[PATCH] D141215: [clang-repl] Introduce Value and implement pretty printing

2023-03-24 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 508068.
junaire added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/ASTHelpers.cpp
  clang/lib/Interpreter/ASTHelpers.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -139,6 +144,8 @@
 
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
 
+  // FIXME: Now we will include some runtime headers when the first we enter
+  // the REPL, so this doesn't work anymore.
   // Fail to undo.
   auto Err1 = Interp->Undo();
   EXPECT_EQ("Operation failed. Too many undos",
@@ -276,8 +283,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +320,31 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V2));
+  EXPECT_EQ(V2.getInt(), 42);
+  EXPECT_TRUE(V2.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 43);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
+  if (PP.isIncrementalProce

[PATCH] D146808: [AMDGPU] Add clang builtin for __builtin_amdgcn_ds_atomic_fadd_v2f16

2023-03-24 Thread Jay Foad via Phabricator via cfe-commits
foad accepted this revision.
foad added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: clang/include/clang/Basic/BuiltinsAMDGPU.def:234
 TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_v2bf16, "V2sV2s*3V2s", "t", 
"atomic-ds-pk-add-16-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_v2f16, "V2hV2h*3V2h", "t", 
"atomic-ds-pk-add-16-insts")
 

Just curious - is there a reason that these builtins can't be declared in 
LLVM's IntrinsicsAMDGPU.td?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146808

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


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

2023-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D144651#4217750 , @john.brawn 
wrote:

> Unfortunately I still can't reproduce this even using exactly the same cmake 
> command as you gave. Looking at above cmake log some possible causes of 
> difference are:
>
> - I'm doing this on an M1  macbook with host 
> triple arm64-apple-darwin21.6.0 but the host triple on that bot is 
> x86_64-apple-darwin20.6.0
> - I'm using python 3.9, bot is using python 3.10
> - I'm doing a build from clean whereas the bot is doing an incremental build
>
> Also if I try to run the simpler reproducer you give then I get the error
>
>   error: expression failed to parse:
>   error: Header search couldn't locate module Cocoa
>
> I'm now on holiday, I won't be able to get back to this until 2023-04-03.

The build lab's lldb builders are all green, and greendragon's standalone build 
is also green. Could this be a problem with incremental builds being in a bad 
state somehow?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

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


[PATCH] D146802: [Documentation] improved documentation of diagnostic messages by explaining thier syntax and test of clang by telling which subobject is uninitialized

2023-03-24 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

You are combining documentation of the syntax for defining diagnostics, and 
changes to the content of certain diagnostics. The LLVM project wants to see 
one topic per patch, so these things need to be done separately.

Also, the documentation probably does not want to live in one of the many .td 
files that define diagnostics. It wants to go somewhere generic, and I'm not 
sure what a good place would be.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146802

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-03-24 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 508072.
junaire added a comment.

Update comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/include/clang/Parse/Parser.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/ASTHelpers.cpp
  clang/lib/Interpreter/ASTHelpers.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/Value.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,10 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+int getGlobal() { return Global; }
+void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -139,7 +144,6 @@
 
   auto Interp = createInterpreter(ExtraArgs, DiagPrinter.get());
 
-  // Fail to undo.
   auto Err1 = Interp->Undo();
   EXPECT_EQ("Operation failed. Too many undos",
 llvm::toString(std::move(Err1)));
@@ -276,8 +280,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -314,4 +317,31 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V2));
+  EXPECT_EQ(V2.getInt(), 42);
+  EXPECT_TRUE(V2.getType()->isIntegerType());
+
+  // Change the global from the compiled code.
+  setGlobal(43);
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V3));
+  EXPECT_EQ(V3.getInt(), 43);
+  EXPECT_TRUE(V3.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+}
 } // end anonymous namespace
Index: clang/unittests/Interpreter/CMakeLists.txt
===
--- clang/unittests/Interpreter/CMakeLists.txt
+++ clang/unittests/Interpreter/CMakeLists.txt
@@ -22,3 +22,5 @@
 if(NOT WIN32)
   add_subdirectory(ExceptionTests)
 endif()
+
+export_executable_symbols(ClangReplInterpreterTests)
Index: clang/tools/clang-repl/CMakeLists.txt
===
--- clang/tools/clang-repl/CMakeLists.txt
+++ clang/tools/clang-repl/CMakeLists.txt
@@ -12,6 +12,7 @@
   )
 
 clang_target_link_libraries(clang-repl PRIVATE
+  clangAST
   clangBasic
   clangFrontend
   clangInterpreter
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -616,8 +617,8 @@
 
   // Skip over the EOF token, flagging end of previous input for incremental
   // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
+  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::annot_input_end))
+ConsumeAnyToken(

[PATCH] D146376: Update static_assert message for redundant cases

2023-03-24 Thread Krishna Narayanan via Phabricator via cfe-commits
Krishna-13-cyber added a comment.

The above Binary operator test case says that there are two Boolean 
expressions,**UsefulToPrintExpr** says we can avoid to print these expressions 
as they are don't need a note and are understandable.

So if we go by this we will have to remove the note.By this we are removing 
note for boolean literals as well as expressions.It will be nice to make it 
generic rather than specifically target cases of false || false , false && 
false. As the warning note print out the boolean values which can be avoided 
giving preference to the other diagnostics in terms of boolean literals and 
expressions.

Yes, I making a **new diff for test cases** of conjunction and disjunction as 
well.




Comment at: clang/test/SemaCXX/static-assert.cpp:261-265
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
-// expected-note 
{{evaluates to 'false == true'}}
 
   /// No notes here since we compare a bool expression with a bool literal.
   static_assert(invert(true) == true, ""); // expected-error {{failed}}

cjdb wrote:
> We should also have a test for conjunctions, disjunctions, and negations.
Yes, I making a new diff for test cases of conjunction and disjunction as well.



Comment at: clang/test/SemaCXX/static-assert.cpp:262
   static_assert(invert(true) == invert(false), ""); // expected-error 
{{failed}} \
-// expected-note 
{{evaluates to 'false == true'}}
 

tbaeder wrote:
> This diagnostic should be kept. From looking at the condition, it is not 
> obvious what the two functions evaluate to.
The above Binary operator test case says that there are two Boolean 
expressions,**UsefulToPrintExpr** says we can avoid to print these expressions 
as they are don't need a note and are understandable.

So if we go by this we will have to remove the note.By this we are removing 
note for boolean literals as well as expressions.It will be nice to make it 
generic rather than specifically target cases of false || false , false && 
false. As the warning note print out the boolean values which can be avoided 
giving preference to the other diagnostics in terms of boolean literals and 
expressions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146376

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


[PATCH] D146809: [WIP][clang-repl] Implement Value pretty printing

2023-03-24 Thread Jun Zhang via Phabricator via cfe-commits
junaire created this revision.
Herald added a subscriber: mstorsjo.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch implements Value::dump related code so the pretty printing
will work.

The problem for the patch is that it doesn't work with 'template types'
like all the STL components. For exmaple:
clang-repl> #include 
clang-repl> auto p = std::make_shared(42);
clang-repl> p

JIT session error: Symbols not found: [ 
_Z17PrintValueRuntimeIiENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPSt10shared_ptrIT_E
 ]
(shared_ptr &) ERROR: Failed to materialize symbols: { (main, { 
_Z23__InterpreterCallPrint1B5cxx11v }) }

RFC: 
https://discourse.llvm.org/t/rfc-handle-execution-results-in-clang-repl/68493

Signed-off-by: Jun Zhang 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146809

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__clang_interpreter_runtime_printvalue.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/Value.cpp
  clang/lib/Interpreter/ValuePrinter.cpp
  clang/test/Interpreter/pretty-print.cpp

Index: clang/test/Interpreter/pretty-print.cpp
===
--- /dev/null
+++ clang/test/Interpreter/pretty-print.cpp
@@ -0,0 +1,38 @@
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | clang-repl | FileCheck %s
+char c = 'a';
+c
+// CHECK: (char) 'a'
+
+int x = 42;
+x
+// CHECK-NEXT: (int) 42
+
+x - 2
+// CHECK-NEXT: (int) 40
+
+float f = 4.2f;
+f
+// CHECK-NEXT: (float) 4.2f
+
+double d = 4.21;
+d
+// CHECK-NEXT: (double) 4.210
+
+struct S{};
+S s;
+s
+// CHECK-NEXT: (S &) [[Addr:@0x.*]]
+
+S{}
+// CHECK-NEXT: (S) [[Addr:@0x.*]]
+
+struct SS { ~SS() {} };
+SS{}
+// CHECK-NEXT: (SS) [[Addr:@0x.*]]
+
+%quit
+
Index: clang/lib/Interpreter/ValuePrinter.cpp
===
--- /dev/null
+++ clang/lib/Interpreter/ValuePrinter.cpp
@@ -0,0 +1,528 @@
+#include "ASTHelpers.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/Type.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Interpreter/Interpreter.h"
+#include "clang/Interpreter/Value.h"
+#include "clang/Parse/Parser.h"
+#include "clang/Sema/Lookup.h"
+#include "clang/Sema/Sema.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+
+using namespace clang;
+
+static std::string PrintDeclType(const QualType &QT, NamedDecl *D) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  if (QT.hasQualifiers())
+SS << QT.getQualifiers().getAsString() << " ";
+  SS << D->getQualifiedNameAsString();
+  return Str;
+}
+
+static std::string PrintQualType(ASTContext &Ctx, QualType QT) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+  PrintingPolicy Policy(Ctx.getPrintingPolicy());
+  // Print the Allocator in STL containers, for instance.
+  Policy.SuppressDefaultTemplateArgs = false;
+  Policy.SuppressUnwrittenScope = true;
+  // Print 'a >' rather than 'a>'.
+  Policy.SplitTemplateClosers = true;
+
+  class LocalPrintingPolicyRAII {
+  public:
+LocalPrintingPolicyRAII(ASTContext &Ctx, PrintingPolicy &PPol)
+: Context(Ctx), Policy(Ctx.getPrintingPolicy()) {
+  Context.setPrintingPolicy(PPol);
+}
+~LocalPrintingPolicyRAII() { Context.setPrintingPolicy(Policy); }
+
+  private:
+ASTContext &Context;
+PrintingPolicy Policy;
+  } X(Ctx, Policy);
+
+  const QualType NonRefTy = QT.getNonReferenceType();
+
+  if (const auto *TTy = llvm::dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TTy->getDecl());
+  else if (const auto *TRy = dyn_cast(NonRefTy))
+SS << PrintDeclType(NonRefTy, TRy->getDecl());
+  else {
+const QualType Canon = NonRefTy.getCanonicalType();
+if (Canon->isBuiltinType() && !NonRefTy->isFunctionPointerType() &&
+!NonRefTy->isMemberPointerType()) {
+  SS << Canon.getAsString(Ctx.getPrintingPolicy());
+} else if (const auto *TDTy = dyn_cast(NonRefTy)) {
+  // FIXME: TemplateSpecializationType & SubstTemplateTypeParmType checks
+  // are predominately to get STL containers to print nicer and might be
+  // better handled in GetFullyQualifiedName.
+  //
+  // std::vector::iterator is a TemplateSpecializationType
+  // std::vector::value_type is a SubstTemplateTypeParmType
+  //
+  QualType SSDesugar = TDTy->getLocallyUnqualifiedSingleStepDesugaredType();
+  if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, Canon);
+  else if (llvm::isa(SSDesugar))
+SS << GetFullTypeName(Ctx, NonRefTy);
+  else
+SS << PrintDeclType(NonRefTy, TDTy->getDecl());

[PATCH] D146595: [clang] Add clang trampoline_mangled_target attribute

2023-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/Basic/Attr.td:776
+  let Subjects = SubjectList<[Function, ObjCMethod]>;
+  let Args = [StringArgument<"Name">];
+  let Documentation = [TrampolineDocs];

augusto2112 wrote:
> aaron.ballman wrote:
> > This is quite fragile, for a few reasons.
> > 
> > 1) It's too easy for the user to get undiagnosed typos. e.g., they want to 
> > dispatch to `bar` but accidentally dispatch to `barf` or `bar()` instead.
> > 2) How does this work with overloaded functions? Templated functions with 
> > specializations?
> > 
> > It seems to me that this should be accepting an Expr argument that's either 
> > a `CallExpr`/`MemberCallExpr` or is a `DeclRefExpr` that names a function, 
> > so you could do:
> > 
> > ```
> > void bar();
> > void baz(int), baz(float);
> > 
> > __attribute__((trampoline(bar))) void foo() { bar(); }
> > // or
> > __attribute__((trampoline(baz(12))) void foo() { baz(12); }
> > ```
> > 
> > That said, this is still fragile in that it's easy to write the attribute 
> > and then the function body drifts out of sync with the attribute over time. 
> > Given that this only impacts debug information, that sort of latent issue 
> > is likely to hide in the code for a long time. Should we consider a warning 
> > if the function named by the attribute is not called within the function 
> > carrying the attribute?
> I understand the concerns you brought up as I didn't make it clear initially 
> that this isn't supposed to be used by users, but meant to be used in 
> compiler generated code. Given that, do you still think this should be an 
> `Expr`? I think that'd be more error prone for tools to generate the correct 
> C++ code to write, when compared with the mangled name.
Hyrem's law exists, and attributes are the proof of that one :)  Anything we 
provide in the attributes list gets used by users SOMEWHERE, and we need to do 
what we can to not have our interface be user hostile.

Also, this means that whatever code is generated needs to have the same mangled 
name... and then doesn't this get defeated by the inliner?  Can you name 
something that will later be removed?  What if you're naming something without 
linkage?



Comment at: clang/include/clang/Basic/AttrDocs.td:6923
+
+Indicates to debuggers that stepping into ``foo`` should jump directly to 
``bar`` instead.
+  }];

I'm sure there is a compelling reason here, but if I ever saw this happen in a 
debugger, I'd get very confused.



Comment at: clang/lib/Sema/SemaDeclAttr.cpp:6775
 
+static void handleTrampolineMangledTarget(Sema &S, Decl *D,
+  const ParsedAttr &AL) {

I don't see anything for instantiating this in a template? As it is, I think 
this attribute will be dropped if on a primary template. What about dependent 
arguments?

Should we prevent this from being placed on function templates?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146595

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


[PATCH] D146801: [clang] Fix consteval initializers of temporaries

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

The changes LGTM (though I had a small nit), but you should add a release note 
when landing.




Comment at: clang/lib/Sema/SemaExprCXX.cpp:1593-1595
+  if (ConstantExpr *CE = dyn_cast_or_null(Inner))
+if (CE->isImmediateInvocation())
+  Inner = CE->getSubExpr();

This will need reformatting, but because we can use C++17 features, we can be 
slightly fancier here. :-)

NB: I think we don't need to use `dyn_cast_or_null` here or on the predicate 
above. We're calling `isa(Inner)` immediately below and that will 
assert if `Inner` was null, so it seems like we're already relying on `Inner` 
being nonnull.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146801

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


[PATCH] D146784: [clang] Test for AST Dumping of the template variables

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508076.
tomasz-kaminski-sonarsource added a comment.

Added FIXME


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

Files:
  clang/test/AST/ast-dump-template-decls.cpp


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
@@ -1,12 +1,12 @@
 // Test without serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -ast-dump %s \
-// RUN: | FileCheck -strict-whitespace %s
+// RUN: | FileCheck -strict-whitespace %s --check-prefix=DIRECT
 //
 // Test with serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -x c++ -std=c++17 -triple x86_64-unknown-unknown 
-include-pch %t -ast-dump-all /dev/null \
 // RUN: | sed -e "s/ //" -e "s/ imported//" \
-// RUN: | FileCheck --strict-whitespace %s
+// RUN: | FileCheck --strict-whitespace %s --check-prefix=SERIALIZED
 
 template 
 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <{{.*}}:1, line:[[@LINE+2]]:10> 
col:6 a
@@ -178,3 +178,80 @@
 // CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A'
 // CHECK-NEXT:   `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
 } // namespace subst_default_argument
+
+namespace D146733 {
+template
+T unTempl = 1;
+// CHECK:VarTemplateDecl 0x{{[^ ]*}}  
col:3 unTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 unTempl 
'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int unTempl;
+// FIXME - serializing and loading AST should not affect reported source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float unTempl = 1;
+// FIXME - serializing and loading AST should not affect reported source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+T binTempl = 1;
+// CHECK:  VarTemplateDecl 0x{{[^ ]*}}  col:3 binTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  col:25 
class depth 0 index 1 U
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 
binTempl 'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+int binTempl;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} 
 col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' 
dependent depth 0 index 0
+
+template
+float binTempl = 1;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} 
 col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: | `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' 
dependent depth 0 index 0
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int binTempl;
+// FIXME - serializing and loading AST should not affect reported source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float binTempl = 1;
+// FIXME - serializing and loading AST should not affect reported source range
+// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-Builti

[PATCH] D146784: [clang] Test for AST Dumping of the template variables

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added inline comments.



Comment at: clang/test/AST/ast-dump-template-decls.cpp:193
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'

erichkeane wrote:
> Hmm... thats curious.  We shouldn't commit this unless there is a 'fixme' on 
> it showing we don't really mean it, but in reality, this just deserves a 
> Github bug.
Will add a FIXME. Feel free to create a GitHub bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508077.
tomasz-kaminski-sonarsource added a comment.

Including release note


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp

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
@@ -197,9 +197,7 @@
 
 template<>
 float unTempl = 1;
-// FIXME - serializing and loading AST should not affect reported source range
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
@@ -245,9 +243,7 @@
 
 template<>
 float binTempl = 1;
-// FIXME - serializing and loading AST should not affect reported source range
-// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: |-TemplateArgument type 'float'
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 //===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 //===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -225,6 +225,8 @@
   enabling short-circuiting coroutines use cases. This fixes
   (`#56532 `_) in
   antecipation of `CWG2563 _`.
+- Fix  ``getSourceRange`` behavior on  ``VarTemplateSpecializationDecl``
+  and ``VarTemplatePartialSpecializationDecl``, that represents variable

[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:228
   antecipation of `CWG2563 
_`.
+- Fix  ``getSourceRange`` behavior on  ``VarTemplateSpecializationDecl``
+  and ``VarTemplatePartialSpecializationDecl``, that represents variable with 
initializer.

Needs a little more detail here.  Something about what was wrong before, and 
what is wrong now, particularly since there is no github bug to link to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D141497: [clang][Interp] Record initialization via conditional operator

2023-03-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.h:182-183
 
+  template 
+  bool visitConditional(const AbstractConditionalOperator *E, VisitFn V);
+

tbaeder wrote:
> aaron.ballman wrote:
> > The template definition isn't available within the header file, so this is 
> > fragile (impossible to instantiate from anything but ByteCodeExprGen.cpp).
> What's the alternative? If I make it a static function in 
> `ByteCodeExprGen.cpp`, I'd have to make a lot of members of `ByteCodeEmitter` 
> etc. public which  is not a very clean solution. Moving the definition into 
> the header file isn't very nice either, all the others are in the source file.
What about making it a static template in `ByteCodeExprGen.cpp`, but make it a 
'friend' here?  I think that would work, wouldn't it?  Something like: 
https://godbolt.org/z/ofYbGvfYa

You unfortunately cannot make it static, but as it is a template, at least it 
is inline.  WDYT?


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

https://reviews.llvm.org/D141497

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


[PATCH] D146784: [clang] Test for AST Dumping of the template variables

2023-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/AST/ast-dump-template-decls.cpp:193
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'

tomasz-kaminski-sonarsource wrote:
> erichkeane wrote:
> > Hmm... thats curious.  We shouldn't commit this unless there is a 'fixme' 
> > on it showing we don't really mean it, but in reality, this just deserves a 
> > Github bug.
> Will add a FIXME. Feel free to create a GitHub bug.
More test coverage is usually a good thing, but in this case, I'd prefer we 
either fixed the issue or filed a bug (having a test file with a FIXME comment 
but no issue basically means the issue will be ignored forever in practice, so 
we're running a test with very little benefit beyond verifying there's not a 
crash).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508081.
tomasz-kaminski-sonarsource added a comment.

Updated release note to be more descriptive.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp

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
@@ -197,9 +197,7 @@
 
 template<>
 float unTempl = 1;
-// FIXME - serializing and loading AST should not affect reported source range
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
@@ -245,9 +243,7 @@
 
 template<>
 float binTempl = 1;
-// FIXME - serializing and loading AST should not affect reported source range
-// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: |-TemplateArgument type 'float'
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 //===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 //===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -225,6 +225,11 @@
   enabling short-circuiting coroutines use cases. This fixes
   (`#56532 `_) in
   antecipation of `CWG2563 _`.
+- Fix  ``getSourceRange`` on  ``VarTemplateSpecializationDecl`` and
+  ``VarTemplatePartialSpecializationDecl``, which repr

[PATCH] D145584: [libc] Add support for setjmp and longjmp in riscv

2023-03-24 Thread Mikhail Ramalho via Phabricator via cfe-commits
mikhail.ramalho added inline comments.



Comment at: libc/src/setjmp/riscv64/longjmp.cpp:54-55
+
+  LIBC_INLINE_ASM("seqz %0, %1" : "+r"(buf) : "r"(val) :);
+  LIBC_INLINE_ASM("add %0, %0, %1" : "+r"(buf) : "r"(val), "r"(buf) :);
+}

sivachandra wrote:
> Your comment is in the previous diff but thanks for the explanation. I think 
> we have missed the `val` check for zero in the x86_64 case and should be 
> fixed separately.
> 
> For the above two instructions, in the interest of reducing the amount of 
> logic in inline assembly, can we do:
> 
> ```
>   val = val == 0 ? 1 : val;
>   LIBC_INLINE_ASM("add a0, %0, zero\n\t" : : "r"(val) :);
> ```
> Your comment is in the previous diff but thanks for the explanation. I think 
> we have missed the `val` check for zero in the x86_64 case and should be 
> fixed separately.

no problem, do you want me to fix the x86_64 version?

> 
> For the above two instructions, in the interest of reducing the amount of 
> logic in inline assembly, can we do:
> 
> ```
>   val = val == 0 ? 1 : val;
>   LIBC_INLINE_ASM("add a0, %0, zero\n\t" : : "r"(val) :);
> ```

Done, I'll rerun the tests now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145584

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


[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-03-24 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D146764#4219278 , @hans wrote:

> +mstorsjo is this okay for mingw mode too?

I believe the current form of the patch is fine - i.e. disabled by default in 
mingw mode, but enabled if the extra MS language extensions are enabled. (I 
didn't check myself how those options map to `LangOpts.MicrosoftExt` but I 
presume it works as I described above.)




Comment at: clang/include/clang/Testing/TestClangConfig.h:61
 
-  bool hasDelayedTemplateParsing() const {
-return Target == "x86_64-pc-win32-msvc";
-  }
+  bool isWin32() const { return Target == "x86_64-pc-win32-msvc"; }
+

I'm not entirely sure of the use context of this function (only specific 
tests?), but mingw targets with a differen triple are win32 too. But then they 
could also be using an entirely different architecture than x86_64, so I guess 
this might be ok too if we're ready to tweak it when a need arises?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


[PATCH] D146788: [clang][Interp] Fix zero-initializing of floating types

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

LGTM with a suggestion.




Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1076-1081
+  case PT_Float: {
+const auto &Sem = Ctx.getASTContext().getFloatTypeSemantics(E->getType());
+
+APFloat Val(Sem);
+return this->emitConstFloat(Val, E);
+  }

Desperately needs reformatting, but can do this in a one-liner that's actually 
a bit more clear.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146788

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 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.

LGTM!  Let me know if you need someone to commit this for you, and include 
"Name To Use "


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

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


[PATCH] D146801: [clang] Fix consteval initializers of temporaries

2023-03-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 508082.
Fznamznon added a comment.

Apply the suggestion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146801

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1050,3 +1050,18 @@
 
 }
 }
+
+namespace GH60286 {
+
+struct A {
+  int i = 0;
+
+  consteval A() {}
+  A(const A&) { i = 1; }
+  consteval int f() { return i; }
+};
+
+constexpr auto B = A{A{}}.f();
+static_assert(B == 0);
+
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1590,6 +1590,9 @@
   Expr *Inner = Result.get();
   if (CXXBindTemporaryExpr *BTE = 
dyn_cast_or_null(Inner))
 Inner = BTE->getSubExpr();
+  if (auto *CE = dyn_cast(Inner);
+  CE && CE->isImmediateInvocation())
+Inner = CE->getSubExpr();
   if (!isa(Inner) &&
   !isa(Inner)) {
 // If we created a CXXTemporaryObjectExpr, that node also represents the
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -229,6 +229,9 @@
   antecipation of `CWG2563 
_`.
 - Fix highlighting issue with ``_Complex`` and initialization list with more 
than
   2 items. (`#61518 `_)
+- Fix false-positive diagnostic issued for consteval initializers of temporary
+  objects.
+  (`#60286 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1050,3 +1050,18 @@
 
 }
 }
+
+namespace GH60286 {
+
+struct A {
+  int i = 0;
+
+  consteval A() {}
+  A(const A&) { i = 1; }
+  consteval int f() { return i; }
+};
+
+constexpr auto B = A{A{}}.f();
+static_assert(B == 0);
+
+}
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -1590,6 +1590,9 @@
   Expr *Inner = Result.get();
   if (CXXBindTemporaryExpr *BTE = dyn_cast_or_null(Inner))
 Inner = BTE->getSubExpr();
+  if (auto *CE = dyn_cast(Inner);
+  CE && CE->isImmediateInvocation())
+Inner = CE->getSubExpr();
   if (!isa(Inner) &&
   !isa(Inner)) {
 // If we created a CXXTemporaryObjectExpr, that node also represents the
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -229,6 +229,9 @@
   antecipation of `CWG2563 _`.
 - Fix highlighting issue with ``_Complex`` and initialization list with more than
   2 items. (`#61518 `_)
+- Fix false-positive diagnostic issued for consteval initializers of temporary
+  objects.
+  (`#60286 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146801: [clang] Fix consteval initializers of temporaries

2023-03-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:1593-1595
+  if (ConstantExpr *CE = dyn_cast_or_null(Inner))
+if (CE->isImmediateInvocation())
+  Inner = CE->getSubExpr();

aaron.ballman wrote:
> This will need reformatting, but because we can use C++17 features, we can be 
> slightly fancier here. :-)
> 
> NB: I think we don't need to use `dyn_cast_or_null` here or on the predicate 
> above. We're calling `isa(Inner)` immediately below and that will 
> assert if `Inner` was null, so it seems like we're already relying on `Inner` 
> being nonnull.
That makes sense, thank you.
Although, I can't make `CE` const because `Inner` is not `const`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146801

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


[PATCH] D146655: [clang-tidy] Ignore DISABLED_ in test suite name in google-avoid-underscore-in-googletest-name

2023-03-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:237
 
+- Fixed an issue in :doc:`google-avoid-underscore-in-googletest-name
+  ` when using

carlosgalvezp wrote:
> Eugene.Zelenko wrote:
> > carlosgalvezp wrote:
> > > Eugene.Zelenko wrote:
> > > > Eugene.Zelenko wrote:
> > > > > carlosgalvezp wrote:
> > > > > > PiotrZSL wrote:
> > > > > > > carlosgalvezp wrote:
> > > > > > > > Eugene.Zelenko wrote:
> > > > > > > > > Please keep alphabetical order (by check name) in this 
> > > > > > > > > section.
> > > > > > > > I was planning to do that but noticed that the alphabetical 
> > > > > > > > order is already broken. It seems to be a source of friction 
> > > > > > > > and there's no official documentation that states it should be 
> > > > > > > > done like that, so I can understand if it gets broken often. Do 
> > > > > > > > you know if this is documented somewhere? If not, do we see 
> > > > > > > > value in keeping this convention? I suppose now we would need 
> > > > > > > > an NFC patch to fix the order again, causing churn.
> > > > > > > I run into same issue also. I would say, let leave it as it is, 
> > > > > > > and fix it with one commit at the end of release.
> > > > > > Good idea, let's do that!
> > > > > Often it's also broken after rebases which may be automatic.
> > > > Anyway, some kind of order is much better than disorder.
> > > Definitely. Could we stick to some simple convention? For example always 
> > > append or prepend to the list of modifications to checks. Then before 
> > > release we put up a patch for reordering.
> > I think it will be harder to reader. Sorting by check name is much better 
> > in this respect. And this was used in many releases.
> To clarify, what I mean is:
> 
> - Apply a simple convention (e.g. append or prepend to the list) //while 
> developing//.
> - Right before creating a release, put up a patch to sort alphabetically. 
> Then it will be easy to read for users when it's released.
> 
> Or do you mean that the list shall be alphabetically sorted at all times?
It'll be much easier to sort partially sorted list at release time than 
completely unsorted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146655

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


[PATCH] D146801: [clang] Fix consteval initializers of temporaries

2023-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:1593-1595
+  if (ConstantExpr *CE = dyn_cast_or_null(Inner))
+if (CE->isImmediateInvocation())
+  Inner = CE->getSubExpr();

Fznamznon wrote:
> aaron.ballman wrote:
> > This will need reformatting, but because we can use C++17 features, we can 
> > be slightly fancier here. :-)
> > 
> > NB: I think we don't need to use `dyn_cast_or_null` here or on the 
> > predicate above. We're calling `isa(Inner)` immediately below and 
> > that will assert if `Inner` was null, so it seems like we're already 
> > relying on `Inner` being nonnull.
> That makes sense, thank you.
> Although, I can't make `CE` const because `Inner` is not `const`.
Ah, that's fine, no worries about the `const` then. That suggestion is mostly a 
reflex for me at this point. :-D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146801

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


[PATCH] D146784: [clang] Test for AST Dumping of the template variables

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added a comment.

This is now tracked as https://github.com/llvm/llvm-project/issues/61680. Let 
me know if I should refer it in the test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

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


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

2023-03-24 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill updated this revision to Diff 508086.
Endill added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144115

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Lex/Pragma.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/test/AST/ast-dump-lookups.cpp

Index: clang/test/AST/ast-dump-lookups.cpp
===
--- clang/test/AST/ast-dump-lookups.cpp
+++ clang/test/AST/ast-dump-lookups.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 -ast-dump -ast-dump-filter Test %s | FileCheck -check-prefix DECLS %s
 // RUN: %clang_cc1 -std=c++11 -ast-dump-lookups -ast-dump-filter Test %s | FileCheck -check-prefix LOOKUPS %s
 // RUN: %clang_cc1 -std=c++11 -ast-dump -ast-dump-lookups -ast-dump-filter Test %s | FileCheck -check-prefix DECLS-LOOKUPS %s
-// RUN: %clang_cc1 -std=c++11 -DPRAGMA -fsyntax-only %s 2>&1 | FileCheck -check-prefix PRAGMA %s
+// RUN: %clang_cc1 -std=c++11 -DPRAGMA -fsyntax-only -verify %s 2>&1 | FileCheck -check-prefix PRAGMA %s
 
 namespace Test {
   typedef int T;
@@ -51,3 +51,50 @@
 //
 // DECLS-LOOKUPS: Dumping Test:
 // DECLS-LOOKUPS-NEXT: Lookup map is in primary DeclContext
+
+#ifdef PRAGMA
+namespace Test {
+  struct S {
+const S& operator+(const S&) { return *this; }
+  };
+  void foo(S) {}
+}
+
+#pragma clang __debug dump foo(Test::S{})
+// PRAGMA: CallExpr {{.*}} adl
+// PRAGMA-NEXT: |-ImplicitCastExpr {{.*}}
+// PRAGMA-NEXT: | `-DeclRefExpr {{.*}} 'void (S)' lvalue Function {{.*}} 'foo' 'void (S)'
+
+#pragma clang __debug dump Test::S{} + Test::S{}
+// PRAGMA: CXXOperatorCallExpr {{.*}}
+// PRAGMA-NEXT: |-ImplicitCastExpr {{.*}}
+// PRAGMA-NEXT: | `-DeclRefExpr {{.*}} 'const S &(const S &)' lvalue CXXMethod {{.*}} 'operator+' 'const S &(const S &)'
+
+#pragma clang __debug dump &Test::S::operator+
+// PRAGMA: UnaryOperator {{.*}}
+// PRAGMA-NEXT: `-DeclRefExpr {{.*}} 'const S &(const S &)' CXXMethod {{.*}} 'operator+' 'const S &(const S &)'
+
+template
+void bar() {
+#pragma clang __debug dump T{} // expected-warning {{type-dependent expression}}
+#pragma clang __debug dump +I  // expected-warning {{value-dependent expression}}
+}
+
+template 
+struct S {
+  static constexpr const T *str = "string";
+};
+
+template <>
+struct S {
+  static constexpr const wchar_t *str = L"wide string";
+};
+
+void func() {
+  #pragma clang __debug dump S::str;
+  // PRAGMA: DeclRefExpr {{.*}} 'const wchar_t *const' lvalue Var {{.*}} 'str' 'const wchar_t *const'
+}
+
+#pragma clang __debug dump this is nonsense // expected-error {{invalid use of 'this'}}
+
+#endif
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -5841,3 +5841,7 @@
   LookupName(R, S);
   R.dump();
 }
+
+void Sema::ActOnPragmaDump(Expr *E) {
+  E->dump();
+}
Index: clang/lib/Parse/ParsePragma.cpp
===
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -706,10 +706,36 @@
 
 void Parser::HandlePragmaDump() {
   assert(Tok.is(tok::annot_pragma_dump));
-  IdentifierInfo *II =
-  reinterpret_cast(Tok.getAnnotationValue());
-  Actions.ActOnPragmaDump(getCurScope(), Tok.getLocation(), II);
   ConsumeAnnotationToken();
+  if (Tok.is(tok::eod)) {
+PP.Diag(Tok, diag::warn_pragma_debug_missing_argument) << "dump";
+  } else if (NextToken().is(tok::eod)) {
+if (Tok.isNot(tok::identifier)) {
+  PP.Diag(Tok, diag::warn_pragma_debug_unexpected_argument);
+  ConsumeAnyToken();
+  ExpectAndConsume(tok::eod);
+  return;
+}
+IdentifierInfo *II = Tok.getIdentifierInfo();
+Actions.ActOnPragmaDump(getCurScope(), Tok.getLocation(), II);
+ConsumeToken();
+  } else {
+SourceLocation StartLoc = Tok.getLocation();
+EnterExpressionEvaluationContext Ctx(
+  Actions, Sema::ExpressionEvaluationContext::Unevaluated);
+ExprResult E = ParseExpression();
+if (!E.isUsable() || E.get()->containsErrors()) {
+  // Diagnostics were emitted during parsing. No action needed.
+} else if (E.get()->getDependence() != ExprDependence::None) {
+  PP.Diag(StartLoc, diag::warn_pragma_debug_dependent_argument)
+<< E.get()->isTypeDependent()
+<< SourceRange(StartLoc, Tok.getLocation());
+} else {
+  Actions.ActOnPragmaDump(E.get());
+}
+SkipUntil(tok::eod, StopBeforeMatch);
+  }
+  ExpectAndConsume(tok::eod);
 }
 
 void Parser::HandlePragmaWeak() {
Index: clang/lib/Lex/Pragma.cpp
===
--- clang/lib/Lex/P

[PATCH] D146784: [clang] Test for AST Dumping of the template variables

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

In D146784#4219469 , 
@tomasz-kaminski-sonarsource wrote:

> This is now tracked as https://github.com/llvm/llvm-project/issues/61680. Let 
> me know if I should refer it in the test.

Thanks, the issue LG! Let's go ahead and mention it here in the test so it's 
clear this test relates to that issue. LGTM with that handled.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

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


[PATCH] D146784: [clang] Test for AST Dumping of the template variables

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508088.
tomasz-kaminski-sonarsource added a comment.

Updated FIXME with GitHub bug reference.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

Files:
  clang/test/AST/ast-dump-template-decls.cpp


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
@@ -1,12 +1,12 @@
 // Test without serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -ast-dump %s \
-// RUN: | FileCheck -strict-whitespace %s
+// RUN: | FileCheck -strict-whitespace %s --check-prefix=DIRECT
 //
 // Test with serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -x c++ -std=c++17 -triple x86_64-unknown-unknown 
-include-pch %t -ast-dump-all /dev/null \
 // RUN: | sed -e "s/ //" -e "s/ imported//" \
-// RUN: | FileCheck --strict-whitespace %s
+// RUN: | FileCheck --strict-whitespace %s --check-prefix=SERIALIZED
 
 template 
 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <{{.*}}:1, line:[[@LINE+2]]:10> 
col:6 a
@@ -178,3 +178,80 @@
 // CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A'
 // CHECK-NEXT:   `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
 } // namespace subst_default_argument
+
+namespace D146733 {
+template
+T unTempl = 1;
+// CHECK:VarTemplateDecl 0x{{[^ ]*}}  
col:3 unTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 unTempl 
'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int unTempl;
+// FIXME (#61680) - serializing and loading AST should not affect reported 
source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float unTempl = 1;
+// FIXME (#61680) - serializing and loading AST should not affect reported 
source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+T binTempl = 1;
+// CHECK:  VarTemplateDecl 0x{{[^ ]*}}  col:3 binTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  col:25 
class depth 0 index 1 U
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 
binTempl 'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+int binTempl;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} 
 col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' 
dependent depth 0 index 0
+
+template
+float binTempl = 1;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} 
 col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: | `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' 
dependent depth 0 index 0
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int binTempl;
+// FIXME (#61680) - serializing and loading AST should not affect reported 
source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float binTempl = 1;
+// FIXME (#61680) - serializing and loading AST should not affect reported 
source range
+// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// C

[PATCH] D146784: [clang] Test for AST Dumping of the template variables

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508091.
tomasz-kaminski-sonarsource added a comment.

Rebased on updated test commit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp

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
@@ -1,12 +1,12 @@
 // Test without serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -ast-dump %s \
-// RUN: | FileCheck -strict-whitespace %s
+// RUN: | FileCheck -strict-whitespace %s --check-prefix=DIRECT
 //
 // Test with serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -x c++ -std=c++17 -triple x86_64-unknown-unknown -include-pch %t -ast-dump-all /dev/null \
 // RUN: | sed -e "s/ //" -e "s/ imported//" \
-// RUN: | FileCheck --strict-whitespace %s
+// RUN: | FileCheck --strict-whitespace %s --check-prefix=SERIALIZED
 
 template 
 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <{{.*}}:1, line:[[@LINE+2]]:10> col:6 a
@@ -178,3 +178,76 @@
 // CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A'
 // CHECK-NEXT:   `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
 } // namespace subst_default_argument
+
+namespace D146733 {
+template
+T unTempl = 1;
+// CHECK:VarTemplateDecl 0x{{[^ ]*}}  col:3 unTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 unTempl 'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int unTempl;
+// FIXME (#61680) - serializing and loading AST should not affect reported source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float unTempl = 1;
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+T binTempl = 1;
+// CHECK:  VarTemplateDecl 0x{{[^ ]*}}  col:3 binTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  col:25 class depth 0 index 1 U
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 binTempl 'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+int binTempl;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' dependent depth 0 index 0
+
+template
+float binTempl = 1;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: | `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' dependent depth 0 index 0
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int binTempl;
+// FIXME (#61680) - serializing and loading AST should not affect reported source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float binTempl = 1;
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+}
Index: clang/lib/AST/DeclTemplate.cpp

[clang] 467ed27 - [clang] Extend pragma dump to support expressions

2023-03-24 Thread Vlad Serebrennikov via cfe-commits

Author: Vlad Serebrennikov
Date: 2023-03-24T17:35:35+03:00
New Revision: 467ed2798772344e2a3b4a8d368575f1f9d1a8c6

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

LOG: [clang] Extend pragma dump to support expressions

Extend `#pragma clang __debug dump` to support not only single identifier, but 
an expression as well. This makes it possible to test ADL and overload 
resolution directly, without being creative to make them observable via 
diagnostics (e.g. when [[ http://eel.is/c++draft/over.match.best | 
over.match.best ]] is involved). This implementation has a known limitation of 
not supporting dependent expressions properly, but it's quite useful even 
without such support.

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

Added: 


Modified: 
clang/docs/LanguageExtensions.rst
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Lex/Pragma.cpp
clang/lib/Parse/ParsePragma.cpp
clang/lib/Sema/SemaLookup.cpp
clang/test/AST/ast-dump-lookups.cpp

Removed: 




diff  --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index b68d44e75e9b5..cda08066c6ab2 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -4917,3 +4917,21 @@ The following x86-specific intrinsics can be used in 
constant expressions:
 * ``_rotwr``
 * ``_lrotl``
 * ``_lrotr``
+
+Debugging the Compiler
+==
+
+Clang supports a number of pragma directives that help debugging the compiler 
itself.
+Syntax is the following: `#pragma clang __debug  `.
+Note, all of debugging pragmas are subject to change.
+
+`dump`
+--
+Accepts either a single identifier or an expression. When a single identifier 
is passed,
+the lookup results for the identifier are printed to `stderr`. When an 
expression is passed, 
+the AST for the expression is printed to `stderr`. The expression is an 
unevaluated operand,
+so things like overload resolution and template instantiations are performed,
+but the expression has no runtime effects.
+Type- and value-dependent expressions are not supported yet.
+
+This facility is designed to aid with testing name lookup machinery.

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 29e3f516c06e5..526ea11303708 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -126,6 +126,7 @@ Non-comprehensive list of changes in this release
   from the invocation point, with no path components included).
 - Clang now supports ``__builtin_assume_separate_storage`` that indicates that
   its arguments point to objects in separate storage allocations.
+- Clang now supports expressions in ``#pragma clang __debug dump``.
 
 New Compiler Flags
 --

diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 9b8103c97e39c..f574b0f0171b7 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -63,6 +63,10 @@ def err_invalid_character_udl : Error<
   "character literal with user-defined suffix cannot be used here">;
 def err_invalid_numeric_udl : Error<
   "numeric literal with user-defined suffix cannot be used here">;
+def warn_pragma_debug_missing_argument : Warning<
+  "missing argument to debug command '%0'">, InGroup;
+def warn_pragma_debug_unexpected_argument : Warning<
+  "unexpected argument to debug command">, InGroup;
 
 }
 

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index fbb08a6f761be..b77c19b816d86 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -655,10 +655,6 @@ def warn_pragma_debug_missing_command : Warning<
   "missing debug command">, InGroup;
 def warn_pragma_debug_unexpected_command : Warning<
   "unexpected debug command '%0'">, InGroup;
-def warn_pragma_debug_missing_argument : Warning<
-  "missing argument to debug command '%0'">, InGroup;
-def warn_pragma_debug_unexpected_argument : Warning<
-  "unexpected argument to debug command">, InGroup;
 def warn_pragma_debug_unknown_module : Warning<
   "unknown module '%0'">, InGroup;
 // #pragma module

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 2ad4d98f0ed88..929ba9e3287ef 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1300,6 +1300,10 @@ def note_pragma_attribute_namespace_on

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

2023-03-24 Thread Vlad Serebrennikov 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 rG467ed2798772: [clang] Extend pragma dump to support 
expressions (authored by Endill).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144115

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Lex/Pragma.cpp
  clang/lib/Parse/ParsePragma.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/test/AST/ast-dump-lookups.cpp

Index: clang/test/AST/ast-dump-lookups.cpp
===
--- clang/test/AST/ast-dump-lookups.cpp
+++ clang/test/AST/ast-dump-lookups.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -std=c++11 -ast-dump -ast-dump-filter Test %s | FileCheck -check-prefix DECLS %s
 // RUN: %clang_cc1 -std=c++11 -ast-dump-lookups -ast-dump-filter Test %s | FileCheck -check-prefix LOOKUPS %s
 // RUN: %clang_cc1 -std=c++11 -ast-dump -ast-dump-lookups -ast-dump-filter Test %s | FileCheck -check-prefix DECLS-LOOKUPS %s
-// RUN: %clang_cc1 -std=c++11 -DPRAGMA -fsyntax-only %s 2>&1 | FileCheck -check-prefix PRAGMA %s
+// RUN: %clang_cc1 -std=c++11 -DPRAGMA -fsyntax-only -verify %s 2>&1 | FileCheck -check-prefix PRAGMA %s
 
 namespace Test {
   typedef int T;
@@ -51,3 +51,50 @@
 //
 // DECLS-LOOKUPS: Dumping Test:
 // DECLS-LOOKUPS-NEXT: Lookup map is in primary DeclContext
+
+#ifdef PRAGMA
+namespace Test {
+  struct S {
+const S& operator+(const S&) { return *this; }
+  };
+  void foo(S) {}
+}
+
+#pragma clang __debug dump foo(Test::S{})
+// PRAGMA: CallExpr {{.*}} adl
+// PRAGMA-NEXT: |-ImplicitCastExpr {{.*}}
+// PRAGMA-NEXT: | `-DeclRefExpr {{.*}} 'void (S)' lvalue Function {{.*}} 'foo' 'void (S)'
+
+#pragma clang __debug dump Test::S{} + Test::S{}
+// PRAGMA: CXXOperatorCallExpr {{.*}}
+// PRAGMA-NEXT: |-ImplicitCastExpr {{.*}}
+// PRAGMA-NEXT: | `-DeclRefExpr {{.*}} 'const S &(const S &)' lvalue CXXMethod {{.*}} 'operator+' 'const S &(const S &)'
+
+#pragma clang __debug dump &Test::S::operator+
+// PRAGMA: UnaryOperator {{.*}}
+// PRAGMA-NEXT: `-DeclRefExpr {{.*}} 'const S &(const S &)' CXXMethod {{.*}} 'operator+' 'const S &(const S &)'
+
+template
+void bar() {
+#pragma clang __debug dump T{} // expected-warning {{type-dependent expression}}
+#pragma clang __debug dump +I  // expected-warning {{value-dependent expression}}
+}
+
+template 
+struct S {
+  static constexpr const T *str = "string";
+};
+
+template <>
+struct S {
+  static constexpr const wchar_t *str = L"wide string";
+};
+
+void func() {
+  #pragma clang __debug dump S::str;
+  // PRAGMA: DeclRefExpr {{.*}} 'const wchar_t *const' lvalue Var {{.*}} 'str' 'const wchar_t *const'
+}
+
+#pragma clang __debug dump this is nonsense // expected-error {{invalid use of 'this'}}
+
+#endif
Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -5841,3 +5841,7 @@
   LookupName(R, S);
   R.dump();
 }
+
+void Sema::ActOnPragmaDump(Expr *E) {
+  E->dump();
+}
Index: clang/lib/Parse/ParsePragma.cpp
===
--- clang/lib/Parse/ParsePragma.cpp
+++ clang/lib/Parse/ParsePragma.cpp
@@ -706,10 +706,36 @@
 
 void Parser::HandlePragmaDump() {
   assert(Tok.is(tok::annot_pragma_dump));
-  IdentifierInfo *II =
-  reinterpret_cast(Tok.getAnnotationValue());
-  Actions.ActOnPragmaDump(getCurScope(), Tok.getLocation(), II);
   ConsumeAnnotationToken();
+  if (Tok.is(tok::eod)) {
+PP.Diag(Tok, diag::warn_pragma_debug_missing_argument) << "dump";
+  } else if (NextToken().is(tok::eod)) {
+if (Tok.isNot(tok::identifier)) {
+  PP.Diag(Tok, diag::warn_pragma_debug_unexpected_argument);
+  ConsumeAnyToken();
+  ExpectAndConsume(tok::eod);
+  return;
+}
+IdentifierInfo *II = Tok.getIdentifierInfo();
+Actions.ActOnPragmaDump(getCurScope(), Tok.getLocation(), II);
+ConsumeToken();
+  } else {
+SourceLocation StartLoc = Tok.getLocation();
+EnterExpressionEvaluationContext Ctx(
+  Actions, Sema::ExpressionEvaluationContext::Unevaluated);
+ExprResult E = ParseExpression();
+if (!E.isUsable() || E.get()->containsErrors()) {
+  // Diagnostics were emitted during parsing. No action needed.
+} else if (E.get()->getDependence() != ExprDependence::None) {
+  PP.Diag(StartLoc, diag::warn_pragma_debug_dependent_argument)
+<< E.get()->isTypeDependent()
+<< SourceRange(StartLoc, Tok.getLocation());
+} else {
+  Actions.ActOnPragmaDump(E.get());
+}
+SkipUntil(tok::eod, StopBeforeMatch);
+  }
+  ExpectAndConsume(tok::eod);
 

[PATCH] D146802: [Documentation] improved documentation of diagnostic messages by explaining thier syntax and test of clang by telling which subobject is uninitialized

2023-03-24 Thread Oliver Stannard via Phabricator via cfe-commits
olista01 added a comment.

There is existing documentation of the diagnostics system here, which you could 
extend if something is still unclear or incomplete:

- clang/docs/InternalsManual.rst
- https://clang.llvm.org/docs/InternalsManual.html#the-diagnostics-subsystem


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146802

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


[PATCH] D146408: [clang][Interp] Start supporting complex types

2023-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/AST/Interp/Context.cpp:84-85
 
+  if (T->isAnyComplexType())
+return std::nullopt;
+

tbaeder wrote:
> aaron.ballman wrote:
> > Hmmm, this seems surprising to me, I would have assumed that _Complex 
> > needed to be a primitive type so that we could perform typical math on it 
> > rather than treat it as a pair of values.
> I was going to add special opcodes for this case (or add //one// opcode for 
> complex/vector/bitint/... things to do everything?). 
> 
> If we don't do it this way we'd have to add `isAnyComplexType()` checks 
> everywhere so we can figure out if we need to look at one or two values, 
> don't we?
Hmm I think it depends on whether we consider the type to be primitive or not, 
maybe? I can see why it's not primitive -- it's comprised of two other 
primitive types. So that could be reasonable. But it's also primitive in that 
you need both of those values in order for the type to be meaningful for any 
operation (e.g., we don't want to accidentally split the values; we're always 
going to want to pass a complex value as "one thing", right). Buttt then 
again, if we treat it as not being primitive, then perhaps that gives us more 
optimization opportunities around things like "is an array of complex values an 
array of structs or a struct of arrays" kind of situations where we can decide 
to handle it differently depending on the situation.

So I guess I'm not certain of whether this is wrong or right.



Comment at: clang/test/AST/Interp/complex.cpp:7
+
+constexpr _Complex double z1 = {1.0, 2.0};
+static_assert(__real(z1) == 1.0);

tbaeder wrote:
> aaron.ballman wrote:
> > Can you add tests for `_Complex int` as well? (That's also covered by 
> > `isAnyComplexType()`)
> There's a `FIXME` comment above in `EvalEmitter.cpp` so returning those 
> doesn't work yet (but is otherwise not problematic I think.)
Hmmm, why the FIXME instead of just making the complex int type? 
(Alternatively, should we not use `isAnyComplexType()` and wait to add complex 
int support later?)


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

https://reviews.llvm.org/D146408

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


[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-03-24 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:3586-3591
+  // MSVC treats all predefined expressions as string literals rather than char
+  // arrays.
+  if (LangOpts.MicrosoftExt)
+return SL;
+
   return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL);

aaron.ballman wrote:
> This is incorrect -- these are still predefined expressions even if they're a 
> string literal. Otherwise, we lose AST fidelity and things like the 
> `predefinedExpr()` AST matcher don't work 
> (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/ASTMatchers/ASTMatchers.h#L2697),
>  and `-ast-print` will print the wrong thing 
> (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/StmtPrinter.cpp#L1248).
how would you structure this? an almost identical `PredefinedExpr` class that 
also subclasses `StringLiteral`? or special case all the places that check for 
`StringLiteral` to also check for `PredefinedExpr` (the case I was mostly 
looking at was initializing a char array with predefined expressions but 
presumably there are more places that matter)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


[PATCH] D146075: [flang][driver][openmp] Write MLIR for -save-temps

2023-03-24 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 508099.
skatrak added a comment.
Herald added subscribers: Moerafaat, zero9178, sdasgup3, wenzhicui, wrengr, 
cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, 
Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, nicolasvasilache, 
antiagainst, shauheen, mehdi_amini, thopre.

Revision of tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146075

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Driver/save-mlir-temps.f90

Index: flang/test/Driver/save-mlir-temps.f90
===
--- /dev/null
+++ flang/test/Driver/save-mlir-temps.f90
@@ -0,0 +1,58 @@
+! Tests for the `-save-temps` flag. Instead of checking the commands generated
+! by the driver with `-###` (like the save-temps.f90 test does), here we check
+! that the MLIR files are actually produced in the specified location because
+! the driver does not generate specific passes for MLIR. Instead, they are
+! generated during code generation as additional outputs.
+
+! As `flang` does not implement `-fc1as` (i.e. a driver for the integrated
+! assembler), we need to use `-fno-integrated-as` here.
+
+! UNSUPPORTED: system-windows
+
+!--
+! Invalid output directory
+!--
+! RUN: not %flang_fc1 -emit-llvm-bc -save-temps=#invalid-dir -o - %s 2>&1 | FileCheck %s -check-prefix=MLIR-ERROR
+! MLIR-ERROR: error: Saving MLIR temp file failed
+
+!--
+! Save to cwd
+!--
+! RUN: rm -rf %t && mkdir -p %t
+! RUN: pushd %t && %flang -c -fno-integrated-as -save-temps=cwd -o out.o %s 2>&1
+! RUN: FileCheck %s -input-file=save-mlir-temps-fir.mlir -check-prefix=MLIR-FIR
+! RUN: FileCheck %s -input-file=save-mlir-temps-llvmir.mlir -check-prefix=MLIR-LLVMIR
+! RUN: popd
+
+! RUN: rm -rf %t && mkdir -p %t
+! RUN: pushd %t && %flang -c -fno-integrated-as -save-temps -o out.o %s 2>&1
+! RUN: FileCheck %s -input-file=save-mlir-temps-fir.mlir -check-prefix=MLIR-FIR
+! RUN: FileCheck %s -input-file=save-mlir-temps-llvmir.mlir -check-prefix=MLIR-LLVMIR
+! RUN: popd
+
+!--
+! Save to output directory
+!--
+! RUN: rm -rf %t && mkdir -p %t
+! RUN: %flang -c -fno-integrated-as -save-temps=obj -o %t/out.o %s 2>&1
+! RUN: FileCheck %s -input-file=%t/save-mlir-temps-fir.mlir -check-prefix=MLIR-FIR
+! RUN: FileCheck %s -input-file=%t/save-mlir-temps-llvmir.mlir -check-prefix=MLIR-LLVMIR
+
+!--
+! Save to specific directory
+!--
+! RUN: rm -rf %t && mkdir -p %t
+! RUN: %flang -c -fno-integrated-as -save-temps=%t -o %t/out.o %s 2>&1
+! RUN: FileCheck %s -input-file=%t/save-mlir-temps-fir.mlir -check-prefix=MLIR-FIR
+! RUN: FileCheck %s -input-file=%t/save-mlir-temps-llvmir.mlir -check-prefix=MLIR-LLVMIR
+
+!--
+! Content to check from the MLIR outputs
+!--
+! MLIR-FIR-NOT: llvm.func
+! MLIR-FIR: func.func @{{.*}}main() {
+
+! MLIR-FIR-NOT: func.func
+! MLIR-LLVMIR: llvm.func @{{.*}}main() {
+
+end program
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -15,7 +15,8 @@
 ! RUN: -fassociative-math \
 ! RUN: -freciprocal-math \
 ! RUN: -fpass-plugin=Bye%pluginext \
-! RUN: -mllvm -print-before-all\
+! RUN: -mllvm -print-before-all \
+! RUN: -save-temps=obj \
 ! RUN: -P \
 ! RUN:   | FileCheck %s
 
@@ -34,3 +35,4 @@
 ! CHECK: "-fconvert=little-endian"
 ! CHECK: "-fpass-plugin=Bye
 ! CHECK: "-mllvm" "-print-before-all"
+! CHECK: "-save-temps=obj"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -170,6 +170,8 @@
 ! HELP-FC1-NEXT: -pic-level   Value for __PIC__
 ! HELP-FC1-NEXT: -plugin  Use the named plugin action instead of the default action (use "help" to list available options)
 ! HELP-FC1-NEXT: -P Disable linemarker output in -E mode
+! HELP-FC1-NEXT: -save-temps=Save intermediate compilation results.
+! HELP-FC1-NEXT: -save-tempsSave intermediate compilation results
 ! HELP-FC1-NEXT: -std=   Language standard to compile for
 ! HELP-FC1-NEXT: -S Only run preprocess and compilation steps
 ! HELP-FC1-NEXT: -target-cpu Target a specific cpu type
Index: flang/lib/Frontend/FrontendActions.cpp
=

[PATCH] D146784: [clang] Test for AST Dumping of the template variables

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508102.
tomasz-kaminski-sonarsource added a comment.

Reverted accidentally included changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

Files:
  clang/test/AST/ast-dump-template-decls.cpp


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
@@ -1,12 +1,12 @@
 // Test without serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -ast-dump %s \
-// RUN: | FileCheck -strict-whitespace %s
+// RUN: | FileCheck -strict-whitespace %s --check-prefix=DIRECT
 //
 // Test with serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -x c++ -std=c++17 -triple x86_64-unknown-unknown 
-include-pch %t -ast-dump-all /dev/null \
 // RUN: | sed -e "s/ //" -e "s/ imported//" \
-// RUN: | FileCheck --strict-whitespace %s
+// RUN: | FileCheck --strict-whitespace %s --check-prefix=SERIALIZED
 
 template 
 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <{{.*}}:1, line:[[@LINE+2]]:10> 
col:6 a
@@ -178,3 +178,80 @@
 // CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A'
 // CHECK-NEXT:   `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
 } // namespace subst_default_argument
+
+namespace D146733 {
+template
+T unTempl = 1;
+// CHECK:VarTemplateDecl 0x{{[^ ]*}}  
col:3 unTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 unTempl 
'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int unTempl;
+// FIXME - serializing and loading AST should not affect reported source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float unTempl = 1;
+// FIXME - serializing and loading AST should not affect reported source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+T binTempl = 1;
+// CHECK:  VarTemplateDecl 0x{{[^ ]*}}  col:3 binTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  col:25 
class depth 0 index 1 U
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 
binTempl 'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+int binTempl;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} 
 col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' 
dependent depth 0 index 0
+
+template
+float binTempl = 1;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} 
 col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: | `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' 
dependent depth 0 index 0
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int binTempl;
+// FIXME - serializing and loading AST should not affect reported source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float binTempl = 1;
+// FIXME - serializing and loading AST should not affect reported source range
+// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'float

[PATCH] D146814: [Flang] Add debug flag to enable current debug information pass

2023-03-24 Thread Sacha Ballantyne via Phabricator via cfe-commits
SBallantyne created this revision.
SBallantyne added reviewers: MaskRay, awarzynski, DavidTruby, 
kiranchandramohan, tblah.
Herald added a reviewer: sscalpone.
Herald added a subscriber: sunshaoce.
Herald added projects: Flang, All.
SBallantyne requested review of this revision.
Herald added subscribers: cfe-commits, jdoerfert.
Herald added a project: clang.

While a pass exists to generate basic debug information, currently there is not 
a corresponding flag to enable it.
This patch adds support for activating this pass at any debug level >= -g1, as 
well as emiting a warning for higher levels that the functionality is not yet 
fully implemented.

This patch also adds -g and -gline-tables-only to appear when `flang-new` 
--help is run


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146814

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.def
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/include/flang/Tools/CLOptions.inc
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90

Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -56,6 +56,8 @@
 ! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-NEXT: -funderscoring Appends one trailing underscore to external names
 ! HELP-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
+! HELP-NEXT: -gline-tables-only Emit debug line number tables only
+! HELP-NEXT: -g Generate source-level debug information
 ! HELP-NEXT: -help  Display available options
 ! HELP-NEXT: -IAdd directory to the end of the list of include search paths
 ! HELP-NEXT: -mllvm=   Alias for -mllvm
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -60,6 +60,8 @@
 ! CHECK-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! CHECK-NEXT: -funderscoring Appends one trailing underscore to external names
 ! CHECK-NEXT: -fxor-operator Enable .XOR. as a synonym of .NEQV.
+! CHECK-NEXT: -gline-tables-only Emit debug line number tables only
+! CHECK-NEXT: -g Generate source-level debug information
 ! CHECK-NEXT: -help Display available options
 ! CHECK-NEXT: -IAdd directory to the end of the list of include search paths
 ! CHECK-NEXT: -mllvm=   Alias for -mllvm
Index: flang/lib/Frontend/FrontendActions.cpp
===
--- flang/lib/Frontend/FrontendActions.cpp
+++ flang/lib/Frontend/FrontendActions.cpp
@@ -55,6 +55,7 @@
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
+#include 
 #include 
 
 using namespace Fortran::frontend;
@@ -555,7 +556,7 @@
 
   // Create the pass pipeline
   fir::createMLIRToLLVMPassPipeline(pm, level, opts.StackArrays,
-opts.Underscoring);
+opts.Underscoring, opts.getDebugInfo());
   mlir::applyPassManagerCLOptions(pm);
 
   // run the pass manager
Index: flang/lib/Frontend/CompilerInvocation.cpp
===
--- flang/lib/Frontend/CompilerInvocation.cpp
+++ flang/lib/Frontend/CompilerInvocation.cpp
@@ -35,6 +35,7 @@
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/Triple.h"
+#include 
 #include 
 #include 
 
@@ -117,9 +118,43 @@
   return true;
 }
 
+static void parseDebugArgs(Fortran::frontend::CodeGenOptions &opts,
+   llvm::opt::ArgList &args,
+   clang::DiagnosticsEngine &diags) {
+  if (llvm::opt::Arg *arg =
+  args.getLastArg(clang::driver::options::OPT_debug_info_kind_EQ)) {
+unsigned val =
+llvm::StringSwitch(arg->getValue())
+.Case("line-tables-only",
+  clang::codegenoptions::DebugLineTablesOnly)
+.Case("line-directives-only",
+  clang::codegenoptions::DebugDirectivesOnly)
+.Case("constructor", clang::codegenoptions::DebugInfoConstructor)
+.Case("limited", clang::codegenoptions::LimitedDebugInfo)
+.Case("standalone", clang::codegenoptions::FullDebugInfo)
+.Case("unused-types", clang::codegenoptions::UnusedTypeInfo)
+.Default(~0U);
+if (val == ~0U) {
+  diags.Report(clang::diag::err_drv_invalid_value)
+  << arg->getAsString(ar

[PATCH] D146784: [clang] Test for AST Dumping of the template variables

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508104.
tomasz-kaminski-sonarsource added a comment.

Reintroduced bug commit refernces. Sorry for the noise, but I still sometimes 
get confused with arc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146784

Files:
  clang/test/AST/ast-dump-template-decls.cpp


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
@@ -1,12 +1,12 @@
 // Test without serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -ast-dump %s \
-// RUN: | FileCheck -strict-whitespace %s
+// RUN: | FileCheck -strict-whitespace %s --check-prefix=DIRECT
 //
 // Test with serialization:
 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -emit-pch -o %t %s
 // RUN: %clang_cc1 -x c++ -std=c++17 -triple x86_64-unknown-unknown 
-include-pch %t -ast-dump-all /dev/null \
 // RUN: | sed -e "s/ //" -e "s/ imported//" \
-// RUN: | FileCheck --strict-whitespace %s
+// RUN: | FileCheck --strict-whitespace %s --check-prefix=SERIALIZED
 
 template 
 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} <{{.*}}:1, line:[[@LINE+2]]:10> 
col:6 a
@@ -178,3 +178,80 @@
 // CHECK-NEXT: `-RecordType 0x{{[^ ]*}} 'subst_default_argument::A'
 // CHECK-NEXT:   `-ClassTemplateSpecialization 0x{{[^ ]*}} 'A'
 } // namespace subst_default_argument
+
+namespace D146733 {
+template
+T unTempl = 1;
+// CHECK:VarTemplateDecl 0x{{[^ ]*}}  
col:3 unTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 unTempl 
'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int unTempl;
+// FIXME (#61680) - serializing and loading AST should not affect reported 
source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 unTempl 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float unTempl = 1;
+// FIXME (#61680) - serializing and loading AST should not affect reported 
source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+T binTempl = 1;
+// CHECK:  VarTemplateDecl 0x{{[^ ]*}}  col:3 binTempl
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 T
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  col:25 
class depth 0 index 1 U
+// CHECK-NEXT: |-VarDecl 0x{{[^ ]*}}  col:3 
binTempl 'T' cinit
+// CHECK-NEXT: | `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template
+int binTempl;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} 
 col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' 
dependent depth 0 index 0
+
+template
+float binTempl = 1;
+// CHECK:  VarTemplatePartialSpecializationDecl 0x{{[^ ]*}} 
 col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateTypeParmDecl 0x{{[^ ]*}}  
col:16 referenced class depth 0 index 0 U
+// CHECK-NEXT: |-TemplateArgument type 'float'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
+// CHECK-NEXT: |-TemplateArgument type 'type-parameter-0-0'
+// CHECK-NEXT: | `-TemplateTypeParmType 0x{{[^ ]*}} 'type-parameter-0-0' 
dependent depth 0 index 0
+// CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 

+// CHECK-NEXT: `-IntegerLiteral 0x{{[^ ]*}}  'int' 1
+
+template<>
+int binTempl;
+// FIXME (#61680) - serializing and loading AST should not affect reported 
source range
+// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:5 binTempl 'int'
+// CHECK-NEXT: |-TemplateArgument type 'int'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'int'
+// CHECK-NEXT: `-TemplateArgument type 'int'
+// CHECK-NEXT: `-BuiltinType 0x{{[^ ]*}} 'int'
+
+template<>
+float binTempl = 1;
+// FIXME (#61680) - serializing and loading AST should not affect reported 
source range
+// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK-NEXT: |-TemplateArgument type 'flo

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

2023-03-24 Thread Felipe de Azevedo Piovezan via Phabricator via cfe-commits
fdeazeve added a comment.

In D144651#4219340 , @aaron.ballman 
wrote:

> In D144651#4217750 , @john.brawn 
> wrote:
>
>> Unfortunately I still can't reproduce this even using exactly the same cmake 
>> command as you gave. Looking at above cmake log some possible causes of 
>> difference are:
>>
>> - I'm doing this on an M1  macbook with host 
>> triple arm64-apple-darwin21.6.0 but the host triple on that bot is 
>> x86_64-apple-darwin20.6.0
>> - I'm using python 3.9, bot is using python 3.10
>> - I'm doing a build from clean whereas the bot is doing an incremental build
>>
>> Also if I try to run the simpler reproducer you give then I get the error
>>
>>   error: expression failed to parse:
>>   error: Header search couldn't locate module Cocoa
>>
>> I'm now on holiday, I won't be able to get back to this until 2023-04-03.
>
> The build lab's lldb builders are all green, and greendragon's standalone 
> build is also green. Could this be a problem with incremental builds being in 
> a bad state somehow?

I don't think so, as I can reliably reproduce this on my machine. I believe the 
_contents_ of the SDK headers affect what is fed to Clang, and therefore we see 
the crash with some SDKs but not others.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

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


[PATCH] D146733: [clang] source range of variable template specialization should include initializer

2023-03-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 508105.
tomasz-kaminski-sonarsource added a comment.

Rebasing on test commit. My applogies for noise, I still get confused with arc 
sometimes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146733

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclTemplate.h
  clang/lib/AST/DeclTemplate.cpp
  clang/test/AST/ast-dump-template-decls.cpp

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
@@ -197,9 +197,7 @@
 
 template<>
 float unTempl = 1;
-// FIXME (#61680) - serializing and loading AST should not affect reported source range
-// DIRECT: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
+// CHECK:  VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 unTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: `-ImplicitCastExpr 0x{{[^ ]*}}  'float' 
@@ -245,9 +243,7 @@
 
 template<>
 float binTempl = 1;
-// FIXME (#61680) - serializing and loading AST should not affect reported source range
-// DIRECT:VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
-// SERIALIZED: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
+// CHECK: VarTemplateSpecializationDecl 0x{{[^ ]*}}  col:7 binTempl 'float' cinit
 // CHECK-NEXT: |-TemplateArgument type 'float'
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'float'
 // CHECK-NEXT: |-TemplateArgument type 'float'
Index: clang/lib/AST/DeclTemplate.cpp
===
--- clang/lib/AST/DeclTemplate.cpp
+++ clang/lib/AST/DeclTemplate.cpp
@@ -1402,6 +1402,15 @@
   ASTTemplateArgumentListInfo::Create(getASTContext(), ArgsInfo);
 }
 
+SourceRange VarTemplateSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
+
 //===--===//
 // VarTemplatePartialSpecializationDecl Implementation
 //===--===//
@@ -1447,6 +1456,14 @@
   return new (C, ID) VarTemplatePartialSpecializationDecl(C);
 }
 
+SourceRange VarTemplatePartialSpecializationDecl::getSourceRange() const {
+  if (isExplicitSpecialization() && !hasInit()) {
+if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
+  return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
+  }
+  return VarDecl::getSourceRange();
+}
+
 static TemplateParameterList *
 createMakeIntegerSeqParameterList(const ASTContext &C, DeclContext *DC) {
   // typename T
Index: clang/include/clang/AST/DeclTemplate.h
===
--- clang/include/clang/AST/DeclTemplate.h
+++ clang/include/clang/AST/DeclTemplate.h
@@ -2926,13 +2926,7 @@
 return ExplicitInfo ? ExplicitInfo->TemplateKeywordLoc : SourceLocation();
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsInfo())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
 Profile(ID, TemplateArgs->asArray(), getASTContext());
@@ -3091,13 +3085,7 @@
 return First->InstantiatedFromMember.setInt(true);
   }
 
-  SourceRange getSourceRange() const override LLVM_READONLY {
-if (isExplicitSpecialization()) {
-  if (const ASTTemplateArgumentListInfo *Info = getTemplateArgsAsWritten())
-return SourceRange(getOuterLocStart(), Info->getRAngleLoc());
-}
-return VarDecl::getSourceRange();
-  }
+  SourceRange getSourceRange() const override LLVM_READONLY;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
 Profile(ID, getTemplateArgs().asArray(), getTemplateParameters(),
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -230,6 +230,11 @@
   antecipation of `CWG2563 _`.
 - Fix highlighting issue with ``_Complex`` and initialization list with more than
   2 items. (`#61518 `_)
+- Fix  ``getSourceRange`` on  ``

[PATCH] D146075: [flang][driver][openmp] Write MLIR for -save-temps

2023-03-24 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak marked 3 inline comments as done.
skatrak added inline comments.



Comment at: flang/lib/Frontend/FrontendActions.cpp:103
+  std::error_code ec;
+  llvm::ToolOutputFile out(outDir + outFile, ec, llvm::sys::fs::OF_Text);
+  if (ec)

awarzynski wrote:
> skatrak wrote:
> > awarzynski wrote:
> > > Why not just [[ 
> > > https://github.com/llvm/llvm-project/blob/3b1951aceb8c58acd3d5c5ba2d042ad3d03c13c4/flang/lib/Frontend/FrontendActions.cpp#L793
> > >  | print ]] the MLIR module?
> > I'm not sure I completely understand the issue here, by looking at the code 
> > you linked to. Maybe it's related to the fact that this function is 
> > implemented by creating new files apart from the main output of the current 
> > compiler invocation. I developed the idea a bit more in the reply to your 
> > comment on "save-temps.f90".
> Apologies, I am blind - you were using `print` already!
No problem! That makes it two of us, then ;)



Comment at: flang/test/Driver/save-temps.f90:58
+!--
+! MLIR generation
+!--

awarzynski wrote:
> [nit] For MLIR you check the contents of the intermediate files (great!), but 
> then for all other temp files we don't (some of them are binary and that's 
> one reason). Given that testing for MLIR temp files is so different, I'd be 
> tempted to move to a different file. Or at least add a comment here to 
> explain the rationale for testing differently.
Thanks for the suggestion. I separated that into its own test which also 
contains an explanation of why it's tested differently.



Comment at: flang/test/Driver/save-temps.f90:14
 ! CHECK-NEXT: "-o" "save-temps.o"
 ! CHECK-NEXT: "-o" "a.out"
 

awarzynski wrote:
> skatrak wrote:
> > awarzynski wrote:
> > > Why are there no MLIR files here? Same comment for other invocations.
> > This is because the general way in which -save-temps works is different 
> > from what's implemented in this patch for MLIR in flang. In the other 
> > cases, the driver splits the work into several frontend invocations, where 
> > each step generally produces the input of the next. `-save-temps` makes 
> > sure these intermediate files are kept where the user specified and not 
> > deleted.
> > 
> > In this patch, instead of modifying the driver to create a frontend 
> > invocation to produce MLIR (generating the *-fir.mlir file), another one to 
> > optimize/lower that (generating the *-llvmir.mlir file), and a third one to 
> > translate lowered MLIR into LLVM IR, we just forward the flag to the 
> > frontend, which creates extra MLIR files at particular spots of the codegen 
> > process if the flag is set. Hence, MLIR files don't show in the output of 
> > `flang-new -###`.
> So, IIUC, without `-emit-llvm-bc` there should be no intermediate MLIR files? 
> I would add `CHECK-NOT`.
Actually, with this approach there are no changes to the output of `flang -###` 
either way. I was using `-fc1 -emit-llvm-bc` just because that triggers both 
MLIR temp outputs (the one before any optimizations/lowering, and the one right 
before LLVM IR generation), but I simplified that a bit by just using `flang 
-c` instead and avoid confusion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146075

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


[PATCH] D146814: [Flang] Add debug flag to enable current debug information pass

2023-03-24 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added inline comments.



Comment at: flang/include/flang/Frontend/CodeGenOptions.h:18
 
+#include "clang/Basic/DebugInfoOptions.h"
 #include "llvm/Support/CodeGen.h"

The following patch might be useful to avoid adding the clang header. Could you 
try it locally and see whether it works? If so you can either commandeer the 
following patch or alternatively include the following patch as part of the 
current one.
https://reviews.llvm.org/D142347


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146814

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


[PATCH] D146244: [clangd] Show used symbols on #include line hover.

2023-03-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

(pardon the interruption, some drive-by comments :))




Comment at: clang-tools-extra/clangd/Hover.cpp:1174
+  return;
+
+for (const include_cleaner::Header &H : Providers) {

note that we don't care about each reference of a target, so speed things up 
(rather than going through each reference inside the main file), you can check 
if you've seen Ref.Target before and skip processing providers in that case.



Comment at: clang-tools-extra/clangd/Hover.cpp:1175
+
+for (const include_cleaner::Header &H : Providers) {
+  if (!ConvertedIncludes.match(H).empty()) {

note that this will attribute a symbol to it's non-preferred providers too, 
e.g. if you have:
h1.h:
```
struct Foo; // defined in foo.h
struct Bar; // defined in bar.h
struct Baz; // defined in baz.h
struct H1 {};
```

I believe we want the following:
main.cc:
```
#include foo.h // Provides Foo
#include bar.h // Provides Bar
#include h1.h // Provides Baz, H1

Foo *x;
Bar *y;
Baz *z;
H1 *h;
```

and not saying that h1.h provides all Foo, Bar, Baz and H1 (otherwise an LLVM 
header will always provide dozens of symbols, e.g. 
https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/Type.h#L109)

Basically in addition to checking that the particular header we're interested 
in being a provider, we should also be checking there were no other providers 
that are mentioned in the main file with a higher rank.



Comment at: clang-tools-extra/clangd/Hover.cpp:1192
   const SymbolIndex *Index) {
   PrintingPolicy PP =
   getPrintingPolicy(AST.getASTContext().getPrintingPolicy());

can you introduce a trace::metric here for tracking hover distributions on 
certain symbol types? you can see an example in 
https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clangd/XRefs.cpp#L352

i believe the cases we care about are:
- include
- macro
- keyword
- expr
- decl
- attribute

(so that we have some idea about how often we provide this information)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146244

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


[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:3586-3591
+  // MSVC treats all predefined expressions as string literals rather than char
+  // arrays.
+  if (LangOpts.MicrosoftExt)
+return SL;
+
   return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL);

aeubanks wrote:
> aaron.ballman wrote:
> > This is incorrect -- these are still predefined expressions even if they're 
> > a string literal. Otherwise, we lose AST fidelity and things like the 
> > `predefinedExpr()` AST matcher don't work 
> > (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/ASTMatchers/ASTMatchers.h#L2697),
> >  and `-ast-print` will print the wrong thing 
> > (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/StmtPrinter.cpp#L1248).
> how would you structure this? an almost identical `PredefinedExpr` class that 
> also subclasses `StringLiteral`? or special case all the places that check 
> for `StringLiteral` to also check for `PredefinedExpr` (the case I was mostly 
> looking at was initializing a char array with predefined expressions but 
> presumably there are more places that matter)
We can't inherit from `StringLiteral` (it's a `final` class because it has 
`TrailingObjects`), so that might be the only viable approach. However, there's 
a fair number of places in the compiler where we care if something is or isn't 
a `StringLiteral`, so I can see why we'd want to avoid that if possible.

Oye, but it seems that even MSVC is not consistent with whether the predefined 
expression is a string literal or not: https://godbolt.org/z/jzY8cz79d


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


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

2023-03-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D144651#4219633 , @fdeazeve wrote:

> In D144651#4219340 , @aaron.ballman 
> wrote:
>
>> The build lab's lldb builders are all green, and greendragon's standalone 
>> build is also green. Could this be a problem with incremental builds being 
>> in a bad state somehow?
>
> I don't think so, as I can reliably reproduce this on my machine. I believe 
> the _contents_ of the SDK headers affect what is fed to Clang, and therefore 
> we see the crash with some SDKs but not others.

Ouch. :-( I think we're going to need some help getting a reproducer that 
doesn't rely on the SDK headers. In the meantime, because this is causing 
disruption by introducing a crash, I think it's fine to revert the changes 
until @john.brawn returns from vacation, but I'd appreciate it if we had such a 
reproducer in hand fairly shortly (I don't want to stick John in a position 
where his patch was reverted and he has no reasonable way in which to address 
the issue so it can be re-landed).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144651

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


[PATCH] D146808: [AMDGPU] Add clang builtin for __builtin_amdgcn_ds_atomic_fadd_v2f16

2023-03-24 Thread Mariusz Sikora 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 rG69061f96275c: [AMDGPU] Add clang builtin for 
__builtin_amdgcn_ds_atomic_fadd_v2f16 (authored by mariusz-sikora-at-amd).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146808

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
  clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
  clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx940.cl

Index: clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx940.cl
===
--- clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx940.cl
+++ clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx940.cl
@@ -48,3 +48,19 @@
 short2 test_local_add_2bf16(__local short2 *addr, short2 x) {
   return __builtin_amdgcn_ds_atomic_fadd_v2bf16(addr, x);
 }
+
+// CHECK-LABEL: test_local_add_2f16
+// CHECK: call <2 x half> @llvm.amdgcn.ds.fadd.v2f16(ptr addrspace(3) %{{.*}}, <2 x half> %
+// GFX940-LABEL:  test_local_add_2f16
+// GFX940: ds_pk_add_rtn_f16
+half2 test_local_add_2f16(__local half2 *addr, half2 x) {
+  return __builtin_amdgcn_ds_atomic_fadd_v2f16(addr, x);
+}
+
+// CHECK-LABEL: test_local_add_2f16_noret
+// CHECK: call <2 x half> @llvm.amdgcn.ds.fadd.v2f16(ptr addrspace(3) %{{.*}}, <2 x half> %
+// GFX940-LABEL:  test_local_add_2f16_noret
+// GFX940: ds_pk_add_f16
+void test_local_add_2f16_noret(__local half2 *addr, half2 x) {
+  __builtin_amdgcn_ds_atomic_fadd_v2f16(addr, x);
+}
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
@@ -6,7 +6,7 @@
 typedef half  __attribute__((ext_vector_type(2))) half2;
 typedef short __attribute__((ext_vector_type(2))) short2;
 
-void test_atomic_fadd(__global half2 *addrh2, half2 xh2,
+void test_atomic_fadd(__global half2 *addrh2, __local half2 *addrh2l, half2 xh2,
   __global short2 *addrs2, __local short2 *addrs2l, short2 xs2,
   __global float *addrf, float xf) {
   __builtin_amdgcn_flat_atomic_fadd_f32(addrf, xf); // expected-error{{'__builtin_amdgcn_flat_atomic_fadd_f32' needs target feature gfx940-insts}}
@@ -14,4 +14,5 @@
   __builtin_amdgcn_flat_atomic_fadd_v2bf16(addrs2, xs2); // expected-error{{'__builtin_amdgcn_flat_atomic_fadd_v2bf16' needs target feature atomic-flat-pk-add-16-insts}}
   __builtin_amdgcn_global_atomic_fadd_v2bf16(addrs2, xs2); // expected-error{{'__builtin_amdgcn_global_atomic_fadd_v2bf16' needs target feature atomic-global-pk-add-bf16-inst}}
   __builtin_amdgcn_ds_atomic_fadd_v2bf16(addrs2l, xs2); // expected-error{{'__builtin_amdgcn_ds_atomic_fadd_v2bf16' needs target feature atomic-ds-pk-add-16-insts}}
+  __builtin_amdgcn_ds_atomic_fadd_v2f16(addrh2l, xh2); // expected-error{{'__builtin_amdgcn_ds_atomic_fadd_v2f16' needs target feature atomic-ds-pk-add-16-insts}}
 }
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
+++ clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
@@ -4,9 +4,9 @@
 
 typedef half __attribute__((ext_vector_type(2))) half2;
 
-void test_global_add_2f16(__global half2 *addrh2, half2 xh2,
-  __global float *addrf, float xf,
-  __global double *addr, double x) {
+void test_global_fadd(__global half2 *addrh2, __local half2 *addrh2l, half2 xh2,
+  __global float *addrf, float xf,
+  __global double *addr, double x) {
   half2 *half_rtn;
   float *fp_rtn;
   double *rtn;
@@ -18,4 +18,5 @@
   *rtn = __builtin_amdgcn_flat_atomic_fadd_f64(addr, x); // expected-error{{'__builtin_amdgcn_flat_atomic_fadd_f64' needs target feature gfx90a-insts}}
   *rtn = __builtin_amdgcn_flat_atomic_fmin_f64(addr, x); // expected-error{{'__builtin_amdgcn_flat_atomic_fmin_f64' needs target feature gfx90a-insts}}
   *rtn = __builtin_amdgcn_flat_atomic_fmax_f64(addr, x); // expected-error{{'__builtin_amdgcn_flat_atomic_fmax_f64' needs target feature gfx90a-insts}}
+  __builtin_amdgcn_ds_atomic_fadd_v2f16(addrh2l, xh2); // expected-error{{'__builtin_amdgcn_ds_atomic_fadd_v2f16' needs target feature atomic-ds-pk-add-16-insts}}
 }
Index: clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
===
--- clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
+++ cla

[clang] 69061f9 - [AMDGPU] Add clang builtin for __builtin_amdgcn_ds_atomic_fadd_v2f16

2023-03-24 Thread Mariusz Sikora via cfe-commits

Author: Mariusz Sikora
Date: 2023-03-24T16:27:44+01:00
New Revision: 69061f96275c3053623a8699ce641c0f0ac61aed

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

LOG: [AMDGPU] Add clang builtin for __builtin_amdgcn_ds_atomic_fadd_v2f16

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

Added: 


Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx90a-err.cl
clang/test/CodeGenOpenCL/builtins-fp-atomics-gfx940.cl

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index ed75b58ddbf96..965bd97a97d79 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -231,6 +231,7 @@ TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_v2f16, 
"V2hV2h*0V2h", "t", "ato
 TARGET_BUILTIN(__builtin_amdgcn_flat_atomic_fadd_v2bf16, "V2sV2s*0V2s", "t", 
"atomic-flat-pk-add-16-insts")
 TARGET_BUILTIN(__builtin_amdgcn_global_atomic_fadd_v2bf16, "V2sV2s*1V2s", "t", 
"atomic-global-pk-add-bf16-inst")
 TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_v2bf16, "V2sV2s*3V2s", "t", 
"atomic-ds-pk-add-16-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_atomic_fadd_v2f16, "V2hV2h*3V2h", "t", 
"atomic-ds-pk-add-16-insts")
 
 
//===--===//
 // Deep learning builtins.

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index b3aea13878c1c..c8112b0ea0ec0 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17213,7 +17213,8 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 return Builder.CreateCall(F, {Addr, Val});
   }
   case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f64:
-  case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f32: {
+  case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f32:
+  case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2f16: {
 Intrinsic::ID IID;
 llvm::Type *ArgTy;
 switch (BuiltinID) {
@@ -17225,6 +17226,11 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   ArgTy = llvm::Type::getDoubleTy(getLLVMContext());
   IID = Intrinsic::amdgcn_ds_fadd;
   break;
+case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2f16:
+  ArgTy = llvm::FixedVectorType::get(
+  llvm::Type::getHalfTy(getLLVMContext()), 2);
+  IID = Intrinsic::amdgcn_ds_fadd;
+  break;
 }
 llvm::Value *Addr = EmitScalarExpr(E->getArg(0));
 llvm::Value *Val = EmitScalarExpr(E->getArg(1));

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
index 3044fdedca36b..39191322ca6e4 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx11-err.cl
@@ -15,4 +15,5 @@ void test_atomic_fadd(__global half2 *addrh2, __local half2 
*addrh2l, half2 xh2,
   __builtin_amdgcn_global_atomic_fadd_v2bf16(addrs2, xs2); // 
expected-error{{'__builtin_amdgcn_global_atomic_fadd_v2bf16' needs target 
feature atomic-global-pk-add-bf16-inst}}
   __builtin_amdgcn_global_atomic_fadd_v2f16(addrh2, xh2); // 
expected-error{{'__builtin_amdgcn_global_atomic_fadd_v2f16' needs target 
feature atomic-buffer-global-pk-add-f16-insts}}
   __builtin_amdgcn_ds_atomic_fadd_v2bf16(addrs2l, xs2); // 
expected-error{{'__builtin_amdgcn_ds_atomic_fadd_v2bf16' needs target feature 
atomic-ds-pk-add-16-insts}}
+  __builtin_amdgcn_ds_atomic_fadd_v2f16(addrh2l, xh2); // 
expected-error{{'__builtin_amdgcn_ds_atomic_fadd_v2f16' needs target feature 
atomic-ds-pk-add-16-insts}}
 }

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
index fd813ac029eab..0548b825a7265 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-fp-atomics-gfx908-err.cl
@@ -4,9 +4,9 @@
 
 typedef half __attribute__((ext_vector_type(2))) half2;
 
-void test_global_add_2f16(__global half2 *addrh2, half2 xh2,
-  __global float *addrf, float xf,
-  __global double *addr, double x) {
+void test_global_fadd(__global half2 *addrh2, __local half2 *addrh2l, half2 
xh2,
+  __global float *addrf, float xf,
+  __global double *addr, double x) {
   half2 *half_rtn;
   float *fp_rtn;
   double *rtn;
@@ -18,4 +18,5 @@ void test_gl

[PATCH] D146764: [clang] Make predefined expressions string literals under -fms-extensions

2023-03-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:3586-3591
+  // MSVC treats all predefined expressions as string literals rather than char
+  // arrays.
+  if (LangOpts.MicrosoftExt)
+return SL;
+
   return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL);

aaron.ballman wrote:
> aeubanks wrote:
> > aaron.ballman wrote:
> > > This is incorrect -- these are still predefined expressions even if 
> > > they're a string literal. Otherwise, we lose AST fidelity and things like 
> > > the `predefinedExpr()` AST matcher don't work 
> > > (https://github.com/llvm/llvm-project/blob/main/clang/include/clang/ASTMatchers/ASTMatchers.h#L2697),
> > >  and `-ast-print` will print the wrong thing 
> > > (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/StmtPrinter.cpp#L1248).
> > how would you structure this? an almost identical `PredefinedExpr` class 
> > that also subclasses `StringLiteral`? or special case all the places that 
> > check for `StringLiteral` to also check for `PredefinedExpr` (the case I 
> > was mostly looking at was initializing a char array with predefined 
> > expressions but presumably there are more places that matter)
> We can't inherit from `StringLiteral` (it's a `final` class because it has 
> `TrailingObjects`), so that might be the only viable approach. However, 
> there's a fair number of places in the compiler where we care if something is 
> or isn't a `StringLiteral`, so I can see why we'd want to avoid that if 
> possible.
> 
> Oye, but it seems that even MSVC is not consistent with whether the 
> predefined expression is a string literal or not: 
> https://godbolt.org/z/jzY8cz79d
I think these should be plain old string literals, but for the purpose or AST 
matchers and such, maybe we could have a "predefined macro" bit, or even an 
additional object that stores the name.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146764

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


[PATCH] D146814: [Flang] Add debug flag to enable current debug information pass

2023-03-24 Thread Tom Eccles via Phabricator via cfe-commits
tblah added a comment.

Thanks for adding this flang.

Please could you add a test checking that the pass is actually run when the 
flag is given. For example, see the tests on this patch 
https://reviews.llvm.org/D146278




Comment at: flang/include/flang/Tools/CLOptions.inc:21
 #include "llvm/Support/CommandLine.h"
+#include 
 

nit: clang is conceptually "above" LLVM in the dependency hierarchy:

https://llvm.org/docs/CodingStandards.html#include-style
>LLVM project and subproject headers should be grouped from most specific to 
>least specific, for the same reasons described above. For example, LLDB 
>depends on both clang and LLVM, and clang depends on LLVM. So an LLDB source 
>file should include lldb headers first, followed by clang headers, followed by 
>llvm headers, to reduce the possibility (for example) of an LLDB header 
>accidentally picking up a missing include due to the previous inclusion of 
>that header in the main source file or some earlier header file.



Comment at: flang/lib/Frontend/FrontendActions.cpp:58
 #include "llvm/Transforms/Utils/ModuleUtils.h"
+#include 
 #include 

nit: is this include required?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146814

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


  1   2   >