[clang-tools-extra] 72390c5 - [clang-tidy][misleading-indentation]ignore false-positives for line started with empty macro (#75061)

2023-12-27 Thread via cfe-commits

Author: Congcong Cai
Date: 2023-12-27T16:16:57+08:00
New Revision: 72390c5c56c5f6a2c2d55231d96f03471eee8cb4

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

LOG: [clang-tidy][misleading-indentation]ignore false-positives for line 
started with empty macro (#75061)

Fixes: #71767

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
index 2c011f5c0e6904..e32f79589a059b 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "MisleadingIndentationCheck.h"
+#include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -51,8 +52,20 @@ void MisleadingIndentationCheck::danglingElseCheck(const 
SourceManager &SM,
 diag(ElseLoc, "
diff erent indentation for 'if' and corresponding 'else'");
 }
 
-void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
-const CompoundStmt *CStmt) 
{
+static bool isAtStartOfLineIncludingEmptyMacro(SourceLocation NextLoc,
+   const SourceManager &SM,
+   const LangOptions &LangOpts) {
+  const SourceLocation BeforeLoc =
+  utils::lexer::getPreviousTokenAndStart(NextLoc, SM, LangOpts).second;
+  if (BeforeLoc.isInvalid())
+return false;
+  return SM.getExpansionLineNumber(BeforeLoc) !=
+ SM.getExpansionLineNumber(NextLoc);
+}
+
+void MisleadingIndentationCheck::missingBracesCheck(
+const SourceManager &SM, const CompoundStmt *CStmt,
+const LangOptions &LangOpts) {
   const static StringRef StmtNames[] = {"if", "for", "while"};
   for (unsigned int I = 0; I < CStmt->size() - 1; I++) {
 const Stmt *CurrentStmt = CStmt->body_begin()[I];
@@ -92,6 +105,8 @@ void MisleadingIndentationCheck::missingBracesCheck(const 
SourceManager &SM,
 
 if (NextLoc.isInvalid() || NextLoc.isMacroID())
   continue;
+if (!isAtStartOfLineIncludingEmptyMacro(NextLoc, SM, LangOpts))
+  continue;
 
 if (SM.getExpansionColumnNumber(InnerLoc) ==
 SM.getExpansionColumnNumber(NextLoc)) {
@@ -117,7 +132,8 @@ void MisleadingIndentationCheck::check(const 
MatchFinder::MatchResult &Result) {
 danglingElseCheck(*Result.SourceManager, Result.Context, If);
 
   if (const auto *CStmt = Result.Nodes.getNodeAs("compound"))
-missingBracesCheck(*Result.SourceManager, CStmt);
+missingBracesCheck(*Result.SourceManager, CStmt,
+   Result.Context->getLangOpts());
 }
 
 } // namespace clang::tidy::readability

diff  --git 
a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h 
b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
index c336abbc7c4a91..9c92fc1e18b6f3 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
@@ -32,7 +32,8 @@ class MisleadingIndentationCheck : public ClangTidyCheck {
 private:
   void danglingElseCheck(const SourceManager &SM, ASTContext *Context,
  const IfStmt *If);
-  void missingBracesCheck(const SourceManager &SM, const CompoundStmt *CStmt);
+  void missingBracesCheck(const SourceManager &SM, const CompoundStmt *CStmt,
+  const LangOptions &LangOpts);
 };
 
 } // namespace clang::tidy::readability

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fe7f40d95fe6ca..571808a51596a8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -465,6 +465,10 @@ Changes in existing checks
   `AllowPointerConditions` options. It also now provides more consistent
   suggestions when parentheses are added to the return value.
 
+- Improved :doc:`readability-misleading-indentation
+  ` check to ignore
+  false-positives for line started with empty macro.
+
 - Improved :doc:`readability-non-const-parameter
   ` check to ignore
   false-positives in initializer list of record.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
 

[clang-tools-extra] [clang-tidy][misleading-indentation]ignore false-positives for line started with empty macro (PR #75061)

2023-12-27 Thread Congcong Cai via cfe-commits

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


[clang] 2df0fa4 - [clang] Use StringRef::consume_front (NFC)

2023-12-27 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-12-27T00:19:12-08:00
New Revision: 2df0fa41a3aa416d84f9f22490f329bf851d447e

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

LOG: [clang] Use StringRef::consume_front (NFC)

Added: 


Modified: 
clang/lib/Basic/Warnings.cpp
clang/lib/Driver/ToolChains/Arch/X86.cpp

Removed: 




diff  --git a/clang/lib/Basic/Warnings.cpp b/clang/lib/Basic/Warnings.cpp
index bab1af4f03b67b..92954cab6fb040 100644
--- a/clang/lib/Basic/Warnings.cpp
+++ b/clang/lib/Basic/Warnings.cpp
@@ -96,11 +96,7 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
 
   // Check to see if this warning starts with "no-", if so, this is a
   // negative form of the option.
-  bool isPositive = true;
-  if (Opt.starts_with("no-")) {
-isPositive = false;
-Opt = Opt.substr(3);
-  }
+  bool isPositive = !Opt.consume_front("no-");
 
   // Figure out how this option affects the warning.  If -Wfoo, map the
   // diagnostic to a warning, if -Wno-foo, map it to ignore.

diff  --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp 
b/clang/lib/Driver/ToolChains/Arch/X86.cpp
index fef0522aaf45b8..53e26a9f8e229e 100644
--- a/clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -237,9 +237,7 @@ void x86::getX86TargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
 assert(Name.starts_with("m") && "Invalid feature name.");
 Name = Name.substr(1);
 
-bool IsNegative = Name.starts_with("no-");
-if (IsNegative)
-  Name = Name.substr(3);
+bool IsNegative = Name.consume_front("no-");
 
 #ifndef NDEBUG
 assert(Name.starts_with("avx10.") && "Invalid AVX10 feature name.");



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


[llvm] [clang] [RFC][RISCV] Support RISC-V Profiles in -march option (PR #76357)

2023-12-27 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/76357

>From 965c1c682d16a3f47c563a301c89e3717bf4d1c5 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH] [RFC][RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.

We may need to pass it to backend so that we can emit an ELF attr
proposed by
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/409.
---
 clang/test/Driver/riscv-profiles.c | 105 +
 llvm/lib/Support/RISCVISAInfo.cpp  |  43 ++
 llvm/lib/Target/RISCV/RISCV.td |   6 ++
 llvm/lib/Target/RISCV/RISCVProfiles.td |  70 +
 llvm/lib/Target/RISCV/RISCVSubtarget.h |  14 
 5 files changed, 238 insertions(+)
 create mode 100644 clang/test/Driver/riscv-profiles.c
 create mode 100644 llvm/lib/Target/RISCV/RISCVProfiles.td

diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..7f54d0d885c7d7
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,105 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-cpu" "generic-rv64"
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+// RVI20U32: "-target-abi" "ilp32"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-cpu" "generic-rv64"
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+// RVI20U64: "-target-abi" "lp64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-cpu" "generic-rv64"
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-cpu" "generic-rv64"
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-cpu" "generic-rv64"
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zfhmin" 
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+// RVA22U64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-cpu" "generic-rv64"
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+zicsr"
+// RVA22S64: "-target-feature" "+zifencei"
+// RVA22S64: "-target-feature" "+zihintpause"
+// RVA22S64: "-target-feature" "+zfhmin" 
+// RVA22S64: "-target-feature" "+zba"
+// RVA22S64: "-target-feature" "+zbb"
+// RVA22S64: "-target-feature" "+zbs"
+// RVA22S64: "-target-feature" "+zkt"
+// RVA22S64: "-target-feature" "+svinval"
+// RVA22S64: "-target-feature" "+svpbmt"
+// RVA22S64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64_zfa | FileCheck 
-check-prefix=PROFILE-WITH-ADDITIONAL %s
+// PROFILE-WITH-ADDITIONAL: "-target-cpu" "generic-rv64"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+m"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+a"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+f"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+d"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+c"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zicbom"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+z

[clang] [clang][ASTImporter][StructuralEquivalence] improve StructuralEquivalence on recordType (PR #76226)

2023-12-27 Thread via cfe-commits

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


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


[clang] [Clang][RISCV] Forward --no-relax option to linker for RISC-V (PR #76432)

2023-12-27 Thread Andreu Carminati via cfe-commits

https://github.com/andcarminati created 
https://github.com/llvm/llvm-project/pull/76432

In the case of -mno-relax option. Otherwise, we cannot prevent relaxation if we 
split compilation and linking using Clang driver.

One can consider the following use case:

clang [...] -c -o myobject.o (just compile)
clang [...] myobject.o -o myobject.elf -mno-relax (linking)

In this case, myobject.elf will be relaxed, the -mno-relax will be silently 
ignored.

>From 13648eaf3becc5650924c3399fb1dc1ecb9fa7c7 Mon Sep 17 00:00:00 2001
From: Andreu Carminati 
Date: Wed, 27 Dec 2023 09:47:54 +0100
Subject: [PATCH] [Clang][RISCV] Forward --no-relax option to linker for RISC-V

In the case of -mno-relax option. Otherwise, we cannot prevent relaxation
if we split compilation and linking using Clang driver.

One can consider the following use case:

clang [...] -c -o myobject.o (just compile)
clang [...] myobject.o -o myobject.elf -mno-relax (linking)

In this case, myobject.elf will be relaxed, the -mno-relax will be silently 
ignored.
---
 clang/lib/Driver/ToolChains/BareMetal.cpp  |  3 +++
 clang/lib/Driver/ToolChains/RISCVToolchain.cpp |  3 +++
 clang/test/Driver/baremetal.cpp| 12 
 clang/test/Driver/riscv32-toolchain.c  | 16 
 clang/test/Driver/riscv64-toolchain.c  | 16 
 5 files changed, 50 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 42c8336e626c7b..007a24f2b81ae7 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -443,6 +443,9 @@ void baremetal::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   CmdArgs.push_back("-Bstatic");
 
+  if (TC.getTriple().isRISCV() && Args.hasArg(options::OPT_mno_relax))
+CmdArgs.push_back("--no-relax");
+
   if (Triple.isARM() || Triple.isThumb()) {
 bool IsBigEndian = arm::isARMBigEndian(Triple, Args);
 if (IsBigEndian)
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 7e6abd14442878..0be7d1a8899495 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -156,6 +156,9 @@ void RISCV::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
+  if (Args.hasArg(options::OPT_mno_relax))
+CmdArgs.push_back("--no-relax");
+
   bool IsRV64 = ToolChain.getArch() == llvm::Triple::riscv64;
   CmdArgs.push_back("-m");
   if (IsRV64) {
diff --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index c04f4506a0994d..7511d7d1adb4dd 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -460,3 +460,15 @@
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARCH %s
 // CHECK-CLANGRT-ARCH: "-lclang_rt.builtins-armv6m"
 // CHECK-CLANGRT-ARCH-NOT: "-lclang_rt.builtins"
+
+// Check that "--no-relax" is forwarded to the linker for RISC-V.
+// RUN: %clang %s -### 2>&1 --target=riscv64-unknown-elf -nostdinc -mno-relax \
+// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf \
+// RUN:   | FileCheck --check-prefix=CHECK-RV64-NORELAX %s
+// CHECK-RV64-NORELAX: "--no-relax"
+
+// Check that "--no-relax" is not forwarded to the linker for RISC-V.
+// RUN: %clang %s -### 2>&1 --target=riscv64-unknown-elf -nostdinc \
+// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf \
+// RUN:   | FileCheck --check-prefix=CHECK-RV64-RELAX %s
+// CHECK-RV64-RELAX-NOT: "--no-relax"
\ No newline at end of file
diff --git a/clang/test/Driver/riscv32-toolchain.c 
b/clang/test/Driver/riscv32-toolchain.c
index 63690c946ca0bc..701da05da9189d 100644
--- a/clang/test/Driver/riscv32-toolchain.c
+++ b/clang/test/Driver/riscv32-toolchain.c
@@ -215,6 +215,22 @@
 
 // RUN: %clang --target=riscv32 %s -emit-llvm -S -o - | FileCheck %s
 
+// Check that "--no-relax" is forwarded to the linker for RISC-V 
(RISCVToolchain.cpp).
+// RUN: env "PATH=" %clang %s -### 2>&1 -mno-relax \
+// RUN:   --target=riscv32-unknown-elf --rtlib=platform --unwindlib=platform 
--sysroot= \
+// RUN:   -march=rv32imac -mabi=lp32\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-RV32-NORELAX %s
+// CHECK-RV32-NORELAX: "--no-relax"
+
+// Check that "--no-relax" is not forwarded to the linker for RISC-V 
(RISCVToolchain.cpp).
+// RUN:env "PATH=" %clang %s -### 2>&1 \
+// RUN:   --target=riscv32-unknown-elf --rtlib=platform --unwindlib=platform 
--sysroot= \
+// RUN:   -march=rv32imac -mabi=lp32\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-RV32-RELAX %s
+// CHECK-RV32-RELAX-NOT: "--no-relax"
+
 typedef __builtin_va_list va_list;
 typedef __SIZE_TYPE__ size_t;
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
diff --git

[clang] [Clang][RISCV] Forward --no-relax option to linker for RISC-V (PR #76432)

2023-12-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Andreu Carminati (andcarminati)


Changes

In the case of -mno-relax option. Otherwise, we cannot prevent relaxation if we 
split compilation and linking using Clang driver.

One can consider the following use case:

clang [...] -c -o myobject.o (just compile)
clang [...] myobject.o -o myobject.elf -mno-relax (linking)

In this case, myobject.elf will be relaxed, the -mno-relax will be silently 
ignored.

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


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+3) 
- (modified) clang/lib/Driver/ToolChains/RISCVToolchain.cpp (+3) 
- (modified) clang/test/Driver/baremetal.cpp (+12) 
- (modified) clang/test/Driver/riscv32-toolchain.c (+16) 
- (modified) clang/test/Driver/riscv64-toolchain.c (+16) 


``diff
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 42c8336e626c7b..007a24f2b81ae7 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -443,6 +443,9 @@ void baremetal::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   CmdArgs.push_back("-Bstatic");
 
+  if (TC.getTriple().isRISCV() && Args.hasArg(options::OPT_mno_relax))
+CmdArgs.push_back("--no-relax");
+
   if (Triple.isARM() || Triple.isThumb()) {
 bool IsBigEndian = arm::isARMBigEndian(Triple, Args);
 if (IsBigEndian)
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 7e6abd14442878..0be7d1a8899495 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -156,6 +156,9 @@ void RISCV::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
+  if (Args.hasArg(options::OPT_mno_relax))
+CmdArgs.push_back("--no-relax");
+
   bool IsRV64 = ToolChain.getArch() == llvm::Triple::riscv64;
   CmdArgs.push_back("-m");
   if (IsRV64) {
diff --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index c04f4506a0994d..7511d7d1adb4dd 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -460,3 +460,15 @@
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARCH %s
 // CHECK-CLANGRT-ARCH: "-lclang_rt.builtins-armv6m"
 // CHECK-CLANGRT-ARCH-NOT: "-lclang_rt.builtins"
+
+// Check that "--no-relax" is forwarded to the linker for RISC-V.
+// RUN: %clang %s -### 2>&1 --target=riscv64-unknown-elf -nostdinc -mno-relax \
+// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf \
+// RUN:   | FileCheck --check-prefix=CHECK-RV64-NORELAX %s
+// CHECK-RV64-NORELAX: "--no-relax"
+
+// Check that "--no-relax" is not forwarded to the linker for RISC-V.
+// RUN: %clang %s -### 2>&1 --target=riscv64-unknown-elf -nostdinc \
+// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf \
+// RUN:   | FileCheck --check-prefix=CHECK-RV64-RELAX %s
+// CHECK-RV64-RELAX-NOT: "--no-relax"
\ No newline at end of file
diff --git a/clang/test/Driver/riscv32-toolchain.c 
b/clang/test/Driver/riscv32-toolchain.c
index 63690c946ca0bc..701da05da9189d 100644
--- a/clang/test/Driver/riscv32-toolchain.c
+++ b/clang/test/Driver/riscv32-toolchain.c
@@ -215,6 +215,22 @@
 
 // RUN: %clang --target=riscv32 %s -emit-llvm -S -o - | FileCheck %s
 
+// Check that "--no-relax" is forwarded to the linker for RISC-V 
(RISCVToolchain.cpp).
+// RUN: env "PATH=" %clang %s -### 2>&1 -mno-relax \
+// RUN:   --target=riscv32-unknown-elf --rtlib=platform --unwindlib=platform 
--sysroot= \
+// RUN:   -march=rv32imac -mabi=lp32\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-RV32-NORELAX %s
+// CHECK-RV32-NORELAX: "--no-relax"
+
+// Check that "--no-relax" is not forwarded to the linker for RISC-V 
(RISCVToolchain.cpp).
+// RUN:env "PATH=" %clang %s -### 2>&1 \
+// RUN:   --target=riscv32-unknown-elf --rtlib=platform --unwindlib=platform 
--sysroot= \
+// RUN:   -march=rv32imac -mabi=lp32\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-RV32-RELAX %s
+// CHECK-RV32-RELAX-NOT: "--no-relax"
+
 typedef __builtin_va_list va_list;
 typedef __SIZE_TYPE__ size_t;
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
diff --git a/clang/test/Driver/riscv64-toolchain.c 
b/clang/test/Driver/riscv64-toolchain.c
index f177bff33dd4d7..da07c57d8e1fc4 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -171,6 +171,22 @@
 
 // RUN: %clang --target=riscv64 %s -emit-llvm -S -o - | FileCheck %s
 
+// Check that "--no-relax" is forwarded to the linker for RISC-V 
(RISCVToolchain.cpp).
+// RUN: env "PATH=" %clang %s -### 2>&1 -mno-relax \
+// RUN:   --target=riscv64-unknown-elf --r

[clang] [Clang][RISCV] Forward --no-relax option to linker for RISC-V (PR #76432)

2023-12-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Andreu Carminati (andcarminati)


Changes

In the case of -mno-relax option. Otherwise, we cannot prevent relaxation if we 
split compilation and linking using Clang driver.

One can consider the following use case:

clang [...] -c -o myobject.o (just compile)
clang [...] myobject.o -o myobject.elf -mno-relax (linking)

In this case, myobject.elf will be relaxed, the -mno-relax will be silently 
ignored.

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


5 Files Affected:

- (modified) clang/lib/Driver/ToolChains/BareMetal.cpp (+3) 
- (modified) clang/lib/Driver/ToolChains/RISCVToolchain.cpp (+3) 
- (modified) clang/test/Driver/baremetal.cpp (+12) 
- (modified) clang/test/Driver/riscv32-toolchain.c (+16) 
- (modified) clang/test/Driver/riscv64-toolchain.c (+16) 


``diff
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 42c8336e626c7b..007a24f2b81ae7 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -443,6 +443,9 @@ void baremetal::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   CmdArgs.push_back("-Bstatic");
 
+  if (TC.getTriple().isRISCV() && Args.hasArg(options::OPT_mno_relax))
+CmdArgs.push_back("--no-relax");
+
   if (Triple.isARM() || Triple.isThumb()) {
 bool IsBigEndian = arm::isARMBigEndian(Triple, Args);
 if (IsBigEndian)
diff --git a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp 
b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
index 7e6abd14442878..0be7d1a8899495 100644
--- a/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
+++ b/clang/lib/Driver/ToolChains/RISCVToolchain.cpp
@@ -156,6 +156,9 @@ void RISCV::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   if (!D.SysRoot.empty())
 CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
+  if (Args.hasArg(options::OPT_mno_relax))
+CmdArgs.push_back("--no-relax");
+
   bool IsRV64 = ToolChain.getArch() == llvm::Triple::riscv64;
   CmdArgs.push_back("-m");
   if (IsRV64) {
diff --git a/clang/test/Driver/baremetal.cpp b/clang/test/Driver/baremetal.cpp
index c04f4506a0994d..7511d7d1adb4dd 100644
--- a/clang/test/Driver/baremetal.cpp
+++ b/clang/test/Driver/baremetal.cpp
@@ -460,3 +460,15 @@
 // RUN:   | FileCheck --check-prefix=CHECK-CLANGRT-ARCH %s
 // CHECK-CLANGRT-ARCH: "-lclang_rt.builtins-armv6m"
 // CHECK-CLANGRT-ARCH-NOT: "-lclang_rt.builtins"
+
+// Check that "--no-relax" is forwarded to the linker for RISC-V.
+// RUN: %clang %s -### 2>&1 --target=riscv64-unknown-elf -nostdinc -mno-relax \
+// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf \
+// RUN:   | FileCheck --check-prefix=CHECK-RV64-NORELAX %s
+// CHECK-RV64-NORELAX: "--no-relax"
+
+// Check that "--no-relax" is not forwarded to the linker for RISC-V.
+// RUN: %clang %s -### 2>&1 --target=riscv64-unknown-elf -nostdinc \
+// RUN: --sysroot=%S/Inputs/basic_riscv64_tree/riscv64-unknown-elf \
+// RUN:   | FileCheck --check-prefix=CHECK-RV64-RELAX %s
+// CHECK-RV64-RELAX-NOT: "--no-relax"
\ No newline at end of file
diff --git a/clang/test/Driver/riscv32-toolchain.c 
b/clang/test/Driver/riscv32-toolchain.c
index 63690c946ca0bc..701da05da9189d 100644
--- a/clang/test/Driver/riscv32-toolchain.c
+++ b/clang/test/Driver/riscv32-toolchain.c
@@ -215,6 +215,22 @@
 
 // RUN: %clang --target=riscv32 %s -emit-llvm -S -o - | FileCheck %s
 
+// Check that "--no-relax" is forwarded to the linker for RISC-V 
(RISCVToolchain.cpp).
+// RUN: env "PATH=" %clang %s -### 2>&1 -mno-relax \
+// RUN:   --target=riscv32-unknown-elf --rtlib=platform --unwindlib=platform 
--sysroot= \
+// RUN:   -march=rv32imac -mabi=lp32\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-RV32-NORELAX %s
+// CHECK-RV32-NORELAX: "--no-relax"
+
+// Check that "--no-relax" is not forwarded to the linker for RISC-V 
(RISCVToolchain.cpp).
+// RUN:env "PATH=" %clang %s -### 2>&1 \
+// RUN:   --target=riscv32-unknown-elf --rtlib=platform --unwindlib=platform 
--sysroot= \
+// RUN:   -march=rv32imac -mabi=lp32\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-RV32-RELAX %s
+// CHECK-RV32-RELAX-NOT: "--no-relax"
+
 typedef __builtin_va_list va_list;
 typedef __SIZE_TYPE__ size_t;
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
diff --git a/clang/test/Driver/riscv64-toolchain.c 
b/clang/test/Driver/riscv64-toolchain.c
index f177bff33dd4d7..da07c57d8e1fc4 100644
--- a/clang/test/Driver/riscv64-toolchain.c
+++ b/clang/test/Driver/riscv64-toolchain.c
@@ -171,6 +171,22 @@
 
 // RUN: %clang --target=riscv64 %s -emit-llvm -S -o - | FileCheck %s
 
+// Check that "--no-relax" is forwarded to the linker for RISC-V 
(RISCVToolchain.cpp).
+// RUN: env "PATH=" %clang %s -### 2>&1 -mno-relax \
+// RUN:   --target=riscv64-unknown-elf --rtlib=platform --unwindlib

[llvm] [clang] [RISCV] Always emit relocations for resolved symbols and relax (PR #73793)

2023-12-27 Thread Andreu Carminati via cfe-commits

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


[llvm] [clang] [RISCV] Always emit relocations for resolved symbols and relax (PR #73793)

2023-12-27 Thread Andreu Carminati via cfe-commits

andcarminati wrote:

> The current patch doesn't do what the title implies ("Always emit relocations 
> for resolved ").

Sure, I will close this PR because I created another one targeting just this 
case: https://github.com/llvm/llvm-project/pull/76432

Regards.

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


[flang] [clang-tools-extra] [llvm] [clang] [flang] Pass to add frame pointer attribute (PR #74598)

2023-12-27 Thread Radu Salavat via cfe-commits

https://github.com/Radu2k updated 
https://github.com/llvm/llvm-project/pull/74598

>From fda39a4d196c6cdafe3ee42358c962ef0173aaca Mon Sep 17 00:00:00 2001
From: Radu2k 
Date: Wed, 6 Dec 2023 14:39:24 +
Subject: [PATCH 01/16] Pass to add frame pointer attribute

---
 .../include/flang/Frontend/CodeGenOptions.def |  1 +
 .../flang/Optimizer/Transforms/Passes.h   |  8 ++
 .../flang/Optimizer/Transforms/Passes.td  | 17 
 flang/include/flang/Tools/CLOptions.inc   |  4 +
 flang/include/flang/Tools/CrossToolHelpers.h  |  2 +
 flang/lib/Frontend/CompilerInvocation.cpp | 13 +++
 flang/lib/Optimizer/Transforms/CMakeLists.txt |  1 +
 .../lib/Optimizer/Transforms/FunctionAttr.cpp | 97 +++
 flang/test/Driver/func-attr.f90   | 12 +++
 .../test/Driver/mlir-debug-pass-pipeline.f90  |  2 +
 flang/test/Driver/mlir-pass-pipeline.f90  |  2 +
 flang/test/Driver/save-mlir-temps.f90 |  4 +-
 flang/test/Fir/basic-program.fir  |  2 +
 flang/test/Fir/box-offset-codegen.fir |  8 +-
 flang/test/Fir/polymorphic.fir|  8 +-
 flang/test/Fir/tbaa-codegen.fir   |  2 +-
 flang/test/Fir/tbaa-codegen2.fir  |  2 +-
 17 files changed, 173 insertions(+), 12 deletions(-)
 create mode 100644 flang/lib/Optimizer/Transforms/FunctionAttr.cpp
 create mode 100644 flang/test/Driver/func-attr.f90

diff --git a/flang/include/flang/Frontend/CodeGenOptions.def 
b/flang/include/flang/Frontend/CodeGenOptions.def
index 72e7bdab12a14d..774f225974d7ea 100644
--- a/flang/include/flang/Frontend/CodeGenOptions.def
+++ b/flang/include/flang/Frontend/CodeGenOptions.def
@@ -38,6 +38,7 @@ CODEGENOPT(Underscoring, 1, 1)
 ENUM_CODEGENOPT(RelocationModel, llvm::Reloc::Model, 3, llvm::Reloc::PIC_) 
///< Name of the relocation model to use.
 ENUM_CODEGENOPT(DebugInfo,  llvm::codegenoptions::DebugInfoKind, 4,  
llvm::codegenoptions::NoDebugInfo) ///< Level of debug info to generate
 ENUM_CODEGENOPT(VecLib, llvm::driver::VectorLibrary, 3, 
llvm::driver::VectorLibrary::NoLibrary) ///< Vector functions library to use
+ENUM_CODEGENOPT(FramePointer, llvm::FramePointerKind, 2, 
llvm::FramePointerKind::None) /// frame-pointer: all,non-leaf,none
 
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.h 
b/flang/include/flang/Optimizer/Transforms/Passes.h
index 92bc7246eca700..c5f09fc2581bd3 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.h
+++ b/flang/include/flang/Optimizer/Transforms/Passes.h
@@ -12,6 +12,7 @@
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "mlir/Pass/Pass.h"
 #include "mlir/Pass/PassRegistry.h"
+#include "llvm/Support/CodeGen.h"
 #include 
 
 namespace mlir {
@@ -83,6 +84,13 @@ std::unique_ptr createVScaleAttrPass();
 std::unique_ptr
 createVScaleAttrPass(std::pair vscaleAttr);
 
+struct FunctionAttrTypes{
+llvm::FramePointerKind framePointerKind;
+};
+
+std::unique_ptr createFunctionAttrPass();
+std::unique_ptr createFunctionAttrPass(FunctionAttrTypes 
&functionAttr);
+
 // declarative passes
 #define GEN_PASS_REGISTRATION
 #include "flang/Optimizer/Transforms/Passes.h.inc"
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td 
b/flang/include/flang/Optimizer/Transforms/Passes.td
index c3768fd2d689c1..eddf94e162e9c9 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -349,4 +349,21 @@ def VScaleAttr : Pass<"vscale-attr", "mlir::func::FuncOp"> 
{
   let constructor = "::fir::createVScaleAttrPass()";
 }
 
+def FunctionAttr : Pass<"function-attr", "mlir::func::FuncOp"> {
+  let summary = "Enhance functions with different attributes";
+  let description = [{ This feature introduces a general attribute aimed at 
customizing function characteristics. 
+ Options include:
+ Add "frame-pointer" attribute to functions: Set an attribute for the 
frame pointer on functions, to enable 
+ the compiler, to avoid saving the frame pointer in a register in 
functions where it is unnecessary. 
+ This eliminates the need for instructions to save, establish, and restore 
frame pointers, while also freeing up an additional register in numerous 
functions. 
+ However, this approach can make debugging unfeasible on certain machines.
+  }];
+  let options = [
+Option<"framePointerKind", "frame-pointer",
+   "mlir::LLVM::framePointerKind::FramePointerKind", 
/*default=*/"mlir::LLVM::framePointerKind::FramePointerKind{}",
+   "frame pointer">,
+  ];
+  let constructor = "::fir::createFunctionAttrPass()";
+}
+
 #endif // FLANG_OPTIMIZER_TRANSFORMS_PASSES
diff --git a/flang/include/flang/Tools/CLOptions.inc 
b/flang/include/flang/Tools/CLOptions.inc
index d3e4dc6cd4a243..3494e588b34606 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -311,6 +311,10 @@ inline void createDefaultFIRCodeGenPassPipeline(
   if (config.VScaleMin

[clang] [llvm] [RFC][RISCV] Support RISC-V Profiles in -march option (PR #76357)

2023-12-27 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/76357

>From f4ca1ac0dedf5af0d9ddf05f7a67f30091b296ee Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH] [RFC][RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.

We may need to pass it to backend so that we can emit an ELF attr
proposed by
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/409.
---
 clang/test/Driver/riscv-profiles.c | 105 +
 llvm/lib/Support/RISCVISAInfo.cpp  |  44 +++
 llvm/lib/Target/RISCV/RISCV.td |   6 ++
 llvm/lib/Target/RISCV/RISCVProfiles.td |  70 +
 llvm/lib/Target/RISCV/RISCVSubtarget.h |  14 
 5 files changed, 239 insertions(+)
 create mode 100644 clang/test/Driver/riscv-profiles.c
 create mode 100644 llvm/lib/Target/RISCV/RISCVProfiles.td

diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..7f54d0d885c7d7
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,105 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-cpu" "generic-rv64"
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+// RVI20U32: "-target-abi" "ilp32"
+
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-cpu" "generic-rv64"
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+// RVI20U64: "-target-abi" "lp64"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20u64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-cpu" "generic-rv64"
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva20s64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-cpu" "generic-rv64"
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-cpu" "generic-rv64"
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zfhmin" 
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+// RVA22U64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22s64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-cpu" "generic-rv64"
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+zicbom"
+// RVA22S64: "-target-feature" "+zicbop"
+// RVA22S64: "-target-feature" "+zicboz"
+// RVA22S64: "-target-feature" "+zicsr"
+// RVA22S64: "-target-feature" "+zifencei"
+// RVA22S64: "-target-feature" "+zihintpause"
+// RVA22S64: "-target-feature" "+zfhmin" 
+// RVA22S64: "-target-feature" "+zba"
+// RVA22S64: "-target-feature" "+zbb"
+// RVA22S64: "-target-feature" "+zbs"
+// RVA22S64: "-target-feature" "+zkt"
+// RVA22S64: "-target-feature" "+svinval"
+// RVA22S64: "-target-feature" "+svpbmt"
+// RVA22S64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64_zfa | FileCheck 
-check-prefix=PROFILE-WITH-ADDITIONAL %s
+// PROFILE-WITH-ADDITIONAL: "-target-cpu" "generic-rv64"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+m"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+a"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+f"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+d"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+c"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+zicbom"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+

[flang] [mlir] [clang-tools-extra] [clang] [llvm] [compiler-rt] [lld] [X86] Remove RAO-INT from Grandridge (PR #76420)

2023-12-27 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/76420

>From ae1d12c24facb36323b9b46a73a1fbc3edff4dc8 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Wed, 27 Dec 2023 10:33:30 +0800
Subject: [PATCH] [X86] Remove RAO-INT from Grandridge

According to latest spec: https://cdrdv2.intel.com/v1/dl/getContent/671368
---
 clang/test/Preprocessor/predefined-arch-macros.c |  6 ++
 llvm/lib/Target/X86/X86.td   | 11 +++
 llvm/lib/TargetParser/X86TargetParser.cpp|  4 +---
 3 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/clang/test/Preprocessor/predefined-arch-macros.c 
b/clang/test/Preprocessor/predefined-arch-macros.c
index 1ae6faea776785..27c7b4a271fee8 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -2515,7 +2515,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M32
 // RUN: %clang -march=grandridge -m32 -E -dM %s -o - 2>&1 \
 // RUN: --target=i386 \
-// RUN:   | FileCheck -match-full-lines %s 
-check-prefixes=CHECK_SRF_M32,CHECK_GRR_M32
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_SRF_M32
 // RUN: %clang -march=arrowlake -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M32
@@ -2572,7 +2572,6 @@
 // CHECK_SRF_M32: #define __PRFCHW__ 1
 // CHECK_SRF_M32: #define __PTWRITE__ 1
 // CHECK_SRF_M32-NOT: #define __RAOINT__ 1
-// CHECK_GRR_M32: #define __RAOINT__ 1
 // CHECK_SRF_M32: #define __RDPID__ 1
 // CHECK_SRF_M32: #define __RDRND__ 1
 // CHECK_SRF_M32: #define __RDSEED__ 1
@@ -2618,7 +2617,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M64
 // RUN: %clang -march=grandridge -m64 -E -dM %s -o - 2>&1 \
 // RUN: --target=i386 \
-// RUN:   | FileCheck -match-full-lines %s 
-check-prefixes=CHECK_SRF_M64,CHECK_GRR_M64
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_SRF_M64
 // RUN: %clang -march=arrowlake -m64 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M64
@@ -2675,7 +2674,6 @@
 // CHECK_SRF_M64: #define __PRFCHW__ 1
 // CHECK_SRF_M64: #define __PTWRITE__ 1
 // CHECK_SRF_M64-NOT: #define __RAOINT__ 1
-// CHECK_GRR_M64: #define __RAOINT__ 1
 // CHECK_SRF_M64: #define __RDPID__ 1
 // CHECK_SRF_M64: #define __RDRND__ 1
 // CHECK_SRF_M64: #define __RDSEED__ 1
diff --git a/llvm/lib/Target/X86/X86.td b/llvm/lib/Target/X86/X86.td
index 5fd6828f43129d..e89ddcc570c96c 100644
--- a/llvm/lib/Target/X86/X86.td
+++ b/llvm/lib/Target/X86/X86.td
@@ -1256,11 +1256,6 @@ def ProcessorFeatures {
   list SRFFeatures =
 !listconcat(ADLFeatures, SRFAdditionalFeatures);
 
-  // Grandridge
-  list GRRAdditionalFeatures = [FeatureRAOINT];
-  list GRRFeatures =
-!listconcat(SRFFeatures, GRRAdditionalFeatures);
-
   // Arrowlake S
   list ARLSAdditionalFeatures = [FeatureAVXVNNIINT16,
FeatureSHA512,
@@ -1706,10 +1701,10 @@ foreach P = ["goldmont_plus", "goldmont-plus"] in {
 }
 def : ProcModel<"tremont", SLMModel, ProcessorFeatures.TRMFeatures,
 ProcessorFeatures.TRMTuning>;
-def : ProcModel<"sierraforest", AlderlakePModel, ProcessorFeatures.SRFFeatures,
-ProcessorFeatures.TRMTuning>;
-def : ProcModel<"grandridge", AlderlakePModel, ProcessorFeatures.GRRFeatures,
+foreach P = ["sierraforest", "grandridge"] in {
+  def : ProcModel;
+}
 
 // "Arrandale" along with corei3 and corei5
 foreach P = ["nehalem", "corei7", "core_i7_sse4_2"] in {
diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp 
b/llvm/lib/TargetParser/X86TargetParser.cpp
index 085554f18b2b6b..d46ff07ec7340a 100644
--- a/llvm/lib/TargetParser/X86TargetParser.cpp
+++ b/llvm/lib/TargetParser/X86TargetParser.cpp
@@ -162,8 +162,6 @@ constexpr FeatureBitset FeaturesAlderlake =
 constexpr FeatureBitset FeaturesSierraforest =
 FeaturesAlderlake | FeatureCMPCCXADD | FeatureAVXIFMA | FeatureUINTR |
 FeatureENQCMD | FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
-constexpr FeatureBitset FeaturesGrandridge =
-FeaturesSierraforest | FeatureRAOINT;
 constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest |
 FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4;
 constexpr FeatureBitset FeaturesPantherlake =
@@ -369,7 +367,7 @@ constexpr ProcInfo Processors[] = {
   // Sierraforest microarchitecture based processors.
   { {"sierraforest"}, CK_Sierraforest, FEATURE_AVX2, FeaturesSierraforest, 
'p', false },
   // Grandridge microarchitecture based processors.
-  { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesGrandridge, 'p', 
false },
+  { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesSierraforest, 'p', 
false },
   // Granite Rapids microarchitecture based processors.
   { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, 
FeaturesGr

[clang] [Clang] Implement the 'counted_by' attribute (PR #76348)

2023-12-27 Thread Bill Wendling via cfe-commits

bwendling wrote:

Some (hopefully) helpful comments on this admittedly very large patch.

General Comment:

I pulled back on allowing the `count` to be in a non-anonymous struct that 
doesn't contain the flexible array. So this is no longer allowed:

```
struct count_not_in_substruct {
  unsigned long flags;
  unsigned char count; // expected-note {{field 'count' declared here}}
  struct A {
int dummy;
int array[] __counted_by(count); // expected-error {{'counted_by' field 
'count' isn't within the same struct as the flexible array}}
  } a;
};
```

This should align with @rapidsna's bounds checking work and get rid of the 
"different behaviors for a pointer and non-pointer" that we had in the previous 
PR (https://github.com/llvm/llvm-project/pull/73730#discussion_r1430672564).

SEMA:

The SEMA code is a bit different from the previous PR. Most notably is that I'm 
not using the SEMA "lookup" utility the same way. There's no clear way to 
prevent lookup from climbing from the current scope up through the top-level 
scope. This leads to false negatives, duplicate warnings, and other horrors. 
Also, the `Scope` for each sub-structure is deleted by the time the entire 
structure's parsing is completed, making checking the entire struct after 
parsing more difficult. And the `isAnonymousStructOrUnion` flag isn't set 
during SEMA.

All of these combined to make the use of the "lookup" utility very frustrating. 
There are probably many improvements that could be made to the lookup, but I'd 
prefer to do those in a follow-up patch.

CodeGen:

One observation: the `getNonTransparentContext()` (sp?) method doesn't appear 
to work. In particular, if called on an anonymous struct, it will return that 
struct and not the enclosing "non-transparent" one. I may be misunderstanding 
what's meant by non-transparent in this case.

There are two ways that the `counted_by` attribute are used during code 
generation: for sanitizer checks, and with `__builtin_dynamic_object_size()`.

* Sanitizer check: This uses @rjmccall's suggestion 
(https://github.com/llvm/llvm-project/pull/73730#discussion_r1427627732) of 
calculating a byte offset from the flexible array to the "count." It works very 
well (barring some issues with negative offsets being represented by an 
unsigned `~1U` value). The only bit of ugliness was determining the offsets of 
fields that aren't in the top-level of a `RecordDecl`. (I'm curious why this 
hasn't come up before, but I digress.) I created `getFieldOffsetInBits()` to do 
this. It's not quite a hack, but could probably be a bit more elegant. (For 
instance, there could be a `RecordLayout` method indicating if a `FieldDecl` 
exists in the `RecordDecl`, but that wouldn't take sub-`RecordDecls` into 
account, and so on, and so on...)

* `__builtin_dynamic_object_size()`: Side-effects aren't allowed with this 
builtin. So we can work only with pointers that have either already been 
emitted or that have no side-effects. The "visitor" tries to find the "base" of 
the expression. If it's a `DeclRefExpr`, we should be able to emit a load of 
that and continue. If not, we look at `LocalDeclMap` to see if the base is 
already available. If not, we check to see if it has side-effects and emit it 
if it doesn't. Assuming one of those three happen, we grab the indices to the 
`count` and build a series of `GEPs` to them (which seems to be how Clang 
generates GEPs to nested fields). Again, there didn't appear to be an existing 
method to get these indices. (I assume that the general case isn't as easy as 
when working with C structures.)

So that's basically it. I have a program on my machine that compiles most of 
the examples in the `test/CodeGen/attr-counted-by.c` and it works well. I don't 
know if there's a unittest like place that runs examples such as these, but I'd 
be happy to include that test there.

Thank you all for taking the time to review this!

Share and enjoy!

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


[clang] [analyzer][docs] Update the release notes for llvm-18 (PR #76446)

2023-12-27 Thread Balazs Benics via cfe-commits

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


[clang] [analyzer][docs] Update the release notes for llvm-18 (PR #76446)

2023-12-27 Thread Balazs Benics via cfe-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/76446

This PR prepares the release notes of the Clang Static Analyzer for the llvm-18 
release branch, due in about a week.
See the regular [release 
schedule](https://llvm.org/docs/HowToReleaseLLVM.html#annual-release-schedule).

This patch was written after examining the relevant Static Analyzer commits 
since the last release.
Have a look at the commits, and provide feedback if I missed anything 
interesting.
Note that the release notes is not meant to be an exhaustive list of the 
changes, but rather a curated list of the relevant changes that might interest 
our stakeholders, such as tool vendors based on top of CSA or users with custom 
checkers.

See the relevant commits by using this command:
```
git log --oneline llvmorg-18-init..llvm/main   
clang/{lib/StaticAnalyzer,include/clang/StaticAnalyzer} | grep -v NFC | grep -v 
-i revert
```

Tasks to do before llvm-18 branches off:

We need to adjust/add documentation after the following PRs, to the 
`clang/docs/analyzer/checkers.rst`:

 - [ ] #73247: The list in the docs is incomplete. We need to check and update 
it.
 - [ ] #66481: The `StdVariant` alpha checker experimental, but we should still 
have some documentation for it. Now its completely absent.

>From a4a8704644067a7cf81bee601e4898bbc6b9d289 Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Wed, 27 Dec 2023 14:13:08 +0100
Subject: [PATCH] [analyzer][docs] Update the release notes for llvm-18

---
 clang/docs/ReleaseNotes.rst | 108 +---
 1 file changed, 101 insertions(+), 7 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee211c16a48ac8..17b6e285a89ca2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1052,18 +1052,92 @@ libclang
 Static Analyzer
 ---
 
+- Implemented the ``[[clang::suppress]]`` attribute for suppressing diagnostics
+  of static analysis tools, such as the Clang Static Analyzer.
+  `Documentation 
`__.
+
+- Added a new experimental checker ``alpha.core.StdVariant`` to detect variant
+  accesses via wrong alternatives.
+  (`#66481 `_)
+
+- Added a new experimental checker ``alpha.cplusplus.ArrayDelete`` to detect
+  destructions of arrays of polymorphic objects that are destructed as their
+  base class (`CERT EXP51-CPP 
`_).
+  `Documentation 
`__.
+  (`0e246bb67573 
`_)
+
 - Added a new checker ``core.BitwiseShift`` which reports situations where
   bitwise shift operators produce undefined behavior (because some operand is
   negative or too large).
+  `Documentation 
`__.
+
+- Support "Deducing this" (P0847R7). (Worked out of the box)
+  (`af4751738db8 
`__)
 
 - Move checker ``alpha.unix.Errno`` out of the ``alpha`` package
   to ``unix.Errno``.
+  `Documentation 
`__.
 
 - Move checker ``alpha.unix.StdCLibraryFunctions`` out of the ``alpha`` package
   to ``unix.StdCLibraryFunctions``.
 
+- Added a new checker configuration option to
+  ``alpha.security.cert.InvalidPtrChecker``.
+  `Documentation 
`__.
+  (`#67663 `_)
+
+- Move checker ``alpha.security.cert.env.InvalidPtr`` out of the ``alpha``
+  package to ``security.cert.env.InvalidPtr``.
+  `Documentation 
`__.
+
+- Move checker ``alpha.cplusplus.EnumCastOutOfRange`` out of the ``alpha``
+  package to ``optin.core.EnumCastOutOfRange``.
+  `Documentation 
`__.
+
+- Improved the diagnostics of the ``optin.core.EnumCastOutOfRange`` checker.
+  It will display the name and the declaration of the enumeration along with
+  the concrete value being cast to the enum.
+  (`#74503 `_)
+
+- Improved the ``ArrayBoundV2`` checker for detecting buffer accesses prior
+  the buffer; and also reworked the diagnostic messages.
+  (`3e014038b373 
`_,
+  `#70056 `_,
+  `#72107 `_)
+

[clang] [analyzer][docs] Update the release notes for llvm-18 (PR #76446)

2023-12-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balazs Benics (steakhal)


Changes

This PR prepares the release notes of the Clang Static Analyzer for the llvm-18 
release branch, due in about a week.
See the regular [release 
schedule](https://llvm.org/docs/HowToReleaseLLVM.html#annual-release-schedule).

This patch was written after examining the relevant Static Analyzer commits 
since the last release.
Have a look at the commits, and provide feedback if I missed anything 
interesting.
Note that the release notes is not meant to be an exhaustive list of the 
changes, but rather a curated list of the relevant changes that might interest 
our stakeholders, such as tool vendors based on top of CSA or users with custom 
checkers.

See the relevant commits by using this command:
```
git log --oneline llvmorg-18-init..llvm/main   
clang/{lib/StaticAnalyzer,include/clang/StaticAnalyzer} | grep -v NFC | grep -v 
-i revert
```

Tasks to do before llvm-18 branches off:

We need to adjust/add documentation after the following PRs, to the 
`clang/docs/analyzer/checkers.rst`:

 - [ ] #73247: The list in the docs is incomplete. We need to check and 
update it.
 - [ ] #66481: The `StdVariant` alpha checker experimental, but we 
should still have some documentation for it. Now its completely absent.

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


1 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+101-7) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ee211c16a48ac8..17b6e285a89ca2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1052,18 +1052,92 @@ libclang
 Static Analyzer
 ---
 
+- Implemented the ``[[clang::suppress]]`` attribute for suppressing diagnostics
+  of static analysis tools, such as the Clang Static Analyzer.
+  `Documentation 
`__.
+
+- Added a new experimental checker ``alpha.core.StdVariant`` to detect variant
+  accesses via wrong alternatives.
+  (`#66481 `_)
+
+- Added a new experimental checker ``alpha.cplusplus.ArrayDelete`` to detect
+  destructions of arrays of polymorphic objects that are destructed as their
+  base class (`CERT EXP51-CPP 
`_).
+  `Documentation 
`__.
+  (`0e246bb67573 
`_)
+
 - Added a new checker ``core.BitwiseShift`` which reports situations where
   bitwise shift operators produce undefined behavior (because some operand is
   negative or too large).
+  `Documentation 
`__.
+
+- Support "Deducing this" (P0847R7). (Worked out of the box)
+  (`af4751738db8 
`__)
 
 - Move checker ``alpha.unix.Errno`` out of the ``alpha`` package
   to ``unix.Errno``.
+  `Documentation 
`__.
 
 - Move checker ``alpha.unix.StdCLibraryFunctions`` out of the ``alpha`` package
   to ``unix.StdCLibraryFunctions``.
 
+- Added a new checker configuration option to
+  ``alpha.security.cert.InvalidPtrChecker``.
+  `Documentation 
`__.
+  (`#67663 `_)
+
+- Move checker ``alpha.security.cert.env.InvalidPtr`` out of the ``alpha``
+  package to ``security.cert.env.InvalidPtr``.
+  `Documentation 
`__.
+
+- Move checker ``alpha.cplusplus.EnumCastOutOfRange`` out of the ``alpha``
+  package to ``optin.core.EnumCastOutOfRange``.
+  `Documentation 
`__.
+
+- Improved the diagnostics of the ``optin.core.EnumCastOutOfRange`` checker.
+  It will display the name and the declaration of the enumeration along with
+  the concrete value being cast to the enum.
+  (`#74503 `_)
+
+- Improved the ``ArrayBoundV2`` checker for detecting buffer accesses prior
+  the buffer; and also reworked the diagnostic messages.
+  (`3e014038b373 
`_,
+  `#70056 `_,
+  `#72107 `_)
+
+- Improved the ``CStringChecker`` checking both ends of the buffers in more 
cases.
+  (`c3a87ddad62a 


[clang] [analyzer][docs] Update the release notes for llvm-18 (PR #76446)

2023-12-27 Thread Balazs Benics via cfe-commits

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


[clang] [analyzer][docs] Update the release notes for llvm-18 (PR #76446)

2023-12-27 Thread Balazs Benics via cfe-commits

steakhal wrote:

The `docs-clang-html` build target produces the following html document at 
`tools/clang/docs/html/ReleaseNotes.html#static-analyzer`, without any warnings:
![image](https://github.com/llvm/llvm-project/assets/6280485/3c90c648-ba56-476d-8ba2-0e1d2ba8402a)

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


[libcxx] [clang] [llvm] [libc] [compiler-rt] [clang-tools-extra] [lldb] [flang] [libc++][variant] P2637R3 - Member `visit` (PR #76447)

2023-12-27 Thread via cfe-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
886655869cef2e0f11da8981da30d70ad7892ff9...653ec7af66441bf9f9885622cec12c48322767b8
 libcxx/utils/generate_feature_test_macro_components.py
``





View the diff from darker here.


``diff
--- generate_feature_test_macro_components.py   2023-12-25 09:05:09.00 +
+++ generate_feature_test_macro_components.py   2023-12-27 15:50:38.123618 +
@@ -1263,11 +1263,11 @@
 "headers": ["functional"],
 },
 {
 "name": "__cpp_lib_variant",
 "values": {
-"c++17": 202102, # std::visit for classes derived from 
std::variant
+"c++17": 202102,  # std::visit for classes derived from 
std::variant
 # "c++20": 202106, # Fully constexpr std::variant
 # "c++26": 202306, # Member visit
 },
 "headers": ["variant"],
 },

``




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


[libcxx] [flang] [compiler-rt] [lldb] [clang] [llvm] [clang-tools-extra] [libc] [libc++][variant] P2637R3: Member `visit` (PR #76447)

2023-12-27 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov edited 
https://github.com/llvm/llvm-project/pull/76447
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [flang] [clang-tools-extra] [llvm] [libc] [lldb] [libcxx] [clang] [libc++][variant] P2637R3: Member `visit` (PR #76447)

2023-12-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libcxx

Author: Hristo Hristov (H-G-Hristov)


Changes

Implements parts of: 
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2637r3.html 
(https://eel.is/c++draft/variant.visit)

Adds member `visit` tests and (NFC) refactors + reformats the non-member 
`visit` tests to accomodate the member `visit` additions for consistency.

---

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


7 Files Affected:

- (modified) libcxx/docs/Status/Cxx2c.rst (+2) 
- (modified) libcxx/docs/Status/Cxx2cPapers.csv (+1-1) 
- (modified) libcxx/include/variant (+34) 
- (modified) 
libcxx/test/std/utilities/variant/variant.visit/robust_against_adl.pass.cpp 
(+37-16) 
- (modified) libcxx/test/std/utilities/variant/variant.visit/visit.pass.cpp 
(+428-178) 
- (modified) 
libcxx/test/std/utilities/variant/variant.visit/visit_return_type.pass.cpp 
(+545-223) 
- (modified) libcxx/utils/generate_feature_test_macro_components.py (+5-1) 


``diff
diff --git a/libcxx/docs/Status/Cxx2c.rst b/libcxx/docs/Status/Cxx2c.rst
index a7ebc4662f517c..5c700d2cb0d6d3 100644
--- a/libcxx/docs/Status/Cxx2c.rst
+++ b/libcxx/docs/Status/Cxx2c.rst
@@ -40,6 +40,8 @@ Paper Status
 .. note::
 
.. [#note-P2510R3] This paper is applied as DR against C++20. (MSVC STL and 
libstdc++ will do the same.)
+   .. [#note-P2637R3] P2637R3: Implemented `variant` member `visit`
+
 
 .. _issues-status-cxx2c:
 
diff --git a/libcxx/docs/Status/Cxx2cPapers.csv 
b/libcxx/docs/Status/Cxx2cPapers.csv
index ff83648aa76830..a3214ab2bfe75c 100644
--- a/libcxx/docs/Status/Cxx2cPapers.csv
+++ b/libcxx/docs/Status/Cxx2cPapers.csv
@@ -17,7 +17,7 @@
 "`P0792R14 `__","LWG","``function_ref``: a 
type-erased callable reference","Varna June 2023","","",""
 "`P2874R2 `__","LWG","Mandating Annex D Require No 
More","Varna June 2023","","",""
 "`P2757R3 `__","LWG","Type-checking format 
args","Varna June 2023","","","|format|"
-"`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","","","|format|"
+"`P2637R3 `__","LWG","Member ``visit``","Varna June 
2023","|Partial| [#note-P2637R3]","18.0",""
 "`P2641R4 `__","CWG, LWG","Checking if a ``union`` 
alternative is active","Varna June 2023","","",""
 "`P1759R6 `__","LWG","Native handles and file 
streams","Varna June 2023","","",""
 "`P2697R1 `__","LWG","Interfacing ``bitset`` with 
``string_view``","Varna June 2023","|Complete|","18.0",""
diff --git a/libcxx/include/variant b/libcxx/include/variant
index 6179b2a1a0ab61..4c9b04942f2779 100644
--- a/libcxx/include/variant
+++ b/libcxx/include/variant
@@ -69,6 +69,12 @@ namespace std {
 
 // 20.7.2.6, swap
 void swap(variant&) noexcept(see below);
+
+// [variant.visit], visitation
+template
+  constexpr decltype(auto) visit(this Self&&, Visitor&&);
+template
+  constexpr R visit(this Self&&, Visitor&&);
   };
 
   // 20.7.3, variant helper classes
@@ -235,6 +241,7 @@ namespace std {
 #include <__type_traits/void_t.h>
 #include <__utility/declval.h>
 #include <__utility/forward.h>
+#include <__utility/forward_like.h>
 #include <__utility/in_place.h>
 #include <__utility/move.h>
 #include <__utility/swap.h>
@@ -1273,6 +1280,15 @@ public:
 __impl_.__swap(__that.__impl_);
   }
 
+#  if _LIBCPP_STD_VER >= 26
+  // [variant.visit], visitation
+  template 
+  constexpr decltype(auto) visit(this _Self&& __self, _Visitor&& __visitor);
+
+  template 
+  constexpr _R visit(this _Self&& __self, _Visitor&& __visitor);
+#  endif
+
 private:
   __variant_detail::__impl<_Types...> __impl_;
 
@@ -1532,6 +1548,24 @@ visit(_Visitor&& __visitor, _Vs&&... __vs) {
 }
 #  endif
 
+#  if _LIBCPP_STD_VER >= 26
+// [variant.visit], visitation
+
+template 
+template 
+constexpr decltype(auto) variant<_Types...>::visit(this _Self&& __self, 
_Visitor&& __visitor) {
+  using _V = _OverrideRef<_Self&&, _CopyConst, 
variant>>;
+  return std::visit(std::forward<_Visitor>(__visitor), (_V)__self);
+}
+
+template 
+template 
+constexpr _Rp variant<_Types...>::visit(this _Self&& __self, _Visitor&& 
__visitor) {
+  using _V = _OverrideRef<_Self&&, _CopyConst, 
variant>>;
+  return std::visit<_Rp>(std::forward<_Visitor>(__visitor), (_V)__self);
+}
+#  endif
+
 template 
 _LIBCPP_HIDE_FROM_ABI auto
 swap(variant<_Types...>& __lhs, variant<_Types...>& __rhs) 
noexcept(noexcept(__lhs.swap(__rhs)))
diff --git 
a/libcxx/test/std/utilities/variant/variant.visit/robust_against_adl.pass.cpp 
b/libcxx/test/std/utilities/variant/variant.visit/robust_against_adl.pass.cpp
index 6f17fa32648d41..3bd305a7c62c17 100644
--- 
a/libcxx/test/std/utilities/variant/variant.visit/robust_against_adl.pass.cpp
+++ 
b/libcxx/test/std/utilities/variant/variant.visit/robust_against_adl.pa

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits

https://github.com/mordante created 
https://github.com/llvm/llvm-project/pull/76451

This implements a way for the compiler to find the modules.json associated with 
the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library 
installs this manifest. #75741 adds this feature in libc++.

>From f3f0db64da4d341f8e4a2054f9f25c87f8eda829 Mon Sep 17 00:00:00 2001
From: Mark de Wever 
Date: Wed, 27 Dec 2023 17:34:10 +0100
Subject: [PATCH] [clang][modules] Print library module manifest path.

This implements a way for the compiler to find the modules.json
associated with the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library
installs this manifest. #75741 adds this feature in libc++.
---
 clang/include/clang/Driver/Driver.h   | 10 +
 clang/include/clang/Driver/Options.td |  3 ++
 clang/lib/Driver/Driver.cpp   | 40 +++
 .../usr/lib/x86_64-linux-gnu/libc++.so|  0
 .../usr/lib/x86_64-linux-gnu/modules.json |  0
 ...dules-print-library-module-manifest-path.c | 15 +++
 ...arwin-print-library-module-manifest-path.c |  9 +
 7 files changed, 77 insertions(+)
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
 create mode 100644 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json
 create mode 100644 
clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c
 create mode 100644 
clang/test/Driver/darwin-print-library-module-manifest-path.c

diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation &C,
+const ToolChain &TC) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Mark de Wever (mordante)


Changes

This implements a way for the compiler to find the modules.json associated with 
the C++23 Standard library modules.

This is based on a discussion in SG15. At the moment no Standard library 
installs this manifest. #75741 adds this feature in libc++.

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


7 Files Affected:

- (modified) clang/include/clang/Driver/Driver.h (+10) 
- (modified) clang/include/clang/Driver/Options.td (+3) 
- (modified) clang/lib/Driver/Driver.cpp (+40) 
- (added) 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so () 
- (added) 
clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/modules.json () 
- (added) clang/test/Driver/cxx23-modules-print-library-module-manifest-path.c 
(+15) 
- (added) clang/test/Driver/darwin-print-library-module-manifest-path.c (+9) 


``diff
diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 3ee1bcf2a69c9b..2e1e3b128744ff 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation &C,
+const ToolChain &TC) const;
+
   /// HandleAutocompletions - Handle --autocomplete by searching and printing
   /// possible flags, descriptions, and its arguments.
   void HandleAutocompletions(StringRef PassedFlags) const;
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2b93ddf033499c..890257e11485b6 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5280,6 +5280,9 @@ def print_resource_dir : Flag<["-", "--"], 
"print-resource-dir">,
 def print_search_dirs : Flag<["-", "--"], "print-search-dirs">,
   HelpText<"Print the paths used for finding libraries and programs">,
   Visibility<[ClangOption, CLOption]>;
+def print_library_module_manifest_path : Flag<["-", "--"], 
"print-library-module-manifest-path">,
+  HelpText<"Print the path for the C++ Standard library module manifest">,
+  Visibility<[ClangOption, CLOption]>;
 def print_targets : Flag<["-", "--"], "print-targets">,
   HelpText<"Print the registered targets">,
   Visibility<[ClangOption, CLOption]>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..8d682f9238c6b8 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="
+ << GetModuleManifestPath(C, C.getDefaultToolChain()) << '\n';
+return false;
+  }
+
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
 if (std::optional RuntimePath = TC.getRuntimePath())
   llvm::outs() << *RuntimePath << '\n';
@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";
+}
+
 std::string Driver::GetTemporaryPath(StringRef Prefix, StringRef Suffix) const 
{
   SmallString<128> Path;
   std::error_code EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, 
Path);
diff --git 
a/clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so 
b/clang/test/Driver/Inputs/cxx23_modules/usr/lib/x86_64-linux-gnu/libc++.so
new

[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation &C,

tschuett wrote:

Could this be something fallible instead? Printing "" for GNU is suboptimal.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

tschuett wrote:

--print-runtime-dir, --print-target-triple,  --print-supported-cpus, and 
--print-supported-extensions take 2 dashes.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

mordante wrote:

They work with one or two dashes, `Flag<["-", "--"]`, in `Options.td` does 
that. This option does the same.

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


[clang] a70dcc2 - [clang] Use StringRef::ltrim (NFC)

2023-12-27 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-12-27T09:10:39-08:00
New Revision: a70dcc2cda6b60c2dbd4b96d229b4c1bf43c23d1

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

LOG: [clang] Use StringRef::ltrim (NFC)

Added: 


Modified: 
clang/lib/ASTMatchers/Dynamic/Parser.cpp
clang/lib/Basic/IdentifierTable.cpp
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/X86.cpp

Removed: 




diff  --git a/clang/lib/ASTMatchers/Dynamic/Parser.cpp 
b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
index 27096a83b8dd60..6a16c2184fcfb1 100644
--- a/clang/lib/ASTMatchers/Dynamic/Parser.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Parser.cpp
@@ -299,10 +299,8 @@ class Parser::CodeTokenizer {
 
   /// Consume all leading whitespace from \c Code.
   void consumeWhitespace() {
-Code = Code.drop_while([](char c) {
-  // Don't trim newlines.
-  return StringRef(" \t\v\f\r").contains(c);
-});
+// Don't trim newlines.
+Code = Code.ltrim(" \t\v\f\r");
   }
 
   SourceLocation currentLocation() {

diff  --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index 5902c6dc3ce0b4..d0d8316385b452 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -628,8 +628,7 @@ ObjCMethodFamily Selector::getMethodFamilyImpl(Selector 
sel) {
 return OMF_performSelector;
 
   // The other method families may begin with a prefix of underscores.
-  while (!name.empty() && name.front() == '_')
-name = name.substr(1);
+  name = name.ltrim('_');
 
   if (name.empty()) return OMF_None;
   switch (name.front()) {

diff  --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index 3ee39133fcee72..2f8395cb8932f2 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1365,8 +1365,7 @@ bool AArch64TargetInfo::validateConstraintModifier(
 StringRef Constraint, char Modifier, unsigned Size,
 std::string &SuggestedModifier) const {
   // Strip off constraint modifiers.
-  while (Constraint[0] == '=' || Constraint[0] == '+' || Constraint[0] == '&')
-Constraint = Constraint.substr(1);
+  Constraint = Constraint.ltrim("=+&");
 
   switch (Constraint[0]) {
   default:

diff  --git a/clang/lib/Basic/Targets/ARM.cpp b/clang/lib/Basic/Targets/ARM.cpp
index 6e1842fc64e505..01f9e844da12a0 100644
--- a/clang/lib/Basic/Targets/ARM.cpp
+++ b/clang/lib/Basic/Targets/ARM.cpp
@@ -1230,8 +1230,7 @@ bool ARMTargetInfo::validateConstraintModifier(
   bool isInOut = (Constraint[0] == '+');
 
   // Strip off constraint modifiers.
-  while (Constraint[0] == '=' || Constraint[0] == '+' || Constraint[0] == '&')
-Constraint = Constraint.substr(1);
+  Constraint = Constraint.ltrim("=+&");
 
   switch (Constraint[0]) {
   default:

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index b97f88647fa49f..3deaa19f8d4fc4 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -1613,8 +1613,7 @@ bool X86TargetInfo::validateOutputSize(const 
llvm::StringMap &FeatureMap,
StringRef Constraint,
unsigned Size) const {
   // Strip off constraint modifiers.
-  while (Constraint[0] == '=' || Constraint[0] == '+' || Constraint[0] == '&')
-Constraint = Constraint.substr(1);
+  Constraint = Constraint.ltrim("=+&");
 
   return validateOperandSize(FeatureMap, Constraint, Size);
 }



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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain &TC) const;
 
+  /// GetModuleManifestPath - Lookup the name of the Standard library manifest.
+  ///
+  /// \param C - The compilation.
+  /// \param TC - The tool chain for additional information on
+  /// directories to search.
+  //
+  // FIXME: This should be in CompilationInfo.
+  std::string GetModuleManifestPath(const Compilation &C,

mordante wrote:

That is an option, I could do `` or something like that. I'm not 
sure what the tool vendors prefer. A magic string or an empty string.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

tschuett wrote:

The trend seems to go to two dashes and there are no tests for 2 dashes.

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


[clang-tools-extra] [flang] [clang] [llvm] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

2023-12-27 Thread Peter Klausler via cfe-commits


@@ -173,5 +173,70 @@ RT_API_ATTRS void ShallowCopy(const Descriptor &to, const 
Descriptor &from) {
   ShallowCopy(to, from, to.IsContiguous(), from.IsContiguous());
 }
 
+RT_API_ATTRS const char *EnsureNullTerminated(
+const char *str, size_t length, Terminator &terminator) {
+  if (length <= std::strlen(str)) {

klausler wrote:

Do not call `std::strlen()` on a string that is not known to be NUL terminated. 
 Use `std::memchr` instead.

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


[llvm] [flang] [clang-tools-extra] [clang] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

2023-12-27 Thread Peter Klausler via cfe-commits


@@ -0,0 +1,203 @@
+//===-- runtime/execute.cpp 
---===//
+//
+// 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
+//
+//===--===//
+
+#include "flang/Runtime/execute.h"
+#include "environment.h"
+#include "stat.h"
+#include "terminator.h"
+#include "tools.h"
+#include "flang/Runtime/descriptor.h"
+#include 
+#include 
+#include 
+#ifdef _WIN32
+#define LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#include 
+#else
+#include 
+#include 
+#endif
+
+namespace Fortran::runtime {
+
+// cmdstat specified in 16.9.73
+// −1 if the processor does not support command line execution,
+// a processor-dependent positive value if an error condition occurs
+// −2 if no error condition occurs but WAIT is present with the value false
+// and the processor does not support asynchronous execution. Otherwise it is
+// assigned the value 0
+enum CMD_STAT {
+  ASYNC_NO_SUPPORT_ERR = -2,
+  NO_SUPPORT_ERR = -1,
+  CMD_EXECUTED = 0,
+  FORK_ERR = 1,
+  EXECL_ERR = 2,
+  INVALID_CL_ERR = 3,
+  SIGNAL_ERR = 4
+};
+
+// Override CopyCharsToDescriptor in tools.h, pass string directly
+void CopyCharsToDescriptor(const Descriptor &value, const char *rawValue) {
+  CopyCharsToDescriptor(value, rawValue, std::strlen(rawValue));
+}
+
+void CheckAndCopyCharsToDescriptor(
+const Descriptor *value, const char *rawValue) {
+  if (value) {
+CopyCharsToDescriptor(*value, rawValue);
+  }
+}
+
+void CheckAndStoreIntToDescriptor(
+const Descriptor *intVal, std::int64_t value, Terminator &terminator) {
+  if (intVal) {
+StoreIntToDescriptor(intVal, value, terminator);
+  }
+}
+
+// If a condition occurs that would assign a nonzero value to CMDSTAT but
+// the CMDSTAT variable is not present, error termination is initiated.
+int TerminationCheck(int status, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, Terminator &terminator) {
+  if (status == -1) {
+if (!cmdstat) {
+  terminator.Crash("Execution error with system status code: %d", status);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, EXECL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Execution error");
+}
+  }
+#ifdef _WIN32
+  // On WIN32 API std::system returns exit status directly
+  int exitStatusVal{status};
+  if (exitStatusVal == 1) {
+#else
+  int exitStatusVal{WEXITSTATUS(status)};
+  if (exitStatusVal == 127 || exitStatusVal == 126) {
+#endif
+if (!cmdstat) {
+  terminator.Crash(
+  "Invalid command quit with exit status code: %d", exitStatusVal);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, INVALID_CL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Invalid command line");
+}
+  }
+#if defined(WIFSIGNALED) && defined(WTERMSIG)
+  if (WIFSIGNALED(status)) {
+if (!cmdstat) {
+  terminator.Crash("killed by signal: %d", WTERMSIG(status));
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, SIGNAL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "killed by signal");
+}
+  }
+#endif
+#if defined(WIFSTOPPED) && defined(WSTOPSIG)
+  if (WIFSTOPPED(status)) {
+if (!cmdstat) {
+  terminator.Crash("stopped by signal: %d", WSTOPSIG(status));
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, SIGNAL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "stopped by signal");
+}
+  }
+#endif
+  return exitStatusVal;
+}
+
+void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
+const Descriptor *exitstat, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, const char *sourceFile, int line) {
+  Terminator terminator{sourceFile, line};
+  const char *newCmd{EnsureNullTerminated(
+  command.OffsetElement(), command.ElementBytes(), terminator)};
+
+  if (exitstat) {
+RUNTIME_CHECK(terminator, IsValidIntDescriptor(exitstat));
+  }
+
+  if (cmdstat) {
+RUNTIME_CHECK(terminator, IsValidIntDescriptor(cmdstat));
+// Assigned 0 as specifed in standard, if error then overwrite
+StoreIntToDescriptor(cmdstat, CMD_EXECUTED, terminator);
+  }
+
+  if (cmdmsg) {
+RUNTIME_CHECK(terminator, IsValidCharDescriptor(cmdmsg));
+  }
+
+  if (wait) {
+// either wait is not specified or wait is true: synchronous mode
+int status{std::system(newCmd)};
+int exitStatusVal{TerminationCheck(status, cmdstat, cmdmsg, terminator)};
+// If sync, assigned processor-dependent exit status. Otherwise unchanged
+CheckAndStoreIntToDescriptor(exitstat, exitStatusVal, terminator);
+  } else {
+// Asynchronous mode
+#ifdef _WIN32
+STARTUPINFO si;
+PROCESS_INFORMATION pi;
+ZeroMemory(&si, sizeof(si));
+si.cb = sizeof(si);
+ZeroMemory(&pi, sizeof(pi));
+
+// append "cmd.exe /c " to the beginning of command
+const char *pre

[llvm] [clang-tools-extra] [flang] [clang] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

2023-12-27 Thread Peter Klausler via cfe-commits


@@ -411,6 +412,24 @@ RT_API_ATTRS void ShallowCopy(const Descriptor &to, const 
Descriptor &from,
 bool toIsContiguous, bool fromIsContiguous);
 RT_API_ATTRS void ShallowCopy(const Descriptor &to, const Descriptor &from);
 
+RT_API_ATTRS const char *EnsureNullTerminated(
+const char *str, size_t length, Terminator &terminator);
+
+RT_API_ATTRS bool IsValidCharDescriptor(const Descriptor *value);
+
+RT_API_ATTRS bool IsValidIntDescriptor(const Descriptor *intVal);
+
+// Copy a null-terminated character array \p rawValue to descriptor \p value.
+// The copy starts at the given \p offset, if not present then start at 0.
+// If descriptor `errmsg` is provided, error messages will be stored to it.
+// Returns stats specified in standard.
+RT_API_ATTRS std::int32_t CopyCharsToDescriptor(const Descriptor &value,
+const char *rawValue, std::int64_t rawValueLength,

klausler wrote:

`rawValueLength` should probably be `std::size_t`.

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


[clang] [llvm] [flang] [clang-tools-extra] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

2023-12-27 Thread Peter Klausler via cfe-commits


@@ -0,0 +1,203 @@
+//===-- runtime/execute.cpp 
---===//
+//
+// 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
+//
+//===--===//
+
+#include "flang/Runtime/execute.h"
+#include "environment.h"
+#include "stat.h"
+#include "terminator.h"
+#include "tools.h"
+#include "flang/Runtime/descriptor.h"
+#include 
+#include 
+#include 
+#ifdef _WIN32
+#define LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+#include 
+#else
+#include 
+#include 
+#endif
+
+namespace Fortran::runtime {
+
+// cmdstat specified in 16.9.73
+// −1 if the processor does not support command line execution,
+// a processor-dependent positive value if an error condition occurs
+// −2 if no error condition occurs but WAIT is present with the value false
+// and the processor does not support asynchronous execution. Otherwise it is
+// assigned the value 0
+enum CMD_STAT {
+  ASYNC_NO_SUPPORT_ERR = -2,
+  NO_SUPPORT_ERR = -1,
+  CMD_EXECUTED = 0,
+  FORK_ERR = 1,
+  EXECL_ERR = 2,
+  INVALID_CL_ERR = 3,
+  SIGNAL_ERR = 4
+};
+
+// Override CopyCharsToDescriptor in tools.h, pass string directly
+void CopyCharsToDescriptor(const Descriptor &value, const char *rawValue) {
+  CopyCharsToDescriptor(value, rawValue, std::strlen(rawValue));
+}
+
+void CheckAndCopyCharsToDescriptor(
+const Descriptor *value, const char *rawValue) {
+  if (value) {
+CopyCharsToDescriptor(*value, rawValue);
+  }
+}
+
+void CheckAndStoreIntToDescriptor(
+const Descriptor *intVal, std::int64_t value, Terminator &terminator) {
+  if (intVal) {
+StoreIntToDescriptor(intVal, value, terminator);
+  }
+}
+
+// If a condition occurs that would assign a nonzero value to CMDSTAT but
+// the CMDSTAT variable is not present, error termination is initiated.
+int TerminationCheck(int status, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, Terminator &terminator) {
+  if (status == -1) {
+if (!cmdstat) {
+  terminator.Crash("Execution error with system status code: %d", status);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, EXECL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Execution error");
+}
+  }
+#ifdef _WIN32
+  // On WIN32 API std::system returns exit status directly
+  int exitStatusVal{status};
+  if (exitStatusVal == 1) {
+#else
+  int exitStatusVal{WEXITSTATUS(status)};
+  if (exitStatusVal == 127 || exitStatusVal == 126) {
+#endif
+if (!cmdstat) {
+  terminator.Crash(
+  "Invalid command quit with exit status code: %d", exitStatusVal);
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, INVALID_CL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "Invalid command line");
+}
+  }
+#if defined(WIFSIGNALED) && defined(WTERMSIG)
+  if (WIFSIGNALED(status)) {
+if (!cmdstat) {
+  terminator.Crash("killed by signal: %d", WTERMSIG(status));
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, SIGNAL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "killed by signal");
+}
+  }
+#endif
+#if defined(WIFSTOPPED) && defined(WSTOPSIG)
+  if (WIFSTOPPED(status)) {
+if (!cmdstat) {
+  terminator.Crash("stopped by signal: %d", WSTOPSIG(status));
+} else {
+  CheckAndStoreIntToDescriptor(cmdstat, SIGNAL_ERR, terminator);
+  CopyCharsToDescriptor(*cmdmsg, "stopped by signal");
+}
+  }
+#endif
+  return exitStatusVal;
+}
+
+void RTNAME(ExecuteCommandLine)(const Descriptor &command, bool wait,
+const Descriptor *exitstat, const Descriptor *cmdstat,
+const Descriptor *cmdmsg, const char *sourceFile, int line) {
+  Terminator terminator{sourceFile, line};
+  const char *newCmd{EnsureNullTerminated(
+  command.OffsetElement(), command.ElementBytes(), terminator)};
+
+  if (exitstat) {
+RUNTIME_CHECK(terminator, IsValidIntDescriptor(exitstat));
+  }
+
+  if (cmdstat) {
+RUNTIME_CHECK(terminator, IsValidIntDescriptor(cmdstat));
+// Assigned 0 as specifed in standard, if error then overwrite
+StoreIntToDescriptor(cmdstat, CMD_EXECUTED, terminator);
+  }
+
+  if (cmdmsg) {
+RUNTIME_CHECK(terminator, IsValidCharDescriptor(cmdmsg));
+  }
+
+  if (wait) {
+// either wait is not specified or wait is true: synchronous mode
+int status{std::system(newCmd)};
+int exitStatusVal{TerminationCheck(status, cmdstat, cmdmsg, terminator)};
+// If sync, assigned processor-dependent exit status. Otherwise unchanged
+CheckAndStoreIntToDescriptor(exitstat, exitStatusVal, terminator);
+  } else {
+// Asynchronous mode
+#ifdef _WIN32
+STARTUPINFO si;
+PROCESS_INFORMATION pi;
+ZeroMemory(&si, sizeof(si));
+si.cb = sizeof(si);
+ZeroMemory(&pi, sizeof(pi));
+
+// append "cmd.exe /c " to the beginning of command
+const char *pre

[llvm] [clang] [flang] [clang-tools-extra] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

2023-12-27 Thread Peter Klausler via cfe-commits


@@ -0,0 +1,31 @@
+//===-- include/flang/Runtime/command.h -*- 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
+//
+//===--===//
+
+#ifndef FORTRAN_RUNTIME_EXECUTE_H_
+#define FORTRAN_RUNTIME_EXECUTE_H_
+
+#include "flang/Runtime/entry-names.h"
+
+#include 

klausler wrote:

Is this `#include` necessary to define anything in this header?

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


[clang-tools-extra] [flang] [llvm] [clang] [flang] Add EXECUTE_COMMAND_LINE runtime and lowering intrinsics implementation (PR #74077)

2023-12-27 Thread Peter Klausler via cfe-commits


@@ -173,5 +173,70 @@ RT_API_ATTRS void ShallowCopy(const Descriptor &to, const 
Descriptor &from) {
   ShallowCopy(to, from, to.IsContiguous(), from.IsContiguous());
 }
 
+RT_API_ATTRS const char *EnsureNullTerminated(
+const char *str, size_t length, Terminator &terminator) {

klausler wrote:

`std::size_t`

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";

tschuett wrote:

Note: path foo does not exist.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";

tschuett wrote:

Note: libstdc++ is not supported.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Thorsten Schütt via cfe-commits


@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";
+  }
+
+  case ToolChain::CST_Libstdcxx:
+// libstdc++ does not provide Standard library modules yet.
+return "";
+  }
+
+  return "";

tschuett wrote:

Note: found unknown STL.

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -6135,6 +6141,40 @@ std::string Driver::GetProgramPath(StringRef Name, const 
ToolChain &TC) const {
   return std::string(Name);
 }
 
+std::string Driver::GetModuleManifestPath(const Compilation &C,
+  const ToolChain &TC) const {
+
+  switch (TC.GetCXXStdlibType(C.getArgs())) {
+  case ToolChain::CST_Libcxx: {
+std::string lib = "libc++.so";
+std::string path = GetFilePath(lib, TC);
+
+// Note when there are multiple flavours of libc++ the module json needs to
+// look at the command-line arguments for the proper json.
+
+// For example
+/*
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(C.getArgs());
+if (Sanitize.needsAsanRt())
+  return path.replace(path.size() - lib.size(), lib.size(),
+  "modules-asan.json");
+*/
+
+path = path.replace(path.size() - lib.size(), lib.size(), "modules.json");
+if (TC.getVFS().exists(path))
+  return path;
+
+return "";

mordante wrote:

I like one error value, the goal of the output is to be usable by tools. 

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


[clang] [clang][modules] Print library module manifest path. (PR #76451)

2023-12-27 Thread Mark de Wever via cfe-commits


@@ -0,0 +1,15 @@
+// Test that -print-library-module-manifest-path finds the correct file.
+
+// RUN: %clang -print-library-module-manifest-path \

mordante wrote:

I wasn't aware of that. I got used to using one dash using clang.

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


[libcxx] [clang] [libc++] Re-enable the clang_modules_include test for Objective-C++ (PR #66801)

2023-12-27 Thread Mark de Wever via cfe-commits

mordante wrote:

> @mordante I'm not certain what's going on here, I get
> 
> ```
> [...]/clang_modules_include.gen.py/__std_clang_module.compile.pass.mm:22:2: 
> error: import of module 'std' imported non C++20 importable modules
>22 | @import std;
>   |  ^
> 1 error generated.
> ```
> 
> Can you assist? It only happens with Clang trunk.

I tested this locally and indeed it works with clang-17 and fails with clang-18

@ChuanqiXu9 This seems to be introduced in 
574ee1c02ef73b66c5957cf93888234b0471695f.

This test uses a Objective-C++ file. Is it easy for you to fix or should I file 
a bug report?

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


[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2023-12-27 Thread David Goldman via cfe-commits

https://github.com/DavidGoldman created 
https://github.com/llvm/llvm-project/pull/76466

This is based on  top of #76410 

>From 4caf5b3c779bf18236b4b0be5bc7147d10339f2b Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 15:59:01 -0500
Subject: [PATCH 1/4] [clangd][SymbolCollector] Treat ObjC methods as spelled

We'll treat multi-arg methods as spelled once we have full rename
support for them.
---
 .../clangd/index/SymbolCollector.cpp  |  6 ++-
 .../clangd/unittests/SymbolCollectorTests.cpp | 42 +++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 7ef4b15febad22..336bc3506bb360 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -174,7 +174,9 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
   auto Name = ND.getDeclName();
   const auto NameKind = Name.getNameKind();
   if (NameKind != DeclarationName::Identifier &&
-  NameKind != DeclarationName::CXXConstructorName)
+  NameKind != DeclarationName::CXXConstructorName &&
+  NameKind != DeclarationName::ObjCZeroArgSelector &&
+  NameKind != DeclarationName::ObjCOneArgSelector)
 return false;
   const auto &AST = ND.getASTContext();
   const auto &SM = AST.getSourceManager();
@@ -183,6 +185,8 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
   if (clang::Lexer::getRawToken(Loc, Tok, SM, LO))
 return false;
   auto StrName = Name.getAsString();
+  if (const auto *MD = dyn_cast(&ND))
+StrName = MD->getSelector().getNameForSlot(0).str();
   return clang::Lexer::getSpelling(Tok, SM, LO) == StrName;
 }
 } // namespace
diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 9cdc57ec01f327..1d4e1c1d75ea23 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -105,6 +105,9 @@ MATCHER(refRange, "") {
 MATCHER_P2(OverriddenBy, Subject, Object, "") {
   return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID};
 }
+MATCHER(isSpelled, "") {
+  return static_cast(arg.Kind & RefKind::Spelled);
+}
 ::testing::Matcher &>
 haveRanges(const std::vector Ranges) {
   return ::testing::UnorderedPointwise(refRange(), Ranges);
@@ -524,6 +527,45 @@ TEST_F(SymbolCollectorTest, templateArgs) {
  forCodeCompletion(false);
 }
 
+TEST_F(SymbolCollectorTest, ObjCRefs) {
+  Annotations Header(R"(
+  @interface Person
+  - (void)$talk[[talk]];
+  - (void)$say[[say]]:(id)something;
+  @end
+  @interface Person (Category)
+  - (void)categoryMethod;
+  - (void)multiArg:(id)a method:(id)b;
+  @end
+  )");
+  Annotations Main(R"(
+  @implementation Person
+  - (void)$talk[[talk]] {}
+  - (void)$say[[say]]:(id)something {}
+  @end
+
+  void fff(Person *p) {
+[p $talk[[talk]]];
+[p $say[[say]]:0];
+[p categoryMethod];
+[p multiArg:0 method:0];
+  }
+  )");
+  CollectorOpts.RefFilter = RefKind::All;
+  CollectorOpts.CollectMainFileRefs = true;
+  TestFileName = testPath("test.m");
+  runSymbolCollector(Header.code(), Main.code(),
+ {"-fblocks", "-xobjective-c++", "-Wno-objc-root-class"});
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::talk").ID,
+  haveRanges(Main.ranges("talk");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
+  haveRanges(Main.ranges("say");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::categoryMethod").ID,
+  ElementsAre(isSpelled();
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::multiArg:method:").ID,
+  ElementsAre(Not(isSpelled());
+}
+
 TEST_F(SymbolCollectorTest, ObjCSymbols) {
   const std::string Header = R"(
 @interface Person

>From 1b6a09464ff5c7b1988fcb479d0a4ff876f696e6 Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 16:12:03 -0500
Subject: [PATCH 2/4] Run clang-format

---
 .../clangd/unittests/SymbolCollectorTests.cpp  | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 1d4e1c1d75ea23..5c20b950e4eac0 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -560,10 +560,12 @@ TEST_F(SymbolCollectorTest, ObjCRefs) {
   haveRanges(Main.ranges("talk");
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
   haveRanges(Main.ranges("say");
-  EXPECT_T

[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2023-12-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: David Goldman (DavidGoldman)


Changes

This is based on  top of #76410 

---

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


11 Files Affected:

- (modified) clang-tools-extra/clangd/ClangdLSPServer.cpp (+5-2) 
- (modified) clang-tools-extra/clangd/ClangdLSPServer.h (+1-1) 
- (modified) clang-tools-extra/clangd/Protocol.cpp (+10) 
- (modified) clang-tools-extra/clangd/Protocol.h (+8) 
- (modified) clang-tools-extra/clangd/SourceCode.cpp (+8) 
- (modified) clang-tools-extra/clangd/SourceCode.h (+4) 
- (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+6-1) 
- (modified) clang-tools-extra/clangd/refactor/Rename.cpp (+283-38) 
- (modified) clang-tools-extra/clangd/refactor/Rename.h (+37-7) 
- (modified) clang-tools-extra/clangd/unittests/RenameTests.cpp (+34-14) 
- (modified) clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp (+44) 


``diff
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index a87da252b7a7e9..0e628cfc71c2de 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -844,14 +844,17 @@ void ClangdLSPServer::onWorkspaceSymbol(
 }
 
 void ClangdLSPServer::onPrepareRename(const TextDocumentPositionParams &Params,
-  Callback> Reply) {
+  
Callback> Reply) {
   Server->prepareRename(
   Params.textDocument.uri.file(), Params.position, /*NewName*/ 
std::nullopt,
   Opts.Rename,
   [Reply = std::move(Reply)](llvm::Expected Result) mutable {
 if (!Result)
   return Reply(Result.takeError());
-return Reply(std::move(Result->Target));
+PrepareRenameResult PrepareResult;
+PrepareResult.range = Result->Target;
+PrepareResult.placeholder = Result->Placeholder;
+return Reply(std::move(PrepareResult));
   });
 }
 
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index 79579c22b788a9..3a60b6e5db86bc 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -134,7 +134,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks,
   void onWorkspaceSymbol(const WorkspaceSymbolParams &,
  Callback>);
   void onPrepareRename(const TextDocumentPositionParams &,
-   Callback>);
+   Callback>);
   void onRename(const RenameParams &, Callback);
   void onHover(const TextDocumentPositionParams &,
Callback>);
diff --git a/clang-tools-extra/clangd/Protocol.cpp 
b/clang-tools-extra/clangd/Protocol.cpp
index a6370649f5ad1c..29b99da27101a8 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -1187,6 +1187,16 @@ bool fromJSON(const llvm::json::Value &Params, 
RenameParams &R,
  O.map("position", R.position) && O.map("newName", R.newName);
 }
 
+llvm::json::Value toJSON(const PrepareRenameResult &PRR) {
+  if (!PRR.placeholder) {
+return toJSON(PRR.range);
+  }
+  return llvm::json::Object{
+  {"range", toJSON(PRR.range)},
+  {"placeholder", PRR.placeholder},
+  };
+}
+
 llvm::json::Value toJSON(const DocumentHighlight &DH) {
   return llvm::json::Object{
   {"range", toJSON(DH.range)},
diff --git a/clang-tools-extra/clangd/Protocol.h 
b/clang-tools-extra/clangd/Protocol.h
index e88c804692568f..18ac530e9c1a0f 100644
--- a/clang-tools-extra/clangd/Protocol.h
+++ b/clang-tools-extra/clangd/Protocol.h
@@ -1436,6 +1436,14 @@ struct RenameParams {
 };
 bool fromJSON(const llvm::json::Value &, RenameParams &, llvm::json::Path);
 
+struct PrepareRenameResult {
+  /// Range of the string to rename.
+  Range range;
+  /// Placeholder text to use in the editor, if set.
+  std::optional placeholder;
+};
+llvm::json::Value toJSON(const PrepareRenameResult &PRR);
+
 enum class DocumentHighlightKind { Text = 1, Read = 2, Write = 3 };
 
 /// A document highlight is a range inside a text document which deserves
diff --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 835038423fdf37..73e12fc7ebde51 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -1243,6 +1243,14 @@ SourceLocation 
translatePreamblePatchLocation(SourceLocation Loc,
   return Loc;
 }
 
+clangd::Range tokenRangeForLoc(SourceLocation TokLoc, const SourceManager &SM, 
const LangOptions &LangOpts) {
+  auto TokenLength = clang::Lexer::MeasureTokenLength(TokLoc, SM, LangOpts);
+  clangd::Range Result;
+  Result.start = sourceLocToPosition(SM, TokLoc);
+  Result.end = sourceLocToPosition(SM, TokLoc.getLocWithOffset(TokenLength));
+  return Result;
+}
+
 clangd::Range rangeTillEOL(llvm::StringRef Code, unsigned HashOffset) {
   c

[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2023-12-27 Thread David Goldman via cfe-commits

https://github.com/DavidGoldman updated 
https://github.com/llvm/llvm-project/pull/76466

>From 4caf5b3c779bf18236b4b0be5bc7147d10339f2b Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 15:59:01 -0500
Subject: [PATCH 1/5] [clangd][SymbolCollector] Treat ObjC methods as spelled

We'll treat multi-arg methods as spelled once we have full rename
support for them.
---
 .../clangd/index/SymbolCollector.cpp  |  6 ++-
 .../clangd/unittests/SymbolCollectorTests.cpp | 42 +++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 7ef4b15febad22..336bc3506bb360 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -174,7 +174,9 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
   auto Name = ND.getDeclName();
   const auto NameKind = Name.getNameKind();
   if (NameKind != DeclarationName::Identifier &&
-  NameKind != DeclarationName::CXXConstructorName)
+  NameKind != DeclarationName::CXXConstructorName &&
+  NameKind != DeclarationName::ObjCZeroArgSelector &&
+  NameKind != DeclarationName::ObjCOneArgSelector)
 return false;
   const auto &AST = ND.getASTContext();
   const auto &SM = AST.getSourceManager();
@@ -183,6 +185,8 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
   if (clang::Lexer::getRawToken(Loc, Tok, SM, LO))
 return false;
   auto StrName = Name.getAsString();
+  if (const auto *MD = dyn_cast(&ND))
+StrName = MD->getSelector().getNameForSlot(0).str();
   return clang::Lexer::getSpelling(Tok, SM, LO) == StrName;
 }
 } // namespace
diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 9cdc57ec01f327..1d4e1c1d75ea23 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -105,6 +105,9 @@ MATCHER(refRange, "") {
 MATCHER_P2(OverriddenBy, Subject, Object, "") {
   return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID};
 }
+MATCHER(isSpelled, "") {
+  return static_cast(arg.Kind & RefKind::Spelled);
+}
 ::testing::Matcher &>
 haveRanges(const std::vector Ranges) {
   return ::testing::UnorderedPointwise(refRange(), Ranges);
@@ -524,6 +527,45 @@ TEST_F(SymbolCollectorTest, templateArgs) {
  forCodeCompletion(false);
 }
 
+TEST_F(SymbolCollectorTest, ObjCRefs) {
+  Annotations Header(R"(
+  @interface Person
+  - (void)$talk[[talk]];
+  - (void)$say[[say]]:(id)something;
+  @end
+  @interface Person (Category)
+  - (void)categoryMethod;
+  - (void)multiArg:(id)a method:(id)b;
+  @end
+  )");
+  Annotations Main(R"(
+  @implementation Person
+  - (void)$talk[[talk]] {}
+  - (void)$say[[say]]:(id)something {}
+  @end
+
+  void fff(Person *p) {
+[p $talk[[talk]]];
+[p $say[[say]]:0];
+[p categoryMethod];
+[p multiArg:0 method:0];
+  }
+  )");
+  CollectorOpts.RefFilter = RefKind::All;
+  CollectorOpts.CollectMainFileRefs = true;
+  TestFileName = testPath("test.m");
+  runSymbolCollector(Header.code(), Main.code(),
+ {"-fblocks", "-xobjective-c++", "-Wno-objc-root-class"});
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::talk").ID,
+  haveRanges(Main.ranges("talk");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
+  haveRanges(Main.ranges("say");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::categoryMethod").ID,
+  ElementsAre(isSpelled();
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::multiArg:method:").ID,
+  ElementsAre(Not(isSpelled());
+}
+
 TEST_F(SymbolCollectorTest, ObjCSymbols) {
   const std::string Header = R"(
 @interface Person

>From 1b6a09464ff5c7b1988fcb479d0a4ff876f696e6 Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 16:12:03 -0500
Subject: [PATCH 2/5] Run clang-format

---
 .../clangd/unittests/SymbolCollectorTests.cpp  | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 1d4e1c1d75ea23..5c20b950e4eac0 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -560,10 +560,12 @@ TEST_F(SymbolCollectorTest, ObjCRefs) {
   haveRanges(Main.ranges("talk");
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
   haveRanges(Main.ranges("say");
-  EXPECT_THAT(Refs, Contains(Pair(findSymbol

[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2023-12-27 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 8b485070844d03cda467e75aa8c924184ba671cf 
76385b51db0e33a25df9646eb6d59f04a4f65af7 -- 
clang-tools-extra/clangd/ClangdLSPServer.cpp 
clang-tools-extra/clangd/ClangdLSPServer.h 
clang-tools-extra/clangd/Protocol.cpp clang-tools-extra/clangd/Protocol.h 
clang-tools-extra/clangd/SourceCode.cpp clang-tools-extra/clangd/SourceCode.h 
clang-tools-extra/clangd/index/SymbolCollector.cpp 
clang-tools-extra/clangd/refactor/Rename.cpp 
clang-tools-extra/clangd/refactor/Rename.h 
clang-tools-extra/clangd/unittests/RenameTests.cpp 
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 0e628cfc71..641266b76c 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -843,8 +843,9 @@ void ClangdLSPServer::onWorkspaceSymbol(
   });
 }
 
-void ClangdLSPServer::onPrepareRename(const TextDocumentPositionParams &Params,
-  
Callback> Reply) {
+void ClangdLSPServer::onPrepareRename(
+const TextDocumentPositionParams &Params,
+Callback> Reply) {
   Server->prepareRename(
   Params.textDocument.uri.file(), Params.position, /*NewName*/ 
std::nullopt,
   Opts.Rename,
diff --git a/clang-tools-extra/clangd/SourceCode.cpp 
b/clang-tools-extra/clangd/SourceCode.cpp
index 73e12fc7eb..ac20ed095b 100644
--- a/clang-tools-extra/clangd/SourceCode.cpp
+++ b/clang-tools-extra/clangd/SourceCode.cpp
@@ -1243,7 +1243,8 @@ SourceLocation 
translatePreamblePatchLocation(SourceLocation Loc,
   return Loc;
 }
 
-clangd::Range tokenRangeForLoc(SourceLocation TokLoc, const SourceManager &SM, 
const LangOptions &LangOpts) {
+clangd::Range tokenRangeForLoc(SourceLocation TokLoc, const SourceManager &SM,
+   const LangOptions &LangOpts) {
   auto TokenLength = clang::Lexer::MeasureTokenLength(TokLoc, SM, LangOpts);
   clangd::Range Result;
   Result.start = sourceLocToPosition(SM, TokLoc);
diff --git a/clang-tools-extra/clangd/SourceCode.h 
b/clang-tools-extra/clangd/SourceCode.h
index d671e05aed..efe6d66c16 100644
--- a/clang-tools-extra/clangd/SourceCode.h
+++ b/clang-tools-extra/clangd/SourceCode.h
@@ -338,8 +338,7 @@ inline bool isReservedName(llvm::StringRef Name) {
 SourceLocation translatePreamblePatchLocation(SourceLocation Loc,
   const SourceManager &SM);
 
-clangd::Range tokenRangeForLoc(SourceLocation TokLoc,
-   const SourceManager &SM,
+clangd::Range tokenRangeForLoc(SourceLocation TokLoc, const SourceManager &SM,
const LangOptions &LangOpts);
 
 /// Returns the range starting at offset and spanning the whole line. Escaped
diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp 
b/clang-tools-extra/clangd/refactor/Rename.cpp
index 4f945f74e8..e5686c963a 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -585,11 +585,9 @@ renameWithinFile(ParsedAST &AST, const NamedDecl 
&RenameDecl,
 for (const auto &Loc : Locs)
   Ranges.push_back(tokenRangeForLoc(Loc, SM, LangOpts));
 auto FilePath = AST.tuPath();
-auto RenameRanges =
-adjustRenameRanges(Code, RenameIdentifier,
-   std::move(Ranges),
-   RenameDecl.getASTContext().getLangOpts(),
-   MD->getSelector());
+auto RenameRanges = adjustRenameRanges(
+Code, RenameIdentifier, std::move(Ranges),
+RenameDecl.getASTContext().getLangOpts(), MD->getSelector());
 if (!RenameRanges) {
   // Our heuristics fails to adjust rename ranges to the current state of
   // the file, it is most likely the index is stale, so we give up the
@@ -598,8 +596,7 @@ renameWithinFile(ParsedAST &AST, const NamedDecl 
&RenameDecl,
"(selector handling may be incorrect)",
FilePath);
 }
-auto RenameEdit =
-buildRenameEdit(FilePath, Code, *RenameRanges, NewNames);
+auto RenameEdit = buildRenameEdit(FilePath, Code, *RenameRanges, NewNames);
 if (!RenameEdit)
   return error("failed to rename in file {0}: {1}", FilePath,
RenameEdit.takeError());
@@ -736,8 +733,7 @@ renameOutsideFile(const NamedDecl &RenameDecl, 
llvm::StringRef MainFilePath,
 auto RenameRanges =
 adjustRenameRanges(AffectedFileCode, RenameIdentifier,
std::move(FileAndOccurrences.second),
-   RenameDecl.getASTContext().getLangOpts(),
-   Selector);
+

[clang-tools-extra] Add support for renaming objc methods, even those with multiple selector pieces (PR #76466)

2023-12-27 Thread David Goldman via cfe-commits

https://github.com/DavidGoldman updated 
https://github.com/llvm/llvm-project/pull/76466

>From 4caf5b3c779bf18236b4b0be5bc7147d10339f2b Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 15:59:01 -0500
Subject: [PATCH 1/6] [clangd][SymbolCollector] Treat ObjC methods as spelled

We'll treat multi-arg methods as spelled once we have full rename
support for them.
---
 .../clangd/index/SymbolCollector.cpp  |  6 ++-
 .../clangd/unittests/SymbolCollectorTests.cpp | 42 +++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index 7ef4b15febad22..336bc3506bb360 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -174,7 +174,9 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
   auto Name = ND.getDeclName();
   const auto NameKind = Name.getNameKind();
   if (NameKind != DeclarationName::Identifier &&
-  NameKind != DeclarationName::CXXConstructorName)
+  NameKind != DeclarationName::CXXConstructorName &&
+  NameKind != DeclarationName::ObjCZeroArgSelector &&
+  NameKind != DeclarationName::ObjCOneArgSelector)
 return false;
   const auto &AST = ND.getASTContext();
   const auto &SM = AST.getSourceManager();
@@ -183,6 +185,8 @@ bool isSpelled(SourceLocation Loc, const NamedDecl &ND) {
   if (clang::Lexer::getRawToken(Loc, Tok, SM, LO))
 return false;
   auto StrName = Name.getAsString();
+  if (const auto *MD = dyn_cast(&ND))
+StrName = MD->getSelector().getNameForSlot(0).str();
   return clang::Lexer::getSpelling(Tok, SM, LO) == StrName;
 }
 } // namespace
diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 9cdc57ec01f327..1d4e1c1d75ea23 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -105,6 +105,9 @@ MATCHER(refRange, "") {
 MATCHER_P2(OverriddenBy, Subject, Object, "") {
   return arg == Relation{Subject.ID, RelationKind::OverriddenBy, Object.ID};
 }
+MATCHER(isSpelled, "") {
+  return static_cast(arg.Kind & RefKind::Spelled);
+}
 ::testing::Matcher &>
 haveRanges(const std::vector Ranges) {
   return ::testing::UnorderedPointwise(refRange(), Ranges);
@@ -524,6 +527,45 @@ TEST_F(SymbolCollectorTest, templateArgs) {
  forCodeCompletion(false);
 }
 
+TEST_F(SymbolCollectorTest, ObjCRefs) {
+  Annotations Header(R"(
+  @interface Person
+  - (void)$talk[[talk]];
+  - (void)$say[[say]]:(id)something;
+  @end
+  @interface Person (Category)
+  - (void)categoryMethod;
+  - (void)multiArg:(id)a method:(id)b;
+  @end
+  )");
+  Annotations Main(R"(
+  @implementation Person
+  - (void)$talk[[talk]] {}
+  - (void)$say[[say]]:(id)something {}
+  @end
+
+  void fff(Person *p) {
+[p $talk[[talk]]];
+[p $say[[say]]:0];
+[p categoryMethod];
+[p multiArg:0 method:0];
+  }
+  )");
+  CollectorOpts.RefFilter = RefKind::All;
+  CollectorOpts.CollectMainFileRefs = true;
+  TestFileName = testPath("test.m");
+  runSymbolCollector(Header.code(), Main.code(),
+ {"-fblocks", "-xobjective-c++", "-Wno-objc-root-class"});
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::talk").ID,
+  haveRanges(Main.ranges("talk");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
+  haveRanges(Main.ranges("say");
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::categoryMethod").ID,
+  ElementsAre(isSpelled();
+  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::multiArg:method:").ID,
+  ElementsAre(Not(isSpelled());
+}
+
 TEST_F(SymbolCollectorTest, ObjCSymbols) {
   const std::string Header = R"(
 @interface Person

>From 1b6a09464ff5c7b1988fcb479d0a4ff876f696e6 Mon Sep 17 00:00:00 2001
From: David Goldman 
Date: Tue, 26 Dec 2023 16:12:03 -0500
Subject: [PATCH 2/6] Run clang-format

---
 .../clangd/unittests/SymbolCollectorTests.cpp  | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 1d4e1c1d75ea23..5c20b950e4eac0 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -560,10 +560,12 @@ TEST_F(SymbolCollectorTest, ObjCRefs) {
   haveRanges(Main.ranges("talk");
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
   haveRanges(Main.ranges("say");
-  EXPECT_THAT(Refs, Contains(Pair(findSymbol

[clang] [RISCV][NFC] Use errorToBool (PR #76429)

2023-12-27 Thread Craig Topper via cfe-commits

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

LGTM

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


[clang] [RISCV][NFC] Use RISCVISAInfo instead of string comparison (PR #76387)

2023-12-27 Thread Craig Topper via cfe-commits

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

LGTM

https://github.com/llvm/llvm-project/pull/76387
___
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 check readability-return-expression-in-void-function (PR #76249)

2023-12-27 Thread Danny Mösch via cfe-commits

https://github.com/SimplyDanny updated 
https://github.com/llvm/llvm-project/pull/76249

From 0257d24b12fe60d7d0fd758f4e843db3caf9a623 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Danny=20M=C3=B6sch?= 
Date: Fri, 22 Dec 2023 17:09:59 +0100
Subject: [PATCH 01/13] [clang-tidy] Add check
 readability-return-expression-in-void-function

---
 .../clang-tidy/readability/CMakeLists.txt |  1 +
 .../readability/ReadabilityTidyModule.cpp |  3 ++
 .../ReturnExpressionInVoidFunctionCheck.cpp   | 31 +++
 .../ReturnExpressionInVoidFunctionCheck.h | 30 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  7 +
 .../docs/clang-tidy/checks/list.rst   |  1 +
 .../return-expression-in-void-function.rst| 30 ++
 .../return-expression-in-void-function.cpp| 23 ++
 8 files changed, 126 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/readability/return-expression-in-void-function.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/return-expression-in-void-function.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
index 5452c2d48a4617..7d0399ed901267 100644
--- a/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/readability/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangTidyReadabilityModule
   RedundantStringCStrCheck.cpp
   RedundantStringInitCheck.cpp
   ReferenceToConstructedTemporaryCheck.cpp
+  ReturnExpressionInVoidFunctionCheck.cpp
   SimplifyBooleanExprCheck.cpp
   SimplifySubscriptExprCheck.cpp
   StaticAccessedThroughInstanceCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp 
b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
index b8e6e641432060..2a9134071b9a72 100644
--- a/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
@@ -45,6 +45,7 @@
 #include "RedundantStringCStrCheck.h"
 #include "RedundantStringInitCheck.h"
 #include "ReferenceToConstructedTemporaryCheck.h"
+#include "ReturnExpressionInVoidFunctionCheck.h"
 #include "SimplifyBooleanExprCheck.h"
 #include "SimplifySubscriptExprCheck.h"
 #include "StaticAccessedThroughInstanceCheck.h"
@@ -119,6 +120,8 @@ class ReadabilityModule : public ClangTidyModule {
 "readability-redundant-preprocessor");
 CheckFactories.registerCheck(
 "readability-reference-to-constructed-temporary");
+CheckFactories.registerCheck(
+"readability-return-expression-in-void-function");
 CheckFactories.registerCheck(
 "readability-simplify-subscript-expr");
 CheckFactories.registerCheck(
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
new file mode 100644
index 00..2308d0782ae1c3
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.cpp
@@ -0,0 +1,31 @@
+//===--- ReturnExpressionInVoidFunctionCheck.cpp - clang-tidy 
-===//
+//
+// 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
+//
+//===--===//
+
+#include "ReturnExpressionInVoidFunctionCheck.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+void ReturnExpressionInVoidFunctionCheck::registerMatchers(
+MatchFinder *Finder) {
+  Finder->addMatcher(
+  returnStmt(hasReturnValue(hasType(voidType(.bind("void_return"),
+  this);
+}
+
+void ReturnExpressionInVoidFunctionCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *VoidReturn = Result.Nodes.getNodeAs("void_return");
+  diag(VoidReturn->getBeginLoc(), "return statements should not return void");
+}
+
+} // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
new file mode 100644
index 00..e28f9cebd2620e
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/readability/ReturnExpressionInVoidFunctionCheck.h
@@ -0,0 +1,30 @@
+//===--- ReturnExpressionInVoidFunctionCheck.h - clang-tidy -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.

[clang-tools-extra] [clang-tidy] Add check readability-return-expression-in-void-function (PR #76249)

2023-12-27 Thread Danny Mösch via cfe-commits

SimplyDanny wrote:

> I think that both IgnoreMacros and StrictMode(false) could be needed. If 
> StrictMode is false then only returnStmt that got compoundStmt as parent 
> should be check, to reduce impact.

Fair points. Both options are added now. However, I'm not sure about the name 
of the second one `StrictMode`. It doesn't imply its purpose. Do you think we 
should pick a more descriptive name?

I also found a case involving initializer lists that requires special 
treatment, because the list is seen as an expression returning `void`. This is 
addressed in the [last 
commit](https://github.com/llvm/llvm-project/pull/76249/commits/ce006f2957402a8a7bacc023cc96963b211e1290).

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


[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu created 
https://github.com/llvm/llvm-project/pull/76471

This PR exposes three PGO functions `__llvm_profile_reset_counters`, 
`__llvm_profile_dump` and `__llvm_orderfile_dump` to user programs through the 
new header `instr_prof_interface.h` under `compiler-rt/include/profile`. This 
way, the user can include the header `profile/instr_prof_interface.h` to 
introduce these three names to their programs. 

Additionally, this PR defines macro `__LLVM_INSTR_PROFILE_GENERATE` when the 
program is compiled with profile generation, and defines macro 
`__LLVM_INSTR_PROFILE_USE` when the program is compiled with profile use. 
`__LLVM_INSTR_PROFILE_GENERATE` together with `instr_prof_interface.h` define 
the three PGO functions only when the program is compiled with profile 
generation. When profile generation is off, these PGO functions are defined 
away and leave no trace in the user's program. 



>From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 27 Dec 2023 13:05:01 -0500
Subject: [PATCH 1/4] Initial commit

---
 .../ExpandModularHeadersPPCallbacks.cpp   |  2 +-
 clang/include/clang/Frontend/Utils.h  |  4 +-
 clang/lib/Frontend/CompilerInstance.cpp   |  2 +-
 clang/lib/Frontend/InitPreprocessor.cpp   | 12 ++--
 compiler-rt/include/CMakeLists.txt|  1 +
 .../include/profile/instr_prof_interface.h| 66 +++
 compiler-rt/lib/profile/InstrProfiling.h  | 32 +
 7 files changed, 83 insertions(+), 36 deletions(-)
 create mode 100644 compiler-rt/include/profile/instr_prof_interface.h

diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index e414ac8c770508..5ecd4fb19131e4 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -100,7 +100,7 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
   /*OwnsHeaderSearch=*/false);
   PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
   InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
- Compiler.getFrontendOpts());
+ Compiler.getFrontendOpts(), 
Compiler.getCodeGenOpts());
   ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
Compiler.getTarget().getTriple());
 }
diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 143cf4359f00b5..604e42067a3f1e 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -43,12 +43,14 @@ class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
+class CodeGenOptions;
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions 
&PPOpts,
 const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts);
+const FrontendOptions &FEOpts,
+const CodeGenOptions &CodeGenOpts);
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 56bbef9697b650..ea44a26b6db7da 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -470,7 +470,7 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Predefine macros and configure the preprocessor.
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
- getFrontendOpts());
+ getFrontendOpts(), getCodeGenOpts());
 
   // Initialize the header search object.  In CUDA compilations, we use the aux
   // triple (the host triple) to initialize our header search, since we need to
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index d83128adb511ef..009a67eea1eb52 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
-void clang::InitializePreprocessor(
-Preprocessor &PP, const PreprocessorOptions &InitOpts,
-const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts) {
+void clang::InitializePreprocessor(Preprocessor &PP,
+   const PreprocessorOptions &InitOpts,
+   

[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qiongsi Wu (qiongsiwu)


Changes

This PR exposes three PGO functions `__llvm_profile_reset_counters`, 
`__llvm_profile_dump` and `__llvm_orderfile_dump` to user programs through the 
new header `instr_prof_interface.h` under `compiler-rt/include/profile`. This 
way, the user can include the header `profile/instr_prof_interface.h` to 
introduce these three names to their programs. 

Additionally, this PR defines macro `__LLVM_INSTR_PROFILE_GENERATE` when the 
program is compiled with profile generation, and defines macro 
`__LLVM_INSTR_PROFILE_USE` when the program is compiled with profile use. 
`__LLVM_INSTR_PROFILE_GENERATE` together with `instr_prof_interface.h` define 
the three PGO functions only when the program is compiled with profile 
generation. When profile generation is off, these PGO functions are defined 
away and leave no trace in the user's program. 



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


10 Files Affected:

- (modified) clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
(+1-1) 
- (modified) clang/include/clang/Basic/CodeGenOptions.h (+6) 
- (modified) clang/include/clang/Frontend/Utils.h (+3-1) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+1-1) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+19-4) 
- (modified) clang/test/Profile/c-general.c (+9) 
- (modified) compiler-rt/include/CMakeLists.txt (+1) 
- (added) compiler-rt/include/profile/instr_prof_interface.h (+66) 
- (modified) compiler-rt/lib/profile/InstrProfiling.h (+3-29) 
- (added) compiler-rt/test/profile/instrprof-api.c (+26) 


``diff
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index e414ac8c770508..5ecd4fb19131e4 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -100,7 +100,7 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
   /*OwnsHeaderSearch=*/false);
   PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
   InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
- Compiler.getFrontendOpts());
+ Compiler.getFrontendOpts(), 
Compiler.getCodeGenOpts());
   ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
Compiler.getTarget().getTriple());
 }
diff --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 6952b48e898a81..e06f1094784caf 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -494,6 +494,12 @@ class CodeGenOptions : public CodeGenOptionsBase {
 return getProfileInstr() == ProfileCSIRInstr;
   }
 
+  /// Check if any form of instrumentation is on.
+  bool hasProfileInstr() const {
+return hasProfileClangInstr() || hasProfileIRInstr() ||
+   hasProfileCSIRInstr();
+  }
+
   /// Check if Clang profile use is on.
   bool hasProfileClangUse() const {
 return getProfileUse() == ProfileClangInstr;
diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 143cf4359f00b5..604e42067a3f1e 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -43,12 +43,14 @@ class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
+class CodeGenOptions;
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions 
&PPOpts,
 const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts);
+const FrontendOptions &FEOpts,
+const CodeGenOptions &CodeGenOpts);
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 56bbef9697b650..ea44a26b6db7da 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -470,7 +470,7 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Predefine macros and configure the preprocessor.
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
- getFrontendOpts());
+ getFrontendOpts(), getCodeGenOpts());
 
   // Initialize the header search object.  In CUDA compilations, we use the aux
   // triple (the host triple) to initialize our header search, since we need to
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Fro

[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

Note to reviewers: I am only adding these three PGO functions because I am not 
sure if more should be added. Please let me know, and I will revise the PR. 

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


[clang] [analyzer][docs] Update the release notes for llvm-18 (PR #76446)

2023-12-27 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.


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


[clang] [analyzer][docs] Update the release notes for llvm-18 (PR #76446)

2023-12-27 Thread Gábor Horváth via cfe-commits


@@ -1072,16 +1146,36 @@ Static Analyzer
   Read the PR for the details.
   (`#66086 `_)
 
+- Other taint-related improvements.
+  (`#66358 `_,
+  `#66074 `_,
+  `#66358 `_)
+
 - A few crashes have been found and fixed using randomized testing related
-  to the use of ``_BitInt()`` in tidy checks and in clang analysis. See
-  `#67212 `_,
+  to the use of ``_BitInt()`` in tidy checks and in clang analysis.
+  (`#67212 `_,
   `#66782 `_,
   `#65889 `_,
-  `#65888 `_, and
-  `#65887 `_
+  `#65888 `_,
+  `#65887 `_)
 
-- Move checker ``alpha.cplusplus.EnumCastOutOfRange`` out of the ``alpha``
-  package to ``optin.core.EnumCastOutOfRange``.
+- Fixed note links of the HTML output.
+  (`#64054 `_)
+
+- Allow widening rage-based for loops.
+  (`#70190 `_)
+
+- Fixed uninitialized base class with initializer list when ctor is not
+  declared in the base class.
+  (`#70464 `_,
+  `#59493 `_,
+  `#54533 `_)
+
+- Added support for the ``cleanup`` attribute.
+  `Documentation 
`__.

Xazax-hun wrote:

In some cases, we link to the PR/commit, in other cases only to the 
documentation. I am OK with this, I was only wondering whether we want to add 
links to the commits everywhere. Feel free to ignore.

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


[clang] [analyzer][docs] Update the release notes for llvm-18 (PR #76446)

2023-12-27 Thread Gábor Horváth via cfe-commits

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


[clang] [analyzer][docs] Update the release notes for llvm-18 (PR #76446)

2023-12-27 Thread Gábor Horváth via cfe-commits


@@ -1052,18 +1052,92 @@ libclang
 Static Analyzer
 ---
 
+- Implemented the ``[[clang::suppress]]`` attribute for suppressing diagnostics
+  of static analysis tools, such as the Clang Static Analyzer.
+  `Documentation 
`__.
+
+- Added a new experimental checker ``alpha.core.StdVariant`` to detect variant
+  accesses via wrong alternatives.
+  (`#66481 `_)
+
+- Added a new experimental checker ``alpha.cplusplus.ArrayDelete`` to detect
+  destructions of arrays of polymorphic objects that are destructed as their
+  base class (`CERT EXP51-CPP 
`_).
+  `Documentation 
`__.
+  (`0e246bb67573 
`_)
+
 - Added a new checker ``core.BitwiseShift`` which reports situations where
   bitwise shift operators produce undefined behavior (because some operand is
   negative or too large).
+  `Documentation 
`__.
+
+- Support "Deducing this" (P0847R7). (Worked out of the box)
+  (`af4751738db8 
`__)
 
 - Move checker ``alpha.unix.Errno`` out of the ``alpha`` package
   to ``unix.Errno``.
+  `Documentation 
`__.
 
 - Move checker ``alpha.unix.StdCLibraryFunctions`` out of the ``alpha`` package
   to ``unix.StdCLibraryFunctions``.
 
+- Added a new checker configuration option to

Xazax-hun wrote:

Maybe we want to have a short sentence about what the configuration option is 
doing?

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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Teresa Johnson via cfe-commits

teresajohnson wrote:

The way we have done this in the past is to declare these as weak symbols and 
check if they exist before calling. E.g.:

```
extern "C" __attribute__((weak)) int __llvm_profile_dump(void);

if (__llvm_profile_dump)
  if (__llvm_profile_dump() != 0) { ...
```

Not necessarily opposed to adding the macros etc, but the advantage of the weak 
symbol approach vs what you have here is that the user code can check the 
return values.

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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Snehasish Kumar via cfe-commits

snehasish wrote:

@teresajohnson I mentioned the same thing on 
[discourse](https://discourse.llvm.org/t/pgo-are-the-llvm-profile-functions-stable-c-apis-across-llvm-releases/75832/5)
 but it seems like linking on AIX does not support this model.

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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Snehasish Kumar via cfe-commits


@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes();
 ValueProfNode *__llvm_profile_end_vnodes();
 uint32_t *__llvm_profile_begin_orderfile();
 
-/*!
- * \brief Clear profile counters to zero.
- *
- */
-void __llvm_profile_reset_counters(void);

snehasish wrote:

I think removing these methods from the InstrProfiling.h header may break 
downstream users. Instead can you add a wrapper around these methods in the new 
header? These wrappers can then be guarded by  __LLVM_INSTR_PROFILE_GENERATE .

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


[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Snehasish Kumar via cfe-commits


@@ -0,0 +1,26 @@
+// RUN: %clang_profgen %s -S -emit-llvm -o - | FileCheck %s 
--check-prefix=PROFGEN
+// RUN: %clang_profgen -o %t %s
+// RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: %clang_profuse=%t.profdata %s -S -emit-llvm -o - | FileCheck %s 
--check-prefix=PROFUSE
+#include "profile/instr_profiling.h"
+
+__attribute__((noinline)) int bar() { return 4; }
+
+int foo() {
+  __llvm_profile_reset_counters();

snehasish wrote:

Can you also add a test with the weak linking approach to ensure that is 
unaffected?

(Maybe there exists one already but I'm not sure).

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


[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Snehasish Kumar via cfe-commits


@@ -44,6 +44,7 @@ endif(COMPILER_RT_BUILD_ORC)
 if (COMPILER_RT_BUILD_PROFILE)
   set(PROFILE_HEADERS
 profile/InstrProfData.inc
+profile/instr_prof_interface.h

snehasish wrote:

Can you rename the header to follow the existing CamelCase convention? 

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


[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Snehasish Kumar via cfe-commits


@@ -1364,12 +1364,22 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   TI.getTargetDefines(LangOpts, Builder);
 }
 
+static void InitializePGOProfileMacros(const CodeGenOptions &CodeGenOpts,

snehasish wrote:

There are IR PGO users (e.g. Rust) which don't use the clang frontend. Do we 
need this macro based checks? 

I would prefer to just limit this patch to exposing the necessary interfaces. 
End-users can manage their own macros if they want to exclude the profile APIs 
from the source. 

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


[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/76471

>From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 27 Dec 2023 13:05:01 -0500
Subject: [PATCH 1/5] Initial commit

---
 .../ExpandModularHeadersPPCallbacks.cpp   |  2 +-
 clang/include/clang/Frontend/Utils.h  |  4 +-
 clang/lib/Frontend/CompilerInstance.cpp   |  2 +-
 clang/lib/Frontend/InitPreprocessor.cpp   | 12 ++--
 compiler-rt/include/CMakeLists.txt|  1 +
 .../include/profile/instr_prof_interface.h| 66 +++
 compiler-rt/lib/profile/InstrProfiling.h  | 32 +
 7 files changed, 83 insertions(+), 36 deletions(-)
 create mode 100644 compiler-rt/include/profile/instr_prof_interface.h

diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index e414ac8c770508..5ecd4fb19131e4 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -100,7 +100,7 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
   /*OwnsHeaderSearch=*/false);
   PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
   InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
- Compiler.getFrontendOpts());
+ Compiler.getFrontendOpts(), 
Compiler.getCodeGenOpts());
   ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
Compiler.getTarget().getTriple());
 }
diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 143cf4359f00b5..604e42067a3f1e 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -43,12 +43,14 @@ class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
+class CodeGenOptions;
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions 
&PPOpts,
 const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts);
+const FrontendOptions &FEOpts,
+const CodeGenOptions &CodeGenOpts);
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 56bbef9697b650..ea44a26b6db7da 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -470,7 +470,7 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Predefine macros and configure the preprocessor.
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
- getFrontendOpts());
+ getFrontendOpts(), getCodeGenOpts());
 
   // Initialize the header search object.  In CUDA compilations, we use the aux
   // triple (the host triple) to initialize our header search, since we need to
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index d83128adb511ef..009a67eea1eb52 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
-void clang::InitializePreprocessor(
-Preprocessor &PP, const PreprocessorOptions &InitOpts,
-const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts) {
+void clang::InitializePreprocessor(Preprocessor &PP,
+   const PreprocessorOptions &InitOpts,
+   const PCHContainerReader &PCHContainerRdr,
+   const FrontendOptions &FEOpts,
+   const CodeGenOptions &CodeGenOpts) {
   const LangOptions &LangOpts = PP.getLangOpts();
   std::string PredefineBuffer;
   PredefineBuffer.reserve(4080);
@@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor(
   InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
  FEOpts, Builder);
 
+  if (CodeGenOpts.hasProfileIRInstr())
+Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE");
+
   // Add on the predefines from the driver.  Wrap in a #line directive to 
report
   // that they come from the command line.
   Builder.append("# 1 \"\" 1");
diff --git a/compiler-rt/include/CMakeLists.txt 
b/compiler-rt/include/CMakeLists.txt
index

[clang-tools-extra] [compiler-rt] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Teresa Johnson via cfe-commits

teresajohnson wrote:

> @teresajohnson I mentioned the same thing on 
> [discourse](https://discourse.llvm.org/t/pgo-are-the-llvm-profile-functions-stable-c-apis-across-llvm-releases/75832/5)
>  but it seems like linking on AIX does not support this model.

I see. Perhaps instead of defining these away completely, they should be 
defined to a dummy function with the same signature that always returns success 
(0 I think)? Alternatively, not define them at all when 
__LLVM_INSTR_PROFILE_GENERATE not defined and have the user guard calls by 
`#ifdef __LLVM_INSTR_PROFILE_GENERATE`. Otherwise, the user either cannot check 
the return values, or they have to guard their usage by a check of 
__LLVM_INSTR_PROFILE_GENERATE anyway.

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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

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


[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits


@@ -44,6 +44,7 @@ endif(COMPILER_RT_BUILD_ORC)
 if (COMPILER_RT_BUILD_PROFILE)
   set(PROFILE_HEADERS
 profile/InstrProfData.inc
+profile/instr_prof_interface.h

qiongsiwu wrote:

Yes absolutely! That said, I am following the existing convention for interface 
headers in other runtime components. See 
https://github.com/llvm/llvm-project/pull/76471/files/b741a557715eb17b69fa5b4013f2efeadcb80fda#diff-acb14b664a9f7bf0598dfd6e22dad2071ac4106753612c9f0cf3ab96bfeac0afR25,
 
https://github.com/llvm/llvm-project/pull/76471/files/b741a557715eb17b69fa5b4013f2efeadcb80fda#diff-acb14b664a9f7bf0598dfd6e22dad2071ac4106753612c9f0cf3ab96bfeac0afL32
 and numerous ones here 
https://github.com/llvm/llvm-project/pull/76471/files/b741a557715eb17b69fa5b4013f2efeadcb80fda#diff-acb14b664a9f7bf0598dfd6e22dad2071ac4106753612c9f0cf3ab96bfeac0afR3.
 Could you confirm which convention I should follow? 

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


[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits


@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes();
 ValueProfNode *__llvm_profile_end_vnodes();
 uint32_t *__llvm_profile_begin_orderfile();
 
-/*!
- * \brief Clear profile counters to zero.
- *
- */
-void __llvm_profile_reset_counters(void);

qiongsiwu wrote:

These functions are not actually removed from this file because the new header 
`instr_prof_interface.h` is included in this file (see 
https://github.com/llvm/llvm-project/pull/76471/files#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR16).
 Are there downstream use cases that pull out 
`compiler-rt/lib/profile/InstrProfiling.h` and use it by itself? 

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


[clang] [compiler-rt] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu commented:

Thanks so much @snehasish for the fast review! I have two questions regarding 
your comments. I will address the remaining comments soon as well! 

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


[clang-tools-extra] [clang] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Snehasish Kumar via cfe-commits


@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes();
 ValueProfNode *__llvm_profile_end_vnodes();
 uint32_t *__llvm_profile_begin_orderfile();
 
-/*!
- * \brief Clear profile counters to zero.
- *
- */
-void __llvm_profile_reset_counters(void);

snehasish wrote:

They are effectively removed if the frontend does not define 
__LLVM_INSTR_PROFILE_GENERATE (see my other comment). I would prefer the 
dependency to be in the other direction, include InstrProfiling.h in the 
interface `instr_prof_interface.h`.

> Are there downstream use cases that pull out 
> compiler-rt/lib/profile/InstrProfiling.h and use it by itself?

Yes, we have one internal user that I can find.


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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Snehasish Kumar via cfe-commits


@@ -44,6 +44,7 @@ endif(COMPILER_RT_BUILD_ORC)
 if (COMPILER_RT_BUILD_PROFILE)
   set(PROFILE_HEADERS
 profile/InstrProfData.inc
+profile/instr_prof_interface.h

snehasish wrote:

Good point, looks like we treat `interface` filenames with snake case as 
opposed to headers. Please ignore this comment.

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


[clang] [Serialization] Fix instantiated default arguments (PR #76473)

2023-12-27 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo created 
https://github.com/llvm/llvm-project/pull/76473

`ParmVarDecl::getDefaultArg()` strips the outermost `FullExpr`, such as 
`ExprWithCleanups`. This leads to an `llvm_unreachable` being executed with the 
added test `clang/test/Modules/pr68702.cpp`; instead use the more generic 
`VarDecl::getInit()` which also returns `FullExpr`'s.

Closes https://github.com/llvm/llvm-project/issues/68702

>From def58be1572162b4862e37ba983793e422208d38 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Wed, 27 Dec 2023 23:10:13 +0100
Subject: [PATCH] [Serialization] Fix instantiated default arguments

ParmVarDecl::getDefaultArg() strips the outermost FullExpr, such as
ExprWithCleanups. This leads to an llvm_unreachable being executed
with the added test clang/test/Modules/pr68702.cpp; instead use the
more generic VarDecl::getInit() which also returns FullExpr's.

Closes https://github.com/llvm/llvm-project/issues/68702
---
 clang/lib/Serialization/ASTWriter.cpp |  6 ++-
 clang/test/Modules/pr68702.cpp| 65 +++
 2 files changed, 69 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Modules/pr68702.cpp

diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 78939bfd533ffa..b9f65dc6d452fc 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5293,8 +5293,10 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl 
&OffsetsRecord) {
 break;
 
   case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT:
-Record.AddStmt(const_cast(
-cast(Update.getDecl())->getDefaultArg()));
+// Do not use ParmVarDecl::getDefaultArg(): It strips the outermost
+// FullExpr, such as ExprWithCleanups.
+Record.AddStmt(
+const_cast(cast(Update.getDecl())->getInit()));
 break;
 
   case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER:
diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
new file mode 100644
index 00..d32f946910f4fb
--- /dev/null
+++ b/clang/test/Modules/pr68702.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {
+  export *
+  module "V.h" {
+export *
+header "V.h"
+  }
+  module "inst1.h" {
+export *
+header "inst1.h"
+  }
+}
+
+module "inst2.h" {
+  export *
+  header "inst2.h"
+}
+
+//--- main.cpp
+#include "V.h"
+#include "inst2.h"
+
+static void m() {
+  static V v(100);
+}

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


[clang] [Serialization] Fix instantiated default arguments (PR #76473)

2023-12-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Jonas Hahnfeld (hahnjo)


Changes

`ParmVarDecl::getDefaultArg()` strips the outermost `FullExpr`, such as 
`ExprWithCleanups`. This leads to an `llvm_unreachable` being executed with the 
added test `clang/test/Modules/pr68702.cpp`; instead use the more generic 
`VarDecl::getInit()` which also returns `FullExpr`'s.

Closes https://github.com/llvm/llvm-project/issues/68702

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


2 Files Affected:

- (modified) clang/lib/Serialization/ASTWriter.cpp (+4-2) 
- (added) clang/test/Modules/pr68702.cpp (+65) 


``diff
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 78939bfd533ffa..b9f65dc6d452fc 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5293,8 +5293,10 @@ void ASTWriter::WriteDeclUpdatesBlocks(RecordDataImpl 
&OffsetsRecord) {
 break;
 
   case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT:
-Record.AddStmt(const_cast(
-cast(Update.getDecl())->getDefaultArg()));
+// Do not use ParmVarDecl::getDefaultArg(): It strips the outermost
+// FullExpr, such as ExprWithCleanups.
+Record.AddStmt(
+const_cast(cast(Update.getDecl())->getInit()));
 break;
 
   case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER:
diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
new file mode 100644
index 00..d32f946910f4fb
--- /dev/null
+++ b/clang/test/Modules/pr68702.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {
+  export *
+  module "V.h" {
+export *
+header "V.h"
+  }
+  module "inst1.h" {
+export *
+header "inst1.h"
+  }
+}
+
+module "inst2.h" {
+  export *
+  header "inst2.h"
+}
+
+//--- main.cpp
+#include "V.h"
+#include "inst2.h"
+
+static void m() {
+  static V v(100);
+}

``




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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits


@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes();
 ValueProfNode *__llvm_profile_end_vnodes();
 uint32_t *__llvm_profile_begin_orderfile();
 
-/*!
- * \brief Clear profile counters to zero.
- *
- */
-void __llvm_profile_reset_counters(void);

qiongsiwu wrote:

> They are effectively removed if the frontend does not define 
> __LLVM_INSTR_PROFILE_GENERATE (see my other comment).

`__LLVM_INSTR_PROFILE_GENERATE` is defined explicitly in this header 
`compiler-rt/lib/profile/InstrProfiling.h` before the new header is included 
(see 
https://github.com/llvm/llvm-project/pull/76471/files#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR15)
 so that we do not depend on the frontend for the macro in the compiler-rt 
context, and we make sure that these three names are always available 
(regardless of frontend options). 

I am trying to avoid wrappers or duplicating definitions. [This 
comment](https://discourse.llvm.org/t/pgo-are-the-llvm-profile-functions-stable-c-apis-across-llvm-releases/75832/7?u=qwu_ibm)
 seem to imply that creating wrapper or duplicating definition is not 
desirable. However, if avoiding wrapper or duplication is making downstream 
code unnecessarily complicated, I will create the wrappers instead. 

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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

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


[compiler-rt] [clang] [clang-tools-extra] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits


@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes();
 ValueProfNode *__llvm_profile_end_vnodes();
 uint32_t *__llvm_profile_begin_orderfile();
 
-/*!
- * \brief Clear profile counters to zero.
- *
- */
-void __llvm_profile_reset_counters(void);

qiongsiwu wrote:

> I would prefer the dependency to be in the other direction, include 
> InstrProfiling.h in the interface instr_prof_interface.h.

Hmmm this is also something I am trying to avoid. The reason is that we are 
trying to not expose PGO internal definitions to the user. The intention is 
that a user can safely include `instr_prof_interface.h` in their program to use 
these public PGO APIs, without introducing all the PGO internal symbols to 
their programs.

Could you help me understand the advantage for `instr_prof_interface.h` to 
include `InstrProfiling.h`? 

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-12-27 Thread Jonas Hahnfeld via cfe-commits

https://github.com/hahnjo updated 
https://github.com/llvm/llvm-project/pull/69076

>From a55ca99a373b17501d56d18af9e8aa2dc2cbcea0 Mon Sep 17 00:00:00 2001
From: Jonas Hahnfeld 
Date: Sat, 14 Oct 2023 20:10:28 +0200
Subject: [PATCH] Fix crash with modules and constexpr destructor

With modules, serialization might omit the outer ExprWithCleanups
as it calls ParmVarDecl::getDefaultArg(). Complementary to fixing
this in a separate change, make the code more robust by adding a
FullExpressionRAII and avoid the llvm_unreachable in the added test
clang/test/Modules/pr68702.cpp.

Closes https://github.com/llvm/llvm-project/issues/68702
---
 clang/lib/AST/ExprConstant.cpp | 16 ++---
 clang/test/Modules/pr68702.cpp | 65 ++
 2 files changed, 77 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Modules/pr68702.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..416d48ae82933f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15754,10 +15754,18 @@ bool Expr::EvaluateAsInitializer(APValue &Value, 
const ASTContext &Ctx,
 LValue LVal;
 LVal.set(VD);
 
-if (!EvaluateInPlace(Value, Info, LVal, this,
- /*AllowNonLiteralTypes=*/true) ||
-EStatus.HasSideEffects)
-  return false;
+{
+  // C++23 [intro.execution]/p5
+  // A full-expression is ... an init-declarator ([dcl.decl]) or a
+  // mem-initializer.
+  // So we need to make sure temporary objects are destroyed after having
+  // evaluated the expression (per C++23 [class.temporary]/p4).
+  FullExpressionRAII Scope(Info);
+  if (!EvaluateInPlace(Value, Info, LVal, this,
+   /*AllowNonLiteralTypes=*/true) ||
+  EStatus.HasSideEffects)
+return false;
+}
 
 // At this point, any lifetime-extended temporaries are completely
 // initialized.
diff --git a/clang/test/Modules/pr68702.cpp b/clang/test/Modules/pr68702.cpp
new file mode 100644
index 00..d32f946910f4fb
--- /dev/null
+++ b/clang/test/Modules/pr68702.cpp
@@ -0,0 +1,65 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -fmodules -fimplicit-module-maps 
-fmodules-cache-path=%t %t/main.cpp -o %t/main.o
+
+//--- V.h
+#ifndef V_H
+#define V_H
+
+class A {
+public:
+  constexpr A() { }
+  constexpr ~A() { }
+};
+
+template 
+class V {
+public:
+  V() = default;
+
+  constexpr V(int n, const A& a = A()) {}
+};
+
+#endif
+
+//--- inst1.h
+#include "V.h"
+
+static void inst1() {
+  V v;
+}
+
+//--- inst2.h
+#include "V.h"
+
+static void inst2() {
+  V v(100);
+}
+
+//--- module.modulemap
+module "M" {
+  export *
+  module "V.h" {
+export *
+header "V.h"
+  }
+  module "inst1.h" {
+export *
+header "inst1.h"
+  }
+}
+
+module "inst2.h" {
+  export *
+  header "inst2.h"
+}
+
+//--- main.cpp
+#include "V.h"
+#include "inst2.h"
+
+static void m() {
+  static V v(100);
+}

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-12-27 Thread Jonas Hahnfeld via cfe-commits

hahnjo wrote:

I finally had time to debug this: The reason for modules being involved here is 
because the serialization code calls `ParmVarDecl::getDefaultArg()` which 
strips the outermost `FullExpr`, such as `ExprWithCleanups`. A potential fix is 
in https://github.com/llvm/llvm-project/pull/76473 though I'm not really 
convinced by this asymmetry between `getInit()` but calling `setDefaultArg()`. 
However, removing the handling of `FullExpr` in `setDefaultArg()` causes a 
total 29 test failures, so that's not an (easy) option...

Personally, I would argue that adding `FullExpressionRAII` makes the code more 
robust against the absence of `ExprWithCleanups` so that's maybe a good thing 
to have regardless of fixing the serialization code.

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


[clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)

2023-12-27 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@kadircet gentle ping

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


[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Snehasish Kumar via cfe-commits


@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes();
 ValueProfNode *__llvm_profile_end_vnodes();
 uint32_t *__llvm_profile_begin_orderfile();
 
-/*!
- * \brief Clear profile counters to zero.
- *
- */
-void __llvm_profile_reset_counters(void);

snehasish wrote:

Ok, if we don't want to expose the internals then the existing approach seems 
like the simplest one. I think @davidxl's comment in the discourse thread is 
about ensuring no control flow changes in profile gen and use in hot code 
paths. This does not necessarily preclude additional wrappers. 

> Update: I think the explicit definition needs to be guarded by an #ifndef.
Yes, I misread the original as `#ifdef` causing some confusion. This should 
also be `#undef` afterwards. I was thinking about churn for existing users of 
InstrProfiling.h but it should be a no-op.

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


[clang] [clang-tools-extra] [compiler-rt] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Snehasish Kumar via cfe-commits

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


[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu updated 
https://github.com/llvm/llvm-project/pull/76471

>From 6c9381ec324595947237bd25642b03ab40b6a4df Mon Sep 17 00:00:00 2001
From: Qiongsi Wu 
Date: Wed, 27 Dec 2023 13:05:01 -0500
Subject: [PATCH 1/6] Initial commit

---
 .../ExpandModularHeadersPPCallbacks.cpp   |  2 +-
 clang/include/clang/Frontend/Utils.h  |  4 +-
 clang/lib/Frontend/CompilerInstance.cpp   |  2 +-
 clang/lib/Frontend/InitPreprocessor.cpp   | 12 ++--
 compiler-rt/include/CMakeLists.txt|  1 +
 .../include/profile/instr_prof_interface.h| 66 +++
 compiler-rt/lib/profile/InstrProfiling.h  | 32 +
 7 files changed, 83 insertions(+), 36 deletions(-)
 create mode 100644 compiler-rt/include/profile/instr_prof_interface.h

diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index e414ac8c770508..5ecd4fb19131e4 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -100,7 +100,7 @@ 
ExpandModularHeadersPPCallbacks::ExpandModularHeadersPPCallbacks(
   /*OwnsHeaderSearch=*/false);
   PP->Initialize(Compiler.getTarget(), Compiler.getAuxTarget());
   InitializePreprocessor(*PP, *PO, Compiler.getPCHContainerReader(),
- Compiler.getFrontendOpts());
+ Compiler.getFrontendOpts(), 
Compiler.getCodeGenOpts());
   ApplyHeaderSearchOptions(*HeaderInfo, *HSO, LangOpts,
Compiler.getTarget().getTriple());
 }
diff --git a/clang/include/clang/Frontend/Utils.h 
b/clang/include/clang/Frontend/Utils.h
index 143cf4359f00b5..604e42067a3f1e 100644
--- a/clang/include/clang/Frontend/Utils.h
+++ b/clang/include/clang/Frontend/Utils.h
@@ -43,12 +43,14 @@ class PCHContainerReader;
 class Preprocessor;
 class PreprocessorOptions;
 class PreprocessorOutputOptions;
+class CodeGenOptions;
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
 void InitializePreprocessor(Preprocessor &PP, const PreprocessorOptions 
&PPOpts,
 const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts);
+const FrontendOptions &FEOpts,
+const CodeGenOptions &CodeGenOpts);
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor &PP, raw_ostream *OS,
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index 56bbef9697b650..ea44a26b6db7da 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -470,7 +470,7 @@ void 
CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
 
   // Predefine macros and configure the preprocessor.
   InitializePreprocessor(*PP, PPOpts, getPCHContainerReader(),
- getFrontendOpts());
+ getFrontendOpts(), getCodeGenOpts());
 
   // Initialize the header search object.  In CUDA compilations, we use the aux
   // triple (the host triple) to initialize our header search, since we need to
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index d83128adb511ef..009a67eea1eb52 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1366,10 +1366,11 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
-void clang::InitializePreprocessor(
-Preprocessor &PP, const PreprocessorOptions &InitOpts,
-const PCHContainerReader &PCHContainerRdr,
-const FrontendOptions &FEOpts) {
+void clang::InitializePreprocessor(Preprocessor &PP,
+   const PreprocessorOptions &InitOpts,
+   const PCHContainerReader &PCHContainerRdr,
+   const FrontendOptions &FEOpts,
+   const CodeGenOptions &CodeGenOpts) {
   const LangOptions &LangOpts = PP.getLangOpts();
   std::string PredefineBuffer;
   PredefineBuffer.reserve(4080);
@@ -1416,6 +1417,9 @@ void clang::InitializePreprocessor(
   InitializeStandardPredefinedMacros(PP.getTargetInfo(), PP.getLangOpts(),
  FEOpts, Builder);
 
+  if (CodeGenOpts.hasProfileIRInstr())
+Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE");
+
   // Add on the predefines from the driver.  Wrap in a #line directive to 
report
   // that they come from the command line.
   Builder.append("# 1 \"\" 1");
diff --git a/compiler-rt/include/CMakeLists.txt 
b/compiler-rt/include/CMakeLists.txt
index

[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits


@@ -100,12 +103,6 @@ ValueProfNode *__llvm_profile_begin_vnodes();
 ValueProfNode *__llvm_profile_end_vnodes();
 uint32_t *__llvm_profile_begin_orderfile();
 
-/*!
- * \brief Clear profile counters to zero.
- *
- */
-void __llvm_profile_reset_counters(void);

qiongsiwu wrote:

> Ok, if we don't want to expose the internals then the existing approach seems 
> like the simplest one. I think @davidxl's comment in the discourse thread is 
> about ensuring no control flow changes in profile gen and use in hot code 
> paths. This does not necessarily preclude additional wrappers.
> 
> > Update: I think the explicit definition needs to be guarded by an #ifndef.
> 
> Yes, I misread the original as `#ifdef` causing some confusion. This should 
> also be `#undef` afterwards. I was thinking about churn for existing users of 
> InstrProfiling.h but it should be a no-op.

Ah got it! Thanks so much for the clarification! `InstrProfiling.h` is updated 
so we are guarding `__LLVM_INSTR_PROFILE_GENERATE`'s macro definition. 

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


[compiler-rt] [clang-tools-extra] [clang] [PGO] Exposing PGO's Counter Reset and File Dumping APIs (PR #76471)

2023-12-27 Thread Qiongsi Wu via cfe-commits

qiongsiwu wrote:

> > @teresajohnson I mentioned the same thing on 
> > [discourse](https://discourse.llvm.org/t/pgo-are-the-llvm-profile-functions-stable-c-apis-across-llvm-releases/75832/5)
> >  but it seems like linking on AIX does not support this model.
> 
> I see. Perhaps instead of defining these away completely, they should be 
> defined to a dummy function with the same signature that always returns 
> success (0 I think)? Alternatively, not define them at all when 
> __LLVM_INSTR_PROFILE_GENERATE not defined and have the user guard calls by 
> `#ifdef __LLVM_INSTR_PROFILE_GENERATE`. Otherwise, the user either cannot 
> check the return values, or they have to guard their usage by a check of 
> __LLVM_INSTR_PROFILE_GENERATE anyway.

Ah good catch! Thanks so much! The definitions of `__llvm_profile_dump` and 
`__llvm_orderfile_dump` are revised to `(0)` so they can be used in `if` 
conditions. See 
https://github.com/llvm/llvm-project/pull/76471/commits/cce25f062c00424c153254fc159309808441414c#diff-c21b547d913313490258f0fdb733251d783c5c5a242429ccc2fa5672914f22a2R58.
 

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


[compiler-rt] [flang] [libc] [lld] [mlir] [clang] [clang-tools-extra] [openmp] [llvm] [X86] Remove RAO-INT from Grandridge (PR #76420)

2023-12-27 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/76420

>From ae1d12c24facb36323b9b46a73a1fbc3edff4dc8 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Wed, 27 Dec 2023 10:33:30 +0800
Subject: [PATCH] [X86] Remove RAO-INT from Grandridge

According to latest spec: https://cdrdv2.intel.com/v1/dl/getContent/671368
---
 clang/test/Preprocessor/predefined-arch-macros.c |  6 ++
 llvm/lib/Target/X86/X86.td   | 11 +++
 llvm/lib/TargetParser/X86TargetParser.cpp|  4 +---
 3 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/clang/test/Preprocessor/predefined-arch-macros.c 
b/clang/test/Preprocessor/predefined-arch-macros.c
index 1ae6faea776785..27c7b4a271fee8 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -2515,7 +2515,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M32
 // RUN: %clang -march=grandridge -m32 -E -dM %s -o - 2>&1 \
 // RUN: --target=i386 \
-// RUN:   | FileCheck -match-full-lines %s 
-check-prefixes=CHECK_SRF_M32,CHECK_GRR_M32
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_SRF_M32
 // RUN: %clang -march=arrowlake -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M32
@@ -2572,7 +2572,6 @@
 // CHECK_SRF_M32: #define __PRFCHW__ 1
 // CHECK_SRF_M32: #define __PTWRITE__ 1
 // CHECK_SRF_M32-NOT: #define __RAOINT__ 1
-// CHECK_GRR_M32: #define __RAOINT__ 1
 // CHECK_SRF_M32: #define __RDPID__ 1
 // CHECK_SRF_M32: #define __RDRND__ 1
 // CHECK_SRF_M32: #define __RDSEED__ 1
@@ -2618,7 +2617,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M64
 // RUN: %clang -march=grandridge -m64 -E -dM %s -o - 2>&1 \
 // RUN: --target=i386 \
-// RUN:   | FileCheck -match-full-lines %s 
-check-prefixes=CHECK_SRF_M64,CHECK_GRR_M64
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_SRF_M64
 // RUN: %clang -march=arrowlake -m64 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M64
@@ -2675,7 +2674,6 @@
 // CHECK_SRF_M64: #define __PRFCHW__ 1
 // CHECK_SRF_M64: #define __PTWRITE__ 1
 // CHECK_SRF_M64-NOT: #define __RAOINT__ 1
-// CHECK_GRR_M64: #define __RAOINT__ 1
 // CHECK_SRF_M64: #define __RDPID__ 1
 // CHECK_SRF_M64: #define __RDRND__ 1
 // CHECK_SRF_M64: #define __RDSEED__ 1
diff --git a/llvm/lib/Target/X86/X86.td b/llvm/lib/Target/X86/X86.td
index 5fd6828f43129d..e89ddcc570c96c 100644
--- a/llvm/lib/Target/X86/X86.td
+++ b/llvm/lib/Target/X86/X86.td
@@ -1256,11 +1256,6 @@ def ProcessorFeatures {
   list SRFFeatures =
 !listconcat(ADLFeatures, SRFAdditionalFeatures);
 
-  // Grandridge
-  list GRRAdditionalFeatures = [FeatureRAOINT];
-  list GRRFeatures =
-!listconcat(SRFFeatures, GRRAdditionalFeatures);
-
   // Arrowlake S
   list ARLSAdditionalFeatures = [FeatureAVXVNNIINT16,
FeatureSHA512,
@@ -1706,10 +1701,10 @@ foreach P = ["goldmont_plus", "goldmont-plus"] in {
 }
 def : ProcModel<"tremont", SLMModel, ProcessorFeatures.TRMFeatures,
 ProcessorFeatures.TRMTuning>;
-def : ProcModel<"sierraforest", AlderlakePModel, ProcessorFeatures.SRFFeatures,
-ProcessorFeatures.TRMTuning>;
-def : ProcModel<"grandridge", AlderlakePModel, ProcessorFeatures.GRRFeatures,
+foreach P = ["sierraforest", "grandridge"] in {
+  def : ProcModel;
+}
 
 // "Arrandale" along with corei3 and corei5
 foreach P = ["nehalem", "corei7", "core_i7_sse4_2"] in {
diff --git a/llvm/lib/TargetParser/X86TargetParser.cpp 
b/llvm/lib/TargetParser/X86TargetParser.cpp
index 085554f18b2b6b..d46ff07ec7340a 100644
--- a/llvm/lib/TargetParser/X86TargetParser.cpp
+++ b/llvm/lib/TargetParser/X86TargetParser.cpp
@@ -162,8 +162,6 @@ constexpr FeatureBitset FeaturesAlderlake =
 constexpr FeatureBitset FeaturesSierraforest =
 FeaturesAlderlake | FeatureCMPCCXADD | FeatureAVXIFMA | FeatureUINTR |
 FeatureENQCMD | FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
-constexpr FeatureBitset FeaturesGrandridge =
-FeaturesSierraforest | FeatureRAOINT;
 constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest |
 FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4;
 constexpr FeatureBitset FeaturesPantherlake =
@@ -369,7 +367,7 @@ constexpr ProcInfo Processors[] = {
   // Sierraforest microarchitecture based processors.
   { {"sierraforest"}, CK_Sierraforest, FEATURE_AVX2, FeaturesSierraforest, 
'p', false },
   // Grandridge microarchitecture based processors.
-  { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesGrandridge, 'p', 
false },
+  { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesSierraforest, 'p', 
false },
   // Granite Rapids microarchitecture based processors.
   { {"graniterapids"}, CK_Graniterapids, FEATURE_AVX512BF16, 
FeaturesGr

[clang] [clang] Add basic support for #embed. (PR #76480)

2023-12-27 Thread Junior Rantila via cfe-commits

https://github.com/juniorrantila created 
https://github.com/llvm/llvm-project/pull/76480

This patch takes the first steps toward C23 #embed support. We can include 
binary files, but embed-parameter-sequences are not implemented. Adding the 
embedded file to the -M dependency array is also not implemented.

>From 00e9c665c18c1efafc15e293ea6dc35b1ed32e48 Mon Sep 17 00:00:00 2001
From: Junior Rantila 
Date: Wed, 27 Dec 2023 22:00:35 +0100
Subject: [PATCH] [clang] Add basic support for #embed.

This patch takes the first steps toward C23 #embed support.
We can include binary files, but embed-parameter-sequences are not
implemented. Adding the embedded file to the -M dependency array is
also not implemented.
---
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 clang/include/clang/Basic/TokenKinds.def  |   3 +
 .../clang/Lex/DependencyDirectivesScanner.h   |   1 +
 clang/include/clang/Lex/Preprocessor.h|   3 +
 clang/lib/Basic/IdentifierTable.cpp   |   1 +
 clang/lib/Lex/DependencyDirectivesScanner.cpp |  12 +
 clang/lib/Lex/Lexer.cpp   |   1 +
 clang/lib/Lex/PPDirectives.cpp| 221 +-
 8 files changed, 240 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index e4b1069cde1850..56258df192f9ff 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -165,6 +165,8 @@ def ext_c99_feature : Extension<
   "'%0' is a C99 extension">, InGroup;
 def ext_c11_feature : Extension<
   "'%0' is a C11 extension">, InGroup;
+def ext_c23_feature : Extension<
+  "'%0' is a C23 extension">, InGroup;
 def warn_c23_compat_keyword : Warning<
  "'%0' is incompatible with C standards before C23">,
  InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3f0e1e1a7d45ad..591684c004f908 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -113,6 +113,9 @@ PPKEYWORD(defined)
 PPKEYWORD(include)
 PPKEYWORD(__include_macros)
 
+// C23 6.10.2 - Binary resource inclusion
+PPKEYWORD(embed)
+
 // C99 6.10.3 - Macro Replacement.
 PPKEYWORD(define)
 PPKEYWORD(undef)
diff --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h 
b/clang/include/clang/Lex/DependencyDirectivesScanner.h
index 0e115906fbfe51..b00b9391d0074a 100644
--- a/clang/include/clang/Lex/DependencyDirectivesScanner.h
+++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h
@@ -70,6 +70,7 @@ enum DirectiveKind : uint8_t {
   pp_pragma_include_alias,
   pp_pragma_system_header,
   pp_include_next,
+  pp_embed,
   pp_if,
   pp_ifdef,
   pp_ifndef,
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4ec21a8b6be2c8..4ff097eae78571 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2689,6 +2689,9 @@ class Preprocessor {
   void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok);
   void HandleImportDirective(SourceLocation HashLoc, Token &Tok);
   void HandleMicrosoftImportDirective(Token &Tok);
+  void HandleEmbedDirective(SourceLocation HashLoc, Token &Tok,
+ConstSearchDirIterator LookupFrom = nullptr,
+const FileEntry *LookupFromFile = nullptr);
 
 public:
   /// Check that the given module is available, producing a diagnostic if not.
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index 5902c6dc3ce0b4..50cf1925acf49e 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -446,6 +446,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   CASE( 5, 'i', 'e', ident);
   CASE( 5, 'i', 'd', ifdef);
   CASE( 5, 'u', 'd', undef);
+  CASE( 5, 'e', 'b', embed);
 
   CASE( 6, 'a', 's', assert);
   CASE( 6, 'd', 'f', define);
diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 980f865cf24c97..867614cdb27167 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -91,6 +91,9 @@ struct Scanner {
   dependency_directives_scan::Token &lexIncludeFilename(const char *&First,
 const char *const End);
 
+  dependency_directives_scan::Token &lexEmbedFilename(const char *&First,
+  const char *const End);
+
   void skipLine(const char *&First, const char *const End);
   void skipDirective(StringRef Name, const char *&First, const char *const 
End);
 
@@ -541,6 +544,11 @@ Scanner::lexIncludeFilename(const char *&First, const char 
*const End) {
   return CurDirToks.back();
 }
 
+dependency_directives_scan::Token &
+Scanner::lexEmbedFilename(const char *&Fir

[clang] [clang] Add basic support for #embed. (PR #76480)

2023-12-27 Thread via cfe-commits

github-actions[bot] wrote:

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang] Add basic support for #embed. (PR #76480)

2023-12-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Junior Rantila (juniorrantila)


Changes

This patch takes the first steps toward C23 #embed support. We can include 
binary files, but embed-parameter-sequences are not implemented. Adding the 
embedded file to the -M dependency array is also not implemented.

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


8 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+2) 
- (modified) clang/include/clang/Basic/TokenKinds.def (+3) 
- (modified) clang/include/clang/Lex/DependencyDirectivesScanner.h (+1) 
- (modified) clang/include/clang/Lex/Preprocessor.h (+3) 
- (modified) clang/lib/Basic/IdentifierTable.cpp (+1) 
- (modified) clang/lib/Lex/DependencyDirectivesScanner.cpp (+12) 
- (modified) clang/lib/Lex/Lexer.cpp (+1) 
- (modified) clang/lib/Lex/PPDirectives.cpp (+217-4) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index e4b1069cde1850..56258df192f9ff 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -165,6 +165,8 @@ def ext_c99_feature : Extension<
   "'%0' is a C99 extension">, InGroup;
 def ext_c11_feature : Extension<
   "'%0' is a C11 extension">, InGroup;
+def ext_c23_feature : Extension<
+  "'%0' is a C23 extension">, InGroup;
 def warn_c23_compat_keyword : Warning<
  "'%0' is incompatible with C standards before C23">,
  InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3f0e1e1a7d45ad..591684c004f908 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -113,6 +113,9 @@ PPKEYWORD(defined)
 PPKEYWORD(include)
 PPKEYWORD(__include_macros)
 
+// C23 6.10.2 - Binary resource inclusion
+PPKEYWORD(embed)
+
 // C99 6.10.3 - Macro Replacement.
 PPKEYWORD(define)
 PPKEYWORD(undef)
diff --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h 
b/clang/include/clang/Lex/DependencyDirectivesScanner.h
index 0e115906fbfe51..b00b9391d0074a 100644
--- a/clang/include/clang/Lex/DependencyDirectivesScanner.h
+++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h
@@ -70,6 +70,7 @@ enum DirectiveKind : uint8_t {
   pp_pragma_include_alias,
   pp_pragma_system_header,
   pp_include_next,
+  pp_embed,
   pp_if,
   pp_ifdef,
   pp_ifndef,
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4ec21a8b6be2c8..4ff097eae78571 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2689,6 +2689,9 @@ class Preprocessor {
   void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok);
   void HandleImportDirective(SourceLocation HashLoc, Token &Tok);
   void HandleMicrosoftImportDirective(Token &Tok);
+  void HandleEmbedDirective(SourceLocation HashLoc, Token &Tok,
+ConstSearchDirIterator LookupFrom = nullptr,
+const FileEntry *LookupFromFile = nullptr);
 
 public:
   /// Check that the given module is available, producing a diagnostic if not.
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index 5902c6dc3ce0b4..50cf1925acf49e 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -446,6 +446,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   CASE( 5, 'i', 'e', ident);
   CASE( 5, 'i', 'd', ifdef);
   CASE( 5, 'u', 'd', undef);
+  CASE( 5, 'e', 'b', embed);
 
   CASE( 6, 'a', 's', assert);
   CASE( 6, 'd', 'f', define);
diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 980f865cf24c97..867614cdb27167 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -91,6 +91,9 @@ struct Scanner {
   dependency_directives_scan::Token &lexIncludeFilename(const char *&First,
 const char *const End);
 
+  dependency_directives_scan::Token &lexEmbedFilename(const char *&First,
+  const char *const End);
+
   void skipLine(const char *&First, const char *const End);
   void skipDirective(StringRef Name, const char *&First, const char *const 
End);
 
@@ -541,6 +544,11 @@ Scanner::lexIncludeFilename(const char *&First, const char 
*const End) {
   return CurDirToks.back();
 }
 
+dependency_directives_scan::Token &
+Scanner::lexEmbedFilename(const char *&First, const char *const End) {
+  return lexIncludeFilename(First, End);
+}
+
 void Scanner::lexPPDirectiveBody(const char *&First, const char *const End) {
   while (true) {
 const dependency_directives_scan::Token &Tok = lexToken(First, End);
@@ -875,6 +883,7 @@ bool Scanner::lexPPLine(const char *&First, const char 
*const

[clang-tools-extra] Fix #75686: add iter_swap and iter_move to the matched name (PR #76117)

2023-12-27 Thread via cfe-commits

https://github.com/Da-Viper updated 
https://github.com/llvm/llvm-project/pull/76117

>From 97eeda4684804229d9faad19ea7b7888dcd91786 Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Thu, 21 Dec 2023 02:30:34 +
Subject: [PATCH 1/2] Fix #75686: add iter_swap and iter_move to the matched
 name

---
 .../bugprone/ExceptionEscapeCheck.cpp   | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
index 90bf523ffb00b6..18cd7150185a20 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
@@ -58,14 +58,15 @@ void 
ExceptionEscapeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
 
 void ExceptionEscapeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(isDefinition(),
-   anyOf(isNoThrow(),
- allOf(anyOf(cxxDestructorDecl(),
- cxxConstructorDecl(isMoveConstructor()),
- cxxMethodDecl(isMoveAssignmentOperator()),
- isMain(), hasName("swap")),
-   unless(isExplicitThrow())),
- isEnabled(FunctionsThatShouldNotThrow)))
+  functionDecl(
+  isDefinition(),
+  anyOf(isNoThrow(),
+allOf(anyOf(cxxDestructorDecl(),
+cxxConstructorDecl(isMoveConstructor()),
+cxxMethodDecl(isMoveAssignmentOperator()), 
isMain(),
+hasAnyName("swap", "iter_swap", "iter_move")),
+  unless(isExplicitThrow())),
+isEnabled(FunctionsThatShouldNotThrow)))
   .bind("thrower"),
   this);
 }

>From c7cbf4c9bebbf450410c2679af188672257895aa Mon Sep 17 00:00:00 2001
From: Ezike Ebuka 
Date: Thu, 28 Dec 2023 01:30:35 +
Subject: [PATCH 2/2] [clang-tidy] Update documentation, release notes and
 tests for bugprone-exception-escape

---
 clang-tools-extra/docs/ReleaseNotes.rst|  4 
 .../clang-tidy/checks/bugprone/exception-escape.rst|  2 ++
 .../clang-tidy/checkers/bugprone/exception-escape.cpp  | 10 ++
 3 files changed, 16 insertions(+)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6d91748e4cef18..967597cbba11b1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -242,6 +242,10 @@ Changes in existing checks
   casting during type conversions at variable initialization, now with improved
   compatibility for C++17 and later versions.
 
+- Improved :doc:`bugprone-exception-escape
+  ` check by extending the default
+  check function names to include ``iter_swap`` and ``iter_move``.
+
 - Improved :doc:`bugprone-lambda-function-name
   ` check by adding option
   `IgnoreMacros` to ignore warnings in macros.
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
index e6aa8e001492a6..182fade7f47a03 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst
@@ -11,6 +11,8 @@ should not. The functions which should not throw exceptions 
are the following:
 * Move assignment operators
 * The ``main()`` functions
 * ``swap()`` functions
+* ``iter_swap()`` functions
+* ``iter_move()`` functions
 * Functions marked with ``throw()`` or ``noexcept``
 * Other functions given as option
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
index 4a7149e81ce7e5..e20aa267392f55 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -586,6 +586,16 @@ void swap(int&, int&) {
   throw 1;
 }
 
+void iter_swap(int&, int&) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 
function 'iter_swap' which should not throw exceptions
+  throw 1;
+}
+
+void iter_move(int&, int&) {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in 
function 'iter_move' which should not throw exceptions
+  throw 1;
+}
+
 namespace std {
 class bad_alloc {};
 }

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


[clang] [clang] Add basic support for #embed. (PR #76480)

2023-12-27 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 38c9390b59c4d2b9181614d6a909887497d3692f 
00e9c665c18c1efafc15e293ea6dc35b1ed32e48 -- 
clang/include/clang/Lex/DependencyDirectivesScanner.h 
clang/include/clang/Lex/Preprocessor.h clang/lib/Basic/IdentifierTable.cpp 
clang/lib/Lex/DependencyDirectivesScanner.cpp clang/lib/Lex/Lexer.cpp 
clang/lib/Lex/PPDirectives.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index 50cf1925ac..459e03f337 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -446,7 +446,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   CASE( 5, 'i', 'e', ident);
   CASE( 5, 'i', 'd', ifdef);
   CASE( 5, 'u', 'd', undef);
-  CASE( 5, 'e', 'b', embed);
+  CASE(5, 'e', 'b', embed);
 
   CASE( 6, 'a', 's', assert);
   CASE( 6, 'd', 'f', define);

``




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


[clang] [clang] Add basic support for #embed. (PR #76480)

2023-12-27 Thread Junior Rantila via cfe-commits

https://github.com/juniorrantila updated 
https://github.com/llvm/llvm-project/pull/76480

>From a51561dcfb9877c0881651ecdc9de8928991506c Mon Sep 17 00:00:00 2001
From: Junior Rantila 
Date: Wed, 27 Dec 2023 22:00:35 +0100
Subject: [PATCH] [clang] Add basic support for #embed.

This patch takes the first steps toward C23 #embed support.
We can include binary files, but embed-parameter-sequences are not
implemented. Adding the embedded file to the -M dependency array is
also not implemented.
---
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 clang/include/clang/Basic/TokenKinds.def  |   3 +
 .../clang/Lex/DependencyDirectivesScanner.h   |   1 +
 clang/include/clang/Lex/Preprocessor.h|   3 +
 clang/lib/Basic/IdentifierTable.cpp   |   1 +
 clang/lib/Lex/DependencyDirectivesScanner.cpp |  12 +
 clang/lib/Lex/Lexer.cpp   |   1 +
 clang/lib/Lex/PPDirectives.cpp| 221 +-
 8 files changed, 240 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index e4b1069cde1850..56258df192f9ff 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -165,6 +165,8 @@ def ext_c99_feature : Extension<
   "'%0' is a C99 extension">, InGroup;
 def ext_c11_feature : Extension<
   "'%0' is a C11 extension">, InGroup;
+def ext_c23_feature : Extension<
+  "'%0' is a C23 extension">, InGroup;
 def warn_c23_compat_keyword : Warning<
  "'%0' is incompatible with C standards before C23">,
  InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3f0e1e1a7d45ad..591684c004f908 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -113,6 +113,9 @@ PPKEYWORD(defined)
 PPKEYWORD(include)
 PPKEYWORD(__include_macros)
 
+// C23 6.10.2 - Binary resource inclusion
+PPKEYWORD(embed)
+
 // C99 6.10.3 - Macro Replacement.
 PPKEYWORD(define)
 PPKEYWORD(undef)
diff --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h 
b/clang/include/clang/Lex/DependencyDirectivesScanner.h
index 0e115906fbfe51..b00b9391d0074a 100644
--- a/clang/include/clang/Lex/DependencyDirectivesScanner.h
+++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h
@@ -70,6 +70,7 @@ enum DirectiveKind : uint8_t {
   pp_pragma_include_alias,
   pp_pragma_system_header,
   pp_include_next,
+  pp_embed,
   pp_if,
   pp_ifdef,
   pp_ifndef,
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4ec21a8b6be2c8..4ff097eae78571 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2689,6 +2689,9 @@ class Preprocessor {
   void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok);
   void HandleImportDirective(SourceLocation HashLoc, Token &Tok);
   void HandleMicrosoftImportDirective(Token &Tok);
+  void HandleEmbedDirective(SourceLocation HashLoc, Token &Tok,
+ConstSearchDirIterator LookupFrom = nullptr,
+const FileEntry *LookupFromFile = nullptr);
 
 public:
   /// Check that the given module is available, producing a diagnostic if not.
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index 5902c6dc3ce0b4..459e03f337fa87 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -446,6 +446,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   CASE( 5, 'i', 'e', ident);
   CASE( 5, 'i', 'd', ifdef);
   CASE( 5, 'u', 'd', undef);
+  CASE(5, 'e', 'b', embed);
 
   CASE( 6, 'a', 's', assert);
   CASE( 6, 'd', 'f', define);
diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 980f865cf24c97..867614cdb27167 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -91,6 +91,9 @@ struct Scanner {
   dependency_directives_scan::Token &lexIncludeFilename(const char *&First,
 const char *const End);
 
+  dependency_directives_scan::Token &lexEmbedFilename(const char *&First,
+  const char *const End);
+
   void skipLine(const char *&First, const char *const End);
   void skipDirective(StringRef Name, const char *&First, const char *const 
End);
 
@@ -541,6 +544,11 @@ Scanner::lexIncludeFilename(const char *&First, const char 
*const End) {
   return CurDirToks.back();
 }
 
+dependency_directives_scan::Token &
+Scanner::lexEmbedFilename(const char *&First, const char *const End) {
+  return lexIncludeFilename(First, End);
+}
+
 void Scanner::lexPPDirectiveBody(const char *&First, const char *const End) {
   while (true) {
 const dependency_directives_scan::Token &To

[clang] [clang] Add basic support for #embed. (PR #76480)

2023-12-27 Thread Junior Rantila via cfe-commits

https://github.com/juniorrantila updated 
https://github.com/llvm/llvm-project/pull/76480

>From 554b85be15f9ee9767d74db18ef6db75119b308a Mon Sep 17 00:00:00 2001
From: Junior Rantila 
Date: Wed, 27 Dec 2023 22:00:35 +0100
Subject: [PATCH] [clang] Add basic support for #embed

This patch takes the first steps toward C23 #embed support.
We can include binary files, but embed-parameter-sequences are not
implemented. Adding the embedded file to the -M dependency array is
also not implemented.
---
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 clang/include/clang/Basic/TokenKinds.def  |   3 +
 .../clang/Lex/DependencyDirectivesScanner.h   |   1 +
 clang/include/clang/Lex/Preprocessor.h|   3 +
 clang/lib/Basic/IdentifierTable.cpp   |   1 +
 clang/lib/Lex/DependencyDirectivesScanner.cpp |  12 +
 clang/lib/Lex/Lexer.cpp   |   1 +
 clang/lib/Lex/PPDirectives.cpp| 221 +-
 8 files changed, 240 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index e4b1069cde1850..56258df192f9ff 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -165,6 +165,8 @@ def ext_c99_feature : Extension<
   "'%0' is a C99 extension">, InGroup;
 def ext_c11_feature : Extension<
   "'%0' is a C11 extension">, InGroup;
+def ext_c23_feature : Extension<
+  "'%0' is a C23 extension">, InGroup;
 def warn_c23_compat_keyword : Warning<
  "'%0' is incompatible with C standards before C23">,
  InGroup, DefaultIgnore;
diff --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 3f0e1e1a7d45ad..591684c004f908 100644
--- a/clang/include/clang/Basic/TokenKinds.def
+++ b/clang/include/clang/Basic/TokenKinds.def
@@ -113,6 +113,9 @@ PPKEYWORD(defined)
 PPKEYWORD(include)
 PPKEYWORD(__include_macros)
 
+// C23 6.10.2 - Binary resource inclusion
+PPKEYWORD(embed)
+
 // C99 6.10.3 - Macro Replacement.
 PPKEYWORD(define)
 PPKEYWORD(undef)
diff --git a/clang/include/clang/Lex/DependencyDirectivesScanner.h 
b/clang/include/clang/Lex/DependencyDirectivesScanner.h
index 0e115906fbfe51..b00b9391d0074a 100644
--- a/clang/include/clang/Lex/DependencyDirectivesScanner.h
+++ b/clang/include/clang/Lex/DependencyDirectivesScanner.h
@@ -70,6 +70,7 @@ enum DirectiveKind : uint8_t {
   pp_pragma_include_alias,
   pp_pragma_system_header,
   pp_include_next,
+  pp_embed,
   pp_if,
   pp_ifdef,
   pp_ifndef,
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index 4ec21a8b6be2c8..4ff097eae78571 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2689,6 +2689,9 @@ class Preprocessor {
   void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok);
   void HandleImportDirective(SourceLocation HashLoc, Token &Tok);
   void HandleMicrosoftImportDirective(Token &Tok);
+  void HandleEmbedDirective(SourceLocation HashLoc, Token &Tok,
+ConstSearchDirIterator LookupFrom = nullptr,
+const FileEntry *LookupFromFile = nullptr);
 
 public:
   /// Check that the given module is available, producing a diagnostic if not.
diff --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index 5902c6dc3ce0b4..459e03f337fa87 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -446,6 +446,7 @@ tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {
   CASE( 5, 'i', 'e', ident);
   CASE( 5, 'i', 'd', ifdef);
   CASE( 5, 'u', 'd', undef);
+  CASE(5, 'e', 'b', embed);
 
   CASE( 6, 'a', 's', assert);
   CASE( 6, 'd', 'f', define);
diff --git a/clang/lib/Lex/DependencyDirectivesScanner.cpp 
b/clang/lib/Lex/DependencyDirectivesScanner.cpp
index 980f865cf24c97..867614cdb27167 100644
--- a/clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ b/clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -91,6 +91,9 @@ struct Scanner {
   dependency_directives_scan::Token &lexIncludeFilename(const char *&First,
 const char *const End);
 
+  dependency_directives_scan::Token &lexEmbedFilename(const char *&First,
+  const char *const End);
+
   void skipLine(const char *&First, const char *const End);
   void skipDirective(StringRef Name, const char *&First, const char *const 
End);
 
@@ -541,6 +544,11 @@ Scanner::lexIncludeFilename(const char *&First, const char 
*const End) {
   return CurDirToks.back();
 }
 
+dependency_directives_scan::Token &
+Scanner::lexEmbedFilename(const char *&First, const char *const End) {
+  return lexIncludeFilename(First, End);
+}
+
 void Scanner::lexPPDirectiveBody(const char *&First, const char *const End) {
   while (true) {
 const dependency_directives_scan::Token &Tok

[clang] [clang] Add basic support for #embed (PR #76480)

2023-12-27 Thread Junior Rantila via cfe-commits

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


[libcxx] [clang] [libc++] Re-enable the clang_modules_include test for Objective-C++ (PR #66801)

2023-12-27 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> https://reviews.llvm.org/D158694

The motivation of my change is that I find multiple people are trying to fake 
`import std` from clang modules. This is not wanted. So I tried to ban it. I'll 
try to fix it or revert it later today if I didn't.

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


[clang] Fix crash with modules and constexpr destructor (PR #69076)

2023-12-27 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> I finally had time to debug this: The reason for modules being involved here 
> is because the serialization code calls `ParmVarDecl::getDefaultArg()` which 
> strips the outermost `FullExpr`, such as `ExprWithCleanups`. A potential fix 
> is in #76473 though I'm not really convinced by this asymmetry between 
> `getInit()` but calling `setDefaultArg()`. However, removing the handling of 
> `FullExpr` in `setDefaultArg()` causes a total 29 test failures, so that's 
> not an (easy) option...
> 
> Personally, I would argue that adding `FullExpressionRAII` makes the code 
> more robust against the absence of `ExprWithCleanups` so that's maybe a good 
> thing to have regardless of fixing the serialization code.

Thanks for looking into this. Good enough for me. Yeah the asymmetry between 
`getInit()` but calling `setDefaultArg()` is a concerning. Also it may be not 
easy to understand and fix the underlying problem (why getDefaultArg() will 
strip the outmost `FullExpr`) **properly**.

So personally I am fine with the current workaround with a `FIXME`. Let's wait 
for the opinion from @cor3ntin and @shafik 

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


[clang] 19e7846 - [X86] Remove RAO-INT from Grandridge (#76420)

2023-12-27 Thread via cfe-commits

Author: Freddy Ye
Date: 2023-12-28T10:06:54+08:00
New Revision: 19e784604c70d27cd6f3b2cf5d42e4363af12264

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

LOG: [X86] Remove RAO-INT from Grandridge (#76420)

According to latest spec:
https://cdrdv2.intel.com/v1/dl/getContent/671368

Added: 


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

Removed: 




diff  --git a/clang/test/Preprocessor/predefined-arch-macros.c 
b/clang/test/Preprocessor/predefined-arch-macros.c
index 1ae6faea776785..27c7b4a271fee8 100644
--- a/clang/test/Preprocessor/predefined-arch-macros.c
+++ b/clang/test/Preprocessor/predefined-arch-macros.c
@@ -2515,7 +2515,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M32
 // RUN: %clang -march=grandridge -m32 -E -dM %s -o - 2>&1 \
 // RUN: --target=i386 \
-// RUN:   | FileCheck -match-full-lines %s 
-check-prefixes=CHECK_SRF_M32,CHECK_GRR_M32
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_SRF_M32
 // RUN: %clang -march=arrowlake -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M32
@@ -2572,7 +2572,6 @@
 // CHECK_SRF_M32: #define __PRFCHW__ 1
 // CHECK_SRF_M32: #define __PTWRITE__ 1
 // CHECK_SRF_M32-NOT: #define __RAOINT__ 1
-// CHECK_GRR_M32: #define __RAOINT__ 1
 // CHECK_SRF_M32: #define __RDPID__ 1
 // CHECK_SRF_M32: #define __RDRND__ 1
 // CHECK_SRF_M32: #define __RDSEED__ 1
@@ -2618,7 +2617,7 @@
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M64
 // RUN: %clang -march=grandridge -m64 -E -dM %s -o - 2>&1 \
 // RUN: --target=i386 \
-// RUN:   | FileCheck -match-full-lines %s 
-check-prefixes=CHECK_SRF_M64,CHECK_GRR_M64
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_SRF_M64
 // RUN: %clang -march=arrowlake -m64 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_SRF_M64
@@ -2675,7 +2674,6 @@
 // CHECK_SRF_M64: #define __PRFCHW__ 1
 // CHECK_SRF_M64: #define __PTWRITE__ 1
 // CHECK_SRF_M64-NOT: #define __RAOINT__ 1
-// CHECK_GRR_M64: #define __RAOINT__ 1
 // CHECK_SRF_M64: #define __RDPID__ 1
 // CHECK_SRF_M64: #define __RDRND__ 1
 // CHECK_SRF_M64: #define __RDSEED__ 1

diff  --git a/llvm/lib/Target/X86/X86.td b/llvm/lib/Target/X86/X86.td
index 5fd6828f43129d..e89ddcc570c96c 100644
--- a/llvm/lib/Target/X86/X86.td
+++ b/llvm/lib/Target/X86/X86.td
@@ -1256,11 +1256,6 @@ def ProcessorFeatures {
   list SRFFeatures =
 !listconcat(ADLFeatures, SRFAdditionalFeatures);
 
-  // Grandridge
-  list GRRAdditionalFeatures = [FeatureRAOINT];
-  list GRRFeatures =
-!listconcat(SRFFeatures, GRRAdditionalFeatures);
-
   // Arrowlake S
   list ARLSAdditionalFeatures = [FeatureAVXVNNIINT16,
FeatureSHA512,
@@ -1706,10 +1701,10 @@ foreach P = ["goldmont_plus", "goldmont-plus"] in {
 }
 def : ProcModel<"tremont", SLMModel, ProcessorFeatures.TRMFeatures,
 ProcessorFeatures.TRMTuning>;
-def : ProcModel<"sierraforest", AlderlakePModel, ProcessorFeatures.SRFFeatures,
-ProcessorFeatures.TRMTuning>;
-def : ProcModel<"grandridge", AlderlakePModel, ProcessorFeatures.GRRFeatures,
+foreach P = ["sierraforest", "grandridge"] in {
+  def : ProcModel;
+}
 
 // "Arrandale" along with corei3 and corei5
 foreach P = ["nehalem", "corei7", "core_i7_sse4_2"] in {

diff  --git a/llvm/lib/TargetParser/X86TargetParser.cpp 
b/llvm/lib/TargetParser/X86TargetParser.cpp
index 085554f18b2b6b..d46ff07ec7340a 100644
--- a/llvm/lib/TargetParser/X86TargetParser.cpp
+++ b/llvm/lib/TargetParser/X86TargetParser.cpp
@@ -162,8 +162,6 @@ constexpr FeatureBitset FeaturesAlderlake =
 constexpr FeatureBitset FeaturesSierraforest =
 FeaturesAlderlake | FeatureCMPCCXADD | FeatureAVXIFMA | FeatureUINTR |
 FeatureENQCMD | FeatureAVXNECONVERT | FeatureAVXVNNIINT8;
-constexpr FeatureBitset FeaturesGrandridge =
-FeaturesSierraforest | FeatureRAOINT;
 constexpr FeatureBitset FeaturesArrowlakeS = FeaturesSierraforest |
 FeatureAVXVNNIINT16 | FeatureSHA512 | FeatureSM3 | FeatureSM4;
 constexpr FeatureBitset FeaturesPantherlake =
@@ -369,7 +367,7 @@ constexpr ProcInfo Processors[] = {
   // Sierraforest microarchitecture based processors.
   { {"sierraforest"}, CK_Sierraforest, FEATURE_AVX2, FeaturesSierraforest, 
'p', false },
   // Grandridge microarchitecture based processors.
-  { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesGrandridge, 'p', 
false },
+  { {"grandridge"}, CK_Grandridge, FEATURE_AVX2, FeaturesSierraforest, 'p', 
false },
   // Granite Rapids microarchitecture

[mlir] [compiler-rt] [clang] [openmp] [llvm] [flang] [lld] [libc] [clang-tools-extra] [X86] Remove RAO-INT from Grandridge (PR #76420)

2023-12-27 Thread Freddy Ye via cfe-commits

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


  1   2   >