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

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


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

ChuanqiXu9 wrote:

But "module: =" doesn't look like an error value too. And I feel it just adds 
the work the tool vendors need to do. @mathstuf @boris-kolpackov do you have an 
opinion here?

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] [llvm] [RFC][RISCV] Support RISC-V Profiles in -march option (PR #76357)

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

W-angler wrote:

Current implementation is based on the 
comment(https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36#issuecomment-1867859642),
 not the RFC. @dtcxzyw 

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


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

2023-12-28 Thread Yingwei Zheng via cfe-commits


@@ -0,0 +1,112 @@
+// RUN: %clang -### -c %s 2>&1 -march=rvi20u32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-cpu" "generic-rv32"
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+// RVI20U32: "-target-feature" "+rvi20u32"
+// 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-feature" "+rvi20u64"
+// 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-feature" "+rva20u64"
+// 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-feature" "+rva20s64"
+// 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-feature" "+rva22u64"
+// 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-feature" "+rva22s64"
+// RVA22S64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=rva22u64_zfa | FileCheck 
-check-prefix=PROFILE-WITH-ADDITIONAL %s

dtcxzyw wrote:

```suggestion
// RUN: %clang -### -c %s 2>&1 -march=RVA22U64+zfa | FileCheck 
-check-prefix=PROFILE-WITH-ADDITIONAL %s
```

> profiles format has the following BNF form 
> `"-march=""+"[option-ext]*`.

https://github.com/llvm/llvm-project/pull/76357
___
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-28 Thread Yingwei Zheng via cfe-commits


@@ -206,6 +210,17 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zvfbfwma", RISCVExtensionVersion{0, 8}},
 };
 
+static const RISCVProfile SupportedProfiles[] = {
+{"rvi20u32", "rv32i"},

dtcxzyw wrote:

Profile names should use uppercase letters.
> e.g. `-march=RVA20U64` is a legal profile input, it will be expanded into:
 `-march=rv64imafdc_zicsr_ziccif_ziccrse_ziccamoa_zicclsm_za128rs`,
 which include all the mandatory extensions required by this profile.
 `-march=RVA20U64+zba_zbb_zbc_zbs` is also a legal profile input, it will add
 four new extensions after expanded profile strings:
 
`-march=rv64imafdc_zicsr_ziccif_ziccrse_ziccamoa_zicclsm_za128rs_zba_zbb_zbc_zbs`
 and `-march=rva20u64` is an illegal profile input, it does not use uppercase 
letters.

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


[clang-tools-extra] [clangd] Avoid crash when summarizing pointer-to-member expr for block-end hint (PR #76492)

2023-12-28 Thread Nathan Ridge via cfe-commits

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


[clang-tools-extra] dbd1fb8 - [clangd] Avoid crash when summarizing pointer-to-member expr for block-end hint (#76492)

2023-12-28 Thread via cfe-commits

Author: Nathan Ridge
Date: 2023-12-29T02:18:48-05:00
New Revision: dbd1fb8e6f1e4a8c91059308b286f8f2a9471a8e

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

LOG: [clangd] Avoid crash when summarizing pointer-to-member expr for block-end 
hint (#76492)

For calls through a pointer to member, CXXMemberCallExpr::getCallee() is
a BinaryOperator with operator ->* (after unwrapping parens).

getMethodDecl() only returns non-null if the callee is a MemberExpr.

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

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp
clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 6fbb310b660a17..5722ca8f66eb72 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -286,7 +286,7 @@ std::string summarizeExpr(const Expr *E) {
 // Step through implicit nodes that clang doesn't classify as such.
 std::string VisitCXXMemberCallExpr(const CXXMemberCallExpr *E) {
   // Call to operator bool() inside if (X): dispatch to X.
-  if (E->getNumArgs() == 0 &&
+  if (E->getNumArgs() == 0 && E->getMethodDecl() &&
   E->getMethodDecl()->getDeclName().getNameKind() ==
   DeclarationName::CXXConversionFunctionName &&
   E->getSourceRange() ==

diff  --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 0ca95b5fed5d31..0fff0dfca6c9b8 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -2205,6 +2205,19 @@ TEST(BlockEndHints, Macro) {
   ExpectedHint{" // struct S1", "S1"});
 }
 
+TEST(BlockEndHints, PointerToMemberFunction) {
+  // Do not crash trying to summarize `a->*p`.
+  assertBlockEndHints(R"cpp(
+class A {};
+using Predicate = bool(A::*)();
+void foo(A* a, Predicate p) {
+  if ((a->*p)()) {
+  $ptrmem[[}]]
+} // suppress
+  )cpp",
+  ExpectedHint{" // if", "ptrmem"});
+}
+
 // FIXME: Low-hanging fruit where we could omit a type hint:
 //  - auto x = TypeName(...);
 //  - auto x = (TypeName) (...);



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


[clang-tools-extra] [clangd] Avoid crash when summarizing pointer-to-member expr for block-end hint (PR #76492)

2023-12-28 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> btw, it looks like there is a FIXME 
> (https://github.com/llvm/llvm-project/blob/main/clang/lib/AST/ExprCXX.cpp#L677)
>  for supporting this particular case.

I saw it, but I'm not clear on what that would look like.

Which member function a member function pointer resolves to is a runtime 
property of the pointer variable. I don't think we can produce a 
`CXXMethodDecl` there unless perhaps the pointer is a constant expression, 
which seems like an edge case.

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


[clang] [clang] Correctly implement CWG 2672 (PR #75001)

2023-12-28 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

friendly ping~

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


[clang-tools-extra] [clangd] Avoid crash when summarizing pointer-to-member expr for block-end hint (PR #76492)

2023-12-28 Thread Nathan Ridge via cfe-commits

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

>From ec31d400915dba372501c49db8bab7c8123228df Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Thu, 28 Dec 2023 02:47:04 -0500
Subject: [PATCH] [clangd] Avoid crash when summarizing pointer-to-member expr
 for block-end hint

For calls through a pointer to member, CXXMemberCallExpr::getCallee() is
a BinaryOperator with operator ->* (after unwrapping parens).

getMethodDecl() only returns non-null if the callee is a MemberExpr.

Fixes https://github.com/clangd/clangd/issues/1873
---
 clang-tools-extra/clangd/InlayHints.cpp |  2 +-
 .../clangd/unittests/InlayHintTests.cpp | 13 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 3da047f9542138..fd28b48b5a0b02 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -286,7 +286,7 @@ std::string summarizeExpr(const Expr *E) {
 // Step through implicit nodes that clang doesn't classify as such.
 std::string VisitCXXMemberCallExpr(const CXXMemberCallExpr *E) {
   // Call to operator bool() inside if (X): dispatch to X.
-  if (E->getNumArgs() == 0 &&
+  if (E->getNumArgs() == 0 && E->getMethodDecl() &&
   E->getMethodDecl()->getDeclName().getNameKind() ==
   DeclarationName::CXXConversionFunctionName &&
   E->getSourceRange() ==
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp 
b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 20c1cdd985dbc0..ea5ee18f1da65c 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -2172,6 +2172,19 @@ TEST(BlockEndHints, Macro) {
   ExpectedHint{" // struct S1", "S1"});
 }
 
+TEST(BlockEndHints, PointerToMemberFunction) {
+  // Do not crash trying to summarize `a->*p`.
+  assertBlockEndHints(R"cpp(
+class A {};
+using Predicate = bool(A::*)();
+void foo(A* a, Predicate p) {
+  if ((a->*p)()) {
+  $ptrmem[[}]]
+} // suppress
+  )cpp",
+  ExpectedHint{" // if", "ptrmem"});
+}
+
 // FIXME: Low-hanging fruit where we could omit a type hint:
 //  - auto x = TypeName(...);
 //  - auto x = (TypeName) (...);

___
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-28 Thread Mark de Wever via cfe-commits


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

mordante wrote:

returning an empty string gives an empty output. This feels wrong, returning an 
error value indicates the tool has done something with the request. No output 
may mean the request has been ignored.

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-format] Fix bad indentation with attribute and templated type (PR #76336)

2023-12-28 Thread Owen Pan via cfe-commits


@@ -26492,6 +26492,10 @@ TEST_F(FormatTest, BreakAfterAttributes) {
   verifyFormat("[[nodiscard]]\n"
"Foo& operator-(Foo&);",
Style);
+
+  verifyFormat("[[maybe_unused]]\n"
+   "foo f;",

owenca wrote:

```suggestion
   "foo k;",
```
See below.

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


[clang] [clang-format] Fix bad indentation with attribute and templated type (PR #76336)

2023-12-28 Thread Owen Pan via cfe-commits


@@ -26492,6 +26492,10 @@ TEST_F(FormatTest, BreakAfterAttributes) {
   verifyFormat("[[nodiscard]]\n"
"Foo& operator-(Foo&);",
Style);
+
+  verifyFormat("[[maybe_unused]]\n"
+   "foo f;",
+   Style);

owenca wrote:

Please move it up and insert it into `Code`:
```
  constexpr StringRef Code("[[maybe_unused]] const int i;\n"
   "[[foo([[]])]] [[maybe_unused]]\n"
   "int j;\n"
   "[[maybe_unused]]\n"
   "foo k;\n"
   "[[nodiscard]] inline int f(int );\n"
```
and update the test cases for `ABS_Never` and `ABS_Always`.

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


[llvm] [clang] [FuncAttrs] Deduce `noundef` attributes for return values (PR #76553)

2023-12-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Yingwei Zheng (dtcxzyw)


Changes

This patch deduces `noundef` attributes for return values.
IIUC, a function returns `noundef` values iff all of its return values are 
guaranteed not to be `undef` or `poison`.
Definition of `noundef` from LangRef:
```
noundef
This attribute applies to parameters and return values. If the value 
representation contains any 
undefined or poison bits, the behavior is undefined. Note that this does not 
refer to padding 
introduced by the type’s storage representation.
```
Alive2: https://alive2.llvm.org/ce/z/g8Eis6

Compile-time impact: 
http://llvm-compile-time-tracker.com/compare.php?from=7f69c8b3a6c02ea32fefb16c2016dfa1ba994858to=1dafc281ff8c04bb0a968fb3d898f08876dc59e0stat=instructions:u
|stage1-O3|stage1-ReleaseThinLTO|stage1-ReleaseLTO-g|stage1-O0-g|stage2-O3|stage2-O0-g|stage2-clang|
|--|--|--|--|--|--|--|
|+0.01%|+0.01%|-0.01%|+0.00%|+0.03%|+0.02%|+0.01%|

The motivation of this patch is to reduce the number of `freeze` insts and 
enable more optimizations.
Example:
```
diff --git a/bench/flac/optimized/replaygain.c.ll 
b/bench/flac/optimized/replaygain.c.ll
index fa826475..413bd717 100644
--- a/bench/flac/optimized/replaygain.c.ll
+++ b/bench/flac/optimized/replaygain.c.ll
@@ -63,7 +63,7 @@ entry:
 declare i32 @InitGainAnalysis(i64 noundef) local_unnamed_addr #1
 
 ; Function Attrs: nounwind sspstrong uwtable
-define dso_local i32 @grabbag__replaygain_analyze(ptr nocapture 
noundef readonly %input, i32 noundef %is_stereo, i32 noundef %bps, i32 noundef 
%samples) local_unnamed_addr #0 {
+define dso_local noundef i32 @grabbag__replaygain_analyze(ptr 
nocapture noundef readonly %input, i32 noundef %is_stereo, i32 noundef %bps, 
i32 noundef %samples) local_unnamed_addr #0 {
 entry:
   %cmp = icmp eq i32 %bps, 16
   br i1 %cmp, label %if.then, label %if.else71
@@ -337,7 +337,7 @@ entry:
 declare float @GetTitleGain() local_unnamed_addr #1
 
 ; Function Attrs: nounwind sspstrong uwtable
-define dso_local ptr @grabbag__replaygain_analyze_file(ptr noundef 
%filename, ptr nocapture noundef writeonly %title_gain, ptr nocapture noundef 
writeonly %title_peak) local_unnamed_addr #0 {
+define dso_local noundef ptr @grabbag__replaygain_analyze_file(ptr 
noundef %filename, ptr nocapture noundef writeonly %title_gain, ptr nocapture 
noundef writeonly %title_peak) local_unnamed_addr #0 {
 entry:
   %instance = alloca %struct.DecoderInstance, align 4
   %call = tail call ptr @FLAC__stream_decoder_new() #15
@@ -392,7 +392,7 @@ declare i32 @FLAC__stream_decoder_set_metadata_respond(ptr noundef, i32 noundef)
 declare i32 @FLAC__stream_decoder_init_file(ptr noundef, ptr noundef, 
ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1
 
 ; Function Attrs: nounwind sspstrong uwtable
-define internal i32 @write_callback_(ptr nocapture readnone %decoder, 
ptr nocapture noundef readonly %frame, ptr nocapture noundef readonly %buffer, 
ptr nocapture noundef %client_data) #0 {
+define internal noundef i32 @write_callback_(ptr nocapture readnone 
%decoder, ptr nocapture noundef readonly %frame, ptr nocapture noundef readonly 
%buffer, ptr nocapture noundef %client_data) #0 {
 entry:
   %bits_per_sample1 = getelementptr inbounds %struct.FLAC__FrameHeader, ptr 
%frame, i64 0, i32 4
   %0 = load i32, ptr %bits_per_sample1, align 8
@@ -429,23 +429,16 @@ land.lhs.true14:  ; preds 
= %land.lhs.true11
   %cmp16 = icmp eq i32 %2, %8
   br i1 %cmp16, label %if.end, label %if.end.thread
 
-if.end.thread:; preds = %land.lhs.true, 
%land.lhs.true14, %land.lhs.true11, %land.lhs.true8, %entry
-  store i32 1, ptr %error, align 4
-  br label %9
-
 if.end:   ; preds = %land.lhs.true14
   %conv = zext i1 %cmp to i32
   %call = tail call i32 @grabbag__replaygain_analyze(ptr noundef 
%buffer, i32 noundef %conv, i32 noundef %0, i32 noundef %3), !range !14
-  %call.fr = freeze i32 %call
-  %lnot.ext = xor i32 %call.fr, 1
-  store i32 %lnot.ext, ptr %error, align 4
-  %tobool22.not = icmp ne i32 %lnot.ext, 0
-  %spec.select = zext i1 %tobool22.not to i32
-  br label %9
-
-9:; preds = %if.end, 
%if.end.thread
-  %10 = phi i32 [ 1, %if.end.thread ], [ %spec.select, %if.end ]
-  ret i32 %10
+  %lnot.ext = xor i32 %call, 1
+  br label %if.end.thread
+
+if.end.thread:; preds = %entry, 
%land.lhs.true8, %land.lhs.true11, %land.lhs.true14, %land.lhs.true, %if.end
+  %storemerge = phi i32 [ %lnot.ext, %if.end ], [ 1, %land.lhs.true ], [ 1, 
%land.lhs.true14 ], [ 1, %land.lhs.true11 ], [ 1, %land.lhs.true8 ], [ 1, 
%entry ]
+  store i32 %storemerge, ptr %error, align 4
+  ret i32 %storemerge
 }
 
 ; Function Attrs: nounwind sspstrong uwtable

```

---

Patch is 55.83 KiB, truncated to 20.00 KiB below, full version: 

[clang] [llvm] [FuncAttrs] Deduce `noundef` attributes for return values (PR #76553)

2023-12-28 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-clang

Author: Yingwei Zheng (dtcxzyw)


Changes

This patch deduces `noundef` attributes for return values.
IIUC, a function returns `noundef` values iff all of its return values are 
guaranteed not to be `undef` or `poison`.
Definition of `noundef` from LangRef:
```
noundef
This attribute applies to parameters and return values. If the value 
representation contains any 
undefined or poison bits, the behavior is undefined. Note that this does not 
refer to padding 
introduced by the type’s storage representation.
```
Alive2: https://alive2.llvm.org/ce/z/g8Eis6

Compile-time impact: 
http://llvm-compile-time-tracker.com/compare.php?from=7f69c8b3a6c02ea32fefb16c2016dfa1ba994858to=1dafc281ff8c04bb0a968fb3d898f08876dc59e0stat=instructions:u
|stage1-O3|stage1-ReleaseThinLTO|stage1-ReleaseLTO-g|stage1-O0-g|stage2-O3|stage2-O0-g|stage2-clang|
|--|--|--|--|--|--|--|
|+0.01%|+0.01%|-0.01%|+0.00%|+0.03%|+0.02%|+0.01%|

The motivation of this patch is to reduce the number of `freeze` insts and 
enable more optimizations.
Example:
```
diff --git a/bench/flac/optimized/replaygain.c.ll 
b/bench/flac/optimized/replaygain.c.ll
index fa826475..413bd717 100644
--- a/bench/flac/optimized/replaygain.c.ll
+++ b/bench/flac/optimized/replaygain.c.ll
@@ -63,7 +63,7 @@ entry:
 declare i32 @InitGainAnalysis(i64 noundef) local_unnamed_addr #1
 
 ; Function Attrs: nounwind sspstrong uwtable
-define dso_local i32 @grabbag__replaygain_analyze(ptr nocapture 
noundef readonly %input, i32 noundef %is_stereo, i32 noundef %bps, i32 noundef 
%samples) local_unnamed_addr #0 {
+define dso_local noundef i32 @grabbag__replaygain_analyze(ptr 
nocapture noundef readonly %input, i32 noundef %is_stereo, i32 noundef %bps, 
i32 noundef %samples) local_unnamed_addr #0 {
 entry:
   %cmp = icmp eq i32 %bps, 16
   br i1 %cmp, label %if.then, label %if.else71
@@ -337,7 +337,7 @@ entry:
 declare float @GetTitleGain() local_unnamed_addr #1
 
 ; Function Attrs: nounwind sspstrong uwtable
-define dso_local ptr @grabbag__replaygain_analyze_file(ptr noundef 
%filename, ptr nocapture noundef writeonly %title_gain, ptr nocapture noundef 
writeonly %title_peak) local_unnamed_addr #0 {
+define dso_local noundef ptr @grabbag__replaygain_analyze_file(ptr 
noundef %filename, ptr nocapture noundef writeonly %title_gain, ptr nocapture 
noundef writeonly %title_peak) local_unnamed_addr #0 {
 entry:
   %instance = alloca %struct.DecoderInstance, align 4
   %call = tail call ptr @FLAC__stream_decoder_new() #15
@@ -392,7 +392,7 @@ declare i32 @FLAC__stream_decoder_set_metadata_respond(ptr noundef, i32 noundef)
 declare i32 @FLAC__stream_decoder_init_file(ptr noundef, ptr noundef, 
ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1
 
 ; Function Attrs: nounwind sspstrong uwtable
-define internal i32 @write_callback_(ptr nocapture readnone %decoder, 
ptr nocapture noundef readonly %frame, ptr nocapture noundef readonly %buffer, 
ptr nocapture noundef %client_data) #0 {
+define internal noundef i32 @write_callback_(ptr nocapture readnone 
%decoder, ptr nocapture noundef readonly %frame, ptr nocapture noundef readonly 
%buffer, ptr nocapture noundef %client_data) #0 {
 entry:
   %bits_per_sample1 = getelementptr inbounds %struct.FLAC__FrameHeader, ptr 
%frame, i64 0, i32 4
   %0 = load i32, ptr %bits_per_sample1, align 8
@@ -429,23 +429,16 @@ land.lhs.true14:  ; preds 
= %land.lhs.true11
   %cmp16 = icmp eq i32 %2, %8
   br i1 %cmp16, label %if.end, label %if.end.thread
 
-if.end.thread:; preds = %land.lhs.true, 
%land.lhs.true14, %land.lhs.true11, %land.lhs.true8, %entry
-  store i32 1, ptr %error, align 4
-  br label %9
-
 if.end:   ; preds = %land.lhs.true14
   %conv = zext i1 %cmp to i32
   %call = tail call i32 @grabbag__replaygain_analyze(ptr noundef 
%buffer, i32 noundef %conv, i32 noundef %0, i32 noundef %3), !range !14
-  %call.fr = freeze i32 %call
-  %lnot.ext = xor i32 %call.fr, 1
-  store i32 %lnot.ext, ptr %error, align 4
-  %tobool22.not = icmp ne i32 %lnot.ext, 0
-  %spec.select = zext i1 %tobool22.not to i32
-  br label %9
-
-9:; preds = %if.end, 
%if.end.thread
-  %10 = phi i32 [ 1, %if.end.thread ], [ %spec.select, %if.end ]
-  ret i32 %10
+  %lnot.ext = xor i32 %call, 1
+  br label %if.end.thread
+
+if.end.thread:; preds = %entry, 
%land.lhs.true8, %land.lhs.true11, %land.lhs.true14, %land.lhs.true, %if.end
+  %storemerge = phi i32 [ %lnot.ext, %if.end ], [ 1, %land.lhs.true ], [ 1, 
%land.lhs.true14 ], [ 1, %land.lhs.true11 ], [ 1, %land.lhs.true8 ], [ 1, 
%entry ]
+  store i32 %storemerge, ptr %error, align 4
+  ret i32 %storemerge
 }
 
 ; Function Attrs: nounwind sspstrong uwtable

```

---

Patch is 55.83 KiB, truncated to 20.00 KiB below, full version: 

[clang] [llvm] [FuncAttrs] Deduce `noundef` attributes for return values (PR #76553)

2023-12-28 Thread Yingwei Zheng via cfe-commits

https://github.com/dtcxzyw created 
https://github.com/llvm/llvm-project/pull/76553

This patch deduces `noundef` attributes for return values.
IIUC, a function returns `noundef` values iff all of its return values are 
guaranteed not to be `undef` or `poison`.
Definition of `noundef` from LangRef:
```
noundef
This attribute applies to parameters and return values. If the value 
representation contains any 
undefined or poison bits, the behavior is undefined. Note that this does not 
refer to padding 
introduced by the type’s storage representation.
```
Alive2: https://alive2.llvm.org/ce/z/g8Eis6

Compile-time impact: 
http://llvm-compile-time-tracker.com/compare.php?from=7f69c8b3a6c02ea32fefb16c2016dfa1ba994858=1dafc281ff8c04bb0a968fb3d898f08876dc59e0=instructions:u
|stage1-O3|stage1-ReleaseThinLTO|stage1-ReleaseLTO-g|stage1-O0-g|stage2-O3|stage2-O0-g|stage2-clang|
|--|--|--|--|--|--|--|
|+0.01%|+0.01%|-0.01%|+0.00%|+0.03%|+0.02%|+0.01%|

The motivation of this patch is to reduce the number of `freeze` insts and 
enable more optimizations.
Example:
```
diff --git a/bench/flac/optimized/replaygain.c.ll 
b/bench/flac/optimized/replaygain.c.ll
index fa826475..413bd717 100644
--- a/bench/flac/optimized/replaygain.c.ll
+++ b/bench/flac/optimized/replaygain.c.ll
@@ -63,7 +63,7 @@ entry:
 declare i32 @InitGainAnalysis(i64 noundef) local_unnamed_addr #1
 
 ; Function Attrs: nounwind sspstrong uwtable
-define dso_local i32 @grabbag__replaygain_analyze(ptr nocapture noundef 
readonly %input, i32 noundef %is_stereo, i32 noundef %bps, i32 noundef 
%samples) local_unnamed_addr #0 {
+define dso_local noundef i32 @grabbag__replaygain_analyze(ptr nocapture 
noundef readonly %input, i32 noundef %is_stereo, i32 noundef %bps, i32 noundef 
%samples) local_unnamed_addr #0 {
 entry:
   %cmp = icmp eq i32 %bps, 16
   br i1 %cmp, label %if.then, label %if.else71
@@ -337,7 +337,7 @@ entry:
 declare float @GetTitleGain() local_unnamed_addr #1
 
 ; Function Attrs: nounwind sspstrong uwtable
-define dso_local ptr @grabbag__replaygain_analyze_file(ptr noundef %filename, 
ptr nocapture noundef writeonly %title_gain, ptr nocapture noundef writeonly 
%title_peak) local_unnamed_addr #0 {
+define dso_local noundef ptr @grabbag__replaygain_analyze_file(ptr noundef 
%filename, ptr nocapture noundef writeonly %title_gain, ptr nocapture noundef 
writeonly %title_peak) local_unnamed_addr #0 {
 entry:
   %instance = alloca %struct.DecoderInstance, align 4
   %call = tail call ptr @FLAC__stream_decoder_new() #15
@@ -392,7 +392,7 @@ declare i32 @FLAC__stream_decoder_set_metadata_respond(ptr 
noundef, i32 noundef)
 declare i32 @FLAC__stream_decoder_init_file(ptr noundef, ptr noundef, ptr 
noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1
 
 ; Function Attrs: nounwind sspstrong uwtable
-define internal i32 @write_callback_(ptr nocapture readnone %decoder, ptr 
nocapture noundef readonly %frame, ptr nocapture noundef readonly %buffer, ptr 
nocapture noundef %client_data) #0 {
+define internal noundef i32 @write_callback_(ptr nocapture readnone %decoder, 
ptr nocapture noundef readonly %frame, ptr nocapture noundef readonly %buffer, 
ptr nocapture noundef %client_data) #0 {
 entry:
   %bits_per_sample1 = getelementptr inbounds %struct.FLAC__FrameHeader, ptr 
%frame, i64 0, i32 4
   %0 = load i32, ptr %bits_per_sample1, align 8
@@ -429,23 +429,16 @@ land.lhs.true14:  ; preds 
= %land.lhs.true11
   %cmp16 = icmp eq i32 %2, %8
   br i1 %cmp16, label %if.end, label %if.end.thread
 
-if.end.thread:; preds = %land.lhs.true, 
%land.lhs.true14, %land.lhs.true11, %land.lhs.true8, %entry
-  store i32 1, ptr %error, align 4
-  br label %9
-
 if.end:   ; preds = %land.lhs.true14
   %conv = zext i1 %cmp to i32
   %call = tail call i32 @grabbag__replaygain_analyze(ptr noundef %buffer, i32 
noundef %conv, i32 noundef %0, i32 noundef %3), !range !14
-  %call.fr = freeze i32 %call
-  %lnot.ext = xor i32 %call.fr, 1
-  store i32 %lnot.ext, ptr %error, align 4
-  %tobool22.not = icmp ne i32 %lnot.ext, 0
-  %spec.select = zext i1 %tobool22.not to i32
-  br label %9
-
-9:; preds = %if.end, 
%if.end.thread
-  %10 = phi i32 [ 1, %if.end.thread ], [ %spec.select, %if.end ]
-  ret i32 %10
+  %lnot.ext = xor i32 %call, 1
+  br label %if.end.thread
+
+if.end.thread:; preds = %entry, 
%land.lhs.true8, %land.lhs.true11, %land.lhs.true14, %land.lhs.true, %if.end
+  %storemerge = phi i32 [ %lnot.ext, %if.end ], [ 1, %land.lhs.true ], [ 1, 
%land.lhs.true14 ], [ 1, %land.lhs.true11 ], [ 1, %land.lhs.true8 ], [ 1, 
%entry ]
+  store i32 %storemerge, ptr %error, align 4
+  ret i32 %storemerge
 }
 
 ; Function Attrs: nounwind sspstrong uwtable

```

>From 30dcc33c4ea3ab50397a7adbe85fe977d4a400bd Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Fri, 29 Dec 2023 14:27:22 

[llvm] [clang] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-28 Thread John McCall via cfe-commits


@@ -4598,8 +4602,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
   if (base.getTBAAInfo().isMayAlias() ||
   rec->hasAttr() || FieldType->isVectorType()) {
 FieldTBAAInfo = TBAAAccessInfo::getMayAliasInfo();
-  } else if (rec->isUnion()) {
-// TODO: Support TBAA for unions.
+  } else if (rec->isUnion() && !CGM.getCodeGenOpts().UnionTBAA) {

rjmccall wrote:

Well, I understand your intent and was asking whether you've put any effort in 
analyzing whether this rule actually matches the standard's aliasing rules.  
For what it's worth, I think it does, at least as currently written; IIRC, the 
committee has considered various weaker rules that permit union members to 
alias.  But it's also true that this is going to make us enforce a stricter 
rule than we have been.

This patch is both implementing the stricter rules and enabling them by 
default, right?  I think we should probably stage those separately, i.e. land 
this as an opt-in feature and then try turning it on by default in a  follow-up 
commit.  That way, if we see miscompiles from this, we can (temporarily) revert 
the small commit changing the default while we're analyzing that and not have 
to revert the whole implementation.

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


[clang] [llvm] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-28 Thread John McCall via cfe-commits


@@ -184,13 +205,59 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
 return getChar();
 
   // Handle pointers and references.
-  // TODO: Implement C++'s type "similarity" and consider dis-"similar"
-  // pointers distinct.
-  if (Ty->isPointerType() || Ty->isReferenceType())
-return createScalarTypeNode("any pointer", getChar(), Size);
+  //
+  // In C11 for two pointer type to alias it is required for them to be
+  // compatible [section 6.5 p7].

rjmccall wrote:

This comment is pretty good, but it'd be better if we had a good comment on the 
function itself, and then this could be specifically in the context of that.  
Please add something like this as a doc comment on the entire function:

```
/// Return an LLVM TBAA metadata node appropriate for an access through
/// an l-value of the given type.  Type-based alias analysis takes advantage
/// of the following rules from the language standards:
///
/// C 6.5p7:
///   An object shall have its stored value accessed only by an lvalue
///   expression that has one of the following types:
///   - a type compatible with the effective type of the object,
///   - a qualified version of a type compatible with the effective
/// type of the object,
///   - a type that is the signed or unsigned type corresponding
/// to the effective type of the object,
///   - a type that is the signed or unsigned type corresponding
/// to a qualified version of the effective type of the object,
///   - an aggregate or union type that includes one of the
/// aforementioned types among its members (including,
/// recursively, a member of a subaggregate or contained union), or
///   - a character type.
///
/// C++ [basic.lval]p11:
///   If a program attempts to access the stored value of an object
///   through a glvalue whose type is not similar to one of the following
///   types the behavior is undefined:
///   - the dynamic type of the object,
///   - a type that is the signed or unsigned type corresponding
/// to the dynamic type of the object, or
///   - a char, unsigned char, or std::byte type.
///
/// The C and C++ rules about effective/dynamic type are broadly similar
/// and permit memory to be reused with a different type.  C does not have
/// an explicit operation to change the effective type of memory; any store
/// can do it.  While C++ arguably does have such an operation (the standard
/// global `operator new(void*, size_t)`), in practice it is important to
/// be just as permissive as C.  We therefore treat all stores as being able to
/// change the effective type of memory, regardless of language mode.  That is,
/// loads have both a precondition and a postcondition on the effective
/// type of the memory, but stores only have a postcondition.  This imposes
/// an inherent limitation that TBAA can only be used to reorder loads
/// before stores.  This is quite restrictive, but we don't have much of a
/// choice.  In practice, hoisting loads is the most important optimization
/// for alias analysis to enable anyway.
///
/// Therefore, given a load (and its precondition) and an earlier store
/// (and its postcondition), the question posed to TBAA is whether there
/// exists a type that is consistent with both accesses.  If there isn't,
/// it's fine to hoist the load because either the memory is non-overlapping
/// or the precondition on the load is wrong (which would be UB).
///
/// LLVM TBAA says that two accesses with TBAA metadata nodes may alias if:
/// - the metadata nodes are the same,
/// - one of the metadata nodes is a base of the other (this can be
///   recursive, but it has to be the original node that's a base,
///   not just that the nodes have a common base), or
/// - one of the metadata nodes is a `tbaa.struct` node (the access
///   necessarily being a `memcpy`) with a subobject node that would
///   be allowed to alias with the other.
///
/// Our job here is to produce metadata nodes that will never say that
/// an alias is not allowed when there exists a type that would be consistent
/// with the types of the accesses from which the nodes were produced.
///
/// The last clause in both language rules permits character types to
/// alias objects of any type.  We handle this by converting all character
/// types (as well as `std::byte` and types with the `mayalias` attribute)
/// to a single metadata node (the `char` node), then making sure that
/// that node is a base of every other metadata node we generate.
/// We can always just conservatively use this node if we aren't otherwise
/// sure how to implement the language rules for a type.
///
/// Read literally, the C rule for aggregates permits an aggregate l-value
/// (e.g. of type `struct { int x; }`) to be used to access an object that
/// is not part of an aggregate object of that type (e.g. a local variable
/// of type `int`).  That case is perhaps sensical, but it would also permit
/// e.g. an l-value of 

[llvm] [clang] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-28 Thread John McCall via cfe-commits


@@ -105,13 +105,34 @@ static bool isValidBaseType(QualType QTy) {
 if (RD->hasFlexibleArrayMember())
   return false;
 // RD can be struct, union, class, interface or enum.
-// For now, we only handle struct and class.
-if (RD->isStruct() || RD->isClass())
+if (RD->isStruct() || RD->isClass() ||
+(RD->isUnion() && CodeGenOpts.UnionTBAA))
   return true;
   }
   return false;
 }
 
+// Give unique tag for compatible types.
+std::string CodeGenTBAA::getPointeeName(const Type *Ty) {

rjmccall wrote:

Since this is always being used to build a larger string, could you make this 
append to a `raw_ostream`?

I guess `Ty` *is* guaranteed to be a canonical type here, because that's 
apparently a precondition of `getTypeInfoHelper`.  Could you assert that?

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


[llvm] [clang] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-28 Thread John McCall via cfe-commits


@@ -184,13 +199,24 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type 
*Ty) {
 return getChar();
 
   // Handle pointers and references.
-  // TODO: Implement C++'s type "similarity" and consider dis-"similar"
-  // pointers distinct.
-  if (Ty->isPointerType() || Ty->isReferenceType())
-return createScalarTypeNode("any pointer", getChar(), Size);
+  // Pointer types never alias if their pointee type is distinct.
+  if ((Ty->isPointerType() || Ty->isReferenceType())) {
+llvm::MDNode *AnyPtr = createScalarTypeNode("any pointer", getChar(), 
Size);
+if (!CodeGenOpts.PointerTBAA)
+  return AnyPtr;
+unsigned PtrDepth = 0;
+do {
+  PtrDepth++;
+  Ty = Ty->getPointeeType().getTypePtr();
+} while (!Ty->getPointeeType().isNull());

rjmccall wrote:

You're right, you do need to look through member pointers here, although this 
means you're also treating member-pointer structure as if it were just pointer 
structure.  I guess that's okay for now.

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


[clang] [clang-format] Add .clang-format-ignore for ignoring files (PR #76327)

2023-12-28 Thread Owen Pan via cfe-commits

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

>From 4afd12db61528b40d842a7fbee9af37c2235822c Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 24 Dec 2023 01:18:55 -0800
Subject: [PATCH 1/7] [clang-format] Add .clang-format.ignore for ignoring
 files

Closes #52975.
---
 clang/docs/ClangFormat.rst| 18 ++
 clang/test/Format/clang-format-ignore.cpp | 24 
 clang/tools/clang-format/ClangFormat.cpp  | 71 ++-
 3 files changed, 112 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Format/clang-format-ignore.cpp

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index f52f35550d03eb..a0b28f2273991f 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -131,6 +131,24 @@ An easy way to create the ``.clang-format`` file is:
 
 Available style options are described in :doc:`ClangFormatStyleOptions`.
 
+You can create ``.clang-format-ignore`` files to make ``clang-format`` ignore
+certain files. A ``.clang-format-ignore`` file consists of patterns of file 
path
+names. It has the following format:
+- A blank line is skipped.
+- Leading and trailing spaces of a line are trimmed.
+- A line starting with a hash (``#``) is a comment.
+- A non-comment line is a single pattern.
+- The slash (``/``) is used as the directory separator.
+- A pattern is relative to the directory of the ``.clang-format-ignore`` file
+  (or the root directory if the pattern starts with a slash).
+- Patterns follow the rules specified in POSIX 2.13.1, 2.13.2, and Rule 1 of
+  2.13.3.
+- A pattern is negated if it starts with a bang (``!``).
+To match all files in a directory, use e.g. ``foo/bar/*``. To match all files 
in
+the directory of the ``.clang-format-ignore`` file, use ``*``.
+Multiple ``.clang-format-ignore`` files are supported similar to the
+``.clang-format`` files, with a lower directory level file voiding the higher
+level ones.
 
 Vim Integration
 ===
diff --git a/clang/test/Format/clang-format-ignore.cpp 
b/clang/test/Format/clang-format-ignore.cpp
new file mode 100644
index 00..a2210266034d4c
--- /dev/null
+++ b/clang/test/Format/clang-format-ignore.cpp
@@ -0,0 +1,24 @@
+// RUN: mkdir -p %t.dir/level1/level2
+
+// RUN: cd %t.dir
+// RUN: printf "*\nlevel*/*.c*\n*/*2/foo.*\n" > .clang-format-ignore
+// RUN: touch foo.cc
+// RUN: clang-format -verbose .clang-format-ignore foo.cc 2> %t.stderr
+// RUN: not grep "Formatting" %t.stderr
+
+// RUN: cd level1
+// RUN: touch bar.cc baz.c
+// RUN: clang-format -verbose bar.cc baz.c 2> %t.stderr
+// RUN: not grep "Formatting" %t.stderr
+
+// RUN: cd level2
+// RUN: touch foo.c foo.js
+// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
+// RUN: not grep "Formatting" %t.stderr
+// RUN: printf "*.js\n" > .clang-format-ignore
+// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
+// RUN: grep -E "Formatting (.*)foo.c(.*)" %t.stderr
+// RUN: not grep -E "Formatting (.*)foo.js(.*)" %t.stderr
+
+// RUN: cd ../../..
+// RUN: rm -rf %t.dir
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index d2e3d8d43aef21..be78f8cbebf5e1 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -12,6 +12,7 @@
 ///
 
//===--===//
 
+#include "../../lib/Format/MatchFilePath.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
@@ -570,6 +571,71 @@ static int dumpConfig(bool IsSTDIN) {
   return 0;
 }
 
+// Check whether `FilePath` is ignored according to the nearest
+// .clang-format-ignore file based on the rules below:
+// - A blank line is skipped.
+// - Leading and trailing spaces of a line are trimmed.
+// - A line starting with a hash (`#`) is a comment.
+// - A non-comment line is a single pattern.
+// - The slash (`/`) is used as the directory separator.
+// - A pattern is relative to the directory of the .clang-format-ignore file 
(or
+//   the root directory if the pattern starts with a slash).
+// - A pattern is negated if it starts with a bang (`!`).
+static bool isIgnored(const StringRef FilePath) {
+  if (!llvm::sys::fs::is_regular_file(FilePath))
+return false;
+
+  using namespace llvm::sys::path;
+  SmallString<128> Path, AbsPath{convert_to_slash(FilePath)};
+
+  llvm::vfs::getRealFileSystem()->makeAbsolute(AbsPath);
+  remove_dots(AbsPath, /*remove_dot_dot=*/true);
+
+  StringRef IgnoreDir{AbsPath};
+  do {
+IgnoreDir = parent_path(IgnoreDir);
+if (IgnoreDir.empty())
+  return false;
+
+Path = IgnoreDir;
+append(Path, ".clang-format-ignore");
+  } while (!llvm::sys::fs::is_regular_file(Path));
+
+  std::ifstream IgnoreFile{Path.c_str()};
+  if (!IgnoreFile.good())
+return false;
+
+  bool HasMatch = false;
+  for (std::string Pattern; std::getline(IgnoreFile, Pattern);) {
+   

[clang] [clang-format] Add .clang-format-ignore for ignoring files (PR #76327)

2023-12-28 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Add .clang-format.ignore for ignoring files (PR #76327)

2023-12-28 Thread Owen Pan via cfe-commits


@@ -570,6 +571,74 @@ static int dumpConfig(bool IsSTDIN) {
   return 0;
 }
 
+// Check whether `FilePath` is ignored according to the nearest
+// .clang-format-ignore file based on the rules below:
+// - A blank line is skipped.
+// - Leading and trailing spaces of a line are trimmed.
+// - A line starting with a hash (`#`) is a comment.
+// - A non-comment line is a single pattern.
+// - The slash (`/`) is used as the directory separator.
+// - A pattern is relative to the directory of the .clang-format-ignore file 
(or
+//   the root directory if the pattern starts with a slash).
+// - A pattern is negated if it starts with a bang (`!`).
+static bool isIgnored(StringRef FilePath) {
+  using namespace llvm::sys::fs;
+  if (!is_regular_file(FilePath))
+return false;
+
+  using namespace llvm::sys::path;
+  SmallString<128> Path, AbsPath{FilePath};
+
+  make_absolute(AbsPath);
+  remove_dots(AbsPath, /*remove_dot_dot=*/true);
+
+  StringRef IgnoreDir{AbsPath};
+  do {
+IgnoreDir = parent_path(IgnoreDir);
+if (IgnoreDir.empty())
+  return false;
+
+Path = IgnoreDir;
+append(Path, ".clang-format-ignore");
+  } while (!is_regular_file(Path));
+
+  std::ifstream IgnoreFile{Path.c_str()};
+  if (!IgnoreFile.good())
+return false;
+
+  AbsPath = convert_to_slash(AbsPath);
+
+  bool HasMatch = false;
+  for (std::string Pattern; std::getline(IgnoreFile, Pattern);) {
+Pattern = StringRef(Pattern).trim();

owenca wrote:

I converted back to `std::string` because `StringRef` doesn't have `erase()`. 
However, I can use `drop_front()`.

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


[clang] [clang-format] Add .clang-format.ignore for ignoring files (PR #76327)

2023-12-28 Thread Owen Pan via cfe-commits


@@ -570,6 +571,74 @@ static int dumpConfig(bool IsSTDIN) {
   return 0;
 }
 
+// Check whether `FilePath` is ignored according to the nearest
+// .clang-format-ignore file based on the rules below:
+// - A blank line is skipped.
+// - Leading and trailing spaces of a line are trimmed.
+// - A line starting with a hash (`#`) is a comment.
+// - A non-comment line is a single pattern.
+// - The slash (`/`) is used as the directory separator.
+// - A pattern is relative to the directory of the .clang-format-ignore file 
(or
+//   the root directory if the pattern starts with a slash).
+// - A pattern is negated if it starts with a bang (`!`).
+static bool isIgnored(StringRef FilePath) {
+  using namespace llvm::sys::fs;
+  if (!is_regular_file(FilePath))
+return false;
+
+  using namespace llvm::sys::path;
+  SmallString<128> Path, AbsPath{FilePath};
+
+  make_absolute(AbsPath);
+  remove_dots(AbsPath, /*remove_dot_dot=*/true);
+
+  StringRef IgnoreDir{AbsPath};
+  do {
+IgnoreDir = parent_path(IgnoreDir);
+if (IgnoreDir.empty())
+  return false;
+
+Path = IgnoreDir;
+append(Path, ".clang-format-ignore");
+  } while (!is_regular_file(Path));
+
+  std::ifstream IgnoreFile{Path.c_str()};
+  if (!IgnoreFile.good())
+return false;
+
+  AbsPath = convert_to_slash(AbsPath);
+
+  bool HasMatch = false;
+  for (std::string Pattern; std::getline(IgnoreFile, Pattern);) {
+Pattern = StringRef(Pattern).trim();
+if (Pattern.empty() || Pattern[0] == '#')
+  continue;
+
+const bool IsNegated = Pattern[0] == '!';
+if (IsNegated)
+  Pattern.erase(0, 1);
+
+if (Pattern.empty())
+  continue;
+
+Pattern = StringRef(Pattern).ltrim();
+if (Pattern[0] != '/') {
+  Path = convert_to_slash(IgnoreDir);
+  append(Path, Style::posix, Pattern);
+  remove_dots(Path, /*remove_dot_dot=*/true, Style::posix);
+  Pattern = Path.str();
+}
+
+if (clang::format::matchFilePath(Pattern, AbsPath.str()) == !IsNegated) {
+  HasMatch = true;

owenca wrote:

I added the flag because I thought I had to close the file handle explicitly.

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


[clang] 2d0b55c - [Driver][test] -fbasic-block-sections: replace legacy -target with --target=

2023-12-28 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-12-28T19:39:50-08:00
New Revision: 2d0b55c7756c376b221b58cd939b320c6b569de7

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

LOG: [Driver][test] -fbasic-block-sections: replace legacy -target with 
--target=

Added: 


Modified: 
clang/test/Driver/fbasic-block-sections.c

Removed: 




diff  --git a/clang/test/Driver/fbasic-block-sections.c 
b/clang/test/Driver/fbasic-block-sections.c
index 417cf9b6319bde..24262209d1e4d5 100644
--- a/clang/test/Driver/fbasic-block-sections.c
+++ b/clang/test/Driver/fbasic-block-sections.c
@@ -1,15 +1,15 @@
-// RUN: %clang -### -target x86_64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
-// RUN: %clang -### -target x86_64 -fbasic-block-sections=all %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-ALL %s
-// RUN: %clang -### -target x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LIST %s
-// RUN: %clang -### -target x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
-// RUN: not %clang -c -target arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
-// RUN: %clang -### -target arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
+// RUN: %clang -### --target=x86_64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: %clang -### --target=x86_64 -fbasic-block-sections=all %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-ALL %s
+// RUN: %clang -### --target=x86_64 -fbasic-block-sections=list=%s %s -S 2>&1 
| FileCheck -check-prefix=CHECK-OPT-LIST %s
+// RUN: %clang -### --target=x86_64 -fbasic-block-sections=labels %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-LABELS %s
+// RUN: not %clang -c --target=arm-unknown-linux -fbasic-block-sections=all %s 
-S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: %clang -### --target=arm-unknown-linux -fbasic-block-sections=all 
-fbasic-block-sections=none %s -S 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK-NOOPT %s
-// RUN: not %clang -c -target x86_64-apple-darwin10 -fbasic-block-sections=all 
%s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
-// RUN: not %clang -### -target x86_64 -fbasic-block-sections=alll %s -S 2>&1 
| FileCheck -check-prefix=CHECK-INVALID-VALUE %s
-// RUN: not %clang -### -target x86_64 -fbasic-block-sections=list %s -S 2>&1 
| FileCheck -check-prefix=CHECK-INVALID-VALUE %s
-// RUN: %clang -### -target x86_64 -fbasic-block-sections=list= %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NULL-LIST %s
-// RUN: %clang -### -target x86_64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
+// RUN: not %clang -c --target=x86_64-apple-darwin10 
-fbasic-block-sections=all %s -S 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: not %clang -### --target=x86_64 -fbasic-block-sections=alll %s -S 2>&1 
| FileCheck -check-prefix=CHECK-INVALID-VALUE %s
+// RUN: not %clang -### --target=x86_64 -fbasic-block-sections=list %s -S 2>&1 
| FileCheck -check-prefix=CHECK-INVALID-VALUE %s
+// RUN: %clang -### --target=x86_64 -fbasic-block-sections=list= %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NULL-LIST %s
+// RUN: %clang -### --target=x86_64 -fbasic-block-sections=none %s -S 2>&1 | 
FileCheck -check-prefix=CHECK-OPT-NONE %s
 // RUN: %clang -### -x cuda -nocudainc -nocudalib --target=x86_64 
-fbasic-block-sections=all --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s -c 2>&1 
\
 // RUN:   | FileCheck -check-prefix=CHECK-CUDA %s
 



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


[clang-tools-extra] [libunwind] [llvm] [clang] [libunwind] Replace process_vm_readv with SYS_rt_sigprocmask (PR #74791)

2023-12-28 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> Hmm. It looks like `[[maybe_unused]]` is still disallowed...

`[[maybe_unused]]` should be allowed when the pull request includes commit 
47413bb2760e63a3302871ea770d6c0f5a742036 (C++17 for libunwind).

https://github.com/llvm/llvm-project/pull/74791
___
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-28 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 01/10] 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 , const PreprocessorOptions 
,
 const PCHContainerReader ,
-const FrontendOptions );
+const FrontendOptions ,
+const CodeGenOptions );
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor , 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 
,
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
-void clang::InitializePreprocessor(
-Preprocessor , const PreprocessorOptions ,
-const PCHContainerReader ,
-const FrontendOptions ) {
+void clang::InitializePreprocessor(Preprocessor ,
+   const PreprocessorOptions ,
+   const PCHContainerReader ,
+   const FrontendOptions ,
+   const CodeGenOptions ) {
   const LangOptions  = 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 78427beedb3cc4..7a100c66bbcfda 100644
--- a/compiler-rt/include/CMakeLists.txt
+++ b/compiler-rt/include/CMakeLists.txt
@@ -44,6 +44,7 @@ 

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

2023-12-28 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/9] 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 , const PreprocessorOptions 
,
 const PCHContainerReader ,
-const FrontendOptions );
+const FrontendOptions ,
+const CodeGenOptions );
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor , 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 
,
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
-void clang::InitializePreprocessor(
-Preprocessor , const PreprocessorOptions ,
-const PCHContainerReader ,
-const FrontendOptions ) {
+void clang::InitializePreprocessor(Preprocessor ,
+   const PreprocessorOptions ,
+   const PCHContainerReader ,
+   const FrontendOptions ,
+   const CodeGenOptions ) {
   const LangOptions  = 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 78427beedb3cc4..7a100c66bbcfda 100644
--- a/compiler-rt/include/CMakeLists.txt
+++ b/compiler-rt/include/CMakeLists.txt
@@ -44,6 +44,7 @@ 

[clang] [RISCV] Support __riscv_v_fixed_vlen for vbool types. (PR #76551)

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

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/76551

>From 4e651e382ef68ae3f9ff7c9f9059ea1a1bddf892 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 28 Dec 2023 16:14:32 -0800
Subject: [PATCH 1/2] [RISCV] Support __riscv_v_fixed_vlen for vbool types.

This adopts a similar behavior to AArch64 SVE, where bool vectors
are represented as a vector of chars with 1/8 the number of elements.
This ensures the vector always occupies a power of 2 number of bytes.

A consequence of this is that vbool64_t, vbool32_t, and vool16_t
can only be used with a vector length that guarantees at least 8 bits.
---
 clang/include/clang/AST/Type.h|   3 +
 clang/include/clang/Basic/AttrDocs.td |   5 +-
 clang/lib/AST/ASTContext.cpp  |  20 +-
 clang/lib/AST/ItaniumMangle.cpp   |  25 +-
 clang/lib/AST/JSONNodeDumper.cpp  |   3 +
 clang/lib/AST/TextNodeDumper.cpp  |   3 +
 clang/lib/AST/Type.cpp|  15 +-
 clang/lib/AST/TypePrinter.cpp |   2 +
 clang/lib/CodeGen/Targets/RISCV.cpp   |  21 +-
 clang/lib/Sema/SemaExpr.cpp   |   6 +-
 clang/lib/Sema/SemaType.cpp   |  21 +-
 .../attr-riscv-rvv-vector-bits-bitcast.c  | 100 ++
 .../CodeGen/attr-riscv-rvv-vector-bits-call.c |  74 +
 .../CodeGen/attr-riscv-rvv-vector-bits-cast.c |  76 -
 .../attr-riscv-rvv-vector-bits-codegen.c  | 172 +++
 .../attr-riscv-rvv-vector-bits-globals.c  | 107 +++
 .../attr-riscv-rvv-vector-bits-types.c| 284 ++
 .../riscv-mangle-rvv-fixed-vectors.cpp|  72 +
 clang/test/Sema/attr-riscv-rvv-vector-bits.c  |  88 +-
 19 files changed, 1063 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..82c4a5e8701fa5 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3492,6 +3492,9 @@ enum class VectorKind {
 
   /// is RISC-V RVV fixed-length data vector
   RVVFixedLengthData,
+
+  /// is RISC-V RVV fixed-length mask vector
+  RVVFixedLengthMask,
 };
 
 /// Represents a GCC generic vector type. This type is created using
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 98a7ecc7fd7df3..c4d69d5a50093c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2415,7 +2415,10 @@ only be a power of 2 between 64 and 65536.
 For types where LMUL!=1, ``__riscv_v_fixed_vlen`` needs to be scaled by the 
LMUL
 of the type before passing to the attribute.
 
-``vbool*_t`` types are not supported at this time.
+For ``vbool*_t`` types, ``__riscv_v_fixed_vlen`` needs to be divided by the
+number from the type name. For example, ``vbool8_t`` needs to use
+``__riscv_v_fixed_vlen`` / 8. If the resulting value is not a multiple of 8,
+the type is not supported for that value of ``__riscv_v_fixed_vlen``.
 }];
 }
 
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 0395b3e47ab6f8..97df251fef6442 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1938,7 +1938,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
 else if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)
   // Adjust the alignment for fixed-length SVE predicates.
   Align = 16;
-else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData)
+else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask)
   // Adjust the alignment for fixed-length RVV vectors.
   Align = std::min(64, Width);
 break;
@@ -9404,7 +9405,9 @@ bool ASTContext::areCompatibleVectorTypes(QualType 
FirstVec,
   Second->getVectorKind() != VectorKind::SveFixedLengthData &&
   Second->getVectorKind() != VectorKind::SveFixedLengthPredicate &&
   First->getVectorKind() != VectorKind::RVVFixedLengthData &&
-  Second->getVectorKind() != VectorKind::RVVFixedLengthData)
+  Second->getVectorKind() != VectorKind::RVVFixedLengthData &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask)
 return true;
 
   return false;
@@ -9510,8 +9513,11 @@ static uint64_t getRVVTypeSize(ASTContext , 
const BuiltinType *Ty) {
 
   ASTContext::BuiltinVectorTypeInfo Info = 
Context.getBuiltinVectorTypeInfo(Ty);
 
-  uint64_t EltSize = Context.getTypeSize(Info.ElementType);
-  uint64_t MinElts = Info.EC.getKnownMinValue();
+  unsigned EltSize = Context.getTypeSize(Info.ElementType);
+  if (Info.ElementType == Context.BoolTy)
+EltSize = 1;
+
+  unsigned MinElts = Info.EC.getKnownMinValue();
   return VScale->first * MinElts * EltSize;
 }
 
@@ -9525,6 +9531,12 @@ bool ASTContext::areCompatibleRVVTypes(QualType 
FirstType,
   auto IsValidCast = 

[clang] [RISCV] Support __riscv_v_fixed_vlen for vbool types. (PR #76551)

2023-12-28 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 2dc50d28414c827b6723ae6b01c20a7fc3f38165 
4e651e382ef68ae3f9ff7c9f9059ea1a1bddf892 -- clang/include/clang/AST/Type.h 
clang/lib/AST/ASTContext.cpp clang/lib/AST/ItaniumMangle.cpp 
clang/lib/AST/JSONNodeDumper.cpp clang/lib/AST/TextNodeDumper.cpp 
clang/lib/AST/Type.cpp clang/lib/AST/TypePrinter.cpp 
clang/lib/CodeGen/Targets/RISCV.cpp clang/lib/Sema/SemaExpr.cpp 
clang/lib/Sema/SemaType.cpp 
clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c 
clang/test/CodeGen/attr-riscv-rvv-vector-bits-call.c 
clang/test/CodeGen/attr-riscv-rvv-vector-bits-cast.c 
clang/test/CodeGen/attr-riscv-rvv-vector-bits-codegen.c 
clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c 
clang/test/CodeGen/attr-riscv-rvv-vector-bits-types.c 
clang/test/CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp 
clang/test/Sema/attr-riscv-rvv-vector-bits.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 774ca8e55f..66fc145b8f 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -2479,8 +2479,8 @@ bool Type::isRVVVLSBuiltinType() const {
 IsFP, IsBF)
\
   case BuiltinType::Id:
\
 return NF == 1;
-#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls) \
-  case BuiltinType::Id: \
+#define RVV_PREDICATE_TYPE(Name, Id, SingletonId, NumEls)  
\
+  case BuiltinType::Id:
\
 return true;
 #include "clang/Basic/RISCVVTypes.def"
 default:

``




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


[clang] [RISCV] Support __riscv_v_fixed_vlen for vbool types. (PR #76551)

2023-12-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Craig Topper (topperc)


Changes

This adopts a similar behavior to AArch64 SVE, where bool vectors are 
represented as a vector of chars with 1/8 the number of elements. This ensures 
the vector always occupies a power of 2 number of bytes.

A consequence of this is that vbool64_t, vbool32_t, and vool16_t can only be 
used with a vector length that guarantees at least 8 bits.

---

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


19 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+3) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+4-1) 
- (modified) clang/lib/AST/ASTContext.cpp (+16-4) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+17-8) 
- (modified) clang/lib/AST/JSONNodeDumper.cpp (+3) 
- (modified) clang/lib/AST/TextNodeDumper.cpp (+3) 
- (modified) clang/lib/AST/Type.cpp (+14-1) 
- (modified) clang/lib/AST/TypePrinter.cpp (+2) 
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+15-6) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+4-2) 
- (modified) clang/lib/Sema/SemaType.cpp (+15-6) 
- (modified) clang/test/CodeGen/attr-riscv-rvv-vector-bits-bitcast.c (+100) 
- (modified) clang/test/CodeGen/attr-riscv-rvv-vector-bits-call.c (+74) 
- (modified) clang/test/CodeGen/attr-riscv-rvv-vector-bits-cast.c (+72-4) 
- (modified) clang/test/CodeGen/attr-riscv-rvv-vector-bits-codegen.c (+172) 
- (modified) clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c (+107) 
- (modified) clang/test/CodeGen/attr-riscv-rvv-vector-bits-types.c (+284) 
- (modified) clang/test/CodeGenCXX/riscv-mangle-rvv-fixed-vectors.cpp (+72) 
- (modified) clang/test/Sema/attr-riscv-rvv-vector-bits.c (+86-2) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..82c4a5e8701fa5 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3492,6 +3492,9 @@ enum class VectorKind {
 
   /// is RISC-V RVV fixed-length data vector
   RVVFixedLengthData,
+
+  /// is RISC-V RVV fixed-length mask vector
+  RVVFixedLengthMask,
 };
 
 /// Represents a GCC generic vector type. This type is created using
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 98a7ecc7fd7df3..c4d69d5a50093c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2415,7 +2415,10 @@ only be a power of 2 between 64 and 65536.
 For types where LMUL!=1, ``__riscv_v_fixed_vlen`` needs to be scaled by the 
LMUL
 of the type before passing to the attribute.
 
-``vbool*_t`` types are not supported at this time.
+For ``vbool*_t`` types, ``__riscv_v_fixed_vlen`` needs to be divided by the
+number from the type name. For example, ``vbool8_t`` needs to use
+``__riscv_v_fixed_vlen`` / 8. If the resulting value is not a multiple of 8,
+the type is not supported for that value of ``__riscv_v_fixed_vlen``.
 }];
 }
 
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 0395b3e47ab6f8..97df251fef6442 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1938,7 +1938,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
 else if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)
   // Adjust the alignment for fixed-length SVE predicates.
   Align = 16;
-else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData)
+else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask)
   // Adjust the alignment for fixed-length RVV vectors.
   Align = std::min(64, Width);
 break;
@@ -9404,7 +9405,9 @@ bool ASTContext::areCompatibleVectorTypes(QualType 
FirstVec,
   Second->getVectorKind() != VectorKind::SveFixedLengthData &&
   Second->getVectorKind() != VectorKind::SveFixedLengthPredicate &&
   First->getVectorKind() != VectorKind::RVVFixedLengthData &&
-  Second->getVectorKind() != VectorKind::RVVFixedLengthData)
+  Second->getVectorKind() != VectorKind::RVVFixedLengthData &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask)
 return true;
 
   return false;
@@ -9510,8 +9513,11 @@ static uint64_t getRVVTypeSize(ASTContext , 
const BuiltinType *Ty) {
 
   ASTContext::BuiltinVectorTypeInfo Info = 
Context.getBuiltinVectorTypeInfo(Ty);
 
-  uint64_t EltSize = Context.getTypeSize(Info.ElementType);
-  uint64_t MinElts = Info.EC.getKnownMinValue();
+  unsigned EltSize = Context.getTypeSize(Info.ElementType);
+  if (Info.ElementType == Context.BoolTy)
+EltSize = 1;
+
+  unsigned MinElts = Info.EC.getKnownMinValue();
   return VScale->first * MinElts * EltSize;
 }
 
@@ -9525,6 +9531,12 @@ bool ASTContext::areCompatibleRVVTypes(QualType 
FirstType,
   auto IsValidCast = [this](QualType FirstType, QualType 

[clang] [RISCV] Support __riscv_v_fixed_vlen for vbool types. (PR #76551)

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

topperc wrote:

CC @ita-sc 

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


[clang] [RISCV] Support __riscv_v_fixed_vlen for vbool types. (PR #76551)

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

https://github.com/topperc created 
https://github.com/llvm/llvm-project/pull/76551

This adopts a similar behavior to AArch64 SVE, where bool vectors are 
represented as a vector of chars with 1/8 the number of elements. This ensures 
the vector always occupies a power of 2 number of bytes.

A consequence of this is that vbool64_t, vbool32_t, and vool16_t can only be 
used with a vector length that guarantees at least 8 bits.

>From 4e651e382ef68ae3f9ff7c9f9059ea1a1bddf892 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 28 Dec 2023 16:14:32 -0800
Subject: [PATCH] [RISCV] Support __riscv_v_fixed_vlen for vbool types.

This adopts a similar behavior to AArch64 SVE, where bool vectors
are represented as a vector of chars with 1/8 the number of elements.
This ensures the vector always occupies a power of 2 number of bytes.

A consequence of this is that vbool64_t, vbool32_t, and vool16_t
can only be used with a vector length that guarantees at least 8 bits.
---
 clang/include/clang/AST/Type.h|   3 +
 clang/include/clang/Basic/AttrDocs.td |   5 +-
 clang/lib/AST/ASTContext.cpp  |  20 +-
 clang/lib/AST/ItaniumMangle.cpp   |  25 +-
 clang/lib/AST/JSONNodeDumper.cpp  |   3 +
 clang/lib/AST/TextNodeDumper.cpp  |   3 +
 clang/lib/AST/Type.cpp|  15 +-
 clang/lib/AST/TypePrinter.cpp |   2 +
 clang/lib/CodeGen/Targets/RISCV.cpp   |  21 +-
 clang/lib/Sema/SemaExpr.cpp   |   6 +-
 clang/lib/Sema/SemaType.cpp   |  21 +-
 .../attr-riscv-rvv-vector-bits-bitcast.c  | 100 ++
 .../CodeGen/attr-riscv-rvv-vector-bits-call.c |  74 +
 .../CodeGen/attr-riscv-rvv-vector-bits-cast.c |  76 -
 .../attr-riscv-rvv-vector-bits-codegen.c  | 172 +++
 .../attr-riscv-rvv-vector-bits-globals.c  | 107 +++
 .../attr-riscv-rvv-vector-bits-types.c| 284 ++
 .../riscv-mangle-rvv-fixed-vectors.cpp|  72 +
 clang/test/Sema/attr-riscv-rvv-vector-bits.c  |  88 +-
 19 files changed, 1063 insertions(+), 34 deletions(-)

diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1afa693672860f..82c4a5e8701fa5 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -3492,6 +3492,9 @@ enum class VectorKind {
 
   /// is RISC-V RVV fixed-length data vector
   RVVFixedLengthData,
+
+  /// is RISC-V RVV fixed-length mask vector
+  RVVFixedLengthMask,
 };
 
 /// Represents a GCC generic vector type. This type is created using
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 98a7ecc7fd7df3..c4d69d5a50093c 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2415,7 +2415,10 @@ only be a power of 2 between 64 and 65536.
 For types where LMUL!=1, ``__riscv_v_fixed_vlen`` needs to be scaled by the 
LMUL
 of the type before passing to the attribute.
 
-``vbool*_t`` types are not supported at this time.
+For ``vbool*_t`` types, ``__riscv_v_fixed_vlen`` needs to be divided by the
+number from the type name. For example, ``vbool8_t`` needs to use
+``__riscv_v_fixed_vlen`` / 8. If the resulting value is not a multiple of 8,
+the type is not supported for that value of ``__riscv_v_fixed_vlen``.
 }];
 }
 
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 0395b3e47ab6f8..97df251fef6442 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1938,7 +1938,8 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const 
{
 else if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)
   // Adjust the alignment for fixed-length SVE predicates.
   Align = 16;
-else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData)
+else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
+ VT->getVectorKind() == VectorKind::RVVFixedLengthMask)
   // Adjust the alignment for fixed-length RVV vectors.
   Align = std::min(64, Width);
 break;
@@ -9404,7 +9405,9 @@ bool ASTContext::areCompatibleVectorTypes(QualType 
FirstVec,
   Second->getVectorKind() != VectorKind::SveFixedLengthData &&
   Second->getVectorKind() != VectorKind::SveFixedLengthPredicate &&
   First->getVectorKind() != VectorKind::RVVFixedLengthData &&
-  Second->getVectorKind() != VectorKind::RVVFixedLengthData)
+  Second->getVectorKind() != VectorKind::RVVFixedLengthData &&
+  First->getVectorKind() != VectorKind::RVVFixedLengthMask &&
+  Second->getVectorKind() != VectorKind::RVVFixedLengthMask)
 return true;
 
   return false;
@@ -9510,8 +9513,11 @@ static uint64_t getRVVTypeSize(ASTContext , 
const BuiltinType *Ty) {
 
   ASTContext::BuiltinVectorTypeInfo Info = 
Context.getBuiltinVectorTypeInfo(Ty);
 
-  uint64_t EltSize = Context.getTypeSize(Info.ElementType);
-  uint64_t MinElts = 

[polly] [mlir] [libc] [compiler-rt] [openmp] [clang] [clang-tools-extra] [llvm] [flang] [libcxx] [lld] [CostModel][X86] Fix fpext conversion cost for 16 elements (PR #76278)

2023-12-28 Thread via cfe-commits

https://github.com/HaohaiWen updated 
https://github.com/llvm/llvm-project/pull/76278

>From 87f3d68e82dcc752aa727f62b8b1b56b1257b343 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Sat, 23 Dec 2023 13:16:02 +0800
Subject: [PATCH 1/2] [CostModel][X86] Track fpext conversion for 16 elements

---
 llvm/test/Analysis/CostModel/X86/cast.ll | 20 
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/llvm/test/Analysis/CostModel/X86/cast.ll 
b/llvm/test/Analysis/CostModel/X86/cast.ll
index 5a83d4e81fd38e..e0173e9df4dc3b 100644
--- a/llvm/test/Analysis/CostModel/X86/cast.ll
+++ b/llvm/test/Analysis/CostModel/X86/cast.ll
@@ -616,27 +616,31 @@ define void @fp_conv(<8 x float> %a, <16 x float>%b, <4 x 
float> %c) {
 ; SSE-LABEL: 'fp_conv'
 ; SSE-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A1 = 
fpext <4 x float> %c to <4 x double>
 ; SSE-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A2 = 
fpext <8 x float> %a to <8 x double>
-; SSE-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A3 = 
fptrunc <4 x double> undef to <4 x float>
-; SSE-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A4 = 
fptrunc <8 x double> undef to <8 x float>
+; SSE-NEXT:  Cost Model: Found an estimated cost of 12 for instruction: %A3 = 
fpext <16 x float> %b to <16 x double>
+; SSE-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A4 = 
fptrunc <4 x double> undef to <4 x float>
+; SSE-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A5 = 
fptrunc <8 x double> undef to <8 x float>
 ; SSE-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
 ; AVX-LABEL: 'fp_conv'
 ; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A1 = 
fpext <4 x float> %c to <4 x double>
 ; AVX-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A2 = 
fpext <8 x float> %a to <8 x double>
-; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A3 = 
fptrunc <4 x double> undef to <4 x float>
-; AVX-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A4 = 
fptrunc <8 x double> undef to <8 x float>
+; AVX-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A3 = 
fpext <16 x float> %b to <16 x double>
+; AVX-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A4 = 
fptrunc <4 x double> undef to <4 x float>
+; AVX-NEXT:  Cost Model: Found an estimated cost of 3 for instruction: %A5 = 
fptrunc <8 x double> undef to <8 x float>
 ; AVX-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret void
 ;
 ; AVX512-LABEL: 'fp_conv'
 ; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A1 
= fpext <4 x float> %c to <4 x double>
 ; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A2 
= fpext <8 x float> %a to <8 x double>
-; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A3 
= fptrunc <4 x double> undef to <4 x float>
-; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A4 
= fptrunc <8 x double> undef to <8 x float>
+; AVX512-NEXT:  Cost Model: Found an estimated cost of 6 for instruction: %A3 
= fpext <16 x float> %b to <16 x double>
+; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A4 
= fptrunc <4 x double> undef to <4 x float>
+; AVX512-NEXT:  Cost Model: Found an estimated cost of 1 for instruction: %A5 
= fptrunc <8 x double> undef to <8 x float>
 ; AVX512-NEXT:  Cost Model: Found an estimated cost of 0 for instruction: ret 
void
 ;
   %A1 = fpext <4 x float> %c to <4 x double>
   %A2 = fpext <8 x float> %a to <8 x double>
-  %A3 = fptrunc <4 x double> undef to <4 x float>
-  %A4 = fptrunc <8 x double> undef to <8 x float>
+  %A3 = fpext <16 x float> %b to <16 x double>
+  %A4 = fptrunc <4 x double> undef to <4 x float>
+  %A5 = fptrunc <8 x double> undef to <8 x float>
   ret void
 }

>From 90c9efc967dd02a37ebf2abf0c771011ae670dea Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Sat, 23 Dec 2023 13:28:10 +0800
Subject: [PATCH 2/2] [CostModel][X86] Fix fpext conversion cost for 16
 elements

The fpext conversion cost for 16 elements should be 5.
---
 llvm/lib/Target/X86/X86TargetTransformInfo.cpp | 1 +
 llvm/test/Analysis/CostModel/X86/cast.ll   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp 
b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
index 8a04987e768a12..e7b7c9666ed43c 100644
--- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
+++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp
@@ -2223,6 +2223,7 @@ InstructionCost X86TTIImpl::getCastInstrCost(unsigned 
Opcode, Type *Dst,
   static const TypeConversionCostTblEntry AVX512FConversionTbl[] = {
 { ISD::FP_EXTEND, MVT::v8f64,   MVT::v8f32,  1 },
 { ISD::FP_EXTEND, MVT::v8f64,   MVT::v16f32, 3 },
+{ ISD::FP_EXTEND, MVT::v16f64,  MVT::v16f32, 5 }, // 

[clang] 2dc50d2 - [RISCV] Correct the CHECK prefixes in attr-riscv-rvv-vector-bits-globals.c to use the correct vector size. NFC

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

Author: Craig Topper
Date: 2023-12-28T18:15:12-08:00
New Revision: 2dc50d28414c827b6723ae6b01c20a7fc3f38165

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

LOG: [RISCV] Correct the CHECK prefixes in attr-riscv-rvv-vector-bits-globals.c 
to use the correct vector size. NFC

These were copied from AArch64 where vscale is multiplied by 128
to get the vector length.  For RISC-V, vscale is multiplied by 64.

Added: 


Modified: 
clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c

Removed: 




diff  --git a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c 
b/clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c
index 447c3803dec8e3..8bdcd9af20efca 100644
--- a/clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c
+++ b/clang/test/CodeGen/attr-riscv-rvv-vector-bits-globals.c
@@ -1,6 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
-// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +f 
-target-feature +d -target-feature +zve64d -mvscale-min=1 -mvscale-max=1 -S -O1 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-128
-// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +f 
-target-feature +d -target-feature +zve64d -mvscale-min=4 -mvscale-max=4 -S -O1 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-512
+// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +f 
-target-feature +d -target-feature +zve64d -mvscale-min=1 -mvscale-max=1 -S -O1 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-64
+// RUN: %clang_cc1 -triple riscv64-none-linux-gnu -target-feature +f 
-target-feature +d -target-feature +zve64d -mvscale-min=4 -mvscale-max=4 -S -O1 
-emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-256
 
 // REQUIRES: riscv-registered-target
 
@@ -25,17 +25,17 @@ fixed_int64m1_t global_i64;
 // WRITES
 
//===--===//
 
-// CHECK-128-LABEL: @write_global_i64(
-// CHECK-128-NEXT:  entry:
-// CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = tail call <1 x i64> 
@llvm.vector.extract.v1i64.nxv1i64( [[V:%.*]], i64 0)
-// CHECK-128-NEXT:store <1 x i64> [[CASTFIXEDSVE]], ptr @global_i64, align 
8, !tbaa [[TBAA4:![0-9]+]]
-// CHECK-128-NEXT:ret void
+// CHECK-64-LABEL: @write_global_i64(
+// CHECK-64-NEXT:  entry:
+// CHECK-64-NEXT:[[CAST_FIXED:%.*]] = tail call <1 x i64> 
@llvm.vector.extract.v1i64.nxv1i64( [[V:%.*]], i64 0)
+// CHECK-64-NEXT:store <1 x i64> [[CAST_FIXED]], ptr @global_i64, align 8, 
!tbaa [[TBAA4:![0-9]+]]
+// CHECK-64-NEXT:ret void
 //
-// CHECK-512-LABEL: @write_global_i64(
-// CHECK-512-NEXT:  entry:
-// CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = tail call <4 x i64> 
@llvm.vector.extract.v4i64.nxv1i64( [[V:%.*]], i64 0)
-// CHECK-512-NEXT:store <4 x i64> [[CASTFIXEDSVE]], ptr @global_i64, align 
8, !tbaa [[TBAA4:![0-9]+]]
-// CHECK-512-NEXT:ret void
+// CHECK-256-LABEL: @write_global_i64(
+// CHECK-256-NEXT:  entry:
+// CHECK-256-NEXT:[[CAST_FIXED:%.*]] = tail call <4 x i64> 
@llvm.vector.extract.v4i64.nxv1i64( [[V:%.*]], i64 0)
+// CHECK-256-NEXT:store <4 x i64> [[CAST_FIXED]], ptr @global_i64, align 
8, !tbaa [[TBAA4:![0-9]+]]
+// CHECK-256-NEXT:ret void
 //
 void write_global_i64(vint64m1_t v) { global_i64 = v; }
 
@@ -43,16 +43,16 @@ void write_global_i64(vint64m1_t v) { global_i64 = v; }
 // READS
 
//===--===//
 
-// CHECK-128-LABEL: @read_global_i64(
-// CHECK-128-NEXT:  entry:
-// CHECK-128-NEXT:[[TMP0:%.*]] = load <1 x i64>, ptr @global_i64, align 8, 
!tbaa [[TBAA4]]
-// CHECK-128-NEXT:[[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv1i64.v1i64( undef, <1 x i64> [[TMP0]], 
i64 0)
-// CHECK-128-NEXT:ret  [[CASTSCALABLESVE]]
+// CHECK-64-LABEL: @read_global_i64(
+// CHECK-64-NEXT:  entry:
+// CHECK-64-NEXT:[[TMP0:%.*]] = load <1 x i64>, ptr @global_i64, align 8, 
!tbaa [[TBAA4]]
+// CHECK-64-NEXT:[[CAST_SCALABLE:%.*]] = tail call  
@llvm.vector.insert.nxv1i64.v1i64( undef, <1 x i64> [[TMP0]], 
i64 0)
+// CHECK-64-NEXT:ret  [[CAST_SCALABLE]]
 //
-// CHECK-512-LABEL: @read_global_i64(
-// CHECK-512-NEXT:  entry:
-// CHECK-512-NEXT:[[TMP0:%.*]] = load <4 x i64>, ptr @global_i64, align 8, 
!tbaa [[TBAA4]]
-// CHECK-512-NEXT:[[CASTSCALABLESVE:%.*]] = tail call  
@llvm.vector.insert.nxv1i64.v4i64( undef, <4 x i64> [[TMP0]], 
i64 0)
-// CHECK-512-NEXT:ret  [[CASTSCALABLESVE]]
+// CHECK-256-LABEL: @read_global_i64(
+// CHECK-256-NEXT:  entry:
+// CHECK-256-NEXT:[[TMP0:%.*]] = load <4 x i64>, ptr @global_i64, align 8, 
!tbaa [[TBAA4]]
+// CHECK-256-NEXT:[[CAST_SCALABLE:%.*]] = tail call  
@llvm.vector.insert.nxv1i64.v4i64( undef, <4 x i64> 

[clang] [clang][Sema] deleted overriding function can have lax except spec (PR #76248)

2023-12-28 Thread Sirui Mu via cfe-commits

https://github.com/Lancern updated 
https://github.com/llvm/llvm-project/pull/76248

>From c219e38a7953b5bd494554760043053ae3b8ff60 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Sat, 23 Dec 2023 00:02:08 +0800
Subject: [PATCH 1/4] [clang][Sema] deleted overriding function can have lax
 except spec

---
 clang/lib/Sema/SemaExceptionSpec.cpp | 5 +
 clang/test/CXX/except/except.spec/p5-virtual.cpp | 4 
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index 75730ea888afb4..f8f9c9d491a18e 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -979,6 +979,11 @@ bool Sema::CheckOverridingFunctionExceptionSpec(const 
CXXMethodDecl *New,
   if (isa(New) && New->getParent()->isDependentType())
 return false;
 
+  // CWG1351: if either of the old function or the new function is defined as
+  // deleted, we don't need this check.
+  if (Old->isDeleted() || New->isDeleted())
+return false;
+
   // If the old exception specification hasn't been parsed yet, or the new
   // exception specification can't be computed yet, remember that we need to
   // perform this check when we get to the end of the outermost
diff --git a/clang/test/CXX/except/except.spec/p5-virtual.cpp 
b/clang/test/CXX/except/except.spec/p5-virtual.cpp
index 69daec6ee53347..2cecd6ce51f698 100644
--- a/clang/test/CXX/except/except.spec/p5-virtual.cpp
+++ b/clang/test/CXX/except/except.spec/p5-virtual.cpp
@@ -45,6 +45,8 @@ struct Base
   virtual void f15();
   virtual void f16();
 
+  virtual void f17() noexcept = delete;
+
   virtual void g1() throw(); // expected-note {{overridden virtual function is 
here}}
   virtual void g2() throw(int); // expected-note {{overridden virtual function 
is here}}
   virtual void g3() throw(A); // expected-note {{overridden virtual function 
is here}}
@@ -81,6 +83,8 @@ struct Derived : Base
   virtual void f15() noexcept;
   virtual void f16() throw();
 
+  virtual void f17() = delete;
+
   virtual void g1() throw(int); // expected-error {{exception specification of 
overriding function is more lax}}
   virtual void g2(); // expected-error {{exception specification of overriding 
function is more lax}}
   virtual void g3() throw(D); // expected-error {{exception specification of 
overriding function is more lax}}

>From 8a55a5e9c5b746d90a84ab2421873145348379a2 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Fri, 29 Dec 2023 10:05:44 +0800
Subject: [PATCH 2/4] only check whether New is deleted

---
 clang/lib/Sema/SemaExceptionSpec.cpp | 97 ++--
 1 file changed, 49 insertions(+), 48 deletions(-)

diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index f8f9c9d491a18e..0d815454bdcc68 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -10,7 +10,6 @@
 //
 
//===--===//
 
-#include "clang/Sema/SemaInternal.h"
 #include "clang/AST/ASTMutationListener.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/Expr.h"
@@ -19,14 +18,14 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
 #include 
 
 namespace clang {
 
-static const FunctionProtoType *GetUnderlyingFunction(QualType T)
-{
+static const FunctionProtoType *GetUnderlyingFunction(QualType T) {
   if (const PointerType *PtrTy = T->getAs())
 T = PtrTy->getPointeeType();
   else if (const ReferenceType *RefTy = T->getAs())
@@ -148,8 +147,7 @@ bool Sema::CheckSpecifiedExceptionType(QualType , 
SourceRange Range) {
   // C++11 [except.spec]p2:
   //   A type denoted in an exception-specification shall not denote [...]
   //   an rvalue reference type.
-  Diag(Range.getBegin(), diag::err_rref_in_exception_spec)
-<< T << Range;
+  Diag(Range.getBegin(), diag::err_rref_in_exception_spec) << T << Range;
   return true;
 }
   }
@@ -237,7 +235,7 @@ Sema::ResolveExceptionSpec(SourceLocation Loc, const 
FunctionProtoType *FPT) {
 InstantiateExceptionSpec(Loc, SourceDecl);
 
   const FunctionProtoType *Proto =
-SourceDecl->getType()->castAs();
+  SourceDecl->getType()->castAs();
   if (Proto->getExceptionSpecType() == clang::EST_Unparsed) {
 Diag(Loc, diag::err_exception_spec_not_parsed);
 Proto = nullptr;
@@ -245,9 +243,8 @@ Sema::ResolveExceptionSpec(SourceLocation Loc, const 
FunctionProtoType *FPT) {
   return Proto;
 }
 
-void
-Sema::UpdateExceptionSpec(FunctionDecl *FD,
-  const FunctionProtoType::ExceptionSpecInfo ) {
+void Sema::UpdateExceptionSpec(
+FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo ) {
   // If we've fully resolved the exception specification, notify listeners.
   if 

[flang] [llvm] [libcxx] [clang-tools-extra] [compiler-rt] [clang] [polly] [mlir] [lld] [CostModel][X86] Fix fpext conversion cost for 16 elements (PR #76278)

2023-12-28 Thread via cfe-commits

HaohaiWen wrote:

> I meant - llvm-mca currently says the throughput for skylake etc. is 3cy not 
> 5cy - so do you know why the intel scheduler models are underestimating the 
> throughput?

SKX schedule model reports correct lat/uops/tpt for each instruction.
vcvtps2pd: https://uops.info/html-instr/VCVTPS2PD_ZMM_YMM.html#SKX
```
Instruction   Lat   TP  Uops
Ports
VEXTRACTF64X4 (YMM, ZMM, I8)AVX512EVEX  3   1.00 / 1.00 1 / 1   
 1*p5
```
vextractf64x4: https://uops.info/html-instr/VEXTRACTF64X4_YMM_ZMM_I8.html#SKX
```
Instruction  Lat TP UopsPorts
VCVTPS2PD (ZMM, YMM)AVX512EVEX  7   1.00 / 1.09 2 / 2   
1*p05+1*p5
```

There're totally 5 uops, 3 for p5 and 2 for p05. I guess mca thought those 
3\*p5 and 2\*p05 can run in parallel.
We can see 2\*p05 indeed went to p0 from nanoBench result. Looks like there're 
some dependencies and they can't ideally run parallelly. I don't know uiCA 
analyzed it.

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


[llvm] [clang] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-28 Thread Yeting Kuo via cfe-commits

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


[llvm] [clang] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-28 Thread Yeting Kuo via cfe-commits


@@ -1024,6 +1024,7 @@ static const char *ImpliedExtsZfinx[] = {"zicsr"};
 static const char *ImpliedExtsZhinx[] = {"zhinxmin"};
 static const char *ImpliedExtsZhinxmin[] = {"zfinx"};
 static const char *ImpliedExtsZicntr[] = {"zicsr"};
+static const char *ImpliedExtsZicfiss[] = {"zicsr", "zimop", "zcmop"};

yetingk wrote:

I add a patch to not imply Zcmop and enable c.sspush when Zcmop enabled.

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


[clang] [clang][Sema] deleted overriding function can have lax except spec (PR #76248)

2023-12-28 Thread Sirui Mu via cfe-commits

Lancern wrote:

Oops, code formatter formats unrelated code. Revert and re-commit.

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


[clang] [clang][Sema] deleted overriding function can have lax except spec (PR #76248)

2023-12-28 Thread Sirui Mu via cfe-commits

https://github.com/Lancern updated 
https://github.com/llvm/llvm-project/pull/76248

>From c219e38a7953b5bd494554760043053ae3b8ff60 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Sat, 23 Dec 2023 00:02:08 +0800
Subject: [PATCH 1/2] [clang][Sema] deleted overriding function can have lax
 except spec

---
 clang/lib/Sema/SemaExceptionSpec.cpp | 5 +
 clang/test/CXX/except/except.spec/p5-virtual.cpp | 4 
 2 files changed, 9 insertions(+)

diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index 75730ea888afb4..f8f9c9d491a18e 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -979,6 +979,11 @@ bool Sema::CheckOverridingFunctionExceptionSpec(const 
CXXMethodDecl *New,
   if (isa(New) && New->getParent()->isDependentType())
 return false;
 
+  // CWG1351: if either of the old function or the new function is defined as
+  // deleted, we don't need this check.
+  if (Old->isDeleted() || New->isDeleted())
+return false;
+
   // If the old exception specification hasn't been parsed yet, or the new
   // exception specification can't be computed yet, remember that we need to
   // perform this check when we get to the end of the outermost
diff --git a/clang/test/CXX/except/except.spec/p5-virtual.cpp 
b/clang/test/CXX/except/except.spec/p5-virtual.cpp
index 69daec6ee53347..2cecd6ce51f698 100644
--- a/clang/test/CXX/except/except.spec/p5-virtual.cpp
+++ b/clang/test/CXX/except/except.spec/p5-virtual.cpp
@@ -45,6 +45,8 @@ struct Base
   virtual void f15();
   virtual void f16();
 
+  virtual void f17() noexcept = delete;
+
   virtual void g1() throw(); // expected-note {{overridden virtual function is 
here}}
   virtual void g2() throw(int); // expected-note {{overridden virtual function 
is here}}
   virtual void g3() throw(A); // expected-note {{overridden virtual function 
is here}}
@@ -81,6 +83,8 @@ struct Derived : Base
   virtual void f15() noexcept;
   virtual void f16() throw();
 
+  virtual void f17() = delete;
+
   virtual void g1() throw(int); // expected-error {{exception specification of 
overriding function is more lax}}
   virtual void g2(); // expected-error {{exception specification of overriding 
function is more lax}}
   virtual void g3() throw(D); // expected-error {{exception specification of 
overriding function is more lax}}

>From 8a55a5e9c5b746d90a84ab2421873145348379a2 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Fri, 29 Dec 2023 10:05:44 +0800
Subject: [PATCH 2/2] only check whether New is deleted

---
 clang/lib/Sema/SemaExceptionSpec.cpp | 97 ++--
 1 file changed, 49 insertions(+), 48 deletions(-)

diff --git a/clang/lib/Sema/SemaExceptionSpec.cpp 
b/clang/lib/Sema/SemaExceptionSpec.cpp
index f8f9c9d491a18e..0d815454bdcc68 100644
--- a/clang/lib/Sema/SemaExceptionSpec.cpp
+++ b/clang/lib/Sema/SemaExceptionSpec.cpp
@@ -10,7 +10,6 @@
 //
 
//===--===//
 
-#include "clang/Sema/SemaInternal.h"
 #include "clang/AST/ASTMutationListener.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/Expr.h"
@@ -19,14 +18,14 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Sema/SemaInternal.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallString.h"
 #include 
 
 namespace clang {
 
-static const FunctionProtoType *GetUnderlyingFunction(QualType T)
-{
+static const FunctionProtoType *GetUnderlyingFunction(QualType T) {
   if (const PointerType *PtrTy = T->getAs())
 T = PtrTy->getPointeeType();
   else if (const ReferenceType *RefTy = T->getAs())
@@ -148,8 +147,7 @@ bool Sema::CheckSpecifiedExceptionType(QualType , 
SourceRange Range) {
   // C++11 [except.spec]p2:
   //   A type denoted in an exception-specification shall not denote [...]
   //   an rvalue reference type.
-  Diag(Range.getBegin(), diag::err_rref_in_exception_spec)
-<< T << Range;
+  Diag(Range.getBegin(), diag::err_rref_in_exception_spec) << T << Range;
   return true;
 }
   }
@@ -237,7 +235,7 @@ Sema::ResolveExceptionSpec(SourceLocation Loc, const 
FunctionProtoType *FPT) {
 InstantiateExceptionSpec(Loc, SourceDecl);
 
   const FunctionProtoType *Proto =
-SourceDecl->getType()->castAs();
+  SourceDecl->getType()->castAs();
   if (Proto->getExceptionSpecType() == clang::EST_Unparsed) {
 Diag(Loc, diag::err_exception_spec_not_parsed);
 Proto = nullptr;
@@ -245,9 +243,8 @@ Sema::ResolveExceptionSpec(SourceLocation Loc, const 
FunctionProtoType *FPT) {
   return Proto;
 }
 
-void
-Sema::UpdateExceptionSpec(FunctionDecl *FD,
-  const FunctionProtoType::ExceptionSpecInfo ) {
+void Sema::UpdateExceptionSpec(
+FunctionDecl *FD, const FunctionProtoType::ExceptionSpecInfo ) {
   // If we've fully resolved the exception specification, notify listeners.
   if 

[llvm] [clang] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-28 Thread Yeting Kuo via cfe-commits

https://github.com/yetingk updated 
https://github.com/llvm/llvm-project/pull/66043

>From 4a73535ec7206951c6b843e11c81e6c0c01cc1d0 Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 12 Sep 2023 12:28:00 +0800
Subject: [PATCH 1/4] [RISCV] Add MC layer support for Zicfiss.

The patch adds the instructions in Zicfiss extension. Zicfiss extension is
to support shadow stack for control flow integrity.

Differential Revision: https://reviews.llvm.org/D152793
---
 .../test/Preprocessor/riscv-target-features.c |   9 ++
 llvm/docs/RISCVUsage.rst  |   2 +-
 llvm/lib/Support/RISCVISAInfo.cpp |   2 +
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |  25 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   7 ++
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |  11 +-
 .../lib/Target/RISCV/RISCVInstrInfoZicfiss.td |  71 
 llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp   |   3 +
 llvm/lib/Target/RISCV/RISCVRegisterInfo.td|   7 ++
 llvm/test/MC/RISCV/attribute-arch.s   |   3 +
 llvm/test/MC/RISCV/compressed-zicfiss.s   |  53 +
 llvm/test/MC/RISCV/rv32zicfiss-invalid.s  |  17 +++
 llvm/test/MC/RISCV/rv64zicfiss-invalid.s  |  17 +++
 llvm/test/MC/RISCV/zicfiss-valid.s| 102 ++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |   1 +
 15 files changed, 324 insertions(+), 6 deletions(-)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoZicfiss.td
 create mode 100644 llvm/test/MC/RISCV/compressed-zicfiss.s
 create mode 100644 llvm/test/MC/RISCV/rv32zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rv64zicfiss-invalid.s
 create mode 100644 llvm/test/MC/RISCV/zicfiss-valid.s

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 43fcb35aba039c..5605a5ed7f29cb 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -119,6 +119,7 @@
 // CHECK-NOT: __riscv_zfa {{.*$}}
 // CHECK-NOT: __riscv_zfbfmin {{.*$}}
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
+// CHECK-NOT: __riscv_zicfiss {{.*$}}
 // CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zimop {{.*$}}
 // CHECK-NOT: __riscv_zcmop {{.*$}}
@@ -1296,3 +1297,11 @@
 // RUN: %clang --target=riscv64-unknown-linux-gnu -march=rv64i -E -dM %s \
 // RUN:   -munaligned-access -o - | FileCheck %s 
--check-prefix=CHECK-MISALIGNED-FAST
 // CHECK-MISALIGNED-FAST: __riscv_misaligned_fast 1
+
+// RUN: %clang -target riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32izicfiss0p4 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// RUN: %clang -target riscv64 -menable-experimental-extensions \
+// RUN: -march=rv64izicfiss0p4 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZICFISS-EXT %s
+// CHECK-ZICFISS-EXT: __riscv_zicfiss 4000{{$}}
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 836a4e9ff08e55..53c56e3fb23018 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -212,7 +212,7 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zfbfmin``, ``experimental-zvfbfmin``, ``experimental-zvfbfwma``
   LLVM implements assembler support for the `0.8.0 draft specification 
`_.
 
-``experimental-zicfilp``
+``experimental-zicfilp``, ``experimental-zicfiss``
   LLVM implements the `0.4 draft specification 
`__.
 
 ``experimental-zicond``
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index 14079a0eb07603..052abc4a3a1063 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -196,6 +196,8 @@ static const RISCVSupportedExtension 
SupportedExperimentalExtensions[] = {
 {"zfbfmin", RISCVExtensionVersion{0, 8}},
 
 {"zicfilp", RISCVExtensionVersion{0, 4}},
+{"zicfiss", RISCVExtensionVersion{0, 4}},
+
 {"zicond", RISCVExtensionVersion{1, 0}},
 
 {"zimop", RISCVExtensionVersion{0, 1}},
diff --git a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp 
b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
index 184000b48987e6..d23f60302f42c7 100644
--- a/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
+++ b/llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
@@ -74,6 +74,17 @@ static DecodeStatus DecodeGPRRegisterClass(MCInst , 
uint32_t RegNo,
   return MCDisassembler::Success;
 }
 
+static DecodeStatus DecodeGPRX1X5RegisterClass(MCInst , uint32_t RegNo,
+   uint64_t Address,
+   const MCDisassembler *Decoder) {
+  MCRegister Reg = RISCV::X0 + RegNo;
+  if (Reg != RISCV::X1 && Reg != RISCV::X5)
+return MCDisassembler::Fail;
+
+  Inst.addOperand(MCOperand::createReg(Reg));
+  return MCDisassembler::Success;
+}

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

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


@@ -2164,6 +2164,12 @@ bool Driver::HandleImmediateArgs(const Compilation ) {
 return false;
   }
 
+  if (C.getArgs().hasArg(options::OPT_print_library_module_manifest_path)) {
+llvm::outs() << "module: ="

ChuanqiXu9 wrote:

I don't get why we can't just return empty string if we can't find it.

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-28 Thread Chuanqi Xu via cfe-commits


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

ChuanqiXu9 wrote:

Let's change the suffix of this file to `.cpp`

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-28 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,9 @@
+// Test that -print-library-module-manifest-path finds the correct file.

ChuanqiXu9 wrote:

Let's change the suffix.

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-28 Thread Chuanqi Xu via cfe-commits


@@ -602,6 +602,16 @@ class Driver {
   // FIXME: This should be in CompilationInfo.
   std::string GetProgramPath(StringRef Name, const ToolChain ) 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.

ChuanqiXu9 wrote:

Got it. I didn't look into the context.

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][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)

2023-12-28 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/76493

>From a891331098d34724495798650e4a6e7ad9ebefcb Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 28 Dec 2023 15:51:32 +0800
Subject: [PATCH] [clang][ASTImporter] import InstantiatedFromMember of
 ClassTemplateSpecializationDecl

---
 clang/lib/AST/ASTImporter.cpp   |  5 
 clang/unittests/AST/ASTImporterTest.cpp | 32 +
 2 files changed, 37 insertions(+)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index b61180c4f3491d..9ffae72346f2af 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6141,6 +6141,11 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateSpecializationDecl(
   InsertPos))
   // Add this partial specialization to the class template.
   ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
+if (Expected ToInstOrErr =
+import(PartialSpec->getInstantiatedFromMember()))
+  PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
+else
+  return ToInstOrErr.takeError();
 
 updateLookupTableForTemplateParameters(*ToTPList);
   } else { // Not a partial specialization.
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index ed8ecb080e268d..b4a853952f00a3 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportConflictTypeAliasTemplate) {
   EXPECT_FALSE(ImportedCallable);
 }
 
+AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) {
+  if (auto Instantiate = Node.getInstantiatedFrom()) {
+if (auto *FromPartialSpecialization =
+Instantiate.get()) {
+  return nullptr != FromPartialSpecialization->getInstantiatedFromMember();
+}
+  }
+  return false;
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) {
+  const char *Code =
+  R"(
+  template  struct B {
+template  union D;
+template  union D {};
+D d;
+  };
+  B b;
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("D"),
+  hasInstantiatedFromMember()));
+  auto *FromPartialSpecialization =
+  cast(
+  FromA->getInstantiatedFrom());
+  auto *ImportedPartialSpecialization =
+  Import(FromPartialSpecialization, Lang_CXX11);
+  EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember());
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

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


[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)

2023-12-28 Thread Qizhi Hu via cfe-commits


@@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportConflictTypeAliasTemplate) {
   EXPECT_FALSE(ImportedCallable);
 }
 
+AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) {
+  if (auto Instantiate = Node.getInstantiatedFrom()) {
+if (auto *FromPartialSpecialization =
+Instantiate.get()) {
+  return nullptr != FromPartialSpecialization->getInstantiatedFromMember();
+}
+  }
+  return false;
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) {
+  const char *Code =
+  R"(
+  template  struct B {
+template  union D;
+template  union D {};
+D d;
+  };
+  B b;
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX17);

jcsxky wrote:

fixed, use C++11 instead.

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


[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)

2023-12-28 Thread Qizhi Hu via cfe-commits

https://github.com/jcsxky updated 
https://github.com/llvm/llvm-project/pull/76493

>From 9a9a203bbea079a033a14e610a3c00dff5ec408a Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Thu, 28 Dec 2023 15:51:32 +0800
Subject: [PATCH] [clang][ASTImporter] import InstantiatedFromMember of
 ClassTemplateSpecializationDecl

---
 clang/lib/AST/ASTImporter.cpp   |  5 
 clang/unittests/AST/ASTImporterTest.cpp | 32 +
 2 files changed, 37 insertions(+)

diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index b61180c4f3491d..9ffae72346f2af 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6141,6 +6141,11 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateSpecializationDecl(
   InsertPos))
   // Add this partial specialization to the class template.
   ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
+if (Expected ToInstOrErr =
+import(PartialSpec->getInstantiatedFromMember()))
+  PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
+else
+  return ToInstOrErr.takeError();
 
 updateLookupTableForTemplateParameters(*ToTPList);
   } else { // Not a partial specialization.
diff --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index ed8ecb080e268d..3c228d0e5ecd5f 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportConflictTypeAliasTemplate) {
   EXPECT_FALSE(ImportedCallable);
 }
 
+AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) {
+  if (auto Instantiate = Node.getInstantiatedFrom()) {
+if (auto *FromPartialSpecialization =
+Instantiate.get()) {
+  return nullptr != FromPartialSpecialization->getInstantiatedFromMember();
+}
+  }
+  return false;
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) {
+  const char *Code =
+  R"(
+  template  struct B {
+template  union D;
+template  union D {};
+D d;
+  };
+  B b;
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX17);
+  auto *FromA = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl(hasName("D"),
+  hasInstantiatedFromMember()));
+  auto *FromPartialSpecialization =
+  cast(
+  FromA->getInstantiatedFrom());
+  auto *ImportedPartialSpecialization =
+  Import(FromPartialSpecialization, Lang_CXX11);
+  EXPECT_TRUE(ImportedPartialSpecialization->getInstantiatedFromMember());
+}
+
 INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
  DefaultTestValuesForRunOptions);
 

___
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-28 Thread Qiongsi Wu via cfe-commits


@@ -12,6 +12,19 @@
 #include "InstrProfilingPort.h"
 #include 
 
+// Make sure __LLVM_INSTR_PROFILE_GENERATE is always defined before
+// including instr_prof_interface.h so the interface functions are
+// declared correctly for the runtime. Additionally, make sure
+// that __LLVM_INSTR_PROFILE_GENERATE is undefined only when it is
+// not explicitly defined somewhere else.
+#ifndef __LLVM_INSTR_PROFILE_GENERATE
+#define __LLVM_INSTR_PROFILE_GENERATE
+#include "profile/instr_prof_interface.h"
+#undef __LLVM_INSTR_PROFILE_GENERATE
+#else

qiongsiwu wrote:

Yes indeed! I was not aware of the fact that we do not support instrumenting 
the profiling runtime itself. The code is simplified. 

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-28 Thread Qiongsi Wu via cfe-commits


@@ -1364,12 +1364,22 @@ static void InitializePredefinedMacros(const TargetInfo 
,
   TI.getTargetDefines(LangOpts, Builder);
 }
 
+static void InitializePGOProfileMacros(const CodeGenOptions ,
+   MacroBuilder ) {
+  if (CodeGenOpts.hasProfileInstr())
+Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE");

qiongsiwu wrote:

Ahh this is a good idea! Documentation added at 
https://github.com/llvm/llvm-project/pull/76471/files#diff-7389be311daf0b9b476c876bef04245fa3c0ad9337ce865682174bd77d53b648R2812.
 

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-28 Thread Qiongsi Wu via cfe-commits


@@ -0,0 +1,17 @@
+// RUN: %clang_pgogen -o %t %s
+// RUN: not %t
+// RUN: %clang -o %t %s
+// RUN: %t
+
+__attribute__((weak)) void __llvm_profile_reset_counters(void);
+
+__attribute__((noinline)) int bar() { return 4; }
+int foo() {
+  if (__llvm_profile_reset_counters) {
+__llvm_profile_reset_counters();
+return 0;
+  }
+  return bar();

qiongsiwu wrote:

Ah good point! I think neither `foo` or `bar` is necessary. The code is 
simplified. 

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-28 Thread Qiongsi Wu via cfe-commits


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

qiongsiwu wrote:

Got it! Thanks for the clarification! 

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-28 Thread Qiongsi Wu via cfe-commits

https://github.com/qiongsiwu commented:

@snehasish I appreciate your timely feedback! The latest commit aims at 
addressing all the comments. 

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-28 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] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

2023-12-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Craig Topper (topperc)


Changes

Instead of only handling vscale x 16 x i1 predicate vectors, handle any 
scalable i1 vector where the known minimum is divisible by 8.

This will be used on RISC-V where we have multiple sizes of predicate types.

Though I do wonder if we have the bitcast on the wrong side. Maybe we should be 
casting the fixed type to an i1 fixed vector? That would better handle cases 
where the mininum elements isn't a multiple of 8, but vscale*min_elements is.

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+14-10) 


``diff
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 6adf99531e30e3..ace4f743c77596 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2136,14 +2136,16 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *FixedSrc = dyn_cast(SrcTy)) {
   if (const auto *ScalableDst = dyn_cast(DstTy)) 
{
-// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
+// If we are casting a fixed i8 vector to a scalable i1 predicate
 // vector, use a vector insert and bitcast the result.
 bool NeedsBitCast = false;
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
 llvm::Type *OrigType = DstTy;
-if (ScalableDst == PredType &&
-FixedSrc->getElementType() == Builder.getInt8Ty()) {
-  DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableDst->getElementType()->isIntegerTy(1) &&
+ScalableDst->getElementCount().isKnownMultipleOf(8) &&
+FixedSrc->getElementType()->isIntegerTy(8)) {
+  DstTy = llvm::VectorType::get(
+  FixedSrc->getElementType(),
+  ScalableDst->getElementCount().divideCoefficientBy(8));
   ScalableDst = cast(DstTy);
   NeedsBitCast = true;
 }
@@ -2164,12 +2166,14 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *ScalableSrc = dyn_cast(SrcTy)) {
   if (const auto *FixedDst = dyn_cast(DstTy)) {
-// If we are casting a scalable 16 x i1 predicate vector to a fixed i8
+// If we are casting a scalable i1 predicate vector to a fixed i8
 // vector, bitcast the source and use a vector extract.
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
-if (ScalableSrc == PredType &&
-FixedDst->getElementType() == Builder.getInt8Ty()) {
-  SrcTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableSrc->getElementType()->isIntegerTy(1) &&
+ScalableSrc->getElementCount().isKnownMultipleOf(8) &&
+FixedDst->getElementType()->isIntegerTy(8)) {
+  SrcTy = llvm::VectorType::get(
+  FixedDst->getElementType(),
+  ScalableSrc->getElementCount().divideCoefficientBy(8));
   ScalableSrc = cast(SrcTy);
   Src = Builder.CreateBitCast(Src, SrcTy);
 }

``




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


[clang] [IRGen][AArch64][RISCV] Generalize bitcast between i1 predicate vector and i8 fixed vector. (PR #76548)

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

https://github.com/topperc created 
https://github.com/llvm/llvm-project/pull/76548

Instead of only handling vscale x 16 x i1 predicate vectors, handle any 
scalable i1 vector where the known minimum is divisible by 8.

This will be used on RISC-V where we have multiple sizes of predicate types.

Though I do wonder if we have the bitcast on the wrong side. Maybe we should be 
casting the fixed type to an i1 fixed vector? That would better handle cases 
where the mininum elements isn't a multiple of 8, but vscale*min_elements is.

>From a9af720f8a4b42077031efdb27e4868cc2af2c44 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Thu, 28 Dec 2023 16:49:03 -0800
Subject: [PATCH] [IRGen][AArch64][RISCV] Generalize bitcast between i1
 predicate vector and i8 fixed vector.

Instead of only handling vscale x 16 x i1 predicate vectors, handle
any scalable i1 vector where the known minimum is divisible by 8.

This will be used on RISC-V where we have multiple sizes of predicate
types.

Though I do wonder if we have the bitcast on the wrong side. Maybe
we should be casting the fixed type to an i1 fixed vector? That would
better handle cases where the mininum elements isn't a multiple of 8,
but vscale*min_elements is.
---
 clang/lib/CodeGen/CGExprScalar.cpp | 24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 6adf99531e30e3..ace4f743c77596 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2136,14 +2136,16 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *FixedSrc = dyn_cast(SrcTy)) {
   if (const auto *ScalableDst = dyn_cast(DstTy)) 
{
-// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
+// If we are casting a fixed i8 vector to a scalable i1 predicate
 // vector, use a vector insert and bitcast the result.
 bool NeedsBitCast = false;
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
 llvm::Type *OrigType = DstTy;
-if (ScalableDst == PredType &&
-FixedSrc->getElementType() == Builder.getInt8Ty()) {
-  DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableDst->getElementType()->isIntegerTy(1) &&
+ScalableDst->getElementCount().isKnownMultipleOf(8) &&
+FixedSrc->getElementType()->isIntegerTy(8)) {
+  DstTy = llvm::VectorType::get(
+  FixedSrc->getElementType(),
+  ScalableDst->getElementCount().divideCoefficientBy(8));
   ScalableDst = cast(DstTy);
   NeedsBitCast = true;
 }
@@ -2164,12 +2166,14 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
 // bitcast.
 if (const auto *ScalableSrc = dyn_cast(SrcTy)) {
   if (const auto *FixedDst = dyn_cast(DstTy)) {
-// If we are casting a scalable 16 x i1 predicate vector to a fixed i8
+// If we are casting a scalable i1 predicate vector to a fixed i8
 // vector, bitcast the source and use a vector extract.
-auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
-if (ScalableSrc == PredType &&
-FixedDst->getElementType() == Builder.getInt8Ty()) {
-  SrcTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
+if (ScalableSrc->getElementType()->isIntegerTy(1) &&
+ScalableSrc->getElementCount().isKnownMultipleOf(8) &&
+FixedDst->getElementType()->isIntegerTy(8)) {
+  SrcTy = llvm::VectorType::get(
+  FixedDst->getElementType(),
+  ScalableSrc->getElementCount().divideCoefficientBy(8));
   ScalableSrc = cast(SrcTy);
   Src = Builder.CreateBitCast(Src, SrcTy);
 }

___
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-28 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/8] 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 , const PreprocessorOptions 
,
 const PCHContainerReader ,
-const FrontendOptions );
+const FrontendOptions ,
+const CodeGenOptions );
 
 /// DoPrintPreprocessedInput - Implement -E mode.
 void DoPrintPreprocessedInput(Preprocessor , 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 
,
 
 /// InitializePreprocessor - Initialize the preprocessor getting it and the
 /// environment ready to process a single file.
-void clang::InitializePreprocessor(
-Preprocessor , const PreprocessorOptions ,
-const PCHContainerReader ,
-const FrontendOptions ) {
+void clang::InitializePreprocessor(Preprocessor ,
+   const PreprocessorOptions ,
+   const PCHContainerReader ,
+   const FrontendOptions ,
+   const CodeGenOptions ) {
   const LangOptions  = 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 78427beedb3cc4..7a100c66bbcfda 100644
--- a/compiler-rt/include/CMakeLists.txt
+++ b/compiler-rt/include/CMakeLists.txt
@@ -44,6 +44,7 @@ 

[clang] [Clang][AST] Fix crash in APValue::LValueBase::getType when we have invalid decl (PR #75130)

2023-12-28 Thread Shafik Yaghmour via cfe-commits


@@ -70,11 +70,13 @@ QualType APValue::LValueBase::getType() const {
 // constexpr int *p = [1]; // valid?
 //
 // For now, we take the most complete type we can find.
-for (auto *Redecl = cast(D->getMostRecentDecl()); Redecl;
+for (auto *Redecl = cast(D->getMostRecentDecl());
+ Redecl && !Redecl->isInvalidDecl();

shafik wrote:

We are dealing with ill-formed code here. So there is not "right answer", 
right? Are you saying that we might misdiagnose an error?

Or are you saying the original code is incorrect and you think there is 
well-formed code we will not do the correct thing on?

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


[clang-tools-extra] [llvm] [libcxx] [clang] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,118 @@
+// -*- 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 _LIBCPP___ALGORITHM_FOLD_H
+#define _LIBCPP___ALGORITHM_FOLD_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/invocable.h>
+#include <__concepts/movable.h>
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/invoke.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+template 
+struct in_value_result {
+  _Ip in;
+  _Tp result;
+};
+
+template 
+using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
+
+template >
+concept __indirectly_binary_left_foldable_impl =
+convertible_to<_Rp, _Up> &&//
+movable<_Tp> &&//
+movable<_Up> &&//
+convertible_to<_Tp, _Up> &&//
+invocable<_Fp&, _Up, iter_reference_t<_Ip>> && //
+assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>;
+
+template 
+concept __indirectly_binary_left_foldable =
+copy_constructible<_Fp> && //
+invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && //
+__indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, 
invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
+
+struct __fold_left_with_iter {
+  template  _Sp, class _Tp, 
__indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto
+  operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
+using _Up = decay_t>>;
+
+if (__first == __last) {
+  return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), 
_Up(std::move(__init))};
+}
+
+_Up __result = std::invoke(__f, std::move(__init), *__first);
+for (++__first; __first != __last; ++__first) {
+  __result = std::invoke(__f, std::move(__result), *__first);
+}
+
+return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), 
std::move(__result)};
+  }
+
+  template > _Fp>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto 
operator()(_Rp&& __r, _Tp __init, _Fp __f) {
+auto __result = operator()(ranges::begin(__r), ranges::end(__r), 
std::move(__init), std::ref(__f));
+
+using _Up = decay_t>>;
+return fold_left_with_iter_result, _Up>{
+std::move(__result.in), std::move(__result.result)};
+  }
+};
+
+inline namespace __cpo {
+inline constexpr auto fold_left_with_iter = __fold_left_with_iter();
+} // namespace __cpo
+
+struct __fold_left {
+  template  _Sp, class _Tp, 
__indirectly_binary_left_foldable<_Tp, _Ip> _Fp>

cjdb wrote:

See #76540 for the renaming patch.

https://github.com/llvm/llvm-project/pull/75259
___
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-28 Thread Snehasish Kumar via cfe-commits


@@ -1364,12 +1364,22 @@ static void InitializePredefinedMacros(const TargetInfo 
,
   TI.getTargetDefines(LangOpts, Builder);
 }
 
+static void InitializePGOProfileMacros(const CodeGenOptions ,
+   MacroBuilder ) {
+  if (CodeGenOpts.hasProfileInstr())
+Builder.defineMacro("__LLVM_INSTR_PROFILE_GENERATE");

snehasish wrote:

We should document these macros in the clang documentation at 
https://clang.llvm.org/docs/UsersManual.html#profiling-with-instrumentation 

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-28 Thread Snehasish Kumar via cfe-commits


@@ -12,6 +12,19 @@
 #include "InstrProfilingPort.h"
 #include 
 
+// Make sure __LLVM_INSTR_PROFILE_GENERATE is always defined before
+// including instr_prof_interface.h so the interface functions are
+// declared correctly for the runtime. Additionally, make sure
+// that __LLVM_INSTR_PROFILE_GENERATE is undefined only when it is
+// not explicitly defined somewhere else.
+#ifndef __LLVM_INSTR_PROFILE_GENERATE
+#define __LLVM_INSTR_PROFILE_GENERATE
+#include "profile/instr_prof_interface.h"
+#undef __LLVM_INSTR_PROFILE_GENERATE
+#else

snehasish wrote:

Is this `else` for the case where compiler-rt itself is instrumented? I don't 
think we support this. 

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-28 Thread Snehasish Kumar via cfe-commits


@@ -0,0 +1,17 @@
+// RUN: %clang_pgogen -o %t %s
+// RUN: not %t
+// RUN: %clang -o %t %s
+// RUN: %t
+
+__attribute__((weak)) void __llvm_profile_reset_counters(void);
+
+__attribute__((noinline)) int bar() { return 4; }
+int foo() {
+  if (__llvm_profile_reset_counters) {
+__llvm_profile_reset_counters();
+return 0;
+  }
+  return bar();

snehasish wrote:

Do we need bar or can we just return 1 here (and remove the subtraction below)? 
 Perhaps the no-inline just needs to be applied to foo then.

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-28 Thread Snehasish Kumar via cfe-commits

https://github.com/snehasish commented:

Thanks for your patience with my comments!

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-28 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


[clang] [riscv] Fix for __riscv_v_fixed_vlen in vector mask types (PR #76510)

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

topperc wrote:

I also have a patch for this that I started on 6 months ago. Let me dig it up 
and see how far along it was. I recall there being some tricky issues.

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


[clang] [clang][Sema] deleted overriding function can have lax except spec (PR #76248)

2023-12-28 Thread Shafik Yaghmour via cfe-commits


@@ -979,6 +979,11 @@ bool Sema::CheckOverridingFunctionExceptionSpec(const 
CXXMethodDecl *New,
   if (isa(New) && New->getParent()->isDependentType())
 return false;
 
+  // CWG1351: if either of the old function or the new function is defined as
+  // deleted, we don't need this check.
+  if (Old->isDeleted() || New->isDeleted())

shafik wrote:

Either they both have to be deleted or not. We should diagnose otherwise. So I 
think checking both is redundant. 

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


[clang] 6dc5ba4 - [RISCV] Remove XSfcie extension.

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

Author: Craig Topper
Date: 2023-12-28T13:54:15-08:00
New Revision: 6dc5ba4cca72a5c25597722b8a8c7dcff5fb67be

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

LOG: [RISCV] Remove XSfcie extension.

This reverts 0d3eee33f262402562a1ff28106dbb2f59031bdb and
4c37d30e22ae655394c8b3a7e292c06d393b9b44.

XSfcie is not an official SiFive extension name. It stands for
SiFive Custom Instruction Extension, which is mentioned in the S76
manual, but then elsewhere in the manual says it is not supported
for S76.

LLVM had various instructions and CSRs listed as part of this
extension, but as far as SiFive is concerned, none of them are part
of it. There are no documented extension names for these instructions
and CSRs either externally or internally.

If these are important to LLVM users, I can facilitate creating
extension names for them and have them documented. For now I'm
removing everything.

Unfortunately, these instructions and CSRs are in LLVM 17 so this
is an incompatible change.

Added: 


Modified: 
clang/test/Driver/riscv-cpus.c
clang/test/Preprocessor/riscv-target-features.c
llvm/docs/RISCVUsage.rst
llvm/docs/ReleaseNotes.rst
llvm/lib/Support/RISCVISAInfo.cpp
llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
llvm/lib/Target/RISCV/Disassembler/RISCVDisassembler.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.cpp
llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
llvm/lib/Target/RISCV/MCTargetDesc/RISCVInstPrinter.cpp
llvm/lib/Target/RISCV/RISCVFeatures.td
llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td
llvm/lib/Target/RISCV/RISCVProcessors.td
llvm/lib/Target/RISCV/RISCVSystemOperands.td
llvm/test/MC/RISCV/attribute-arch.s
llvm/test/MC/RISCV/machine-csr-names.s
llvm/unittests/Support/RISCVISAInfoTest.cpp

Removed: 
llvm/test/MC/RISCV/xsfcie-invalid.s
llvm/test/MC/RISCV/xsfcie-valid.s



diff  --git a/clang/test/Driver/riscv-cpus.c b/clang/test/Driver/riscv-cpus.c
index f32d511ec3d18b..d181755bb58507 100644
--- a/clang/test/Driver/riscv-cpus.c
+++ b/clang/test/Driver/riscv-cpus.c
@@ -153,7 +153,6 @@
 // MCPU-SIFIVE-S76: "-target-feature" "+m" "-target-feature" "+a" 
"-target-feature" "+f" "-target-feature" "+d"
 // MCPU-SIFIVE-S76: "-target-feature" "+c"
 // MCPU-SIFIVE-S76: "-target-feature" "+zicsr" "-target-feature" "+zifencei" 
"-target-feature" "+zihintpause"
-// MCPU-SIFIVE-S76: "-target-feature" "+xsfcie"
 // MCPU-SIFIVE-S76: "-target-abi" "lp64d"
 
 // mcpu with default march

diff  --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 43fcb35aba039c..b16a1b0c17300a 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -33,7 +33,6 @@
 // CHECK-NOT: __riscv_xcvmac {{.*$}}
 // CHECK-NOT: __riscv_xcvmem {{.*$}}
 // CHECK-NOT: __riscv_xcvsimd {{.*$}}
-// CHECK-NOT: __riscv_xsfcie {{.*$}}
 // CHECK-NOT: __riscv_xsfvcp {{.*$}}
 // CHECK-NOT: __riscv_xsfvfnrclipxfqf {{.*$}}
 // CHECK-NOT: __riscv_xsfvfwmaccqqq {{.*$}}
@@ -315,14 +314,6 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-XCVSIMD-EXT %s
 // CHECK-XCVSIMD-EXT: __riscv_xcvsimd 100{{$}}
 
-// RUN: %clang --target=riscv32-unknown-linux-gnu \
-// RUN: -march=rv32ixsfcie -x c -E -dM %s \
-// RUN: -o - | FileCheck --check-prefix=CHECK-XSFCIE-EXT %s
-// RUN: %clang --target=riscv64-unknown-linux-gnu \
-// RUN: -march=rv64ixsfcie -x c -E -dM %s \
-// RUN: -o - | FileCheck --check-prefix=CHECK-XSFCIE-EXT %s
-// CHECK-XSFCIE-EXT: __riscv_xsfcie 100{{$}}
-
 // RUN: %clang --target=riscv32-unknown-linux-gnu \
 // RUN: -march=rv32ixsfvcp -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-XSFVCP-EXT %s

diff  --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 836a4e9ff08e55..4dc04bc8361e67 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -300,9 +300,6 @@ The current vendor extensions supported are:
 ``XCVbi``
   LLVM implements `version 1.0.0 of the CORE-V immediate branching custom 
instructions specification 
`_
 by OpenHW Group.  All instructions are prefixed with `cv.` as described in the 
specification. These instructions are only available for riscv32 at this time.
 
-``XSfcie``
-  LLVM implements `version 1.0.0 of the SiFive Custom Instruction Extension 
(CIE) Software Specification 
`_
 by SiFive.  All custom instruction are added as described in the 
specification, and the riscv-toolchain-convention document linked above. These 
instructions are only available for 

[clang] [analyzer][solver] On SymSym RelOps, check EQClass members for contradictions (PR #71284)

2023-12-28 Thread via cfe-commits

DonatNagyE wrote:

I'd like to abstain from deciding this question.

Personally I don't like the idea that we add yet another hack that'll remain in 
the codebase forever and slows down all other development efforts in this area 
(as contributors who want to understand this logic will need to study some 
extra logic); but if a more experienced reviewer (e.g @Xazax-hun or @martong) 
accepts this PR, the I won't oppose it. 

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


[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)

2023-12-28 Thread Shafik Yaghmour via cfe-commits

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


[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)

2023-12-28 Thread Shafik Yaghmour via cfe-commits


@@ -9342,6 +9342,38 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportConflictTypeAliasTemplate) {
   EXPECT_FALSE(ImportedCallable);
 }
 
+AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) {
+  if (auto Instantiate = Node.getInstantiatedFrom()) {
+if (auto *FromPartialSpecialization =
+Instantiate.get()) {
+  return nullptr != FromPartialSpecialization->getInstantiatedFromMember();
+}
+  }
+  return false;
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportInstantiatedFromMember) {
+  const char *Code =
+  R"(
+  template  struct B {
+template  union D;
+template  union D {};
+D d;
+  };
+  B b;
+  )";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX17);

shafik wrote:

nitpick, I don't think this requires C++17 even though the original test case 
uses C++17.

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


[clang] [clang][ASTImporter] import InstantiatedFromMember of ClassTemplateSpecializationDecl (PR #76493)

2023-12-28 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

LGTM but I will let @balazske approve

https://github.com/llvm/llvm-project/pull/76493
___
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-28 Thread Snehasish Kumar via cfe-commits


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

snehasish wrote:

Yes, my previous comment about other frontends was based on my (incorrect) 
understanding header inclusion in InstrProfiling.h. Adding the macros in this 
PR sgtm.

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] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,93 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// 
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// template S, class T,
+//  indirectly-binary-left-foldable F>
+//   constexpr see below ranges::fold_left(I first, S last, T init, F f);
+//
+// template> F>
+//   constexpr see below ranges::fold_left(R&& r, T init, F f);
+
+#include 
+#include 
+#include 
+#include 
+
+#include "test_range.h"
+#include "../gaussian_sum.h"
+
+constexpr bool test() {
+  {
+auto data = std::vector{1, 2, 3, 4};
+auto const result = std::ranges::fold_left(data.begin(), data.begin(), 0, 
std::plus());
+
+assert(result == 0);
+
+auto range = std::span(data.data(), 0);
+assert(std::ranges::fold_left(range, 0, std::plus()) == result);
+  }

cjdb wrote:

I've completely separated them per more recent feedback below.

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


[clang-tools-extra] [libcxx] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,118 @@
+// -*- 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 _LIBCPP___ALGORITHM_FOLD_H
+#define _LIBCPP___ALGORITHM_FOLD_H
+
+#include <__concepts/assignable.h>
+#include <__concepts/convertible_to.h>
+#include <__concepts/invocable.h>
+#include <__concepts/movable.h>
+#include <__config>
+#include <__functional/invoke.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/iterator_traits.h>
+#include <__iterator/next.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__ranges/dangling.h>
+#include <__type_traits/decay.h>
+#include <__type_traits/invoke.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+template 
+struct in_value_result {
+  _Ip in;
+  _Tp result;
+};
+
+template 
+using fold_left_with_iter_result = in_value_result<_Ip, _Tp>;
+
+template >
+concept __indirectly_binary_left_foldable_impl =
+convertible_to<_Rp, _Up> &&//
+movable<_Tp> &&//
+movable<_Up> &&//
+convertible_to<_Tp, _Up> &&//
+invocable<_Fp&, _Up, iter_reference_t<_Ip>> && //
+assignable_from<_Up&, invoke_result_t<_Fp&, _Up, iter_reference_t<_Ip>>>;
+
+template 
+concept __indirectly_binary_left_foldable =
+copy_constructible<_Fp> && //
+invocable<_Fp&, _Tp, iter_reference_t<_Ip>> && //
+__indirectly_binary_left_foldable_impl<_Fp, _Tp, _Ip, 
invoke_result_t<_Fp&, _Tp, iter_reference_t<_Ip>>>;
+
+struct __fold_left_with_iter {
+  template  _Sp, class _Tp, 
__indirectly_binary_left_foldable<_Tp, _Ip> _Fp>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto
+  operator()(_Ip __first, _Sp __last, _Tp __init, _Fp __f) {
+using _Up = decay_t>>;
+
+if (__first == __last) {
+  return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), 
_Up(std::move(__init))};
+}
+
+_Up __result = std::invoke(__f, std::move(__init), *__first);
+for (++__first; __first != __last; ++__first) {
+  __result = std::invoke(__f, std::move(__result), *__first);
+}
+
+return fold_left_with_iter_result<_Ip, _Up>{std::move(__first), 
std::move(__result)};
+  }
+
+  template > _Fp>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto 
operator()(_Rp&& __r, _Tp __init, _Fp __f) {
+auto __result = operator()(ranges::begin(__r), ranges::end(__r), 
std::move(__init), std::ref(__f));
+
+using _Up = decay_t>>;
+return fold_left_with_iter_result, _Up>{
+std::move(__result.in), std::move(__result.result)};
+  }
+};
+
+inline namespace __cpo {
+inline constexpr auto fold_left_with_iter = __fold_left_with_iter();
+} // namespace __cpo
+
+struct __fold_left {
+  template  _Sp, class _Tp, 
__indirectly_binary_left_foldable<_Tp, _Ip> _Fp>

cjdb wrote:

I am okay with the current resolution given that a discussion has happened, and 
am happy to make a dedicated migration patch for all `_Ip`/`_Sp` names. This 
has **not** been applied in #76534: I'll make a dedicated commit for that in 
about an hour.

I think that the contribution guidelines should probably issue guidance on what 
kinds of names we expect, especially when it comes to names that we want to 
have some element of consistency for. Perhaps that could be the subject of the 
new discussion.

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


[clang-tools-extra] [libcxx] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,315 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// 
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// template S, class T,
+//  indirectly-binary-left-foldable F>
+//   constexpr see below ranges::fold_left_with_iter(I first, S last, T init, 
F f);
+//
+// template> F>
+//   constexpr see below ranges::fold_left_with_iter(R&& r, T init, F f);
+
+// template S, class T,
+//  indirectly-binary-left-foldable F>
+//   constexpr see below ranges::fold_left(I first, S last, T init, F f);
+//
+// template> F>
+//   constexpr see below ranges::fold_left(R&& r, T init, F f);
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_range.h"
+#include "invocable_with_telemetry.h"
+#include "maths.h"
+
+using std::ranges::fold_left;
+using std::ranges::fold_left_with_iter;
+
+template 
+concept is_in_value_result =
+std::same_as, T>>;
+
+template 
+concept is_dangling_with = std::same_as>;
+
+struct Long {

cjdb wrote:

Agreed. Renamed in #76534.

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


[clang-tools-extra] [libcxx] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,259 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// 
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// Checks that `std::ranges::fold_left_with_iter`'s requirements reject 
parameters that don't meet

cjdb wrote:

Applied in #76534.

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,104 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// template 
+// struct in_value_result;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "MoveOnly.h"
+
+struct A {
+  explicit A(int);
+};
+// no implicit conversion
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result>);
+
+struct B {
+  B(int);
+};
+// implicit conversion
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result>);
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result&>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result&>);
+
+struct C {
+  C(int&);
+};
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result&>);
+
+// has to be convertible via const&
+static_assert(std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+
+// should be move constructible
+static_assert(std::is_move_constructible_v>);
+static_assert(std::is_move_constructible_v>);
+
+// should not copy constructible with move-only type
+static_assert(!std::is_copy_constructible_v>);
+static_assert(!std::is_copy_constructible_v>);
+
+struct NotConvertible {};
+// conversions should not work if there is no conversion
+static_assert(
+!std::is_convertible_v, 
std::ranges::in_value_result>);
+static_assert(
+!std::is_convertible_v, 
std::ranges::in_value_result>);
+
+template 
+struct ConvertibleFrom {
+  constexpr ConvertibleFrom(T c) : content{c} {}
+  T content;
+};
+
+constexpr bool test() {
+  {

cjdb wrote:

I lifted these from one of the other tests in this directory, so we should add 
the description to all of them. Applied in #76534.

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,89 @@
+//===--===//
+//
+// 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 TEST_SUPPORT_INVOCABLE_WITH_TELEMETRY_H

cjdb wrote:

My guess is "probably not", though we should come up with a consistent design 
(happy to work with you on that). I wasn't aware of those two, but the contents 
of `support/counting_predicates.h` weren't quite right for the application. I 
suggest we consolidate all of the counting invocable types into a single 
`counting_invocable` or `TracedInvocable` so that there's only one canonical 
type.

Looking at `TracedCopyMove`, it looks like it'll need a call operator added. 
Would you like me to add tests for explicitly counting copies and moves? It may 
be better to have these be separate tests for modularity.

Nothing has been applied yet, but I suspect a change to be made in the next 
week or so.

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


[clang-tools-extra] [libcxx] [clang] [llvm] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,89 @@
+//===--===//
+//
+// 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 TEST_SUPPORT_INVOCABLE_WITH_TELEMETRY_H
+#define TEST_SUPPORT_INVOCABLE_WITH_TELEMETRY_H
+
+#include 
+#include 
+#include 
+#include 
+
+#if TEST_STD_VER < 20
+#  error invocable_with_telemetry requires C++20
+#else
+struct invocable_telemetry {

cjdb wrote:

Thoughts summarised in the comment below.

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


[clang] [clang-tools-extra] [llvm] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,104 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// template 
+// struct in_value_result;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "MoveOnly.h"
+
+struct A {
+  explicit A(int);
+};
+// no implicit conversion
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result>);
+
+struct B {
+  B(int);
+};
+// implicit conversion
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result>);
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result&>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result&>);
+
+struct C {
+  C(int&);
+};
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result&>);
+
+// has to be convertible via const&
+static_assert(std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+
+// should be move constructible
+static_assert(std::is_move_constructible_v>);
+static_assert(std::is_move_constructible_v>);
+
+// should not copy constructible with move-only type
+static_assert(!std::is_copy_constructible_v>);
+static_assert(!std::is_copy_constructible_v>);
+
+struct NotConvertible {};
+// conversions should not work if there is no conversion
+static_assert(
+!std::is_convertible_v, 
std::ranges::in_value_result>);
+static_assert(
+!std::is_convertible_v, 
std::ranges::in_value_result>);
+
+template 
+struct ConvertibleFrom {
+  constexpr ConvertibleFrom(T c) : content{c} {}
+  T content;
+};
+
+constexpr bool test() {
+  {
+std::ranges::in_value_result res{10, 0.};
+assert(res.in == 10);
+assert(res.value == 0.);
+std::ranges::in_value_result, 
ConvertibleFrom> res2 = res;
+assert(res2.in.content == 10);
+assert(res2.value.content == 0.);
+  }

cjdb wrote:

I've applied this in #76534.

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits


@@ -0,0 +1,104 @@
+//===--===//
+//
+// 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
+//
+//===--===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
+
+// template 
+// struct in_value_result;
+
+#include 
+#include 
+#include 
+#include 
+
+#include "MoveOnly.h"
+
+struct A {
+  explicit A(int);
+};
+// no implicit conversion
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result>);
+
+struct B {
+  B(int);
+};
+// implicit conversion
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result>);
+static_assert(std::is_constructible_v, 
std::ranges::in_value_result&>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result>);
+static_assert(
+std::is_constructible_v, const 
std::ranges::in_value_result&>);
+
+struct C {
+  C(int&);
+};
+static_assert(!std::is_constructible_v, 
std::ranges::in_value_result&>);
+
+// has to be convertible via const&
+static_assert(std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+static_assert(
+std::is_convertible_v&&, 
std::ranges::in_value_result>);
+
+// should be move constructible
+static_assert(std::is_move_constructible_v>);
+static_assert(std::is_move_constructible_v>);
+
+// should not copy constructible with move-only type

cjdb wrote:

> I fully agree that adding this to a project-wide style guide would be very 
> useful (to be clear, I don't mean to imply it has to be a comprehensive huge 
> guide, even if it documents just a few randomly chosen aspects, it's already 
> helpful and we can always expand later). We do have a ["Coding 
> standards"](https://libcxx.llvm.org/Contributing.html#coding-standards) 
> section in the `Contributing` document -- we might want to add a new page and 
> link it from that section. Thanks for taking this on!

Re ultranit: applied in #76534.

Re second comment: Not sure what this is pertaining to?

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


[clang-tools-extra] [llvm] [clang] [libcxx] [libcxx] adds ranges::fold_left_with_iter and ranges::fold_left (PR #75259)

2023-12-28 Thread Christopher Di Bella via cfe-commits

cjdb wrote:

> > I see @var-const has "requested changes" set, but I feel we've addressed 
> > the one unresolved comment of his.
> 
> @EricWF In fact, this patch changed quite significantly since I last looked 
> at it (based on your feedback, I believe), so I would have appreciated being 
> able to do another round of review before this was merged.

That is fair. My understanding is that Eric was trying to balance respecting 
that you might have feedback with me struggling to switch off while OOO, if a 
PR is still in my "active context".

I ended up coming back into the office early, and prioritised applying your 
feedback as a result (see #76534). Please do make further commentary as 
necessary.

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


[clang] [Clang][Parser] Fix crash of clang when using C++ constructs like :: in C code (PR #74926)

2023-12-28 Thread via cfe-commits

ChipsSpectre wrote:

@tahonermann @AaronBallman @nicolasvasilache @dcaballe Could you please approve 
this issue?

The bug is fixed and already approved twice, but the pull request can not be 
landed without your approval.

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


[clang] [analyzer] Add documentation for std::variant checker (PR #76501)

2023-12-28 Thread Gábor Spaits via cfe-commits

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


[clang] 1d2fab7 - [analyzer] Add documentation for std::variant checker (#76501)

2023-12-28 Thread via cfe-commits

Author: Gábor Spaits
Date: 2023-12-28T22:19:51+01:00
New Revision: 1d2fab74af73a279a21641b6649dca59f70e6519

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

LOG: [analyzer] Add documentation for std::variant checker (#76501)

Add a short documentation for `StdVariantChecker`.

-

Co-authored-by: Balazs Benics 
Co-authored-by: whisperity 
Co-authored-by: DonatNagyE 

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/analyzer/checkers.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e21ec78a1e8a77..3c08d1808b0e7f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1072,6 +1072,7 @@ New features
 
 - Added a new experimental checker ``alpha.core.StdVariant`` to detect variant
   accesses via wrong alternatives.
+  `Documentation 
`__.
   (`#66481 `_)
 
 - Added a new experimental checker ``alpha.cplusplus.ArrayDelete`` to detect

diff  --git a/clang/docs/analyzer/checkers.rst 
b/clang/docs/analyzer/checkers.rst
index 64a4752695f11f..bb637cf1b8007b 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2095,6 +2095,21 @@ This checker is a part of ``core.StackAddressEscape``, 
but is temporarily disabl
  //   returned block
  }
 
+.. _alpha-core-StdVariant:
+
+alpha.core.StdVariant (C++)
+"""
+Check if a value of active type is retrieved from an ``std::variant`` instance 
with ``std::get``.
+In case of bad variant type access (the accessed type 
diff ers from the active type)
+a warning is emitted. Currently, this checker does not take exception handling 
into account.
+
+.. code-block:: cpp
+
+ void test() {
+   std::variant v = 25;
+   char c = stg::get(v); // warn: "int" is the active alternative
+ }
+
 .. _alpha-core-TestAfterDivZero:
 
 alpha.core.TestAfterDivZero (C)



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


[clang] [clang-format] Fix bad indentation with attribute and templated type (PR #76336)

2023-12-28 Thread via cfe-commits

XDeme wrote:

Hi, Thanks for reviewing, could you merge this for me? I don't have write access

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


[clang] [flang] [flang][driver] Rename `flang-new` as `flang` (PR #74377)

2023-12-28 Thread Steve Scalpone via cfe-commits

sscalpone wrote:

Still gathering feedback 
https://discourse.llvm.org/t/proposal-rename-flang-new-to-flang/69462/54

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


[clang] [analyzer] Add documentation for std::variant checker (PR #76501)

2023-12-28 Thread Gábor Spaits via cfe-commits

spaits wrote:

I will merge the PR when the CI builds have finished. Thank you for reviewing.

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


[clang] [analyzer] Add documentation for std::variant checker (PR #76501)

2023-12-28 Thread Balazs Benics via cfe-commits
=?utf-8?q?G=C3=A1bor?= Spaits,=?utf-8?q?G=C3=A1bor?= Spaits,
=?utf-8?q?G=C3=A1bor?= Spaits,Balazs Benics 
Message-ID:
In-Reply-To: 


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

LGTM now. Thanks.

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


[clang] [analyzer] Add documentation for std::variant checker (PR #76501)

2023-12-28 Thread Balazs Benics via cfe-commits
=?utf-8?q?Gábor?= Spaits,=?utf-8?q?Gábor?= Spaits,
=?utf-8?q?Gábor?= Spaits,Balazs Benics 
Message-ID:
In-Reply-To: 


https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/76501

>From b271420a6e4ed23abf2749d767f986aa16d9fe9d Mon Sep 17 00:00:00 2001
From: Gabor Spaits 
Date: Thu, 28 Dec 2023 14:17:55 +0100
Subject: [PATCH 1/6] [analyzer] Add documentation for std::variant checker

---
 clang/docs/ReleaseNotes.rst  |  1 +
 clang/docs/analyzer/checkers.rst | 15 +++
 2 files changed, 16 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e21ec78a1e8a77..bf63cc981eb32d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -1072,6 +1072,7 @@ New features
 
 - Added a new experimental checker ``alpha.core.StdVariant`` to detect variant
   accesses via wrong alternatives.
+  `Documentation 
`__.
   (`#66481 `_)
 
 - Added a new experimental checker ``alpha.cplusplus.ArrayDelete`` to detect
diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 64a4752695f11f..94c712f63d5ba3 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2095,6 +2095,21 @@ This checker is a part of ``core.StackAddressEscape``, 
but is temporarily disabl
  //   returned block
  }
 
+.. _alpha-core-StdVariant:
+
+alpha.core.StdVariant (C++)
+"""
+Check if a value of active type is retrieved from an ``std::variant`` instance 
with ``std::get``.
+In case of bad variant type access(the accessed type differs from the active 
type)
+a warning is emitted. Currently this checker does not take exception handling 
into account.
+
+.. code-block:: cpp
+
+ void test() {
+   std::variant  v = 25;
+   char c = stg::get(v); // warn
+ }
+
 .. _alpha-core-TestAfterDivZero:
 
 alpha.core.TestAfterDivZero (C)

>From 450fd58fd64e64b2a0df6cb90b6c232b2d84ece6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A1bor=20Spaits?=
 <48805437+spa...@users.noreply.github.com>
Date: Thu, 28 Dec 2023 17:11:39 +0100
Subject: [PATCH 2/6] Update clang/docs/analyzer/checkers.rst

Co-authored-by: Balazs Benics 
---
 clang/docs/analyzer/checkers.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 94c712f63d5ba3..7903ad75bcb831 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2101,7 +2101,7 @@ alpha.core.StdVariant (C++)
 """
 Check if a value of active type is retrieved from an ``std::variant`` instance 
with ``std::get``.
 In case of bad variant type access(the accessed type differs from the active 
type)
-a warning is emitted. Currently this checker does not take exception handling 
into account.
+a warning is emitted. Currently, this checker does not take exception handling 
into account.
 
 .. code-block:: cpp
 

>From 6ba5052007ef724e90f6665d6df350ee6d9aa1f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A1bor=20Spaits?=
 <48805437+spa...@users.noreply.github.com>
Date: Thu, 28 Dec 2023 17:11:46 +0100
Subject: [PATCH 3/6] Update clang/docs/analyzer/checkers.rst

Co-authored-by: Balazs Benics 
---
 clang/docs/analyzer/checkers.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index 7903ad75bcb831..eb01fcf8020802 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2107,7 +2107,7 @@ a warning is emitted. Currently, this checker does not 
take exception handling i
 
  void test() {
std::variant  v = 25;
-   char c = stg::get(v); // warn
+   char c = stg::get(v); // warn: "int" is the active alternative
  }
 
 .. _alpha-core-TestAfterDivZero:

>From 7615eaab9fda0799543a7b708a68694ea5d774a2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A1bor=20Spaits?=
 <48805437+spa...@users.noreply.github.com>
Date: Thu, 28 Dec 2023 18:22:51 +0100
Subject: [PATCH 4/6] Update checkers.rst

Co-authored-by: whisperity 
---
 clang/docs/analyzer/checkers.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/analyzer/checkers.rst b/clang/docs/analyzer/checkers.rst
index eb01fcf8020802..cce1af65cc608b 100644
--- a/clang/docs/analyzer/checkers.rst
+++ b/clang/docs/analyzer/checkers.rst
@@ -2106,7 +2106,7 @@ a warning is emitted. Currently, this checker does not 
take exception handling i
 .. code-block:: cpp
 
  void test() {
-   std::variant  v = 25;
+   std::variant v = 25;
char c = stg::get(v); // warn: "int" is the active alternative
  }
 

>From be919aa74856eee9b1316bc79e13fbbfc081c671 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A1bor=20Spaits?=
 <48805437+spa...@users.noreply.github.com>
Date: Thu, 28 Dec 2023 18:23:12 +0100
Subject: 

[clang-tools-extra] [compiler-rt] [mlir] [libcxx] [lldb] [flang] [llvm] [clang] [lld] [libc] [mlir][linalg] Implement common interface for depthwise convolution ops (PR #75017)

2023-12-28 Thread via cfe-commits

srcarroll wrote:

I'm starting to think that maybe grouped convs should have received this 
treatment first since depthwise is a subset of grouped, so a lot of this should 
be abstracted to a grouped conv interface. Looking forward to hearing thoughts

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


[clang] 6cd41dd - [RISCV] Remove isRVVType from Type.h. NFC

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

Author: Craig Topper
Date: 2023-12-28T11:54:50-08:00
New Revision: 6cd41dde88c6b70b1326ac77255f0f0af96c97d8

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

LOG: [RISCV] Remove isRVVType from Type.h. NFC

These are no longer used.

Added: 


Modified: 
clang/include/clang/AST/Type.h

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index b3ae66e6e769d0..1afa693672860f 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2383,10 +2383,6 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   /// Check if the type is the CUDA device builtin texture type.
   bool isCUDADeviceBuiltinTextureType() const;
 
-  bool isRVVType(unsigned ElementCount) const;
-
-  bool isRVVType(unsigned Bitwidth, bool IsFloat, bool IsBFloat = false) const;
-
   /// Return the implicit lifetime for this type, which must not be dependent.
   Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const;
 
@@ -7283,28 +7279,6 @@ inline bool Type::isOpenCLSpecificType() const {
  isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType();
 }
 
-inline bool Type::isRVVType(unsigned ElementCount) const {
-  bool Ret = false;
-#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP, IsBF)
\
-  if (NumEls == ElementCount)  
\
-Ret |= isSpecificBuiltinType(BuiltinType::Id);
-#include "clang/Basic/RISCVVTypes.def"
-  return Ret;
-}
-
-inline bool Type::isRVVType(unsigned Bitwidth, bool IsFloat,
-bool IsBFloat) const {
-  bool Ret = false;
-#define RVV_TYPE(Name, Id, SingletonId)
-#define RVV_VECTOR_TYPE(Name, Id, SingletonId, NumEls, ElBits, NF, IsSigned,   
\
-IsFP, IsBF)
\
-  if (ElBits == Bitwidth && IsFloat == IsFP && IsBFloat == IsBF)   
\
-Ret |= isSpecificBuiltinType(BuiltinType::Id);
-#include "clang/Basic/RISCVVTypes.def"
-  return Ret;
-}
-
 inline bool Type::isTemplateTypeParmType() const {
   return isa(CanonicalType);
 }



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


[clang] 8076ee9 - [RISCV] Use getBuiltinVectorTypeInfo instead of isRVVType.

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

Author: Craig Topper
Date: 2023-12-28T11:15:14-08:00
New Revision: 8076ee9667198c28cfd1ef6dc8f01c3e539549a2

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

LOG: [RISCV] Use getBuiltinVectorTypeInfo instead of isRVVType.

I'm trying to remove all uses of isRVVType.

Fix diagnostic message to report an error for the builtin instead
of the type. Though I can't seem to get a test to hit it.

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2e61dafacab02d..da0570b7b0f1e6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5388,15 +5388,17 @@ bool Sema::CheckRISCVBuiltinFunctionCall(const 
TargetInfo ,
 QualType Op1Type = TheCall->getArg(0)->getType();
 QualType Op2Type = TheCall->getArg(1)->getType();
 QualType Op3Type = TheCall->getArg(2)->getType();
-uint64_t ElemSize = Op1Type->isRVVType(32, false) ? 32 : 64;
+ASTContext::BuiltinVectorTypeInfo Info =
+Context.getBuiltinVectorTypeInfo(Op1Type->castAs());
+uint64_t ElemSize = Context.getTypeSize(Info.ElementType);
 if (ElemSize == 64 && !TI.hasFeature("zvknhb"))
   return Diag(TheCall->getBeginLoc(),
-  diag::err_riscv_type_requires_extension)
- << Op1Type << "zvknhb";
+  diag::err_riscv_builtin_requires_extension)
+ << /* IsExtension */ true << TheCall->getSourceRange() << "zvknb";
 
-return CheckInvalidVLENandLMUL(TI, TheCall, *this, Op1Type, ElemSize << 2) 
||
-   CheckInvalidVLENandLMUL(TI, TheCall, *this, Op2Type, ElemSize << 2) 
||
-   CheckInvalidVLENandLMUL(TI, TheCall, *this, Op3Type, ElemSize << 2);
+return CheckInvalidVLENandLMUL(TI, TheCall, *this, Op1Type, ElemSize * 4) 
||
+   CheckInvalidVLENandLMUL(TI, TheCall, *this, Op2Type, ElemSize * 4) 
||
+   CheckInvalidVLENandLMUL(TI, TheCall, *this, Op3Type, ElemSize * 4);
   }
 
   case RISCVVector::BI__builtin_rvv_sf_vc_i_se_u8mf8:



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


[clang] [llvm] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

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


@@ -1024,6 +1024,7 @@ static const char *ImpliedExtsZfinx[] = {"zicsr"};
 static const char *ImpliedExtsZhinx[] = {"zhinxmin"};
 static const char *ImpliedExtsZhinxmin[] = {"zfinx"};
 static const char *ImpliedExtsZicntr[] = {"zicsr"};
+static const char *ImpliedExtsZicfiss[] = {"zicsr", "zimop", "zcmop"};

topperc wrote:

Here's my issue 
https://github.com/riscv/riscv-cfi/issues/201#issuecomment-1871383717. From the 
response I got, I think we should drop Zcmop here and make the CompressPat 
depend on Zcmop.

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


[clang] [Analyzer][NFC] Remove redundant function call (PR #75076)

2023-12-28 Thread Gábor Spaits via cfe-commits

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


[clang] [Clang] Fix ICE where C++ Template Instantiation failed to handle attributed lambdas (PR #76523)

2023-12-28 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Yuxuan Chen (yuxuanchen1997)


Changes

This PR is proposing a fix for 
https://github.com/llvm/llvm-project/issues/76521.

Clang used to assume that during template instantiation, Lambda expressions can 
only have `FunctionProtoTypeLoc`s. However, this is not true for certain 
attributes like `__attribute__((pcs("aapcs-vfp")))`, whose interpretation 
happens after template instantiation. This PR changes the transformation logic 
for lambdas. 

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/Sema/TreeTransform.h (+54-17) 
- (added) clang/test/SemaCXX/template-instantiation.cpp (+15) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e21ec78a1e8a77..888a11bef15e7e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -856,6 +856,9 @@ Bug Fixes to AST Handling
 - Fixed a bug where RecursiveASTVisitor fails to visit the
   initializer of a bitfield.
   `Issue 64916 `_
+- Fixed a bug where Template Instantiation failed to handle Lambda Expressions
+  with certain types of Attributes.
+  (`#76521 `_)
 
 Miscellaneous Bug Fixes
 ^^^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7df5bf0cb71370..5e9b5184570704 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -674,6 +674,10 @@ class TreeTransform {
   Qualifiers ThisTypeQuals,
   Fn TransformExceptionSpec);
 
+  template 
+  QualType TransformAttributedType(TypeLocBuilder , AttributedTypeLoc TL,
+   Fn TransformModifiedType);
+
   bool TransformExceptionSpec(SourceLocation Loc,
   FunctionProtoType::ExceptionSpecInfo ,
   SmallVectorImpl ,
@@ -7050,12 +7054,12 @@ 
TreeTransform::TransformElaboratedType(TypeLocBuilder ,
   return Result;
 }
 
-template
+template 
+template 
 QualType TreeTransform::TransformAttributedType(
-TypeLocBuilder ,
-AttributedTypeLoc TL) {
+TypeLocBuilder , AttributedTypeLoc TL, Fn TransformModifiedTypeFn) {
   const AttributedType *oldType = TL.getTypePtr();
-  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
+  QualType modifiedType = TransformModifiedTypeFn(TLB, TL.getModifiedLoc());
   if (modifiedType.isNull())
 return QualType();
 
@@ -7099,6 +7103,15 @@ QualType TreeTransform::TransformAttributedType(
   return result;
 }
 
+template 
+QualType TreeTransform::TransformAttributedType(TypeLocBuilder ,
+ AttributedTypeLoc TL) 
{
+  return getDerived().TransformAttributedType(
+  TLB, TL, [&](TypeLocBuilder , TypeLoc ModifiedLoc) -> QualType {
+return getDerived().TransformType(TLB, ModifiedLoc);
+  });
+}
+
 template 
 QualType TreeTransform::TransformBTFTagAttributedType(
 TypeLocBuilder , BTFTagAttributedTypeLoc TL) {
@@ -13600,32 +13613,56 @@ 
TreeTransform::TransformLambdaExpr(LambdaExpr *E) {
   // transformed parameters.
   TypeSourceInfo *NewCallOpTSI = nullptr;
   {
-TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
-auto OldCallOpFPTL =
-OldCallOpTSI->getTypeLoc().getAs();
+auto OldCallOpTypeLoc =
+E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
+
+auto TransformFunctionProtoTypeLoc =
+[this](TypeLocBuilder , FunctionProtoTypeLoc FPTL) -> QualType {
+  SmallVector ExceptionStorage;
+  TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
+  return this->TransformFunctionProtoType(
+  TLB, FPTL, nullptr, Qualifiers(),
+  [&](FunctionProtoType::ExceptionSpecInfo , bool ) {
+return This->TransformExceptionSpec(FPTL.getBeginLoc(), ESI,
+ExceptionStorage, Changed);
+  });
+};
 
+QualType NewCallOpType;
 TypeLocBuilder NewCallOpTLBuilder;
-SmallVector ExceptionStorage;
-TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
-QualType NewCallOpType = TransformFunctionProtoType(
-NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
-[&](FunctionProtoType::ExceptionSpecInfo , bool ) {
-  return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
-  ExceptionStorage, Changed);
-});
+
+if (auto ATL = OldCallOpTypeLoc.getAs()) {
+  NewCallOpType = this->TransformAttributedType(
+  NewCallOpTLBuilder, ATL,
+  [&](TypeLocBuilder , 

[clang] [Clang] Fix ICE where C++ Template Instantiation failed to handle attributed lambdas (PR #76523)

2023-12-28 Thread Yuxuan Chen via cfe-commits

https://github.com/yuxuanchen1997 created 
https://github.com/llvm/llvm-project/pull/76523

This PR is proposing a fix for 
https://github.com/llvm/llvm-project/issues/76521.

Clang used to assume that during template instantiation, Lambda expressions can 
only have `FunctionProtoTypeLoc`s. However, this is not true for certain 
attributes like `__attribute__((pcs("aapcs-vfp")))`, whose interpretation 
happens after template instantiation. This PR changes the transformation logic 
for lambdas. 

>From 09b339575b506317a5fbf5c4d52d3e5d0243a3c3 Mon Sep 17 00:00:00 2001
From: Yuxuan Chen 
Date: Thu, 21 Dec 2023 14:48:52 -0800
Subject: [PATCH] attempt to fix the crash

---
 clang/docs/ReleaseNotes.rst   |  3 +
 clang/lib/Sema/TreeTransform.h| 71 ++-
 clang/test/SemaCXX/template-instantiation.cpp | 15 
 3 files changed, 72 insertions(+), 17 deletions(-)
 create mode 100644 clang/test/SemaCXX/template-instantiation.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e21ec78a1e8a77..888a11bef15e7e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -856,6 +856,9 @@ Bug Fixes to AST Handling
 - Fixed a bug where RecursiveASTVisitor fails to visit the
   initializer of a bitfield.
   `Issue 64916 `_
+- Fixed a bug where Template Instantiation failed to handle Lambda Expressions
+  with certain types of Attributes.
+  (`#76521 `_)
 
 Miscellaneous Bug Fixes
 ^^^
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7df5bf0cb71370..5e9b5184570704 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -674,6 +674,10 @@ class TreeTransform {
   Qualifiers ThisTypeQuals,
   Fn TransformExceptionSpec);
 
+  template 
+  QualType TransformAttributedType(TypeLocBuilder , AttributedTypeLoc TL,
+   Fn TransformModifiedType);
+
   bool TransformExceptionSpec(SourceLocation Loc,
   FunctionProtoType::ExceptionSpecInfo ,
   SmallVectorImpl ,
@@ -7050,12 +7054,12 @@ 
TreeTransform::TransformElaboratedType(TypeLocBuilder ,
   return Result;
 }
 
-template
+template 
+template 
 QualType TreeTransform::TransformAttributedType(
-TypeLocBuilder ,
-AttributedTypeLoc TL) {
+TypeLocBuilder , AttributedTypeLoc TL, Fn TransformModifiedTypeFn) {
   const AttributedType *oldType = TL.getTypePtr();
-  QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
+  QualType modifiedType = TransformModifiedTypeFn(TLB, TL.getModifiedLoc());
   if (modifiedType.isNull())
 return QualType();
 
@@ -7099,6 +7103,15 @@ QualType TreeTransform::TransformAttributedType(
   return result;
 }
 
+template 
+QualType TreeTransform::TransformAttributedType(TypeLocBuilder ,
+ AttributedTypeLoc TL) 
{
+  return getDerived().TransformAttributedType(
+  TLB, TL, [&](TypeLocBuilder , TypeLoc ModifiedLoc) -> QualType {
+return getDerived().TransformType(TLB, ModifiedLoc);
+  });
+}
+
 template 
 QualType TreeTransform::TransformBTFTagAttributedType(
 TypeLocBuilder , BTFTagAttributedTypeLoc TL) {
@@ -13600,32 +13613,56 @@ 
TreeTransform::TransformLambdaExpr(LambdaExpr *E) {
   // transformed parameters.
   TypeSourceInfo *NewCallOpTSI = nullptr;
   {
-TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
-auto OldCallOpFPTL =
-OldCallOpTSI->getTypeLoc().getAs();
+auto OldCallOpTypeLoc =
+E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
+
+auto TransformFunctionProtoTypeLoc =
+[this](TypeLocBuilder , FunctionProtoTypeLoc FPTL) -> QualType {
+  SmallVector ExceptionStorage;
+  TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
+  return this->TransformFunctionProtoType(
+  TLB, FPTL, nullptr, Qualifiers(),
+  [&](FunctionProtoType::ExceptionSpecInfo , bool ) {
+return This->TransformExceptionSpec(FPTL.getBeginLoc(), ESI,
+ExceptionStorage, Changed);
+  });
+};
 
+QualType NewCallOpType;
 TypeLocBuilder NewCallOpTLBuilder;
-SmallVector ExceptionStorage;
-TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
-QualType NewCallOpType = TransformFunctionProtoType(
-NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
-[&](FunctionProtoType::ExceptionSpecInfo , bool ) {
-  return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
-  

[clang] [analyzer] Add documentation for std::variant checker (PR #76501)

2023-12-28 Thread Balazs Benics via cfe-commits
=?utf-8?q?G=C3=A1bor?= Spaits,=?utf-8?q?G=C3=A1bor?= Spaits,
=?utf-8?q?G=C3=A1bor?= Spaits
Message-ID:
In-Reply-To: 


steakhal wrote:

let me check it again

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


[clang] 5c37e71 - [Frontend] Use StringRef::drop_while (NFC)

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

Author: Kazu Hirata
Date: 2023-12-28T10:06:20-08:00
New Revision: 5c37e711df6b81c2b669fb8a0d8b15f7a79e6e4a

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

LOG: [Frontend] Use StringRef::drop_while (NFC)

Added: 


Modified: 
clang/lib/Frontend/LayoutOverrideSource.cpp

Removed: 




diff  --git a/clang/lib/Frontend/LayoutOverrideSource.cpp 
b/clang/lib/Frontend/LayoutOverrideSource.cpp
index f474d4fe8fdcb8..a1866ec09c9d3d 100644
--- a/clang/lib/Frontend/LayoutOverrideSource.cpp
+++ b/clang/lib/Frontend/LayoutOverrideSource.cpp
@@ -147,8 +147,7 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef 
Filename) {
 
 // Skip over this offset, the following comma, and any spaces.
 LineStr = LineStr.substr(1);
-while (!LineStr.empty() && isWhitespace(LineStr[0]))
-  LineStr = LineStr.substr(1);
+LineStr = LineStr.drop_while(isWhitespace);
   }
 }
 
@@ -163,8 +162,7 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef 
Filename) {
 
 // Skip over this offset, the following comma, and any spaces.
 LineStr = LineStr.substr(1);
-while (!LineStr.empty() && isWhitespace(LineStr[0]))
-  LineStr = LineStr.substr(1);
+LineStr = LineStr.drop_while(isWhitespace);
   }
   continue;
 }
@@ -180,8 +178,7 @@ LayoutOverrideSource::LayoutOverrideSource(StringRef 
Filename) {
 
 // Skip over this offset, the following comma, and any spaces.
 LineStr = LineStr.substr(1);
-while (!LineStr.empty() && isWhitespace(LineStr[0]))
-  LineStr = LineStr.substr(1);
+LineStr = LineStr.drop_while(isWhitespace);
   }
 }
   }



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


[clang] [riscv] Fix for __riscv_v_fixed_vlen in vector mask types (PR #76510)

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

topperc wrote:

Missing CodeGen tests

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


  1   2   3   >