[clang] [clang][AMDGPU] Don't define feature macros on host code (PR #83558)

2024-03-03 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh closed 
https://github.com/llvm/llvm-project/pull/83558
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [llvm][vfs] Allow root directory remap. Fix assertion failure. (PR #83766)

2024-03-03 Thread via cfe-commits

https://github.com/yelleyee updated 
https://github.com/llvm/llvm-project/pull/83766

>From b4e8c6825f39c0748cef53b590a494970409aae9 Mon Sep 17 00:00:00 2001
From: yelleyee 
Date: Mon, 4 Mar 2024 05:32:13 +
Subject: [PATCH] [llvm][vfs] Allow root directory remap

Add a new feature allowing root(/) directory remap by breaking the
assumption that remap root must be a directory.
Now the config below will be allowed.

Directory-remap config of root(/) is not allowed in previous impl.
Config list below will cause assertion failure in
`uniqueOverlayTree`.

'name': '/',
'type': 'directory-remap',
'external-contents': '//xxx'
---
 clang/test/VFS/Inputs/system-root-remap.yaml  | 12 ++
 clang/test/VFS/system-root-remap.c| 14 +++
 llvm/lib/Support/VirtualFileSystem.cpp| 19 -
 .../Support/VirtualFileSystemTest.cpp | 42 +++
 4 files changed, 86 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/VFS/Inputs/system-root-remap.yaml
 create mode 100644 clang/test/VFS/system-root-remap.c

diff --git a/clang/test/VFS/Inputs/system-root-remap.yaml 
b/clang/test/VFS/Inputs/system-root-remap.yaml
new file mode 100644
index 00..43d25fcc952236
--- /dev/null
+++ b/clang/test/VFS/Inputs/system-root-remap.yaml
@@ -0,0 +1,12 @@
+{
+  'version': 0,
+  'use-external-names': false,
+  'redirecting-with': 'redirect-only'
+  'roots': [
+{
+  'name': '/',
+  'type': 'directory-remap',
+  'external-contents': 'EXTERNAL_DIR'
+}
+  ]
+}
diff --git a/clang/test/VFS/system-root-remap.c 
b/clang/test/VFS/system-root-remap.c
new file mode 100644
index 00..f4168b75f29909
--- /dev/null
+++ b/clang/test/VFS/system-root-remap.c
@@ -0,0 +1,14 @@
+// RUN: mkdir -p %t
+// RUN: cd %t
+// RUN: sed -e "s@INPUT_DIR@%{/S:regex_replacement}/Inputs@g" -e 
"s@EXTERNAL_DIR@%{/t:regex_replacement}@g" %S/Inputs/system-root-remap.yaml  > 
%t.yaml
+// RUN: mkdir -p %t%t
+// RUN: cp %S/Inputs/actual_header.h %t%t/not_real.h
+// RUN: mkdir -p %t%S
+// RUN: cp %s %t%S
+// RUN: %clang_cc1 -Werror -I . -vfsoverlay %t.yaml -fsyntax-only 
-working-directory=%t %s
+
+#include "not_real.h"
+
+void foo(void) {
+  bar();
+}
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp 
b/llvm/lib/Support/VirtualFileSystem.cpp
index 051dd2a67d120f..349a9974a83b83 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -1747,6 +1747,10 @@ class llvm::vfs::RedirectingFileSystemParser {
   void uniqueOverlayTree(RedirectingFileSystem *FS,
  RedirectingFileSystem::Entry *SrcE,
  RedirectingFileSystem::Entry *NewParentE = nullptr) {
+if (NewParentE) {
+  assert(NewParentE->getKind() == RedirectingFileSystem::EK_Directory &&
+ "NewParentE must be a directory entry or nullptr");
+}
 StringRef Name = SrcE->getName();
 switch (SrcE->getKind()) {
 case RedirectingFileSystem::EK_Directory: {
@@ -1756,13 +1760,26 @@ class llvm::vfs::RedirectingFileSystemParser {
   // is parsed. This only leads to redundant walks, ignore it.
   if (!Name.empty())
 NewParentE = lookupOrCreateEntry(FS, Name, NewParentE);
+  if (NewParentE->getKind() != RedirectingFileSystem::EK_Directory) {
+// Found non directory entry, no need to generate the left nodes.
+break;
+  }
   for (std::unique_ptr &SubEntry :
llvm::make_range(DE->contents_begin(), DE->contents_end()))
 uniqueOverlayTree(FS, SubEntry.get(), NewParentE);
   break;
 }
 case RedirectingFileSystem::EK_DirectoryRemap: {
-  assert(NewParentE && "Parent entry must exist");
+  // Root DirectoryRemap:
+  // name: "/"
+  // external-name: ""
+  if (!NewParentE) {
+auto *DR = cast(SrcE);
+FS->Roots.push_back(
+std::make_unique(
+Name, DR->getExternalContentsPath(), DR->getUseName()));
+break;
+  }
   auto *DR = cast(SrcE);
   auto *DE = cast(NewParentE);
   DE->addContent(
diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp 
b/llvm/unittests/Support/VirtualFileSystemTest.cpp
index d4abbb4345873c..0a77d8b13eca0e 100644
--- a/llvm/unittests/Support/VirtualFileSystemTest.cpp
+++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp
@@ -1715,6 +1715,48 @@ TEST_F(VFSFromYAMLTest, MappedRoot) {
   EXPECT_EQ(0, NumDiagnostics);
 }
 
+TEST_F(VFSFromYAMLTest, MappedSysRoot) {
+  IntrusiveRefCntPtr Lower(new DummyFileSystem());
+  Lower->addDirectory("//root/foo/bar");
+  Lower->addRegularFile("//root/foo/bar/a");
+  IntrusiveRefCntPtr FS =
+  getFromYAMLString("{ 'roots': [\n"
+"{\n"
+"  'type': 'directory-remap',\n"
+"  'name': '/',\n"
+"  'external-contents': '//root/foo/bar'\n"
+"}\n"
+   

[clang] [llvm] [llvm][vfs] Allow root directory remap. Fix assertion failure. (PR #83766)

2024-03-03 Thread via cfe-commits

https://github.com/yelleyee updated 
https://github.com/llvm/llvm-project/pull/83766

>From f133ce3ee5f26f18182218949cc19ba4ff5ecd92 Mon Sep 17 00:00:00 2001
From: yelleyee 
Date: Mon, 4 Mar 2024 05:32:13 +
Subject: [PATCH] [llvm][vfs] Allow root directory remap

Add a new feature allowing root(/) directory remap by breaking the
assumption that remap root must be a directory.
Now the config below will be allowed.

Directory-remap config of root(/) is not allowed in previous impl.
Config list below will cause assertion failure in
`uniqueOverlayTree`.

'name': '/',
'type': 'directory-remap',
'external-contents': '//xxx'
---
 clang/test/VFS/Inputs/system-root-remap.yaml  | 12 ++
 clang/test/VFS/system-root-remap.c| 14 +++
 llvm/lib/Support/VirtualFileSystem.cpp| 32 ++
 .../Support/VirtualFileSystemTest.cpp | 42 +++
 4 files changed, 92 insertions(+), 8 deletions(-)
 create mode 100644 clang/test/VFS/Inputs/system-root-remap.yaml
 create mode 100644 clang/test/VFS/system-root-remap.c

diff --git a/clang/test/VFS/Inputs/system-root-remap.yaml 
b/clang/test/VFS/Inputs/system-root-remap.yaml
new file mode 100644
index 00..43d25fcc952236
--- /dev/null
+++ b/clang/test/VFS/Inputs/system-root-remap.yaml
@@ -0,0 +1,12 @@
+{
+  'version': 0,
+  'use-external-names': false,
+  'redirecting-with': 'redirect-only'
+  'roots': [
+{
+  'name': '/',
+  'type': 'directory-remap',
+  'external-contents': 'EXTERNAL_DIR'
+}
+  ]
+}
diff --git a/clang/test/VFS/system-root-remap.c 
b/clang/test/VFS/system-root-remap.c
new file mode 100644
index 00..f4168b75f29909
--- /dev/null
+++ b/clang/test/VFS/system-root-remap.c
@@ -0,0 +1,14 @@
+// RUN: mkdir -p %t
+// RUN: cd %t
+// RUN: sed -e "s@INPUT_DIR@%{/S:regex_replacement}/Inputs@g" -e 
"s@EXTERNAL_DIR@%{/t:regex_replacement}@g" %S/Inputs/system-root-remap.yaml  > 
%t.yaml
+// RUN: mkdir -p %t%t
+// RUN: cp %S/Inputs/actual_header.h %t%t/not_real.h
+// RUN: mkdir -p %t%S
+// RUN: cp %s %t%S
+// RUN: %clang_cc1 -Werror -I . -vfsoverlay %t.yaml -fsyntax-only 
-working-directory=%t %s
+
+#include "not_real.h"
+
+void foo(void) {
+  bar();
+}
diff --git a/llvm/lib/Support/VirtualFileSystem.cpp 
b/llvm/lib/Support/VirtualFileSystem.cpp
index 051dd2a67d120f..3a94afea9a0629 100644
--- a/llvm/lib/Support/VirtualFileSystem.cpp
+++ b/llvm/lib/Support/VirtualFileSystem.cpp
@@ -54,8 +54,8 @@
 using namespace llvm;
 using namespace llvm::vfs;
 
-using llvm::sys::fs::file_t;
 using llvm::sys::fs::file_status;
+using llvm::sys::fs::file_t;
 using llvm::sys::fs::file_type;
 using llvm::sys::fs::kInvalidFile;
 using llvm::sys::fs::perms;
@@ -1056,7 +1056,7 @@ llvm::ErrorOr InMemoryFileSystem::status(const 
Twine &Path) {
 
 llvm::ErrorOr>
 InMemoryFileSystem::openFileForRead(const Twine &Path) {
-  auto Node = lookupNode(Path,/*FollowFinalSymlink=*/true);
+  auto Node = lookupNode(Path, /*FollowFinalSymlink=*/true);
   if (!Node)
 return Node.getError();
 
@@ -1224,7 +1224,6 @@ static bool isFileNotFound(std::error_code EC,
 
 } // anonymous namespace
 
-
 RedirectingFileSystem::RedirectingFileSystem(IntrusiveRefCntPtr FS)
 : ExternalFS(std::move(FS)) {
   if (ExternalFS)
@@ -1350,7 +1349,8 @@ std::error_code RedirectingFileSystem::isLocal(const 
Twine &Path_,
   return ExternalFS->isLocal(Path, Result);
 }
 
-std::error_code RedirectingFileSystem::makeAbsolute(SmallVectorImpl 
&Path) const {
+std::error_code
+RedirectingFileSystem::makeAbsolute(SmallVectorImpl &Path) const {
   // is_absolute(..., Style::windows_*) accepts paths with both slash types.
   if (llvm::sys::path::is_absolute(Path, llvm::sys::path::Style::posix) ||
   llvm::sys::path::is_absolute(Path,
@@ -1747,6 +1747,10 @@ class llvm::vfs::RedirectingFileSystemParser {
   void uniqueOverlayTree(RedirectingFileSystem *FS,
  RedirectingFileSystem::Entry *SrcE,
  RedirectingFileSystem::Entry *NewParentE = nullptr) {
+if (NewParentE) {
+  assert(NewParentE->getKind() == RedirectingFileSystem::EK_Directory &&
+ "NewParentE must be a directory entry or nullptr");
+}
 StringRef Name = SrcE->getName();
 switch (SrcE->getKind()) {
 case RedirectingFileSystem::EK_Directory: {
@@ -1756,13 +1760,26 @@ class llvm::vfs::RedirectingFileSystemParser {
   // is parsed. This only leads to redundant walks, ignore it.
   if (!Name.empty())
 NewParentE = lookupOrCreateEntry(FS, Name, NewParentE);
+  if (NewParentE->getKind() != RedirectingFileSystem::EK_Directory) {
+// Found non directory entry, no need to generate the left nodes.
+break;
+  }
   for (std::unique_ptr &SubEntry :
llvm::make_range(DE->contents_begin(), DE->contents_end()))
 uniqueOverlayTree(FS, SubEntry.get(), NewParentE);
   break;
 }
 case RedirectingFileSystem::EK_Di

[clang] [clang][StaticAnalyzer] fix function evalCall() typo in CheckerDocumentation (PR #83677)

2024-03-03 Thread via cfe-commits

https://github.com/mzyKi closed https://github.com/llvm/llvm-project/pull/83677
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8715f25 - [clang][StaticAnalyzer] fix function evalCall() typo in CheckerDocumentation (#83677)

2024-03-03 Thread via cfe-commits

Author: Exile
Date: 2024-03-04T15:20:24+08:00
New Revision: 8715f256911786520bb727ce067098d7082ac45c

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

LOG: [clang][StaticAnalyzer] fix function evalCall() typo in 
CheckerDocumentation (#83677)

```bool evalCall(const CallEvent &Call, CheckerContext &C)``` is corret form.

Co-authored-by: miaozhiyuan 

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
index 3e5e2b9139149d..0ca0c487b64550 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
@@ -226,7 +226,7 @@ class CheckerDocumentation : public Checker< 
check::PreStmt,
   /// first one wins.
   ///
   /// eval::Call
-  bool evalCall(const CallExpr *CE, CheckerContext &C) const { return true; }
+  bool evalCall(const CallEvent &Call, CheckerContext &C) const { return true; 
}
 
   /// Handles assumptions on symbolic values.
   ///



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


[clang] [clang][RISCV] Support function attribute __attribute__((target("+attr"))) (PR #83674)

2024-03-03 Thread Piyou Chen via cfe-commits


@@ -0,0 +1,41 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple riscv64 -S -verify %s
+
+// REQUIRES: riscv-registered-target
+#include 
+
+void test_builtin() {
+  __riscv_vsetvl_e8m8(1); // expected-error {{'__builtin_rvv_vsetvli' needs 
target feature zve32x}}
+}
+
+__attribute__((target("+zve32x")))

BeMg wrote:

Base on 
[spec](https://github.com/riscv-non-isa/riscv-c-api-doc/blob/master/riscv-c-api.md#__attribute__targetattr-string),
 this target attribute should update as 
`__attribute__((target("arch=+zve32x")))`

https://github.com/llvm/llvm-project/pull/83674
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][RISCV] Support function attribute __attribute__((target("+attr"))) (PR #83674)

2024-03-03 Thread Piyou Chen via cfe-commits

https://github.com/BeMg edited https://github.com/llvm/llvm-project/pull/83674
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Add __builtin_start_object_lifetime builtin. (PR #82776)

2024-03-03 Thread via cfe-commits

cor3ntin wrote:

I am a bit concerned that this does not actually have the desired semantics at 
all, but @zygoloid seemed to be "happy" with it.  I will admit I struggle 
understanding the motivation of adding a builtin that does...less than it 
should (when it should do something).

Similarly, do you have plans for the array version of start_lifetime_as?

https://github.com/llvm/llvm-project/pull/82776
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][RISCV] Support function attribute __attribute__((target("+attr"))) (PR #83674)

2024-03-03 Thread Piyou Chen via cfe-commits


@@ -463,7 +463,8 @@ ParsedTargetAttr RISCVTargetInfo::parseTargetAttr(StringRef 
Features) const {
 Ret.Duplicate = "tune=";
 
   Ret.Tune = AttrString;
-}
+} else if (Feature.starts_with("+"))

BeMg wrote:

This code section will make clang violate target attribute syntax specification.

https://github.com/riscv-non-isa/riscv-c-api-doc/blob/master/riscv-c-api.md#__attribute__targetattr-string
 

https://github.com/llvm/llvm-project/pull/83674
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/82968

>From a06fa5e18313ad50019d50006e34a6b8249d95cd Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Mon, 26 Feb 2024 16:32:28 +0800
Subject: [PATCH 1/4] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm

These builtins are already there in Clang, however current codegen may
produce suboptimal results due to their complex behavior. Implement them
as intrinsics to ensure expected instructions are emitted.
---
 clang/lib/CodeGen/CGBuiltin.cpp   |  29 ++---
 .../PowerPC/builtins-ppc-xlcompat-rotate.c|  24 ++--
 llvm/include/llvm/IR/IntrinsicsPowerPC.td |  12 ++
 llvm/lib/Target/PowerPC/PPCISelLowering.cpp   |  52 
 llvm/test/CodeGen/PowerPC/rldimi.ll   |  15 +++
 llvm/test/CodeGen/PowerPC/rlwimi.ll   | 123 --
 llvm/test/CodeGen/PowerPC/rlwinm.ll   | 108 ++-
 7 files changed, 259 insertions(+), 104 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 734eb5a035ca49..5d55be6e9e99df 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17080,37 +17080,24 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 }
 return Builder.CreateCall(CGM.getIntrinsic(ID), Ops, "");
   }
-  // Rotate and insert under mask operation.
-  // __rldimi(rs, is, shift, mask)
-  // (rotl64(rs, shift) & mask) | (is & ~mask)
-  // __rlwimi(rs, is, shift, mask)
-  // (rotl(rs, shift) & mask) | (is & ~mask)
   case PPC::BI__builtin_ppc_rldimi:
   case PPC::BI__builtin_ppc_rlwimi: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));
 Value *Op2 = EmitScalarExpr(E->getArg(2));
 Value *Op3 = EmitScalarExpr(E->getArg(3));
-llvm::Type *Ty = Op0->getType();
-Function *F = CGM.getIntrinsic(Intrinsic::fshl, Ty);
-if (BuiltinID == PPC::BI__builtin_ppc_rldimi)
-  Op2 = Builder.CreateZExt(Op2, Int64Ty);
-Value *Shift = Builder.CreateCall(F, {Op0, Op0, Op2});
-Value *X = Builder.CreateAnd(Shift, Op3);
-Value *Y = Builder.CreateAnd(Op1, Builder.CreateNot(Op3));
-return Builder.CreateOr(X, Y);
-  }
-  // Rotate and insert under mask operation.
-  // __rlwnm(rs, shift, mask)
-  // rotl(rs, shift) & mask
+return Builder.CreateCall(
+CGM.getIntrinsic(BuiltinID == PPC::BI__builtin_ppc_rldimi
+ ? Intrinsic::ppc_rldimi
+ : Intrinsic::ppc_rlwimi),
+{Op0, Op1, Op2, Op3});
+  }
   case PPC::BI__builtin_ppc_rlwnm: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
 Value *Op1 = EmitScalarExpr(E->getArg(1));
 Value *Op2 = EmitScalarExpr(E->getArg(2));
-llvm::Type *Ty = Op0->getType();
-Function *F = CGM.getIntrinsic(Intrinsic::fshl, Ty);
-Value *Shift = Builder.CreateCall(F, {Op0, Op0, Op1});
-return Builder.CreateAnd(Shift, Op2);
+return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::ppc_rlwnm),
+  {Op0, Op1, Op2});
   }
   case PPC::BI__builtin_ppc_poppar4:
   case PPC::BI__builtin_ppc_poppar8: {
diff --git a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
index d96bfb4621421e..b218547c00d931 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat-rotate.c
@@ -16,11 +16,8 @@ void test_builtin_ppc_rldimi() {
   // CHECK:   %res = alloca i64, align 8
   // CHECK-NEXT:  [[RA:%[0-9]+]] = load i64, ptr @ull, align 8
   // CHECK-NEXT:  [[RB:%[0-9]+]] = load i64, ptr @ull, align 8
-  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i64 @llvm.fshl.i64(i64 [[RA]], i64 
[[RA]], i64 63)
-  // CHECK-NEXT:  [[RD:%[0-9]+]] = and i64 [[RC]], 72057593769492480
-  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i64 [[RB]], -72057593769492481
-  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i64 [[RD]], [[RE]]
-  // CHECK-NEXT:  store i64 [[RF]], ptr %res, align 8
+  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i64 @llvm.ppc.rldimi(i64 [[RA]], i64 
[[RB]], i32 63, i64 72057593769492480)
+  // CHECK-NEXT:  store i64 [[RC]], ptr %res, align 8
   // CHECK-NEXT:  ret void
 
   /*shift = 63, mask = 0x00FFF000 = 72057593769492480, ~mask = 
0xFF000FFF = -72057593769492481*/
@@ -32,11 +29,8 @@ void test_builtin_ppc_rlwimi() {
   // CHECK:   %res = alloca i32, align 4
   // CHECK-NEXT:  [[RA:%[0-9]+]] = load i32, ptr @ui, align 4
   // CHECK-NEXT:  [[RB:%[0-9]+]] = load i32, ptr @ui, align 4
-  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i32 @llvm.fshl.i32(i32 [[RA]], i32 
[[RA]], i32 31)
-  // CHECK-NEXT:  [[RD:%[0-9]+]] = and i32 [[RC]], 16776960
-  // CHECK-NEXT:  [[RE:%[0-9]+]] = and i32 [[RB]], -16776961
-  // CHECK-NEXT:  [[RF:%[0-9]+]] = or i32 [[RD]], [[RE]]
-  // CHECK-NEXT:  store i32 [[RF]], ptr %res, align 4
+  // CHECK-NEXT:  [[RC:%[0-9]+]] = call i32 @llvm.ppc.rlwimi(i32 [[RA]], i32 
[[R

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/83709

>From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 2 Mar 2024 22:08:29 -0800
Subject: [PATCH 1/5] [clang-format] Handle common C++ non-keyword types as
 such

Fixes #83400.
---
 clang/lib/Format/FormatToken.cpp  | 16 --
 clang/lib/Format/FormatToken.h|  4 +--
 clang/lib/Format/QualifierAlignmentFixer.cpp  | 25 +---
 clang/lib/Format/QualifierAlignmentFixer.h|  5 ++--
 clang/lib/Format/TokenAnnotator.cpp   | 29 ++-
 clang/lib/Format/UnwrappedLineParser.cpp  | 12 
 clang/unittests/Format/TokenAnnotatorTest.cpp |  6 
 7 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 56a7b2d6387765..02952bd20acf9a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
+bool FormatToken::isSimpleTypeSpecifier(bool IsCpp) const {
   switch (Tok.getKind()) {
   case tok::kw_short:
   case tok::kw_long:
@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);
   default:
 return false;
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+bool FormatToken::isTypeOrIdentifier(bool IsCpp) const {
+  return isSimpleTypeSpecifier(IsCpp) ||
+ Tok.isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 31245495041960..2bc136c51d23f1 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -674,9 +674,9 @@ struct FormatToken {
   }
 
   /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
+  [[nodiscard]] bool isSimpleTypeSpecifier(bool IsCpp) const;
 
-  [[nodiscard]] bool isTypeOrIdentifier() const;
+  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 0c63d330b5aed4..834ae115908856 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -268,11 +268,13 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isSimpleTypeSpecifier(IsCpp)) {
 // The case `const decltype(foo)` -> `const decltype(foo)`
 // The case `const typeof(foo)` -> `const typeof(foo)`
 // The case `const _Atomic(foo)` -> `const _Atomic(foo)`
@@ -280,8 +282,10 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   return Tok;
 
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
-while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment()))
+while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
+ IsCpp)) {
   LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
+}
 
 rotateTokens(SourceMgr, Fixes, Tok, LastSimpleTypeSpecifier,
  /*Left=*/false);
@@ -291,7 +295,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   // The case  `unsigned short const` -> `unsigned short const`
   // The case:
   // `unsigned short volatile const` -> `unsigned short const volatile`
-  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier()) {
+  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier(IsCpp)) {
 if (LastQual != Tok)
   rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false);
 return Tok;
@@ -4

[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-03 Thread Chuanqi Xu via cfe-commits


@@ -72,6 +72,10 @@ sections with improvements to Clang's support for those 
languages.
 C++ Language Changes
 
 
+C++14 Feature Support
+^
+- Sized deallocation is enabled by default in C++14 onwards.

ChuanqiXu9 wrote:

It may be good to mention the flag enabled so that people met regression can 
disable it locally to workaround it.

https://github.com/llvm/llvm-project/pull/83774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-03 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,44 @@
+//===--- SizedDellocation.h - Sized Deallocation *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file
+/// Defines a function that returns the minimum OS versions supporting
+/// C++14's sized deallocation functions.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_BASIC_SIZEDDEALLOCATION_H
+#define LLVM_CLANG_BASIC_SIZEDDEALLOCATION_H
+
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/VersionTuple.h"
+#include "llvm/TargetParser/Triple.h"
+
+namespace clang {
+inline llvm::VersionTuple sizedDeallocMinVersion(llvm::Triple::OSType OS) {

ChuanqiXu9 wrote:

If I read correctly, this is only used in `Darwin.cpp`, so it would be better 
to inline the function there.

https://github.com/llvm/llvm-project/pull/83774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-03 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp edited 
https://github.com/llvm/llvm-project/pull/83774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-03 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp edited 
https://github.com/llvm/llvm-project/pull/83774
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-03 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tidy
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-libcxx

Author: Wang Pengcheng (wangpc-pp)


Changes

Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

This is another try of https://reviews.llvm.org/D112921.

Some buildbots failed last time and I hope the owners may help me to
find the causes as I may not have such environments.



---

Patch is 53.09 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/83774.diff


41 Files Affected:

- (modified) clang-tools-extra/clangd/unittests/FindTargetTests.cpp (+3-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp (-10) 
- (modified) clang/docs/ReleaseNotes.rst (+4) 
- (added) clang/include/clang/Basic/SizedDeallocation.h (+44) 
- (modified) clang/include/clang/Driver/Options.td (+3-2) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+9-4) 
- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+38-3) 
- (modified) clang/lib/Driver/ToolChains/Darwin.h (+4) 
- (modified) clang/lib/Driver/ToolChains/ZOS.cpp (+6) 
- (modified) clang/test/AST/ast-dump-expr-json.cpp (+1-1) 
- (modified) clang/test/AST/ast-dump-expr.cpp (+1-1) 
- (modified) clang/test/AST/ast-dump-stmt-json.cpp (+241-3) 
- (modified) clang/test/Analysis/cxxnewexpr-callback.cpp (+2-2) 
- (modified) 
clang/test/CXX/basic/basic.stc/basic.stc.dynamic/basic.stc.dynamic.deallocation/p2.cpp
 (+1-1) 
- (modified) clang/test/CXX/drs/dr292.cpp (+3-3) 
- (modified) clang/test/CXX/expr/expr.unary/expr.new/p14.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/cxx1y-sized-deallocation.cpp (+5-5) 
- (modified) clang/test/CodeGenCXX/cxx1z-aligned-allocation.cpp (+3-3) 
- (modified) clang/test/CodeGenCXX/cxx2a-destroying-delete.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/delete-two-arg.cpp (+3-1) 
- (modified) clang/test/CodeGenCXX/delete.cpp (+7-5) 
- (modified) clang/test/CodeGenCXX/dllimport.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/new.cpp (+3-3) 
- (modified) clang/test/CodeGenCoroutines/coro-aligned-alloc-2.cpp (-2) 
- (modified) clang/test/CodeGenCoroutines/coro-aligned-alloc.cpp (+4-2) 
- (modified) clang/test/CodeGenCoroutines/coro-alloc.cpp (+4-2) 
- (modified) clang/test/CodeGenCoroutines/coro-cleanup.cpp (+4-2) 
- (modified) clang/test/CodeGenCoroutines/coro-dealloc.cpp (-2) 
- (modified) clang/test/CodeGenCoroutines/coro-gro.cpp (+2-1) 
- (modified) clang/test/CodeGenCoroutines/pr56919.cpp (+6-3) 
- (modified) clang/test/Lexer/cxx-features.cpp (+10-10) 
- (modified) clang/test/PCH/cxx1z-aligned-alloc.cpp (+5-5) 
- (modified) clang/test/SemaCXX/MicrosoftExtensions.cpp (+7-1) 
- (modified) clang/test/SemaCXX/builtin-operator-new-delete.cpp (+1-1) 
- (modified) clang/test/SemaCXX/cxx1y-sized-deallocation.cpp (+1-1) 
- (modified) clang/test/SemaCXX/unavailable_aligned_allocation.cpp (+9-6) 
- (modified) clang/unittests/StaticAnalyzer/CallEventTest.cpp (+1-1) 
- (modified) clang/www/cxx_status.html (+5-6) 
- (modified) 
libcxx/test/libcxx/language.support/support.dynamic/libcpp_deallocate.sh.cpp 
(+3) 
- (modified) 
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array14.pass.cpp
 (+5-3) 
- (modified) 
libcxx/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete14.pass.cpp
 (+5-3) 


``diff
diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 0af6036734ba53..1b7b96281dfaa5 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -839,7 +839,9 @@ TEST_F(TargetDeclTest, OverloadExpr) {
   [[delete]] x;
 }
   )cpp";
-  EXPECT_DECLS("CXXDeleteExpr", "void operator delete(void *) noexcept");
+  // Sized deallocation is enabled by default in C++14 onwards.
+  EXPECT_DECLS("CXXDeleteExpr",
+   "void operator delete(void *, unsigned long) noexcept");
 }
 
 TEST_F(TargetDeclTest, DependentExprs) {
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
index 78f021144b2e19..f86fe8a4c5b14f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
@@ -12,16 +12,6 @@ struct S {
 // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: declaration of 'operator new' has 
no matching declaration of 'operator delete' at the same scope
 void *operator new(size_t size) noexcept(false);
 
-struct T {
-  // Sized deallocations are not enabled by default, and so this new/delete 
pair
-  // does not match. However, we expect only one warning, for the new, because
-  // the operator delete is a placement delete and we do not warn o

[clang] [clang-tools-extra] [libcxx] [clang] Enable sized deallocation by default in C++14 onwards (PR #83774)

2024-03-03 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp created 
https://github.com/llvm/llvm-project/pull/83774

Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

This is another try of https://reviews.llvm.org/D112921.

Some buildbots failed last time and I hope the owners may help me to
find the causes as I may not have such environments.



>From 26245679b0f40b510e628aaed091739e9931c29c Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Fri, 14 Jul 2023 10:38:14 +0800
Subject: [PATCH] [clang] Enable sized deallocation by default in C++14 onwards

Since C++14 has been released for about nine years and most standard
libraries have implemented sized deallocation functions, it's time to
make this feature default again.

Differential Revision: https://reviews.llvm.org/D112921
---
 .../clangd/unittests/FindTargetTests.cpp  |   4 +-
 .../checkers/misc/new-delete-overloads.cpp|  10 -
 clang/docs/ReleaseNotes.rst   |   4 +
 clang/include/clang/Basic/SizedDeallocation.h |  44 
 clang/include/clang/Driver/Options.td |   5 +-
 clang/lib/Driver/ToolChains/Clang.cpp |  13 +-
 clang/lib/Driver/ToolChains/Darwin.cpp|  41 ++-
 clang/lib/Driver/ToolChains/Darwin.h  |   4 +
 clang/lib/Driver/ToolChains/ZOS.cpp   |   6 +
 clang/test/AST/ast-dump-expr-json.cpp |   2 +-
 clang/test/AST/ast-dump-expr.cpp  |   2 +-
 clang/test/AST/ast-dump-stmt-json.cpp | 244 +-
 clang/test/Analysis/cxxnewexpr-callback.cpp   |   4 +-
 .../basic.stc.dynamic.deallocation/p2.cpp |   2 +-
 clang/test/CXX/drs/dr292.cpp  |   6 +-
 .../test/CXX/expr/expr.unary/expr.new/p14.cpp |   2 +-
 .../CodeGenCXX/cxx1y-sized-deallocation.cpp   |  10 +-
 .../CodeGenCXX/cxx1z-aligned-allocation.cpp   |   6 +-
 .../CodeGenCXX/cxx2a-destroying-delete.cpp|   4 +-
 clang/test/CodeGenCXX/delete-two-arg.cpp  |   4 +-
 clang/test/CodeGenCXX/delete.cpp  |  12 +-
 clang/test/CodeGenCXX/dllimport.cpp   |   4 +-
 clang/test/CodeGenCXX/new.cpp |   6 +-
 .../coro-aligned-alloc-2.cpp  |   2 -
 .../CodeGenCoroutines/coro-aligned-alloc.cpp  |   6 +-
 clang/test/CodeGenCoroutines/coro-alloc.cpp   |   6 +-
 clang/test/CodeGenCoroutines/coro-cleanup.cpp |   6 +-
 clang/test/CodeGenCoroutines/coro-dealloc.cpp |   2 -
 clang/test/CodeGenCoroutines/coro-gro.cpp |   3 +-
 clang/test/CodeGenCoroutines/pr56919.cpp  |   9 +-
 clang/test/Lexer/cxx-features.cpp |  20 +-
 clang/test/PCH/cxx1z-aligned-alloc.cpp|  10 +-
 clang/test/SemaCXX/MicrosoftExtensions.cpp|   8 +-
 .../SemaCXX/builtin-operator-new-delete.cpp   |   2 +-
 .../test/SemaCXX/cxx1y-sized-deallocation.cpp |   2 +-
 .../unavailable_aligned_allocation.cpp|  15 +-
 .../StaticAnalyzer/CallEventTest.cpp  |   2 +-
 clang/www/cxx_status.html |  11 +-
 .../support.dynamic/libcpp_deallocate.sh.cpp  |   3 +
 .../sized_delete_array14.pass.cpp |   8 +-
 .../new.delete.single/sized_delete14.pass.cpp |   8 +-
 41 files changed, 458 insertions(+), 104 deletions(-)
 create mode 100644 clang/include/clang/Basic/SizedDeallocation.h

diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 0af6036734ba53..1b7b96281dfaa5 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -839,7 +839,9 @@ TEST_F(TargetDeclTest, OverloadExpr) {
   [[delete]] x;
 }
   )cpp";
-  EXPECT_DECLS("CXXDeleteExpr", "void operator delete(void *) noexcept");
+  // Sized deallocation is enabled by default in C++14 onwards.
+  EXPECT_DECLS("CXXDeleteExpr",
+   "void operator delete(void *, unsigned long) noexcept");
 }
 
 TEST_F(TargetDeclTest, DependentExprs) {
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
index 78f021144b2e19..f86fe8a4c5b14f 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/new-delete-overloads.cpp
@@ -12,16 +12,6 @@ struct S {
 // CHECK-MESSAGES: :[[@LINE+1]]:7: warning: declaration of 'operator new' has 
no matching declaration of 'operator delete' at the same scope
 void *operator new(size_t size) noexcept(false);
 
-struct T {
-  // Sized deallocations are not enabled by default, and so this new/delete 
pair
-  // does not match. However, we expect only one warning, for the new, because
-  // the operator delete is a placement delete and we do not warn on 
mismatching
-  // placement operations.
-  // CHECK-MESSAGES: :[[@LINE+1]]:9: warning: declaration of 'operator new' 
has no matching declaration of 'operator delete' at 

[clang] [llvm] [llvm][vfs] Allow root directory remap. Fix assertion failure. (PR #83766)

2024-03-03 Thread via cfe-commits

yelleyee wrote:

Refinement: The current implementation suggests that the top `remap-entry` node 
must be a directory in the tree, which is not consistent with the rest of the 
tree design.
In the reset nodes of the tree, both `directory` and `directory-remap` should 
be allowed. Therefore, the `uniqueOverlayTree` function should allow the `SrcE` 
parameter to be passed with a `EK_DirectoryRemap` kind parameter when initially 
entering the function.

https://github.com/llvm/llvm-project/pull/83766
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][AMDGPU] Don't define feature macros on host code (PR #83558)

2024-03-03 Thread Matt Arsenault via cfe-commits


@@ -6,32 +6,32 @@
 // R600-based processors.
 //
 
-// RUN: %clang -E -dM -target r600 -mcpu=r600 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,R600 %s -DCPU=r600
-// RUN: %clang -E -dM -target r600 -mcpu=rv630 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,R600 %s -DCPU=r600
-// RUN: %clang -E -dM -target r600 -mcpu=rv635 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,R600 %s -DCPU=r600
-// RUN: %clang -E -dM -target r600 -mcpu=r630 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,R630 %s -DCPU=r630
-// RUN: %clang -E -dM -target r600 -mcpu=rs780 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,RS880 %s -DCPU=rs880
-// RUN: %clang -E -dM -target r600 -mcpu=rs880 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,RS880 %s -DCPU=rs880
-// RUN: %clang -E -dM -target r600 -mcpu=rv610 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,RS880 %s -DCPU=rs880
-// RUN: %clang -E -dM -target r600 -mcpu=rv620 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,RS880 %s -DCPU=rs880
-// RUN: %clang -E -dM -target r600 -mcpu=rv670 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,RV670 %s -DCPU=rv670
-// RUN: %clang -E -dM -target r600 -mcpu=rv710 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,RV710 %s -DCPU=rv710
-// RUN: %clang -E -dM -target r600 -mcpu=rv730 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,RV730 %s -DCPU=rv730
-// RUN: %clang -E -dM -target r600 -mcpu=rv740 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,RV770 %s -DCPU=rv770
-// RUN: %clang -E -dM -target r600 -mcpu=rv770 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,RV770 %s -DCPU=rv770
-// RUN: %clang -E -dM -target r600 -mcpu=cedar %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,CEDAR %s -DCPU=cedar
-// RUN: %clang -E -dM -target r600 -mcpu=palm %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,CEDAR %s -DCPU=cedar
-// RUN: %clang -E -dM -target r600 -mcpu=cypress %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,CYPRESS %s -DCPU=cypress
-// RUN: %clang -E -dM -target r600 -mcpu=hemlock %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,CYPRESS %s -DCPU=cypress
-// RUN: %clang -E -dM -target r600 -mcpu=juniper %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,JUNIPER %s -DCPU=juniper
-// RUN: %clang -E -dM -target r600 -mcpu=redwood %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,REDWOOD %s -DCPU=redwood
-// RUN: %clang -E -dM -target r600 -mcpu=sumo %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,SUMO %s -DCPU=sumo
-// RUN: %clang -E -dM -target r600 -mcpu=sumo2 %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,SUMO %s -DCPU=sumo
-// RUN: %clang -E -dM -target r600 -mcpu=barts %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,BARTS %s -DCPU=barts
-// RUN: %clang -E -dM -target r600 -mcpu=caicos %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,CAICOS %s -DCPU=caicos
-// RUN: %clang -E -dM -target r600 -mcpu=aruba %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,CAYMAN %s -DCPU=cayman
-// RUN: %clang -E -dM -target r600 -mcpu=cayman %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,CAYMAN %s -DCPU=cayman
-// RUN: %clang -E -dM -target r600 -mcpu=turks %s 2>&1 | FileCheck 
--check-prefixes=ARCH-R600,TURKS %s -DCPU=turks
+// RUN: %clang -E -dM -Xclang -fcuda-is-device -target r600 -mcpu=r600 %s 2>&1 
| FileCheck --check-prefixes=ARCH-R600,R600 %s -DCPU=r600

arsenm wrote:

s/should/should not/

https://github.com/llvm/llvm-project/pull/83558
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [llvm][vfs] Allow root directory remap. Fix assertion failure. (PR #83766)

2024-03-03 Thread via cfe-commits

https://github.com/yelleyee edited 
https://github.com/llvm/llvm-project/pull/83766
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [llvm][vfs] Allow root directory remap (PR #83766)

2024-03-03 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-llvm-support

Author: None (yelleyee)


Changes

Add a new feature allowing root(/) directory remap by breaking the
assumption that remap root must be a directory.
Now the config below will be allowed.

Directory-remap config of root(/) is not allowed in previous impl.
Config list below will cause assertion failure in
`uniqueOverlayTree`.

```json
'name': '/',
'type': 'directory-remap',
'external-contents': '//xxx'
```

Assertion failed stack is attached below:
```
clang -cc1 -ferror-limit 19 -fcolor-diagnostics -o /dev/null -disable-free 
-emit-obj -x c a.c -tune-cpu generic -target-cpu x86-64 -triple 
x86_64-unknown-linux-gnu -resource-dir 
///MY_ROOT///Source/llvm-project/build/lib/clang/18 -isystem 
///MY_ROOT///Source/llvm-project/build/lib/clang/18/include -isystem 
/usr/local/include -isystem 
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include 
-internal-externc-isystem /usr/include/x86_64-linux-gnu 
-internal-externc-isystem /include -internal-externc-isystem /usr/include 
-std=gnu17 -fmath-errno -fno-implicit-modules -pic-level 2 -pic-is-pie 
-fgnuc-version=4.2.1 -ffp-contract=on 
-fno-experimental-relative-c++-abi-vtables -fno-file-reproducible -O0 
-fdebug-compilation-dir=///MY_ROOT_1///gitWorkSpace/test 
-fcoverage-compilation-dir=///MY_ROOT_1///gitWorkSpace/test -faddrsig 
-mrelax-all -debugger-tuning=gdb -funwind-tables=2 -mconstructor-aliases 
-clear-ast-before-backend -main-file-name a.c -mframe-pointer=all 
-fdiagnostics-hotness-threshold=0 -fdiagnostics-misexpect-tolerance=0 -D 
__GCC_HAVE_DWARF2_CFI_ASM=1 -ivfsoverlay vfs.yaml
clang: ///MY_ROOT///llvm-project/llvm/lib/Support/VirtualFileSystem.cpp:1749: 
void 
llvm::vfs::RedirectingFileSystemParser::uniqueOverlayTree(llvm::vfs::RedirectingFileSystem*,
 llvm::vfs::RedirectingFileSystem::Entry*, 
llvm::vfs::RedirectingFileSystem::Entry*): Assertion `NewParentE && 
"Parent entry must exist"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: clang -cc1 -ferror-limit 19 -fcolor-diagnostics -o 
/dev/null -disable-free -emit-obj -x c a.c -tune-cpu generic -target-cpu x86-64 
-triple x86_64-unknown-linux-gnu -resource-dir 
///MY_ROOT///Source/llvm-project/build/lib/clang/18 -isystem 
///MY_ROOT///Source/llvm-project/build/lib/clang/18/include -isystem 
/usr/local/include -isystem 
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include 
-internal-externc-isystem /usr/include/x86_64-linux-gnu 
-internal-externc-isystem /include -internal-externc-isystem /usr/include 
-std=gnu17 -fmath-errno -fno-implicit-modules -pic-level 2 -pic-is-pie 
-fgnuc-version=4.2.1 -ffp-contract=on 
-fno-experimental-relative-c++-abi-vtables -fno-file-reproducible -O0 
-fdebug-compilation-dir=///MY_ROOT_1///gitWorkSpace/test 
-fcoverage-compilation-dir=///MY_ROOT_1///gitWorkSpace/test -faddrsig 
-mrelax-all -debugger-tuning=gdb -funwind-tables=2 -mconstructor-aliases 
-clear-ast-before-backend -main-file-name a.c -mframe-pointer=all 
-fdiagnostics-hotness-threshold=0 -fdiagnostics-misexpect-tolerance=0 -D 
__GCC_HAVE_DWARF2_CFI_ASM=1 -ivfsoverlay vfs.yaml
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVMSupport.so.16   0x7f3786891a7c 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 82
1  libLLVMSupport.so.16   0x7f3786891e47
2  libLLVMSupport.so.16   0x7f378688f72a llvm::sys::RunSignalHandlers() 
+ 159
3  libLLVMSupport.so.16   0x7f37868913b0
4  libc.so.6  0x7f378606f090
5  libc.so.6  0x7f378606f00b gsignal + 203
6  libc.so.6  0x7f378604e859 abort + 299
7  libc.so.6  0x7f378604e729
8  libc.so.6  0x7f378605ffd6
9  libLLVMSupport.so.16   0x7f37868320d2
10 libLLVMSupport.so.16   0x7f3786834be3
11 libLLVMSupport.so.16   0x7f3786822f00 
llvm::vfs::RedirectingFileSystem::create(std::unique_ptr>, void (*)(llvm::SMDiagnostic 
const&, void*), llvm::StringRef, void*, 
llvm::IntrusiveRefCntPtr) + 994
12 libLLVMSupport.so.16   0x7f3786825b06 
llvm::vfs::getVFSFromYAML(std::unique_ptr>, void (*)(llvm::SMDiagnostic 
const&, void*), llvm::StringRef, void*, 
llvm::IntrusiveRefCntPtr) + 169
13 libclangFrontend.so.16 0x7f378c6145c0 
clang::createVFSFromOverlayFiles(llvm::ArrayRef, std::allocator>>, 
clang::DiagnosticsEngine&, 
llvm::IntrusiveRefCntPtr) + 520
14 libclangFr

[clang] [llvm] [llvm][vfs] Allow root directory remap (PR #83766)

2024-03-03 Thread via cfe-commits

https://github.com/yelleyee created 
https://github.com/llvm/llvm-project/pull/83766

Add a new feature allowing root(/) directory remap by breaking the
assumption that remap root must be a directory.
Now the config below will be allowed.

Directory-remap config of root(/) is not allowed in previous impl.
Config list below will cause assertion failure in
`uniqueOverlayTree`.

```json
'name': '/',
'type': 'directory-remap',
'external-contents': '//xxx'
```

Assertion failed stack is attached below:
```
clang -cc1 -ferror-limit 19 -fcolor-diagnostics -o /dev/null -disable-free 
-emit-obj -x c a.c -tune-cpu generic -target-cpu x86-64 -triple 
x86_64-unknown-linux-gnu -resource-dir 
///MY_ROOT///Source/llvm-project/build/lib/clang/18 -isystem 
///MY_ROOT///Source/llvm-project/build/lib/clang/18/include -isystem 
/usr/local/include -isystem 
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include 
-internal-externc-isystem /usr/include/x86_64-linux-gnu 
-internal-externc-isystem /include -internal-externc-isystem /usr/include 
-std=gnu17 -fmath-errno -fno-implicit-modules -pic-level 2 -pic-is-pie 
-fgnuc-version=4.2.1 -ffp-contract=on 
-fno-experimental-relative-c++-abi-vtables -fno-file-reproducible -O0 
-fdebug-compilation-dir=///MY_ROOT_1///gitWorkSpace/test 
-fcoverage-compilation-dir=///MY_ROOT_1///gitWorkSpace/test -faddrsig 
-mrelax-all -debugger-tuning=gdb -funwind-tables=2 -mconstructor-aliases 
-clear-ast-before-backend -main-file-name a.c -mframe-pointer=all 
-fdiagnostics-hotness-threshold=0 -fdiagnostics-misexpect-tolerance=0 -D 
__GCC_HAVE_DWARF2_CFI_ASM=1 -ivfsoverlay vfs.yaml
clang: ///MY_ROOT///llvm-project/llvm/lib/Support/VirtualFileSystem.cpp:1749: 
void 
llvm::vfs::RedirectingFileSystemParser::uniqueOverlayTree(llvm::vfs::RedirectingFileSystem*,
 llvm::vfs::RedirectingFileSystem::Entry*, 
llvm::vfs::RedirectingFileSystem::Entry*): Assertion `NewParentE && "Parent 
entry must exist"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and 
include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: clang -cc1 -ferror-limit 19 -fcolor-diagnostics -o 
/dev/null -disable-free -emit-obj -x c a.c -tune-cpu generic -target-cpu x86-64 
-triple x86_64-unknown-linux-gnu -resource-dir 
///MY_ROOT///Source/llvm-project/build/lib/clang/18 -isystem 
///MY_ROOT///Source/llvm-project/build/lib/clang/18/include -isystem 
/usr/local/include -isystem 
/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include 
-internal-externc-isystem /usr/include/x86_64-linux-gnu 
-internal-externc-isystem /include -internal-externc-isystem /usr/include 
-std=gnu17 -fmath-errno -fno-implicit-modules -pic-level 2 -pic-is-pie 
-fgnuc-version=4.2.1 -ffp-contract=on 
-fno-experimental-relative-c++-abi-vtables -fno-file-reproducible -O0 
-fdebug-compilation-dir=///MY_ROOT_1///gitWorkSpace/test 
-fcoverage-compilation-dir=///MY_ROOT_1///gitWorkSpace/test -faddrsig 
-mrelax-all -debugger-tuning=gdb -funwind-tables=2 -mconstructor-aliases 
-clear-ast-before-backend -main-file-name a.c -mframe-pointer=all 
-fdiagnostics-hotness-threshold=0 -fdiagnostics-misexpect-tolerance=0 -D 
__GCC_HAVE_DWARF2_CFI_ASM=1 -ivfsoverlay vfs.yaml
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH 
or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVMSupport.so.16   0x7f3786891a7c 
llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 82
1  libLLVMSupport.so.16   0x7f3786891e47
2  libLLVMSupport.so.16   0x7f378688f72a llvm::sys::RunSignalHandlers() 
+ 159
3  libLLVMSupport.so.16   0x7f37868913b0
4  libc.so.6  0x7f378606f090
5  libc.so.6  0x7f378606f00b gsignal + 203
6  libc.so.6  0x7f378604e859 abort + 299
7  libc.so.6  0x7f378604e729
8  libc.so.6  0x7f378605ffd6
9  libLLVMSupport.so.16   0x7f37868320d2
10 libLLVMSupport.so.16   0x7f3786834be3
11 libLLVMSupport.so.16   0x7f3786822f00 
llvm::vfs::RedirectingFileSystem::create(std::unique_ptr>, void (*)(llvm::SMDiagnostic const&, 
void*), llvm::StringRef, void*, 
llvm::IntrusiveRefCntPtr) + 994
12 libLLVMSupport.so.16   0x7f3786825b06 
llvm::vfs::getVFSFromYAML(std::unique_ptr>, void (*)(llvm::SMDiagnostic const&, 
void*), llvm::StringRef, void*, 
llvm::IntrusiveRefCntPtr) + 169
13 libclangFrontend.so.16 0x7f378c6145c0 
clang::createVFSFromOverlayFiles(llvm::ArrayRef, std::allocator>>, clang::DiagnosticsEngine&, 
llvm::IntrusiveRefCntPtr) + 520
14 libclangFrontend.so.16 0x7f378c614392 
clang::createVFSFromCompilerInvocation(clang::CompilerInvocation const&, 
clang::DiagnosticsEngine&, llvm::IntrusiveRefCntPtr) + 
138
15 libclangFrontend.so.16 0x7f378c6142e1 
clang::createVFSFromCompilerInvocation(clang::CompilerInvocation

[clang-tools-extra] [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (PR #83542)

2024-03-03 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 closed 
https://github.com/llvm/llvm-project/pull/83542
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] e6e53ca - [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (#83542)

2024-03-03 Thread via cfe-commits

Author: Nathan Ridge
Date: 2024-03-04T00:12:56-05:00
New Revision: e6e53ca8470d719882539359ebe3ad8b442a8cb0

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

LOG: [clangd] [HeuristicResolver] Protect against infinite recursion on 
DependentNameTypes (#83542)

When resolving names inside templates that implement recursive
compile-time functions (e.g. waldo::type is defined in terms
of waldo::type), HeuristicResolver could get into an infinite
recursion, specifically one where resolveDependentNameType() can
be called recursively with the same DependentNameType*.

To guard against this, HeuristicResolver tracks, for each external
call into a HeuristicResolver function, the set of DependentNameTypes
that it has seen, and bails if it sees the same DependentNameType again.

To implement this, a helper class HeuristicResolverImpl is introduced
to store state that persists for the duration of an external call into
HeuristicResolver (but does not persist between such calls).

Fixes https://github.com/clangd/clangd/issues/1951

Added: 


Modified: 
clang-tools-extra/clangd/HeuristicResolver.cpp
clang-tools-extra/clangd/HeuristicResolver.h
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 3c147b6b582bf0..26d54200eeffd2 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -16,6 +16,80 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+// Helper class for implementing HeuristicResolver.
+// Unlike HeuristicResolver which is a long-lived class,
+// a new instance of this class is created for every external
+// call into a HeuristicResolver operation. That allows this
+// class to store state that's local to such a top-level call,
+// particularly "recursion protection sets" that keep track of
+// nodes that have already been seen to avoid infinite recursion.
+class HeuristicResolverImpl {
+public:
+  HeuristicResolverImpl(ASTContext &Ctx) : Ctx(Ctx) {}
+
+  // These functions match the public interface of HeuristicResolver
+  // (but aren't const since they may modify the recursion protection sets).
+  std::vector
+  resolveMemberExpr(const CXXDependentScopeMemberExpr *ME);
+  std::vector
+  resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE);
+  std::vector resolveTypeOfCallExpr(const CallExpr *CE);
+  std::vector resolveCalleeOfCallExpr(const CallExpr *CE);
+  std::vector
+  resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD);
+  std::vector
+  resolveDependentNameType(const DependentNameType *DNT);
+  std::vector resolveTemplateSpecializationType(
+  const DependentTemplateSpecializationType *DTST);
+  const Type *resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS);
+  const Type *getPointeeType(const Type *T);
+
+private:
+  ASTContext &Ctx;
+
+  // Recursion protection sets
+  llvm::SmallSet SeenDependentNameTypes;
+
+  // Given a tag-decl type and a member name, heuristically resolve the
+  // name to one or more declarations.
+  // The current heuristic is simply to look up the name in the primary
+  // template. This is a heuristic because the template could potentially
+  // have specializations that declare 
diff erent members.
+  // Multiple declarations could be returned if the name is overloaded
+  // (e.g. an overloaded method in the primary template).
+  // This heuristic will give the desired answer in many cases, e.g.
+  // for a call to vector::size().
+  std::vector
+  resolveDependentMember(const Type *T, DeclarationName Name,
+ llvm::function_ref Filter);
+
+  // Try to heuristically resolve the type of a possibly-dependent expression
+  // `E`.
+  const Type *resolveExprToType(const Expr *E);
+  std::vector resolveExprToDecls(const Expr *E);
+
+  // Helper function for HeuristicResolver::resolveDependentMember()
+  // which takes a possibly-dependent type `T` and heuristically
+  // resolves it to a CXXRecordDecl in which we can try name lookup.
+  CXXRecordDecl *resolveTypeToRecordDecl(const Type *T);
+
+  // This is a reimplementation of CXXRecordDecl::lookupDependentName()
+  // so that the implementation can call into other HeuristicResolver helpers.
+  // FIXME: Once HeuristicResolver is upstreamed to the clang libraries
+  // (https://github.com/clangd/clangd/discussions/1662),
+  // CXXRecordDecl::lookupDepenedentName() can be removed, and its call sites
+  // can be modified to benefit from the more comprehensive heuristics offered
+  // by HeuristicResolver instead.
+  std::vector
+  lookupDependentName(CXXRecordDecl *RD, DeclarationName Name,
+  llvm::function_ref Filter);
+ 

[clang-tools-extra] [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (PR #83542)

2024-03-03 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> I don't have any other concerns about the refactor, so feel free to land it 
> or wait for other folks' opinions.

Thank you for reviewing!

I'm going to merge this sooner rather than later, since due to the severe 
nature of the bug (crash on standard library headers), I'd like to backport it 
to LLVM 18.

Of course, I'm happy to make follow-up changes if others have additional 
feedback.

https://github.com/llvm/llvm-project/pull/83542
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (PR #83542)

2024-03-03 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

Updated patch with two changes:

 * Added the `even`/`odd` exampls as a second test case 
 * Elaborated on the problem and solution in the commit message

https://github.com/llvm/llvm-project/pull/83542
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (PR #83542)

2024-03-03 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 edited 
https://github.com/llvm/llvm-project/pull/83542
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HIP] add --offload-compression-level= option (PR #83605)

2024-03-03 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu edited 
https://github.com/llvm/llvm-project/pull/83605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [HIP] add --offload-compression-level= option (PR #83605)

2024-03-03 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu edited 
https://github.com/llvm/llvm-project/pull/83605
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] [HeuristicResolver] Protect against infinite recursion on DependentNameTypes (PR #83542)

2024-03-03 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/83542

>From 1495cd55329d9d9d6ef7f61a9dc3f3cc48a72dac Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Fri, 1 Mar 2024 03:27:51 -0500
Subject: [PATCH] [clangd] [HeuristicResolver] Protect against infinite
 recursion on DependentNameTypes

When resolving names inside templates that implement recursive
compile-time functions (e.g. waldo::type is defined in terms
of waldo::type), HeuristicResolver could get into an infinite
recursion, specifically one where resolveDependentNameType() can
be called recursively with the same DependentNameType*.

To guard against this, HeuristicResolver tracks, for each external
call into a HeuristicResolver function, the set of DependentNameTypes
that it has seen, and bails if it sees the same DependentNameType again.

To implement this, a helper class HeuristicResolverImpl is introduced
to store state that persists for the duration of an external call into
HeuristicResolver (but does not persist between such calls).

Fixes https://github.com/clangd/clangd/issues/1951
---
 .../clangd/HeuristicResolver.cpp  | 170 ++
 clang-tools-extra/clangd/HeuristicResolver.h  |  37 
 .../clangd/unittests/FindTargetTests.cpp  |  27 +++
 3 files changed, 165 insertions(+), 69 deletions(-)

diff --git a/clang-tools-extra/clangd/HeuristicResolver.cpp 
b/clang-tools-extra/clangd/HeuristicResolver.cpp
index 3c147b6b582bf0..26d54200eeffd2 100644
--- a/clang-tools-extra/clangd/HeuristicResolver.cpp
+++ b/clang-tools-extra/clangd/HeuristicResolver.cpp
@@ -16,6 +16,80 @@
 namespace clang {
 namespace clangd {
 
+namespace {
+
+// Helper class for implementing HeuristicResolver.
+// Unlike HeuristicResolver which is a long-lived class,
+// a new instance of this class is created for every external
+// call into a HeuristicResolver operation. That allows this
+// class to store state that's local to such a top-level call,
+// particularly "recursion protection sets" that keep track of
+// nodes that have already been seen to avoid infinite recursion.
+class HeuristicResolverImpl {
+public:
+  HeuristicResolverImpl(ASTContext &Ctx) : Ctx(Ctx) {}
+
+  // These functions match the public interface of HeuristicResolver
+  // (but aren't const since they may modify the recursion protection sets).
+  std::vector
+  resolveMemberExpr(const CXXDependentScopeMemberExpr *ME);
+  std::vector
+  resolveDeclRefExpr(const DependentScopeDeclRefExpr *RE);
+  std::vector resolveTypeOfCallExpr(const CallExpr *CE);
+  std::vector resolveCalleeOfCallExpr(const CallExpr *CE);
+  std::vector
+  resolveUsingValueDecl(const UnresolvedUsingValueDecl *UUVD);
+  std::vector
+  resolveDependentNameType(const DependentNameType *DNT);
+  std::vector resolveTemplateSpecializationType(
+  const DependentTemplateSpecializationType *DTST);
+  const Type *resolveNestedNameSpecifierToType(const NestedNameSpecifier *NNS);
+  const Type *getPointeeType(const Type *T);
+
+private:
+  ASTContext &Ctx;
+
+  // Recursion protection sets
+  llvm::SmallSet SeenDependentNameTypes;
+
+  // Given a tag-decl type and a member name, heuristically resolve the
+  // name to one or more declarations.
+  // The current heuristic is simply to look up the name in the primary
+  // template. This is a heuristic because the template could potentially
+  // have specializations that declare different members.
+  // Multiple declarations could be returned if the name is overloaded
+  // (e.g. an overloaded method in the primary template).
+  // This heuristic will give the desired answer in many cases, e.g.
+  // for a call to vector::size().
+  std::vector
+  resolveDependentMember(const Type *T, DeclarationName Name,
+ llvm::function_ref Filter);
+
+  // Try to heuristically resolve the type of a possibly-dependent expression
+  // `E`.
+  const Type *resolveExprToType(const Expr *E);
+  std::vector resolveExprToDecls(const Expr *E);
+
+  // Helper function for HeuristicResolver::resolveDependentMember()
+  // which takes a possibly-dependent type `T` and heuristically
+  // resolves it to a CXXRecordDecl in which we can try name lookup.
+  CXXRecordDecl *resolveTypeToRecordDecl(const Type *T);
+
+  // This is a reimplementation of CXXRecordDecl::lookupDependentName()
+  // so that the implementation can call into other HeuristicResolver helpers.
+  // FIXME: Once HeuristicResolver is upstreamed to the clang libraries
+  // (https://github.com/clangd/clangd/discussions/1662),
+  // CXXRecordDecl::lookupDepenedentName() can be removed, and its call sites
+  // can be modified to benefit from the more comprehensive heuristics offered
+  // by HeuristicResolver instead.
+  std::vector
+  lookupDependentName(CXXRecordDecl *RD, DeclarationName Name,
+  llvm::function_ref Filter);
+  bool findOrdinaryMemberInDependentClasses(const CXXBaseSpecifier *Specifier,
+ 

[clang] [llvm] [HIP] change compress level (PR #83605)

2024-03-03 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/83605

>From f846e24d2ac287f6f9466615536c4f53f6d0e0ed Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Fri, 1 Mar 2024 13:16:45 -0500
Subject: [PATCH] [HIP] add --offload-compression-level= option

Added --offload-compression-level= option to clang and -compression-level=
option to clang-offload-bundler for controlling compression level.

Change default compression level to 20 for zstd for better compression rate.
---
 clang/include/clang/Driver/OffloadBundler.h   |  6 +-
 clang/include/clang/Driver/Options.td |  4 +
 clang/lib/Driver/OffloadBundler.cpp   | 90 +--
 clang/lib/Driver/ToolChains/Clang.cpp | 20 +++--
 clang/lib/Driver/ToolChains/Clang.h   |  2 +
 clang/lib/Driver/ToolChains/HIPUtility.cpp|  7 +-
 .../test/Driver/clang-offload-bundler-zlib.c  | 21 -
 .../test/Driver/clang-offload-bundler-zstd.c  | 19 +++-
 .../test/Driver/hip-offload-compress-zlib.hip |  7 +-
 .../test/Driver/hip-offload-compress-zstd.hip |  5 +-
 .../ClangOffloadBundler.cpp   |  5 ++
 llvm/include/llvm/Support/Compression.h   |  1 +
 12 files changed, 141 insertions(+), 46 deletions(-)

diff --git a/clang/include/clang/Driver/OffloadBundler.h 
b/clang/include/clang/Driver/OffloadBundler.h
index 84349abe185fa4..65d33bfbd2825f 100644
--- a/clang/include/clang/Driver/OffloadBundler.h
+++ b/clang/include/clang/Driver/OffloadBundler.h
@@ -17,6 +17,7 @@
 #ifndef LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
 #define LLVM_CLANG_DRIVER_OFFLOADBUNDLER_H
 
+#include "llvm/Support/Compression.h"
 #include "llvm/Support/Error.h"
 #include "llvm/TargetParser/Triple.h"
 #include 
@@ -36,6 +37,8 @@ class OffloadBundlerConfig {
   bool HipOpenmpCompatible = false;
   bool Compress = false;
   bool Verbose = false;
+  llvm::compression::Format CompressionFormat;
+  int CompressionLevel;
 
   unsigned BundleAlignment = 1;
   unsigned HostInputIndex = ~0u;
@@ -116,7 +119,8 @@ class CompressedOffloadBundle {
 
 public:
   static llvm::Expected>
-  compress(const llvm::MemoryBuffer &Input, bool Verbose = false);
+  compress(llvm::compression::Params P, const llvm::MemoryBuffer &Input,
+   bool Verbose = false);
   static llvm::Expected>
   decompress(const llvm::MemoryBuffer &Input, bool Verbose = false);
 };
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3e857f4e6faf87..a3cd818fed9bd9 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1264,6 +1264,10 @@ def fno_gpu_sanitize : Flag<["-"], "fno-gpu-sanitize">, 
Group;
 def offload_compress : Flag<["--"], "offload-compress">,
   HelpText<"Compress offload device binaries (HIP only)">;
 def no_offload_compress : Flag<["--"], "no-offload-compress">;
+
+def offload_compression_level_EQ : Joined<["--"], 
"offload-compression-level=">,
+  Flags<[HelpHidden]>,
+  HelpText<"Compression level for offload device binaries (HIP only)">;
 }
 
 // CUDA options
diff --git a/clang/lib/Driver/OffloadBundler.cpp 
b/clang/lib/Driver/OffloadBundler.cpp
index 99a34d25cfcd56..3629c610f5dc7d 100644
--- a/clang/lib/Driver/OffloadBundler.cpp
+++ b/clang/lib/Driver/OffloadBundler.cpp
@@ -906,6 +906,16 @@ CreateFileHandler(MemoryBuffer &FirstInput,
 }
 
 OffloadBundlerConfig::OffloadBundlerConfig() {
+  if (llvm::compression::zstd::isAvailable()) {
+CompressionFormat = llvm::compression::Format::Zstd;
+// Use a high zstd compress level by default for better size reduction.
+CompressionLevel = 20;
+  } else if (llvm::compression::zlib::isAvailable()) {
+CompressionFormat = llvm::compression::Format::Zlib;
+// Use default level for zlib since higher level does not have significant
+// improvement.
+CompressionLevel = llvm::compression::zlib::DefaultCompression;
+  }
   auto IgnoreEnvVarOpt =
   llvm::sys::Process::GetEnv("OFFLOAD_BUNDLER_IGNORE_ENV_VAR");
   if (IgnoreEnvVarOpt.has_value() && IgnoreEnvVarOpt.value() == "1")
@@ -919,11 +929,41 @@ OffloadBundlerConfig::OffloadBundlerConfig() {
   llvm::sys::Process::GetEnv("OFFLOAD_BUNDLER_COMPRESS");
   if (CompressEnvVarOpt.has_value())
 Compress = CompressEnvVarOpt.value() == "1";
+
+  auto CompressionLevelEnvVarOpt =
+  llvm::sys::Process::GetEnv("OFFLOAD_BUNDLER_COMPRESSION_LEVEL");
+  if (CompressionLevelEnvVarOpt.has_value()) {
+llvm::StringRef CompressionLevelStr = CompressionLevelEnvVarOpt.value();
+int Level;
+if (!CompressionLevelStr.getAsInteger(10, Level))
+  CompressionLevel = Level;
+else
+  llvm::errs()
+  << "Warning: Invalid value for OFFLOAD_BUNDLER_COMPRESSION_LEVEL: "
+  << CompressionLevelStr.str() << ". Ignoring it.\n";
+  }
+}
+
+// Utility function to format numbers with commas
+static std::string formatWithCommas(unsigned long long Value) {
+  std::string Num = std::to_string(Value);
+  int InsertPosition = Num.lengt

[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Chen Zheng via cfe-commits


@@ -58,3 +58,18 @@ entry:
   %8 = or i64 %6, %7
   ret i64 %8
 }
+
+define i64 @rldimi_intrinsic(i64 %a) {
+; CHECK-LABEL: rldimi_intrinsic:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:rldimi 3, 3, 8, 0
+; CHECK-NEXT:rldimi 3, 3, 16, 0
+; CHECK-NEXT:rldimi 3, 3, 32, 0
+; CHECK-NEXT:blr
+  %r1 = call i64 @llvm.ppc.rldimi(i64 %a, i64 %a, i32 8, i64 -256)
+  %r2 = call i64 @llvm.ppc.rldimi(i64 %r1, i64 %r1, i32 16, i64 -65536)
+  %r3 = call i64 @llvm.ppc.rldimi(i64 %r2, i64 %r2, i32 32, i64 -4294967296)
+  ret i64 %r3
+}
+
+declare i64 @llvm.ppc.rldimi(i64, i64, i32 immarg, i64 immarg)

chenzheng1030 wrote:

OK. Thanks. TIL : )

https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Qiu Chaofan via cfe-commits


@@ -1,61 +1,111 @@
-; All of these ands and shifts should be folded into rlwimi's
-; RUN: llc -verify-machineinstrs < %s -mtriple=ppc32-- -o %t
-; RUN: not grep and %t
-; RUN: not grep srawi %t
-; RUN: not grep srwi %t
-; RUN: not grep slwi %t
-; RUN: grep rlwinm %t | count 8
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64le-unknown-linux-gnu | 
FileCheck %s
 
 define i32 @test1(i32 %a) {
+; CHECK-LABEL: test1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 0, 4, 19
+; CHECK-NEXT:blr
 entry:
-   %tmp.1 = and i32 %a, 268431360  ;  [#uses=1]
-   ret i32 %tmp.1
+  %tmp.1 = and i32 %a, 268431360
+  ret i32 %tmp.1
 }
 
 define i32 @test2(i32 %a) {
+; CHECK-LABEL: test2:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rldicl 3, 3, 36, 24
+; CHECK-NEXT:rldicl 3, 3, 28, 32

ecnelises wrote:

Yes, I just meant `rlwinm` does not sign-ext higher 32 bits.

https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Chen Zheng via cfe-commits


@@ -1,61 +1,111 @@
-; All of these ands and shifts should be folded into rlwimi's
-; RUN: llc -verify-machineinstrs < %s -mtriple=ppc32-- -o %t
-; RUN: not grep and %t
-; RUN: not grep srawi %t
-; RUN: not grep srwi %t
-; RUN: not grep slwi %t
-; RUN: grep rlwinm %t | count 8
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64le-unknown-linux-gnu | 
FileCheck %s
 
 define i32 @test1(i32 %a) {
+; CHECK-LABEL: test1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 0, 4, 19
+; CHECK-NEXT:blr
 entry:
-   %tmp.1 = and i32 %a, 268431360  ;  [#uses=1]
-   ret i32 %tmp.1
+  %tmp.1 = and i32 %a, 268431360
+  ret i32 %tmp.1
 }
 
 define i32 @test2(i32 %a) {
+; CHECK-LABEL: test2:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rldicl 3, 3, 36, 24
+; CHECK-NEXT:rldicl 3, 3, 28, 32

chenzheng1030 wrote:

hmm, OK. The `rlwinm` does not match the 64-bit semantic here. Would you please 
just remove this case. It would be strange to keep it in the rlwinm file now.

Please don't treat rlwinm as a 32-bit instruction. It alters and well defined 
the high 32 bit of a GPR as well especially the MB/ME are wrapped.

https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Qiu Chaofan via cfe-commits


@@ -1,61 +1,111 @@
-; All of these ands and shifts should be folded into rlwimi's
-; RUN: llc -verify-machineinstrs < %s -mtriple=ppc32-- -o %t
-; RUN: not grep and %t
-; RUN: not grep srawi %t
-; RUN: not grep srwi %t
-; RUN: not grep slwi %t
-; RUN: grep rlwinm %t | count 8
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64le-unknown-linux-gnu | 
FileCheck %s
 
 define i32 @test1(i32 %a) {
+; CHECK-LABEL: test1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 0, 4, 19
+; CHECK-NEXT:blr
 entry:
-   %tmp.1 = and i32 %a, 268431360  ;  [#uses=1]
-   ret i32 %tmp.1
+  %tmp.1 = and i32 %a, 268431360
+  ret i32 %tmp.1
 }
 
 define i32 @test2(i32 %a) {
+; CHECK-LABEL: test2:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rldicl 3, 3, 36, 24
+; CHECK-NEXT:rldicl 3, 3, 28, 32

ecnelises wrote:

`rlwinm` is a 32-bit instruction, in 64-bit mode both the input arg and return 
values are sign-extended. `rldicl` here does more stuff including 
sign-extending it (so here we see no `extsw` exists)

https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Qiu Chaofan via cfe-commits


@@ -58,3 +58,18 @@ entry:
   %8 = or i64 %6, %7
   ret i64 %8
 }
+
+define i64 @rldimi_intrinsic(i64 %a) {
+; CHECK-LABEL: rldimi_intrinsic:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:rldimi 3, 3, 8, 0
+; CHECK-NEXT:rldimi 3, 3, 16, 0
+; CHECK-NEXT:rldimi 3, 3, 32, 0
+; CHECK-NEXT:blr
+  %r1 = call i64 @llvm.ppc.rldimi(i64 %a, i64 %a, i32 8, i64 -256)
+  %r2 = call i64 @llvm.ppc.rldimi(i64 %r1, i64 %r1, i32 16, i64 -65536)
+  %r3 = call i64 @llvm.ppc.rldimi(i64 %r2, i64 %r2, i32 32, i64 -4294967296)
+  ret i64 %r3
+}
+
+declare i64 @llvm.ppc.rldimi(i64, i64, i32 immarg, i64 immarg)

ecnelises wrote:

immarg specifies the argument is constant, like 
PowerPC/builtins-ppc-xlcompat-test.ll 

https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Chen Zheng via cfe-commits

chenzheng1030 wrote:

The failure in the buildkite should be unrelated. But would be better to double 
confirm.

https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Chen Zheng via cfe-commits


@@ -1,70 +1,117 @@
-; All of these ands and shifts should be folded into rlwimi's
-; RUN: llc -verify-machineinstrs < %s -mtriple=ppc32-- | not grep and
-; RUN: llc -verify-machineinstrs < %s -mtriple=ppc32-- | grep rlwimi | count 8
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64le-unknown-linux-gnu | 
FileCheck %s
 
 define i32 @test1(i32 %x, i32 %y) {
+; CHECK-LABEL: test1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwimi 4, 3, 16, 0, 15
+; CHECK-NEXT:mr 3, 4
+; CHECK-NEXT:blr
 entry:
-   %tmp.3 = shl i32 %x, 16 ;  [#uses=1]
-   %tmp.7 = and i32 %y, 65535  ;  [#uses=1]
-   %tmp.9 = or i32 %tmp.7, %tmp.3  ;  [#uses=1]
-   ret i32 %tmp.9
+  %tmp.3 = shl i32 %x, 16
+  %tmp.7 = and i32 %y, 65535
+  %tmp.9 = or i32 %tmp.7, %tmp.3
+  ret i32 %tmp.9
 }
 
 define i32 @test2(i32 %x, i32 %y) {
+; CHECK-LABEL: test2:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwimi 3, 4, 16, 0, 15
+; CHECK-NEXT:blr
 entry:
-   %tmp.7 = and i32 %x, 65535  ;  [#uses=1]
-   %tmp.3 = shl i32 %y, 16 ;  [#uses=1]
-   %tmp.9 = or i32 %tmp.7, %tmp.3  ;  [#uses=1]
-   ret i32 %tmp.9
+  %tmp.7 = and i32 %x, 65535
+  %tmp.3 = shl i32 %y, 16
+  %tmp.9 = or i32 %tmp.7, %tmp.3
+  ret i32 %tmp.9
 }
 
 define i32 @test3(i32 %x, i32 %y) {
+; CHECK-LABEL: test3:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwimi 4, 3, 16, 16, 31
+; CHECK-NEXT:mr 3, 4
+; CHECK-NEXT:blr
 entry:
-   %tmp.3 = lshr i32 %x, 16;  [#uses=1]
-   %tmp.6 = and i32 %y, -65536 ;  [#uses=1]
-   %tmp.7 = or i32 %tmp.6, %tmp.3  ;  [#uses=1]
-   ret i32 %tmp.7
+  %tmp.3 = lshr i32 %x, 16
+  %tmp.6 = and i32 %y, -65536
+  %tmp.7 = or i32 %tmp.6, %tmp.3
+  ret i32 %tmp.7
 }
 
 define i32 @test4(i32 %x, i32 %y) {
+; CHECK-LABEL: test4:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwimi 3, 4, 16, 16, 31
+; CHECK-NEXT:blr
 entry:
-   %tmp.6 = and i32 %x, -65536 ;  [#uses=1]
-   %tmp.3 = lshr i32 %y, 16;  [#uses=1]
-   %tmp.7 = or i32 %tmp.6, %tmp.3  ;  [#uses=1]
-   ret i32 %tmp.7
+  %tmp.6 = and i32 %x, -65536
+  %tmp.3 = lshr i32 %y, 16
+  %tmp.7 = or i32 %tmp.6, %tmp.3
+  ret i32 %tmp.7
 }
 
 define i32 @test5(i32 %x, i32 %y) {
+; CHECK-LABEL: test5:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwimi 4, 3, 1, 0, 15
+; CHECK-NEXT:mr 3, 4
+; CHECK-NEXT:blr
 entry:
-   %tmp.3 = shl i32 %x, 1  ;  [#uses=1]
-   %tmp.4 = and i32 %tmp.3, -65536 ;  [#uses=1]
-   %tmp.7 = and i32 %y, 65535  ;  [#uses=1]
-   %tmp.9 = or i32 %tmp.4, %tmp.7  ;  [#uses=1]
-   ret i32 %tmp.9
+  %tmp.3 = shl i32 %x, 1
+  %tmp.4 = and i32 %tmp.3, -65536
+  %tmp.7 = and i32 %y, 65535
+  %tmp.9 = or i32 %tmp.4, %tmp.7
+  ret i32 %tmp.9
 }
 
 define i32 @test6(i32 %x, i32 %y) {
+; CHECK-LABEL: test6:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwimi 3, 4, 1, 0, 15
+; CHECK-NEXT:blr
 entry:
-   %tmp.7 = and i32 %x, 65535  ;  [#uses=1]
-   %tmp.3 = shl i32 %y, 1  ;  [#uses=1]
-   %tmp.4 = and i32 %tmp.3, -65536 ;  [#uses=1]
-   %tmp.9 = or i32 %tmp.4, %tmp.7  ;  [#uses=1]
-   ret i32 %tmp.9
+  %tmp.7 = and i32 %x, 65535
+  %tmp.3 = shl i32 %y, 1
+  %tmp.4 = and i32 %tmp.3, -65536
+  %tmp.9 = or i32 %tmp.4, %tmp.7
+  ret i32 %tmp.9
 }
 
 define i32 @test7(i32 %x, i32 %y) {
+; CHECK-LABEL: test7:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:andis. 3, 3, 65535
+; CHECK-NEXT:rldimi 3, 4, 0, 48
+; CHECK-NEXT:blr
 entry:
-   %tmp.2 = and i32 %x, -65536 ;  [#uses=1]
-   %tmp.5 = and i32 %y, 65535  ;  [#uses=1]
-   %tmp.7 = or i32 %tmp.5, %tmp.2  ;  [#uses=1]
-   ret i32 %tmp.7
+  %tmp.2 = and i32 %x, -65536
+  %tmp.5 = and i32 %y, 65535
+  %tmp.7 = or i32 %tmp.5, %tmp.2
+  ret i32 %tmp.7
 }
 
 define i32 @test8(i32 %bar) {
+; CHECK-LABEL: test8:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwimi 3, 3, 1, 30, 30
+; CHECK-NEXT:blr
 entry:
-   %tmp.3 = shl i32 %bar, 1;  [#uses=1]
-   %tmp.4 = and i32 %tmp.3, 2  ;  [#uses=1]
-   %tmp.6 = and i32 %bar, -3   ;  [#uses=1]
-   %tmp.7 = or i32 %tmp.4, %tmp.6  ;  [#uses=1]
-   ret i32 %tmp.7
+  %tmp.3 = shl i32 %bar, 1
+  %tmp.4 = and i32 %tmp.3, 2
+  %tmp.6 = and i32 %bar, -3
+  %tmp.7 = or i32 %tmp.4, %tmp.6
+  ret i32 %tmp.7
 }
+
+define i32 @test9(i32 %a, i32 %b) {
+; CHECK-LABEL: test9:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwimi 3, 4, 8, 20, 26
+; CHECK-NEXT:blr
+entry:
+  %r = call i32 @llvm.ppc.rlwimi(i32 %a, i32 %b, i32 8, i32 4064)
+  ret i32 %r
+}
+
+declare i32 @llvm.ppc.rlwimi(i32, i32, i32 immarg, i32 i

[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Chen Zheng via cfe-commits


@@ -1,61 +1,111 @@
-; All of these ands and shifts should be folded into rlwimi's
-; RUN: llc -verify-machineinstrs < %s -mtriple=ppc32-- -o %t
-; RUN: not grep and %t
-; RUN: not grep srawi %t
-; RUN: not grep srwi %t
-; RUN: not grep slwi %t
-; RUN: grep rlwinm %t | count 8
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64le-unknown-linux-gnu | 
FileCheck %s
 
 define i32 @test1(i32 %a) {
+; CHECK-LABEL: test1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 0, 4, 19
+; CHECK-NEXT:blr
 entry:
-   %tmp.1 = and i32 %a, 268431360  ;  [#uses=1]
-   ret i32 %tmp.1
+  %tmp.1 = and i32 %a, 268431360
+  ret i32 %tmp.1
 }
 
 define i32 @test2(i32 %a) {
+; CHECK-LABEL: test2:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rldicl 3, 3, 36, 24
+; CHECK-NEXT:rldicl 3, 3, 28, 32

chenzheng1030 wrote:

After the triple change, now two `rldicl` are emitted instead of a single 
`rlwinm`. Would you please help to add a FIXME here? or create an issue in 
github? Thanks.

https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Chen Zheng via cfe-commits


@@ -1,61 +1,111 @@
-; All of these ands and shifts should be folded into rlwimi's
-; RUN: llc -verify-machineinstrs < %s -mtriple=ppc32-- -o %t
-; RUN: not grep and %t
-; RUN: not grep srawi %t
-; RUN: not grep srwi %t
-; RUN: not grep slwi %t
-; RUN: grep rlwinm %t | count 8
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 
UTC_ARGS: --version 4
+; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64le-unknown-linux-gnu | 
FileCheck %s
 
 define i32 @test1(i32 %a) {
+; CHECK-LABEL: test1:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 0, 4, 19
+; CHECK-NEXT:blr
 entry:
-   %tmp.1 = and i32 %a, 268431360  ;  [#uses=1]
-   ret i32 %tmp.1
+  %tmp.1 = and i32 %a, 268431360
+  ret i32 %tmp.1
 }
 
 define i32 @test2(i32 %a) {
+; CHECK-LABEL: test2:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rldicl 3, 3, 36, 24
+; CHECK-NEXT:rldicl 3, 3, 28, 32
+; CHECK-NEXT:blr
 entry:
-   %tmp.1 = and i32 %a, -268435441 ;  [#uses=1]
-   ret i32 %tmp.1
+  %tmp.1 = and i32 %a, -268435441
+  ret i32 %tmp.1
 }
 
 define i32 @test3(i32 %a) {
+; CHECK-LABEL: test3:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 24, 24, 31
+; CHECK-NEXT:blr
 entry:
-   %tmp.2 = ashr i32 %a, 8 ;  [#uses=1]
-   %tmp.3 = and i32 %tmp.2, 255;  [#uses=1]
-   ret i32 %tmp.3
+  %tmp.2 = ashr i32 %a, 8
+  %tmp.3 = and i32 %tmp.2, 255
+  ret i32 %tmp.3
 }
 
 define i32 @test4(i32 %a) {
+; CHECK-LABEL: test4:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 24, 24, 31
+; CHECK-NEXT:blr
 entry:
-   %tmp.3 = lshr i32 %a, 8 ;  [#uses=1]
-   %tmp.4 = and i32 %tmp.3, 255;  [#uses=1]
-   ret i32 %tmp.4
+  %tmp.3 = lshr i32 %a, 8
+  %tmp.4 = and i32 %tmp.3, 255
+  ret i32 %tmp.4
 }
 
 define i32 @test5(i32 %a) {
+; CHECK-LABEL: test5:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 8, 0, 8
+; CHECK-NEXT:blr
 entry:
-   %tmp.2 = shl i32 %a, 8  ;  [#uses=1]
-   %tmp.3 = and i32 %tmp.2, -8388608   ;  [#uses=1]
-   ret i32 %tmp.3
+  %tmp.2 = shl i32 %a, 8
+  %tmp.3 = and i32 %tmp.2, -8388608
+  ret i32 %tmp.3
 }
 
 define i32 @test6(i32 %a) {
+; CHECK-LABEL: test6:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 24, 24, 31
+; CHECK-NEXT:blr
 entry:
-   %tmp.1 = and i32 %a, 65280  ;  [#uses=1]
-   %tmp.2 = ashr i32 %tmp.1, 8 ;  [#uses=1]
-   ret i32 %tmp.2
+  %tmp.1 = and i32 %a, 65280
+  %tmp.2 = ashr i32 %tmp.1, 8
+  ret i32 %tmp.2
 }
 
 define i32 @test7(i32 %a) {
+; CHECK-LABEL: test7:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 24, 24, 31
+; CHECK-NEXT:blr
 entry:
-   %tmp.1 = and i32 %a, 65280  ;  [#uses=1]
-   %tmp.2 = lshr i32 %tmp.1, 8 ;  [#uses=1]
-   ret i32 %tmp.2
+  %tmp.1 = and i32 %a, 65280
+  %tmp.2 = lshr i32 %tmp.1, 8
+  ret i32 %tmp.2
 }
 
 define i32 @test8(i32 %a) {
+; CHECK-LABEL: test8:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 8, 0, 7
+; CHECK-NEXT:blr
 entry:
-   %tmp.1 = and i32 %a, 16711680   ;  [#uses=1]
-   %tmp.2 = shl i32 %tmp.1, 8  ;  [#uses=1]
-   ret i32 %tmp.2
+  %tmp.1 = and i32 %a, 16711680
+  %tmp.2 = shl i32 %tmp.1, 8
+  ret i32 %tmp.2
 }
+
+define i32 @test9(i32 %a, i32 %s) {
+; CHECK-LABEL: test9:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwnm 3, 3, 4, 23, 31
+; CHECK-NEXT:blr
+entry:
+  %r = call i32 @llvm.ppc.rlwnm(i32 %a, i32 %s, i32 511)
+  ret i32 %r
+}
+
+define i32 @test10(i32 %a) {
+; CHECK-LABEL: test10:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:rlwinm 3, 3, 31, 23, 31
+; CHECK-NEXT:blr
+entry:
+  %r = call i32 @llvm.ppc.rlwnm(i32 %a, i32 31, i32 511)
+  ret i32 %r
+}
+
+declare i32 @llvm.ppc.rlwnm(i32, i32, i32 immarg)

chenzheng1030 wrote:

nit: ditto


https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 edited 
https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 approved this pull request.

LGTM except two comments in the case change. One is a nit and the other one 
should be other issue unrelated to this patch.

Thanks for implementing this.

https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [PowerPC] Add intrinsics for rldimi/rlwimi/rlwnm (PR #82968)

2024-03-03 Thread Chen Zheng via cfe-commits


@@ -58,3 +58,18 @@ entry:
   %8 = or i64 %6, %7
   ret i64 %8
 }
+
+define i64 @rldimi_intrinsic(i64 %a) {
+; CHECK-LABEL: rldimi_intrinsic:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:rldimi 3, 3, 8, 0
+; CHECK-NEXT:rldimi 3, 3, 16, 0
+; CHECK-NEXT:rldimi 3, 3, 32, 0
+; CHECK-NEXT:blr
+  %r1 = call i64 @llvm.ppc.rldimi(i64 %a, i64 %a, i32 8, i64 -256)
+  %r2 = call i64 @llvm.ppc.rldimi(i64 %r1, i64 %r1, i32 16, i64 -65536)
+  %r3 = call i64 @llvm.ppc.rldimi(i64 %r2, i64 %r2, i32 32, i64 -4294967296)
+  ret i64 %r3
+}
+
+declare i64 @llvm.ppc.rldimi(i64, i64, i32 immarg, i64 immarg)

chenzheng1030 wrote:

nit: missing % before immarg? Why not just remove them?


https://github.com/llvm/llvm-project/pull/82968
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/83709

>From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 2 Mar 2024 22:08:29 -0800
Subject: [PATCH 1/4] [clang-format] Handle common C++ non-keyword types as
 such

Fixes #83400.
---
 clang/lib/Format/FormatToken.cpp  | 16 --
 clang/lib/Format/FormatToken.h|  4 +--
 clang/lib/Format/QualifierAlignmentFixer.cpp  | 25 +---
 clang/lib/Format/QualifierAlignmentFixer.h|  5 ++--
 clang/lib/Format/TokenAnnotator.cpp   | 29 ++-
 clang/lib/Format/UnwrappedLineParser.cpp  | 12 
 clang/unittests/Format/TokenAnnotatorTest.cpp |  6 
 7 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 56a7b2d6387765..02952bd20acf9a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
+bool FormatToken::isSimpleTypeSpecifier(bool IsCpp) const {
   switch (Tok.getKind()) {
   case tok::kw_short:
   case tok::kw_long:
@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);
   default:
 return false;
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+bool FormatToken::isTypeOrIdentifier(bool IsCpp) const {
+  return isSimpleTypeSpecifier(IsCpp) ||
+ Tok.isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 31245495041960..2bc136c51d23f1 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -674,9 +674,9 @@ struct FormatToken {
   }
 
   /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
+  [[nodiscard]] bool isSimpleTypeSpecifier(bool IsCpp) const;
 
-  [[nodiscard]] bool isTypeOrIdentifier() const;
+  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 0c63d330b5aed4..834ae115908856 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -268,11 +268,13 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isSimpleTypeSpecifier(IsCpp)) {
 // The case `const decltype(foo)` -> `const decltype(foo)`
 // The case `const typeof(foo)` -> `const typeof(foo)`
 // The case `const _Atomic(foo)` -> `const _Atomic(foo)`
@@ -280,8 +282,10 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   return Tok;
 
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
-while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment()))
+while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
+ IsCpp)) {
   LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
+}
 
 rotateTokens(SourceMgr, Fixes, Tok, LastSimpleTypeSpecifier,
  /*Left=*/false);
@@ -291,7 +295,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   // The case  `unsigned short const` -> `unsigned short const`
   // The case:
   // `unsigned short volatile const` -> `unsigned short const volatile`
-  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier()) {
+  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier(IsCpp)) {
 if (LastQual != Tok)
   rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false);
 return Tok;
@@ -4

[clang] 938ddbf - [Driver, Darwin] Simplify libc++ include path after #80527. NFC

2024-03-03 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-03-03T18:30:17-08:00
New Revision: 938ddbf349276c6ded6ef2d65432f41c512a86c6

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

LOG: [Driver,Darwin] Simplify libc++ include path after #80527. NFC

My #80527 mentioned that `InstalledDir` was weird in the
-canonical-prefixes mode. #70817 was a workaround to find the libc++
include path for a symlinked clang. After #80527, `InstalledDir` was
identical to `Dir` and was subsequently removed, the code change #70817
can be reverted.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 48b612ec40f61d..c7682c7f1d3379 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2514,25 +2514,19 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
   switch (GetCXXStdlibType(DriverArgs)) {
   case ToolChain::CST_Libcxx: {
 // On Darwin, libc++ can be installed in one of the following places:
-// 1. Alongside the compiler in /include/c++/v1
-// 2. Alongside the compiler in /../include/c++/v1
-// 3. In a SDK (or a custom sysroot) in /usr/include/c++/v1
+// 1. Alongside the compiler in /../include/c++/v1
+// 2. In a SDK (or a custom sysroot) in /usr/include/c++/v1
 //
 // The precedence of paths is as listed above, i.e. we take the first path
 // that exists. Note that we never include libc++ twice -- we take the 
first
 // path that exists and don't send the other paths to CC1 (otherwise
 // include_next could break).
-//
-// Also note that in most cases, (1) and (2) are exactly the same path.
-// Those two paths will 
diff er only when the `clang` program being run
-// is actually a symlink to the real executable.
 
 // Check for (1)
 // Get from '/bin' to '/include/c++/v1'.
 // Note that InstallBin can be relative, so we use '..' instead of
 // parent_path.
-llvm::SmallString<128> InstallBin =
-llvm::StringRef(getDriver().Dir); // /bin
+llvm::SmallString<128> InstallBin(getDriver().Dir); // /bin
 llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
 if (getVFS().exists(InstallBin)) {
   addSystemInclude(DriverArgs, CC1Args, InstallBin);
@@ -2542,20 +2536,7 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
<< "\"\n";
 }
 
-// (2) Check for the folder where the executable is located, if 
diff erent.
-if (getDriver().Dir != getDriver().Dir) {
-  InstallBin = llvm::StringRef(getDriver().Dir);
-  llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
-  if (getVFS().exists(InstallBin)) {
-addSystemInclude(DriverArgs, CC1Args, InstallBin);
-return;
-  } else if (DriverArgs.hasArg(options::OPT_v)) {
-llvm::errs() << "ignoring nonexistent directory \"" << InstallBin
- << "\"\n";
-  }
-}
-
-// Otherwise, check for (3)
+// Otherwise, check for (2)
 llvm::SmallString<128> SysrootUsr = Sysroot;
 llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
 if (getVFS().exists(SysrootUsr)) {



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


[clang] 2b5cd8b - [Driver] Remove InstallDir and getInstalledDir. NFC

2024-03-03 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2024-03-03T18:10:46-08:00
New Revision: 2b5cd8be3af43e5aa5b76b6aeb1edd3141b803ca

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

LOG: [Driver] Remove InstallDir and getInstalledDir. NFC

Follow-up to #80527.

Added: 


Modified: 
clang/include/clang/Driver/Driver.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/AIX.cpp
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/DragonFly.cpp
clang/lib/Driver/ToolChains/Fuchsia.cpp
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/ToolChains/Linux.cpp
clang/lib/Driver/ToolChains/MSVC.cpp
clang/lib/Driver/ToolChains/MinGW.cpp
clang/lib/Driver/ToolChains/MipsLinux.cpp
clang/lib/Driver/ToolChains/OHOS.cpp
clang/lib/Driver/ToolChains/WebAssembly.cpp
clang/lib/Driver/ToolChains/ZOS.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index f145ddc05bd9d6..bcf8c1295f2ddf 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -160,9 +160,6 @@ class Driver {
   /// Target and driver mode components extracted from clang executable name.
   ParsedClangName ClangNameParts;
 
-  /// TODO: Remove this in favor of Dir.
-  std::string InstalledDir;
-
   /// The path to the compiler resource directory.
   std::string ResourceDir;
 
@@ -429,8 +426,6 @@ class Driver {
 
   /// Get the path to where the clang executable was installed.
   const char *getInstalledDir() const {
-if (!InstalledDir.empty())
-  return InstalledDir.c_str();
 return Dir.c_str();
   }
 

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index d7fbb127fed2dd..b8ec0791dc51f7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -209,11 +209,10 @@ Driver::Driver(StringRef ClangExecutable, StringRef 
TargetTriple,
 
   Name = std::string(llvm::sys::path::filename(ClangExecutable));
   Dir = std::string(llvm::sys::path::parent_path(ClangExecutable));
-  InstalledDir = Dir; // Provide a sensible default installed dir.
 
   if ((!SysRoot.empty()) && llvm::sys::path::is_relative(SysRoot)) {
 // Prepend InstalledDir if SysRoot is relative
-SmallString<128> P(InstalledDir);
+SmallString<128> P(Dir);
 llvm::sys::path::append(P, SysRoot);
 SysRoot = std::string(P);
   }
@@ -1337,7 +1336,7 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   if (const Arg *A = Args.getLastArg(options::OPT_target))
 TargetTriple = A->getValue();
   if (const Arg *A = Args.getLastArg(options::OPT_ccc_install_dir))
-Dir = InstalledDir = A->getValue();
+Dir = Dir = A->getValue();
   for (const Arg *A : Args.filtered(options::OPT_B)) {
 A->claim();
 PrefixDirs.push_back(A->getValue(0));
@@ -2000,7 +1999,7 @@ void Driver::PrintVersion(const Compilation &C, 
raw_ostream &OS) const {
   OS << '\n';
 
   // Print out the install directory.
-  OS << "InstalledDir: " << InstalledDir << '\n';
+  OS << "InstalledDir: " << Dir << '\n';
 
   // If configuration files were used, print their paths.
   for (auto ConfigFile : ConfigFiles)

diff  --git a/clang/lib/Driver/ToolChains/AIX.cpp 
b/clang/lib/Driver/ToolChains/AIX.cpp
index e6126ff62db3c9..3c7049a99982d0 100644
--- a/clang/lib/Driver/ToolChains/AIX.cpp
+++ b/clang/lib/Driver/ToolChains/AIX.cpp
@@ -342,9 +342,7 @@ void aix::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 /// AIX - AIX tool chain which can call as(1) and ld(1) directly.
 AIX::AIX(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
 : ToolChain(D, Triple, Args) {
-  getProgramPaths().push_back(getDriver().getInstalledDir());
-  if (getDriver().getInstalledDir() != getDriver().Dir)
-getProgramPaths().push_back(getDriver().Dir);
+  getProgramPaths().push_back(getDriver().Dir);
 
   ParseInlineAsmUsingAsmParser = Args.hasFlag(
   options::OPT_fintegrated_as, options::OPT_fno_integrated_as, true);

diff  --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 6fcbcffd6f0d67..e122379e860e20 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -209,7 +209,7 @@ RocmInstallationDetector::getInstallationPathCandidates() {
   }
 
   // Try to find relative to the compiler binary.
-  const char *InstallDir = D.getInstalledDir();
+  StringRef InstallDir = D.Dir;
 
   // Check both a normal Unix prefix position of the clang binary, as well as
   // the Windows-esque layout the ROCm packages use with the host architecture

[clang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #75711)

2024-03-03 Thread Max Winkler via cfe-commits

MaxEW707 wrote:

Just want to say thanks for everyone taking the time to review the PR and 
providing feedback :).
Looking forward to using this in the next release of clang-cl.

> I'm a bit worried that we don't have any test coverage for this file to begin 
> with, so it's a bit hard to validate that the changes are correct, but we're 
> early enough in a release cycle that I think we'll get feedback with plenty 
> of time to address unintentional fallout.

I'll look into adding unit tests next week in a separate PR. If not it will be 
closer towards the end of March due to personal things.
If any issues pop up feel free to @ me. I don't intend to commit and dash :).

> The changes should come with a release note in clang/docs/ReleaseNotes.rst so 
> that users know about the compile time performance improvements.

Done. Feel free to reword the release notes as necessary. I believe I landed on 
something that is informative but succinct. 

https://github.com/llvm/llvm-project/pull/75711
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector &getLeafConstructs(Directive 
D);\n";

kparzysz wrote:

That's about input parameters (because then we don't restrict what objects can 
be passed, i.e. converted to an ArrayRef).  For return values it doesn't 
matter, at least from the point of view of interface flexibility.  The static 
constructor issue you pointed out will need this though.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Add bugprone-suspicious-stringview-data-usage check (PR #83716)

2024-03-03 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/83716
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -435,6 +450,213 @@ static void GenerateIsAllowedClause(const 
DirectiveLanguage &DirLang,
   OS << "}\n"; // End of function isAllowedClauseForDirective
 }
 
+// Generate the getLeafConstructs function implementation.
+static void GenerateGetLeafConstructs(const DirectiveLanguage &DirLang,
+  raw_ostream &OS) {
+  auto getQualifiedName = [&](StringRef Formatted) -> std::string {
+return (llvm::Twine("llvm::") + DirLang.getCppNamespace() +
+"::Directive::" + DirLang.getDirectivePrefix() + Formatted)
+.str();
+  };
+
+  // For each list of leafs, generate a static local object, then
+  // return a reference to that object for a given directive, e.g.
+  //
+  //   static ListTy leafConstructs_A_B = { A, B };

kparzysz wrote:

Sure, will do.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits

https://github.com/alexey-bataev requested changes to this pull request.


https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -435,6 +450,213 @@ static void GenerateIsAllowedClause(const 
DirectiveLanguage &DirLang,
   OS << "}\n"; // End of function isAllowedClauseForDirective
 }
 
+// Generate the getLeafConstructs function implementation.
+static void GenerateGetLeafConstructs(const DirectiveLanguage &DirLang,
+  raw_ostream &OS) {
+  auto getQualifiedName = [&](StringRef Formatted) -> std::string {
+return (llvm::Twine("llvm::") + DirLang.getCppNamespace() +
+"::Directive::" + DirLang.getDirectivePrefix() + Formatted)
+.str();
+  };
+
+  // For each list of leafs, generate a static local object, then
+  // return a reference to that object for a given directive, e.g.
+  //
+  //   static ListTy leafConstructs_A_B = { A, B };

alexey-bataev wrote:

Looks like this approach breaks 
https://llvm.org/docs/CodingStandards.html#do-not-use-static-constructors. 
Better to avoid static SmallVectors (IIUC you're creating static SmallVector 
vars here) and use POD instead to avoid use of static constructors/destructors.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Let `bugprone-use-after-move` also handle calls to `std::forward` (PR #82673)

2024-03-03 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/82673
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [X86] Add Support for X86 TLSDESC Relocations (PR #83136)

2024-03-03 Thread Phoebe Wang via cfe-commits

phoebewang wrote:

Ping~

https://github.com/llvm/llvm-project/pull/83136
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector &getLeafConstructs(Directive 
D);\n";

alexey-bataev wrote:

Read the documentation 
https://llvm.org/docs/ProgrammersManual.html#llvm-adt-arrayref-h

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector &getLeafConstructs(Directive 
D);\n";

kparzysz wrote:

I'm expecting you to be more professional in your replies.  I'm simply trying 
to understand your motivation here.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-03 Thread via cfe-commits

AtariDreams wrote:

> > @JOE1994 Thoughts on this?
> 
> 
> 
> I'm not an ideal reviewer for this as I'm unfamiliar with ObjC side of Clang,
> 
> but I'll come back to leave a review and to help merge this if this doesn't 
> get merged by the end of today :)

Alright. Thank you so much!

https://github.com/llvm/llvm-project/pull/81335
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector &getLeafConstructs(Directive 
D);\n";

alexey-bataev wrote:

No, it is not.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector &getLeafConstructs(Directive 
D);\n";

kparzysz wrote:

The ArrayRef will be the temporary object.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector &getLeafConstructs(Directive 
D);\n";

alexey-bataev wrote:

No, it won't. ArrayRef is not an owning container, so it does not create a copy.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -665,60 +617,45 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto Leafs = getLeafConstructs(DKind);

kparzysz wrote:

Done

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/5] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_pa

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector &getLeafConstructs(Directive 
D);\n";

kparzysz wrote:

I don't think this is a good idea.  Returning a reference is pretty much free, 
Returning an ArrayRef will always create a temporary object.  You can always 
use ArrayRef in the caller, if that's what's desired there.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -231,6 +244,8 @@ static void EmitDirectivesDecl(RecordKeeper &Records, 
raw_ostream &OS) {
   OS << "bool isAllowedClauseForDirective(Directive D, "
  << "Clause C, unsigned Version);\n";
   OS << "\n";
+  OS << "const llvm::SmallVector &getLeafConstructs(Directive 
D);\n";

alexey-bataev wrote:

```suggestion
  OS << "ArrayRef getLeafConstructs(Directive D);\n";
```


https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -665,60 +617,45 @@ bool 
clang::isOpenMPTargetDataManagementDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPNestingTeamsDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_teams || DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_teams)
+return true;
+  auto Leafs = getLeafConstructs(DKind);

alexey-bataev wrote:

Expand auto here and in other places (ArrayRef)

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Alexey Bataev via cfe-commits


@@ -341,5 +356,19 @@ def TDL_DirA : Directive<"dira"> {
 // IMPL-NEXT:}
 // IMPL-NEXT:llvm_unreachable("Invalid Tdl Directive kind");
 // IMPL-NEXT:  }
+// IMPL-NEXT:  const llvm::SmallVector 
&llvm::tdl::getLeafConstructs(llvm::tdl::Directive Dir) {

alexey-bataev wrote:

```suggestion
// IMPL-NEXT:  ArrayRef 
llvm::tdl::getLeafConstructs(llvm::tdl::Directive Dir) {
```


https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/83625

>From b62919c2ce24feb3c75a5bbecce3d6b6ee8e5b7e Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Tue, 16 Jan 2024 16:40:47 -0600
Subject: [PATCH 1/4] [Frontend] Add leaf constructs and association to
 OpenMP/ACC directives

Add members "leafs" and "association" to .td describing OpenMP/ACC
directives: "leafs" are the leaf constructs for composite/combined
constructs, and "association" is the source language construct to
which the directive applies (e.g. loop, block, etc.)

The tblgen-generated output then contains two additional functions
- getLeafConstructs(D), and
- getDirectiveAssociation(D)
plus "enum class Association", all in namespaces "llvm::omp" and
"llvm::acc".

Note: getLeafConstructs returns an empty sequence for a construct
that is itself a leaf construct.

Use the new functions to simplify a few OpenMP-related functions
in clang.
---
 clang/lib/Basic/OpenMPKinds.cpp   | 130 +++---
 .../llvm/Frontend/Directive/DirectiveBase.td  |  36 +++
 llvm/include/llvm/Frontend/OpenACC/ACC.td |  27 +-
 llvm/include/llvm/Frontend/OpenMP/OMP.td  | 172 +++--
 llvm/include/llvm/TableGen/DirectiveEmitter.h |  10 +
 llvm/utils/TableGen/DirectiveEmitter.cpp  | 236 +-
 6 files changed, 489 insertions(+), 122 deletions(-)

diff --git a/clang/lib/Basic/OpenMPKinds.cpp b/clang/lib/Basic/OpenMPKinds.cpp
index 6c31b0824eb8a4..dd1a096d178111 100644
--- a/clang/lib/Basic/OpenMPKinds.cpp
+++ b/clang/lib/Basic/OpenMPKinds.cpp
@@ -574,31 +574,7 @@ const char 
*clang::getOpenMPSimpleClauseTypeName(OpenMPClauseKind Kind,
 }
 
 bool clang::isOpenMPLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_simd || DKind == OMPD_for || DKind == OMPD_for_simd ||
- DKind == OMPD_parallel_for || DKind == OMPD_parallel_for_simd ||
- DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop || DKind == OMPD_distribute ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_distribute_simd ||
- DKind == OMPD_target_parallel_for_simd || DKind == OMPD_target_simd ||
- DKind == OMPD_teams_distribute ||
- DKind == OMPD_teams_distribute_simd ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_simd || DKind == OMPD_tile ||
- DKind == OMPD_unroll || DKind == OMPD_loop ||
- DKind == OMPD_teams_loop || DKind == OMPD_target_teams_loop ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop;
+  return getDirectiveAssociation(DKind) == Association::Loop;
 }
 
 bool clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_pa

[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz edited 
https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Frontend] Add leaf constructs and association to OpenMP/ACC directives (PR #83625)

2024-03-03 Thread Krzysztof Parzyszek via cfe-commits


@@ -619,44 +595,22 @@ bool 
clang::isOpenMPWorksharingDirective(OpenMPDirectiveKind DKind) {
 }
 
 bool clang::isOpenMPTaskLoopDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_taskloop || DKind == OMPD_taskloop_simd ||
- DKind == OMPD_master_taskloop || DKind == OMPD_master_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_masked_taskloop || DKind == OMPD_masked_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_master_taskloop_simd;
+  return DKind == OMPD_taskloop ||
+ llvm::is_contained(getLeafConstructs(DKind), OMPD_taskloop);
 }
 
 bool clang::isOpenMPParallelDirective(OpenMPDirectiveKind DKind) {
-  return DKind == OMPD_parallel || DKind == OMPD_parallel_for ||
- DKind == OMPD_parallel_for_simd || DKind == OMPD_parallel_sections ||
- DKind == OMPD_target_parallel || DKind == OMPD_target_parallel_for ||
- DKind == OMPD_distribute_parallel_for ||
- DKind == OMPD_distribute_parallel_for_simd ||
- DKind == OMPD_target_parallel_for_simd ||
- DKind == OMPD_teams_distribute_parallel_for ||
- DKind == OMPD_teams_distribute_parallel_for_simd ||
- DKind == OMPD_target_teams_distribute_parallel_for ||
- DKind == OMPD_target_teams_distribute_parallel_for_simd ||
- DKind == OMPD_parallel_master || DKind == OMPD_parallel_masked ||
- DKind == OMPD_parallel_master_taskloop ||
- DKind == OMPD_parallel_master_taskloop_simd ||
- DKind == OMPD_parallel_masked_taskloop ||
- DKind == OMPD_parallel_masked_taskloop_simd ||
- DKind == OMPD_parallel_loop || DKind == OMPD_target_parallel_loop ||
- DKind == OMPD_teams_loop;
+  if (DKind == OMPD_parallel_workshare)
+return false;

kparzysz wrote:

I removed the check.  Formally, it does fall under the "parallel" family of 
directives, so I think we shouldn't exclude it on the basis that it will never 
show up.

https://github.com/llvm/llvm-project/pull/83625
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216

>From 31bb7cee2eb783a242734f3778269efcdb460a4c Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD, Fuchsia and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Fuchsia.cpp |  5 -
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 clang/test/Driver/freebsd.c |  4 
 clang/test/Driver/fuchsia.c |  5 +
 clang/test/Driver/haiku.c   |  5 +
 clang/test/Driver/netbsd.c  |  7 +++
 clang/test/Driver/openbsd.c |  8 
 10 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 9d698f77583950..c5757ddebb0f3e 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple &T = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 14b838500becce..237d1554d4970d 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -119,8 +119,11 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Args.MakeArgString(Dyld));
   }
 
-  if (ToolChain.getArch() == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index ca7faa68765abf..30464e2229e65b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 645d0311641f34..0eec8fddabd5db 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+ 

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/83709

>From 91d6e4c6e0ae2e1d79edf496df22978a4e1f3e1a Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sat, 2 Mar 2024 22:08:29 -0800
Subject: [PATCH 1/3] [clang-format] Handle common C++ non-keyword types as
 such

Fixes #83400.
---
 clang/lib/Format/FormatToken.cpp  | 16 --
 clang/lib/Format/FormatToken.h|  4 +--
 clang/lib/Format/QualifierAlignmentFixer.cpp  | 25 +---
 clang/lib/Format/QualifierAlignmentFixer.h|  5 ++--
 clang/lib/Format/TokenAnnotator.cpp   | 29 ++-
 clang/lib/Format/UnwrappedLineParser.cpp  | 12 
 clang/unittests/Format/TokenAnnotatorTest.cpp |  6 
 7 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 56a7b2d6387765..02952bd20acf9a 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.
-bool FormatToken::isSimpleTypeSpecifier() const {
+bool FormatToken::isSimpleTypeSpecifier(bool IsCpp) const {
   switch (Tok.getKind()) {
   case tok::kw_short:
   case tok::kw_long:
@@ -66,13 +72,17 @@ bool FormatToken::isSimpleTypeSpecifier() const {
   case tok::kw_decltype:
   case tok::kw__Atomic:
 return true;
+  case tok::identifier:
+return IsCpp && std::binary_search(CppNonKeywordTypes.begin(),
+   CppNonKeywordTypes.end(), TokenText);
   default:
 return false;
   }
 }
 
-bool FormatToken::isTypeOrIdentifier() const {
-  return isSimpleTypeSpecifier() || Tok.isOneOf(tok::kw_auto, tok::identifier);
+bool FormatToken::isTypeOrIdentifier(bool IsCpp) const {
+  return isSimpleTypeSpecifier(IsCpp) ||
+ Tok.isOneOf(tok::kw_auto, tok::identifier);
 }
 
 bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 31245495041960..2bc136c51d23f1 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -674,9 +674,9 @@ struct FormatToken {
   }
 
   /// Determine whether the token is a simple-type-specifier.
-  [[nodiscard]] bool isSimpleTypeSpecifier() const;
+  [[nodiscard]] bool isSimpleTypeSpecifier(bool IsCpp) const;
 
-  [[nodiscard]] bool isTypeOrIdentifier() const;
+  [[nodiscard]] bool isTypeOrIdentifier(bool IsCpp) const;
 
   bool isObjCAccessSpecifier() const {
 return is(tok::at) && Next &&
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 0c63d330b5aed4..834ae115908856 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -268,11 +268,13 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   if (isPossibleMacro(TypeToken))
 return Tok;
 
+  const bool IsCpp = Style.isCpp();
+
   // The case `const long long int volatile` -> `long long int const volatile`
   // The case `long const long int volatile` -> `long long int const volatile`
   // The case `long long volatile int const` -> `long long int const volatile`
   // The case `const long long volatile int` -> `long long int const volatile`
-  if (TypeToken->isSimpleTypeSpecifier()) {
+  if (TypeToken->isSimpleTypeSpecifier(IsCpp)) {
 // The case `const decltype(foo)` -> `const decltype(foo)`
 // The case `const typeof(foo)` -> `const typeof(foo)`
 // The case `const _Atomic(foo)` -> `const _Atomic(foo)`
@@ -280,8 +282,10 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   return Tok;
 
 const FormatToken *LastSimpleTypeSpecifier = TypeToken;
-while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment()))
+while (isQualifierOrType(LastSimpleTypeSpecifier->getNextNonComment(),
+ IsCpp)) {
   LastSimpleTypeSpecifier = LastSimpleTypeSpecifier->getNextNonComment();
+}
 
 rotateTokens(SourceMgr, Fixes, Tok, LastSimpleTypeSpecifier,
  /*Left=*/false);
@@ -291,7 +295,7 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
   // The case  `unsigned short const` -> `unsigned short const`
   // The case:
   // `unsigned short volatile const` -> `unsigned short const volatile`
-  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier()) {
+  if (PreviousCheck && PreviousCheck->isSimpleTypeSpecifier(IsCpp)) {
 if (LastQual != Tok)
   rotateTokens(SourceMgr, Fixes, Tok, LastQual, /*Left=*/false);
 return Tok;
@@ -4

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216

>From 6c68cdaef71eacbad4fc2f6b81d2845c08b124fd Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD, Fuchsia and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Fuchsia.cpp |  5 -
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 clang/test/Driver/freebsd.c |  3 +++
 clang/test/Driver/fuchsia.c |  4 
 clang/test/Driver/haiku.c   |  4 
 clang/test/Driver/netbsd.c  |  6 ++
 clang/test/Driver/openbsd.c |  5 ++---
 10 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 9d698f77583950..c5757ddebb0f3e 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple &T = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 14b838500becce..237d1554d4970d 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -119,8 +119,11 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Args.MakeArgString(Dyld));
   }
 
-  if (ToolChain.getArch() == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index ca7faa68765abf..30464e2229e65b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 645d0311641f34..0eec8fddabd5db 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
  

[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits

brad0 wrote:

I fixed up the tesets.

https://github.com/llvm/llvm-project/pull/83216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits

https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/83216

>From 35aee78eda1f3e7ac9e217982227c0769eda5ae1 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Tue, 27 Feb 2024 21:07:09 -0500
Subject: [PATCH] [Driver][RISCV] Forward --no-relax option to linker for
 RISC-V on *BSD, Fuchsia and Haiku

Based on https://github.com/llvm/llvm-project/pull/76432
---
 clang/lib/Driver/ToolChains/FreeBSD.cpp | 11 ---
 clang/lib/Driver/ToolChains/Fuchsia.cpp |  5 -
 clang/lib/Driver/ToolChains/Haiku.cpp   |  7 +--
 clang/lib/Driver/ToolChains/NetBSD.cpp  |  5 -
 clang/lib/Driver/ToolChains/OpenBSD.cpp |  6 +-
 clang/test/Driver/freebsd.c |  3 +++
 clang/test/Driver/fuchsia.c |  4 
 clang/test/Driver/haiku.c   |  4 
 clang/test/Driver/netbsd.c  |  6 ++
 clang/test/Driver/openbsd.c |  5 ++---
 10 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 9d698f77583950..c5757ddebb0f3e 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -133,6 +133,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const llvm::Triple::ArchType Arch = ToolChain.getArch();
   const bool IsPIE =
   !Args.hasArg(options::OPT_shared) &&
@@ -165,8 +166,7 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back("-dynamic-linker");
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
-const llvm::Triple &T = ToolChain.getTriple();
-if (Arch == llvm::Triple::arm || T.isX86())
+if (Arch == llvm::Triple::arm || Triple.isX86())
   CmdArgs.push_back("--hash-style=both");
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -212,12 +212,17 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");
-CmdArgs.push_back("-X");
 break;
   default:
 break;
   }
 
+  if (Triple.isRISCV64()) {
+CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_G)) {
 if (ToolChain.getTriple().isMIPS()) {
   StringRef v = A->getValue();
diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp 
b/clang/lib/Driver/ToolChains/Fuchsia.cpp
index 14b838500becce..237d1554d4970d 100644
--- a/clang/lib/Driver/ToolChains/Fuchsia.cpp
+++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp
@@ -119,8 +119,11 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Args.MakeArgString(Dyld));
   }
 
-  if (ToolChain.getArch() == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   CmdArgs.push_back("-o");
   CmdArgs.push_back(Output.getFilename());
diff --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index ca7faa68765abf..30464e2229e65b 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -25,7 +25,7 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
const char *LinkingOutput) const {
   const auto &ToolChain = static_cast(getToolChain());
   const Driver &D = ToolChain.getDriver();
-  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const llvm::Triple &Triple = ToolChain.getTriple();
   const bool Static = Args.hasArg(options::OPT_static);
   const bool Shared = Args.hasArg(options::OPT_shared);
   ArgStringList CmdArgs;
@@ -61,8 +61,11 @@ void haiku::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!Shared)
 CmdArgs.push_back("--no-undefined");
 
-  if (Arch == llvm::Triple::riscv64)
+  if (Triple.isRISCV64()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
   assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
diff --git a/clang/lib/Driver/ToolChains/NetBSD.cpp 
b/clang/lib/Driver/ToolChains/NetBSD.cpp
index 645d0311641f34..0eec8fddabd5db 100644
--- a/clang/lib/Driver/ToolChains/NetBSD.cpp
+++ b/clang/lib/Driver/ToolChains/NetBSD.cpp
@@ -240,8 +240,11 @@ void netbsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 break;
   }
 
-  if (Triple.isRISCV())
+  if (Triple.isRISCV()) {
 CmdArgs.push_back("-X");
+if (Args.hasArg(options::OPT_mno_relax))
+  CmdArgs.push_back("--no-relax");
+  }
 
  

[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.

owenca wrote:

See 
[here](https://github.com/llvm/llvm-project/pull/83533#issuecomment-1974198544).
 After this patch,I will add another parameter and call 
`Token::isSimpleTypeSpecifier()` (which was moved out of `Sema` in #80101) 
directly. That's the right time to fix (i.e. remove) the comment.

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver][RISCV] Forward --no-relax option to linker for RISC-V on *BS… (PR #83216)

2024-03-03 Thread Brad Smith via cfe-commits


@@ -203,3 +203,12 @@
 // RELOCATABLE-NOT: "-l
 // RELOCATABLE-NOT: crt{{[^./\\]+}}.o
 
+// Check that the -X flag is passed to the linker on riscv64

brad0 wrote:

When I was putting the diff together I was questioning whether I should combine 
the two into one instance.

https://github.com/llvm/llvm-project/pull/83216
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

owenca wrote:

> I find it extremely unlikely that anyone would use `intN_t` as anything other 
> than a type; I think your concerns about regressions are unfounded.

"Extremely unlikely" doesn't mean impossible.

I actually hesitated on whether to include `intptr_t`/`uintprt_t` because they 
are marked as optional. I can include them though.

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Add diagnostics for out-of-bounds vector access (PR #76569)

2024-03-03 Thread via cfe-commits

https://github.com/implicitfield closed 
https://github.com/llvm/llvm-project/pull/76569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits

owenca wrote:

> But looking for a parenthesized single identifier addresses all of the 
> examples in the issue.

I don't think it would work, but you are welcome to submit a patch to prove me 
wrong. 🙂 

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits

owenca wrote:

> > This patch does not only fix formatting of C-casting to a C++ standard 
> > type. It correctly identifies (most of) such types and might have fixed 
> > other kinds of bugs.
> 
> Sure, this patch seems like a good change. But it does not fix #83400.

It does fix the example given. For other diffs involving user-defined types, 
the user need to use the TypeNames option. (If that doesn't work, a separate 
issue should be filed.)

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits

https://github.com/zygoloid edited 
https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

zygoloid wrote:

On codesearch.isocpp.org, `(intptr_t)` is more common than `(int8_t)` and 
`(int16_t)`, and similar to `(int32_t)`. But why should this general function 
that's used in various places in clang-format care about how often the type is 
cast with a C-style cast? That doesn't make sense to me.

I find it extremely unlikely that anyone would use `intN_t` as anything other 
than a type; I think your concerns about regressions are unfounded. In 
contrast, there are 518 hits for `(intptr_t)&` in isocpp codesearch, which 
seems pretty logical to me because casts to `(intptr_t)` will be casts from 
pointers.

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

owenca wrote:

I considered to include all [fixed width integer 
types](https://en.cppreference.com/w/cpp/types/integer) but decided to include 
only the common ones to avoid possible regressions. (I also looked at [fixed 
width floating-point 
types](https://en.cppreference.com/w/cpp/types/floating-point) and think we 
should wait until C++23 is commonly used.)

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits

zygoloid wrote:

> This patch does not only fix formatting of C-casting to a C++ standard type. 
> It correctly identifies (most of) such types and might have fixed other kinds 
> of bugs.

Sure, this patch seems like a good change. But it does not fix #83400.

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.

zygoloid wrote:

Before this patch, the two functions were intended to do the same thing, but 
have apparently diverged. After this patch they are not intended to do the same 
thing. The FIXME is wrong, can you fix it please?

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",

owenca wrote:

Good point about `byte`. I will remove it from the list.

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-03 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

> @JOE1994 Thoughts on this?

I'm not an ideal reviewer for this as I'm unfamiliar with ObjC side of Clang,
but I'll come back to leave a review and to help merge this if this doesn't get 
merged by the end of the day :)

https://github.com/llvm/llvm-project/pull/81335
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread Youngsuk Kim via cfe-commits

JOE1994 wrote:

> Isn't this warning a duplicate of what is already here?

The diganostic warning is not emitted when `clang` is run without the 
`-analyze` flag.

https://github.com/llvm/llvm-project/pull/83741
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread via cfe-commits

https://github.com/AtariDreams commented:

Isn't this warning a duplicate of what is already here?

https://github.com/llvm/llvm-project/pull/83741
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 0c90e8837a9e5f27985ccaf85120083db9e1b43e 
fc0cb9c44ec7945f1a88420675b667167908e07c -- clang/lib/Sema/SemaInit.cpp 
clang/test/Analysis/stack-addr-ps.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 93b125382b..1d81330b7e 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7742,7 +7742,7 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
 break;
   }
 
-  // FIXME: Visit the left-hand side of an -> or ->*.
+// FIXME: Visit the left-hand side of an -> or ->*.
 
   default:
 break;

``




https://github.com/llvm/llvm-project/pull/83741
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits

owenca wrote:

> > > Another possibility to consider for the original bug: 
> > > `(single_identifier)` is almost certainly a cast, not redundant 
> > > parentheses, unless `single_identifier` names a macro argument. So I 
> > > wonder if that would be a better heuristic to use to fix the regression.
> > 
> > 
> > I don’t think that would work as`(identifier)` can be a number of 
> > constructs depending on the context. It can be part of a function/macro 
> > call, function declaration, macro definition, C++ cast, C cast, `sizeof` 
> > operand, etc.
> 
> OK, but the context is deciding whether `(identifier)&x` or `(identifier)*x` 
> is a binary operator or a cast. Given no other information, the fact that 
> it's a single identifier seems like a very strong signal that it's a cast.
> 
> I don't think this PR fixes #83400 -- handling a small handful of common 
> types won't address the same issue for the much larger class of cases where 
> the type name is not one of these types. Eg, in #83400 itself the examples 
> included:
> 
> ```diff
> - static _FORCE_INLINE_ m_type get(const Variant *v) { return 
> (m_type)*VariantInternal::get_int(v); }\
> + static _FORCE_INLINE_ m_type get(const Variant *v) { return 
> (m_type) * VariantInternal::get_int(v); }  \
> ```
> 
> But looking for a parenthesized single identifier addresses all of the 
> examples in the issue.

This patch does not only fix formatting of C-casting to a C++ standard type. It 
correctly identifies (most of) such types and might have fixed other kinds of 
bugs. For casting to a user-defined type, the TypeNames option can be used.

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC] Check entire chain of superclasses to see if class layout is statically known (PR #81335)

2024-03-03 Thread via cfe-commits

AtariDreams wrote:

@JOE1994 Thoughts on this?

https://github.com/llvm/llvm-project/pull/81335
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Youngsuk Kim (JOE1994)


Changes

Emit a warning if pointer/reference to compound literal is returned from a 
function.

In C, compound literals in block scope are lvalues that have automatic storage 
duration. In C++, compound literals in block scope are temporaries.

In either case, returning a pointer/reference to a compound literal can cause a 
use-after-free bug.

Fixes #8678 

---
Full diff: https://github.com/llvm/llvm-project/pull/83741.diff


3 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+1-1) 
- (modified) clang/lib/Sema/SemaInit.cpp (+12) 
- (modified) clang/test/Analysis/stack-addr-ps.c (+2-2) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91105d4231f06a..f5c88b8ae5aade 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9898,7 +9898,7 @@ def err_lifetimebound_ctor_dtor : Error<
 // CHECK: returning address/reference of stack memory
 def warn_ret_stack_addr_ref : Warning<
   "%select{address of|reference to}0 stack memory associated with "
-  "%select{local variable|parameter}2 %1 returned">,
+  "%select{local variable|parameter|compound literal}2 %1 returned">,
   InGroup;
 def warn_ret_local_temp_addr_ref : Warning<
   "returning %select{address of|reference to}0 local temporary object">,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 0fd458837163e5..93b125382b164f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7734,6 +7734,14 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
 break;
   }
 
+  case Stmt::CompoundLiteralExprClass: {
+if (auto *CLE = dyn_cast(Init)) {
+  if (!CLE->isFileScope())
+Visit(Path, Local(CLE), RK);
+}
+break;
+  }
+
   // FIXME: Visit the left-hand side of an -> or ->*.
 
   default:
@@ -8289,6 +8297,10 @@ void Sema::checkInitializerLifetime(const 
InitializedEntity &Entity,
 if (LK == LK_StmtExprResult)
   return false;
 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
+  } else if (auto *CLE = dyn_cast(L)) {
+Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
+<< Entity.getType()->isReferenceType() << CLE->getInitializer() << 
2
+<< DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
  << Entity.getType()->isReferenceType() << DiagRange;
diff --git a/clang/test/Analysis/stack-addr-ps.c 
b/clang/test/Analysis/stack-addr-ps.c
index 26e1cc58350cab..e469396e1bb22a 100644
--- a/clang/test/Analysis/stack-addr-ps.c
+++ b/clang/test/Analysis/stack-addr-ps.c
@@ -20,13 +20,13 @@ int* f3(int x, int *y) {
 
 void* compound_literal(int x, int y) {
   if (x)
-return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}}
+return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}} expected-warning{{address of stack 
memory}}
 
   int* array[] = {};
   struct s { int z; double y; int w; };
   
   if (y)
-return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}}
+return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}} expected-warning{{address of stack memory}}
 
   
   void* p = &((struct s){ 42, 0.4, x ? 42 : 0 });

``




https://github.com/llvm/llvm-project/pull/83741
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Sema] Warn on return of pointer/reference to compound literal (PR #83741)

2024-03-03 Thread Youngsuk Kim via cfe-commits

https://github.com/JOE1994 created 
https://github.com/llvm/llvm-project/pull/83741

Emit a warning if pointer/reference to compound literal is returned from a 
function.

In C, compound literals in block scope are lvalues that have automatic storage 
duration. In C++, compound literals in block scope are temporaries.

In either case, returning a pointer/reference to a compound literal can cause a 
use-after-free bug.

Fixes #8678 

>From fc0cb9c44ec7945f1a88420675b667167908e07c Mon Sep 17 00:00:00 2001
From: JOE1994 
Date: Sun, 3 Mar 2024 12:38:49 -0500
Subject: [PATCH] [clang][Sema] Warn on return of pointer/reference to compound
 literal

Emit a warning if pointer/reference to compound literal is returned from a 
function.

In C, compound literals in block scope are lvalues that have automatic storage 
duration.
In C++, compound literals in block scope are temporaries.

In either case, returning a pointer/reference to a compound literal
can cause a use-after-free bug.
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 +-
 clang/lib/Sema/SemaInit.cpp  | 12 
 clang/test/Analysis/stack-addr-ps.c  |  4 ++--
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91105d4231f06a..f5c88b8ae5aade 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9898,7 +9898,7 @@ def err_lifetimebound_ctor_dtor : Error<
 // CHECK: returning address/reference of stack memory
 def warn_ret_stack_addr_ref : Warning<
   "%select{address of|reference to}0 stack memory associated with "
-  "%select{local variable|parameter}2 %1 returned">,
+  "%select{local variable|parameter|compound literal}2 %1 returned">,
   InGroup;
 def warn_ret_local_temp_addr_ref : Warning<
   "returning %select{address of|reference to}0 local temporary object">,
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 0fd458837163e5..93b125382b164f 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -7734,6 +7734,14 @@ static void 
visitLocalsRetainedByReferenceBinding(IndirectLocalPath &Path,
 break;
   }
 
+  case Stmt::CompoundLiteralExprClass: {
+if (auto *CLE = dyn_cast(Init)) {
+  if (!CLE->isFileScope())
+Visit(Path, Local(CLE), RK);
+}
+break;
+  }
+
   // FIXME: Visit the left-hand side of an -> or ->*.
 
   default:
@@ -8289,6 +8297,10 @@ void Sema::checkInitializerLifetime(const 
InitializedEntity &Entity,
 if (LK == LK_StmtExprResult)
   return false;
 Diag(DiagLoc, diag::warn_ret_addr_label) << DiagRange;
+  } else if (auto *CLE = dyn_cast(L)) {
+Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
+<< Entity.getType()->isReferenceType() << CLE->getInitializer() << 
2
+<< DiagRange;
   } else {
 Diag(DiagLoc, diag::warn_ret_local_temp_addr_ref)
  << Entity.getType()->isReferenceType() << DiagRange;
diff --git a/clang/test/Analysis/stack-addr-ps.c 
b/clang/test/Analysis/stack-addr-ps.c
index 26e1cc58350cab..e469396e1bb22a 100644
--- a/clang/test/Analysis/stack-addr-ps.c
+++ b/clang/test/Analysis/stack-addr-ps.c
@@ -20,13 +20,13 @@ int* f3(int x, int *y) {
 
 void* compound_literal(int x, int y) {
   if (x)
-return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}}
+return &(unsigned short){((unsigned short)0x22EF)}; // 
expected-warning{{Address of stack memory}} expected-warning{{address of stack 
memory}}
 
   int* array[] = {};
   struct s { int z; double y; int w; };
   
   if (y)
-return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}}
+return &((struct s){ 2, 0.4, 5 * 8 }); // expected-warning{{Address of 
stack memory}} expected-warning{{address of stack memory}}
 
   
   void* p = &((struct s){ 42, 0.4, x ? 42 : 0 });

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


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",
+};
+
 // FIXME: This is copy&pasted from Sema. Put it in a common place and remove
 // duplication.

owenca wrote:

That was the case before this patch though.

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits


@@ -34,9 +34,15 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
+// Sorted common C++ non-keyword types.
+static SmallVector CppNonKeywordTypes = {
+"byte",   "int16_t",  "int32_t",  "int64_t",  "int8_t",
+"size_t", "uint16_t", "uint32_t", "uint64_t", "uint8_t",

owenca wrote:

I was aware of that. By “common” I mean common C-casted. We definitely don’t 
want to include POSIX-specific types as we have the TypeNames option for that. 
Also, we don’t want to cater to C-specific constructs if it might regress C++ 
code.

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Richard Smith via cfe-commits

zygoloid wrote:

> > Another possibility to consider for the original bug: `(single_identifier)` 
> > is almost certainly a cast, not redundant parentheses, unless 
> > `single_identifier` names a macro argument. So I wonder if that would be a 
> > better heuristic to use to fix the regression.
> 
> I don’t think that would work as`(identifier)` can be a number of constructs 
> depending on the context. It can be part of a function/macro call, function 
> declaration, macro definition, C++ cast, C cast, `sizeof` operand, etc.

OK, but the context is deciding whether `(identifier)&x` or `(identifier)*x` is 
a binary operator or a cast. Given no other information, the fact that it's a 
single identifier seems like a very strong signal that it's a cast.

I don't think this PR fixes #83400 -- handling a small handful of common types 
won't address the same issue for the much larger class of cases where the type 
name is not one of these types. Eg, in #83400 itself the examples included:

```diff
-   static _FORCE_INLINE_ m_type get(const Variant *v) { return 
(m_type)*VariantInternal::get_int(v); }\
+   static _FORCE_INLINE_ m_type get(const Variant *v) { return 
(m_type) * VariantInternal::get_int(v); }  \
```

But looking for a parenthesized single identifier addresses all of the examples 
in the issue.

https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Handle common C++ non-keyword types as such (PR #83709)

2024-03-03 Thread Owen Pan via cfe-commits

owenca wrote:

> Another possibility to consider for the original bug: `(single_identifier)` 
> is almost certainly a cast, not redundant parentheses, unless 
> `single_identifier` names a macro argument. So I wonder if that would be a 
> better heuristic to use to fix the regression.

I don’t think that would work as`(identifier)` can be a number of constructs 
depending on the context. It can be part of a function/macro call, function 
declaration, macro definition, C++ cast, C cast, `sizeof` operand, etc. 


https://github.com/llvm/llvm-project/pull/83709
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >