[PATCH] D155539: [CUDA][HIP] Use the same default language std as C++

2023-07-20 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

Hi @yaxunl, your change appears to have broken the LLDB build. Can you take a 
look and revert if you time to investigate?

https://lab.llvm.org/buildbot/#/builders/243/builds/9581

  FAILED: 
tools/lldb/source/Plugins/TypeSystem/Clang/CMakeFiles/lldbPluginTypeSystemClang.dir/TypeSystemClang.cpp.o
 
  /opt/ccache/bin/g++ -DGTEST_HAS_RTTI=0 -DHAVE_ROUND -D_DEBUG 
-D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D_LIBCPP_ENABLE_ASSERTIONS 
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/tools/lldb/source/Plugins/TypeSystem/Clang
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Plugins/TypeSystem/Clang
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/tools/lldb/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/llvm/include
 -I/usr/include/python3.10 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/llvm/../clang/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/tools/lldb/../clang/include
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source
 
-I/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/build/tools/lldb/source
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic 
-Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized 
-Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move 
-Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-deprecated-declarations 
-Wno-unknown-pragmas -Wno-strict-aliasing -Wno-stringop-truncation -O3 -DNDEBUG 
 -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -std=c++17 -MD -MT 
tools/lldb/source/Plugins/TypeSystem/Clang/CMakeFiles/lldbPluginTypeSystemClang.dir/TypeSystemClang.cpp.o
 -MF 
tools/lldb/source/Plugins/TypeSystem/Clang/CMakeFiles/lldbPluginTypeSystemClang.dir/TypeSystemClang.cpp.o.d
 -o 
tools/lldb/source/Plugins/TypeSystem/Clang/CMakeFiles/lldbPluginTypeSystemClang.dir/TypeSystemClang.cpp.o
 -c 
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:
 In function ‘void ParseLangArgs(clang::LangOptions&, clang::InputKind, const 
char*)’:
  
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:489:31:
 error: ‘lang_cuda’ is not a member of ‘clang::LangStandard’
489 |   LangStd = LangStandard::lang_cuda;
|   ^
  
/home/buildbot/buildbot-root/cross-project-tests-sie-ubuntu-dwarf5/llvm-project/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:501:31:
 error: ‘lang_hip’ is not a member of ‘clang::LangStandard’
501 |   LangStd = LangStandard::lang_hip;
|   ^~~~

Other failing buildbots:

- https://lab.llvm.org/buildbot/#/builders/96/builds/42305
- https://lab.llvm.org/buildbot/#/builders/17/builds/40545
- https://lab.llvm.org/buildbot/#/builders/68/builds/56513


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155539

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


[PATCH] D150803: [WebAssembly] Support `annotate` clang attributes for marking functions.

2023-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp:568
+  // Group all the custom attributes by name.
+  StringMap> CustomSections;
+  const ConstantArray *CA = cast(V->getOperand(0));

"StringMap iteration order, however, is not guaranteed to be deterministic, so 
any uses which require that should instead use a std::map."  
https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h

I'll fix this in one minute.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150803

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


[PATCH] D155788: [clang][dataflow] Add an `operator<<` for `OptionalTypeIdentifier`.

2023-07-20 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When tests fail in UncheckedOptionalAccessModelTest.cpp, this prints the name of
the optional type instead of a blob of hex.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155788

Files:
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1266,6 +1266,11 @@
   std::string TypeName;
 };
 
+static raw_ostream &operator<<(raw_ostream &OS, const OptionalTypeIdentifier 
&TypeId) {
+  OS << TypeId.NamespaceName << "::" << TypeId.TypeName;
+  return OS;
+}
+
 class UncheckedOptionalAccessTest
 : public ::testing::TestWithParam {
 protected:


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1266,6 +1266,11 @@
   std::string TypeName;
 };
 
+static raw_ostream &operator<<(raw_ostream &OS, const OptionalTypeIdentifier &TypeId) {
+  OS << TypeId.NamespaceName << "::" << TypeId.TypeName;
+  return OS;
+}
+
 class UncheckedOptionalAccessTest
 : public ::testing::TestWithParam {
 protected:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155788: [clang][dataflow] Add an `operator<<` for `OptionalTypeIdentifier`.

2023-07-20 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 542330.
mboehme added a comment.

Format code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155788

Files:
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1266,6 +1266,12 @@
   std::string TypeName;
 };
 
+static raw_ostream &operator<<(raw_ostream &OS,
+   const OptionalTypeIdentifier &TypeId) {
+  OS << TypeId.NamespaceName << "::" << TypeId.TypeName;
+  return OS;
+}
+
 class UncheckedOptionalAccessTest
 : public ::testing::TestWithParam {
 protected:


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1266,6 +1266,12 @@
   std::string TypeName;
 };
 
+static raw_ostream &operator<<(raw_ostream &OS,
+   const OptionalTypeIdentifier &TypeId) {
+  OS << TypeId.NamespaceName << "::" << TypeId.TypeName;
+  return OS;
+}
+
 class UncheckedOptionalAccessTest
 : public ::testing::TestWithParam {
 protected:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 528447f - [clang-tools-extra] the message in a static_assert is not always a string literal

2023-07-20 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-07-20T09:23:08+02:00
New Revision: 528447ff265a6c58b43af6cff2a3ee0ce5784331

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

LOG: [clang-tools-extra] the message in a static_assert is not always a string 
literal

Fixes build failure introduce by 47ccfd7.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
index 81b21565667e8a..c90d2e4f764b89 100644
--- a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
@@ -21,7 +21,8 @@ void UnaryStaticAssertCheck::registerMatchers(MatchFinder 
*Finder) {
 void UnaryStaticAssertCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *MatchedDecl =
   Result.Nodes.getNodeAs("static_assert");
-  const StringLiteral *AssertMessage = MatchedDecl->getMessage();
+  const auto *AssertMessage =
+  dyn_cast_if_present(MatchedDecl->getMessage());
 
   SourceLocation Loc = MatchedDecl->getLocation();
 



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


[PATCH] D155776: [NFC] Add checks for self-assignment.

2023-07-20 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir updated this revision to Diff 542333.
schittir added a comment.

Please consider these changes for review.


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

https://reviews.llvm.org/D155776

Files:
  clang/lib/AST/APValue.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Interpreter/Value.cpp


Index: clang/lib/Interpreter/Value.cpp
===
--- clang/lib/Interpreter/Value.cpp
+++ clang/lib/Interpreter/Value.cpp
@@ -201,16 +201,17 @@
 }
 
 Value &Value::operator=(Value &&RHS) noexcept {
-  if (IsManuallyAlloc)
-ValueStorage::getFromPayload(getPtr())->Release();
+  if (this != RHS) {
+if (IsManuallyAlloc)
+  ValueStorage::getFromPayload(getPtr())->Release();
 
-  Interp = std::exchange(RHS.Interp, nullptr);
-  OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
-  ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
-  IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
-
-  Data = RHS.Data;
+Interp = std::exchange(RHS.Interp, nullptr);
+OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
+ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
+IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
 
+Data = RHS.Data;
+  }
   return *this;
 }
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -832,8 +832,10 @@
 
   // Define copy assignment operator.
   ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
-CGF = Other.CGF;
-Other.CGF = nullptr;
+if (this != Other) {
+  CGF = Other.CGF;
+  Other.CGF = nullptr;
+}
 return *this;
   }
 
Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -390,11 +390,13 @@
 }
 
 APValue &APValue::operator=(APValue &&RHS) {
-  if (Kind != None && Kind != Indeterminate)
-DestroyDataAndMakeUninit();
-  Kind = RHS.Kind;
-  Data = RHS.Data;
-  RHS.Kind = None;
+  if (this != RHS) {
+if (Kind != None && Kind != Indeterminate)
+  DestroyDataAndMakeUninit();
+Kind = RHS.Kind;
+Data = RHS.Data;
+RHS.Kind = None;
+  }
   return *this;
 }
 


Index: clang/lib/Interpreter/Value.cpp
===
--- clang/lib/Interpreter/Value.cpp
+++ clang/lib/Interpreter/Value.cpp
@@ -201,16 +201,17 @@
 }
 
 Value &Value::operator=(Value &&RHS) noexcept {
-  if (IsManuallyAlloc)
-ValueStorage::getFromPayload(getPtr())->Release();
+  if (this != RHS) {
+if (IsManuallyAlloc)
+  ValueStorage::getFromPayload(getPtr())->Release();
 
-  Interp = std::exchange(RHS.Interp, nullptr);
-  OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
-  ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
-  IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
-
-  Data = RHS.Data;
+Interp = std::exchange(RHS.Interp, nullptr);
+OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
+ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
+IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
 
+Data = RHS.Data;
+  }
   return *this;
 }
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -832,8 +832,10 @@
 
   // Define copy assignment operator.
   ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
-CGF = Other.CGF;
-Other.CGF = nullptr;
+if (this != Other) {
+  CGF = Other.CGF;
+  Other.CGF = nullptr;
+}
 return *this;
   }
 
Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -390,11 +390,13 @@
 }
 
 APValue &APValue::operator=(APValue &&RHS) {
-  if (Kind != None && Kind != Indeterminate)
-DestroyDataAndMakeUninit();
-  Kind = RHS.Kind;
-  Data = RHS.Data;
-  RHS.Kind = None;
+  if (this != RHS) {
+if (Kind != None && Kind != Indeterminate)
+  DestroyDataAndMakeUninit();
+Kind = RHS.Kind;
+Data = RHS.Data;
+RHS.Kind = None;
+  }
   return *this;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155446: [clang][dataflow] Eliminate duplication between `AggregateStorageLocation` and `StructValue`.

2023-07-20 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 542337.
mboehme marked 11 inline comments as done.
mboehme added a comment.

Changes in response to review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155446

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/lib/Analysis/FlowSensitive/RecordOps.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
  clang/unittests/Analysis/FlowSensitive/RecordOpsTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -27,6 +27,11 @@
 #include 
 #include 
 
+// FIXME: There are still remaining checks here that check for consistency
+// between `StructValue` and `AggregateStorageLocation`. Now that the redundancy
+// between these two classes has been eliminated, these checks aren't needed any
+// more, so remove them.
+
 namespace {
 
 using namespace clang;
@@ -186,7 +191,7 @@
 
 void target() {
   D Bar;
-  A Foo = Bar.F1.F2.F3;
+  A &Foo = Bar.F1.F2.F3;
   int Zab = Foo.Unmodeled.X;
   // [[p]]
 }
@@ -200,8 +205,9 @@
 
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
-ASSERT_TRUE(FooDecl->getType()->isStructureType());
-auto FooFields = FooDecl->getType()->getAsRecordDecl()->fields();
+QualType FooReferentType = FooDecl->getType()->getPointeeType();
+ASSERT_TRUE(FooReferentType->isStructureType());
+auto FooFields = FooReferentType->getAsRecordDecl()->fields();
 
 FieldDecl *UnmodeledDecl = nullptr;
 for (FieldDecl *Field : FooFields) {
@@ -215,9 +221,9 @@
 
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
-const auto *UnmodeledLoc = &FooLoc->getChild(*UnmodeledDecl);
-ASSERT_TRUE(isa(UnmodeledLoc));
-ASSERT_THAT(Env.getValue(*UnmodeledLoc), IsNull());
+const auto *UnmodeledLoc = FooLoc->getChild(*UnmodeledDecl);
+ASSERT_TRUE(isa(UnmodeledLoc));
+EXPECT_THAT(Env.getValue(*UnmodeledLoc), IsNull());
 
 const ValueDecl *ZabDecl = findValueDecl(ASTCtx, "Zab");
 ASSERT_THAT(ZabDecl, NotNull());
@@ -263,7 +269,7 @@
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
 const auto *BarLoc =
-cast(&FooLoc->getChild(*BarDecl));
+cast(FooLoc->getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
 const auto *BarVal =
@@ -312,7 +318,7 @@
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
 const auto *BarLoc =
-cast(&FooLoc->getChild(*BarDecl));
+cast(FooLoc->getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
 const auto *BarVal =
@@ -360,7 +366,7 @@
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
 const auto *BarLoc =
-cast(&FooLoc->getChild(*BarDecl));
+cast(FooLoc->getChild(*BarDecl));
 
 const auto *FooVal = cast(Env.getValue(*FooLoc));
 const auto *BarVal =
@@ -479,34 +485,26 @@
 
 const auto &FooLoc =
 *cast(Env.getStorageLocation(*FooDecl));
-const auto &FooReferentVal = *cast(Env.getValue(FooLoc));
 
-const auto &BarVal =
-*cast(FooReferentVal.getChild(*BarDecl));
-const auto &BarReferentVal =
-*cast(Env.getValue(BarVal.getReferentLoc()));
+const auto &BarLoc =
+*cast(FooLoc.getChild(*BarDecl));
 
-const auto &FooRefVal =
-*cast(getFieldValue(&BarReferentVal, *FooRefDecl, Env));
 const auto &FooReferentLoc =
-cast(FooRefVal.getReferentLoc());
+*cast(BarLoc.getChild(*FooRefDecl));
 EXPECT_THAT(Env.getValue(FooReferentLoc), NotNull());
 EXPECT_THAT(getFieldValue(&FooReferentLoc, *BarDecl, Env), IsNull());
 
 const auto &FooPtrVal =
-*cast(getFieldValue(&BarReferentVal, *FooPtrDecl, Env));
+*cast(getFieldValue(&BarLoc, *FooPtrDecl, Env));
 const auto &FooPtrPointeeLoc =
 cast(FooPtrVal.getPointeeLoc());
 EXPECT_THAT(Env.getValue(FooPtrPointeeLoc), NotNull());
 EXPECT_THAT(getField

[PATCH] D149162: [Clang][OpenMP][IRBuilder] Move registerTargetGlobalVariable & getAddrOfDeclareTargetVar into the OMPIRBuilder

2023-07-20 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

`registerTargetGlobalVariable` has a iteration order issue using StringMap, 
caught by D155789 

  curl -L 'https://reviews.llvm.org/D155789?download=1' | patch -p1
  cmake ... -DLLVM_ENABLE_REVERSE_ITERATION=on
  ninja -C ... check-llvm-unit  #  `LLVM-Unit :: 
Frontend/./LLVMFrontendTests/OpenMPIRBuilderTest/registerTargetGlobalVariable` 
fails


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149162

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


[PATCH] D155446: [clang][dataflow] Eliminate duplication between `AggregateStorageLocation` and `StructValue`.

2023-07-20 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked 3 inline comments as done.
mboehme added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:466
+  return;
+Env.setStorageLocationStrict(*S, *MemberLoc);
   }

ymandel wrote:
> This diff makes me very happy. :)
Me too! :)



Comment at: clang/lib/Analysis/FlowSensitive/Transfer.cpp:496
+ Env.getValue(*Arg, SkipPast::Reference))) {
+if (auto *Val = cast(Env.createValue(S->getType( {
+  Env.setValueStrict(*S, *Val);

ymandel wrote:
> I thought `cast` requires a nonnull argument, so this will always be true?
Ah, good catch! Yes, the condition will always be true, so the if statement is 
superfluous. (We know `S->getType()` is a record type, and `Env.createValue()` 
will always create a value for record types.)

Removed the if statement.

(Confusingly, this comment now looks as if it's anchored to the if statement 
that does the `Env.getValue()`. The `cast_or_null` there _is_ necessary because 
we might not have a value for the argument.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155446

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


[PATCH] D155361: [Tooling] Avoid boilerplate in common cases

2023-07-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Example of using conusmeASTs + executeFromCommandLine

(It's not that many extra lines of code, but they're not really easy ones to 
write, and to work out whether they're minimal/correct)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155361

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


[PATCH] D155794: [OpenMP][OpenMPIRBuilder] Migrate setPropertyExecutionMode() from Clang to OpenMPIRBuilder.

2023-07-20 Thread Raghu via Phabricator via cfe-commits
raghavendhra created this revision.
Herald added subscribers: sunshaoce, guansong, hiraditya, yaxunl.
Herald added a project: All.
raghavendhra requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, cfe-commits, jplehr, sstefan1.
Herald added projects: clang, LLVM.

Move setPropertyExecutionMode() from Clang to OpenMPIRBuilder and change the 
references in Clang to use the function from OMPIRBuilder.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155794

Files:
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CodeGenModule.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4900,6 +4900,22 @@
   emitBlock(ContBlock, CurFn, /*IsFinished=*/true);
 }
 
+void OpenMPIRBuilder::setPropertyExecutionMode(
+StringRef Name, bool Mode,
+std::vector *LLVMCompilerUsed) {
+  auto *GVMode = new llvm::GlobalVariable(
+  M, llvm::Type::getInt8Ty(M.getContext()), /*isConstant=*/true,
+  llvm::GlobalValue::WeakAnyLinkage,
+  llvm::ConstantInt::get(llvm::Type::getInt8Ty(M.getContext()),
+ Mode ? OMP_TGT_EXEC_MODE_SPMD
+  : OMP_TGT_EXEC_MODE_GENERIC),
+  Twine(Name, "_exec_mode"));
+  GVMode->setVisibility(llvm::GlobalVariable::ProtectedVisibility);
+  assert(!GVMode->isDeclaration() &&
+ "Only globals with definition can force usage.");
+  LLVMCompilerUsed->emplace_back(GVMode);
+}
+
 bool OpenMPIRBuilder::checkAndEmitFlushAfterAtomic(
 const LocationDescription &Loc, llvm::AtomicOrdering AO, AtomicKind AK) {
   assert(!(AO == AtomicOrdering::NotAtomic ||
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1493,6 +1493,19 @@
   void emitIfClause(Value *Cond, BodyGenCallbackTy ThenGen,
 BodyGenCallbackTy ElseGen, InsertPointTy AllocaIP = {});
 
+  /// Create a unique global variable to indicate the execution mode of this
+  /// target region. The execution mode is either 'generic', or 'spmd' depending
+  /// on the target directive. This variable is picked up by the offload library
+  /// to setup the device appropriately before kernel launch. If the execution
+  /// mode is 'generic', the runtime reserves one warp for the master,
+  /// otherwise, all warps participate in parallel work. \param Name The symbol
+  /// name associated with the global. \param Mode Mode to indicate if the
+  /// kernel is an SPMD kernel or not. \param LLVMCompilerUsed List of global
+  /// values which are required to be present in the object file.
+  void
+  setPropertyExecutionMode(StringRef Name, bool Mode,
+   std::vector *LLVMCompilerUsed);
+
   /// Create the global variable holding the offload mappings information.
   GlobalVariable *createOffloadMaptypes(SmallVectorImpl &Mappings,
 std::string VarName);
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1005,6 +1005,10 @@
 return EmittedGlobalBlocks.lookup(BE);
   }
 
+  std::vector *getLLVMCompilerUsed() {
+return &LLVMCompilerUsed;
+  }
+
   /// Notes that BE's global block is available via Addr. Asserts that BE
   /// isn't already emitted.
   void setAddrOfGlobalBlock(const BlockExpr *BE, llvm::Constant *Addr);
Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
===
--- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -833,24 +833,6 @@
   IsInTTDRegion = false;
 }
 
-// Create a unique global variable to indicate the execution mode of this target
-// region. The execution mode is either 'generic', or 'spmd' depending on the
-// target directive. This variable is picked up by the offload library to setup
-// the device appropriately before kernel launch. If the execution mode is
-// 'generic', the runtime reserves one warp for the master, otherwise, all
-// warps participate in parallel work.
-static void setPropertyExecutionMode(CodeGenModule &CGM, StringRef Name,
- bool Mode) {
-  auto *GVMode = new llvm::GlobalVariable(
-  CGM.getModule(), CGM.Int8Ty, /*isConstant=*/true,
-  llvm::GlobalValue::WeakAnyLinkage,
-  llvm::ConstantInt::get(CGM.Int8Ty, Mode ? OMP_TGT_EXEC_MODE_SPMD
-  : OMP_TGT_EXEC_MODE_GENERIC),
-  Twine(Name, "_exec_mode"));
-  GVMode->s

[PATCH] D155773: [llvm][MemoryBuiltins] Add alloca support to getInitialValueOfAllocation

2023-07-20 Thread Nikita Popov via Phabricator via cfe-commits
nikic requested changes to this revision.
nikic added a comment.
This revision now requires changes to proceed.

> This commit is in support of future uninitialized memory handling and adds
> alloca instruction support to getInitialValueOfAllocation. This unifies 
> initial
> memory state querying (both stack and heap) to a single utility function.

Could you explain in more detail what future work you have based on this? Is 
this about the promotion of malloc (and similar) memory?

In any case, I don't think it's acceptable to go through TLI as a required 
dependency for mem2reg. Alloca promotion doesn't need it, and that's what all 
the existing code is doing. This should at least be an optional dependency.

However, I think it would be better to directly pass the initial value to 
mem2reg instead (defaulting to UndefValue), rather than making it query it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155773

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


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-20 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe created this revision.
Herald added subscribers: Enna1, pengfei, hiraditya.
Herald added a project: All.
FreddyYe requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM.
Herald added subscribers: llvm-commits, Sanitizers, cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155798

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -30,6 +30,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=emeraldrapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -88,6 +89,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -210,8 +210,7 @@
 FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureUINTR |
 FeatureWAITPKG;
 constexpr FeatureBitset FeaturesGraniteRapids =
-FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI |
-FeatureAMX_COMPLEX;
+FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI;
 
 // Intel Atom processors.
 // Bonnell has feature parity with Core2 and adds MOVBE.
@@ -428,7 +427,10 @@
   // Grandridge microarchitecture based processors.
   { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesGrandridge, 'p', false },
   // Granite Rapids microarchitecture based processors.
-  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids, 'n', false },
+  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids , 'n', false },
+  // Granite Rapids D microarchitecture based processors.
+  { {"graniterapids-d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', false },
+  { {"graniterapids_d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', true },
   // Emerald Rapids microarchitecture based processors.
   { {"emeraldrapids"}, CK_Emeraldrapids, FEATURE_AVX512BF16, FeaturesSapphireRapids, 'n', false },
   // Knights Landing processor.
Index: llvm/lib/TargetParser/Host.cpp
===
--- llvm/lib/TargetParser/Host.cpp
+++ llvm/lib/TargetParser/Host.cpp
@@ -833,13 +833,19 @@
   break;
 
 // Graniterapids:
-case 0xae:
 case 0xad:
   CPU = "graniterapids";
   *Type = X86::INTEL_COREI7;
   *Subtype = X86::INTEL_COREI7_GRANITERAPIDS;
   break;
 
+// Granite Rapids D:
+case 0xae:
+  CPU = "graniterapids-d";
+  *Type = X86::INTEL_COREI7;
+  *Subtype = X86::INTEL_COREI7_GRANITERAPIDS_D;
+  break;
+
 // Icelake Xeon:
 case 0x6a:
 case 0x6c:
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -1079,11 +1079

[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-20 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 542360.
FreddyYe added a comment.

add clang releasenote


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -30,6 +30,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=emeraldrapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -88,6 +89,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -210,8 +210,7 @@
 FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureUINTR |
 FeatureWAITPKG;
 constexpr FeatureBitset FeaturesGraniteRapids =
-FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI |
-FeatureAMX_COMPLEX;
+FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI;
 
 // Intel Atom processors.
 // Bonnell has feature parity with Core2 and adds MOVBE.
@@ -428,7 +427,10 @@
   // Grandridge microarchitecture based processors.
   { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesGrandridge, 'p', false },
   // Granite Rapids microarchitecture based processors.
-  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids, 'n', false },
+  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids , 'n', false },
+  // Granite Rapids D microarchitecture based processors.
+  { {"graniterapids-d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', false },
+  { {"graniterapids_d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', true },
   // Emerald Rapids microarchitecture based processors.
   { {"emeraldrapids"}, CK_Emeraldrapids, FEATURE_AVX512BF16, FeaturesSapphireRapids, 'n', false },
   // Knights Landing processor.
Index: llvm/lib/TargetParser/Host.cpp
===
--- llvm/lib/TargetParser/Host.cpp
+++ llvm/lib/TargetParser/Host.cpp
@@ -833,13 +833,19 @@
   break;
 
 // Graniterapids:
-case 0xae:
 case 0xad:
   CPU = "graniterapids";
   *Type = X86::INTEL_COREI7;
   *Subtype = X86::INTEL_COREI7_GRANITERAPIDS;
   break;
 
+// Granite Rapids D:
+case 0xae:
+  CPU = "graniterapids-d";
+  *Type = X86::INTEL_COREI7;
+  *Subtype = X86::INTEL_COREI7_GRANITERAPIDS_D;
+  break;
+
 // Icelake Xeon:
 case 0x6a:
 case 0x6c:
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -1079,11 +1079,16 @@
   // Graniterapids
   list GNRAdditionalFeatures = [FeatureAMXFP16,
 

[clang] 1ff1cbb - [LoongArch][NFC] Revise preprocessor test init-loongarch.c

2023-07-20 Thread Weining Lu via cfe-commits

Author: Weining Lu
Date: 2023-07-20T16:20:44+08:00
New Revision: 1ff1cbb595f0181360abbcfb54dacbe54f6301c8

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

LOG: [LoongArch][NFC] Revise preprocessor test init-loongarch.c

- Add `--match-full-lines` to FileCheck invocations.
- Remove useless `grep __loongarch_`s.

Added: 


Modified: 
clang/test/Preprocessor/init-loongarch.c

Removed: 




diff  --git a/clang/test/Preprocessor/init-loongarch.c 
b/clang/test/Preprocessor/init-loongarch.c
index 686c9681361e81..055431479f2425 100644
--- a/clang/test/Preprocessor/init-loongarch.c
+++ b/clang/test/Preprocessor/init-loongarch.c
@@ -3,16 +3,16 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple 
loongarch32-unknown-linux /dev/null \
 // RUN:   | FileCheck --match-full-lines --check-prefixes=LA32,LA32-LINUX %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple 
loongarch32 \
-// RUN: -fforce-enable-int128 /dev/null | FileCheck --match-full-lines \
-// RUN: --check-prefixes=LA32,LA32-INT128 %s
+// RUN:   -fforce-enable-int128 /dev/null | FileCheck --match-full-lines \
+// RUN:   --check-prefixes=LA32,LA32-INT128 %s
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple 
loongarch64 /dev/null \
 // RUN:   | FileCheck --match-full-lines --check-prefix=LA64 %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple 
loongarch64-unknown-linux /dev/null \
 // RUN:   | FileCheck --match-full-lines --check-prefixes=LA64,LA64-LINUX %s
 // RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple 
loongarch64 \
-// RUN: -fforce-enable-int128 /dev/null | FileCheck --match-full-lines \
-// RUN: --check-prefixes=LA64,LA64-INT128 %s
+// RUN:   -fforce-enable-int128 /dev/null | FileCheck --match-full-lines \
+// RUN:   --check-prefixes=LA64,LA64-INT128 %s
 
  Note that common macros are tested in init.c, such as __VERSION__. So 
they're not listed here.
 
@@ -650,141 +650,140 @@
 // LA64-LINUX: #define unix 1
 
 
-/// Check various macros prefixed with "__loongarch_" in 
diff erent cases.
-/// "__loongarch__"" is not listed here as it has been checked above.
+/// Check __loongarch_{double,single,hard,soft}_float, __loongarch_{gr,fr}len, 
__loongarch_lp64.
 
 // RUN: %clang --target=loongarch32 -mfpu=64 -mabi=ilp32d -x c -E -dM %s -o - \
-// RUN:   | grep __loongarch_ | FileCheck --check-prefix=LA32-FPU64-ILP32D %s
+// RUN:   | FileCheck --match-full-lines --check-prefix=LA32-FPU64-ILP32D %s
 // RUN: %clang --target=loongarch32 -mdouble-float -x c -E -dM %s -o - \
-// RUN:   | grep __loongarch_ | FileCheck --check-prefix=LA32-FPU64-ILP32D %s
-// LA32-FPU64-ILP32D: __loongarch_double_float 1
-// LA32-FPU64-ILP32D-NEXT: __loongarch_frlen 64
-// LA32-FPU64-ILP32D-NEXT: __loongarch_grlen 32
-// LA32-FPU64-ILP32D-NEXT: __loongarch_hard_float 1
-// LA32-FPU64-ILP32D-NOT: __loongarch_lp64
-// LA32-FPU64-ILP32D-NOT: __loongarch_single_float
-// LA32-FPU64-ILP32D-NOT: __loongarch_soft_float
+// RUN:   | FileCheck --match-full-lines --check-prefix=LA32-FPU64-ILP32D %s
+// LA32-FPU64-ILP32D: #define __loongarch_double_float 1
+// LA32-FPU64-ILP32D: #define __loongarch_frlen 64
+// LA32-FPU64-ILP32D: #define __loongarch_grlen 32
+// LA32-FPU64-ILP32D: #define __loongarch_hard_float 1
+// LA32-FPU64-ILP32D-NOT: #define __loongarch_lp64
+// LA32-FPU64-ILP32D-NOT: #define __loongarch_single_float
+// LA32-FPU64-ILP32D-NOT: #define __loongarch_soft_float
 
 // RUN: %clang --target=loongarch32 -mfpu=64 -mabi=ilp32f -x c -E -dM %s -o - \
-// RUN:   | grep __loongarch_ | FileCheck --check-prefix=LA32-FPU64-ILP32F %s
-// LA32-FPU64-ILP32F-NOT: __loongarch_double_float
-// LA32-FPU64-ILP32F: __loongarch_frlen 64
-// LA32-FPU64-ILP32F-NEXT: __loongarch_grlen 32
-// LA32-FPU64-ILP32F-NEXT: __loongarch_hard_float 1
-// LA32-FPU64-ILP32F-NOT: __loongarch_lp64
-// LA32-FPU64-ILP32F-NEXT: __loongarch_single_float 1
-// LA32-FPU64-ILP32F-NOT: __loongarch_soft_float
+// RUN:   | FileCheck --match-full-lines --check-prefix=LA32-FPU64-ILP32F %s
+// LA32-FPU64-ILP32F-NOT: #define __loongarch_double_float
+// LA32-FPU64-ILP32F: #define __loongarch_frlen 64
+// LA32-FPU64-ILP32F: #define __loongarch_grlen 32
+// LA32-FPU64-ILP32F: #define __loongarch_hard_float 1
+// LA32-FPU64-ILP32F-NOT: #define __loongarch_lp64
+// LA32-FPU64-ILP32F: #define __loongarch_single_float 1
+// LA32-FPU64-ILP32F-NOT: #define __loongarch_soft_float
 
 // RUN: %clang --target=loongarch32 -mfpu=64 -mabi=ilp32s -x c -E -dM %s -o - \
-// RUN:   | grep __loongarch_ | FileCheck --check-prefix=LA32-FPU64-ILP32S %s
-// LA32-FPU64-ILP32S-NOT: __loongarch_double_float
-// LA32-FPU64-ILP32S: __loongarch_frlen 64
-// LA32-FPU64-ILP32S-NEXT: __loongarch_grlen 32
-// LA32-FPU64-ILP32S

[PATCH] D155802: [clang][dataflow] Print the source line if we saw unexpected diagnostics in tests.

2023-07-20 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This makes it easier to determine which line the unexpected happened on;
previously, we would only get the line number.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155802

Files:
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
@@ -1334,7 +1335,17 @@
   auto &SrcMgr = AO.ASTCtx.getSourceManager();
   llvm::DenseSet DiagnosticLines;
   for (SourceLocation &Loc : Diagnostics) {
-DiagnosticLines.insert(SrcMgr.getPresumedLineNumber(Loc));
+unsigned Line = SrcMgr.getPresumedLineNumber(Loc);
+DiagnosticLines.insert(Line);
+if (!AnnotationLines.contains(Line)) {
+  IntrusiveRefCntPtr DiagOpts(
+  new DiagnosticOptions());
+  TextDiagnostic TD(llvm::errs(), AO.ASTCtx.getLangOpts(),
+DiagOpts.get());
+  TD.emitDiagnostic(
+  FullSourceLoc(Loc, SrcMgr), DiagnosticsEngine::Error,
+  "unexpected diagnostic", std::nullopt, std::nullopt);
+}
   }
 
   EXPECT_THAT(DiagnosticLines, ContainerEq(AnnotationLines));


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
@@ -1334,7 +1335,17 @@
   auto &SrcMgr = AO.ASTCtx.getSourceManager();
   llvm::DenseSet DiagnosticLines;
   for (SourceLocation &Loc : Diagnostics) {
-DiagnosticLines.insert(SrcMgr.getPresumedLineNumber(Loc));
+unsigned Line = SrcMgr.getPresumedLineNumber(Loc);
+DiagnosticLines.insert(Line);
+if (!AnnotationLines.contains(Line)) {
+  IntrusiveRefCntPtr DiagOpts(
+  new DiagnosticOptions());
+  TextDiagnostic TD(llvm::errs(), AO.ASTCtx.getLangOpts(),
+DiagOpts.get());
+  TD.emitDiagnostic(
+  FullSourceLoc(Loc, SrcMgr), DiagnosticsEngine::Error,
+  "unexpected diagnostic", std::nullopt, std::nullopt);
+}
   }
 
   EXPECT_THAT(DiagnosticLines, ContainerEq(AnnotationLines));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 443f490 - Revert "[CUDA][HIP] Use the same default language std as C++"

2023-07-20 Thread Sylvestre Ledru via cfe-commits

Author: Sylvestre Ledru
Date: 2023-07-20T10:54:54+02:00
New Revision: 443f490b6aac4af28500f4b09b68a13260f4fba9

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

LOG: Revert "[CUDA][HIP] Use the same default language std as C++"

This reverts commit 2d1d07152bd26b001dedec3400b4b01d3bb11622.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangStandards.def
clang/lib/Basic/LangStandards.cpp
clang/test/CodeGenCUDA/long-double.cu
clang/test/Driver/unknown-std.cpp
clang/test/Preprocessor/lang-std.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ef1cc898c21f6d..2287ff9d70da3f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -886,9 +886,6 @@ RISC-V Support
 
 CUDA/HIP Language Changes
 ^
-- Clang has been updated to align its default language standard for CUDA/HIP 
with
-  that of C++. The standard has now been enhanced to gnu++17, supplanting the
-  previously used c++14.
 
 CUDA Support
 

diff  --git a/clang/include/clang/Basic/LangStandards.def 
b/clang/include/clang/Basic/LangStandards.def
index 5c28bdd28ef257..911b626e4c9661 100644
--- a/clang/include/clang/Basic/LangStandards.def
+++ b/clang/include/clang/Basic/LangStandards.def
@@ -214,6 +214,14 @@ LANGSTANDARD_ALIAS_DEPR(openclcpp10, "CLC++")
 LANGSTANDARD_ALIAS_DEPR(openclcpp10, "CLC++1.0")
 LANGSTANDARD_ALIAS_DEPR(openclcpp2021, "CLC++2021")
 
+// CUDA
+LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)",
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
+
+// HIP
+LANGSTANDARD(hip, "hip", HIP, "HIP",
+ LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
+
 // HLSL
 LANGSTANDARD(hlsl, "hlsl",
  HLSL, "High Level Shader Language",

diff  --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index 033c0efe8d4f5d..c6a1a0acc2cb7e 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -54,6 +54,8 @@ LangStandard::Kind 
clang::getDefaultLanguageStandard(clang::Language Lang,
 return LangStandard::lang_opencl12;
   case Language::OpenCLCXX:
 return LangStandard::lang_openclcpp10;
+  case Language::CUDA:
+return LangStandard::lang_cuda;
   case Language::Asm:
   case Language::C:
 // The PS4 uses C99 as the default C standard.
@@ -64,13 +66,13 @@ LangStandard::Kind 
clang::getDefaultLanguageStandard(clang::Language Lang,
 return LangStandard::lang_gnu11;
   case Language::CXX:
   case Language::ObjCXX:
-  case Language::CUDA:
-  case Language::HIP:
 if (T.isPS())
   return LangStandard::lang_gnucxx14;
 return LangStandard::lang_gnucxx17;
   case Language::RenderScript:
 return LangStandard::lang_c99;
+  case Language::HIP:
+return LangStandard::lang_hip;
   case Language::HLSL:
 return LangStandard::lang_hlsl2021;
   }

diff  --git a/clang/test/CodeGenCUDA/long-double.cu 
b/clang/test/CodeGenCUDA/long-double.cu
index d52de972ea3da4..454a93ce5f6b6a 100644
--- a/clang/test/CodeGenCUDA/long-double.cu
+++ b/clang/test/CodeGenCUDA/long-double.cu
@@ -6,7 +6,7 @@
 // RUN:   -aux-triple x86_64-unknown-gnu-linux -fcuda-is-device \
 // RUN:   -emit-llvm -o - %s 2>&1 | FileCheck %s
 
-// CHECK: @_ZN15infinity_helperIeE5valueE = {{.*}} double 
0x47EFD586B834,{{.*}} align 8
+// CHECK: @_ZN15infinity_helperIeE5valueE = {{.*}} double 0x47EFD586B834, 
align 8
 // CHECK: @size = {{.*}} i32 8
 
 #include "Inputs/cuda.h"

diff  --git a/clang/test/Driver/unknown-std.cpp 
b/clang/test/Driver/unknown-std.cpp
index 5c58042a0a2c71..e918c087095ef0 100644
--- a/clang/test/Driver/unknown-std.cpp
+++ b/clang/test/Driver/unknown-std.cpp
@@ -4,10 +4,7 @@
 
 // RUN: not %clang %s -std=foobar -c 2>&1 | FileCheck --match-full-lines %s
 // RUN: not %clang -x objective-c++ %s -std=foobar -c 2>&1 | FileCheck 
--match-full-lines %s
-// RUN: not %clang -x cuda -nocudainc -nocudalib 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda \
-// RUN:   %s -std=foobar -c 2>&1 | FileCheck --match-full-lines %s
-// RUN: not %clang -x hip -nocudainc -nocudalib %s -std=foobar -c 2>&1 \
-// RUN:   | FileCheck --match-full-lines %s
+// RUN: not %clang -x cuda -nocudainc -nocudalib 
--cuda-path=%S/Inputs/CUDA/usr/local/cuda %s -std=foobar -c 2>&1 | FileCheck 
--match-full-lines --check-prefix=CHECK --check-prefix=CUDA %s
 
 // CHECK: error: invalid value 'foobar' in '-std=foobar'
 // CHECK-NEXT: note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' 
standard
@@ -24,6 +21,7 @@
 // CHECK-NEXT: note: use 'gnu++23' for 'ISO C++ 2023 DIS with GNU extensions' 
standard
 // CHECK-NEXT: note: use 'c++2c' or 'c++26' for 'Working draft for C++2c' 
standard
 // CHE

[PATCH] D155539: [CUDA][HIP] Use the same default language std as C++

2023-07-20 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

I reverted the patch for causing 
https://github.com/llvm/llvm-project/issues/63974
https://github.com/llvm/llvm-project/commit/443f490b6aac4af28500f4b09b68a13260f4fba9


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155539

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


[PATCH] D155574: [clang][ASTImporter] Fix import of recursive field initializer.

2023-07-20 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 542383.
balazske added a comment.

using clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155574

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


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8107,6 +8107,23 @@
   EXPECT_TRUE(ToX->getInClassInitializer());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportRecursiveFieldInitializer) {
+  const char *Code =
+  R"(
+  class A {
+int b{b};
+  };
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+  auto *FromB =
+  FirstDeclMatcher().match(FromTU, fieldDecl(hasName("b")));
+  EXPECT_TRUE(FromB->hasInClassInitializer());
+
+  auto *ToB = Import(FromB, Lang_CXX11);
+  EXPECT_TRUE(ToB->hasInClassInitializer());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, isNewDecl) {
   Decl *FromTU = getTuDecl(
   R"(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3902,7 +3902,6 @@
   auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
   auto ToBitWidth = importChecked(Err, D->getBitWidth());
   auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
-  auto ToInitializer = importChecked(Err, D->getInClassInitializer());
   if (Err)
 return std::move(Err);
   const Type *ToCapturedVLAType = nullptr;
@@ -3925,12 +3924,17 @@
 return std::move(Err);
   ToField->setAccess(D->getAccess());
   ToField->setLexicalDeclContext(LexicalDC);
-  if (ToInitializer)
-ToField->setInClassInitializer(ToInitializer);
   ToField->setImplicit(D->isImplicit());
   if (ToCapturedVLAType)
 ToField->setCapturedVLAType(cast(ToCapturedVLAType));
   LexicalDC->addDeclInternal(ToField);
+  // Import initializer only after the field was created, it may have recursive
+  // reference to the field.
+  auto ToInitializer = importChecked(Err, D->getInClassInitializer());
+  if (Err)
+return std::move(Err);
+  if (ToInitializer)
+ToField->setInClassInitializer(ToInitializer);
   return ToField;
 }
 


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -8107,6 +8107,23 @@
   EXPECT_TRUE(ToX->getInClassInitializer());
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase, ImportRecursiveFieldInitializer) {
+  const char *Code =
+  R"(
+  class A {
+int b{b};
+  };
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+
+  auto *FromB =
+  FirstDeclMatcher().match(FromTU, fieldDecl(hasName("b")));
+  EXPECT_TRUE(FromB->hasInClassInitializer());
+
+  auto *ToB = Import(FromB, Lang_CXX11);
+  EXPECT_TRUE(ToB->hasInClassInitializer());
+}
+
 TEST_P(ASTImporterOptionSpecificTestBase, isNewDecl) {
   Decl *FromTU = getTuDecl(
   R"(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3902,7 +3902,6 @@
   auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
   auto ToBitWidth = importChecked(Err, D->getBitWidth());
   auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
-  auto ToInitializer = importChecked(Err, D->getInClassInitializer());
   if (Err)
 return std::move(Err);
   const Type *ToCapturedVLAType = nullptr;
@@ -3925,12 +3924,17 @@
 return std::move(Err);
   ToField->setAccess(D->getAccess());
   ToField->setLexicalDeclContext(LexicalDC);
-  if (ToInitializer)
-ToField->setInClassInitializer(ToInitializer);
   ToField->setImplicit(D->isImplicit());
   if (ToCapturedVLAType)
 ToField->setCapturedVLAType(cast(ToCapturedVLAType));
   LexicalDC->addDeclInternal(ToField);
+  // Import initializer only after the field was created, it may have recursive
+  // reference to the field.
+  auto ToInitializer = importChecked(Err, D->getInClassInitializer());
+  if (Err)
+return std::move(Err);
+  if (ToInitializer)
+ToField->setInClassInitializer(ToInitializer);
   return ToField;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 542389.
cor3ntin added a comment.

Correctly track constructor location.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

Files:
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/cxx2c-consteval-propagate.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
===
--- clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -34,7 +34,7 @@
 
 template 
 constexpr T h(T t = id(x)) { // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}} \
- // expected-note 2{{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+ // expected-note {{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
 return t;
 }
 
@@ -164,3 +164,169 @@
 int i = g(x); // expected-error {{call to immediate function 'ConstevalConstructor::g' is not a constant expression}} \
   // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}}
 }
+
+
+
+namespace Aggregate {
+consteval int f(int); // expected-note {{declared here}}
+struct S {
+  int x = f(42); // expected-note {{undefined function 'f' cannot be used in a constant expression}} \
+ // expected-note {{'immediate' is an immediate function because its body contains a call to a consteval function 'f' and that call is not a constant expression}}
+};
+
+constexpr S immediate(auto) {
+return S{};
+}
+
+void test_runtime() {
+(void)immediate(0); // expected-error {{call to immediate function 'Aggregate::immediate' is not a constant expression}} \
+// expected-note {{in call to 'immediate(0)'}}
+}
+consteval int f(int i) {
+return i;
+}
+consteval void test() {
+constexpr S s = immediate(0);
+static_assert(s.x == 42);
+}
+}
+
+
+
+namespace GH63742 {
+void side_effect(); // expected-note  {{declared here}}
+consteval int f(int x) {
+if (!x) side_effect(); // expected-note {{non-constexpr function 'side_effect' cannot be used in a constant expression}}
+return x;
+}
+struct SS {
+  int y = f(1); // Ok
+  int x = f(0); // expected-error {{call to consteval function 'GH63742::f' is not a constant expression}} \
+// expected-note  {{declared here}} \
+// expected-note  {{in call to 'f(0)'}}
+  SS();
+};
+SS::SS(){} // expected-note {{in the default initializer of 'x'}}
+
+consteval int f2(int x) {
+if (!__builtin_is_constant_evaluated()) side_effect();
+return x;
+}
+struct S2 {
+int x = f2(0);
+constexpr S2();
+};
+
+constexpr S2::S2(){}
+S2 s = {};
+constinit S2 s2 = {};
+
+struct S3 {
+int x = f2(0);
+S3();
+};
+S3::S3(){}
+
+}
+
+namespace Defaulted {
+consteval int f(int x);
+struct SS {
+  int x = f(0);
+  SS() = default;
+};
+}
+
+namespace DefaultedUse{
+consteval int f(int x);  // expected-note {{declared here}}
+struct SS {
+  int a = sizeof(f(0)); // Ok
+  int x = f(0); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
+
+  SS() = default; // expected-note {{'SS' is an immediate constructor because the default initializer of 'x' contains a call to a consteval function 'f' and that call is not a constant expression}}
+};
+
+void test() {
+[[maybe_unused]] SS s; // expected-error {{call to immediate function 'DefaultedUse::SS::SS' is not a constant expression}} \
+   //  expected-note {{in call to 'SS()'}}
+}
+}
+
+namespace UserDefinedConstructors {
+consteval int f(int x) {
+return x;
+}
+extern int NonConst; // expected-note 2{{declared here}}
+
+struct ConstevalCtr {
+int y;
+int x = f(y);
+consteval ConstevalCtr(int yy)
+: y(f(yy)) {}
+};
+
+ConstevalCtr c1(1);
+ConstevalCtr c2(NonConst);
+// expected-error@-1 {{call to consteval function 'UserDefinedConstructors::ConstevalCtr::ConstevalCtr' is not a constant expression}} \
+// expected-note@-1 {{read of non-const variable 'NonConst' is not allowed in a constant expression}}
+
+struct ImmediateEscalating {
+int y;
+int x = f(y);
+template
+constexpr ImmediateEscalating(T yy) // expected-note {{ImmediateEscalating' is an immediate constructor because the initializer of 'y' contains a call to a consteval function 'f' and that call is not 

[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

2023-07-20 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> Can you explain why the fix fixes the bug?

Sure, let me try. To be honest, I'm not very familiar with the code either, so 
I'll describe how I came to the fix. I'll be using added test 
`clang/test/SemaTemplate/gh61159.cpp` as example of failing code. The issue 
happens when instantiating `X::impl::f`.
So, the original assertion reported by 
https://github.com/llvm/llvm-project/issues/61159 happens in a function 
`Sema::BuildExpressionFromIntegralTemplateArgument`, because it expects 
non-type integral argument, but receives type argument:

  clang/lib/Sema/SemaTemplate.cpp
  7955Sema::BuildExpressionFromIntegralTemplateArgument(const 
TemplateArgument &Arg,
  7956  SourceLocation 
Loc) {   
  7957  assert(Arg.getKind() == TemplateArgument::Integral &&   

  7958 "Operation is only valid for integral template 
arguments");
  
  (gdb) p Arg.dump()
  int  // that is type argument `int` from outer specialization of struct X.

So, let's see where the argument comes from, for this I went two frames of back 
upper, to function `TemplateInstantiator::TransformTemplateParmRefExpr`:

  clang/lib/Sema/SemaTemplateInstantiate.cpp
  1789  TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), 
NTTP->getPosition());
  
  NTTP is a NonTypeTemplateParmDecl that represents template parameter ct of 
function f
  (gdb) p NTTP->dump()
  NonTypeTemplateParmDecl 0x14b76380  col:18 referenced 
'int' depth 0 index 0 ct
  TemplateArgs is a MultiLevelTemplateArgumentList - data structure containing 
arguments for current instantiation 
  (gdb) p TemplateArgs.dump()
  NumRetainedOuterLevels: 0
  0: 
  1: <17>
  We see it has two arguments - "int" and "17", we should be processing "17" 
but instead end up with "int". Both have same indexes since there is only one 
argument possible, so they should have different depth. For "17" we have zero 
depth.
  (gdb) p NTTP->getDepth()
  $8 = 0

So, after that I went to the place where NonTypeTemplateParmDecl is created to 
see why it has depth "0" instead of "1".

  (gdb) b NonTypeTemplateParmDecl::Create
  (gdb) up several times to see where Depth parameters come from
  
  and it is here:
  clang/lib/Parse/ParseTemplate.cpp
  
  130 if (ParseTemplateParameters(TemplateParamScopes,  
  
  131 
CurTemplateDepthTracker.getDepth(), 
  132 TemplateParams, LAngleLoc, 
RAngleLoc)) {
  133   // Skip until the semi-colon or a '}'.  
  
  134   SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);  
  
  135   TryConsumeToken(tok::semi); 
  
  136   return nullptr; 
  
  137 } 
   
  
  CurTemplateDepthTracker.getDepth() is increased only if template parameter 
list of the declaration being parsed is not empty, i.e. when declaration we 
have is not an explicit specialization:
  
  139 ExprResult OptionalRequiresClauseConstraintER;
  140 if (!TemplateParams.empty()) {
  141   isSpecialization = false;   
  142   ++CurTemplateDepthTracker;  
  
  
  But this is exactly what we have! So we end up having zero depth for our 
NTTP.   

I tried increasing depth unconditionally but it broke handful of tests and 
seems zero depth for cases like this is on purpose so that is not the solution. 
So I figured similar test case which doesn't crash:

  template <>
  struct X {
struct impl {
  template
  int f() { return ct; };
   };
  };
  }

And went through the clang code that was failing for the original example:

  7954ExprResult
 
  7955Sema::BuildExpressionFromIntegralTemplateArgument(const 
TemplateArgument &Arg, 
  7956  SourceLocation 
Loc) {
  7957  assert(Arg.getKind() == TemplateArgument::Integral &&   
  
  
  (gdb) p Arg.dump()
  17 // correct!
  
  Let's go see corresponding NTTP and MultiLevelTemplateArgumentList :
  
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  1789  TemplateArgument Arg = TemplateArgs(NTTP->getDepth(), 
NTTP->getPosition());
  
  (gdb) p NTTP->dump()
  NonTypeTemplateParmDecl 0x14b761b8  col:15 referenced 
'int' depth 0 index 0 ct // all same
  
  (gdb) p TemplateArgs.dump()
  NumRetainedOuterLevels: 0
  0: <17>
  
  TemplateArgs doesn't have "int" paramter at all so all is correct.

So

[PATCH] D139267: Supporting tbaa.struct metadata generation for bitfields

2023-07-20 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 added a comment.
Herald added a subscriber: wangpc.

Ping


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

https://reviews.llvm.org/D139267

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


[PATCH] D154186: [clang][DeclPrinter] Fix AST print of delegating constructors

2023-07-20 Thread Timo Stripf via Phabricator via cfe-commits
strimo378 marked 3 inline comments as done.
strimo378 added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154186

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


[PATCH] D155452: [Flang] Add support for fsave-optimization-record

2023-07-20 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added a comment.

Please check the failing test.




Comment at: flang/test/Driver/fsave-optimization-record.f90:14
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -o %t.o %s
+! RUN: cat %t.opt.yaml | FileCheck %s





Comment at: flang/test/Driver/fsave-optimization-record.f90:19
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -emit-llvm -o %t.o %s
+! RUN: cat %t.opt.yaml




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155452

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


[clang] 578b0bd - [Clang][AArch64][SME] Add ZA zeroing intrinsics

2023-07-20 Thread Bryan Chan via cfe-commits

Author: Bryan Chan
Date: 2023-07-20T06:06:34-04:00
New Revision: 578b0bd4e621304a1ce367e87a53e59e404dec9b

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

LOG: [Clang][AArch64][SME] Add ZA zeroing intrinsics

 This patch adds support for the following SME ACLE intrinsics (as defined
 in https://arm-software.github.io/acle/main/acle.html):

   - svzero_mask_za
   - svzero_za

Co-authored-by: Sagar Kulkarni 

Reviewed By: sdesmalen

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

Added: 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c

Modified: 
clang/include/clang/Basic/arm_sme.td
clang/include/clang/Basic/arm_sve_sme_incl.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 4f82615bfb9d95..7c1daf46adfb13 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -114,3 +114,14 @@ defm SVWRITE_ZA16 : ZAWrite<"za16", "sUshb", 
"aarch64_sme_write", [ImmCheck<0, I
 defm SVWRITE_ZA32 : ZAWrite<"za32", "iUif", "aarch64_sme_write", [ImmCheck<0, 
ImmCheck0_3>, ImmCheck<2, ImmCheck0_3>]>;
 defm SVWRITE_ZA64 : ZAWrite<"za64", "lUld", "aarch64_sme_write", [ImmCheck<0, 
ImmCheck0_7>, ImmCheck<2, ImmCheck0_1>]>;
 defm SVWRITE_ZA128 : ZAWrite<"za128", "csilUcUsUiUlhbfd", 
"aarch64_sme_writeq", [ImmCheck<0, ImmCheck0_15>, ImmCheck<2, ImmCheck0_0>]>;
+
+
+// SME - Zero
+
+let TargetGuard = "sme" in {
+  def SVZERO_MASK_ZA : SInst<"svzero_mask_za", "vi", "", MergeNone, 
"aarch64_sme_zero",
+ [IsOverloadNone, IsStreamingCompatible, 
IsSharedZA],
+ [ImmCheck<0, ImmCheck0_255>]>;
+  def SVZERO_ZA  : SInst<"svzero_za", "v", "", MergeNone, 
"aarch64_sme_zero",
+ [IsOverloadNone, IsStreamingCompatible, 
IsSharedZA]>;
+}

diff  --git a/clang/include/clang/Basic/arm_sve_sme_incl.td 
b/clang/include/clang/Basic/arm_sve_sme_incl.td
index e664b8b3e3f63a..74c9b9266771b0 100644
--- a/clang/include/clang/Basic/arm_sve_sme_incl.td
+++ b/clang/include/clang/Basic/arm_sve_sme_incl.td
@@ -245,6 +245,7 @@ def ImmCheck0_2 : ImmCheckType<14>; // 0..2
 def ImmCheck0_3 : ImmCheckType<15>; // 0..3
 def ImmCheck0_0 : ImmCheckType<16>; // 0..0
 def ImmCheck0_15: ImmCheckType<17>; // 0..15
+def ImmCheck0_255   : ImmCheckType<18>; // 0..255
 
 class ImmCheck {
   int Arg = arg;

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9d9ad162c6f5d3..599539e1fa4343 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9495,6 +9495,16 @@ Value *CodeGenFunction::EmitSMEReadWrite(SVETypeFlags 
TypeFlags,
   return Builder.CreateCall(F, Ops);
 }
 
+Value *CodeGenFunction::EmitSMEZero(SVETypeFlags TypeFlags,
+SmallVectorImpl &Ops,
+unsigned IntID) {
+  // svzero_za() intrinsic zeros the entire za tile and has no paramters.
+  if (Ops.size() == 0)
+Ops.push_back(llvm::ConstantInt::get(Int32Ty, 255));
+  Function *F = CGM.getIntrinsic(IntID, {});
+  return Builder.CreateCall(F, Ops);
+}
+
 // Limit the usage of scalable llvm IR generated by the ACLE by using the
 // sve dup.x intrinsic instead of IRBuilder::CreateVectorSplat.
 Value *CodeGenFunction::EmitSVEDupX(Value *Scalar, llvm::Type *Ty) {
@@ -9955,6 +9965,9 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
 return EmitSMELd1St1(TypeFlags, Ops, Builtin->LLVMIntrinsic);
   else if (TypeFlags.isReadZA() || TypeFlags.isWriteZA())
 return EmitSMEReadWrite(TypeFlags, Ops, Builtin->LLVMIntrinsic);
+  else if (BuiltinID == SME::BI__builtin_sme_svzero_mask_za ||
+   BuiltinID == SME::BI__builtin_sme_svzero_za)
+return EmitSMEZero(TypeFlags, Ops, Builtin->LLVMIntrinsic);
 
   /// Should not happen
   return nullptr;

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 246050b341d67b..8292163ab3365c 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4283,6 +4283,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   llvm::Value *EmitSMEReadWrite(SVETypeFlags TypeFlags,
 llvm::SmallVectorImpl &Ops,
 unsigned IntID);
+  llvm::Value *EmitSMEZero(SVETypeFlags TypeFlags,
+   llvm::SmallVectorImpl &Ops,
+  

[clang] f225898 - [Clang][AArch64][SME] Add intrinsics for ZA array load/store (LDR/STR)

2023-07-20 Thread Bryan Chan via cfe-commits

Author: Bryan Chan
Date: 2023-07-20T06:06:35-04:00
New Revision: f225898a7c6105aa34e64f9c7dbfed7ce3443331

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

LOG: [Clang][AArch64][SME] Add intrinsics for ZA array load/store (LDR/STR)

This patch adds support for the following SME ACLE intrinsics (as defined
in https://arm-software.github.io/acle/main/acle.html):

  - svldr_vnum_za
  - svstr_vnum_za

Co-authored-by: Sagar Kulkarni 

Reviewed By: sdesmalen

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

Added: 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c

Modified: 
clang/include/clang/Basic/arm_sme.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h
clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 7c1daf46adfb13..945f212963d6c9 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -44,6 +44,11 @@ defm SVLD1_ZA32 : ZALoad<"za32", "i", "aarch64_sme_ld1w", 
[ImmCheck<0, ImmCheck0
 defm SVLD1_ZA64 : ZALoad<"za64", "l", "aarch64_sme_ld1d", [ImmCheck<0, 
ImmCheck0_7>, ImmCheck<2, ImmCheck0_1>]>;
 defm SVLD1_ZA128 : ZALoad<"za128", "q", "aarch64_sme_ld1q", [ImmCheck<0, 
ImmCheck0_15>, ImmCheck<2, ImmCheck0_0>]>;
 
+def SVLDR_VNUM_ZA : MInst<"svldr_vnum_za", "vmiQ", "",
+  [IsOverloadNone, IsStreamingCompatible, IsSharedZA],
+  MemEltTyDefault, "aarch64_sme_ldr",
+  [ImmCheck<1, ImmCheck0_15>]>;
+
 

 // Stores
 
@@ -73,6 +78,11 @@ defm SVST1_ZA32 : ZAStore<"za32", "i", "aarch64_sme_st1w", 
[ImmCheck<0, ImmCheck
 defm SVST1_ZA64 : ZAStore<"za64", "l", "aarch64_sme_st1d", [ImmCheck<0, 
ImmCheck0_7>, ImmCheck<2, ImmCheck0_1>]>;
 defm SVST1_ZA128 : ZAStore<"za128", "q", "aarch64_sme_st1q", [ImmCheck<0, 
ImmCheck0_15>, ImmCheck<2, ImmCheck0_0>]>;
 
+def SVSTR_VNUM_ZA : MInst<"svstr_vnum_za", "vmi%", "",
+  [IsOverloadNone, IsStreamingCompatible, IsSharedZA, 
IsPreservesZA],
+  MemEltTyDefault, "aarch64_sme_str",
+  [ImmCheck<1, ImmCheck0_15>]>;
+
 

 // Read horizontal/vertical ZA slices
 

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 599539e1fa4343..416c220351267a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9505,6 +9505,22 @@ Value *CodeGenFunction::EmitSMEZero(SVETypeFlags 
TypeFlags,
   return Builder.CreateCall(F, Ops);
 }
 
+Value *CodeGenFunction::EmitSMELdrStr(SVETypeFlags TypeFlags,
+  SmallVectorImpl &Ops,
+  unsigned IntID) {
+  Function *Vscale = CGM.getIntrinsic(Intrinsic::vscale, Int64Ty);
+  llvm::Value *VscaleCall = Builder.CreateCall(Vscale, {}, "vscale");
+  llvm::Value *MulVL = Builder.CreateMul(
+  VscaleCall,
+  Builder.getInt64(16 * cast(Ops[1])->getZExtValue()),
+  "mulvl");
+  Ops[2] = Builder.CreateGEP(Int8Ty, Ops[2], MulVL);
+  Ops[0] = EmitTileslice(Ops[1], Ops[0]);
+  Ops.erase(&Ops[1]);
+  Function *F = CGM.getIntrinsic(IntID, {});
+  return Builder.CreateCall(F, Ops);
+}
+
 // Limit the usage of scalable llvm IR generated by the ACLE by using the
 // sve dup.x intrinsic instead of IRBuilder::CreateVectorSplat.
 Value *CodeGenFunction::EmitSVEDupX(Value *Scalar, llvm::Type *Ty) {
@@ -9968,6 +9984,9 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
   else if (BuiltinID == SME::BI__builtin_sme_svzero_mask_za ||
BuiltinID == SME::BI__builtin_sme_svzero_za)
 return EmitSMEZero(TypeFlags, Ops, Builtin->LLVMIntrinsic);
+  else if (BuiltinID == SME::BI__builtin_sme_svldr_vnum_za ||
+   BuiltinID == SME::BI__builtin_sme_svstr_vnum_za)
+return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
 
   /// Should not happen
   return nullptr;

diff  --git a/clang/lib/CodeGen/CodeGenFunction.h 
b/clang/lib/CodeGen/CodeGenFunction.h
index 8292163ab3365c..409f48a04906e2 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4286,6 +4286,9 @@ class CodeGenFunction : public CodeGenTypeCache {
   llvm::Value *EmitSMEZero(SVETypeFlags TypeFlags,
llvm::SmallVectorImpl &Ops,
unsigned IntID);
+  llvm::Value *EmitSMELdrStr(SVETypeFlags TypeFlags,
+ llvm::SmallVectorImpl &Ops,
+

[clang] 15d16a7 - [Clang][AArch64][SME] Add intrinsics for reading streaming vector length

2023-07-20 Thread Bryan Chan via cfe-commits

Author: Bryan Chan
Date: 2023-07-20T06:06:35-04:00
New Revision: 15d16a79a01f4fac718556809ecd00914dd7d7a2

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

LOG: [Clang][AArch64][SME] Add intrinsics for reading streaming vector length

This patch adds support for the following SME ACLE intrinsics (as defined
in https://arm-software.github.io/acle/main/acle.html):

  - svcntsb
  - svcntsh
  - svcntsw
  - svcntsd

Co-authored-by: Sagar Kulkarni 

Reviewed By: sdesmalen

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

Added: 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c

Modified: 
clang/include/clang/Basic/arm_sme.td
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 945f212963d6c9..74ba023f4f42cf 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -135,3 +135,19 @@ let TargetGuard = "sme" in {
   def SVZERO_ZA  : SInst<"svzero_za", "v", "", MergeNone, 
"aarch64_sme_zero",
  [IsOverloadNone, IsStreamingCompatible, 
IsSharedZA]>;
 }
+
+
+// SME - Counting elements in a streaming vector
+
+multiclass ZACount {
+  let TargetGuard = "sme" in {
+def NAME : SInst<"sv" # n_suffix, "nv", "", MergeNone,
+  "aarch64_sme_" # n_suffix,
+  [IsOverloadNone, IsStreamingCompatible, IsPreservesZA]>;
+  }
+}
+
+defm SVCNTSB : ZACount<"cntsb">;
+defm SVCNTSH : ZACount<"cntsh">;
+defm SVCNTSW : ZACount<"cntsw">;
+defm SVCNTSD : ZACount<"cntsd">;

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 416c220351267a..d8d1e7aa96ca7a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9955,6 +9955,7 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
   getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments);
   assert(Error == ASTContext::GE_None && "Should not codegen an error");
 
+  llvm::Type *Ty = ConvertType(E->getType());
   llvm::SmallVector Ops;
   for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
 if ((ICEArguments & (1 << i)) == 0)
@@ -9987,6 +9988,12 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
   else if (BuiltinID == SME::BI__builtin_sme_svldr_vnum_za ||
BuiltinID == SME::BI__builtin_sme_svstr_vnum_za)
 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
+  else if (Builtin->LLVMIntrinsic != 0) {
+Function *F = CGM.getIntrinsic(Builtin->LLVMIntrinsic,
+   getSVEOverloadTypes(TypeFlags, Ty, Ops));
+Value *Call = Builder.CreateCall(F, Ops);
+return Call;
+  }
 
   /// Should not happen
   return nullptr;

diff  --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c
new file mode 100644
index 00..b3b2499a383033
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c
@@ -0,0 +1,46 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+// CHECK-C-LABEL: @test_svcntsb(
+// CHECK-CXX-LABEL: @_Z12test_svcntsbv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntsb() {
+  return svcntsb();
+}
+
+// CHECK-C-LABEL: @test_svcntsh(
+// CHECK-CXX-LABEL: @_Z12test_svcntshv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsh()
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntsh() {
+  return svcntsh();
+}
+
+// CHECK-C-LABEL: @test_svcntsw(
+// CHECK-CXX-LABEL: @_Z12test_svcntswv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsw()
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntsw() {
+  return svcntsw();
+}
+
+// CHECK-C-LABEL: @test_svcntsd(
+// CHECK-CXX-LABEL: @_Z12test_svcntsdv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsd()
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntsd() {
+  return svcntsd();
+}



__

[clang] 4ae900c - [Clang][AArch64][SME] Add intrinsics for adding vector elements to ZA tile

2023-07-20 Thread Bryan Chan via cfe-commits

Author: Bryan Chan
Date: 2023-07-20T06:06:36-04:00
New Revision: 4ae900c063634e19346b88913e28204a3fc47825

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

LOG: [Clang][AArch64][SME] Add intrinsics for adding vector elements to ZA tile

This patch adds support for the following SME ACLE intrinsics (as defined
in https://arm-software.github.io/acle/main/acle.html):

  - svaddha_za32[_u32]_m // also for s32
  - svaddva_za32[_u32]_m // also for s32
  - svaddha_za64[_u64]_m // also for s64
  - svaddva_za64[_u64]_m // also for s64

The _za64 versions are available only when the sme-i16i64 feature is enabled.

Co-authored-by: Sagar Kulkarni 

Reviewed By: sdesmalen

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

Added: 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i32.c
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c

Modified: 
clang/include/clang/Basic/arm_sme.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 74ba023f4f42cf..f6c2fb5fd7f6b6 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -151,3 +151,23 @@ defm SVCNTSB : ZACount<"cntsb">;
 defm SVCNTSH : ZACount<"cntsh">;
 defm SVCNTSW : ZACount<"cntsw">;
 defm SVCNTSD : ZACount<"cntsd">;
+
+
+// SME - ADDHA/ADDVA
+
+multiclass ZAAdd {
+  let TargetGuard = "sme" in {
+def NAME # _ZA32: SInst<"sv" # n_suffix # "_za32[_{d}]", "viPPd", "iUi", 
MergeOp1,
+  "aarch64_sme_" # n_suffix, [IsStreaming, IsSharedZA],
+  [ImmCheck<0, ImmCheck0_3>]>;
+  }
+
+  let TargetGuard = "sme-i16i64" in {
+def NAME # _ZA64: SInst<"sv" # n_suffix # "_za64[_{d}]", "viPPd", "lUl", 
MergeOp1,
+ "aarch64_sme_" # n_suffix, [IsStreaming, IsSharedZA],
+ [ImmCheck<0, ImmCheck0_7>]>;
+  }
+}
+
+defm SVADDHA : ZAAdd<"addha">;
+defm SVADDVA : ZAAdd<"addva">;

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d8d1e7aa96ca7a..b7fbafda0e5336 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9989,6 +9989,12 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
BuiltinID == SME::BI__builtin_sme_svstr_vnum_za)
 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
   else if (Builtin->LLVMIntrinsic != 0) {
+// Predicates must match the main datatype.
+for (unsigned i = 0, e = Ops.size(); i != e; ++i)
+  if (auto PredTy = dyn_cast(Ops[i]->getType()))
+if (PredTy->getElementType()->isIntegerTy(1))
+  Ops[i] = EmitSVEPredicateCast(Ops[i], getSVEType(TypeFlags));
+
 Function *F = CGM.getIntrinsic(Builtin->LLVMIntrinsic,
getSVEOverloadTypes(TypeFlags, Ty, Ops));
 Value *Call = Builder.CreateCall(F, Ops);

diff  --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i32.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i32.c
new file mode 100644
index 00..b083df79f6
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i32.c
@@ -0,0 +1,110 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | 
FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ 
%s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+#ifdef SME_OVERLOADED_FORMS
+#define SME_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SME_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-C-LABEL: @test_svaddha_za32_u32(
+// CHECK-CXX-LABEL: 
@_Z21test_svaddha_za32_u32u10__SVBool_tu10__SVBool_tu12__SVUint32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svbool.nxv4i1( [[PN:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  
@llvm.aarch64.sve.convert.from.svb

[clang] aebde82 - [Clang][AArch64][SME] Add outer product intrinsics

2023-07-20 Thread Bryan Chan via cfe-commits

Author: Bryan Chan
Date: 2023-07-20T06:06:36-04:00
New Revision: aebde82b29a80b2849e2b5b1b0030f598edee9a4

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

LOG: [Clang][AArch64][SME] Add outer product intrinsics

This patch adds support for the following SME ACLE intrinsics (as defined
in https://arm-software.github.io/acle/main/acle.html):

  - svmopa_za32[_bf16]_m  // also for s8, u8, f16, f32
  - svmops_za32[_bf16]_m  // also for s8, u8, f16, f32
  - svsumopa_za32[_s8]_m
  - svsumops_za32[_s8]_m
  - svusmopa_za32[_u8]_m
  - svusmops_za32[_u8]_m

When the sme-f64f64 feature is enabled, the following intrinsics are supported:

  - svmopa_za64_f64_m
  - svmops_za64_f64_m

When the sme-i16i64 feature is enabled, the following intrinsics are supported:

  - svmopa_za64[_s16]_m   // also for u16
  - svmops_za64[_s16]_m   // also for u16
  - svsumopa_za64[_s16]_m
  - svsumops_za64[_s16]_m
  - svusmopa_za64[_u16]_m
  - svusmops_za64[_u16]_m

Co-authored-by: Sagar Kulkarni 

Reviewed By: sdesmalen

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

Added: 
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za32.c
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za32.c
clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c

Modified: 
clang/include/clang/Basic/arm_sme.td
clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index f6c2fb5fd7f6b6..b950f5cb8acc20 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -171,3 +171,89 @@ multiclass ZAAdd {
 
 defm SVADDHA : ZAAdd<"addha">;
 defm SVADDVA : ZAAdd<"addva">;
+
+
+// SME - SMOPA, SMOPS, UMOPA, UMOPS
+
+multiclass ZAIntOuterProd {
+  let TargetGuard = "sme" in {
+def NAME # _ZA32_B: SInst<"sv" # n_suffix2 # "_za32[_{d}]",
+  "viPPdd", !cond(!eq(n_suffix1, "s") : "", true: 
"U") # "c",
+  MergeOp1, "aarch64_sme_" # n_suffix1 # n_suffix2 
# "_wide",
+  [IsStreaming, IsSharedZA],
+  [ImmCheck<0, ImmCheck0_3>]>;
+  }
+
+  let TargetGuard = "sme-i16i64" in {
+def NAME # _ZA64_H: SInst<"sv" # n_suffix2 # "_za64[_{d}]",
+  "viPPdd", !cond(!eq(n_suffix1, "s") : "", true: 
"U") # "s",
+  MergeOp1, "aarch64_sme_" # n_suffix1 # n_suffix2 
# "_wide",
+  [IsStreaming, IsSharedZA],
+  [ImmCheck<0, ImmCheck0_7>]>;
+  }
+}
+
+defm SVSMOPA : ZAIntOuterProd<"s", "mopa">;
+defm SVSMOPS : ZAIntOuterProd<"s", "mops">;
+defm SVUMOPA : ZAIntOuterProd<"u", "mopa">;
+defm SVUMOPS : ZAIntOuterProd<"u", "mops">;
+
+
+// SME - SUMOPA, SUMOPS, USMOPA, USMOPS
+
+multiclass ZAIntOuterProdMixedSigns {
+  let TargetGuard = "sme" in {
+def NAME # _ZA32_B: SInst<"sv" # n_suffix1 # n_suffix2 # "_za32[_{d}]",
+  "viPPd" # !cond(!eq(n_suffix1, "su") : "u", 
true: "x"),
+  !cond(!eq(n_suffix1, "su") : "", true: "U") # 
"c",
+  MergeOp1, "aarch64_sme_" # n_suffix1 # n_suffix2 
# "_wide",
+  [IsStreaming, IsSharedZA],
+  [ImmCheck<0, ImmCheck0_3>]>;
+  }
+
+  let TargetGuard = "sme-i16i64" in {
+def NAME # _ZA64_H: SInst<"sv" # n_suffix1 # n_suffix2 # "_za64[_{d}]",
+  "viPPd" # !cond(!eq(n_suffix1, "su") : "u", 
true: "x"),
+  !cond(!eq(n_suffix1, "su") : "", true: "U") # 
"s",
+  MergeOp1, "aarch64_sme_" # n_suffix1 # n_suffix2 
# "_wide",
+  [IsStreaming, IsSharedZA],
+  [ImmCheck<0, ImmCheck0_7>]>;
+  }
+}
+
+defm SVSUMOPA : ZAIntOuterProdMixedSigns<"su", "mopa">;
+defm SVSUMOPS : ZAIntOuterProdMixedSigns<"su", "mops">;
+defm SVUSMOPA : ZAIntOuterProdMixedSigns<"us", "mopa">;
+defm SVUSMOPS : ZAIntOuterProdMixedSigns<"us", "mops">;
+
+
+// SME - FMOPA, FMOPS
+
+multiclass ZAFPOuterProd {
+  let TargetGuard = "sme" in {
+def NAME # _ZA32_B: SInst<"sv" # n_suffix # "_za32[_{d}]", "viPPdd", "h",
+  MergeOp1, "aarch64_sme_" # n_suffix # "_wide",
+  [IsStreaming, IsSharedZA],
+  [ImmCheck<0

[clang] 2c38740 - [Clang][AArch64][SME] Generate target features from +(no)sme.* options

2023-07-20 Thread Bryan Chan via cfe-commits

Author: Bryan Chan
Date: 2023-07-20T06:06:37-04:00
New Revision: 2c38740ca661a10866a796db105752e15372ddce

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

LOG: [Clang][AArch64][SME] Generate target features from +(no)sme.* options

Reviewed By: sdesmalen

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

Added: 
clang/test/Driver/aarch64-implied-sme-features.c

Modified: 
clang/lib/Driver/ToolChains/Arch/AArch64.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp 
b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
index 35470316357951..507ad924770410 100644
--- a/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -82,6 +82,25 @@ static bool DecodeAArch64Features(const Driver &D, StringRef 
text,
 else
   return false;
 
+// +sme implies +bf16.
+// +sme-f64f64 and +sme-i16i64 both imply +sme.
+if (Feature == "sme") {
+  Features.push_back("+bf16");
+} else if (Feature == "nosme") {
+  Features.push_back("-sme-f64f64");
+  Features.push_back("-sme-i16i64");
+} else if (Feature == "sme-f64f64") {
+  Features.push_back("+sme");
+  Features.push_back("+bf16");
+} else if (Feature == "sme-i16i64") {
+  Features.push_back("+sme");
+  Features.push_back("+bf16");
+} else if (Feature == "nobf16") {
+  Features.push_back("-sme");
+  Features.push_back("-sme-f64f64");
+  Features.push_back("-sme-i16i64");
+}
+
 if (Feature == "sve2")
   Features.push_back("+sve");
 else if (Feature == "sve2-bitperm" || Feature == "sve2-sha3" ||

diff  --git a/clang/test/Driver/aarch64-implied-sme-features.c 
b/clang/test/Driver/aarch64-implied-sme-features.c
new file mode 100644
index 00..2277aceb881d73
--- /dev/null
+++ b/clang/test/Driver/aarch64-implied-sme-features.c
@@ -0,0 +1,49 @@
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme %s -### 2>&1 | 
FileCheck %s --check-prefix=SME-IMPLY
+// SME-IMPLY: "-target-feature" "+sme" "-target-feature" "+bf16"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme %s -### 2>&1 | 
FileCheck %s --check-prefix=NOSME
+// NOSME: "-target-feature" "-sme"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme+nosme %s -### 2>&1 
| FileCheck %s --check-prefix=SME-REVERT
+// SME-REVERT-NOT: "-target-feature" "+sme"
+// SME-REVERT: "-target-feature" "+bf16" "-target-feature" "-sme" 
"-target-feature" "-sme-f64f64" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme+nobf16 %s -### 
2>&1 | FileCheck %s --check-prefix=SME-CONFLICT
+// SME-CONFLICT-NOT: "-target-feature" "+sme"
+// SME-CONFLICT-NOT: "-target-feature" "+bf16"
+// SME-CONFLICT: "-target-feature" "-bf16" "-target-feature" "-sme" 
"-target-feature" "-sme-f64f64" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme-i16i64 %s -### 
2>&1 | FileCheck %s --check-prefix=SME-I16I64
+// SME-I16I64: "-target-feature" "+sme-i16i64" "-target-feature" "+sme" 
"-target-feature" "+bf16"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme-i16i64 %s -### 
2>&1 | FileCheck %s --check-prefix=NOSME-I16I64
+// NOSME-I16I64-NOT: "-target-feature" "+sme-i16i64"
+// NOSME-I16I64-NOT: "-target-feature" "+sme"
+// NOSME-I16I64-NOT: "-target-feature" "+bf16"
+// NOSME-I16I64: "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu 
-march=armv8-a+sme-i16i64+nosme-i16i64 %s -### 2>&1 | FileCheck %s 
--check-prefix=SME-I16I64-REVERT
+// SME-I16I64-REVERT: "-target-feature" "+sme" "-target-feature" "+bf16" 
"-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme-f64f64 %s -### 
2>&1 | FileCheck %s --check-prefix=NOSME-F64F64
+// NOSME-F64F64-NOT: "-target-feature" "+sme-f64f64"
+// NOSME-F64F64-NOT: "-target-feature" "+sme"
+// NOSME-F64F64-NOT: "-target-feature" "+bf16"
+// NOSME-F64F64: "-target-feature" "-sme-f64f64"
+
+// RUN: %clang -target aarch64-linux-gnu 
-march=armv8-a+sme-f64f64+nosme-f64f64 %s -### 2>&1 | FileCheck %s 
--check-prefix=SME-F64F64-REVERT
+// SME-F64F64-REVERT: "-target-feature" "+sme" "-target-feature" "+bf16" 
"-target-feature" "-sme-f64f64"
+
+// RUN: %clang -target aarch64-linux-gnu 
-march=armv8-a+sme-f64f64+nosme-i16i64 %s -### 2>&1 | FileCheck %s 
--check-prefix=SME-SUBFEATURE-MIX
+// SME-SUBFEATURE-MIX: "-target-feature" "+sme-f64f64" "-target-feature" 
"+sme" "-target-feature" "+bf16" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme-i16i64+nosme %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT1
+// SME-SUBFEATURE-CONFLICT1: "-target-feature" "+bf16" "-target-feature" 
"-sm

[PATCH] D134677: [Clang][AArch64][SME] Add ZA zeroing intrinsics

2023-07-20 Thread Bryan Chan 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 rG578b0bd4e621: [Clang][AArch64][SME] Add ZA zeroing 
intrinsics (authored by bryanpkc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134677

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/include/clang/Basic/arm_sve_sme_incl.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -192,6 +192,13 @@
   SVE_ACLE_FUNC(svwrite_ver_za8, _s8, _m,)(0, -1, 16, pg, svundef_s8());
 }
 
+void test_range_0_255(svbool_t pg, void *ptr) {
+  // expected-error@+1 {{argument value 256 is outside the valid range [0, 255]}}
+  SVE_ACLE_FUNC(svzero_mask_za,,,)(256);
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 255]}}
+  SVE_ACLE_FUNC(svzero_mask_za,,,)(-1);
+}
+
 void test_constant(uint64_t u64, svbool_t pg, void *ptr) {
   SVE_ACLE_FUNC(svld1_hor_za8,,,)(u64, u64, 0, pg, ptr);  // expected-error {{argument to 'svld1_hor_za8' must be a constant integer}}
   SVE_ACLE_FUNC(svld1_ver_za16,,,)(0, u64, u64, pg, ptr); // expected-error {{argument to 'svld1_ver_za16' must be a constant integer}}
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c
@@ -0,0 +1,46 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+// CHECK-C-LABEL: @test_svzero_mask_za(
+// CHECK-CXX-LABEL: @_Z19test_svzero_mask_zav(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 0)
+// CHECK-NEXT:ret void
+//
+void test_svzero_mask_za() {
+  svzero_mask_za(0);
+}
+
+// CHECK-C-LABEL: @test_svzero_mask_za_1(
+// CHECK-CXX-LABEL: @_Z21test_svzero_mask_za_1v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 176)
+// CHECK-NEXT:ret void
+//
+void test_svzero_mask_za_1() {
+  svzero_mask_za(176);
+}
+
+// CHECK-C-LABEL: @test_svzero_mask_za_2(
+// CHECK-CXX-LABEL: @_Z21test_svzero_mask_za_2v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 255)
+// CHECK-NEXT:ret void
+//
+void test_svzero_mask_za_2() {
+  svzero_mask_za(255);
+}
+
+// CHECK-C-LABEL: @test_svzero_za(
+// CHECK-CXX-LABEL: @_Z14test_svzero_zav(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 255)
+// CHECK-NEXT:ret void
+//
+void test_svzero_za() {
+  svzero_za();
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -3003,6 +3003,10 @@
   if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 0, 15))
 HasError = true;
   break;
+case SVETypeFlags::ImmCheck0_255:
+  if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 0, 255))
+HasError = true;
+  break;
 }
   }
 
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -4283,6 +4283,9 @@
   llvm::Value *EmitSMEReadWrite(SVETypeFlags TypeFlags,
 llvm::SmallVectorImpl &Ops,
 unsigned IntID);
+  llvm::Value *EmitSMEZero(SVETypeFlags TypeFlags,
+   llvm::SmallVectorImpl &Ops,
+   unsigned IntID);
   llvm::Value *EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
 
   llvm::Value *EmitAArch64BuiltinExpr(unsigned BuiltinID, const CallExpr *E,
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -9495,6 +9495,16 @@
   return Builder.CreateCall(F, Ops);
 }
 
+Value *CodeGenFunction::EmitSMEZero(SVETypeFlags TypeFlags,
+   

[PATCH] D134678: [Clang][AArch64][SME] Add intrinsics for ZA array load/store (LDR/STR)

2023-07-20 Thread Bryan Chan 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 rGf225898a7c61: [Clang][AArch64][SME] Add intrinsics for ZA 
array load/store (LDR/STR) (authored by bryanpkc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134678

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -174,6 +174,11 @@
   // expected-error@+1 {{argument value 16 is outside the valid range [0, 15]}}
   SVE_ACLE_FUNC(svst1_ver_vnum_za8,,,)(0, -1, 16, pg, ptr, 1);
 
+  // expected-error@+1 {{argument value 16 is outside the valid range [0, 15]}}
+  SVE_ACLE_FUNC(svldr_vnum_za,,,)(-1, 16, ptr);
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 15]}}
+  SVE_ACLE_FUNC(svstr_vnum_za,,,)(-1, -1, ptr);
+
   // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 15]}}
   SVE_ACLE_FUNC(svread_hor_za128, _s8, _m,)(svundef_s8(), pg, -1, -1, 0);
   // expected-error@+1 {{argument value 16 is outside the valid range [0, 15]}}
@@ -209,6 +214,9 @@
   SVE_ACLE_FUNC(svst1_hor_vnum_za32,,,)(u64, u64, 0, pg, ptr, u64); // expected-error {{argument to 'svst1_hor_vnum_za32' must be a constant integer}}
   SVE_ACLE_FUNC(svst1_ver_vnum_za64,,,)(0, u64, u64, pg, ptr, u64); // expected-error {{argument to 'svst1_ver_vnum_za64' must be a constant integer}}
 
+  SVE_ACLE_FUNC(svldr_vnum_za,,,)(u64, u64, ptr); // expected-error {{argument to 'svldr_vnum_za' must be a constant integer}}
+  SVE_ACLE_FUNC(svstr_vnum_za,,,)(u64, u64, ptr); // expected-error {{argument to 'svstr_vnum_za' must be a constant integer}}
+
   SVE_ACLE_FUNC(svread_hor_za8, _s8, _m,)(svundef_s8(), pg, 0, u64, u64); // expected-error-re {{argument to 'svread_hor_za8{{.*}}_m' must be a constant integer}}
   SVE_ACLE_FUNC(svread_ver_za16, _s16, _m,)(svundef_s16(), pg, u64, u64, 0);  // expected-error-re {{argument to 'svread_ver_za16{{.*}}_m' must be a constant integer}}
   SVE_ACLE_FUNC(svwrite_hor_za32, _s32, _m,)(0, u64, u64, pg, svundef_s32()); // expected-error-re {{argument to 'svwrite_hor_za32{{.*}}_m' must be a constant integer}}
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_str.c
@@ -0,0 +1,30 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+// CHECK-C-LABEL: @test_svstr_vnum_za(
+// CHECK-CXX-LABEL: @_Z18test_svstr_vnum_zajPv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str(i32 [[SLICE_BASE:%.*]], ptr [[PTR:%.*]])
+// CHECK-NEXT:ret void
+//
+void test_svstr_vnum_za(uint32_t slice_base, void *ptr) {
+  svstr_vnum_za(slice_base, 0, ptr);
+}
+
+// CHECK-C-LABEL: @test_svstr_vnum_za_1(
+// CHECK-CXX-LABEL: @_Z20test_svstr_vnum_za_1jPv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VSCALE:%.*]] = tail call i64 @llvm.vscale.i64()
+// CHECK-NEXT:[[MULVL:%.*]] = mul nuw nsw i64 [[VSCALE]], 240
+// CHECK-NEXT:[[TMP0:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 [[MULVL]]
+// CHECK-NEXT:[[TILESLICE:%.*]] = add i32 [[SLICE_BASE:%.*]], 15
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str(i32 [[TILESLICE]], ptr [[TMP0]])
+// CHECK-NEXT:ret void
+//
+void test_svstr_vnum_za_1(uint32_t slice_base, void *ptr) {
+  svstr_vnum_za(slice_base, 15, ptr);
+}
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -0,0 +1,30 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve 

[PATCH] D134679: [Clang][AArch64][SME] Add intrinsics for reading streaming vector length

2023-07-20 Thread Bryan Chan 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 rG15d16a79a01f: [Clang][AArch64][SME] Add intrinsics for 
reading streaming vector length (authored by bryanpkc).

Changed prior to commit:
  https://reviews.llvm.org/D134679?vs=526379&id=542396#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134679

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c


Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c
@@ -0,0 +1,46 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s 
-check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme 
-target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+// CHECK-C-LABEL: @test_svcntsb(
+// CHECK-CXX-LABEL: @_Z12test_svcntsbv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsb()
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntsb() {
+  return svcntsb();
+}
+
+// CHECK-C-LABEL: @test_svcntsh(
+// CHECK-CXX-LABEL: @_Z12test_svcntshv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsh()
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntsh() {
+  return svcntsh();
+}
+
+// CHECK-C-LABEL: @test_svcntsw(
+// CHECK-CXX-LABEL: @_Z12test_svcntswv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsw()
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntsw() {
+  return svcntsw();
+}
+
+// CHECK-C-LABEL: @test_svcntsd(
+// CHECK-CXX-LABEL: @_Z12test_svcntsdv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call i64 @llvm.aarch64.sme.cntsd()
+// CHECK-NEXT:ret i64 [[TMP0]]
+//
+uint64_t test_svcntsd() {
+  return svcntsd();
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -9955,6 +9955,7 @@
   getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments);
   assert(Error == ASTContext::GE_None && "Should not codegen an error");
 
+  llvm::Type *Ty = ConvertType(E->getType());
   llvm::SmallVector Ops;
   for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
 if ((ICEArguments & (1 << i)) == 0)
@@ -9987,6 +9988,12 @@
   else if (BuiltinID == SME::BI__builtin_sme_svldr_vnum_za ||
BuiltinID == SME::BI__builtin_sme_svstr_vnum_za)
 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
+  else if (Builtin->LLVMIntrinsic != 0) {
+Function *F = CGM.getIntrinsic(Builtin->LLVMIntrinsic,
+   getSVEOverloadTypes(TypeFlags, Ty, Ops));
+Value *Call = Builder.CreateCall(F, Ops);
+return Call;
+  }
 
   /// Should not happen
   return nullptr;
Index: clang/include/clang/Basic/arm_sme.td
===
--- clang/include/clang/Basic/arm_sme.td
+++ clang/include/clang/Basic/arm_sme.td
@@ -135,3 +135,19 @@
   def SVZERO_ZA  : SInst<"svzero_za", "v", "", MergeNone, 
"aarch64_sme_zero",
  [IsOverloadNone, IsStreamingCompatible, 
IsSharedZA]>;
 }
+
+
+// SME - Counting elements in a streaming vector
+
+multiclass ZACount {
+  let TargetGuard = "sme" in {
+def NAME : SInst<"sv" # n_suffix, "nv", "", MergeNone,
+  "aarch64_sme_" # n_suffix,
+  [IsOverloadNone, IsStreamingCompatible, IsPreservesZA]>;
+  }
+}
+
+defm SVCNTSB : ZACount<"cntsb">;
+defm SVCNTSH : ZACount<"cntsh">;
+defm SVCNTSW : ZACount<"cntsw">;
+defm SVCNTSD : ZACount<"cntsd">;


Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_cnt.c
@@ -0,0 +1,46 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK

[PATCH] D134680: [Clang][AArch64][SME] Add intrinsics for adding vector elements to ZA tile

2023-07-20 Thread Bryan Chan 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 rG4ae900c06363: [Clang][AArch64][SME] Add intrinsics for 
adding vector elements to ZA tile (authored by bryanpkc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134680

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i32.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -118,6 +118,11 @@
   SVE_ACLE_FUNC(svwrite_hor_za32, _s32, _m,)(0, -1, -1, pg, svundef_s32());
   // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
   SVE_ACLE_FUNC(svwrite_ver_za32, _s32, _m,)(3, -1, 4, pg, svundef_s32());
+
+  // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svaddha_za32, _s32, _m,)(4, pg, pg, svundef_s32());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svaddva_za32, _s32, _m,)(-1, pg, pg, svundef_s32());
 }
 
 void test_range_0_7(svbool_t pg, void *ptr) {
@@ -154,6 +159,11 @@
   SVE_ACLE_FUNC(svwrite_hor_za16, _s16, _m,)(0, -1, -1, pg, svundef_s16());
   // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
   SVE_ACLE_FUNC(svwrite_ver_za16, _s16, _m,)(1, -1, 8, pg, svundef_s16());
+
+  // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svaddha_za64, _s64, _m,)(8, pg, pg, svundef_s64());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svaddva_za64, _s64, _m,)(-1, pg, pg, svundef_s64());
 }
 
 void test_range_0_15(svbool_t pg, void *ptr) {
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_add-i64.c
@@ -0,0 +1,110 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-i16i64 -target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+#ifdef SME_OVERLOADED_FORMS
+#define SME_ACLE_FUNC(A1,A2_UNUSED,A3) A1##A3
+#else
+#define SME_ACLE_FUNC(A1,A2,A3) A1##A2##A3
+#endif
+
+// CHECK-C-LABEL: @test_svaddha_za64_u64(
+// CHECK-CXX-LABEL: @_Z21test_svaddha_za64_u64u10__SVBool_tu10__SVBool_tu12__SVUint64_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PN:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.addha.nxv2i64(i32 0,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]])
+// CHECK-NEXT:ret void
+//
+void test_svaddha_za64_u64(svbool_t pn, svbool_t pm, svuint64_t zn) {
+  SME_ACLE_FUNC(svaddha_za64, _u64, _m)(0, pn, pm, zn);
+}
+
+// CHECK-C-LABEL: @test_svaddha_za64_u64_1(
+// CHECK-CXX-LABEL: @_Z23test_svaddha_za64_u64_1u10__SVBool_tu10__SVBool_tu12__SVUint64_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PN:%.*]])
+// CHECK-NEXT:[[TMP1:%.*]] = tail call  @llvm.aarch64.sve.convert.from.svbool.nxv2i1( [[PM:%.*]])
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.addha.nxv2i64(i32 7,  [[TMP0]],  [[TMP1]],  [[ZN:%.*]])
+// CHECK-NEXT:ret void
+//
+void test_svaddha_za64_u64_1(svbool_t pn, svbool_t pm, svuint64_t zn) {
+  SME_ACLE_FUNC(svaddha_za64, _u64, _m)(7, pn, pm, zn);
+}
+
+// CHECK-C-LABEL: @test_svaddha_za64_s64(
+// CHECK-CXX-LABEL: @_Z21test_svaddha_za64_s64u10__SVBool_tu10__SVBool_tu11__SVInt64_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = tail call  @llvm.aarch64.sve

[PATCH] D134681: [Clang][AArch64][SME] Add outer product intrinsics

2023-07-20 Thread Bryan Chan 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 rGaebde82b29a8: [Clang][AArch64][SME] Add outer product 
intrinsics (authored by bryanpkc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134681

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za32.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mopa-za64.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za32.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -123,6 +123,19 @@
   SVE_ACLE_FUNC(svaddha_za32, _s32, _m,)(4, pg, pg, svundef_s32());
   // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
   SVE_ACLE_FUNC(svaddva_za32, _s32, _m,)(-1, pg, pg, svundef_s32());
+
+  // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svmopa_za32, _s8, _m,)(4, pg, pg, svundef_s8(), svundef_s8());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svmops_za32, _s8, _m,)(-1, pg, pg, svundef_s8(), svundef_s8());
+  // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svsumopa_za32, _s8, _m,)(4, pg, pg, svundef_s8(), svundef_u8());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svsumops_za32, _s8, _m,)(-1, pg, pg, svundef_s8(), svundef_u8());
+  // expected-error@+1 {{argument value 4 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svusmopa_za32, _u8, _m,)(4, pg, pg, svundef_u8(), svundef_s8());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 3]}}
+  SVE_ACLE_FUNC(svusmops_za32, _u8, _m,)(-1, pg, pg, svundef_u8(), svundef_s8());
 }
 
 void test_range_0_7(svbool_t pg, void *ptr) {
@@ -164,6 +177,19 @@
   SVE_ACLE_FUNC(svaddha_za64, _s64, _m,)(8, pg, pg, svundef_s64());
   // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
   SVE_ACLE_FUNC(svaddva_za64, _s64, _m,)(-1, pg, pg, svundef_s64());
+
+  // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svmopa_za64, _s16, _m,)(8, pg, pg, svundef_s16(), svundef_s16());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svmops_za64, _s16, _m,)(-1, pg, pg, svundef_s16(), svundef_s16());
+  // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svsumopa_za64, _s16, _m,)(8, pg, pg, svundef_s16(), svundef_u16());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svsumops_za64, _s16, _m,)(-1, pg, pg, svundef_s16(), svundef_u16());
+  // expected-error@+1 {{argument value 8 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svusmopa_za64, _u16, _m,)(8, pg, pg, svundef_u16(), svundef_s16());
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 7]}}
+  SVE_ACLE_FUNC(svusmops_za64, _u16, _m,)(-1, pg, pg, svundef_u16(), svundef_s16());
 }
 
 void test_range_0_15(svbool_t pg, void *ptr) {
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_mops-za64.c
@@ -0,0 +1,74 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-f64f64 -target-feature +sme-i16i64 -target-feature +sve -target-feature +bf16 -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme-f64f64 -target-feature +sme-i16i64 -target-feature +sve -target-feature +bf16 -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme-f64f64 -target-feature +sme-i16i64 -target-feature +sve -target-feature +bf16 -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -DSME_OVERLOADED_FORMS -triple aarch64-none-linux-gnu -target-feature +sme-f64f64 -target-feature +sme-i16i64 -target-feature +sve -target-feature +bf16 -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-f

[PATCH] D142702: [Clang][AArch64][SME] Generate target features from +(no)sme.* options

2023-07-20 Thread Bryan Chan 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 rG2c38740ca661: [Clang][AArch64][SME] Generate target features 
from +(no)sme.* options (authored by bryanpkc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142702

Files:
  clang/lib/Driver/ToolChains/Arch/AArch64.cpp
  clang/test/Driver/aarch64-implied-sme-features.c


Index: clang/test/Driver/aarch64-implied-sme-features.c
===
--- /dev/null
+++ clang/test/Driver/aarch64-implied-sme-features.c
@@ -0,0 +1,49 @@
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme %s -### 2>&1 | 
FileCheck %s --check-prefix=SME-IMPLY
+// SME-IMPLY: "-target-feature" "+sme" "-target-feature" "+bf16"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme %s -### 2>&1 | 
FileCheck %s --check-prefix=NOSME
+// NOSME: "-target-feature" "-sme"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme+nosme %s -### 2>&1 
| FileCheck %s --check-prefix=SME-REVERT
+// SME-REVERT-NOT: "-target-feature" "+sme"
+// SME-REVERT: "-target-feature" "+bf16" "-target-feature" "-sme" 
"-target-feature" "-sme-f64f64" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme+nobf16 %s -### 
2>&1 | FileCheck %s --check-prefix=SME-CONFLICT
+// SME-CONFLICT-NOT: "-target-feature" "+sme"
+// SME-CONFLICT-NOT: "-target-feature" "+bf16"
+// SME-CONFLICT: "-target-feature" "-bf16" "-target-feature" "-sme" 
"-target-feature" "-sme-f64f64" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme-i16i64 %s -### 
2>&1 | FileCheck %s --check-prefix=SME-I16I64
+// SME-I16I64: "-target-feature" "+sme-i16i64" "-target-feature" "+sme" 
"-target-feature" "+bf16"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme-i16i64 %s -### 
2>&1 | FileCheck %s --check-prefix=NOSME-I16I64
+// NOSME-I16I64-NOT: "-target-feature" "+sme-i16i64"
+// NOSME-I16I64-NOT: "-target-feature" "+sme"
+// NOSME-I16I64-NOT: "-target-feature" "+bf16"
+// NOSME-I16I64: "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu 
-march=armv8-a+sme-i16i64+nosme-i16i64 %s -### 2>&1 | FileCheck %s 
--check-prefix=SME-I16I64-REVERT
+// SME-I16I64-REVERT: "-target-feature" "+sme" "-target-feature" "+bf16" 
"-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme-f64f64 %s -### 
2>&1 | FileCheck %s --check-prefix=NOSME-F64F64
+// NOSME-F64F64-NOT: "-target-feature" "+sme-f64f64"
+// NOSME-F64F64-NOT: "-target-feature" "+sme"
+// NOSME-F64F64-NOT: "-target-feature" "+bf16"
+// NOSME-F64F64: "-target-feature" "-sme-f64f64"
+
+// RUN: %clang -target aarch64-linux-gnu 
-march=armv8-a+sme-f64f64+nosme-f64f64 %s -### 2>&1 | FileCheck %s 
--check-prefix=SME-F64F64-REVERT
+// SME-F64F64-REVERT: "-target-feature" "+sme" "-target-feature" "+bf16" 
"-target-feature" "-sme-f64f64"
+
+// RUN: %clang -target aarch64-linux-gnu 
-march=armv8-a+sme-f64f64+nosme-i16i64 %s -### 2>&1 | FileCheck %s 
--check-prefix=SME-SUBFEATURE-MIX
+// SME-SUBFEATURE-MIX: "-target-feature" "+sme-f64f64" "-target-feature" 
"+sme" "-target-feature" "+bf16" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme-i16i64+nosme %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT1
+// SME-SUBFEATURE-CONFLICT1: "-target-feature" "+bf16" "-target-feature" 
"-sme" "-target-feature" "-sme-f64f64" "-target-feature" "-sme-i16i64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+sme-f64f64+nobf16 %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT2
+// SME-SUBFEATURE-CONFLICT2-NOT: "-target-feature" "+bf16"
+// SME-SUBFEATURE-CONFLICT2-NOT: "-target-feature" "+sme"
+// SME-SUBFEATURE-CONFLICT2-NOT: "-target-feature" "+sme-f64f64"
+
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme+sme-i16i64 %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT-REV
+// SME-SUBFEATURE-CONFLICT-REV: "-target-feature" "-sme-f64f64" 
"-target-feature" "+sme-i16i64" "-target-feature" "+sme" "-target-feature" 
"+bf16"
Index: clang/lib/Driver/ToolChains/Arch/AArch64.cpp
===
--- clang/lib/Driver/ToolChains/Arch/AArch64.cpp
+++ clang/lib/Driver/ToolChains/Arch/AArch64.cpp
@@ -82,6 +82,25 @@
 else
   return false;
 
+// +sme implies +bf16.
+// +sme-f64f64 and +sme-i16i64 both imply +sme.
+if (Feature == "sme") {
+  Features.push_back("+bf16");
+} else if (Feature == "nosme") {
+  Features.push_back("-sme-f64f64");
+  Features.push_back("-sme-i16i64");
+} else if (Feature == "sme-f64f64") {
+  Features.push_back("+sme");
+  Features.push_back("+bf16");
+} else if (Feature == "sme-i16i64") 

[PATCH] D155808: [clang][driver] Missing the condition in ISARMBigEndain function.

2023-07-20 Thread Simi Pallipurath via Phabricator via cfe-commits
simpal01 created this revision.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
simpal01 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

IsARMBIgEndian function returns true only if:

1. The triples are either arm or thumb and the commandline has the  option 
-mbig-endian
2. The triples are either armeb or thumbeb.

Missing the checking of arm or thumb triples in the
first case pass through the --be8 endian flag to
linker For AArch64 as well which is not expected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155808

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp


Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -37,9 +37,12 @@
 // '-mbig-endian'/'-EB'. Unlike other targets the flag does not result in a
 // normalized triple so we must handle the flag here.
 bool arm::isARMBigEndian(const llvm::Triple &Triple, const ArgList &Args) {
-  if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
-   options::OPT_mbig_endian)) {
-return !A->getOption().matches(options::OPT_mlittle_endian);
+  if ((Triple.getArch() == llvm::Triple::arm ||
+   Triple.getArch() == llvm::Triple::thumb)) {
+if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
+ options::OPT_mbig_endian)) {
+  return !A->getOption().matches(options::OPT_mlittle_endian);
+}
   }
 
   return Triple.getArch() == llvm::Triple::armeb ||


Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -37,9 +37,12 @@
 // '-mbig-endian'/'-EB'. Unlike other targets the flag does not result in a
 // normalized triple so we must handle the flag here.
 bool arm::isARMBigEndian(const llvm::Triple &Triple, const ArgList &Args) {
-  if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
-   options::OPT_mbig_endian)) {
-return !A->getOption().matches(options::OPT_mlittle_endian);
+  if ((Triple.getArch() == llvm::Triple::arm ||
+   Triple.getArch() == llvm::Triple::thumb)) {
+if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
+ options::OPT_mbig_endian)) {
+  return !A->getOption().matches(options::OPT_mlittle_endian);
+}
   }
 
   return Triple.getArch() == llvm::Triple::armeb ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155452: [Flang] Add support for fsave-optimization-record

2023-07-20 Thread victorkingi via Phabricator via cfe-commits
victorkingi updated this revision to Diff 542404.
victorkingi added a comment.

Attempt to fix failing test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155452

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-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Driver/fsave-optimization-record.f90

Index: flang/test/Driver/fsave-optimization-record.f90
===
--- /dev/null
+++ flang/test/Driver/fsave-optimization-record.f90
@@ -0,0 +1,42 @@
+! Tests for the '-f[no-]save-optimization-record[=]' flag.
+
+! Test -foptimization-record-file produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -foptimization-record-file=%t.opt.yaml -c %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! Test -fsave-optimization-record produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -c -o %t.o %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -o %t.o %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! Produces an empty file
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -emit-llvm -o %t.o %s
+! RUN: cat %t.opt.yaml
+
+!Test unknown format produces error
+! RUN: not %flang -fsave-optimization-record=hello %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-FORMAT-ERROR %s
+
+! CHECK: --- !Analysis
+! CHECK: Pass:prologepilog
+! CHECK: Name:StackSize
+! CHECK: Function:_QQmain
+! CHECK: Pass:asm-printer
+! CHECK: Name:InstructionMix
+! CHECK: Name:InstructionCount
+
+! CHECK-FORMAT-ERROR: error: unknown remark serializer format: 'hello'
+
+program forttest
+implicit none
+integer :: n
+
+n = 1 * 1
+
+end program forttest
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -15,6 +15,7 @@
 ! RUN: -fassociative-math \
 ! RUN: -freciprocal-math \
 ! RUN: -fpass-plugin=Bye%pluginext \
+! RUN: -fsave-optimization-record \
 ! RUN: -fversion-loops-for-stride \
 ! RUN: -flang-experimental-polymorphism \
 ! RUN: -mllvm -print-before-all \
@@ -22,6 +23,10 @@
 ! RUN: -P \
 ! RUN:   | FileCheck %s
 
+! RUN: %flang -### %s 2>&1 \
+! RUN: -foptimization-record-file=%t.opt.yaml \
+! RUN:   | FileCheck --check-prefix=YAML %s
+
 ! CHECK: "-P"
 ! CHECK: "-finput-charset=utf-8"
 ! CHECK: "-fdefault-double-8"
@@ -38,5 +43,10 @@
 ! CHECK: "-fpass-plugin=Bye
 ! CHECK: "-flang-experimental-polymorphism"
 ! CHECK: "-fversion-loops-for-stride"
+! CHECK: "-opt-record-file" "{{.+}}.opt.yaml"
+! CHECK: "-opt-record-format" "yaml"
 ! CHECK: "-mllvm" "-print-before-all"
 ! CHECK: "-save-temps=obj"
+
+! YAML: "-opt-record-file" "{{.+}}.opt.yaml"
+! YAML: "-opt-record-format" "yaml"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -54,8 +54,16 @@
 ! HELP-NEXT: -fopenmp-version=
 ! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! HELP-NEXT: -foptimization-record-file=
+! HELP-NEXT:Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch  options.
+! HELP-NEXT: -foptimization-record-passes=
+! HELP-NEXT:Only include passes which match a specified regular expression in the generated optimization record (by default, include all passes)
 ! HELP-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! HELP-NEXT: -freciprocal-math  Allow division operations to be reassociated
+! HELP-NEXT: -fsave-optimization-record=
+! HELP-NEXT:Generate an optimization record file in a specific format
+! HELP-NEXT: -fsave-optimization-record
+! HELP-NEXT:Generate a YAML optimization record file
 ! HELP-NEXT: -fstack-arrays Attempt to allocate array temporaries on the stack, no matter their size
 ! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-NEXT: -funderscoring Appends one trailing underscore to external names
@@ 

[PATCH] D155809: [NFC] [Clang] Fix strict weak ordering in ItaniumVTableBuilder

2023-07-20 Thread Danila Kutenin via Phabricator via cfe-commits
danlark created this revision.
Herald added a project: All.
danlark requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In sorting elements can compare with themselves and sometimes assert further 
down the line was triggered


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155809

Files:
  clang/lib/AST/VTableBuilder.cpp


Index: clang/lib/AST/VTableBuilder.cpp
===
--- clang/lib/AST/VTableBuilder.cpp
+++ clang/lib/AST/VTableBuilder.cpp
@@ -1560,6 +1560,7 @@
   std::stable_sort(
   NewImplicitVirtualFunctions.begin(), NewImplicitVirtualFunctions.end(),
   [](const CXXMethodDecl *A, const CXXMethodDecl *B) {
+if (A == B) return false;
 if (A->isCopyAssignmentOperator() != B->isCopyAssignmentOperator())
   return A->isCopyAssignmentOperator();
 if (A->isMoveAssignmentOperator() != B->isMoveAssignmentOperator())


Index: clang/lib/AST/VTableBuilder.cpp
===
--- clang/lib/AST/VTableBuilder.cpp
+++ clang/lib/AST/VTableBuilder.cpp
@@ -1560,6 +1560,7 @@
   std::stable_sort(
   NewImplicitVirtualFunctions.begin(), NewImplicitVirtualFunctions.end(),
   [](const CXXMethodDecl *A, const CXXMethodDecl *B) {
+if (A == B) return false;
 if (A->isCopyAssignmentOperator() != B->isCopyAssignmentOperator())
   return A->isCopyAssignmentOperator();
 if (A->isMoveAssignmentOperator() != B->isMoveAssignmentOperator())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155452: [Flang] Add support for fsave-optimization-record

2023-07-20 Thread victorkingi via Phabricator via cfe-commits
victorkingi updated this revision to Diff 542407.
victorkingi added a comment.

Addressed kiranchandramohan comment on fsave-optimization-record.f90 test file


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155452

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-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Driver/fsave-optimization-record.f90

Index: flang/test/Driver/fsave-optimization-record.f90
===
--- /dev/null
+++ flang/test/Driver/fsave-optimization-record.f90
@@ -0,0 +1,42 @@
+! Tests for the '-f[no-]save-optimization-record[=]' flag.
+
+! Test -foptimization-record-file produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -foptimization-record-file=%t.opt.yaml -c %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! Test -fsave-optimization-record produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -c -o %t.o %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -o %t.s %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! Produces an empty file
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -emit-llvm -o %t.ll %s
+! RUN: cat %t.opt.yaml
+
+!Test unknown format produces error
+! RUN: not %flang -fsave-optimization-record=hello %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-FORMAT-ERROR %s
+
+! CHECK: --- !Analysis
+! CHECK: Pass:prologepilog
+! CHECK: Name:StackSize
+! CHECK: Function:_QQmain
+! CHECK: Pass:asm-printer
+! CHECK: Name:InstructionMix
+! CHECK: Name:InstructionCount
+
+! CHECK-FORMAT-ERROR: error: unknown remark serializer format: 'hello'
+
+program forttest
+implicit none
+integer :: n
+
+n = 1 * 1
+
+end program forttest
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -15,6 +15,7 @@
 ! RUN: -fassociative-math \
 ! RUN: -freciprocal-math \
 ! RUN: -fpass-plugin=Bye%pluginext \
+! RUN: -fsave-optimization-record \
 ! RUN: -fversion-loops-for-stride \
 ! RUN: -flang-experimental-polymorphism \
 ! RUN: -mllvm -print-before-all \
@@ -22,6 +23,10 @@
 ! RUN: -P \
 ! RUN:   | FileCheck %s
 
+! RUN: %flang -### %s 2>&1 \
+! RUN: -foptimization-record-file=%t.opt.yaml \
+! RUN:   | FileCheck --check-prefix=YAML %s
+
 ! CHECK: "-P"
 ! CHECK: "-finput-charset=utf-8"
 ! CHECK: "-fdefault-double-8"
@@ -38,5 +43,10 @@
 ! CHECK: "-fpass-plugin=Bye
 ! CHECK: "-flang-experimental-polymorphism"
 ! CHECK: "-fversion-loops-for-stride"
+! CHECK: "-opt-record-file" "{{.+}}.opt.yaml"
+! CHECK: "-opt-record-format" "yaml"
 ! CHECK: "-mllvm" "-print-before-all"
 ! CHECK: "-save-temps=obj"
+
+! YAML: "-opt-record-file" "{{.+}}.opt.yaml"
+! YAML: "-opt-record-format" "yaml"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -54,8 +54,16 @@
 ! HELP-NEXT: -fopenmp-version=
 ! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! HELP-NEXT: -foptimization-record-file=
+! HELP-NEXT:Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch  options.
+! HELP-NEXT: -foptimization-record-passes=
+! HELP-NEXT:Only include passes which match a specified regular expression in the generated optimization record (by default, include all passes)
 ! HELP-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! HELP-NEXT: -freciprocal-math  Allow division operations to be reassociated
+! HELP-NEXT: -fsave-optimization-record=
+! HELP-NEXT:Generate an optimization record file in a specific format
+! HELP-NEXT: -fsave-optimization-record
+! HELP-NEXT:Generate a YAML optimization record file
 ! HELP-NEXT: -fstack-arrays Attempt to allocate array temporaries on the stack, no matter their size
 ! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-NEXT: -funderscoring A

[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/test/Preprocessor/predefined-arch-macros.c:1922
+// RUN: --target=x86_64 \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_GNRD_M64
 // CHECK_GNR_M64: #define __AES__ 1

Maybe create a common CHECK_GNR_BASE prefix that you can check 
graniterapids/graniterapids-d against - currently graniterapids-d is barely 
testing anything


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

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


[PATCH] D153914: [clang-cl] Enable concatenation of predefined identifiers

2023-07-20 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 542412.
RIscRIpt marked 5 inline comments as done.
RIscRIpt added a comment.

Addressed review comments, rebased onto main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153914

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/TokenKinds.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/TokenKinds.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ms_predefined_expr.cpp
  clang/test/Sema/ms_wide_predefined_expr.cpp

Index: clang/test/Sema/ms_wide_predefined_expr.cpp
===
--- clang/test/Sema/ms_wide_predefined_expr.cpp
+++ /dev/null
@@ -1,28 +0,0 @@
-// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions
-// expected-no-diagnostics
-
-// Wide character predefined identifiers
-#define _STR2WSTR(str) L##str
-#define STR2WSTR(str) _STR2WSTR(str)
-void abcdefghi12(void) {
- const wchar_t (*ss)[12] = &STR2WSTR(__FUNCTION__);
- static int arr[sizeof(STR2WSTR(__FUNCTION__))==12*sizeof(wchar_t) ? 1 : -1];
- const wchar_t (*ss2)[31] = &STR2WSTR(__FUNCSIG__);
- static int arr2[sizeof(STR2WSTR(__FUNCSIG__))==31*sizeof(wchar_t) ? 1 : -1];
-}
-
-namespace PR13206 {
-void foo(const wchar_t *);
-
-template class A {
-public:
- void method() {
-  foo(L__FUNCTION__);
- }
-};
-
-void bar() {
- A x;
- x.method();
-}
-}
Index: clang/test/Sema/ms_predefined_expr.cpp
===
--- clang/test/Sema/ms_predefined_expr.cpp
+++ clang/test/Sema/ms_predefined_expr.cpp
@@ -1,9 +1,123 @@
 // RUN: %clang_cc1 %s -fsyntax-only -Wmicrosoft -verify -fms-extensions
 
-void f() {
+using size_t = __SIZE_TYPE__;
+
+// Test array initialization
+void array_init() {
  const char a[] = __FUNCTION__; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
  const char b[] = __FUNCDNAME__; // expected-warning{{initializing an array from a '__FUNCDNAME__' predefined identifier is a Microsoft extension}}
  const char c[] = __FUNCSIG__; // expected-warning{{initializing an array from a '__FUNCSIG__' predefined identifier is a Microsoft extension}}
  const char d[] = __func__; // expected-warning{{initializing an array from a '__func__' predefined identifier is a Microsoft extension}}
  const char e[] = __PRETTY_FUNCTION__; // expected-warning{{initializing an array from a '__PRETTY_FUNCTION__' predefined identifier is a Microsoft extension}}
+ const wchar_t f[] = L__FUNCTION__; // expected-warning{{initializing an array from a 'L__FUNCTION__' predefined identifier is a Microsoft extension}}
+ const wchar_t g[] = L__FUNCSIG__; // expected-warning{{initializing an array from a 'L__FUNCSIG__' predefined identifier is a Microsoft extension}}
+}
+
+// Test function local identifiers outside of a function
+const char* g_function = __FUNCTION__;// expected-warning{{predefined identifier is only valid inside function}}
+const char* g_function_lconcat = "" __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}} \
+  // expected-warning{{string literal concatenation of predefined identifier '__FUNCTION__' is a Microsoft extension}}
+const char* g_function_rconcat = __FUNCTION__ ""; // expected-warning{{predefined identifier is only valid inside function}} \
+  // expected-warning{{string literal concatenation of predefined identifier '__FUNCTION__' is a Microsoft extension}}
+
+namespace NS
+{
+  const char* function = __FUNCTION__;// expected-warning{{predefined identifier is only valid inside function}}
+  const char* function_lconcat = "" __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}} \
+  // expected-warning{{string literal concatenation of predefined identifier '__FUNCTION__' is a Microsoft extension}}
+  const char* function_rconcat = __FUNCTION__ ""; // expected-warning{{predefined identifier is only valid inside function}} \
+  // expected-warning{{string literal concatenation of predefined identifier '__FUNCTION__' is a Microsoft extension}}
+
+  struct S
+  {
+static constexpr const char* function = __FUNCTION__;// expected-warning{{predefined identifier is only valid inside function}}
+static constexpr const char* function_lconcat = "" __FUNCTION__; // expected-warning{{predefined identifier is only valid inside function}} \
+ // expected-warning{{string literal concatenation of predefined identifier '_

[PATCH] D153914: [clang-cl] Enable concatenation of predefined identifiers

2023-07-20 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added inline comments.



Comment at: clang/lib/Parse/ParseExpr.cpp:1310-1311
+  case tok::kw_L__FUNCSIG__:  // primary-expression: L__FUNCSIG__ [MS]
+if (!getLangOpts().MicrosoftExt ||
+!TokenIsLikeStringLiteral(NextToken(), getLangOpts())) {
+  Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind);

tahonermann wrote:
> `TokenIsLikeStringLiteral()` checks `MicrosoftExt`, so the check here is 
> redundant. This is an example of why I would like to see the `MicrosoftExt` 
> checking pushed down to `isFunctionLocalPredefinedMsMacro()`; that really 
> seems where that checking belongs to me.
Let's consider this code:
```
if (!TokenIsLikeStringLiteral(NextToken(), getLangOpts())) {
  Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind);
  ConsumeToken();
  break;
}
```

The condition can be expanded as follows: `!(isStringLiteral || (MsExt && 
NeededToken))`. Let's consider `MsExt` is `false`, then we have: 
`!isStringLiteral`. So, if next token is StringLiteral we will try to 
concatenate it even without MsExt, which is invalid. Thus this seemingly 
redundant check is needed.



Comment at: clang/lib/Parse/ParseExpr.cpp:3298-3299
+  assert(
+  (StringToks.size() != 1 ||
+   !tok::isFunctionLocalPredefinedMsMacro(StringToks[0].getKind())) &&
+  "single predefined identifiers shall be handled by ActOnPredefinedExpr");

tahonermann wrote:
> Is there a missing check for `MicrosoftExt` here? This is another example of 
> why I would prefer to see those checks pushed down to 
> `isFunctionLocalPredefinedMsMacro()`.
My intention for this `assert` is to ensure that we keep treating single 
predefined identifiers as `PredefinedExpr` (when we don't need to concat them) 
to preserve AST. I've adjusted the check to make it more clear.



Comment at: clang/lib/Parse/ParseExpr.cpp:1300-1307
+if (!getLangOpts().MicrosoftExt || !tok::isUnexpandableMsMacro(SavedKind) 
||
+!tok::isUnexpandableMsMacro(NextToken().getKind()) &&
+!tok::isStringLiteral(NextToken().getKind())) {
+  Res = Actions.ActOnPredefinedExpr(Tok.getLocation(), SavedKind);
+  ConsumeToken();
+  break;
+}

RIscRIpt wrote:
> tahonermann wrote:
> > Since the conditional code is only relevant for some of the tokens here, I 
> > would prefer to see the other token kinds (`kw___func__`, 
> > `kw___PRETTY_FUNCTION__`) handled separately to avoid the conditional 
> > fallthrough. That means duplicating the calls to 
> > `Actions.ActOnPredefinedExpr()` and `ConsumeToken()` between the blocks, 
> > but that bothers me less than having to understand the complicated 
> > condition.
> That's a valid point. And by handling two tokens separately allows 
> simplification of the condition. Adjusted code.
Having `TokenIsLikeStringLiteral` I think we can return to single case. I 
believe 3 values in condition is not difficult.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153914

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


[PATCH] D151547: [RISCV] Remove experimental for zihintntl.

2023-07-20 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

@jacquesguan yes I agree, let's hold off on merging this until that PR is 
merged as it looks like it's quite close.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151547

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


[PATCH] D155716: [clang][CodeGen] Introduce `-frecord-command-line` for MachO

2023-07-20 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added a comment.

That's an excellent patch! I didn't expect it could be so compact. Thanks for 
working on this! Please find below 2 inline comments on details.
On July 25th release/17.x will branch away. It would be great to land this 
before and have it in the upcoming release.




Comment at: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:1424
+MCSection *TargetLoweringObjectFileMachO::getSectionForCommandLines() const {
+  return getContext().getMachOSection("__TEXT", "__command_line", 0,
+  SectionKind::getReadOnly());

Can we put it in `__DATA`?

Also the [[ 
https://github.com/llvm/llvm-project/blob/release/16.x/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp#L1160
 | ELF implementation notes ]] that it "attempts to mimic GCC's switch of the 
same name" and thus calls the section `.GCC.command.line`. I guess we cannot 
use the dots in MachO, but should we add a `gcc` prefix?



Comment at: llvm/test/CodeGen/AArch64/arm64-command-line-metadata.ll:1
+; RUN: llc -mtriple=aarch64-apple-darwin < %s | FileCheck %s
+; Verify that llvm.commandline metadata is emitted to a

The triple doesn't match the name of the test: arm64-command-line-metadata.ll

Why not rename the file to `commandline-metadata.ll` (as in 
llvm/test/CodeGen/X86/commandline-metadata.ll) and maybe change the triple into 
the more common `arm64-apple`?

Optionally, we could also add RUN and CHECK lines for the existing ELF feature 
in AArch64 if there isn't one already.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155716

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


[PATCH] D155808: [clang][driver] Missing the condition in IsARMBigEndain function.

2023-07-20 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/ARM.cpp:39
 // normalized triple so we must handle the flag here.
 bool arm::isARMBigEndian(const llvm::Triple &Triple, const ArgList &Args) {
+  if ((Triple.getArch() == llvm::Triple::arm ||

Is this the right place to fix?

I would expect it to be a precondition that the Triple was Arm or Thumb before 
calling isARMBigEndian?

For example
```
if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) {
bool IsBigEndian = arm::isARMBigEndian(Triple, Args);
if (IsBigEndian)
  arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be;
CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
  }
```
Shouldn't this be refactored to only call isARMBigEndian for isARM and isThumb? 
Something like:
```
if ((Triple.isARM() || Triple.isThumb()) {
  bool BigEndian = arm::isARMBigEndian(Triple, Args);
  if (BigEndian)
arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
  CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
} else if (Triple.isAArch64)) {
  CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
}
```
This is a bit longer but it is easier to read and keeps ARM and AArch64 
separate.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155808

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


[clang] 7d4e14c - [clang][OpenMP] Add interop support for multiple depend clauses

2023-07-20 Thread Michael Halkenhaeuser via cfe-commits

Author: Michael Halkenhaeuser
Date: 2023-07-20T06:26:19-04:00
New Revision: 7d4e14c76b4e79a8718f3cb434cfcacfabd700c3

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

LOG: [clang][OpenMP] Add interop support for multiple depend clauses

This patch removes the constraint of the `interop` directive where only a single
`depend` clause was allowed.

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/interop_irbuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 0c87b70e82cfbf..7721feccb46ee2 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6968,27 +6968,27 @@ void 
CodeGenFunction::EmitOMPTeamsDistributeParallelForSimdDirective(
 void CodeGenFunction::EmitOMPInteropDirective(const OMPInteropDirective &S) {
   llvm::OpenMPIRBuilder &OMPBuilder = CGM.getOpenMPRuntime().getOMPBuilder();
   llvm::Value *Device = nullptr;
+  llvm::Value *NumDependences = nullptr;
+  llvm::Value *DependenceList = nullptr;
+
   if (const auto *C = S.getSingleClause())
 Device = EmitScalarExpr(C->getDevice());
 
-  llvm::Value *NumDependences = nullptr;
-  llvm::Value *DependenceAddress = nullptr;
-  if (const auto *DC = S.getSingleClause()) {
-OMPTaskDataTy::DependData Dependencies(DC->getDependencyKind(),
-   DC->getModifier());
-Dependencies.DepExprs.append(DC->varlist_begin(), DC->varlist_end());
-std::pair DependencePair =
-CGM.getOpenMPRuntime().emitDependClause(*this, Dependencies,
-DC->getBeginLoc());
-NumDependences = DependencePair.first;
-DependenceAddress = Builder.CreatePointerCast(
-DependencePair.second.getPointer(), CGM.Int8PtrTy);
-  }
-
-  assert(!(S.hasClausesOfKind() &&
-   !(S.getSingleClause() ||
- S.getSingleClause() ||
- S.getSingleClause())) &&
+  // Build list and emit dependences
+  OMPTaskDataTy Data;
+  buildDependences(S, Data);
+  if (!Data.Dependences.empty()) {
+Address DependenciesArray = Address::invalid();
+std::tie(NumDependences, DependenciesArray) =
+CGM.getOpenMPRuntime().emitDependClause(*this, Data.Dependences,
+S.getBeginLoc());
+DependenceList = DependenciesArray.getPointer();
+  }
+  Data.HasNowaitClause = S.hasClausesOfKind();
+
+  assert(!(Data.HasNowaitClause && !(S.getSingleClause() ||
+ S.getSingleClause() ||
+ S.getSingleClause())) &&
  "OMPNowaitClause clause is used separately in OMPInteropDirective.");
 
   if (const auto *C = S.getSingleClause()) {
@@ -7002,20 +7002,20 @@ void CodeGenFunction::EmitOMPInteropDirective(const 
OMPInteropDirective &S) {
   InteropType = llvm::omp::OMPInteropType::TargetSync;
 }
 OMPBuilder.createOMPInteropInit(Builder, InteropvarPtr, InteropType, 
Device,
-NumDependences, DependenceAddress,
-S.hasClausesOfKind());
+NumDependences, DependenceList,
+Data.HasNowaitClause);
   } else if (const auto *C = S.getSingleClause()) {
 llvm::Value *InteropvarPtr =
 EmitLValue(C->getInteropVar()).getPointer(*this);
 OMPBuilder.createOMPInteropDestroy(Builder, InteropvarPtr, Device,
-   NumDependences, DependenceAddress,
-   S.hasClausesOfKind());
+   NumDependences, DependenceList,
+   Data.HasNowaitClause);
   } else if (const auto *C = S.getSingleClause()) {
 llvm::Value *InteropvarPtr =
 EmitLValue(C->getInteropVar()).getPointer(*this);
 OMPBuilder.createOMPInteropUse(Builder, InteropvarPtr, Device,
-   NumDependences, DependenceAddress,
-   S.hasClausesOfKind());
+   NumDependences, DependenceList,
+   Data.HasNowaitClause);
   }
 }
 

diff  --git a/clang/test/OpenMP/interop_irbuilder.cpp 
b/clang/test/OpenMP/interop_irbuilder.cpp
index a0e666955ab11d..d37a53a418f2a8 100644
--- a/clang/test/OpenMP/interop_irbuilder.cpp
+++ b/clang/test/OpenMP/interop_irbuilder.cpp
@@ -7,7 +7,7 @@ typedef void *omp_interop_t;
 void test1() {
 
   int device_id = 4;
-  int D0, D1;
+  int D0, D1, D2;
   omp_interop_t interop;
 
 #pragma omp interop init(target : interop)
@@ -20,6 +20,9 @@ void test1() {
 
 #

[PATCH] D155692: [clang][OpenMP] Add interop support for multiple depend clauses

2023-07-20 Thread Michael Halkenhäuser via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d4e14c76b4e: [clang][OpenMP] Add interop support for 
multiple depend clauses (authored by mhalk).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155692

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/test/OpenMP/interop_irbuilder.cpp

Index: clang/test/OpenMP/interop_irbuilder.cpp
===
--- clang/test/OpenMP/interop_irbuilder.cpp
+++ clang/test/OpenMP/interop_irbuilder.cpp
@@ -7,7 +7,7 @@
 void test1() {
 
   int device_id = 4;
-  int D0, D1;
+  int D0, D1, D2;
   omp_interop_t interop;
 
 #pragma omp interop init(target : interop)
@@ -20,6 +20,9 @@
 
 #pragma omp interop use(interop) depend(in : D0, D1) nowait
 
+#pragma omp interop use(interop) depend(in : D0) depend(inout : D1) \
+depend(out : D2) nowait
+
 #pragma omp interop destroy(interop) depend(in : D0, D1)
 }
 
@@ -31,7 +34,7 @@
 void S::member_test() {
 
   int device_id = 4;
-  int D0, D1;
+  int D0, D1, D2;
 
 #pragma omp interop init(target : interop)
 
@@ -43,6 +46,9 @@
 
 #pragma omp interop use(interop) depend(in : D0, D1) nowait
 
+#pragma omp interop use(interop) depend(in : D0) depend(inout : D1) \
+depend(out : D2) nowait
+
 #pragma omp interop destroy(interop) depend(in : D0, D1)
 }
 // CHECK-LABEL: @_Z5test1v(
@@ -50,11 +56,14 @@
 // CHECK-NEXT:[[DEVICE_ID:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[D0:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[D1:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[D2:%.*]] = alloca i32, align 4
 // CHECK-NEXT:[[INTEROP:%.*]] = alloca ptr, align 8
 // CHECK-NEXT:[[DOTDEP_ARR_ADDR:%.*]] = alloca [2 x %struct.kmp_depend_info], align 8
 // CHECK-NEXT:[[DEP_COUNTER_ADDR:%.*]] = alloca i64, align 8
-// CHECK-NEXT:[[DOTDEP_ARR_ADDR5:%.*]] = alloca [2 x %struct.kmp_depend_info], align 8
+// CHECK-NEXT:[[DOTDEP_ARR_ADDR5:%.*]] = alloca [3 x %struct.kmp_depend_info], align 8
 // CHECK-NEXT:[[DEP_COUNTER_ADDR6:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[DOTDEP_ARR_ADDR8:%.*]] = alloca [2 x %struct.kmp_depend_info], align 8
+// CHECK-NEXT:[[DEP_COUNTER_ADDR9:%.*]] = alloca i64, align 8
 // CHECK-NEXT:store i32 4, ptr [[DEVICE_ID]], align 4
 // CHECK-NEXT:[[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1:[0-9]+]])
 // CHECK-NEXT:call void @__tgt_interop_init(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM]], ptr [[INTEROP]], i32 1, i32 -1, i32 0, ptr null, i32 0)
@@ -86,7 +95,7 @@
 // CHECK-NEXT:store i64 2, ptr [[DEP_COUNTER_ADDR]], align 8
 // CHECK-NEXT:[[OMP_GLOBAL_THREAD_NUM4:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
 // CHECK-NEXT:call void @__tgt_interop_use(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM4]], ptr [[INTEROP]], i32 -1, i32 2, ptr [[TMP2]], i32 1)
-// CHECK-NEXT:[[TMP13:%.*]] = getelementptr inbounds [2 x %struct.kmp_depend_info], ptr [[DOTDEP_ARR_ADDR5]], i64 0, i64 0
+// CHECK-NEXT:[[TMP13:%.*]] = getelementptr inbounds [3 x %struct.kmp_depend_info], ptr [[DOTDEP_ARR_ADDR5]], i64 0, i64 0
 // CHECK-NEXT:[[TMP14:%.*]] = ptrtoint ptr [[D0]] to i64
 // CHECK-NEXT:[[TMP15:%.*]] = getelementptr [[STRUCT_KMP_DEPEND_INFO]], ptr [[TMP13]], i64 0
 // CHECK-NEXT:[[TMP16:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], ptr [[TMP15]], i32 0, i32 0
@@ -102,10 +111,38 @@
 // CHECK-NEXT:[[TMP22:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], ptr [[TMP20]], i32 0, i32 1
 // CHECK-NEXT:store i64 4, ptr [[TMP22]], align 8
 // CHECK-NEXT:[[TMP23:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], ptr [[TMP20]], i32 0, i32 2
-// CHECK-NEXT:store i8 1, ptr [[TMP23]], align 8
-// CHECK-NEXT:store i64 2, ptr [[DEP_COUNTER_ADDR6]], align 8
+// CHECK-NEXT:store i8 3, ptr [[TMP23]], align 8
+// CHECK-NEXT:[[TMP24:%.*]] = ptrtoint ptr [[D2]] to i64
+// CHECK-NEXT:[[TMP25:%.*]] = getelementptr [[STRUCT_KMP_DEPEND_INFO]], ptr [[TMP13]], i64 2
+// CHECK-NEXT:[[TMP26:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], ptr [[TMP25]], i32 0, i32 0
+// CHECK-NEXT:store i64 [[TMP24]], ptr [[TMP26]], align 8
+// CHECK-NEXT:[[TMP27:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], ptr [[TMP25]], i32 0, i32 1
+// CHECK-NEXT:store i64 4, ptr [[TMP27]], align 8
+// CHECK-NEXT:[[TMP28:%.*]] = getelementptr inbounds [[STRUCT_KMP_DEPEND_INFO]], ptr [[TMP25]], i32 0, i32 2
+// CHECK-NEXT:store i8 3, ptr [[TMP28]], align 8
+// CHECK-NEXT:store i64 3, ptr [[DEP_COUNTER_ADDR6]], align 8
 // CHECK-NEXT:[[OMP_GLOBAL_THREAD_NUM7:%.*]] = call i32 @__kmpc_global_thread_num(ptr @[[GLOB1]])
-// CHECK-NEXT:call void @__tgt_interop_destroy(ptr @[[GLOB1]], i32 [[OMP_GLOBAL_THREAD_NUM7]], ptr [[INTEROP]], i32 -1, i32 2, ptr [[TMP13]], i32 0)
+// CHECK-NEXT:   

[PATCH] D155446: [clang][dataflow] Eliminate duplication between `AggregateStorageLocation` and `StructValue`.

2023-07-20 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked an inline comment as done.
mboehme added a comment.

CI failures look unrelated:

- Windows failure is in SemaCXX/static-assert-cxx26.cpp. I can't see a way in 
which this patch should affect the failure of this test (the dataflow framework 
isn't used in Clang itself)
- check-format failure is in clang/lib/Analysis/UnsafeBufferUsage.cpp, which 
this patch doesn't touch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155446

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


[PATCH] D154688: [clang] Show verify prefix in error messages

2023-07-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D154688

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


[PATCH] D154262: [clang][Interp] LambdaThisCaptures

2023-07-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154262

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


[PATCH] D154475: [clang][Interp] Fix ignoring MaterializeTemporaryExprs

2023-07-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154475

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


[PATCH] D155627: [clang][Interp] Handle SourceLocExprs

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



Comment at: clang/test/AST/Interp/builtin-functions.cpp:153
+  static_assert(__builtin_LINE() == 152, "");
+}

cor3ntin wrote:
> tbaeder wrote:
> > tbaeder wrote:
> > > cor3ntin wrote:
> > > > what is missing to enable the existing source location tests with the 
> > > > new intterpreter?
> > > There is a crash that I need to investigate first, //but// 
> > > `SemaCXX/source_location.cpp` also uses stuff like 
> > > `static_assert(noexcept(...));` that I don't handle yet.
> > Okay, after my last two patches I uploaded, the only problem missing is the 
> > broken source locations for initializers.
> I think it might be worth doing in this patch (unless it requires a lot of 
> work)
I was wrong and there's some other work needed. Namely, I need to redo how we 
do initializers. I will definitely tackel that this quarter and dial down the 
work on new features.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155627

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


[PATCH] D155627: [clang][Interp] Handle SourceLocExprs

2023-07-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 542420.

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

https://reviews.llvm.org/D155627

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Program.cpp
  clang/test/AST/Interp/builtin-functions.cpp

Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -133,3 +133,31 @@
   _Complex double CD = __arithmetic_fence(CD);
 #endif
 }
+
+namespace std {
+struct source_location {
+  struct __impl {
+unsigned int _M_line;
+const char *_M_file_name;
+signed char _M_column;
+const char *_M_function_name;
+  };
+  using BuiltinT = decltype(__builtin_source_location()); // OK.
+};
+}
+
+namespace SourceLocation {
+  constexpr auto A = __builtin_source_location();
+  static_assert(A->_M_line == 150, "");
+  static_assert(A->_M_column == 22, "");
+  static_assert(__builtin_strcmp(A->_M_function_name, "") == 0, "");
+  static_assert(__builtin_strcmp(A->_M_file_name, __FILE__) == 0, "");
+
+  static_assert(__builtin_LINE() == 156, "");
+
+  struct Foo {
+int a = __builtin_LINE();
+  };
+
+  static_assert(Foo{}.a == 162, "");
+}
Index: clang/lib/AST/Interp/Program.cpp
===
--- clang/lib/AST/Interp/Program.cpp
+++ clang/lib/AST/Interp/Program.cpp
@@ -161,9 +161,12 @@
   const Expr *Init) {
   assert(!getGlobal(VD));
   bool IsStatic, IsExtern;
-  if (auto *Var = dyn_cast(VD)) {
+  if (const auto *Var = dyn_cast(VD)) {
 IsStatic = Context::shouldBeGloballyIndexed(VD);
 IsExtern = !Var->getAnyInitializer();
+  } else if (isa(VD)) {
+IsStatic = true;
+IsExtern = false;
   } else {
 IsStatic = false;
 IsExtern = true;
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -35,6 +35,7 @@
 template  class DeclScope;
 template  class OptionScope;
 template  class ArrayIndexScope;
+template  class SourceLocScope;
 
 /// Compilation context for expressions.
 template 
@@ -100,6 +101,7 @@
   bool VisitPredefinedExpr(const PredefinedExpr *E);
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
+  bool VisitSourceLocExpr(const SourceLocExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
@@ -148,6 +150,8 @@
   bool visitRecordInitializer(const Expr *Initializer);
   /// Creates and initializes a variable from the given decl.
   bool visitVarDecl(const VarDecl *VD);
+  /// Visit an APValue.
+  bool visitAPValue(const APValue &Val, PrimType ValType, const Expr *E);
 
   /// Visits an expression and converts it to a boolean.
   bool visitBool(const Expr *E);
@@ -207,6 +211,7 @@
   friend class DeclScope;
   friend class OptionScope;
   friend class ArrayIndexScope;
+  friend class SourceLocScope;
 
   /// Emits a zero initializer.
   bool visitZeroInitializer(QualType QT, const Expr *E);
@@ -235,12 +240,14 @@
   llvm::function_ref Indirect);
 
   /// Emits an APSInt constant.
+  bool emitConst(const llvm::APSInt &Value, PrimType Ty, const Expr *E);
   bool emitConst(const llvm::APSInt &Value, const Expr *E);
   bool emitConst(const llvm::APInt &Value, const Expr *E) {
 return emitConst(static_cast(Value), E);
   }
 
   /// Emits an integer constant.
+  template  bool emitConst(T Value, PrimType Ty, const Expr *E);
   template  bool emitConst(T Value, const Expr *E);
 
   /// Returns the CXXRecordDecl for the type of the given expression,
@@ -281,6 +288,9 @@
   /// Current argument index. Needed to emit ArrayInitIndexExpr.
   std::optional ArrayIndex;
 
+  /// DefaultInit- or DefaultArgExpr, needed for SourceLocExpr.
+  const Expr *SourceLocDefaultExpr = nullptr;
+
   /// Flag indicating if return value is to be discarded.
   bool DiscardResult = false;
 };
@@ -436,6 +446,25 @@
   std::optional OldArrayIndex;
 };
 
+template  class SourceLocScope final {
+public:
+  SourceLocScope(ByteCodeExprGen *Ctx, const Expr *DefaultExpr)
+  : Ctx(Ctx) {
+assert(DefaultExpr);
+// We only switch if the current SourceLocDefaultExpr is null.
+if (!Ctx->SourceLocDefaultExpr) {
+  OldDefaultExpr = nullptr;
+  Ctx->SourceLocDefaultExpr = DefaultExpr;
+}
+  }
+
+  ~SourceLocScope() { Ctx->SourceLocDefaultExpr = OldDefaultExpr; }
+
+private:
+  ByteCodeExprGen *Ctx;
+  const Expr *OldDefaultExpr;
+};
+
 } // namespace interp
 } // namespace clang
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -

[PATCH] D155813: [clang][dataflow] Remove checks that test for consistency between `StructValue` and `AggregateStorageLocation`.

2023-07-20 Thread Martin Böhme via Phabricator via cfe-commits
mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Now that the redundancy between these two classes has been eliminated, these
checks aren't needed any more.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155813

Files:
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -27,11 +27,6 @@
 #include 
 #include 
 
-// FIXME: There are still remaining checks here that check for consistency
-// between `StructValue` and `AggregateStorageLocation`. Now that the redundancy
-// between these two classes has been eliminated, these checks aren't needed any
-// more, so remove them.
-
 namespace {
 
 using namespace clang;
@@ -268,13 +263,7 @@
 
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
-const auto *BarLoc =
-cast(FooLoc->getChild(*BarDecl));
-
-const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal =
-cast(getFieldValue(FooVal, *BarDecl, Env));
-EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
+EXPECT_TRUE(isa(getFieldValue(FooLoc, *BarDecl, Env)));
   });
 }
 
@@ -317,13 +306,7 @@
 
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
-const auto *BarLoc =
-cast(FooLoc->getChild(*BarDecl));
-
-const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal =
-cast(getFieldValue(FooVal, *BarDecl, Env));
-EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
+EXPECT_TRUE(isa(getFieldValue(FooLoc, *BarDecl, Env)));
   });
 }
 
@@ -365,13 +348,7 @@
 
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
-const auto *BarLoc =
-cast(FooLoc->getChild(*BarDecl));
-
-const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal =
-cast(getFieldValue(FooVal, *BarDecl, Env));
-EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
+EXPECT_TRUE(isa(getFieldValue(FooLoc, *BarDecl, Env)));
   });
 }
 
@@ -1046,13 +1023,7 @@
 
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
-const auto *BarLoc =
-cast(FooLoc->getChild(*BarDecl));
-
-const auto *FooVal = cast(Env.getValue(*FooLoc));
-const auto *BarVal =
-cast(getFieldValue(FooVal, *BarDecl, Env));
-EXPECT_EQ(Env.getValue(*BarLoc), BarVal);
+EXPECT_TRUE(isa(getFieldValue(FooLoc, *BarDecl, Env)));
   });
 }
 
@@ -1150,9 +1121,8 @@
 
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
-const auto *FooVal = cast(Env.getValue(*FooLoc));
 const auto *BarVal =
-cast(getFieldValue(FooVal, *BarDecl, Env));
+cast(getFieldValue(FooLoc, *BarDecl, Env));
 
 const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
 ASSERT_THAT(BazDecl, NotNull());
@@ -1392,9 +1362,8 @@
 
 const auto *FooLoc =
 cast(Env.getStorageLocation(*FooDecl));
-const auto *FooVal = cast(Env.getValue(*FooLoc));
 const auto *BarVal =
-cast(getFieldValue(FooVal, *BarDecl, Env));
+cast(getFieldValue(FooLoc, *BarDecl, Env));
 
 const ValueDecl *BazDecl = findValueDecl(ASTCtx, "Baz");
 ASSERT_THAT(BazDecl, NotNull());
@@ -1553,14 +1522,10 @@
 
 const auto *QuxLoc =
 cast(ThisLoc->getChild(*QuxDecl));
-const auto *QuxVal = dyn_cast(Env.getValue(*QuxLoc));
-ASSERT_THAT(QuxVal, NotNull());
+EXPECT_THAT(dyn_cast(Env.getValue(*QuxLoc)), NotNull());
 
-const auto *BazLoc =
-cast(QuxLoc->getChild(*BazDecl));
 const auto *BazVal =
-cast(getFieldValue(QuxVal, *BazDecl, Env));
-EXPECT_EQ(Env.getValue(*BazLoc), BazVal);
+cast(getFieldValue(QuxLoc, *BazDecl, Env));
 
 const ValueDecl *QuuxDecl = findValueDecl(ASTCtx, "Quux");
 ASSERT_THAT(QuuxDecl, NotNull());
@@ -1628,14 +1593,10 @@
 
 const auto *QuxLoc =
 cast(ThisLoc->getChild(*QuxDecl));
-const auto *QuxVal = dyn_cast(Env.getValue(*QuxLoc));
-ASSERT_THAT(QuxVal, NotNull());
+EXPECT_THAT(dyn_cast(Env.getValue(*QuxLoc)), NotNull());
 
-const auto *BazLoc =
-cast(QuxLoc->getChild(*BazDecl));
 const auto *BazVal =
-cast(getFieldValue(QuxVal, *BazDecl, Env));
-EXPECT_EQ(Env.getValue(*BazLoc), BazVal);
+cast(getFieldValue(QuxLoc, *BazDecl, Env));
 
 const ValueDec

[PATCH] D144164: [clang][Interp] Handle PtrMemOps

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



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:213-214
 
+  if (BO->isPtrMemOp())
+return this->visit(RHS);
+

aaron.ballman wrote:
> Do we need similar changes for unary operators, pointer arithmetic operators, 
> etc?
In what case would we need similar changes for those?



Comment at: clang/lib/AST/Interp/Context.cpp:121
+  if (T->isFunctionPointerType() || T->isFunctionReferenceType() ||
+  T->isFunctionProtoType())
+return PT_FnPtr;

aaron.ballman wrote:
> `isFunctionType()` in general?
You mean additionally to those or as a replacement? `isFunctionType()` return 
false for function pointers it seems.


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

https://reviews.llvm.org/D144164

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


[PATCH] D155814: Fix the linting problems which caused `clang/utils/ci/run-buildbot check-format` to return 1.

2023-07-20 Thread Amirreza Ashouri via Phabricator via cfe-commits
AMP999 created this revision.
AMP999 added a reviewer: clang.
AMP999 added a project: clang.
Herald added a reviewer: NoQ.
Herald added a project: All.
AMP999 requested review of this revision.
Herald added a subscriber: cfe-commits.

`clang/utils/ci/run-buildbot check-format` command in build process caused my 
last differential, https://reviews.llvm.org/D155714, to fail 
(https://buildkite.com/llvm-project/clang-ci/builds/355) and when I checked the 
logs and found out that the problem doesn't reside in my change. So I fixed the 
linting problem in the `clang/lib/Analysis/UnsafeBufferUsage.cpp` file which is 
to remove some redundant white spaces.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155814

Files:
  clang/lib/Analysis/UnsafeBufferUsage.cpp


Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1890,10 +1890,10 @@
   const ParmVarDecl *Parm = FD->getParamDecl(i);
 
   if (Parm->isImplicit())
-continue;  
+continue;
   // FIXME: If a parameter has no name, it is unused in the
   // definition. So we could just leave it as it is.
-  if (!Parm->getIdentifier()) 
+  if (!Parm->getIdentifier())
// If a parameter of a function definition has no name:
 return std::nullopt;
   if (i == ParmIdx)


Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -1890,10 +1890,10 @@
   const ParmVarDecl *Parm = FD->getParamDecl(i);
 
   if (Parm->isImplicit())
-continue;  
+continue;
   // FIXME: If a parameter has no name, it is unused in the
   // definition. So we could just leave it as it is.
-  if (!Parm->getIdentifier()) 
+  if (!Parm->getIdentifier())
 	// If a parameter of a function definition has no name:
 return std::nullopt;
   if (i == ParmIdx)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155165: [clang][Interp] Fully serialize Floatings to bytes

2023-07-20 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155165

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


[PATCH] D155816: [Tooling/Inclusion] Make the Recognizer work for C99 code.

2023-07-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a project: All.
hokein requested review of this revision.
Herald added a project: clang.

C99 is the the earliest C version provided by the language opt.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155816

Files:
  clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
  clang/unittests/Tooling/StandardLibraryTest.cpp


Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -174,6 +174,17 @@
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
+TEST(StdlibTest, RecognizerForC99) {
+  TestInputs Input("typedef char uint8_t;");
+  Input.Language = TestLanguage::Lang_C99;
+  TestAST AST(Input);
+
+  auto &Uint8T = lookup(AST, "uint8_t");
+  stdlib::Recognizer Recognizer;
+  EXPECT_EQ(Recognizer(&Uint8T),
+stdlib::Symbol::named("", "uint8_t", stdlib::Lang::C));
+}
+
 } // namespace
 } // namespace tooling
 } // namespace clang
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -247,13 +247,12 @@
 
 std::optional Recognizer::operator()(const Decl *D) {
   Lang L;
-  if (D->getLangOpts().CPlusPlus) {
+  if (D->getLangOpts().CPlusPlus)
 L = Lang::CXX;
-  } else if (D->getLangOpts().C11) {
+  else if (D->getLangOpts().C99)
 L = Lang::C;
-  } else {
+  else
 return std::nullopt; // not a supported language.
-  }
 
   // If D is std::vector::iterator, `vector` is the outer symbol to look up.
   // We keep all the candidate DCs as some may turn out to be anon enums.


Index: clang/unittests/Tooling/StandardLibraryTest.cpp
===
--- clang/unittests/Tooling/StandardLibraryTest.cpp
+++ clang/unittests/Tooling/StandardLibraryTest.cpp
@@ -174,6 +174,17 @@
   EXPECT_EQ(Recognizer(Sec), std::nullopt);
 }
 
+TEST(StdlibTest, RecognizerForC99) {
+  TestInputs Input("typedef char uint8_t;");
+  Input.Language = TestLanguage::Lang_C99;
+  TestAST AST(Input);
+
+  auto &Uint8T = lookup(AST, "uint8_t");
+  stdlib::Recognizer Recognizer;
+  EXPECT_EQ(Recognizer(&Uint8T),
+stdlib::Symbol::named("", "uint8_t", stdlib::Lang::C));
+}
+
 } // namespace
 } // namespace tooling
 } // namespace clang
Index: clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
===
--- clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -247,13 +247,12 @@
 
 std::optional Recognizer::operator()(const Decl *D) {
   Lang L;
-  if (D->getLangOpts().CPlusPlus) {
+  if (D->getLangOpts().CPlusPlus)
 L = Lang::CXX;
-  } else if (D->getLangOpts().C11) {
+  else if (D->getLangOpts().C99)
 L = Lang::C;
-  } else {
+  else
 return std::nullopt; // not a supported language.
-  }
 
   // If D is std::vector::iterator, `vector` is the outer symbol to look up.
   // We keep all the candidate DCs as some may turn out to be anon enums.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-20 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added inline comments.



Comment at: clang/test/Preprocessor/predefined-arch-macros.c:1922
+// RUN: --target=x86_64 \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_GNRD_M64
 // CHECK_GNR_M64: #define __AES__ 1

RKSimon wrote:
> Maybe create a common CHECK_GNR_BASE prefix that you can check 
> graniterapids/graniterapids-d against - currently graniterapids-d is barely 
> testing anything
Oh, it should be `-check-prefixes=CHECK_GNR_M64,CHECK_GNRD_M64`
I did this before, like: 
https://github.com/llvm/llvm-project/blob/a2160dd34d56ea5440cbb805657bfee0e2228073/clang/test/Preprocessor/predefined-arch-macros.c#L370


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

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


[clang] 465f65a - [clang][Interp][NFC] Add a debugging assertion

2023-07-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-20T14:06:09+02:00
New Revision: 465f65a549e5fd092f6da8b09d0f1d50ca7f4ddc

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

LOG: [clang][Interp][NFC] Add a debugging assertion

We will probably have to remove this at some point, but until then, make
sure we're not running into much-harder-to-debug problems later on.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index c6c4c787e5d849..ad838755c47a58 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1806,6 +1806,7 @@ bool ByteCodeExprGen::VisitCXXMemberCallExpr(
 template 
 bool ByteCodeExprGen::VisitCXXDefaultInitExpr(
 const CXXDefaultInitExpr *E) {
+  assert(classify(E->getType()));
   return this->visit(E->getExpr());
 }
 



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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 542435.
cor3ntin added a comment.

Remove an assert (added in a previous iteration of this PR).

Unfortunately, we sometimes do emit the address of an immediate function,
after we establish the program is ill-formed - as we still proceed to code gen.

  cpp
  
  consteval int id(int i) { return i; }
  constexpr int f(auto t) { 
  return t + id(t); 
  }
  
  auto b = &f;

We establish taking the address of &f is not possible
when exiting the evaluation context.
At this point b has an init expression, which codegen will try to emit.
Ideally we should try to remove the init all together after the fact but so far
I have not been able to do so.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

Files:
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/cxx2c-consteval-propagate.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
===
--- clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value %s -verify
-// RUN: %clang_cc1 -std=c++2b -emit-llvm-only -Wno-unused-value %s -verify
+// RUN: %clang_cc1 -std=c++2a -Wno-unused-value %s -verify
+// RUN: %clang_cc1 -std=c++2b -Wno-unused-value %s -verify
 
 consteval int id(int i) { return i; }
 constexpr char id(char c) { return c; }
@@ -34,7 +34,7 @@
 
 template 
 constexpr T h(T t = id(x)) { // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}} \
- // expected-note 2{{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+ // expected-note {{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
 return t;
 }
 
@@ -164,3 +164,169 @@
 int i = g(x); // expected-error {{call to immediate function 'ConstevalConstructor::g' is not a constant expression}} \
   // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}}
 }
+
+
+
+namespace Aggregate {
+consteval int f(int); // expected-note {{declared here}}
+struct S {
+  int x = f(42); // expected-note {{undefined function 'f' cannot be used in a constant expression}} \
+ // expected-note {{'immediate' is an immediate function because its body contains a call to a consteval function 'f' and that call is not a constant expression}}
+};
+
+constexpr S immediate(auto) {
+return S{};
+}
+
+void test_runtime() {
+(void)immediate(0); // expected-error {{call to immediate function 'Aggregate::immediate' is not a constant expression}} \
+// expected-note {{in call to 'immediate(0)'}}
+}
+consteval int f(int i) {
+return i;
+}
+consteval void test() {
+constexpr S s = immediate(0);
+static_assert(s.x == 42);
+}
+}
+
+
+
+namespace GH63742 {
+void side_effect(); // expected-note  {{declared here}}
+consteval int f(int x) {
+if (!x) side_effect(); // expected-note {{non-constexpr function 'side_effect' cannot be used in a constant expression}}
+return x;
+}
+struct SS {
+  int y = f(1); // Ok
+  int x = f(0); // expected-error {{call to consteval function 'GH63742::f' is not a constant expression}} \
+// expected-note  {{declared here}} \
+// expected-note  {{in call to 'f(0)'}}
+  SS();
+};
+SS::SS(){} // expected-note {{in the default initializer of 'x'}}
+
+consteval int f2(int x) {
+if (!__builtin_is_constant_evaluated()) side_effect();
+return x;
+}
+struct S2 {
+int x = f2(0);
+constexpr S2();
+};
+
+constexpr S2::S2(){}
+S2 s = {};
+constinit S2 s2 = {};
+
+struct S3 {
+int x = f2(0);
+S3();
+};
+S3::S3(){}
+
+}
+
+namespace Defaulted {
+consteval int f(int x);
+struct SS {
+  int x = f(0);
+  SS() = default;
+};
+}
+
+namespace DefaultedUse{
+consteval int f(int x);  // expected-note {{declared here}}
+struct SS {
+  int a = sizeof(f(0)); // Ok
+  int x = f(0); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
+
+  SS() = default; // expected-note {{'SS' is an immediate constructor because the default initializer of 'x' contains a call to a consteval function 'f' and that call is not a constant expression}}
+};
+
+void test() {
+[[maybe_unused]] SS s; // expected-error {{

[PATCH] D134475: [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute

2023-07-20 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 542436.
RIscRIpt marked 3 inline comments as done.
RIscRIpt added a comment.
Herald added a subscriber: MaskRay.

Addressed review comments and rebased onto main.

I have limited support of this attribute to `-fms-compatibility-version` 19.33+ 
(Visual Studio version, when this attribute first appeared).
Added definition of `_MSVC_CONSTEXPR_ATTRIBUTE`.

I am not sure whether and where to mention about adding support of this 
attribute in release notes.

Additionally, bumped `-fms-compatibility-version` to 19.33 in a separate 
commit. Although, I am not aware of all the consequences of this change.

Changed test files their names and locations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134475

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -753,7 +753,7 @@
 
 // Validate that the default triple is used when run an empty tools dir is 
specified
 // RUN: %clang_cl -vctoolsdir "" -### -- %s 2>&1 | FileCheck %s --check-prefix 
VCTOOLSDIR
-// VCTOOLSDIR: "-triple" "{{[a-zA-Z0-9_-]*}}-pc-windows-msvc19.20.0"
+// VCTOOLSDIR: "-triple" "{{[a-zA-Z0-9_-]*}}-pc-windows-msvc19.33.0"
 
 // Validate that built-in include paths are based on the supplied path
 // RUN: %clang_cl --target=aarch64-pc-windows-msvc -vctoolsdir "/fake" 
-winsdkdir "/foo" -winsdkversion 10.0.12345.0 -### -- %s 2>&1 | FileCheck %s 
--check-prefix FAKEDIR
@@ -793,7 +793,7 @@
 
 // RUN: %clang_cl -vctoolsdir "" /arm64EC /c -### -- %s 2>&1 | FileCheck 
--check-prefix=ARM64EC %s 
 // ARM64EC-NOT: /arm64EC has been overridden by specified target
-// ARM64EC: "-triple" "arm64ec-pc-windows-msvc19.20.0"
+// ARM64EC: "-triple" "arm64ec-pc-windows-msvc19.33.0"
 
 // RUN: %clang_cl -vctoolsdir "" /arm64EC /c -target x86_64-pc-windows-msvc  
-### -- %s 2>&1 | FileCheck --check-prefix=ARM64EC_OVERRIDE %s
 // ARM64EC_OVERRIDE: warning: /arm64EC has been overridden by specified 
target: x86_64-pc-windows-msvc; option ignored
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -787,11 +787,11 @@
   if (MSVT.empty() &&
   Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
IsWindowsMSVC)) {
-// -fms-compatibility-version=19.20 is default, aka 2019, 16.x
+// -fms-compatibility-version=19.33 is default, aka 2022, 17.3
 // NOTE: when changing this value, also update
 // clang/docs/CommandGuide/clang.rst and clang/docs/UsersManual.rst
 // accordingly.
-MSVT = VersionTuple(19, 20);
+MSVT = VersionTuple(19, 33);
   }
   return MSVT;
 }
Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -3314,8 +3314,8 @@
 
 For compatibility with existing code that compiles with MSVC, clang defines the
 ``_MSC_VER`` and ``_MSC_FULL_VER`` macros. When on Windows, these default to
-either the same value as the currently installed version of cl.exe, or ``1920``
-and ``19200`` (respectively). The ``-fms-compatibility-version=`` flag
+either the same value as the currently installed version of cl.exe, or ``1933``
+and ``19330`` (respectively). The ``-fms-compatibility-version=`` flag
 overrides these values.  It accepts a dotted version tuple, such as 
19.00.23506.
 Changing the MSVC compatibility version makes clang behave more like that
 version of MSVC. For example, ``-fms-compatibility-version=19`` will enable
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -262,6 +262,8 @@
 - Added ``__builtin_elementwise_nearbyint`` for floating point
   types. This allows access to ``llvm.nearbyint`` for arbitrary
   floating-point and vector of floating-point types.
+- The default value of `_MSC_VER` was raised from 1920 to 1933.
+  MSVC 19.33 added undocumented attribute ``[[msvc::constexpr]]``.
 
 New Compiler Flags
 --


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -753,7 +753,7 @@
 
 // Validate that the default triple is used when run an empty tools dir is specified
 // RUN: %clang_cl -vctoolsdir "" -### -- %s 2>&1 | FileCheck %s --check-prefix VCTOOLSDIR
-// VCTOOLSDIR: "-triple" "{{[a-zA-Z0-9_-]*}}-pc-windows-msvc19.20.0"
+// VCTOOLSDIR: "-triple" "{{[a-zA-Z0-9_-]*}}-pc-windows-msvc19.33.0"
 
 /

[PATCH] D134475: [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute

2023-07-20 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:3609-3611
+.. Note:: To use a ``[[msvc::constexpr]]`` function in a constant context,
+   one may want to create a ``constexpr`` function-wrapper and invoke the
+   ``[[msvc::constexpr]]`` function within a ``[[msvc::constexpr]] return`` 
statement.

RIscRIpt wrote:
> As per latest comments, maybe I should remove this note?
Removed.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2817
+  "[[msvc::constexpr]] has effect only on function definitions and return 
statements">,
+  InGroup;
 

> Given that the intended use case is for usage behind the scenes in the 
> standard library, I don't think we should be changing our diagnostic output 
> at all [there]

How about other places? Theoretically I could re-use existing warnings/errors 
with diagnostics saying `constexpr` instead of `[[msvc::constexpr]]`.



Comment at: clang/lib/AST/ExprConstant.cpp:5615-5627
+if (canEvalMSConstexpr || isMSConstexpr) {
+  // Diagnose invalid usage of [[msvc::constexpr]] function
+  bool isConstructor = isa(Definition);
+  if (canEvalMSConstexpr) { // !isMSConstexpr
+Info.FFDiag(CallLoc, diag::note_constexpr_invalid_function, 1)
+<< /*IsConstexpr*/ 0 << isConstructor << Definition;
+Info.Note(Definition->getLocation(), diag::note_declared_at);

RIscRIpt wrote:
> rsmith wrote:
> > Given that the intended use case is for usage behind the scenes in the 
> > standard library, I don't think we should be changing our diagnostic output 
> > at all here. If the library, as an implementation detail, marks a 
> > non-`constexpr` function as `[[msvc::constexpr]]`, we shouldn't tell the 
> > user to add `[[msvc::constexpr]]` to their code to allow it to be called, 
> > after all, the annotation is an implementation detail of the MS standard 
> > library.
> Sounds fair, I will adjust this code if I'm unable to convince you with my 
> new comments.
Removed, and made the check as a single `if` statement.



Comment at: clang/lib/AST/ExprConstant.cpp:9591-9594
+  bool IsMSConstexpr = Info.CurrentCall->CanEvalMSConstexpr &&
+   OperatorNew->hasAttr();
   if (OperatorNew->isReservedGlobalPlacementOperator() &&
+  (Info.CurrentCall->isStdFunction() || IsMSConstexpr) && !E->isArray()) {

rsmith wrote:
> RIscRIpt wrote:
> > rsmith wrote:
> > > Do we really need this change? Was our existing check of whether the 
> > > caller is in namespace `std` not sufficient for MS' standard library? I'd 
> > > strongly prefer not to have a documented, user-visible attribute that 
> > > gives permission to use placement new directly.
> > Yes, STL's `operator new` is defined in global namespace in [[ 
> > https://gist.github.com/RIscRIpt/9f0991f09f97eafc375fc73ea851a81b#file-vcruntime_new-h-L165
> >  | vcruntime_new.h ]] (and all includes of this file are made from global 
> > namespace).
> The existing code is checking whether the caller of `operator new` (eg, 
> `std::construct_at`) is in namespace `std`, not whether the `operator new` 
> itself is. Does MSVC's `construct_at` need this? It might if it uses a 
> placement new indirectly via a function in a different namespace, but it 
> seems likely to me that it doesn't.
Yes, sorry, my bad. This change is not needed, unless we want to support this 
attribute in user-code, which I guess we don't want to.

Removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134475

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


[PATCH] D134475: [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute

2023-07-20 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 542438.
RIscRIpt added a comment.

add HEAD~2 patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134475

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/AST/ms-constexpr.cpp
  clang/test/Driver/cl-options.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCXX/ms-constexpr-invalid.cpp
  clang/test/SemaCXX/ms-constexpr-new.cpp
  clang/test/SemaCXX/ms-constexpr.cpp

Index: clang/test/SemaCXX/ms-constexpr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-constexpr.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -ast-dump -verify %s | FileCheck %s
+// expected-no-diagnostics
+
+[[msvc::constexpr]] int log2(int x) { [[msvc::constexpr]] return x > 1 ? 1 + log2(x / 2) : 0; }
+constexpr bool test_log2() { [[msvc::constexpr]] return log2(32) == 5; }
+static_assert(test_log2());
+
+[[msvc::constexpr]] int get_value(int x)
+{
+  switch (x)
+  {
+case 42: return 1337;
+default:
+ if (x < 0) [[msvc::constexpr]] return log2(-x);
+ else return x;
+  }
+}
+
+constexpr bool test_complex_expr() {
+  [[msvc::constexpr]] return get_value(get_value(42) - 1337 + get_value(-32) - 5 + (get_value(1) ? get_value(0) : get_value(2))) == get_value(0);
+}
+static_assert(test_complex_expr());
+
+constexpr bool get_constexpr_true() { return true; }
+[[msvc::constexpr]] bool get_msconstexpr_true() { return get_constexpr_true(); }
+constexpr bool test_get_msconstexpr_true() { [[msvc::constexpr]] return get_msconstexpr_true(); }
+static_assert(test_get_msconstexpr_true());
+
+/*
+// TODO: Add support for [[msvc::constexpr]] constructor
+struct S2 {
+[[msvc::constexpr]] S2() {}
+[[msvc::constexpr]] bool value() { return true; }
+static constexpr bool check() { [[msvc::constexpr]] return S2{}.value(); }
+};
+static_assert(S2::check());
+*/
Index: clang/test/SemaCXX/ms-constexpr-new.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-constexpr-new.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify=supported %s
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.32 -std=c++20 -verify=unsupported %s
+// supported-no-diagnostics
+
+[[nodiscard]]
+[[msvc::constexpr]] // unsupported-warning {{unknown attribute 'constexpr' ignored}}
+inline void* __cdecl operator new(decltype(sizeof(void*)), void* p) noexcept { return p; }
+
+namespace std {
+  constexpr int* construct_at(int* p, int v) {
+[[msvc::constexpr]] return ::new (p) int(v); // unsupported-warning {{unknown attribute 'constexpr' ignored}}
+  }
+}
+
+constexpr bool check_construct_at() { int x; return *std::construct_at(&x, 42) == 42; }
+static_assert(check_construct_at());
Index: clang/test/SemaCXX/ms-constexpr-invalid.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-constexpr-invalid.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify %s
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++17 -verify %s
+
+// Check explicitly invalid code
+
+void runtime() {} // expected-note {{declared here}}
+
+[[msvc::constexpr]] void f0() { runtime(); } // expected-error {{[[msvc::constexpr]] function never produces a constant expression}} \
+ // expected-note {{non-constexpr function 'runtime' cannot be used in a constant expression}}
+[[msvc::constexpr]] constexpr void f1() {} // expected-error {{[[msvc::constexpr]] cannot be applied to a constexpr function 'f1'}}
+#if __cplusplus >= 202202L
+[[msvc::constexpr]] consteval void f2() {} // expected-error {{[[msvc::constexpr]] cannot be applied to a consteval function 'f2'}}
+#endif
+
+struct B1 {};
+struct D1 : virtual B1 { // expected-note {{virtual base class declared here}}
+[[msvc::constexpr]] D1() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}}
+};
+
+struct [[msvc::constexpr]] S2{}; // expected-error {{'constexpr' attribute only applies to functions and statements}}
+
+// Check invalid code mixed with valid code
+
+[[msvc::constexpr]] int f4(int x) { return x > 1 ? 1 + f4(x / 2) : 0; } // expected-note {{non-constexpr

[PATCH] D154475: [clang][Interp] Fix ignoring MaterializeTemporaryExprs

2023-07-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@aaron.ballman any opinion on that?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154475

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


[PATCH] D134475: [clang-cl] Add support for [[msvc::constexpr]] C++11 attribute

2023-07-20 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 542441.
RIscRIpt added a comment.

Fix clang/test/SemaCXX/ms-constexpr.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134475

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/Targets/OSTargets.cpp
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaStmtAttr.cpp
  clang/test/AST/ms-constexpr.cpp
  clang/test/Driver/cl-options.c
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaCXX/ms-constexpr-invalid.cpp
  clang/test/SemaCXX/ms-constexpr-new.cpp
  clang/test/SemaCXX/ms-constexpr.cpp

Index: clang/test/SemaCXX/ms-constexpr.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-constexpr.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+[[msvc::constexpr]] int log2(int x) { [[msvc::constexpr]] return x > 1 ? 1 + log2(x / 2) : 0; }
+constexpr bool test_log2() { [[msvc::constexpr]] return log2(32) == 5; }
+static_assert(test_log2());
+
+[[msvc::constexpr]] int get_value(int x)
+{
+  switch (x)
+  {
+case 42: return 1337;
+default:
+ if (x < 0) [[msvc::constexpr]] return log2(-x);
+ else return x;
+  }
+}
+
+constexpr bool test_complex_expr() {
+  [[msvc::constexpr]] return get_value(get_value(42) - 1337 + get_value(-32) - 5 + (get_value(1) ? get_value(0) : get_value(2))) == get_value(0);
+}
+static_assert(test_complex_expr());
+
+constexpr bool get_constexpr_true() { return true; }
+[[msvc::constexpr]] bool get_msconstexpr_true() { return get_constexpr_true(); }
+constexpr bool test_get_msconstexpr_true() { [[msvc::constexpr]] return get_msconstexpr_true(); }
+static_assert(test_get_msconstexpr_true());
+
+/*
+// TODO: Add support for [[msvc::constexpr]] constructor
+struct S2 {
+[[msvc::constexpr]] S2() {}
+[[msvc::constexpr]] bool value() { return true; }
+static constexpr bool check() { [[msvc::constexpr]] return S2{}.value(); }
+};
+static_assert(S2::check());
+*/
Index: clang/test/SemaCXX/ms-constexpr-new.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-constexpr-new.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify=supported %s
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.32 -std=c++20 -verify=unsupported %s
+// supported-no-diagnostics
+
+[[nodiscard]]
+[[msvc::constexpr]] // unsupported-warning {{unknown attribute 'constexpr' ignored}}
+inline void* __cdecl operator new(decltype(sizeof(void*)), void* p) noexcept { return p; }
+
+namespace std {
+  constexpr int* construct_at(int* p, int v) {
+[[msvc::constexpr]] return ::new (p) int(v); // unsupported-warning {{unknown attribute 'constexpr' ignored}}
+  }
+}
+
+constexpr bool check_construct_at() { int x; return *std::construct_at(&x, 42) == 42; }
+static_assert(check_construct_at());
Index: clang/test/SemaCXX/ms-constexpr-invalid.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/ms-constexpr-invalid.cpp
@@ -0,0 +1,52 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++20 -verify %s
+// RUN: %clang_cc1 -fms-compatibility -fms-compatibility-version=19.33 -std=c++17 -verify %s
+
+// Check explicitly invalid code
+
+void runtime() {} // expected-note {{declared here}}
+
+[[msvc::constexpr]] void f0() { runtime(); } // expected-error {{[[msvc::constexpr]] function never produces a constant expression}} \
+ // expected-note {{non-constexpr function 'runtime' cannot be used in a constant expression}}
+[[msvc::constexpr]] constexpr void f1() {} // expected-error {{[[msvc::constexpr]] cannot be applied to a constexpr function 'f1'}}
+#if __cplusplus >= 202202L
+[[msvc::constexpr]] consteval void f2() {} // expected-error {{[[msvc::constexpr]] cannot be applied to a consteval function 'f2'}}
+#endif
+
+struct B1 {};
+struct D1 : virtual B1 { // expected-note {{virtual base class declared here}}
+[[msvc::constexpr]] D1() {} // expected-error {{constexpr constructor not allowed in struct with virtual base class}}
+};
+
+struct [[msvc::constexpr]] S2{}; // expected-error {{'constexpr' attribute only applies to functions and statements}}
+
+// Check invalid code mixed with valid code
+
+[[msvc::constexpr]] int f4(int x) { return x > 1 ? 1 + f4(x / 2) : 0; } // expected-note {{non-constexpr f

[PATCH] D155819: [include-cleaner] Loose matching for verbatim headers

2023-07-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

A verbatim header usually corresponds to a symbol from a header with
a pragma "IWYU pragma: private, include ".

Currently this is only satisfied if the main file contains exactly

  #include 

In practice this is too strict, we also want to allow

  #include "path/to/foo.h"

so long as they resolve to the same file.

We cannot be 100% sure without doing IO, and we're not willing to do
that, but we can detect the common cases based on paths.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155819

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/lib/Types.cpp
  clang-tools-extra/include-cleaner/unittests/TypesTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
@@ -17,6 +17,8 @@
 namespace clang::include_cleaner {
 namespace {
 using testing::ElementsAre;
+using testing::IsEmpty;
+using testing::UnorderedElementsAre;
 
 // Matches an Include* on the specified line;
 MATCHER_P(line, N, "") { return arg->Line == (unsigned)N; }
@@ -43,5 +45,37 @@
   ElementsAre(line(4), line(5)));
 }
 
+TEST(RecordedIncludesTest, MatchVerbatim) {
+  auto FS = llvm::makeIntrusiveRefCnt();
+  FileManager FM(FileSystemOptions{});
+
+  Includes Inc;
+
+  // By default, a verbatim header only matches includes with the same spelling.
+  const FileEntry *Foo =
+  FM.getVirtualFile("repo/lib/include/rel/foo.h", /*Size=*/0, time_t{});
+  Inc.add(Include{"lib/include/rel/foo.h", Foo, SourceLocation(), 1});
+  Inc.add(Include{"rel/foo.h", Foo, SourceLocation(), 2});
+  EXPECT_THAT(Inc.match(Header("")), ElementsAre(line(2)));
+
+  // A verbatim header can match another spelling if the search path
+  // suggests it's equivalent.
+  const FileEntry *Bar =
+  FM.getVirtualFile("repo/lib/include/rel/bar.h", /*Size=*/0, time_t{});
+  Inc.addSearchDirectory("repo/");
+  Inc.addSearchDirectory("repo/lib/include");
+  Inc.add(Include{"lib/include/rel/bar.h", Bar, SourceLocation(), 3});
+  Inc.add(Include{"rel/bar.h", Bar, SourceLocation(), 4});
+  EXPECT_THAT(Inc.match(Header("")),
+  UnorderedElementsAre(line(3), line(4)));
+
+  // We don't apply this logic to system headers, though.
+  const FileEntry *Vector =
+  FM.getVirtualFile("repo/lib/include/vector", /*Size=*/0, time_t{});
+  Inc.add(Include{"lib/include/vector", Vector, SourceLocation(), 5});
+  EXPECT_THAT(Inc.match(Header(*tooling::stdlib::Header::named(""))),
+  IsEmpty());
+}
+
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/Types.cpp
===
--- clang-tools-extra/include-cleaner/lib/Types.cpp
+++ clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -10,8 +10,15 @@
 #include "TypesInternal.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/FileEntry.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 namespace clang::include_cleaner {
 
@@ -94,16 +101,51 @@
   .str();
 }
 
+static llvm::SmallString<128> normalizePath(llvm::StringRef Path) {
+  namespace path = llvm::sys::path;
+
+  llvm::SmallString<128> P = Path;
+  path::remove_dots(P, /*remove_dot_dot=*/true);
+  path::native(P, path::Style::posix);
+  while (!P.empty() && path::is_separator(P.back()))
+P.pop_back();
+  return P;
+}
+
+void Includes::addSearchDirectory(llvm::StringRef Path) {
+  SearchPath.try_emplace(normalizePath(Path));
+}
+
 void Includes::add(const Include &I) {
+  namespace path = llvm::sys::path;
+
   unsigned Index = All.size();
   All.push_back(I);
   auto BySpellingIt = BySpelling.try_emplace(I.Spelled).first;
   All.back().Spelled = BySpellingIt->first(); // Now we own the backing string.
 
   BySpellingIt->second.push_back(Index);
-  if (I.Resolved)
-ByFile[I.Resolved].push_back(Index);
   ByLine[I.Line] = Index;
+  if (I.Resolved) {
+ByFile[I.Resolved].push_back(Index);
+
+// While verbatim headers ideally should match #include spelling exactly,
+// we want to be tolerant of different spellings of the same file.
+//
+// If the search path includes "/a/b" and "/a/b/c/d",
+// verbatim "e/f" should match (spelled=c/d/e/f, resolv

[PATCH] D155819: [include-cleaner] Loose matching for verbatim headers

2023-07-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 542444.
sammccall added a comment.
Herald added a subscriber: ormris.

clean up some leftovers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155819

Files:
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/include-cleaner/lib/Types.cpp
  clang-tools-extra/include-cleaner/unittests/TypesTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/TypesTest.cpp
@@ -8,6 +8,7 @@
 
 #include "clang-include-cleaner/Types.h"
 #include "clang/Basic/FileManager.h"
+#include "clang/Basic/FileSystemOptions.h"
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/Support/VirtualFileSystem.h"
@@ -17,6 +18,8 @@
 namespace clang::include_cleaner {
 namespace {
 using testing::ElementsAre;
+using testing::IsEmpty;
+using testing::UnorderedElementsAre;
 
 // Matches an Include* on the specified line;
 MATCHER_P(line, N, "") { return arg->Line == (unsigned)N; }
@@ -43,5 +46,36 @@
   ElementsAre(line(4), line(5)));
 }
 
+TEST(RecordedIncludesTest, MatchVerbatim) {
+  auto FS = llvm::makeIntrusiveRefCnt();
+  FileManager FM(FileSystemOptions{});
+  Includes Inc;
+
+  // By default, a verbatim header only matches includes with the same spelling.
+  const FileEntry *Foo =
+  FM.getVirtualFile("repo/lib/include/rel/foo.h", /*Size=*/0, time_t{});
+  Inc.add(Include{"lib/include/rel/foo.h", Foo, SourceLocation(), 1});
+  Inc.add(Include{"rel/foo.h", Foo, SourceLocation(), 2});
+  EXPECT_THAT(Inc.match(Header("")), ElementsAre(line(2)));
+
+  // A verbatim header can match another spelling if the search path
+  // suggests it's equivalent.
+  const FileEntry *Bar =
+  FM.getVirtualFile("repo/lib/include/rel/bar.h", /*Size=*/0, time_t{});
+  Inc.addSearchDirectory("repo/");
+  Inc.addSearchDirectory("repo/lib/include");
+  Inc.add(Include{"lib/include/rel/bar.h", Bar, SourceLocation(), 3});
+  Inc.add(Include{"rel/bar.h", Bar, SourceLocation(), 4});
+  EXPECT_THAT(Inc.match(Header("")),
+  UnorderedElementsAre(line(3), line(4)));
+
+  // We don't apply this logic to system headers, though.
+  const FileEntry *Vector =
+  FM.getVirtualFile("repo/lib/include/vector", /*Size=*/0, time_t{});
+  Inc.add(Include{"lib/include/vector", Vector, SourceLocation(), 5});
+  EXPECT_THAT(Inc.match(Header(*tooling::stdlib::Header::named(""))),
+  IsEmpty());
+}
+
 } // namespace
 } // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/lib/Types.cpp
===
--- clang-tools-extra/include-cleaner/lib/Types.cpp
+++ clang-tools-extra/include-cleaner/lib/Types.cpp
@@ -10,8 +10,15 @@
 #include "TypesInternal.h"
 #include "clang/AST/Decl.h"
 #include "clang/Basic/FileEntry.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
+#include 
 
 namespace clang::include_cleaner {
 
@@ -94,16 +101,51 @@
   .str();
 }
 
+static llvm::SmallString<128> normalizePath(llvm::StringRef Path) {
+  namespace path = llvm::sys::path;
+
+  llvm::SmallString<128> P = Path;
+  path::remove_dots(P, /*remove_dot_dot=*/true);
+  path::native(P, path::Style::posix);
+  while (!P.empty() && path::is_separator(P.back()))
+P.pop_back();
+  return P;
+}
+
+void Includes::addSearchDirectory(llvm::StringRef Path) {
+  SearchPath.try_emplace(normalizePath(Path));
+}
+
 void Includes::add(const Include &I) {
+  namespace path = llvm::sys::path;
+
   unsigned Index = All.size();
   All.push_back(I);
   auto BySpellingIt = BySpelling.try_emplace(I.Spelled).first;
   All.back().Spelled = BySpellingIt->first(); // Now we own the backing string.
 
   BySpellingIt->second.push_back(Index);
-  if (I.Resolved)
-ByFile[I.Resolved].push_back(Index);
   ByLine[I.Line] = Index;
+  if (I.Resolved) {
+ByFile[I.Resolved].push_back(Index);
+
+// While verbatim headers ideally should match #include spelling exactly,
+// we want to be tolerant of different spellings of the same file.
+//
+// If the search path includes "/a/b" and "/a/b/c/d",
+// verbatim "e/f" should match (spelled=c/d/e/f, resolved=/a/b/c/d/e/f).
+// We assume entry's (normalized) name will match the search dirs.
+auto Path = normalizePath(I.Resolved->getName());
+for (llvm::StringRef Parent = path::parent_path(Path); !Parent.empty();
+ Parent = path::parent_path(Parent)

[clang] 3e3cdf9 - [LoongArch][NFC] Remove incorrect notes in clang tests

2023-07-20 Thread Weining Lu via cfe-commits

Author: Weining Lu
Date: 2023-07-20T20:26:12+08:00
New Revision: 3e3cdf9a480f0c54e94b011a05443c60a7b20375

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

LOG: [LoongArch][NFC] Remove incorrect notes in clang tests

The assertions in these two tests were not auto-generated by 
update_cc_test_checks.py. Remove them.

Added: 


Modified: 
clang/test/CodeGen/LoongArch/intrinsic-la32-error.c
clang/test/CodeGen/LoongArch/intrinsic-la64-error.c

Removed: 




diff  --git a/clang/test/CodeGen/LoongArch/intrinsic-la32-error.c 
b/clang/test/CodeGen/LoongArch/intrinsic-la32-error.c
index 2c3c249c54b137..0264c2948934e6 100644
--- a/clang/test/CodeGen/LoongArch/intrinsic-la32-error.c
+++ b/clang/test/CodeGen/LoongArch/intrinsic-la32-error.c
@@ -1,4 +1,3 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple loongarch32 -emit-llvm -S -verify %s -o /dev/null
 
 #include 

diff  --git a/clang/test/CodeGen/LoongArch/intrinsic-la64-error.c 
b/clang/test/CodeGen/LoongArch/intrinsic-la64-error.c
index 60dfece74be6ee..efb3b94175cfad 100644
--- a/clang/test/CodeGen/LoongArch/intrinsic-la64-error.c
+++ b/clang/test/CodeGen/LoongArch/intrinsic-la64-error.c
@@ -1,4 +1,3 @@
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
 // RUN: %clang_cc1 -triple loongarch64 -emit-llvm -S -verify %s -o /dev/null
 
 #include 



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


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-20 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 542446.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/attr-cpuspecific-cpus.c
  clang/test/CodeGen/attr-target-mv.c
  clang/test/CodeGen/target-builtin-noerror.c
  clang/test/Driver/x86-march.c
  clang/test/Misc/target-invalid-cpu-note.c
  clang/test/Preprocessor/predefined-arch-macros.c
  compiler-rt/lib/builtins/cpu_model.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/TargetParser/X86TargetParser.def
  llvm/include/llvm/TargetParser/X86TargetParser.h
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/Host.cpp
  llvm/lib/TargetParser/X86TargetParser.cpp
  llvm/test/CodeGen/X86/cpus-intel.ll

Index: llvm/test/CodeGen/X86/cpus-intel.ll
===
--- llvm/test/CodeGen/X86/cpus-intel.ll
+++ llvm/test/CodeGen/X86/cpus-intel.ll
@@ -30,6 +30,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=i686-unknown-unknown -mcpu=emeraldrapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=nocona 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
@@ -88,6 +89,7 @@
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=sierraforest 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=grandridge 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 ; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
+; RUN: llc < %s -o /dev/null -mtriple=x86_64-unknown-unknown -mcpu=graniterapids-d 2>&1 | FileCheck %s --check-prefix=CHECK-NO-ERROR --allow-empty
 
 define void @foo() {
   ret void
Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -210,8 +210,7 @@
 FeatureSERIALIZE | FeatureSHSTK | FeatureTSXLDTRK | FeatureUINTR |
 FeatureWAITPKG;
 constexpr FeatureBitset FeaturesGraniteRapids =
-FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI |
-FeatureAMX_COMPLEX;
+FeaturesSapphireRapids | FeatureAMX_FP16 | FeaturePREFETCHI;
 
 // Intel Atom processors.
 // Bonnell has feature parity with Core2 and adds MOVBE.
@@ -428,7 +427,10 @@
   // Grandridge microarchitecture based processors.
   { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesGrandridge, 'p', false },
   // Granite Rapids microarchitecture based processors.
-  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids, 'n', false },
+  { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, FeaturesGraniteRapids , 'n', false },
+  // Granite Rapids D microarchitecture based processors.
+  { {"graniterapids-d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', false },
+  { {"graniterapids_d"}, CK_GraniterapidsD, FEATURE_AVX512BF16, FeaturesGraniteRapids | FeatureAMX_COMPLEX, 'n', true },
   // Emerald Rapids microarchitecture based processors.
   { {"emeraldrapids"}, CK_Emeraldrapids, FEATURE_AVX512BF16, FeaturesSapphireRapids, 'n', false },
   // Knights Landing processor.
Index: llvm/lib/TargetParser/Host.cpp
===
--- llvm/lib/TargetParser/Host.cpp
+++ llvm/lib/TargetParser/Host.cpp
@@ -833,13 +833,19 @@
   break;
 
 // Graniterapids:
-case 0xae:
 case 0xad:
   CPU = "graniterapids";
   *Type = X86::INTEL_COREI7;
   *Subtype = X86::INTEL_COREI7_GRANITERAPIDS;
   break;
 
+// Granite Rapids D:
+case 0xae:
+  CPU = "graniterapids-d";
+  *Type = X86::INTEL_COREI7;
+  *Subtype = X86::INTEL_COREI7_GRANITERAPIDS_D;
+  break;
+
 // Icelake Xeon:
 case 0x6a:
 case 0x6c:
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -1079,11 +1079,16 @@
   // Graniterapids
   list GNRA

[PATCH] D153769: [clangd] Implement the 'Organize Imports' source action. Fix include-cleaner findings in batch.

2023-07-20 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

there are unittests for tweaks under 
`clang-tools-extra/clangd/unittests/tweaks/` can you create one for 
`OrganizeImports` there and test this in there?

i've got another concern around triggering of this interaction.
in theory code-action context has a `only` field, dictating which code actions 
should be surfaced, but when it's unset (as it's usually not set by clients and 
hard to understand semantics of code action kinds) clangd just provides all of 
the available code actions for a given selection.
since organize imports (and other source actions) are going to be available for 
all selections, it means we'll now have some code action response all the time 
and clients that don't know about semantics for "source" code action kind, will 
likely just show it in their UIs. so we need to be somewhat careful about 
triggering.

two alternatives that I can think of are:
1- show "source" kind code actions, only when they're explicitly requested.
2- make use of trigger kind and return these only when code actions are 
"explicitly" triggered.

1 has the downside of never showing up on editors that don't know about 
"source" code action kind, and also complicates behaviour on clangd side.
2 has the downside of being introduced very recently (trigger kind is made part 
of the spec at LSP 3.17), hence it'll likely be absent in old clients.

so my inclination is towards alternative 2), which at least limits the blast 
radius and gives clients a reasonably easy way to control the behavior. WDYT?




Comment at: clang-tools-extra/clangd/refactor/tweaks/OrganizeImports.cpp:24-25
+
+namespace clang {
+namespace clangd {
+namespace {

nit: `namespace clang::clangd {`



Comment at: clang-tools-extra/clangd/refactor/tweaks/OrganizeImports.cpp:45-49
+std::string OrganizeImports::title() const {
+  return "Remove unused and add missing includes";
+}
+
+bool OrganizeImports::prepare(const Selection &Inputs) { return true; }

nit: i'd inline these into the class definition as well



Comment at: clang-tools-extra/clangd/refactor/tweaks/OrganizeImports.cpp:51
+
+Expected
+OrganizeImports::apply(const Selection &Inputs) {

s/OrganizeImports::Effect/Tweak::Effect



Comment at: clang-tools-extra/clangd/refactor/tweaks/OrganizeImports.cpp:62
+  const auto &SM = Inputs.AST->getSourceManager();
+  std::set Spellings;
+  for (const auto &Missing : Findings.MissingIncludes)

prefer `llvm::StringSet<>`



Comment at: clang-tools-extra/clangd/refactor/tweaks/OrganizeImports.cpp:64-67
+for (const auto &P : Missing.Providers)
+  Spellings.insert(include_cleaner::spellHeader(
+  {P, Inputs.AST->getPreprocessor().getHeaderSearchInfo(),
+   SM.getFileEntryForID(SM.getMainFileID())}));

this will insert all providers for a symbol (e.g. if we have both `foo.h` and 
`bar.h`, we'll insert both).



Comment at: clang-tools-extra/clangd/refactor/tweaks/OrganizeImports.cpp:75
+  auto FileStyle =
+  format::getStyle(format::DefaultFormatStyle, Inputs.AST->tuPath(),
+   format::DefaultFallbackStyle, Inputs.Code, Inputs.FS);





Comment at: clang-tools-extra/clangd/refactor/tweaks/OrganizeImports.cpp:77
+   format::DefaultFallbackStyle, Inputs.Code, Inputs.FS);
+  if (!FileStyle)
+FileStyle = format::getLLVMStyle();

unfortunately we actually have to consume the error here, as `getStyle` returns 
an `Expected` and destroying an unchecked `Expected` is undefined behavior :/

something like `elog("Couldn't get style for {0}: {1}", MainFilePath, 
FileStyle.takeError());` should do the trick.



Comment at: clang-tools-extra/clangd/refactor/tweaks/OrganizeImports.cpp:79-83
+  if (auto Final = format::cleanupAroundReplacements(Inputs.Code, Replacements,
+ *FileStyle))
+return Effect::mainFileEdit(SM, *Final);
+  else
+return Final.takeError();

nit:


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153769

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


[PATCH] D142702: [Clang][AArch64][SME] Generate target features from +(no)sme.* options

2023-07-20 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added inline comments.



Comment at: clang/test/Driver/aarch64-implied-sme-features.c:49
+// RUN: %clang -target aarch64-linux-gnu -march=armv8-a+nosme+sme-i16i64 %s 
-### 2>&1 | FileCheck %s --check-prefix=SME-SUBFEATURE-CONFLICT-REV
+// SME-SUBFEATURE-CONFLICT-REV: "-target-feature" "-sme-f64f64" 
"-target-feature" "+sme-i16i64" "-target-feature" "+sme" "-target-feature" 
"+bf16"

Hi Bryan, this test fails in our downstream toolchain because it has additional 
features that show up in between these features. Breaking the line up as shown 
would fix this. Another option could be to add `{{.*}}` between the features. 
Doing likewise for other checks in this file would make them less brittle as 
well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142702

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


[PATCH] D155784: [X86] Update features for sierraforest, grandridge

2023-07-20 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: clang/test/Preprocessor/predefined-arch-macros.c:2496
 // CHECK_SRF_M32: #define __PTWRITE__ 1
+// CHECK_GRR_M32: #define __RAOINT__ 1
 // CHECK_SRF_M32: #define __RDPID__ 1

This is easy to be confused. How about add a not check? e.g.,

```
... -check-prefix=CHECK_SRF_GRR_M32,CHECK_SRF_M32
... -check-prefixes=CHECK_SRF_GRR_M32,CHECK_GRR_M32
...
// CHECK_SRF_GRR_M32: #define __PTWRITE__ 1
// CHECK_SRF_M32-NOT: __RAOINT__
// CHECK_GRR_M32: #define __RAOINT__ 1
```



Comment at: clang/test/Preprocessor/predefined-arch-macros.c:2568
 // CHECK_SRF_M64: #define __PTWRITE__ 1
+// CHECK_GRR_M64: #define __RAOINT__ 1
 // CHECK_SRF_M64: #define __RDPID__ 1

ditto.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155784

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


[PATCH] D155824: [LoongArch] Support -march=native and -mtune=

2023-07-20 Thread Lu Weining via Phabricator via cfe-commits
SixWeining created this revision.
SixWeining added reviewers: xen0n, xry111, hev, wangleiat.
Herald added a subscriber: hiraditya.
Herald added a project: All.
SixWeining requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, MaskRay.
Herald added projects: clang, LLVM.

As described in [1][2], `-mtune=` is used to select the type of target
microarchitecture, defaults to the value of `-march`. The set of
possible values should be a superset of `-march` values. Currently
possible values of `-march=` and `-mtune=` are `native`, `loongarch64`
and `la464`.

D136146  has supported 
`-march={loongarch64,la464}` and this patch adds
support for `-march=native` and `-mtune=`.

A new ProcessorModel called `loongarch64` is defined in LoongArch.td
to support `-mtune=loongarch64`.

`llvm::sys::getHostCPUName()` returns `generic` on unknown or future
LoongArch CPUs, e.g. the not yet added `la664`, leading to
`llvm::LoongArch::isValidArchName()` failing to parse the arch name.
In this case, use `loongarch64` as the default arch name for 64-bit
CPUs.

And these two preprocessor macros are defined:

- __loongarch_arch
- __loongarch_tune

[1]: 
https://github.com/loongson/LoongArch-Documentation/blob/2023.04.20/docs/LoongArch-toolchain-conventions-EN.adoc
[2]: 
https://github.com/loongson/la-softdev-convention/blob/v0.1/la-softdev-convention.adoc


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155824

Files:
  clang/lib/Basic/Targets/LoongArch.cpp
  clang/lib/Basic/Targets/LoongArch.h
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/loongarch-mtune-error.c
  clang/test/Driver/loongarch-mtune.c
  clang/test/Preprocessor/init-loongarch.c
  llvm/include/llvm/TargetParser/LoongArchTargetParser.h
  llvm/lib/Target/LoongArch/LoongArch.td
  llvm/lib/TargetParser/LoongArchTargetParser.cpp
  llvm/test/CodeGen/LoongArch/cpus-invalid.ll
  llvm/test/CodeGen/LoongArch/cpus.ll

Index: llvm/test/CodeGen/LoongArch/cpus.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/cpus.ll
@@ -0,0 +1,20 @@
+;; This tests that llc accepts all valid LoongArch CPUs.
+;; Note the 'generic' names have been tested in cpu-name-generic.ll.
+
+; RUN: llc < %s --mtriple=loongarch64 --mcpu=loongarch64 2>&1 | FileCheck %s
+; RUN: llc < %s --mtriple=loongarch64 --mcpu=la464 2>&1 | FileCheck %s
+; RUN: llc < %s --mtriple=loongarch64 2>&1 | FileCheck %s
+
+; CHECK-NOT: {{.*}} is not a recognized processor for this target
+
+define void @f() {
+  ret void
+}
+
+define void @tune_cpu_loongarch64() "tune-cpu"="loongarch64" {
+  ret void
+}
+
+define void @tune_cpu_la464() "tune-cpu"="la464" {
+  ret void
+}
Index: llvm/test/CodeGen/LoongArch/cpus-invalid.ll
===
--- /dev/null
+++ llvm/test/CodeGen/LoongArch/cpus-invalid.ll
@@ -0,0 +1,7 @@
+; RUN: llc < %s --mtriple=loongarch64 --mattr=+64bit --mcpu=invalidcpu 2>&1 | FileCheck %s
+
+; CHECK: {{.*}} is not a recognized processor for this target
+
+define void @f() {
+  ret void
+}
Index: llvm/lib/TargetParser/LoongArchTargetParser.cpp
===
--- llvm/lib/TargetParser/LoongArchTargetParser.cpp
+++ llvm/lib/TargetParser/LoongArchTargetParser.cpp
@@ -16,6 +16,9 @@
 using namespace llvm;
 using namespace llvm::LoongArch;
 
+StringRef Arch;
+StringRef TuneCPU;
+
 const FeatureInfo AllFeatures[] = {
 #define LOONGARCH_FEATURE(NAME, KIND) {NAME, KIND},
 #include "llvm/TargetParser/LoongArchTargetParser.def"
@@ -46,3 +49,25 @@
   }
   return false;
 }
+
+bool LoongArch::isValidTuneCPUName(StringRef TuneCPU) {
+  return isValidArchName(TuneCPU);
+}
+
+void LoongArch::fillValidTuneCPUList(SmallVectorImpl &Values) {
+  for (const auto A : AllArchs)
+Values.emplace_back(A.Name);
+}
+
+StringRef LoongArch::getDefaultArch(bool Is64Bit) {
+  // TODO: use a real 32-bit arch name.
+  return Is64Bit ? "loongarch64" : "";
+}
+
+void LoongArch::setArch(StringRef Name) { Arch = Name; }
+
+StringRef LoongArch::getArch() { return Arch; }
+
+void LoongArch::setTuneCPU(StringRef Name) { TuneCPU = Name; }
+
+StringRef LoongArch::getTuneCPU() { return TuneCPU; }
Index: llvm/lib/Target/LoongArch/LoongArch.td
===
--- llvm/lib/Target/LoongArch/LoongArch.td
+++ llvm/lib/Target/LoongArch/LoongArch.td
@@ -117,6 +117,11 @@
 def : ProcessorModel<"generic-la32", NoSchedModel, [Feature32Bit]>;
 def : ProcessorModel<"generic-la64", NoSchedModel, [Feature64Bit, FeatureUAL]>;
 
+// Generic 64-bit processor with double-precision floating-point support.
+def : ProcessorModel<"loongarch64", NoSchedModel, [Feature64Bit,
+   FeatureUAL,
+   FeatureBasicD]>;
+
 // Support gene

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-20 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

FYI, my current aim is to land that early in the Clang 18 cycle, that should 
give us time to find any remaining issue and maybe improve debugger support!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D155826: [Clang][Preprocessor][RFC] Add preprocessor support for C++ Parallel Algorithm Offload

2023-07-20 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx created this revision.
AlexVlx added reviewers: yaxunl, arsenm.
AlexVlx added a project: clang.
Herald added a project: All.
AlexVlx requested review of this revision.
Herald added subscribers: cfe-commits, wdng.

This patch adds the Driver changes needed by the standard algorithm offload 
feature being proposed here: 
https://discourse.llvm.org/t/rfc-adding-c-parallel-algorithm-offload-support-to-clang-llvm/72159/1.
 The verbose documentation is included in the head of the patch series. This 
change merely adds two macros to inform user space if we are compiling in 
`stdpar` mode and, respectively, if the optional allocation interposition mode 
has been requested, as well as associated minimal tests. The macros can be used 
by the runtime implementation of offload to drive conditional compilation, and 
are only defined if the HIP language has been enabled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155826

Files:
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Preprocessor/predefined-macros.c


Index: clang/test/Preprocessor/predefined-macros.c
===
--- clang/test/Preprocessor/predefined-macros.c
+++ clang/test/Preprocessor/predefined-macros.c
@@ -290,3 +290,19 @@
 // RUN:   -fcuda-is-device -fgpu-default-stream=per-thread \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-PTH
 // CHECK-PTH: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -triple 
x86_64-unknown-linux-gnu \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-STDPAR
+// CHECK-STDPAR: #define __STDPAR__ 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -stdpar-interpose-alloc \
+// RUN:  -triple x86_64-unknown-linux-gnu | FileCheck -match-full-lines %s \
+// RUN:  --check-prefix=CHECK-STDPAR-INTERPOSE
+// CHECK-STDPAR-INTERPOSE: #define __STDPAR_INTERPOSE_ALLOC__ 1
+// CHECK-STDPAR-INTERPOSE: #define __STDPAR__ 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -stdpar-interpose-alloc \
+// RUN:  -triple amdgcn-amd-amdhsa -fcuda-is-device | FileCheck 
-match-full-lines \
+// RUN:  %s --check-prefix=CHECK-STDPAR-INTERPOSE-DEV-NEG
+// CHECK-STDPAR-INTERPOSE-DEV-NEG: #define __STDPAR__ 1
+// CHECK-STDPAR-INTERPOSE-DEV-NEG-NOT: #define __STDPAR_INTERPOSE_ALLOC__ 1
\ No newline at end of file
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -586,6 +586,11 @@
 Builder.defineMacro("__HIP_MEMORY_SCOPE_WORKGROUP", "3");
 Builder.defineMacro("__HIP_MEMORY_SCOPE_AGENT", "4");
 Builder.defineMacro("__HIP_MEMORY_SCOPE_SYSTEM", "5");
+if (LangOpts.HIPStdPar) {
+  Builder.defineMacro("__STDPAR__");
+  if (!LangOpts.CUDAIsDevice)
+Builder.defineMacro("__STDPAR_INTERPOSE_ALLOC__");
+}
 if (LangOpts.CUDAIsDevice) {
   Builder.defineMacro("__HIP_DEVICE_COMPILE__");
   if (!TI.hasHIPImageSupport()) {


Index: clang/test/Preprocessor/predefined-macros.c
===
--- clang/test/Preprocessor/predefined-macros.c
+++ clang/test/Preprocessor/predefined-macros.c
@@ -290,3 +290,19 @@
 // RUN:   -fcuda-is-device -fgpu-default-stream=per-thread \
 // RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-PTH
 // CHECK-PTH: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -triple x86_64-unknown-linux-gnu \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-STDPAR
+// CHECK-STDPAR: #define __STDPAR__ 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -stdpar-interpose-alloc \
+// RUN:  -triple x86_64-unknown-linux-gnu | FileCheck -match-full-lines %s \
+// RUN:  --check-prefix=CHECK-STDPAR-INTERPOSE
+// CHECK-STDPAR-INTERPOSE: #define __STDPAR_INTERPOSE_ALLOC__ 1
+// CHECK-STDPAR-INTERPOSE: #define __STDPAR__ 1
+
+// RUN: %clang_cc1 %s -E -dM -o - -x hip -stdpar -stdpar-interpose-alloc \
+// RUN:  -triple amdgcn-amd-amdhsa -fcuda-is-device | FileCheck -match-full-lines \
+// RUN:  %s --check-prefix=CHECK-STDPAR-INTERPOSE-DEV-NEG
+// CHECK-STDPAR-INTERPOSE-DEV-NEG: #define __STDPAR__ 1
+// CHECK-STDPAR-INTERPOSE-DEV-NEG-NOT: #define __STDPAR_INTERPOSE_ALLOC__ 1
\ No newline at end of file
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -586,6 +586,11 @@
 Builder.defineMacro("__HIP_MEMORY_SCOPE_WORKGROUP", "3");
 Builder.defineMacro("__HIP_MEMORY_SCOPE_AGENT", "4");
 Builder.defineMacro("__HIP_MEMORY_SCOPE_SYSTEM", "5");
+if (LangOpts.HIPStdPar) {
+  Builder.defineMacro("__STDPAR__");
+  if (!LangOpts.CUDAIsDevice)
+Builder.defineMacro("__STDPAR_INTERPOSE_ALLOC__");
+}

[clang] 8b5d3ba - [clang][dataflow] Print the source line if we saw unexpected diagnostics in tests.

2023-07-20 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-20T12:40:22Z
New Revision: 8b5d3ba829c162fd4890fd65a4629ce0715825ee

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

LOG: [clang][dataflow] Print the source line if we saw unexpected diagnostics 
in tests.

This makes it easier to determine which line the unexpected happened on; 
previously, we would only get the line number.

Reviewed By: ymandel

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

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
index 4bac015c995f68..a181f284370886 100644
--- 
a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ 
b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
@@ -1334,7 +1335,17 @@ class UncheckedOptionalAccessTest
   auto &SrcMgr = AO.ASTCtx.getSourceManager();
   llvm::DenseSet DiagnosticLines;
   for (SourceLocation &Loc : Diagnostics) {
-DiagnosticLines.insert(SrcMgr.getPresumedLineNumber(Loc));
+unsigned Line = SrcMgr.getPresumedLineNumber(Loc);
+DiagnosticLines.insert(Line);
+if (!AnnotationLines.contains(Line)) {
+  IntrusiveRefCntPtr DiagOpts(
+  new DiagnosticOptions());
+  TextDiagnostic TD(llvm::errs(), AO.ASTCtx.getLangOpts(),
+DiagOpts.get());
+  TD.emitDiagnostic(
+  FullSourceLoc(Loc, SrcMgr), DiagnosticsEngine::Error,
+  "unexpected diagnostic", std::nullopt, std::nullopt);
+}
   }
 
   EXPECT_THAT(DiagnosticLines, ContainerEq(AnnotationLines));



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


[PATCH] D155802: [clang][dataflow] Print the source line if we saw unexpected diagnostics in tests.

2023-07-20 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8b5d3ba829c1: [clang][dataflow] Print the source line if we 
saw unexpected diagnostics in… (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155802

Files:
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
@@ -1334,7 +1335,17 @@
   auto &SrcMgr = AO.ASTCtx.getSourceManager();
   llvm::DenseSet DiagnosticLines;
   for (SourceLocation &Loc : Diagnostics) {
-DiagnosticLines.insert(SrcMgr.getPresumedLineNumber(Loc));
+unsigned Line = SrcMgr.getPresumedLineNumber(Loc);
+DiagnosticLines.insert(Line);
+if (!AnnotationLines.contains(Line)) {
+  IntrusiveRefCntPtr DiagOpts(
+  new DiagnosticOptions());
+  TextDiagnostic TD(llvm::errs(), AO.ASTCtx.getLangOpts(),
+DiagOpts.get());
+  TD.emitDiagnostic(
+  FullSourceLoc(Loc, SrcMgr), DiagnosticsEngine::Error,
+  "unexpected diagnostic", std::nullopt, std::nullopt);
+}
   }
 
   EXPECT_THAT(DiagnosticLines, ContainerEq(AnnotationLines));


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -12,6 +12,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/SourceLocation.h"
+#include "clang/Frontend/TextDiagnostic.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
@@ -1334,7 +1335,17 @@
   auto &SrcMgr = AO.ASTCtx.getSourceManager();
   llvm::DenseSet DiagnosticLines;
   for (SourceLocation &Loc : Diagnostics) {
-DiagnosticLines.insert(SrcMgr.getPresumedLineNumber(Loc));
+unsigned Line = SrcMgr.getPresumedLineNumber(Loc);
+DiagnosticLines.insert(Line);
+if (!AnnotationLines.contains(Line)) {
+  IntrusiveRefCntPtr DiagOpts(
+  new DiagnosticOptions());
+  TextDiagnostic TD(llvm::errs(), AO.ASTCtx.getLangOpts(),
+DiagOpts.get());
+  TD.emitDiagnostic(
+  FullSourceLoc(Loc, SrcMgr), DiagnosticsEngine::Error,
+  "unexpected diagnostic", std::nullopt, std::nullopt);
+}
   }
 
   EXPECT_THAT(DiagnosticLines, ContainerEq(AnnotationLines));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155788: [clang][dataflow] Add an `operator<<` for `OptionalTypeIdentifier`.

2023-07-20 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel accepted this revision.
ymandel added a comment.
This revision is now accepted and ready to land.

Thank you!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155788

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


[PATCH] D155824: [LoongArch] Support -march=native and -mtune=

2023-07-20 Thread Xi Ruoyao via Phabricator via cfe-commits
xry111 added a comment.

Do we need to convert Xuerui's label alignment change to use the -mtune 
framework?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155824

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


[PATCH] D155794: [OpenMP][OpenMPIRBuilder] Migrate setPropertyExecutionMode() from Clang to OpenMPIRBuilder.

2023-07-20 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr added a comment.

Not an expert here, only some minor comments.




Comment at: clang/lib/CodeGen/CodeGenModule.h:1008
 
+  std::vector *getLLVMCompilerUsed() {
+return &LLVMCompilerUsed;

Return a reference instead of pointer here?



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:1506
+  void
+  setPropertyExecutionMode(StringRef Name, bool Mode,
+   std::vector 
*LLVMCompilerUsed);

Rename to sth like `isSPMDMode` or so? To me `Mode` reads overly general.



Comment at: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h:1507
+  setPropertyExecutionMode(StringRef Name, bool Mode,
+   std::vector 
*LLVMCompilerUsed);
+

Should this preferably be a reference instead of pointer?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155794

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


[clang] 477ee05 - [clang][dataflow] Add an `operator<<` for `OptionalTypeIdentifier`.

2023-07-20 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-20T12:52:53Z
New Revision: 477ee05f83c6cc4f11b45e61e606934b99e72290

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

LOG: [clang][dataflow] Add an `operator<<` for `OptionalTypeIdentifier`.

When tests fail in UncheckedOptionalAccessModelTest.cpp, this prints the name 
of the optional type instead of a blob of hex.

Reviewed By: ymandel

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

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
index a181f284370886..719ec271e134c4 100644
--- 
a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ 
b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1267,6 +1267,12 @@ struct OptionalTypeIdentifier {
   std::string TypeName;
 };
 
+static raw_ostream &operator<<(raw_ostream &OS,
+   const OptionalTypeIdentifier &TypeId) {
+  OS << TypeId.NamespaceName << "::" << TypeId.TypeName;
+  return OS;
+}
+
 class UncheckedOptionalAccessTest
 : public ::testing::TestWithParam {
 protected:



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


[PATCH] D155788: [clang][dataflow] Add an `operator<<` for `OptionalTypeIdentifier`.

2023-07-20 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG477ee05f83c6: [clang][dataflow] Add an `operator<<` 
for `OptionalTypeIdentifier`. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155788

Files:
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp


Index: 
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1267,6 +1267,12 @@
   std::string TypeName;
 };
 
+static raw_ostream &operator<<(raw_ostream &OS,
+   const OptionalTypeIdentifier &TypeId) {
+  OS << TypeId.NamespaceName << "::" << TypeId.TypeName;
+  return OS;
+}
+
 class UncheckedOptionalAccessTest
 : public ::testing::TestWithParam {
 protected:


Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -1267,6 +1267,12 @@
   std::string TypeName;
 };
 
+static raw_ostream &operator<<(raw_ostream &OS,
+   const OptionalTypeIdentifier &TypeId) {
+  OS << TypeId.NamespaceName << "::" << TypeId.TypeName;
+  return OS;
+}
+
 class UncheckedOptionalAccessTest
 : public ::testing::TestWithParam {
 protected:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3203d3e - [clang][Interp][NFC] Add InterpStack::dump()

2023-07-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-20T14:56:44+02:00
New Revision: 3203d3eac4d14f44d6e660d8835c10a42a07fee2

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

LOG: [clang][Interp][NFC] Add InterpStack::dump()

Added: 


Modified: 
clang/lib/AST/Interp/InterpStack.cpp
clang/lib/AST/Interp/InterpStack.h

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpStack.cpp 
b/clang/lib/AST/Interp/InterpStack.cpp
index c5d9a459ce8248..5ca530409c8bf9 100644
--- a/clang/lib/AST/Interp/InterpStack.cpp
+++ b/clang/lib/AST/Interp/InterpStack.cpp
@@ -6,9 +6,12 @@
 //
 
//===--===//
 
+#include "InterpStack.h"
+#include "Boolean.h"
+#include "Floating.h"
+#include "Integral.h"
 #include 
 #include 
-#include "InterpStack.h"
 
 using namespace clang;
 using namespace clang::interp;
@@ -79,3 +82,21 @@ void InterpStack::shrink(size_t Size) {
   Chunk->End -= Size;
   StackSize -= Size;
 }
+
+void InterpStack::dump() const {
+#ifndef NDEBUG
+  llvm::errs() << "Items: " << ItemTypes.size() << ". Size: " << size() << 
"\n";
+  size_t Index = 0;
+  size_t Offset = align(primSize(ItemTypes[0]));
+  for (PrimType Ty : ItemTypes) {
+llvm::errs() << Index << "/" << Offset << ": ";
+TYPE_SWITCH(Ty, {
+  const T &V = peek(Offset);
+  llvm::errs() << V;
+});
+llvm::errs() << "\n";
+Offset += align(primSize(Ty));
+++Index;
+  }
+#endif
+}

diff  --git a/clang/lib/AST/Interp/InterpStack.h 
b/clang/lib/AST/Interp/InterpStack.h
index 14a9b69a557c15..ab4351a6dc679f 100644
--- a/clang/lib/AST/Interp/InterpStack.h
+++ b/clang/lib/AST/Interp/InterpStack.h
@@ -89,6 +89,9 @@ class InterpStack final {
   /// Returns whether the stack is empty.
   bool empty() const { return StackSize == 0; }
 
+  /// dump the stack contents to stderr.
+  void dump() const;
+
 private:
   /// All stack slots are aligned to the native pointer alignment for storage.
   /// The size of an object is rounded up to a pointer alignment multiple.



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


[PATCH] D155784: [X86] Update features for sierraforest, grandridge

2023-07-20 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe updated this revision to Diff 542476.
FreddyYe marked an inline comment as done.
FreddyYe added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155784

Files:
  clang/test/Preprocessor/predefined-arch-macros.c
  llvm/lib/Target/X86/X86.td
  llvm/lib/TargetParser/X86TargetParser.cpp

Index: llvm/lib/TargetParser/X86TargetParser.cpp
===
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -234,8 +234,8 @@
 FeatureCLDEMOTE | FeatureMOVDIR64B | FeatureMOVDIRI | FeatureWAITPKG |
 FeatureAVXVNNI | FeatureHRESET | FeatureWIDEKL;
 constexpr FeatureBitset FeaturesSierraforest =
-FeaturesAlderlake | FeatureCMPCCXADD | FeatureAVXIFMA |
-FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
+FeaturesAlderlake | FeatureCMPCCXADD | FeatureAVXIFMA | FeatureUINTR |
+FeatureENQCMD | FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
 constexpr FeatureBitset FeaturesGrandridge =
 FeaturesSierraforest | FeatureRAOINT;
 
Index: llvm/lib/Target/X86/X86.td
===
--- llvm/lib/Target/X86/X86.td
+++ llvm/lib/Target/X86/X86.td
@@ -1201,6 +1201,8 @@
   list SRFAdditionalFeatures = [FeatureCMPCCXADD,
   FeatureAVXIFMA,
   FeatureAVXNECONVERT,
+  FeatureENQCMD,
+  FeatureUINTR,
   FeatureAVXVNNIINT8];
   list SRFFeatures =
 !listconcat(ADLFeatures, SRFAdditionalFeatures);
Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -2455,6 +2455,9 @@
 // RUN: %clang -march=sierraforest -m32 -E -dM %s -o - 2>&1 \
 // RUN: --target=i386 \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M32
+// RUN: %clang -march=grandridge -m32 -E -dM %s -o - 2>&1 \
+// RUN: --target=i386 \
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_SRF_M32,CHECK_GRR_M32
 // CHECK_SRF_M32: #define __ADX__ 1
 // CHECK_SRF_M32: #define __AES__ 1
 // CHECK_SRF_M32: #define __AVX2__ 1
@@ -2470,6 +2473,7 @@
 // CHECK_SRF_M32: #define __CLFLUSHOPT__ 1
 // CHECK_SRF_M32: #define __CLWB__ 1
 // CHECK_SRF_M32: #define __CMPCCXADD__ 1
+// CHECK_SRF_M32: #define __ENQCMD__ 1
 // CHECK_SRF_M32: #define __F16C__ 1
 // CHECK_SRF_M32: #define __FMA__ 1
 // CHECK_SRF_M32: #define __FSGSBASE__ 1
@@ -2489,6 +2493,8 @@
 // CHECK_SRF_M32: #define __POPCNT__ 1
 // CHECK_SRF_M32: #define __PRFCHW__ 1
 // CHECK_SRF_M32: #define __PTWRITE__ 1
+// CHECK_SRF_M32-NOT: #define __RAOINT__ 1
+// CHECK_GRR_M32: #define __RAOINT__ 1
 // CHECK_SRF_M32: #define __RDPID__ 1
 // CHECK_SRF_M32: #define __RDRND__ 1
 // CHECK_SRF_M32: #define __RDSEED__ 1
@@ -2503,6 +2509,7 @@
 // CHECK_SRF_M32: #define __SSE_MATH__ 1
 // CHECK_SRF_M32: #define __SSE__ 1
 // CHECK_SRF_M32: #define __SSSE3__ 1
+// CHECK_SRF_M32: #define __UINTR__ 1
 // CHECK_SRF_M32: #define __VAES__ 1
 // CHECK_SRF_M32: #define __VPCLMULQDQ__ 1
 // CHECK_SRF_M32: #define __WAITPKG__ 1
@@ -2521,6 +2528,9 @@
 // RUN: %clang -march=sierraforest -m64 -E -dM %s -o - 2>&1 \
 // RUN: --target=i386 \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M64
+// RUN: %clang -march=grandridge -m64 -E -dM %s -o - 2>&1 \
+// RUN: --target=i386 \
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_SRF_M64,CHECK_GRR_M64
 // CHECK_SRF_M64: #define __ADX__ 1
 // CHECK_SRF_M64: #define __AES__ 1
 // CHECK_SRF_M64: #define __AVX2__ 1
@@ -2536,6 +2546,7 @@
 // CHECK_SRF_M64: #define __CLFLUSHOPT__ 1
 // CHECK_SRF_M64: #define __CLWB__ 1
 // CHECK_SRF_M64: #define __CMPCCXADD__ 1
+// CHECK_SRF_M64: #define __ENQCMD__ 1
 // CHECK_SRF_M64: #define __F16C__ 1
 // CHECK_SRF_M64: #define __FMA__ 1
 // CHECK_SRF_M64: #define __FSGSBASE__ 1
@@ -2555,6 +2566,8 @@
 // CHECK_SRF_M64: #define __POPCNT__ 1
 // CHECK_SRF_M64: #define __PRFCHW__ 1
 // CHECK_SRF_M64: #define __PTWRITE__ 1
+// CHECK_SRF_M64-NOT: #define __RAOINT__ 1
+// CHECK_GRR_M64: #define __RAOINT__ 1
 // CHECK_SRF_M64: #define __RDPID__ 1
 // CHECK_SRF_M64: #define __RDRND__ 1
 // CHECK_SRF_M64: #define __RDSEED__ 1
@@ -2570,6 +2583,7 @@
 // CHECK_SRF_M64: #define __SSE_MATH__ 1
 // CHECK_SRF_M64: #define __SSE__ 1
 // CHECK_SRF_M64: #define __SSSE3__ 1
+// CHECK_SRF_M64: #define __UINTR__ 1
 // CHECK_SRF_M64: #define __VAES__ 1
 // CHECK_SRF_M64: #define __VPCLMULQDQ__ 1
 // CHECK_SRF_M64: #define __WAITPKG__ 1
@@ -2586,142 +2600,6 @@
 // CHECK_SRF_M64: #define __x86_64 1
 // CHECK_SRF_M64: #define __x86_64__ 1
 
-// 

[PATCH] D155833: [Clang][Sema][RFC] Add Sema support for C++ Parallel Algorithm Offload

2023-07-20 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx created this revision.
AlexVlx added reviewers: yaxunl, jlebar, tra.
AlexVlx added a project: clang.
Herald added subscribers: ChuanqiXu, s.egerton, simoncook, asb, dschuff.
Herald added a project: All.
AlexVlx requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, jplehr, sstefan1, aheejin.
Herald added a reviewer: jdoerfert.

This patch adds the Sema changes needed by the standard algorithm offload 
feature being proposed here: 
https://discourse.llvm.org/t/rfc-adding-c-parallel-algorithm-offload-support-to-clang-llvm/72159/1.
 The verbose documentation is included in the head of the patch series. This 
change impacts the CUDA / HIP language specific checks, and only manifests if 
compiling in `stdpar` mode. In this case, we essentially do two things:

1. Allow device side callers to call host side callees - since the user visible 
HLL would be standard C++, with no annotations / restriction mechanisms, we 
cannot unambiguously establish that such a call is an error, so we 
conservatively allow all such calls, deferring actual cleanup to a subsequent 
pass over IR;
2. Allow host formed lambdas to capture by reference;
3. Allow device functions to use host global variables.

Please note that host and device here are used to match existing nomenclature, 
they would not be present in user code.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155833

Files:
  clang/lib/Sema/SemaCUDA.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaStdPar/Inputs/stdpar_lib.hpp
  clang/test/SemaStdPar/device-can-call-host.cpp
  stdpar_sema.patch

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


[PATCH] D151298: [clang][LoongArch] Fix the calling convention for empty struct in C++ mode

2023-07-20 Thread wanglei via Phabricator via cfe-commits
wangleiat abandoned this revision.
wangleiat added a comment.

We have decided to keep it unchanged. Thank you, everyone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151298

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


[PATCH] D155784: [X86] Update features for sierraforest, grandridge

2023-07-20 Thread Kan Shengchen via Phabricator via cfe-commits
skan added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155784

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


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-20 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: clang/test/Preprocessor/predefined-arch-macros.c:1925
 // CHECK_GNR_M64: #define __AMX_BF16__ 1
-// CHECK_GNR_M64: #define __AMX_COMPLEX__ 1
+// CHECK_GNR_M64-NOT: #define __AMX_COMPLEX__ 1
+// CHECK_GNRD_M64: #define __AMX_COMPLEX__ 1

Won't this fail on the graniterapids-d run?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

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


[PATCH] D155716: [clang][CodeGen] Introduce `-frecord-command-line` for MachO

2023-07-20 Thread Antonio Frighetto via Phabricator via cfe-commits
antoniofrighetto updated this revision to Diff 542483.

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

https://reviews.llvm.org/D155716

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/clang_f_opts.c
  llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/test/CodeGen/AArch64/commandline-metadata.ll


Index: llvm/test/CodeGen/AArch64/commandline-metadata.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/commandline-metadata.ll
@@ -0,0 +1,24 @@
+; RUN: llc -mtriple=arm64-linux-gnu < %s | FileCheck %s
+; RUN: llc -mtriple=arm64-apple-darwin < %s | FileCheck %s 
--check-prefix=CHECK-MACHO
+
+; Verify that llvm.commandline metadata is emitted to the corresponding 
command line section.
+
+; CHECK:  .text
+; CHECK:  .section .GCC.command.line,"MS",@progbits,1
+; CHECK-NEXT: .zero 1
+; CHECK-NEXT: .ascii "clang -command1"
+; CHECK-NEXT: .zero 1
+; CHECK-NEXT: .ascii "clang -command2"
+; CHECK-NEXT: .zero 1
+
+; CHECK-MACHO:.section __TEXT,__text,regular,pure_instructions
+; CHECK-MACHO-NEXT:   .section __TEXT,__command_line
+; CHECK-MACHO-NEXT:   .space   1
+; CHECK-MACHO-NEXT:   .ascii   "clang -command1"
+; CHECK-MACHO-NEXT:   .space   1
+; CHECK-MACHO-NEXT:   .ascii   "clang -command2"
+; CHECK-MACHO-NEXT:   .space   1
+
+!llvm.commandline = !{!0, !1}
+!0 = !{!"clang -command1"}
+!1 = !{!"clang -command2"}
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1420,6 +1420,11 @@
   return ReadOnlySection;  // .const
 }
 
+MCSection *TargetLoweringObjectFileMachO::getSectionForCommandLines() const {
+  return getContext().getMachOSection("__TEXT", "__command_line", 0,
+  SectionKind::getReadOnly());
+}
+
 const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Index: llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
===
--- llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -156,6 +156,8 @@
 
   void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV,
  const TargetMachine &TM) const override;
+
+  MCSection *getSectionForCommandLines() const override;
 };
 
 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -541,7 +541,7 @@
 // RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line 
-frecord-command-line %s 2>&1 | FileCheck 
-check-prefix=CHECK-RECORD-GCC-SWITCHES %s
 // RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line 
-fno-record-command-line %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
 // Test with a couple examples of non-ELF object file formats
-// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 
2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 
2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
 // RUN: %clang -### -S -target x86_64-unknown-windows -frecord-command-line %s 
2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
 // CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
 // CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7179,7 +7179,7 @@
   Args.hasFlag(options::OPT_frecord_command_line,
options::OPT_fno_record_command_line, false);
   if (FRecordSwitches && !Triple.isOSBinFormatELF() &&
-  !Triple.isOSBinFormatXCOFF())
+  !Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
 D.Diag(diag::err_drv_unsupported_opt_for_target)
 << 
Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
 << TripleStr;


Index: llvm/test/CodeGen/AArch64/commandline-metadata.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/commandline-metadata.ll
@@ -0,0 +1,24 @@
+; RUN: llc -mtriple=arm64-linux-gnu < %s | FileCheck %s
+; RUN: llc -mtriple=arm64-apple-darwin < %s | FileCheck %s --check-prefix=CHECK

[PATCH] D155716: [clang][CodeGen] Introduce `-frecord-command-line` for MachO

2023-07-20 Thread Antonio Frighetto via Phabricator via cfe-commits
antoniofrighetto added a comment.

Thanks a lot for the reviews and for pointing out clang tests as well, there 
was a minor update to do there too!




Comment at: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp:1424
+MCSection *TargetLoweringObjectFileMachO::getSectionForCommandLines() const {
+  return getContext().getMachOSection("__TEXT", "__command_line", 0,
+  SectionKind::getReadOnly());

sgraenitz wrote:
> Can we put it in `__DATA`?
> 
> Also the [[ 
> https://github.com/llvm/llvm-project/blob/release/16.x/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp#L1160
>  | ELF implementation notes ]] that it "attempts to mimic GCC's switch of the 
> same name" and thus calls the section `.GCC.command.line`. I guess we cannot 
> use the dots in MachO, but should we add a `gcc` prefix?
Whilst I agree it should be better to distinguish this from executable data, I 
think this should live as read-only data, which `__TEXT` is traditionally for.

Following MachO conventions, I first tried `__gcc_command_line`, but the [[ 
https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/BinaryFormat/MachO.h#L587
 | section name ]] is restricted to 16 chars, and I'm not sure adding more 
bytes for the name is worth the change (thus I thought we'd prefer 
`__command_line` over `__gcc_cmd_line`).


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

https://reviews.llvm.org/D155716

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


[PATCH] D155539: [CUDA][HIP] Use the same default language std as C++

2023-07-20 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D155539#4517882 , @sylvestre.ledru 
wrote:

> I reverted the patch for causing 
> https://github.com/llvm/llvm-project/issues/63974
> https://github.com/llvm/llvm-project/commit/443f490b6aac4af28500f4b09b68a13260f4fba9

Thanks. I will fix it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155539

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


[clang] 5522e31 - [clang][NFC] Simplify SourceLocExpr::EvaluateInContext

2023-07-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-20T15:15:57+02:00
New Revision: 5522e316f91ef490b34ffdf2c21fc8fed8affe5f

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

LOG: [clang][NFC] Simplify SourceLocExpr::EvaluateInContext

Use ASTContext::MakeIntValue and remove the std::tie+lambda weirdness.

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

Added: 


Modified: 
clang/lib/AST/Expr.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 25d3535e5dac43..23aa14784cdaab 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2288,14 +2288,17 @@ APValue SourceLocExpr::EvaluateInContext(const 
ASTContext &Ctx,
   SourceLocation Loc;
   const DeclContext *Context;
 
-  std::tie(Loc,
-   Context) = [&]() -> std::pair {
-if (auto *DIE = dyn_cast_or_null(DefaultExpr))
-  return {DIE->getUsedLocation(), DIE->getUsedContext()};
-if (auto *DAE = dyn_cast_or_null(DefaultExpr))
-  return {DAE->getUsedLocation(), DAE->getUsedContext()};
-return {this->getLocation(), this->getParentContext()};
-  }();
+  if (const auto *DIE = dyn_cast_if_present(DefaultExpr)) {
+Loc = DIE->getUsedLocation();
+Context = DIE->getUsedContext();
+  } else if (const auto *DAE =
+ dyn_cast_if_present(DefaultExpr)) {
+Loc = DAE->getUsedLocation();
+Context = DAE->getUsedContext();
+  } else {
+Loc = getLocation();
+Context = getParentContext();
+  }
 
   PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc(
   Ctx.getSourceManager().getExpansionRange(Loc).getEnd());
@@ -2333,13 +2336,9 @@ APValue SourceLocExpr::EvaluateInContext(const 
ASTContext &Ctx,
 CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : 
std::string(""));
   }
   case SourceLocExpr::Line:
-  case SourceLocExpr::Column: {
-llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy),
-/*isUnsigned=*/true);
-IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine()
-   : PLoc.getColumn();
-return APValue(IntVal);
-  }
+return APValue(Ctx.MakeIntValue(PLoc.getLine(), Ctx.UnsignedIntTy));
+  case SourceLocExpr::Column:
+return APValue(Ctx.MakeIntValue(PLoc.getColumn(), Ctx.UnsignedIntTy));
   case SourceLocExpr::SourceLocStruct: {
 // Fill in a std::source_location::__impl structure, by creating an
 // artificial file-scoped CompoundLiteralExpr, and returning a pointer to
@@ -2352,7 +2351,7 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext 
&Ctx,
 // the ImplDecl type is as expected.
 
 APValue Value(APValue::UninitStruct(), 0, 4);
-for (FieldDecl *F : ImplDecl->fields()) {
+for (const FieldDecl *F : ImplDecl->fields()) {
   StringRef Name = F->getName();
   if (Name == "_M_file_name") {
 SmallString<256> Path(PLoc.getFilename());
@@ -2369,16 +2368,10 @@ APValue SourceLocExpr::EvaluateInContext(const 
ASTContext &Ctx,
   PredefinedExpr::PrettyFunction, CurDecl))
 : "");
   } else if (Name == "_M_line") {
-QualType Ty = F->getType();
-llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
-Ty->hasUnsignedIntegerRepresentation());
-IntVal = PLoc.getLine();
+llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getLine(), F->getType());
 Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
   } else if (Name == "_M_column") {
-QualType Ty = F->getType();
-llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
-Ty->hasUnsignedIntegerRepresentation());
-IntVal = PLoc.getColumn();
+llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getColumn(), F->getType());
 Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
   }
 }



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


[PATCH] D155584: [clang][NFC] Simplify SourceLocExpr::EvaluateInContext

2023-07-20 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5522e316f91e: [clang][NFC] Simplify 
SourceLocExpr::EvaluateInContext (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155584

Files:
  clang/lib/AST/Expr.cpp


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2288,14 +2288,17 @@
   SourceLocation Loc;
   const DeclContext *Context;
 
-  std::tie(Loc,
-   Context) = [&]() -> std::pair {
-if (auto *DIE = dyn_cast_or_null(DefaultExpr))
-  return {DIE->getUsedLocation(), DIE->getUsedContext()};
-if (auto *DAE = dyn_cast_or_null(DefaultExpr))
-  return {DAE->getUsedLocation(), DAE->getUsedContext()};
-return {this->getLocation(), this->getParentContext()};
-  }();
+  if (const auto *DIE = dyn_cast_if_present(DefaultExpr)) {
+Loc = DIE->getUsedLocation();
+Context = DIE->getUsedContext();
+  } else if (const auto *DAE =
+ dyn_cast_if_present(DefaultExpr)) {
+Loc = DAE->getUsedLocation();
+Context = DAE->getUsedContext();
+  } else {
+Loc = getLocation();
+Context = getParentContext();
+  }
 
   PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc(
   Ctx.getSourceManager().getExpansionRange(Loc).getEnd());
@@ -2333,13 +2336,9 @@
 CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : 
std::string(""));
   }
   case SourceLocExpr::Line:
-  case SourceLocExpr::Column: {
-llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy),
-/*isUnsigned=*/true);
-IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine()
-   : PLoc.getColumn();
-return APValue(IntVal);
-  }
+return APValue(Ctx.MakeIntValue(PLoc.getLine(), Ctx.UnsignedIntTy));
+  case SourceLocExpr::Column:
+return APValue(Ctx.MakeIntValue(PLoc.getColumn(), Ctx.UnsignedIntTy));
   case SourceLocExpr::SourceLocStruct: {
 // Fill in a std::source_location::__impl structure, by creating an
 // artificial file-scoped CompoundLiteralExpr, and returning a pointer to
@@ -2352,7 +2351,7 @@
 // the ImplDecl type is as expected.
 
 APValue Value(APValue::UninitStruct(), 0, 4);
-for (FieldDecl *F : ImplDecl->fields()) {
+for (const FieldDecl *F : ImplDecl->fields()) {
   StringRef Name = F->getName();
   if (Name == "_M_file_name") {
 SmallString<256> Path(PLoc.getFilename());
@@ -2369,16 +2368,10 @@
   PredefinedExpr::PrettyFunction, CurDecl))
 : "");
   } else if (Name == "_M_line") {
-QualType Ty = F->getType();
-llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
-Ty->hasUnsignedIntegerRepresentation());
-IntVal = PLoc.getLine();
+llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getLine(), F->getType());
 Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
   } else if (Name == "_M_column") {
-QualType Ty = F->getType();
-llvm::APSInt IntVal(Ctx.getIntWidth(Ty),
-Ty->hasUnsignedIntegerRepresentation());
-IntVal = PLoc.getColumn();
+llvm::APSInt IntVal = Ctx.MakeIntValue(PLoc.getColumn(), F->getType());
 Value.getStructField(F->getFieldIndex()) = APValue(IntVal);
   }
 }


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -2288,14 +2288,17 @@
   SourceLocation Loc;
   const DeclContext *Context;
 
-  std::tie(Loc,
-   Context) = [&]() -> std::pair {
-if (auto *DIE = dyn_cast_or_null(DefaultExpr))
-  return {DIE->getUsedLocation(), DIE->getUsedContext()};
-if (auto *DAE = dyn_cast_or_null(DefaultExpr))
-  return {DAE->getUsedLocation(), DAE->getUsedContext()};
-return {this->getLocation(), this->getParentContext()};
-  }();
+  if (const auto *DIE = dyn_cast_if_present(DefaultExpr)) {
+Loc = DIE->getUsedLocation();
+Context = DIE->getUsedContext();
+  } else if (const auto *DAE =
+ dyn_cast_if_present(DefaultExpr)) {
+Loc = DAE->getUsedLocation();
+Context = DAE->getUsedContext();
+  } else {
+Loc = getLocation();
+Context = getParentContext();
+  }
 
   PresumedLoc PLoc = Ctx.getSourceManager().getPresumedLoc(
   Ctx.getSourceManager().getExpansionRange(Loc).getEnd());
@@ -2333,13 +2336,9 @@
 CurDecl ? PredefinedExpr::ComputeName(Kind, CurDecl) : std::string(""));
   }
   case SourceLocExpr::Line:
-  case SourceLocExpr::Column: {
-llvm::APSInt IntVal(Ctx.getIntWidth(Ctx.UnsignedIntTy),
-/*isUnsigned=*/true);
-IntVal = getIdentKind() == SourceLocExpr::Line ? PLoc.getLine()
-

[clang] f8a36d8 - [IR] Mark add constant expressions as undesirable

2023-07-20 Thread Nikita Popov via cfe-commits

Author: Nikita Popov
Date: 2023-07-20T15:24:19+02:00
New Revision: f8a36d8c3e264c4fccf8058e699201a452ea7bb7

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

LOG: [IR] Mark add constant expressions as undesirable

In preparation for removing support for add expressions, mark them
as undesirable. As such, we will no longer implicitly create such
expressions, but they still exist.

Added: 


Modified: 
clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
llvm/lib/IR/ConstantFold.cpp
llvm/lib/IR/Constants.cpp
llvm/test/CodeGen/Hexagon/atomic-opaque-basic.ll
llvm/test/Transforms/InstCombine/bswap-fold.ll
llvm/test/Transforms/InstSimplify/ConstProp/constant-expr.ll
llvm/test/Transforms/InstSimplify/compare.ll

Removed: 




diff  --git a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c 
b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
index 551ccc4810bcd3..0e0a9b157464a6 100644
--- a/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
+++ b/clang/test/CodeGen/catch-nullptr-and-nonzero-offset.c
@@ -303,7 +303,8 @@ char *one_zero(void) {
 char *one_one_OK(void) {
   // CHECK:   define{{.*}} ptr @one_one_OK()
   // CHECK-NEXT:  [[ENTRY:.*]]:
-  // CHECK-SANITIZE-C-NEXT: br i1 and (i1 icmp ne (ptr inttoptr 
(i64 1 to ptr), ptr null), i1 icmp ne (i64 add (i64 sub (i64 ptrtoint (ptr 
getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 1) to i64), i64 
1), i64 1), i64 0)), label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE-C-NEXT: %[[AND:.*]] = and i1 icmp ne (ptr 
inttoptr (i64 1 to ptr), ptr null), icmp ne (i64 add (i64 sub (i64 ptrtoint 
(ptr getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 1) to i64), 
i64 1), i64 1), i64 0), !nosanitize
+  // CHECK-SANITIZE-C-NEXT: br i1 %[[AND]], label %[[CONT:.*]], 
label %[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE-CPP-NEXT:   br i1 xor (i1 icmp eq (ptr inttoptr 
(i64 1 to ptr), ptr null), i1 icmp ne (i64 add (i64 sub (i64 ptrtoint (ptr 
getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 1) to i64), i64 
1), i64 1), i64 0)), label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE:  [[HANDLER_POINTER_OVERFLOW]]:
   // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_pointer_overflow_abort(ptr @[[LINE_1100]], i64 1, i64 add (i64 
sub (i64 ptrtoint (ptr getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), 
i64 1) to i64), i64 1), i64 1))
@@ -321,7 +322,8 @@ char *one_one_OK(void) {
 char *one_allones_BAD(void) {
   // CHECK:   define{{.*}} ptr @one_allones_BAD()
   // CHECK-NEXT:  [[ENTRY:.*]]:
-  // CHECK-SANITIZE-C-NEXT: br i1 and (i1 icmp ne (ptr inttoptr 
(i64 1 to ptr), ptr null), i1 icmp ne (i64 add (i64 sub (i64 ptrtoint (ptr 
getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 -1) to i64), i64 
1), i64 1), i64 0)), label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE-C-NEXT: %[[AND:.*]] = and i1 icmp ne (ptr 
inttoptr (i64 1 to ptr), ptr null), icmp ne (i64 add (i64 sub (i64 ptrtoint 
(ptr getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 -1) to i64), 
i64 1), i64 1), i64 0), !nosanitize
+  // CHECK-SANITIZE-C-NEXT: br i1 %[[AND]], label %[[CONT:.*]], 
label %[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE-CPP-NEXT:   br i1 xor (i1 icmp eq (ptr inttoptr 
(i64 1 to ptr), ptr null), i1 icmp ne (i64 add (i64 sub (i64 ptrtoint (ptr 
getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), i64 -1) to i64), i64 
1), i64 1), i64 0)), label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
   // CHECK-SANITIZE:  [[HANDLER_POINTER_OVERFLOW]]:
   // CHECK-SANITIZE-NORECOVER-NEXT: call void 
@__ubsan_handle_pointer_overflow_abort(ptr @[[LINE_1200]], i64 1, i64 add (i64 
sub (i64 ptrtoint (ptr getelementptr inbounds (i8, ptr inttoptr (i64 1 to ptr), 
i64 -1) to i64), i64 1), i64 1))
@@ -390,7 +392,8 @@ char *allones_zero_OK(void) {
 char *allones_one_BAD(void) {
   // CHECK: define{{.*}} ptr @allones_one_BAD()
   // CHECK-NEXT: [[ENTRY:.*]]:
-  // CHECK-SANITIZE-C-NEXT: br i1 and (i1 icmp ne (ptr inttoptr 
(i64 -1 to ptr), ptr null), i1 icmp ne (i64 add (i64 sub (i64 ptrtoint (ptr 
getelementptr inbounds (i8, ptr inttoptr (i64 -1 to ptr), i64 1) to i64), i64 
-1), i64 -1), i64 0)), label %[[CONT:.*]], label 
%[[HANDLER_POINTER_OVERFLOW:[^,]+]],{{.*}} !nosanitize
+  // CHECK-SANITIZE-C-NEXT:

[clang] af67614 - [clang][Interp] Call dtor of Floating values

2023-07-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-20T15:27:16+02:00
New Revision: af67614f79059686399e2808c80658af783f48d3

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

LOG: [clang][Interp] Call dtor of Floating values

The APFloat might heap-allocate some memory, so we need to call its
destructor.

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

Added: 


Modified: 
clang/lib/AST/Interp/Descriptor.cpp
clang/test/AST/Interp/floats.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 565c4b20038472..ccd2a993e9f7d3 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -186,6 +186,11 @@ static BlockCtorFn getCtorPrim(PrimType Type) {
 }
 
 static BlockDtorFn getDtorPrim(PrimType Type) {
+  // Floating types are special. They are primitives, but need their
+  // destructor called, since they might allocate memory.
+  if (Type == PT_Float)
+return dtorTy::T>;
+
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }
 

diff  --git a/clang/test/AST/Interp/floats.cpp 
b/clang/test/AST/Interp/floats.cpp
index ab75a537d0ce33..fa1f52317988db 100644
--- a/clang/test/AST/Interp/floats.cpp
+++ b/clang/test/AST/Interp/floats.cpp
@@ -125,3 +125,7 @@ namespace ZeroInit {
   constexpr A b{12};
   static_assert(a.f == 0.0, "");
 };
+
+namespace LongDouble {
+  constexpr long double ld = 3.1425926539;
+}



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


[PATCH] D154928: [clang][Interp] Call dtor of Floating values

2023-07-20 Thread Timm Bäder 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 rGaf67614f7905: [clang][Interp] Call dtor of Floating values 
(authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154928

Files:
  clang/lib/AST/Interp/Descriptor.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
@@ -125,3 +125,7 @@
   constexpr A b{12};
   static_assert(a.f == 0.0, "");
 };
+
+namespace LongDouble {
+  constexpr long double ld = 3.1425926539;
+}
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -186,6 +186,11 @@
 }
 
 static BlockDtorFn getDtorPrim(PrimType Type) {
+  // Floating types are special. They are primitives, but need their
+  // destructor called, since they might allocate memory.
+  if (Type == PT_Float)
+return dtorTy::T>;
+
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }
 


Index: clang/test/AST/Interp/floats.cpp
===
--- clang/test/AST/Interp/floats.cpp
+++ clang/test/AST/Interp/floats.cpp
@@ -125,3 +125,7 @@
   constexpr A b{12};
   static_assert(a.f == 0.0, "");
 };
+
+namespace LongDouble {
+  constexpr long double ld = 3.1425926539;
+}
Index: clang/lib/AST/Interp/Descriptor.cpp
===
--- clang/lib/AST/Interp/Descriptor.cpp
+++ clang/lib/AST/Interp/Descriptor.cpp
@@ -186,6 +186,11 @@
 }
 
 static BlockDtorFn getDtorPrim(PrimType Type) {
+  // Floating types are special. They are primitives, but need their
+  // destructor called, since they might allocate memory.
+  if (Type == PT_Float)
+return dtorTy::T>;
+
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d6b0af0 - [clang][Interp] Add more shift error checking

2023-07-20 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-07-20T15:35:47+02:00
New Revision: d6b0af0574ca21ae7b0fa6aa364345159f451da1

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

LOG: [clang][Interp] Add more shift error checking

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

Added: 


Modified: 
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/shifts.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index cc7c7a9d2430ee..de588ab8c9f191 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -127,7 +127,11 @@ template  class Integral final 
{
 return Compare(V, RHS.V);
   }
 
-  unsigned countLeadingZeros() const { return llvm::countl_zero(V); }
+  unsigned countLeadingZeros() const {
+if constexpr (!Signed)
+  return llvm::countl_zero(V);
+llvm_unreachable("Don't call countLeadingZeros() on signed types.");
+  }
 
   Integral truncate(unsigned TruncBits) const {
 if (TruncBits >= Bits)

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index d70b732f6fd865..15112001536650 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -105,8 +105,9 @@ bool CheckPure(InterpState &S, CodePtr OpPC, const 
CXXMethodDecl *MD);
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
 /// Checks if the shift operation is legal.
-template 
-bool CheckShift(InterpState &S, CodePtr OpPC, const RT &RHS, unsigned Bits) {
+template 
+bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
+unsigned Bits) {
   if (RHS.isNegative()) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
 S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
@@ -122,6 +123,20 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const RT 
&RHS, unsigned Bits) {
 S.CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
 return false;
   }
+
+  if (LHS.isSigned() && !S.getLangOpts().CPlusPlus20) {
+const Expr *E = S.Current->getExpr(OpPC);
+// C++11 [expr.shift]p2: A signed left shift must have a non-negative
+// operand, and must not overflow the corresponding unsigned type.
+if (LHS.isNegative())
+  S.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt();
+else if (LHS.toUnsigned().countLeadingZeros() < static_cast(RHS))
+  S.CCEDiag(E, diag::note_constexpr_lshift_discards);
+  }
+
+  // C++2a [expr.shift]p2: [P0907R4]:
+  //E1 << E2 is the unique value congruent to
+  //E1 x 2^E2 module 2^N.
   return true;
 }
 
@@ -1523,7 +1538,7 @@ inline bool Shr(InterpState &S, CodePtr OpPC) {
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
@@ -1540,7 +1555,7 @@ inline bool Shl(InterpState &S, CodePtr OpPC) {
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;

diff  --git a/clang/test/AST/Interp/shifts.cpp 
b/clang/test/AST/Interp/shifts.cpp
index 3b2fc2619fe355..cf71e7145c2742 100644
--- a/clang/test/AST/Interp/shifts.cpp
+++ b/clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,39 @@ namespace shifts {
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant 
expression}} \
+// ref-cxx17-error {{never produces a constant 
expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}
+  }
+
+  constexpr int negativeShift() { // cxx17-error {{never produces a constant 
expression}} \
+  // ref-cxx17-error {{never produces a 
constant expression}}
+return -1 << 2; // cxx17-warning {{shifting a negative signed value is 
undefined}} \
+// ref-cxx17-warning {{shifting a negative signed value is 
undefined}} \
+// cxx17-note {{left shift of negative value -1}} \
+// ref-cxx17-note {{left shift of negative value -1}}
+  }
+
+  constexpr int foo(int a) {
+return -a << 2; // cxx17-note {{left shift of negative value -10}} \
+// ref-cxx17

[PATCH] D150209: [clang][Interp] Add more shift error checking

2023-07-20 Thread Timm Bäder via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd6b0af0574ca: [clang][Interp] Add more shift error checking 
(authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150209

Files:
  clang/lib/AST/Interp/Integral.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/shifts.cpp

Index: clang/test/AST/Interp/shifts.cpp
===
--- clang/test/AST/Interp/shifts.cpp
+++ clang/test/AST/Interp/shifts.cpp
@@ -152,4 +152,39 @@
   constexpr signed int R = (sizeof(unsigned) * 8) + 1;
   constexpr decltype(L) M  = (R > 32 && R < 64) ?  L << R : 0;
   constexpr decltype(L) M2 = (R > 32 && R < 64) ?  L >> R : 0;
+
+
+  constexpr int signedShift() { // cxx17-error {{never produces a constant expression}} \
+// ref-cxx17-error {{never produces a constant expression}}
+return 1024 << 31; // cxx17-warning {{signed shift result}} \
+   // ref-cxx17-warning {{signed shift result}} \
+   // cxx17-note {{signed left shift discards bits}} \
+   // ref-cxx17-note {{signed left shift discards bits}}
+  }
+
+  constexpr int negativeShift() { // cxx17-error {{never produces a constant expression}} \
+  // ref-cxx17-error {{never produces a constant expression}}
+return -1 << 2; // cxx17-warning {{shifting a negative signed value is undefined}} \
+// ref-cxx17-warning {{shifting a negative signed value is undefined}} \
+// cxx17-note {{left shift of negative value -1}} \
+// ref-cxx17-note {{left shift of negative value -1}}
+  }
+
+  constexpr int foo(int a) {
+return -a << 2; // cxx17-note {{left shift of negative value -10}} \
+// ref-cxx17-note {{left shift of negative value -10}} \
+// cxx17-note {{left shift of negative value -2}} \
+// ref-cxx17-note {{left shift of negative value -2}}
+  }
+  static_assert(foo(10)); // cxx17-error {{not an integral constant expression}} \
+  // cxx17-note {{in call to 'foo(10)'}} \
+  // ref-cxx17-error {{not an integral constant expression}} \
+  // ref-cxx17-note {{in call to 'foo(10)'}}
+
+  constexpr int a = -2;
+  static_assert(foo(a));
+  static_assert(foo(-a)); // cxx17-error {{not an integral constant expression}} \
+  // cxx17-note {{in call to 'foo(2)'}} \
+  // ref-cxx17-error {{not an integral constant expression}} \
+  // ref-cxx17-note {{in call to 'foo(2)'}}
 };
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -105,8 +105,9 @@
 bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
 
 /// Checks if the shift operation is legal.
-template 
-bool CheckShift(InterpState &S, CodePtr OpPC, const RT &RHS, unsigned Bits) {
+template 
+bool CheckShift(InterpState &S, CodePtr OpPC, const LT &LHS, const RT &RHS,
+unsigned Bits) {
   if (RHS.isNegative()) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
 S.CCEDiag(Loc, diag::note_constexpr_negative_shift) << RHS.toAPSInt();
@@ -122,6 +123,20 @@
 S.CCEDiag(E, diag::note_constexpr_large_shift) << Val << Ty << Bits;
 return false;
   }
+
+  if (LHS.isSigned() && !S.getLangOpts().CPlusPlus20) {
+const Expr *E = S.Current->getExpr(OpPC);
+// C++11 [expr.shift]p2: A signed left shift must have a non-negative
+// operand, and must not overflow the corresponding unsigned type.
+if (LHS.isNegative())
+  S.CCEDiag(E, diag::note_constexpr_lshift_of_negative) << LHS.toAPSInt();
+else if (LHS.toUnsigned().countLeadingZeros() < static_cast(RHS))
+  S.CCEDiag(E, diag::note_constexpr_lshift_discards);
+  }
+
+  // C++2a [expr.shift]p2: [P0907R4]:
+  //E1 << E2 is the unique value congruent to
+  //E1 x 2^E2 module 2^N.
   return true;
 }
 
@@ -1523,7 +1538,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
@@ -1540,7 +1555,7 @@
   const auto &LHS = S.Stk.pop();
   const unsigned Bits = LHS.bitWidth();
 
-  if (!CheckShift(S, OpPC, RHS, Bits))
+  if (!CheckShift(S, OpPC, LHS, RHS, Bits))
 return false;
 
   Integral R;
Index: clang/lib/AST/Interp/Integral.h
===
--- clang/lib/AST/Interp/Integral.h
+++ clang/lib/AST/Interp/Integral.h
@@ -127,7 +127,11 @@
 return Compare(V, RHS.V);
   }
 
-  unsigned countLeadingZeros() const { r

  1   2   3   >