[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-08 Thread via cfe-commits

https://github.com/antangelo updated 
https://github.com/llvm/llvm-project/pull/91046

>From 767173a0dfde9858c90867cc5d476da90e5ba898 Mon Sep 17 00:00:00 2001
From: Antonio Abbatangelo 
Date: Tue, 30 Apr 2024 22:58:18 -0400
Subject: [PATCH 1/6] [AArch64] Support preserve_none calling convention

---
 clang/include/clang/Basic/Attr.td |   3 +-
 clang/include/clang/Basic/AttrDocs.td |  19 +-
 clang/lib/Basic/Targets/AArch64.cpp   |   1 +
 clang/test/CodeGen/preserve-call-conv.c   |   6 +-
 llvm/docs/LangRef.rst |   2 +-
 .../Target/AArch64/AArch64CallingConvention.h |   3 +
 .../AArch64/AArch64CallingConvention.td   |  27 ++
 .../Target/AArch64/AArch64ISelLowering.cpp|  34 +-
 .../Target/AArch64/AArch64RegisterInfo.cpp|  12 +-
 .../AArch64/GISel/AArch64CallLowering.cpp |   1 +
 .../AArch64/dynamic-regmask-preserve-none.ll  |  88 +
 llvm/test/CodeGen/AArch64/preserve.ll |   9 +-
 llvm/test/CodeGen/AArch64/preserve_nonecc.ll  |  92 +
 .../CodeGen/AArch64/preserve_nonecc_call.ll   | 325 ++
 .../AArch64/preserve_nonecc_musttail.ll   |  11 +
 .../CodeGen/AArch64/preserve_nonecc_swift.ll  |  16 +
 16 files changed, 631 insertions(+), 18 deletions(-)
 create mode 100644 llvm/test/CodeGen/AArch64/dynamic-regmask-preserve-none.ll
 create mode 100644 llvm/test/CodeGen/AArch64/preserve_nonecc.ll
 create mode 100644 llvm/test/CodeGen/AArch64/preserve_nonecc_call.ll
 create mode 100644 llvm/test/CodeGen/AArch64/preserve_nonecc_musttail.ll
 create mode 100644 llvm/test/CodeGen/AArch64/preserve_nonecc_swift.ll

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 0225598cbbe8a..712c79927304e 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3038,7 +3038,8 @@ def M68kRTD: DeclOrTypeAttr {
   let Documentation = [M68kRTDDocs];
 }
 
-def PreserveNone : DeclOrTypeAttr, TargetSpecificAttr {
+def PreserveNone : DeclOrTypeAttr,
+   
TargetSpecificAttr> {
   let Spellings = [Clang<"preserve_none">];
   let Subjects = SubjectList<[FunctionLike]>;
   let Documentation = [PreserveNoneDocs];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f8253143b596c..d23465b77e7ed 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5658,17 +5658,20 @@ experimental at this time.
 def PreserveNoneDocs : Documentation {
   let Category = DocCatCallingConvs;
   let Content = [{
-On X86-64 target, this attribute changes the calling convention of a function.
+On X86-64 and AArch64 targets, this attribute changes the calling convention 
of a function.
 The ``preserve_none`` calling convention tries to preserve as few general
 registers as possible. So all general registers are caller saved registers. It
 also uses more general registers to pass arguments. This attribute doesn't
-impact floating-point registers (XMMs/YMMs). Floating-point registers still
-follow the c calling convention.
-
-- Only RSP and RBP are preserved by callee.
-
-- Register RDI, RSI, RDX, RCX, R8, R9, R11, R12, R13, R14, R15 and RAX now can
-  be used to pass function arguments.
+impact floating-point registers. 
+
+- On X86-64, only RSP and RBP are preserved by the callee.
+  Registers RDI, RSI, RDX, RCX, R8, R9, R11, R12, R13, R14, R15 and RAX now can
+  be used to pass function arguments. Floating-point registers (XMMs/YMMs) 
still
+  follow the C calling convention.
+- On AArch64, only LR and FP are preserved by the callee.
+  Registers X19-X28 and X0-X17 are used to pass function arguments.
+  X18, SIMD and floating-point registers follow the AAPCS calling
+  convention.
   }];
 }
 
diff --git a/clang/lib/Basic/Targets/AArch64.cpp 
b/clang/lib/Basic/Targets/AArch64.cpp
index c8d243a8fb7ae..e1f7dbf1d9f20 100644
--- a/clang/lib/Basic/Targets/AArch64.cpp
+++ b/clang/lib/Basic/Targets/AArch64.cpp
@@ -1202,6 +1202,7 @@ AArch64TargetInfo::checkCallingConvention(CallingConv CC) 
const {
   case CC_SwiftAsync:
   case CC_PreserveMost:
   case CC_PreserveAll:
+  case CC_PreserveNone:
   case CC_OpenCLKernel:
   case CC_AArch64VectorCall:
   case CC_AArch64SVEPCS:
diff --git a/clang/test/CodeGen/preserve-call-conv.c 
b/clang/test/CodeGen/preserve-call-conv.c
index 74bf695e6f331..65973206403f7 100644
--- a/clang/test/CodeGen/preserve-call-conv.c
+++ b/clang/test/CodeGen/preserve-call-conv.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm < %s | FileCheck 
%s --check-prefixes=CHECK,X86-LINUX
-// RUN: %clang_cc1 -triple arm64-unknown-unknown -emit-llvm < %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm < %s | FileCheck 
%s --check-prefixes=CHECK,LINUX
+// RUN: %clang_cc1 -triple arm64-unknown-unknown -emit-llvm < %s | FileCheck 
%s --check-prefixes=CHECK,LINUX
 
 // RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -emit-llvm %s -o - 

[clang] [llvm] [AMDGPU][WIP] Extend readlane, writelane and readfirstlane intrinsic lowering for generic types (PR #89217)

2024-05-08 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 3d56ea05b6c746a7144f643bef2ebd599f605b8b 
d0610c47c0e2cb4bca5f90c289ffaa5c4178547f -- clang/lib/CodeGen/CGBuiltin.cpp 
llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp 
llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp 
llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h 
llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp 
llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.h 
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
index 16d3219a16..b0a2bbeb61 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
@@ -5415,18 +5415,21 @@ bool 
AMDGPULegalizerInfo::legalizeLaneOp(LegalizerHelper &Helper,
 Register Src0Valid = B.buildBitcast(S32, Src0).getReg(0);
 MachineInstrBuilder LaneOpDst;
 switch (IID) {
-  case Intrinsic::amdgcn_readfirstlane: {
-LaneOpDst = B.buildIntrinsic(IID, {S32}).addUse(Src0Valid);
-break;
-  }
-  case Intrinsic::amdgcn_readlane: {
-LaneOpDst = B.buildIntrinsic(IID, 
{S32}).addUse(Src0Valid).addUse(Src1);
-break;
-  }
-  case Intrinsic::amdgcn_writelane: {
-Register Src2Valid = B.buildBitcast(S32, Src2).getReg(0);
-LaneOpDst = B.buildIntrinsic(IID, 
{S32}).addUse(Src0Valid).addUse(Src1).addUse(Src2Valid);
-  }
+case Intrinsic::amdgcn_readfirstlane: {
+  LaneOpDst = B.buildIntrinsic(IID, {S32}).addUse(Src0Valid);
+  break;
+}
+case Intrinsic::amdgcn_readlane: {
+  LaneOpDst = B.buildIntrinsic(IID, {S32}).addUse(Src0Valid).addUse(Src1);
+  break;
+}
+case Intrinsic::amdgcn_writelane: {
+  Register Src2Valid = B.buildBitcast(S32, Src2).getReg(0);
+  LaneOpDst = B.buildIntrinsic(IID, {S32})
+  .addUse(Src0Valid)
+  .addUse(Src1)
+  .addUse(Src2Valid);
+}
 }
 
 Register LaneOpDstReg = LaneOpDst.getReg(0);
@@ -5443,21 +5446,25 @@ bool 
AMDGPULegalizerInfo::legalizeLaneOp(LegalizerHelper &Helper,
 
 MachineInstrBuilder LaneOpDst;
 switch (IID) {
-  case Intrinsic::amdgcn_readfirstlane: {
-LaneOpDst = B.buildIntrinsic(IID, {S32}).addUse(Src0Valid);
-break;
-  }
-  case Intrinsic::amdgcn_readlane: {
-LaneOpDst = B.buildIntrinsic(IID, 
{S32}).addUse(Src0Valid).addUse(Src1);
-break;
-  }
-  case Intrinsic::amdgcn_writelane: {
-Register Src2Cast = MRI.getType(Src2).isScalar()
-? Src2
-: B.buildBitcast(LLT::scalar(Size), 
Src2).getReg(0);
-Register Src2Valid = B.buildAnyExt(LLT::scalar(32), 
Src2Cast).getReg(0);
-LaneOpDst = B.buildIntrinsic(IID, 
{S32}).addUse(Src0Valid).addUse(Src1).addUse(Src2Valid);
-  }
+case Intrinsic::amdgcn_readfirstlane: {
+  LaneOpDst = B.buildIntrinsic(IID, {S32}).addUse(Src0Valid);
+  break;
+}
+case Intrinsic::amdgcn_readlane: {
+  LaneOpDst = B.buildIntrinsic(IID, {S32}).addUse(Src0Valid).addUse(Src1);
+  break;
+}
+case Intrinsic::amdgcn_writelane: {
+  Register Src2Cast =
+  MRI.getType(Src2).isScalar()
+  ? Src2
+  : B.buildBitcast(LLT::scalar(Size), Src2).getReg(0);
+  Register Src2Valid = B.buildAnyExt(LLT::scalar(32), Src2Cast).getReg(0);
+  LaneOpDst = B.buildIntrinsic(IID, {S32})
+  .addUse(Src0Valid)
+  .addUse(Src1)
+  .addUse(Src2Valid);
+}
 }
 
 Register LaneOpDstReg = LaneOpDst.getReg(0);

``




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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Mike Hommey via cfe-commits

glandium wrote:

Reverting just the SemaTemplate.cpp change fixes it.

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Mike Hommey via cfe-commits

glandium wrote:

This caused some breakage in something completely unrelated to operator= O_o

This is from webrtc code in Firefox:
```
/tmp/gecko/third_party/libwebrtc/rtc_base/containers/flat_map.h:331:49: error: 
out-of-line definition of 'try_emplace' does not match any declaration in 
'flat_map'
  331 | auto flat_map::try_emplace(K&& key,
  | ^~~
/tmp/gecko/third_party/libwebrtc/rtc_base/containers/flat_map.h:343:49: error: 
out-of-line definition of 'try_emplace' does not match any declaration in 
'flat_map'
  343 | auto flat_map::try_emplace(const_iterator hint,
  | ^~~
2 errors generated.
```
The lines with error are: 
https://searchfox.org/mozilla-central/rev/c34cf367c29601ed56ae4ea51e20b28cd8331f9c/third_party/libwebrtc/rtc_base/containers/flat_map.h#331,343

The corresponding declarations are:
https://searchfox.org/mozilla-central/rev/c34cf367c29601ed56ae4ea51e20b28cd8331f9c/third_party/libwebrtc/rtc_base/containers/flat_map.h#243,248

I don't see how they differ.

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


[clang] [llvm] [RISCV] Allow extra underscores in parseNormalizedArchString and parseArchString. (PR #91532)

2024-05-08 Thread Craig Topper via cfe-commits

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

>From 0f5fcf5035d66fd4c1d1e97525e9266d8460b297 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Wed, 8 May 2024 13:40:31 -0700
Subject: [PATCH] [RISCV] Allow extra underscores in parseNormalizedArchString
 and parseArchString.

Allow double underscores and trailing underscores. gcc and binutils
allow extra underscores without error.
---
 clang/test/Driver/riscv-arch.c   |  5 -
 llvm/lib/TargetParser/RISCVISAInfo.cpp   | 16 +++-
 llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 15 +--
 3 files changed, 4 insertions(+), 32 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index ddf617bbb6237..418d8e91595de 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -308,11 +308,6 @@
 // RV32-SMINOR0: error: invalid arch name 'rv32ist2p0',
 // RV32-SMINOR0: unsupported standard supervisor-level extension 'st'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_ -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
-// RV32-XSEP: error: invalid arch name 'rv32ixabc_',
-// RV32-XSEP: extension name missing after separator '_'
-
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
 // RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp 
b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index c553e330a878b..14b757d04ce37 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -452,7 +452,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   // and separated by _. Split by _ and then extract the name and version
   // information for each extension.
   SmallVector Split;
-  Arch.split(Split, '_');
+  Arch.split(Split, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
   for (StringRef Ext : Split) {
 StringRef Prefix, MinorVersionStr;
 std::tie(Prefix, MinorVersionStr) = Ext.rsplit('p');
@@ -651,10 +651,6 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
 break;
   }
 
-  if (Arch.back() == '_')
-return createStringError(errc::invalid_argument,
- "extension name missing after separator '_'");
-
   // Skip baseline.
   StringRef Exts = Arch.drop_front(1);
 
@@ -697,16 +693,10 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
   Exts.consume_front("_");
 
   SmallVector SplitExts;
-  // Only split if the string is not empty. Otherwise the split will push an
-  // empty string into the vector.
-  if (!Exts.empty())
-Exts.split(SplitExts, '_');
+  Exts.split(SplitExts, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
   for (auto Ext : SplitExts) {
-if (Ext.empty())
-  return createStringError(errc::invalid_argument,
-   "extension name missing after separator '_'");
-
+assert(!Ext.empty());
 do {
   if (RISCVISAUtils::AllStdExts.contains(Ext.front())) {
 if (auto E = processSingleLetterExtension(
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp 
b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index f9e386a85fea8..dc2a8b44cf15d 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -38,8 +38,7 @@ TEST(ParseNormalizedArchString, RejectsInvalidBaseISA) {
 }
 
 TEST(ParseNormalizedArchString, RejectsMalformedInputs) {
-  for (StringRef Input :
-   {"rv64i2p0_", "rv32i2p0__a2p0", "rv64e2p", "rv32i", "rv64ip1"}) {
+  for (StringRef Input : {"rv64e2p", "rv32i", "rv64ip1"}) {
 EXPECT_EQ(
 toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
 "extension lacks version in expected format");
@@ -518,18 +517,6 @@ TEST(ParseArchString,
   "unsupported standard user-level extension 'zba1p0m'");
 }
 
-TEST(ParseArchString, RejectsDoubleOrTrailingUnderscore) {
-  EXPECT_EQ(
-  toString(RISCVISAInfo::parseArchString("rv64i__m", true).takeError()),
-  "extension name missing after separator '_'");
-
-  for (StringRef Input :
-   {"rv32ezicsr__zifencei", "rv32i_", "rv32izicsr_", "rv64im_"}) {
-EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-  "extension name missing after separator '_'");
-  }
-}
-
 TEST(ParseArchString, RejectsDuplicateExtensionNames) {
   EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ii", 
true).takeError()),
 "invalid standard user-level extension 'i'");

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


[clang] [llvm] [RISCV] Bump Zaamo and Zalrsc to version 1.0 (PR #91556)

2024-05-08 Thread Brandon Wu via cfe-commits

4vtomat wrote:

> > > Need to update RISCVUsage.rst and ReleaseNotes.rst
> > 
> > 
> > Is it going to be cherry-picked to release branch?
> 
> No. We just try to update the ReleaseNotes proactively for LLVM 19.

Got it!

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


[clang] [llvm] [RISCV] Bump Zaamo and Zalrsc to version 1.0 (PR #91556)

2024-05-08 Thread Craig Topper via cfe-commits

topperc wrote:

> > Need to update RISCVUsage.rst and ReleaseNotes.rst
> 
> Is it going to be cherry-picked to release branch?

No. We just try to update the ReleaseNotes proactively for LLVM 19.

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


[clang] [AArch64][PAC][clang][ELF] Support PAuth ABI core info (PR #85235)

2024-05-08 Thread Fangrui Song via cfe-commits


@@ -1190,6 +1191,36 @@ void CodeGenModule::Release() {
 if (!LangOpts.isSignReturnAddressWithAKey())
   getModule().addModuleFlag(llvm::Module::Min,
 "sign-return-address-with-bkey", 1);
+
+if (getTriple().isOSLinux() && getTriple().isOSBinFormatELF()) {

MaskRay wrote:

Linux implies ELF. You can remove `getTriple().isOSBinFormatELF()`

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


[clang] [AArch64][PAC][clang][ELF] Support PAuth ABI core info (PR #85235)

2024-05-08 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple aarch64-linux -S -emit-llvm -o - \

MaskRay wrote:

`-S` should be removed. I've cleaned up the whole clang/test suite.

After https://github.com/llvm/llvm-project/pull/91140 this will lead to an 
error.

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


[clang] [AArch64][PAC][clang][ELF] Support PAuth ABI core info (PR #85235)

2024-05-08 Thread Fangrui Song via cfe-commits

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

This will need a rebase (or merge main) as `-S -emit-llvm` tests have errors.

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


[clang] [AArch64][PAC][clang][ELF] Support PAuth ABI core info (PR #85235)

2024-05-08 Thread Fangrui Song via cfe-commits

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


[clang] [driver] Only check for unused plugin options (PR #91522)

2024-05-08 Thread Fangrui Song via cfe-commits

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

Consider use a test tag, e.g. `[Driver,test]`

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


[clang] [llvm] [RISCV] Bump Zaamo and Zalrsc to version 1.0 (PR #91556)

2024-05-08 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/91556

>From 062d7d5017b01fb3afbaffe1a34487cfe36288d2 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Wed, 8 May 2024 21:43:07 -0700
Subject: [PATCH 1/2] [RISCV] Bump Zaamo and Zalrsc to version 1.0

The ratified information can be found here:
https://wiki.riscv.org/display/HOME/Ratified+Extensions
---
 .../test/Preprocessor/riscv-target-features.c | 20 +--
 llvm/lib/Target/RISCV/RISCVFeatures.td|  8 
 llvm/test/CodeGen/RISCV/attributes.ll | 16 +++
 llvm/test/MC/RISCV/rv32zaamo-invalid.s|  2 +-
 llvm/test/MC/RISCV/rv32zaamo-valid.s  | 12 +--
 llvm/test/MC/RISCV/rv32zalrsc-invalid.s   |  2 +-
 llvm/test/MC/RISCV/rv32zalrsc-valid.s | 12 +--
 llvm/test/MC/RISCV/rv64zaamo-invalid.s|  2 +-
 llvm/test/MC/RISCV/rv64zaamo-valid.s  |  8 
 llvm/test/MC/RISCV/rv64zalrsc-invalid.s   |  2 +-
 llvm/test/MC/RISCV/rv64zalrsc-valid.s |  8 
 .../TargetParser/RISCVISAInfoTest.cpp |  4 ++--
 12 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 913093bb51db6..ead9ac9b4063f 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -1554,13 +1554,13 @@
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
 
 // Experimental extensions
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zaamo0p2 -E -dM %s \
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zaamo1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_zaamo0p2 -E -dM %s \
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zaamo1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
-// CHECK-ZAAMO-EXT: __riscv_zaamo 2000{{$}}
+// CHECK-ZAAMO-EXT: __riscv_zaamo 100{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32ia_zabha1p0 -E -dM %s \
@@ -1578,13 +1578,13 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s
 // CHECK-ZALASR-EXT: __riscv_zalasr 1000{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zalrsc0p2 -E -dM %s \
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zalrsc1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_zalrsc0p2 -E -dM %s \
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zalrsc1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
-// CHECK-ZALRSC-EXT: __riscv_zalrsc 2000{{$}}
+// CHECK-ZALRSC-EXT: __riscv_zalrsc 100{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32izfbfmin1p0 -E -dM %s \
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 89e1214f469da..b099496d18388 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -211,8 +211,8 @@ def FeatureStdExtZa128rs : RISCVExtension<"za128rs", 1, 0,
   "'Za128rs' (Reservation Set Size of 
at Most 128 Bytes)">;
 
 def FeatureStdExtZaamo
-: RISCVExperimentalExtension<"zaamo", 0, 2,
- "'Zaamo' (Atomic Memory Operations)">;
+: RISCVExtension<"zaamo", 1, 0,
+ "'Zaamo' (Atomic Memory Operations)">;
 def HasStdExtAOrZaamo
 : Predicate<"Subtarget->hasStdExtA() || Subtarget->hasStdExtZaamo()">,
   AssemblerPredicate<(any_of FeatureStdExtA, FeatureStdExtZaamo),
@@ -242,8 +242,8 @@ def HasStdExtZalasr : 
Predicate<"Subtarget->hasStdExtZalasr()">,
   "'Zalasr' (Load-Acquire and Store-Release 
Instructions)">;
 
 def FeatureStdExtZalrsc
-: RISCVExperimentalExtension<"zalrsc", 0, 2,
- "'Zalrsc' (Load-Reserved/Store-Conditional)">;
+: RISCVExtension<"zalrsc", 1, 0,
+ "'Zalrsc' (Load-Reserved/Store-Conditional)">;
 def HasStdExtAOrZalrsc
 : Predicate<"Subtarget->hasStdExtA() || Subtarget->hasStdExtZalrsc()">,
   AssemblerPredicate<(any_of FeatureStdExtA, FeatureStdExtZalrsc),
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 8f49f6648ad28..9fdd842e5dd37 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -112,10 +112,10 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZFBFMIN %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvfbfmin %s -o - | FileCheck 
--check-pref

[clang] [llvm] [RISCV] Bump Zaamo and Zalrsc to version 1.0 (PR #91556)

2024-05-08 Thread Brandon Wu via cfe-commits

4vtomat wrote:

> Need to update RISCVUsage.rst and ReleaseNotes.rst

Is it going to be cherry-picked to release branch?

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


[clang] [llvm] [RISCV] Bump Zaamo and Zalrsc to version 1.0 (PR #91556)

2024-05-08 Thread Craig Topper via cfe-commits

topperc wrote:

Need to update RISCVUsage.rst and ReleaseNotes.rst

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


[clang] [llvm] [RISCV] Bump Zaamo and Zalrsc to version 1.0 (PR #91556)

2024-05-08 Thread via cfe-commits

llvmbot wrote:




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

Author: Brandon Wu (4vtomat)


Changes

The ratified information can be found here:
https://wiki.riscv.org/display/HOME/Ratified+Extensions


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


12 Files Affected:

- (modified) clang/test/Preprocessor/riscv-target-features.c (+10-10) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+4-4) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+8-8) 
- (modified) llvm/test/MC/RISCV/rv32zaamo-invalid.s (+1-1) 
- (modified) llvm/test/MC/RISCV/rv32zaamo-valid.s (+6-6) 
- (modified) llvm/test/MC/RISCV/rv32zalrsc-invalid.s (+1-1) 
- (modified) llvm/test/MC/RISCV/rv32zalrsc-valid.s (+6-6) 
- (modified) llvm/test/MC/RISCV/rv64zaamo-invalid.s (+1-1) 
- (modified) llvm/test/MC/RISCV/rv64zaamo-valid.s (+4-4) 
- (modified) llvm/test/MC/RISCV/rv64zalrsc-invalid.s (+1-1) 
- (modified) llvm/test/MC/RISCV/rv64zalrsc-valid.s (+4-4) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+2-2) 


``diff
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 913093bb51db6..ead9ac9b4063f 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -1554,13 +1554,13 @@
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
 
 // Experimental extensions
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zaamo0p2 -E -dM %s \
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zaamo1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_zaamo0p2 -E -dM %s \
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zaamo1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
-// CHECK-ZAAMO-EXT: __riscv_zaamo 2000{{$}}
+// CHECK-ZAAMO-EXT: __riscv_zaamo 100{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32ia_zabha1p0 -E -dM %s \
@@ -1578,13 +1578,13 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s
 // CHECK-ZALASR-EXT: __riscv_zalasr 1000{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zalrsc0p2 -E -dM %s \
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zalrsc1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_zalrsc0p2 -E -dM %s \
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zalrsc1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
-// CHECK-ZALRSC-EXT: __riscv_zalrsc 2000{{$}}
+// CHECK-ZALRSC-EXT: __riscv_zalrsc 100{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32izfbfmin1p0 -E -dM %s \
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 89e1214f469da..b099496d18388 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -211,8 +211,8 @@ def FeatureStdExtZa128rs : RISCVExtension<"za128rs", 1, 0,
   "'Za128rs' (Reservation Set Size of 
at Most 128 Bytes)">;
 
 def FeatureStdExtZaamo
-: RISCVExperimentalExtension<"zaamo", 0, 2,
- "'Zaamo' (Atomic Memory Operations)">;
+: RISCVExtension<"zaamo", 1, 0,
+ "'Zaamo' (Atomic Memory Operations)">;
 def HasStdExtAOrZaamo
 : Predicate<"Subtarget->hasStdExtA() || Subtarget->hasStdExtZaamo()">,
   AssemblerPredicate<(any_of FeatureStdExtA, FeatureStdExtZaamo),
@@ -242,8 +242,8 @@ def HasStdExtZalasr : 
Predicate<"Subtarget->hasStdExtZalasr()">,
   "'Zalasr' (Load-Acquire and Store-Release 
Instructions)">;
 
 def FeatureStdExtZalrsc
-: RISCVExperimentalExtension<"zalrsc", 0, 2,
- "'Zalrsc' (Load-Reserved/Store-Conditional)">;
+: RISCVExtension<"zalrsc", 1, 0,
+ "'Zalrsc' (Load-Reserved/Store-Conditional)">;
 def HasStdExtAOrZalrsc
 : Predicate<"Subtarget->hasStdExtA() || Subtarget->hasStdExtZalrsc()">,
   AssemblerPredicate<(any_of FeatureStdExtA, FeatureStdExtZalrsc),
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 8f49f6648ad28..9fdd842e5dd37 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -112,10 +112,10 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZFBFMIN %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvfbfmin %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZVFBFMIN %s
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zvfbfwma %s -o - | FileCheck 
--check-prefixes=

[clang] [llvm] [RISCV] Bump Zaamo and Zalrsc to version 1.0 (PR #91556)

2024-05-08 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat created 
https://github.com/llvm/llvm-project/pull/91556

The ratified information can be found here:
https://wiki.riscv.org/display/HOME/Ratified+Extensions


>From 062d7d5017b01fb3afbaffe1a34487cfe36288d2 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Wed, 8 May 2024 21:43:07 -0700
Subject: [PATCH] [RISCV] Bump Zaamo and Zalrsc to version 1.0

The ratified information can be found here:
https://wiki.riscv.org/display/HOME/Ratified+Extensions
---
 .../test/Preprocessor/riscv-target-features.c | 20 +--
 llvm/lib/Target/RISCV/RISCVFeatures.td|  8 
 llvm/test/CodeGen/RISCV/attributes.ll | 16 +++
 llvm/test/MC/RISCV/rv32zaamo-invalid.s|  2 +-
 llvm/test/MC/RISCV/rv32zaamo-valid.s  | 12 +--
 llvm/test/MC/RISCV/rv32zalrsc-invalid.s   |  2 +-
 llvm/test/MC/RISCV/rv32zalrsc-valid.s | 12 +--
 llvm/test/MC/RISCV/rv64zaamo-invalid.s|  2 +-
 llvm/test/MC/RISCV/rv64zaamo-valid.s  |  8 
 llvm/test/MC/RISCV/rv64zalrsc-invalid.s   |  2 +-
 llvm/test/MC/RISCV/rv64zalrsc-valid.s |  8 
 .../TargetParser/RISCVISAInfoTest.cpp |  4 ++--
 12 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 913093bb51db6..ead9ac9b4063f 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -1554,13 +1554,13 @@
 // CHECK-ZVKT-EXT: __riscv_zvkt 100{{$}}
 
 // Experimental extensions
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zaamo0p2 -E -dM %s \
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zaamo1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_zaamo0p2 -E -dM %s \
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zaamo1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZAAMO-EXT %s
-// CHECK-ZAAMO-EXT: __riscv_zaamo 2000{{$}}
+// CHECK-ZAAMO-EXT: __riscv_zaamo 100{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32ia_zabha1p0 -E -dM %s \
@@ -1578,13 +1578,13 @@
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALASR-EXT %s
 // CHECK-ZALASR-EXT: __riscv_zalasr 1000{{$}}
 
-// RUN: %clang --target=riscv32 -menable-experimental-extensions \
-// RUN:   -march=rv32i_zalrsc0p2 -E -dM %s \
+// RUN: %clang --target=riscv32 \
+// RUN:   -march=rv32i_zalrsc1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
-// RUN: %clang --target=riscv64 -menable-experimental-extensions \
-// RUN:   -march=rv64i_zalrsc0p2 -E -dM %s \
+// RUN: %clang --target=riscv64 \
+// RUN:   -march=rv64i_zalrsc1p0 -E -dM %s \
 // RUN:   -o - | FileCheck --check-prefix=CHECK-ZALRSC-EXT %s
-// CHECK-ZALRSC-EXT: __riscv_zalrsc 2000{{$}}
+// CHECK-ZALRSC-EXT: __riscv_zalrsc 100{{$}}
 
 // RUN: %clang --target=riscv32 -menable-experimental-extensions \
 // RUN:   -march=rv32izfbfmin1p0 -E -dM %s \
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index 89e1214f469da..b099496d18388 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -211,8 +211,8 @@ def FeatureStdExtZa128rs : RISCVExtension<"za128rs", 1, 0,
   "'Za128rs' (Reservation Set Size of 
at Most 128 Bytes)">;
 
 def FeatureStdExtZaamo
-: RISCVExperimentalExtension<"zaamo", 0, 2,
- "'Zaamo' (Atomic Memory Operations)">;
+: RISCVExtension<"zaamo", 1, 0,
+ "'Zaamo' (Atomic Memory Operations)">;
 def HasStdExtAOrZaamo
 : Predicate<"Subtarget->hasStdExtA() || Subtarget->hasStdExtZaamo()">,
   AssemblerPredicate<(any_of FeatureStdExtA, FeatureStdExtZaamo),
@@ -242,8 +242,8 @@ def HasStdExtZalasr : 
Predicate<"Subtarget->hasStdExtZalasr()">,
   "'Zalasr' (Load-Acquire and Store-Release 
Instructions)">;
 
 def FeatureStdExtZalrsc
-: RISCVExperimentalExtension<"zalrsc", 0, 2,
- "'Zalrsc' (Load-Reserved/Store-Conditional)">;
+: RISCVExtension<"zalrsc", 1, 0,
+ "'Zalrsc' (Load-Reserved/Store-Conditional)">;
 def HasStdExtAOrZalrsc
 : Predicate<"Subtarget->hasStdExtA() || Subtarget->hasStdExtZalrsc()">,
   AssemblerPredicate<(any_of FeatureStdExtA, FeatureStdExtZalrsc),
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 8f49f6648ad28..9fdd842e5dd37 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -112,10 +112,10 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zfbfmin %s -o - | FileCheck 
--check-prefixes=CHECK,RV32ZFBFM

[clang] [Sema] Don't drop weak_import from a declaration that follows a declaration directly contained in a linkage-specification (PR #85886)

2024-05-08 Thread Akira Hatanaka via cfe-commits

ahatanak wrote:

> With that said, I think you need to check if a definition exists at all and 
> not just whether the last declaration is that definition.

Note that `checkNewAttributesAfterDef`, which is called right before the check, 
removes attributes on `New` if there was a full definition. The updated patch 
just looks for any previously declared tentative definition.

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


[clang] [Sema] Don't drop weak_import from a declaration that follows a declaration directly contained in a linkage-specification (PR #85886)

2024-05-08 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak updated 
https://github.com/llvm/llvm-project/pull/85886

>From d39667c7e65c10babb478d8f8d54fecb66d90568 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Tue, 19 Mar 2024 15:50:00 -0700
Subject: [PATCH 1/2] [Sema] Don't drop weak_import from a declaration that
 follows a declaration directly contained in a linkage-specification

Only drop it if the declaration follows a definition. I believe this is
what 33e022650adee965c65f9aea086ee74f3fd1bad5 was trying to do.

rdar://61865848
---
 clang/lib/Sema/SemaDecl.cpp  | 3 +--
 clang/test/SemaCXX/attr-weak.cpp | 7 +++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5850cd0ab6b9a..2e45f1191273a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4613,8 +4613,7 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult 
&Previous) {
   mergeDeclAttributes(New, Old);
   // Warn if an already-declared variable is made a weak_import in a subsequent
   // declaration
-  if (New->hasAttr() &&
-  Old->getStorageClass() == SC_None &&
+  if (New->hasAttr() && Old->isThisDeclarationADefinition() &&
   !Old->hasAttr()) {
 Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName();
 Diag(Old->getLocation(), diag::note_previous_declaration);
diff --git a/clang/test/SemaCXX/attr-weak.cpp b/clang/test/SemaCXX/attr-weak.cpp
index f065bfd9483f8..a2c5fd4abd35f 100644
--- a/clang/test/SemaCXX/attr-weak.cpp
+++ b/clang/test/SemaCXX/attr-weak.cpp
@@ -55,3 +55,10 @@ constexpr bool weak_method_is_non_null = 
&WithWeakMember::weak_method != nullptr
 // virtual member function is present.
 constexpr bool virtual_weak_method_is_non_null = 
&WithWeakMember::virtual_weak_method != nullptr; // expected-error {{must be 
initialized by a constant expression}}
 // expected-note@-1 {{comparison against pointer to weak member 
'WithWeakMember::virtual_weak_method' can only be performed at runtime}}
+
+// Check that no warnings are emitted.
+extern "C" int g0;
+extern int g0 __attribute__((weak_import));
+
+extern "C" int g1 = 0; // expected-note {{previous definition is here}}
+extern int g1 __attribute__((weak_import)); // expected-warning {{attribute 
declaration must precede definition}}

>From 33e3219c721d0c03f445c9bb977cb9f3809e74ac Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Wed, 8 May 2024 20:40:58 -0700
Subject: [PATCH 2/2] Check whether there's a definition at all

---
 clang/lib/Sema/SemaDecl.cpp | 23 +--
 clang/test/Sema/attr-weak.c |  4 
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 2e45f1191273a..0be6906026a85 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -4613,12 +4613,23 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult 
&Previous) {
   mergeDeclAttributes(New, Old);
   // Warn if an already-declared variable is made a weak_import in a subsequent
   // declaration
-  if (New->hasAttr() && Old->isThisDeclarationADefinition() &&
-  !Old->hasAttr()) {
-Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName();
-Diag(Old->getLocation(), diag::note_previous_declaration);
-// Remove weak_import attribute on new declaration.
-New->dropAttr();
+  if (New->hasAttr()) {
+// We know there's no full definition as the attribute on New would have
+// been removed otherwise. Just look for the most recent tentative
+// definition.
+VarDecl *TentativeDef = nullptr;
+for (auto *D = Old; D; D = D->getPreviousDecl())
+  if (D->isThisDeclarationADefinition() == VarDecl::TentativeDefinition) {
+TentativeDef = D;
+break;
+  }
+
+if (TentativeDef) {
+  Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName();
+  Diag(TentativeDef->getLocation(), diag::note_previous_declaration);
+  // Remove weak_import attribute on new declaration.
+  New->dropAttr();
+}
   }
 
   if (const auto *ILA = New->getAttr())
diff --git a/clang/test/Sema/attr-weak.c b/clang/test/Sema/attr-weak.c
index b827d1539b997..94e1723e125b6 100644
--- a/clang/test/Sema/attr-weak.c
+++ b/clang/test/Sema/attr-weak.c
@@ -19,6 +19,10 @@ static int x __attribute__((weak)); // expected-error {{weak 
declaration cannot
 int C; // expected-note {{previous declaration is here}}
 extern int C __attribute__((weak_import)); // expected-warning {{an 
already-declared variable is made a weak_import declaration}}
 
+int C2; // expected-note {{previous declaration is here}}
+extern int C2;
+extern int C2 __attribute__((weak_import)); // expected-warning {{an 
already-declared variable is made a weak_import declaration}}
+
 static int pr14946_x;
 extern int pr14946_x  __attribute__((weak)); // expected-error {{weak 
declaration cannot have internal linkage}}
 

___
cfe-commits mailing

[clang-tools-extra] [clang-tidy] support expect no diagnosis test (PR #91293)

2024-05-08 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy] support expect no diagnosis test (PR #91293)

2024-05-08 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-tidy] support expect no diagnosis test (PR #91293)

2024-05-08 Thread Congcong Cai via cfe-commits

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


[clang] [llvm] [PowerPC] Tune AIX shared library TLS model at function level (PR #84132)

2024-05-08 Thread Felix via cfe-commits

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


[clang] ea126ae - [PowerPC] Tune AIX shared library TLS model at function level (#84132)

2024-05-08 Thread via cfe-commits

Author: Felix (Ting Wang)
Date: 2024-05-09T09:50:36+08:00
New Revision: ea126aebdc9d8205016f355d85dbf1c15f2f4b28

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

LOG: [PowerPC] Tune AIX shared library TLS model at function level (#84132)

Under some circumstance (library loaded with the main program), TLS
initial-exec model can be applied to local-dynamic access(es). We
could use some simple heuristic to decide the update at function level:
* If there is equal or less than a number of TLS local-dynamic access(es)
in the function, use TLS initial-exec model. (the threshold which default to
1 is controlled by hidden option)

Added: 

llvm/test/CodeGen/PowerPC/aix-shared-lib-tls-model-opt-small-local-dynamic-tls.ll
llvm/test/CodeGen/PowerPC/aix-shared-lib-tls-model-opt.ll
llvm/test/CodeGen/PowerPC/check-aix-shared-lib-tls-model-opt-IRattribute.ll
llvm/test/CodeGen/PowerPC/check-aix-shared-lib-tls-model-opt-Option.ll

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/PPC.cpp
clang/lib/Basic/Targets/PPC.h
llvm/lib/Target/PowerPC/PPC.td
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/lib/Target/PowerPC/PPCMCInstLower.cpp
llvm/lib/Target/PowerPC/PPCMachineFunctionInfo.h
llvm/lib/Target/PowerPC/PPCSubtarget.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 322cc12af34ac..1429528975853 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5077,6 +5077,10 @@ def maix_small_local_dynamic_tls : Flag<["-"], 
"maix-small-local-dynamic-tls">,
"where the offset from the TLS base is encoded as an "
"immediate operand (AIX 64-bit only). "
"This access sequence is not used for variables larger than 32KB.">;
+def maix_shared_lib_tls_model_opt : Flag<["-"], 
"maix-shared-lib-tls-model-opt">,
+  Group,
+  HelpText<"For shared library loaded with the main program, change 
local-dynamic access(es) "
+   "to initial-exec access(es) at the function level (AIX 64-bit 
only).">;
 def maix_struct_return : Flag<["-"], "maix-struct-return">,
   Group, Visibility<[ClangOption, CC1Option]>,
   HelpText<"Return all structs in memory (PPC32 only)">,

diff  --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index bad5259958a88..a1e5f20f7dbe2 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -91,6 +91,8 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector &Features,
   IsISA3_1 = true;
 } else if (Feature == "+quadword-atomics") {
   HasQuadwordAtomics = true;
+} else if (Feature == "+aix-shared-lib-tls-model-opt") {
+  HasAIXShLibTLSModelOpt = true;
 }
 // TODO: Finish this list and add an assert that we've handled them
 // all.
@@ -580,6 +582,9 @@ bool PPCTargetInfo::initFeatureMap(
   Features["aix-small-local-exec-tls"] = false;
   Features["aix-small-local-dynamic-tls"] = false;
 
+  // Turn off TLS model opt by default.
+  Features["aix-shared-lib-tls-model-opt"] = false;
+
   Features["spe"] = llvm::StringSwitch(CPU)
 .Case("8548", true)
 .Case("e500", true)
@@ -722,6 +727,7 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
   .Case("isa-v30-instructions", IsISA3_0)
   .Case("isa-v31-instructions", IsISA3_1)
   .Case("quadword-atomics", HasQuadwordAtomics)
+  .Case("aix-shared-lib-tls-model-opt", HasAIXShLibTLSModelOpt)
   .Default(false);
 }
 

diff  --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index 30059e418e69b..496b6131d09bb 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -81,6 +81,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool IsISA3_0 = false;
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
+  bool HasAIXShLibTLSModelOpt = false;
 
 protected:
   std::string ABI;

diff  --git a/llvm/lib/Target/PowerPC/PPC.td b/llvm/lib/Target/PowerPC/PPC.td
index b962ed28d7200..639771ab9eabb 100644
--- a/llvm/lib/Target/PowerPC/PPC.td
+++ b/llvm/lib/Target/PowerPC/PPC.td
@@ -338,6 +338,12 @@ def FeatureAIXLocalDynamicTLS :
"true", "Produce a faster local-dynamic TLS sequence for 
this "
"function for 64-bit AIX">;
 
+def FeatureAIXSharedLibTLSModelOpt :
+  SubtargetFeature<"aix-shared-lib-tls-model-opt",
+   "HasAIXShLibTLSModelOpt", "true",
+   "Tune TLS model at function level in shared library loaded "
+   "with the main program (for 64-bit AIX only)">;
+
 def FeaturePredictableSelectIsExpe

[clang-tools-extra] [clang-tidy] support expect no diagnosis test (PR #91293)

2024-05-08 Thread Congcong Cai via cfe-commits

HerrCai0907 wrote:

> Why can the tests not just accept reference files that do not contain any 
> CHECK-* comments?

run-clang-tidy do assert for this, since FileCheck need to use this information 
to check the result. If nothing is provided, then  nothing can be detected.

> Also, isn't there the // RUN: not %check_clang_tidy (note the not) command to 
> claim a test file doesn't trigger the specified checks?

`not` will treat non-zero return code as success. It is totally different 
thing. 

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


[clang] [driver] Only check for unused plugin options (PR #91522)

2024-05-08 Thread Hubert Tong via cfe-commits

https://github.com/hubert-reinterpretcast approved this pull request.

LGTM!

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


[clang] [llvm] [WebAssembly] Implement prototype f32.store_f16 instruction. (PR #91545)

2024-05-08 Thread Heejin Ahn via cfe-commits


@@ -192,6 +192,7 @@ 
TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f"
 
 // Half-Precision (fp16)
 TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "nU", "half-precision")

aheejin wrote:

Can stores be considered pure?

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


[clang] [llvm] [WebAssembly] Implement prototype f32.store_f16 instruction. (PR #91545)

2024-05-08 Thread Heejin Ahn via cfe-commits


@@ -171,12 +171,16 @@ defm STORE8_I64 : WebAssemblyStore;
 defm STORE16_I64 : WebAssemblyStore;
 defm STORE32_I64 : WebAssemblyStore;
 
+defm STORE_F16_F32 : WebAssemblyStore;

aheejin wrote:

```suggestion
// Half-precision store.
defm STORE_F16_F32 :
  WebAssemblyStore;
```
How about adding one-line comment? The same for `LOAD` too.
Also 80-col wrapping.

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


[clang] [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (PR #91534)

2024-05-08 Thread Krystian Stasiowski via cfe-commits

sdkrystian wrote:

@erichkeane Release note added

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


[clang] [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (PR #91534)

2024-05-08 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/91534

>From eea39228271166b4d8f39b32d7866cb33dffdd0b Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 8 May 2024 08:43:23 -0400
Subject: [PATCH 1/2] [Clang][Sema] Do not mark template parameters in the
 exception specification as used during partial ordering

---
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 36 +++---
 .../temp.deduct/temp.deduct.partial/p3.cpp| 72 +++
 2 files changed, 100 insertions(+), 8 deletions(-)
 create mode 100644 
clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index fe7e35d841510..c17c5838803a8 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5453,7 +5453,7 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
 // is used.
 if (DeduceTemplateArgumentsByTypeMatch(
 S, TemplateParams, FD2->getType(), FD1->getType(), Info, Deduced,
-TDF_None,
+TDF_AllowCompatibleFunctionType,
 /*PartialOrdering=*/true) != TemplateDeductionResult::Success)
   return false;
 break;
@@ -5485,20 +5485,40 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
   switch (TPOC) {
   case TPOC_Call:
 for (unsigned I = 0, N = Args2.size(); I != N; ++I)
-  ::MarkUsedTemplateParameters(S.Context, Args2[I], false,
-   TemplateParams->getDepth(),
-   UsedParameters);
+  ::MarkUsedTemplateParameters(S.Context, Args2[I], /*OnlyDeduced=*/false,
+   TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Conversion:
-::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(), false,
+::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(),
+ /*OnlyDeduced=*/false,
  TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Other:
-::MarkUsedTemplateParameters(S.Context, FD2->getType(), false,
- TemplateParams->getDepth(),
- UsedParameters);
+// We do not deduce template arguments from the exception specification
+// when determining the primary template of a function template
+// specialization or when taking the address of a function template.
+// Therefore, we do not mark template parameters in the exception
+// specification as used during partial ordering to prevent the following
+// from being ambiguous:
+//
+//   template
+//   void f(U) noexcept(noexcept(T())); // #1
+//
+//   template
+//   void f(T*) noexcept; // #2
+//
+//   template<>
+//   void f(int*) noexcept; // explicit specialization of #2
+//
+// Although there is no corresponding wording in the standard, this seems
+// to be the intended behavior given the definition of
+// 'deduction substitution loci' in [temp.deduct].
+::MarkUsedTemplateParameters(
+S.Context,
+S.Context.getFunctionTypeWithExceptionSpec(FD2->getType(), EST_None),
+/*OnlyDeduced=*/false, TemplateParams->getDepth(), UsedParameters);
 break;
   }
 
diff --git 
a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp 
b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp
new file mode 100644
index 0..cc1d4ecda2ecc
--- /dev/null
+++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template
+struct A { };
+
+constexpr A a;
+constexpr A b;
+
+constexpr int* x = nullptr;
+constexpr short* y = nullptr;
+
+namespace ExplicitArgs {
+  template
+  constexpr int f(U) noexcept(noexcept(T())) {
+return 0;
+  }
+
+  template
+  constexpr int f(T*) noexcept {
+return 1;
+  }
+
+  template<>
+  constexpr int f(int*) noexcept {
+return 2;
+  }
+
+  static_assert(f(1) == 0);
+  static_assert(f(y) == 1);
+  static_assert(f(x) == 2);
+
+  template
+  constexpr int g(U*) noexcept(noexcept(T())) {
+return 3;
+  }
+
+  template
+  constexpr int g(T) noexcept {
+return 4;
+  }
+
+  template<>
+  constexpr int g(int*) noexcept {
+return 5;
+  }
+
+  static_assert(g(y) == 3);
+  static_assert(g(1) == 4);
+  static_assert(g(x) == 5);
+} // namespace ExplicitArgs
+
+namespace DeducedArgs {
+  template
+  constexpr int f(T, A) noexcept(B) {
+return 0;
+  }
+
+  template
+  constexpr int f(T*, A) noexcept(B && B) {
+return 1;
+  }
+
+  template<>
+  constexpr int f(int*, A) {
+return 2;
+  }
+
+  static_assert(f(x, a) == 0);
+  static_assert(f(y, a) == 1);
+  static_assert(f(x, a) == 2);
+} // namespace DeducedArgs

>Fr

[clang] [analyzer] MallocChecker: Recognize std::atomics in smart pointer suppression. (PR #90918)

2024-05-08 Thread Artem Dergachev via cfe-commits

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


[clang] 51f178d - [analyzer] MallocChecker: Recognize std::atomics in smart pointer suppression. (#90918)

2024-05-08 Thread via cfe-commits

Author: Artem Dergachev
Date: 2024-05-08T18:00:59-07:00
New Revision: 51f178d909d477bd269e0b434af1a7f9373d4e61

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

LOG: [analyzer] MallocChecker: Recognize std::atomics in smart pointer 
suppression. (#90918)

Fixes #90498.

Same as 5337efc69cdd5 for atomic builtins, but for `std::atomic` this
time. This is useful because even though the actual builtin atomic is
still there, it may be buried beyond the inlining depth limit.

Also add one popular custom smart pointer class name to the name-based
heuristics, which isn't necessary to fix the bug but arguably a good
idea regardless.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/test/Analysis/Inputs/system-header-simulator-cxx.h
clang/test/Analysis/NewDelete-atomics.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
index dd204b62dcc04..ab89fb14046be 100644
--- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
@@ -3451,7 +3451,7 @@ static bool isReferenceCountingPointerDestructor(const 
CXXDestructorDecl *DD) {
 if (N.contains_insensitive("ptr") || N.contains_insensitive("pointer")) {
   if (N.contains_insensitive("ref") || N.contains_insensitive("cnt") ||
   N.contains_insensitive("intrusive") ||
-  N.contains_insensitive("shared")) {
+  N.contains_insensitive("shared") || N.ends_with_insensitive("rc")) {
 return true;
   }
 }
@@ -3483,13 +3483,24 @@ PathDiagnosticPieceRef 
MallocBugVisitor::VisitNode(const ExplodedNode *N,
   // original reference count is positive, we should not report use-after-frees
   // on objects deleted in such destructors. This can probably be improved
   // through better shared pointer modeling.
-  if (ReleaseDestructorLC) {
+  if (ReleaseDestructorLC && (ReleaseDestructorLC == CurrentLC ||
+  ReleaseDestructorLC->isParentOf(CurrentLC))) {
 if (const auto *AE = dyn_cast(S)) {
+  // Check for manual use of atomic builtins.
   AtomicExpr::AtomicOp Op = AE->getOp();
   if (Op == AtomicExpr::AO__c11_atomic_fetch_add ||
   Op == AtomicExpr::AO__c11_atomic_fetch_sub) {
-if (ReleaseDestructorLC == CurrentLC ||
-ReleaseDestructorLC->isParentOf(CurrentLC)) {
+BR.markInvalid(getTag(), S);
+  }
+} else if (const auto *CE = dyn_cast(S)) {
+  // Check for `std::atomic` and such. This covers both regular method 
calls
+  // and operator calls.
+  if (const auto *MD =
+  dyn_cast_or_null(CE->getDirectCallee())) {
+const CXXRecordDecl *RD = MD->getParent();
+// A bit wobbly with ".contains()" because it may be like
+// "__atomic_base" or something.
+if (StringRef(RD->getNameAsString()).contains("atomic")) {
   BR.markInvalid(getTag(), S);
 }
   }

diff  --git a/clang/test/Analysis/Inputs/system-header-simulator-cxx.h 
b/clang/test/Analysis/Inputs/system-header-simulator-cxx.h
index 1c2be322f83c2..29326ec1f9280 100644
--- a/clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ b/clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -1260,6 +1260,13 @@ template<
 iterator end() const { return iterator(val + 1); }
 };
 
+template 
+class atomic {
+public:
+  T operator++();
+  T operator--();
+};
+
 namespace execution {
 class sequenced_policy {};
 }

diff  --git a/clang/test/Analysis/NewDelete-atomics.cpp 
b/clang/test/Analysis/NewDelete-atomics.cpp
index 54fce17ea7bd2..1425acab7489b 100644
--- a/clang/test/Analysis/NewDelete-atomics.cpp
+++ b/clang/test/Analysis/NewDelete-atomics.cpp
@@ -20,7 +20,7 @@ typedef enum memory_order {
   memory_order_seq_cst = __ATOMIC_SEQ_CST
 } memory_order;
 
-class Obj {
+class RawObj {
   int RefCnt;
 
 public:
@@ -37,11 +37,27 @@ class Obj {
   void foo();
 };
 
+class StdAtomicObj {
+  std::atomic RefCnt;
+
+public:
+  int incRef() {
+return ++RefCnt;
+  }
+
+  int decRef() {
+return --RefCnt;
+  }
+
+  void foo();
+};
+
+template 
 class IntrusivePtr {
-  Obj *Ptr;
+  T *Ptr;
 
 public:
-  IntrusivePtr(Obj *Ptr) : Ptr(Ptr) {
+  IntrusivePtr(T *Ptr) : Ptr(Ptr) {
 Ptr->incRef();
   }
 
@@ -55,22 +71,106 @@ class IntrusivePtr {
   delete Ptr;
   }
 
-  Obj *getPtr() const { return Ptr; } // no-warning
+  T *getPtr() const { return Ptr; } // no-warning
+};
+
+// Also IntrusivePtr but let's dodge name-based heuristics.
+template 
+class DifferentlyNamed {
+  T *Ptr;
+
+public:
+  DifferentlyNamed(T *Ptr) : Ptr(Ptr) {
+Ptr->incRef();
+  }
+
+  DifferentlyNamed(const DifferentlyNamed &Other) : Ptr(Other.Ptr) {
+ 

[clang] [Clang][Sema] Fix lookup of dependent operator= named by using-declaration (PR #91503)

2024-05-08 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/91503

>From 163c22df80a5e8c753ded0d5cf5e909553477059 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 8 May 2024 12:59:24 -0400
Subject: [PATCH 1/3] [Clang][Sema] Fix lookup of dependent operator= named by
 using-declaration

---
 clang/lib/Sema/SemaDeclCXX.cpp | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 157d42c09cfcd..91c83564b567e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -12963,14 +12963,15 @@ NamedDecl *Sema::BuildUsingDeclaration(
 return nullptr;
   }
 
-  DeclContext *LookupContext = computeDeclContext(SS);
   NestedNameSpecifierLoc QualifierLoc = SS.getWithLocInContext(Context);
-  if (!LookupContext || EllipsisLoc.isValid()) {
-NamedDecl *D;
+  DeclContext *LookupContext = computeDeclContext(SS);
+
+  auto BuildDependent = [&] {
+NamedDecl *D = nullptr;
 // Dependent scope, or an unexpanded pack
 if (!LookupContext && CheckUsingDeclQualifier(UsingLoc, HasTypenameKeyword,
   SS, NameInfo, IdentLoc))
-  return nullptr;
+  return D;
 
 if (HasTypenameKeyword) {
   // FIXME: not all declaration name kinds are legal here
@@ -12987,7 +12988,7 @@ NamedDecl *Sema::BuildUsingDeclaration(
 CurContext->addDecl(D);
 ProcessDeclAttributeList(S, D, AttrList);
 return D;
-  }
+  };
 
   auto Build = [&](bool Invalid) {
 UsingDecl *UD =
@@ -13002,6 +13003,9 @@ NamedDecl *Sema::BuildUsingDeclaration(
   auto BuildInvalid = [&]{ return Build(true); };
   auto BuildValid = [&]{ return Build(false); };
 
+  if (!LookupContext || EllipsisLoc.isValid())
+return BuildDependent();
+
   if (RequireCompleteDeclContext(SS, LookupContext))
 return BuildInvalid();
 
@@ -13024,6 +13028,9 @@ NamedDecl *Sema::BuildUsingDeclaration(
 
   LookupQualifiedName(R, LookupContext);
 
+  if (R.wasNotFoundInCurrentInstantiation())
+return BuildDependent();
+
   // Validate the context, now we have a lookup
   if (CheckUsingDeclQualifier(UsingLoc, HasTypenameKeyword, SS, NameInfo,
   IdentLoc, &R))

>From c87423c9b99df81439f148f4953662927ff0cfb6 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 8 May 2024 15:25:30 -0400
Subject: [PATCH 2/3] [FOLD] update test

---
 .../basic.lookup/basic.lookup.qual/class.qual/p2.cpp | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git 
a/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp 
b/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
index be07ab0a48b33..2a6bebb27bbeb 100644
--- a/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
+++ b/clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
@@ -137,17 +137,16 @@ namespace InhCtor {
   int n = b.T(); // expected-error {{'T' is a protected member of 
'InhCtor::A'}}
  // expected-note@-15 {{declared protected here}}
 
-  // FIXME: EDG and GCC reject this too, but it's not clear why it would be
-  // ill-formed.
   template
   struct S : T {
-struct U : S { // expected-note 6{{candidate}}
+// FIXME: S is incomplete here and we should diagnose this!
+struct U : S {
   using S::S;
 };
 using T::T;
   };
-  S::U ua(0); // expected-error {{no match}}
-  S::U ub(0); // expected-error {{no match}}
+  S::U ua(0);
+  S::U ub(0);
 
   template
   struct X : T {

>From 6cd97fd33659b66e2941c530d38878882433539f Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 8 May 2024 15:29:10 -0400
Subject: [PATCH 3/3] [FOLD] add test

---
 .../CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp  | 12 
 1 file changed, 12 insertions(+)

diff --git a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp 
b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
index 43053c18c5076..d5824d251c2a5 100644
--- a/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp
@@ -484,6 +484,18 @@ namespace N3 {
 
   template struct E; // expected-note {{in instantiation of template 
class 'N3::E' requested here}}
 
+  template
+  struct F {
+F& operator=(T);
+struct G;
+  };
+
+  template
+  struct F::G : F {
+using F::operator=;
+  };
+
+  template struct F;
 } // namespace N3
 
 namespace N4 {

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


[clang] [driver] Only check for unused plugin options (PR #91522)

2024-05-08 Thread Jake Egan via cfe-commits

https://github.com/jakeegan updated 
https://github.com/llvm/llvm-project/pull/91522

>From 7684f9e6f99c30287f2822152dc83367a934d8b6 Mon Sep 17 00:00:00 2001
From: Jake Egan 
Date: Wed, 8 May 2024 15:09:46 -0400
Subject: [PATCH 1/2] [driver] Only check for unused plugin options

This fixes matching `clang: error: argument unused during compilation: 
'-Werror' [-Werror,-Wunused-command-line-argument]` on AIX.
---
 clang/test/Driver/plugin-driver-args.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/Driver/plugin-driver-args.cpp 
b/clang/test/Driver/plugin-driver-args.cpp
index 6f0e6e2ba7525..7667cc4ce7b00 100644
--- a/clang/test/Driver/plugin-driver-args.cpp
+++ b/clang/test/Driver/plugin-driver-args.cpp
@@ -23,5 +23,5 @@
 
 // Plugins are only relevant for the -cc1 phase. No warning should be raised
 // when only using the assembler. See GH #88173.
-// RUN: %clang -c -fpass-plugin=bar.so -fplugin=bar.so -fplugin-arg-bar-option 
-Werror -x assembler %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-PLUGIN-ASM
-// CHECK-PLUGIN-ASM-NOT: argument unused during compilation
+// RUN: %clang -c -fpass-plugin=bar.so -fplugin=bar.so -fplugin-arg-bar-option 
-Wunused-command-line-argument -x assembler %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-PLUGIN-ASM
+// CHECK-PLUGIN-ASM-NOT: argument unused during compilation: 
'-f{{[a-z-]*-plugin[^']*}}'

>From 223b76b9419db53286b3b5bdc74de985c1d7b794 Mon Sep 17 00:00:00 2001
From: Jake Egan 
Date: Wed, 8 May 2024 20:51:43 -0400
Subject: [PATCH 2/2] Check for -fplugin*

Co-authored-by: Hubert Tong 
---
 clang/test/Driver/plugin-driver-args.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Driver/plugin-driver-args.cpp 
b/clang/test/Driver/plugin-driver-args.cpp
index 7667cc4ce7b00..6efd859f9d085 100644
--- a/clang/test/Driver/plugin-driver-args.cpp
+++ b/clang/test/Driver/plugin-driver-args.cpp
@@ -24,4 +24,4 @@
 // Plugins are only relevant for the -cc1 phase. No warning should be raised
 // when only using the assembler. See GH #88173.
 // RUN: %clang -c -fpass-plugin=bar.so -fplugin=bar.so -fplugin-arg-bar-option 
-Wunused-command-line-argument -x assembler %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-PLUGIN-ASM
-// CHECK-PLUGIN-ASM-NOT: argument unused during compilation: 
'-f{{[a-z-]*-plugin[^']*}}'
+// CHECK-PLUGIN-ASM-NOT: argument unused during compilation: 
'-f{{[a-z-]*plugin[^']*}}'

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Krystian Stasiowski via cfe-commits

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


[clang] 62b5b61 - [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (#91498)

2024-05-08 Thread via cfe-commits

Author: Krystian Stasiowski
Date: 2024-05-08T20:49:59-04:00
New Revision: 62b5b61f436add042d8729dc9837d055613180d9

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

LOG: [Clang][Sema] Fix lookup of dependent operator= outside of complete-class 
contexts (#91498)

Fixes a crash caused by #90152.

Added: 


Modified: 
clang/lib/Sema/SemaLookup.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p4.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index e63da5875d2c9..e20de338ebb16 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1267,6 +1267,20 @@ struct FindLocalExternScope {
   LookupResult &R;
   bool OldFindLocalExtern;
 };
+
+/// Returns true if 'operator=' should be treated as a dependent name.
+bool isDependentAssignmentOperator(DeclarationName Name,
+   DeclContext *LookupContext) {
+  const auto *LookupRecord = dyn_cast_if_present(LookupContext);
+  // If the lookup context is the current instantiation but we are outside a
+  // complete-class context, we will never find the implicitly declared
+  // copy/move assignment operators because they are declared at the closing 
'}'
+  // of the class specifier. In such cases, we treat 'operator=' like any other
+  // unqualified name because the results of name lookup in the template
+  // definition/instantiation context will always be the same.
+  return Name.getCXXOverloadedOperator() == OO_Equal && LookupRecord &&
+ !LookupRecord->isBeingDefined() && LookupRecord->isDependentContext();
+}
 } // end anonymous namespace
 
 bool Sema::CppLookupName(LookupResult &R, Scope *S) {
@@ -1275,13 +1289,6 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
   DeclarationName Name = R.getLookupName();
   Sema::LookupNameKind NameKind = R.getLookupKind();
 
-  // If this is the name of an implicitly-declared special member function,
-  // go through the scope stack to implicitly declare
-  if (isImplicitlyDeclaredMemberFunctionName(Name)) {
-for (Scope *PreS = S; PreS; PreS = PreS->getParent())
-  if (DeclContext *DC = PreS->getEntity())
-DeclareImplicitMemberFunctionsWithName(*this, Name, R.getNameLoc(), 
DC);
-  }
   // C++23 [temp.dep.general]p2:
   //   The component name of an unqualified-id is dependent if
   //   - it is a conversion-function-id whose conversion-type-id
@@ -1299,9 +1306,8 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
   if (isImplicitlyDeclaredMemberFunctionName(Name)) {
 for (Scope *PreS = S; PreS; PreS = PreS->getParent())
   if (DeclContext *DC = PreS->getEntity()) {
-if (DC->isDependentContext() && isa(DC) &&
-Name.getCXXOverloadedOperator() == OO_Equal &&
-!R.isTemplateNameLookup()) {
+if (!R.isTemplateNameLookup() &&
+isDependentAssignmentOperator(Name, DC)) {
   R.setNotFoundInCurrentInstantiation();
   return false;
 }
@@ -2472,8 +2478,6 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 }
   } QL(LookupCtx);
 
-  bool TemplateNameLookup = R.isTemplateNameLookup();
-  CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
   if (!InUnqualifiedLookup && !R.isForRedeclaration()) {
 // C++23 [temp.dep.type]p5:
 //   A qualified name is dependent if
@@ -2486,13 +2490,14 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 if (DeclarationName Name = R.getLookupName();
 (Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
  Name.getCXXNameType()->isDependentType()) ||
-(Name.getCXXOverloadedOperator() == OO_Equal && LookupRec &&
- LookupRec->isDependentContext() && !TemplateNameLookup)) {
+(!R.isTemplateNameLookup() &&
+ isDependentAssignmentOperator(Name, LookupCtx))) {
   R.setNotFoundInCurrentInstantiation();
   return false;
 }
   }
 
+  CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
   if (LookupDirect(*this, R, LookupCtx)) {
 R.resolveKind();
 if (LookupRec)
@@ -2604,7 +2609,7 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 //   template, and if the name is used as a template-name, the
 //   reference refers to the class template itself and not a
 //   specialization thereof, and is not ambiguous.
-if (TemplateNameLookup)
+if (R.isTemplateNameLookup())
   if (auto *TD = getAsTemplateNameDecl(ND))
 ND = TD;
 

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 7e57fa0696725..480bc74c2001a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp

[clang] [Clang][Sema] access checking of friend declaration should not be delayed (PR #91430)

2024-05-08 Thread Qizhi Hu via cfe-commits

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

>From 324e4361b4cb1b17065b4dc7d4bdfa41fe781e7d Mon Sep 17 00:00:00 2001
From: Qizhi Hu <836744...@qq.com>
Date: Tue, 7 May 2024 22:32:39 +0800
Subject: [PATCH 1/2] [Clang][Sema] access checking of friend declaration
 should not be delayed

---
 clang/include/clang/Sema/Scope.h |  6 ++
 clang/lib/Parse/ParseDecl.cpp|  7 +--
 clang/lib/Sema/Scope.cpp |  2 ++
 clang/lib/Sema/SemaAccess.cpp| 12 ++--
 clang/test/SemaCXX/PR12361.cpp   | 30 ++
 5 files changed, 53 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaCXX/PR12361.cpp

diff --git a/clang/include/clang/Sema/Scope.h b/clang/include/clang/Sema/Scope.h
index 1752a25111a77..084db73034219 100644
--- a/clang/include/clang/Sema/Scope.h
+++ b/clang/include/clang/Sema/Scope.h
@@ -159,6 +159,9 @@ class Scope {
 
 /// This is a scope of type alias declaration.
 TypeAliasScope = 0x2000,
+
+/// This is a scope of friend declaration.
+FriendScope = 0x4000,
   };
 
 private:
@@ -586,6 +589,9 @@ class Scope {
   /// Determine whether this scope is a type alias scope.
   bool isTypeAliasScope() const { return getFlags() & Scope::TypeAliasScope; }
 
+  /// Determine whether this scope is a friend scope.
+  bool isFriendScope() const { return getFlags() & Scope::FriendScope; }
+
   /// Returns if rhs has a higher scope depth than this.
   ///
   /// The caller is responsible for calling this only if one of the two scopes
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 4e4b05b21383e..78a81c77f48c6 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -4332,9 +4332,12 @@ void Parser::ParseDeclarationSpecifiers(
 
 // friend
 case tok::kw_friend:
-  if (DSContext == DeclSpecContext::DSC_class)
+  if (DSContext == DeclSpecContext::DSC_class) {
 isInvalid = DS.SetFriendSpec(Loc, PrevSpec, DiagID);
-  else {
+Scope *CurS = getCurScope();
+if (!isInvalid && CurS)
+  CurS->setFlags(CurS->getFlags() | Scope::FriendScope);
+  } else {
 PrevSpec = ""; // not actually used by the diagnostic
 DiagID = diag::err_friend_invalid_in_context;
 isInvalid = true;
diff --git a/clang/lib/Sema/Scope.cpp b/clang/lib/Sema/Scope.cpp
index 11a41753a1bda..780aa898b1085 100644
--- a/clang/lib/Sema/Scope.cpp
+++ b/clang/lib/Sema/Scope.cpp
@@ -229,6 +229,8 @@ void Scope::dumpImpl(raw_ostream &OS) const {
   {ClassInheritanceScope, "ClassInheritanceScope"},
   {CatchScope, "CatchScope"},
   {OpenACCComputeConstructScope, "OpenACCComputeConstructScope"},
+  {TypeAliasScope, "TypeAliasScope"},
+  {FriendScope, "FriendScope"},
   };
 
   for (auto Info : FlagInfo) {
diff --git a/clang/lib/Sema/SemaAccess.cpp b/clang/lib/Sema/SemaAccess.cpp
index 6a707eeb66d01..72c6736bb6648 100644
--- a/clang/lib/Sema/SemaAccess.cpp
+++ b/clang/lib/Sema/SemaAccess.cpp
@@ -1477,8 +1477,16 @@ static Sema::AccessResult CheckAccess(Sema &S, 
SourceLocation Loc,
   //   void foo(A::private_type);
   //   void B::foo(A::private_type);
   if (S.DelayedDiagnostics.shouldDelayDiagnostics()) {
-S.DelayedDiagnostics.add(DelayedDiagnostic::makeAccess(Loc, Entity));
-return Sema::AR_delayed;
+Scope *TS = S.getCurScope();
+bool IsFriendDeclaration = false;
+while (TS && !IsFriendDeclaration) {
+  IsFriendDeclaration = TS->isFriendScope();
+  TS = TS->getParent();
+}
+if (!IsFriendDeclaration) {
+  S.DelayedDiagnostics.add(DelayedDiagnostic::makeAccess(Loc, Entity));
+  return Sema::AR_delayed;
+}
   }
 
   EffectiveContext EC(S.CurContext);
diff --git a/clang/test/SemaCXX/PR12361.cpp b/clang/test/SemaCXX/PR12361.cpp
new file mode 100644
index 0..95ceb45b7ba04
--- /dev/null
+++ b/clang/test/SemaCXX/PR12361.cpp
@@ -0,0 +1,30 @@
+ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
+ // RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+ 
+class D {
+class E{
+class F{}; // expected-note{{implicitly declared private here}}
+friend  void foo(D::E::F& q);
+};
+friend  void foo(D::E::F& q); // expected-error{{'F' is a private member 
of 'D::E'}}
+};
+
+void foo(D::E::F& q) {}
+
+class D1 {
+class E1{
+class F1{}; // expected-note{{implicitly declared private here}}
+friend  D1::E1::F1 foo1();
+};
+friend  D1::E1::F1 foo1(); // expected-error{{'F1' is a private member of 
'D1::E1'}}
+};
+
+D1::E1::F1 foo1() { return D1::E1::F1(); }
+
+class D2 {
+class E2{
+class F2{};
+friend  void foo2();
+};
+friend  void foo2(){ D2::E2::F2 c;}
+};

>From 97723ff0ec73ac107bc74f222852e4c12b727eb0 Mon Sep 17 00:00:00 2001
From: Qizhi Hu <836744...@qq.com>
Date: Wed, 8 May 2024 21:22:01 +0800
Subject: [PATCH 2/2] apply reviews

---
 clang/docs/ReleaseN

[clang] [analyzer] MallocChecker: Recognize std::atomics in smart pointer suppression. (PR #90918)

2024-05-08 Thread Artem Dergachev via cfe-commits

haoNoQ wrote:

@sharkautarch Yeah I think the situation where we observe the allocation site 
during analysis may be significantly different in presence of smart pointers. 
It may be a good idea to include such check in the heuristic, to reclaim some 
of the false negatives currently silenced by it. If we've seen the initial 
reference count and we've modeled it perfectly so far, these false positives 
can't happen. But this implies that we model our atomics perfectly. And given 
that we don't even know what a "reference count" is (maybe it's just some 
unrelated integer?), it's quite hard to get that right.

Also we don't really do "whole program analysis" and we probably can't do that 
without major changes to our technique; it simply doesn't scale to that scale. 
Our existing cross-TU mode is more about _occasionally_ breaking translation 
unit boundaries when we really want something specific from another TU (like 
the effects of a function call we just encountered), but we still focus on 
small portions of the program at a time. We never really derive whole-program 
conclusions from these small independent invocations of our analysis. That'd 
require very different technology. It's not necessarily difficult per se – we 
could develop such technology and occasionally make our main analysis 
interoperate with it. But we haven't done any of that yet and our cross-TU mode 
isn't that kind of cross-TU mode.

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


[clang] [llvm] [WebAssembly] Implement prototype f32.store_f16 instruction. (PR #91545)

2024-05-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-ir

Author: Brendan Dahl (brendandahl)


Changes

Adds a builtin and intrinsic for the f32.store_f16 instruction.

The instruction stores an f32 value as an f16 memory. Specified at:
https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md

Note: the current spec has f32.store_f16 as opcode 0xFD0121, but this is 
incorrect and will be changed to 0xFC31 soon.

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


10 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsWebAssembly.def (+1) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+6) 
- (modified) clang/test/CodeGen/builtins-wasm.c (+6) 
- (modified) llvm/include/llvm/IR/IntrinsicsWebAssembly.td (+5) 
- (modified) llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h 
(+1) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (+8) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td (+4) 
- (modified) llvm/test/CodeGen/WebAssembly/half-precision.ll (+9) 
- (modified) llvm/test/CodeGen/WebAssembly/offset.ll (+27) 
- (modified) llvm/test/MC/WebAssembly/simd-encodings.s (+3) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index cf54f8f4422f8..41fadd10e9432 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -192,6 +192,7 @@ 
TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f"
 
 // Half-Precision (fp16)
 TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "nU", "half-precision")
 
 // Reference Types builtins
 // Some builtins are custom type-checked - see 't' as part of the third 
argument,
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e8a6bd050e17e..abb644d8eb506 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -21308,6 +21308,12 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_loadf16_f32);
 return Builder.CreateCall(Callee, {Addr});
   }
+  case WebAssembly::BI__builtin_wasm_storef16_f32: {
+Value *Val = EmitScalarExpr(E->getArg(0));
+Value *Addr = EmitScalarExpr(E->getArg(1));
+Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_storef16_f32);
+return Builder.CreateCall(Callee, {Val, Addr});
+  }
   case WebAssembly::BI__builtin_wasm_table_get: {
 assert(E->getArg(0)->getType()->isArrayType());
 Value *Table = EmitArrayToPointerDecay(E->getArg(0)).emitRawPointer(*this);
diff --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index ab1c6cd494ae5..bcb15969de1c5 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -807,6 +807,12 @@ float load_f16_f32(__fp16 *addr) {
   // WEBASSEMBLY: call float @llvm.wasm.loadf16.f32(ptr %{{.*}})
 }
 
+void store_f16_f32(float val, __fp16 *addr) {
+  return __builtin_wasm_storef16_f32(val, addr);
+  // WEBASSEMBLY: tail call void @llvm.wasm.storef16.f32(float %val, ptr 
%{{.*}})
+  // WEBASSEMBLY-NEXT: ret
+}
+
 __externref_t externref_null() {
   return __builtin_wasm_ref_null_extern();
   // WEBASSEMBLY: tail call ptr addrspace(10) @llvm.wasm.ref.null.extern()
diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td 
b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index f8142a8ca9e93..572d334ac9552 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -332,6 +332,11 @@ def int_wasm_loadf16_f32:
 [llvm_ptr_ty],
 [IntrReadMem, IntrArgMemOnly],
  "", [SDNPMemOperand]>;
+def int_wasm_storef16_f32:
+  Intrinsic<[],
+[llvm_float_ty, llvm_ptr_ty],
+[IntrWriteMem, IntrArgMemOnly],
+ "", [SDNPMemOperand]>;
 
 
 
//===--===//
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h 
b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
index d3b496ae59179..d4e9fb057c44d 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
@@ -207,6 +207,7 @@ inline unsigned GetDefaultP2AlignAny(unsigned Opc) {
   WASM_LOAD_STORE(LOAD_LANE_I16x8)
   WASM_LOAD_STORE(STORE_LANE_I16x8)
   WASM_LOAD_STORE(LOAD_F16_F32)
+  WASM_LOAD_STORE(STORE_F16_F32)
   return 1;
   WASM_LOAD_STORE(LOAD_I32)
   WASM_LOAD_STORE(LOAD_F32)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index ed52fe53bc609..527bb4c9fbea6 100644
--- a/llvm/lib/Target/WebAssembly/W

[clang] [llvm] [WebAssembly] Implement prototype f32.store_f16 instruction. (PR #91545)

2024-05-08 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-mc

@llvm/pr-subscribers-backend-webassembly

Author: Brendan Dahl (brendandahl)


Changes

Adds a builtin and intrinsic for the f32.store_f16 instruction.

The instruction stores an f32 value as an f16 memory. Specified at:
https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md

Note: the current spec has f32.store_f16 as opcode 0xFD0121, but this is 
incorrect and will be changed to 0xFC31 soon.

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


10 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsWebAssembly.def (+1) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+6) 
- (modified) clang/test/CodeGen/builtins-wasm.c (+6) 
- (modified) llvm/include/llvm/IR/IntrinsicsWebAssembly.td (+5) 
- (modified) llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h 
(+1) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (+8) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td (+4) 
- (modified) llvm/test/CodeGen/WebAssembly/half-precision.ll (+9) 
- (modified) llvm/test/CodeGen/WebAssembly/offset.ll (+27) 
- (modified) llvm/test/MC/WebAssembly/simd-encodings.s (+3) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index cf54f8f4422f8..41fadd10e9432 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -192,6 +192,7 @@ 
TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f"
 
 // Half-Precision (fp16)
 TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "nU", "half-precision")
 
 // Reference Types builtins
 // Some builtins are custom type-checked - see 't' as part of the third 
argument,
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e8a6bd050e17e..abb644d8eb506 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -21308,6 +21308,12 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_loadf16_f32);
 return Builder.CreateCall(Callee, {Addr});
   }
+  case WebAssembly::BI__builtin_wasm_storef16_f32: {
+Value *Val = EmitScalarExpr(E->getArg(0));
+Value *Addr = EmitScalarExpr(E->getArg(1));
+Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_storef16_f32);
+return Builder.CreateCall(Callee, {Val, Addr});
+  }
   case WebAssembly::BI__builtin_wasm_table_get: {
 assert(E->getArg(0)->getType()->isArrayType());
 Value *Table = EmitArrayToPointerDecay(E->getArg(0)).emitRawPointer(*this);
diff --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index ab1c6cd494ae5..bcb15969de1c5 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -807,6 +807,12 @@ float load_f16_f32(__fp16 *addr) {
   // WEBASSEMBLY: call float @llvm.wasm.loadf16.f32(ptr %{{.*}})
 }
 
+void store_f16_f32(float val, __fp16 *addr) {
+  return __builtin_wasm_storef16_f32(val, addr);
+  // WEBASSEMBLY: tail call void @llvm.wasm.storef16.f32(float %val, ptr 
%{{.*}})
+  // WEBASSEMBLY-NEXT: ret
+}
+
 __externref_t externref_null() {
   return __builtin_wasm_ref_null_extern();
   // WEBASSEMBLY: tail call ptr addrspace(10) @llvm.wasm.ref.null.extern()
diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td 
b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index f8142a8ca9e93..572d334ac9552 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -332,6 +332,11 @@ def int_wasm_loadf16_f32:
 [llvm_ptr_ty],
 [IntrReadMem, IntrArgMemOnly],
  "", [SDNPMemOperand]>;
+def int_wasm_storef16_f32:
+  Intrinsic<[],
+[llvm_float_ty, llvm_ptr_ty],
+[IntrWriteMem, IntrArgMemOnly],
+ "", [SDNPMemOperand]>;
 
 
 
//===--===//
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h 
b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
index d3b496ae59179..d4e9fb057c44d 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
@@ -207,6 +207,7 @@ inline unsigned GetDefaultP2AlignAny(unsigned Opc) {
   WASM_LOAD_STORE(LOAD_LANE_I16x8)
   WASM_LOAD_STORE(STORE_LANE_I16x8)
   WASM_LOAD_STORE(LOAD_F16_F32)
+  WASM_LOAD_STORE(STORE_F16_F32)
   return 1;
   WASM_LOAD_STORE(LOAD_I32)
   WASM_LOAD_STORE(LOAD_F32)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
index ed52fe53bc609..527bb4c9fbea6 100644

[clang] [llvm] [WebAssembly] Implement prototype f32.store_f16 instruction. (PR #91545)

2024-05-08 Thread Brendan Dahl via cfe-commits

https://github.com/brendandahl created 
https://github.com/llvm/llvm-project/pull/91545

Adds a builtin and intrinsic for the f32.store_f16 instruction.

The instruction stores an f32 value as an f16 memory. Specified at:
https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md

Note: the current spec has f32.store_f16 as opcode 0xFD0121, but this is 
incorrect and will be changed to 0xFC31 soon.

>From adcb77e15d09f466f217d754f6f80aeb729aadc4 Mon Sep 17 00:00:00 2001
From: Brendan Dahl 
Date: Wed, 8 May 2024 23:10:07 +
Subject: [PATCH] [WebAssembly] Implement prototype f32.store_f16 instruction.

Adds a builtin and intrinsic for the f32.store_f16 instruction.

The instruction stores an f32 value as an f16 memory.
Specified at:
https://github.com/WebAssembly/half-precision/blob/29a9b9462c9285d4ccc1a5dc39214ddfd1892658/proposals/half-precision/Overview.md

Note: the current spec has f32.store_f16 as opcode 0xFD0121, but this is 
incorrect
and will be changed to 0xFC31 soon.
---
 .../clang/Basic/BuiltinsWebAssembly.def   |  1 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  6 +
 clang/test/CodeGen/builtins-wasm.c|  6 +
 llvm/include/llvm/IR/IntrinsicsWebAssembly.td |  5 
 .../MCTargetDesc/WebAssemblyMCTargetDesc.h|  1 +
 .../WebAssembly/WebAssemblyISelLowering.cpp   |  8 ++
 .../WebAssembly/WebAssemblyInstrMemory.td |  4 +++
 .../CodeGen/WebAssembly/half-precision.ll |  9 +++
 llvm/test/CodeGen/WebAssembly/offset.ll   | 27 +++
 llvm/test/MC/WebAssembly/simd-encodings.s |  3 +++
 10 files changed, 70 insertions(+)

diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def 
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index cf54f8f4422f8..41fadd10e9432 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -192,6 +192,7 @@ 
TARGET_BUILTIN(__builtin_wasm_relaxed_dot_bf16x8_add_f32_f32x4, "V4fV8UsV8UsV4f"
 
 // Half-Precision (fp16)
 TARGET_BUILTIN(__builtin_wasm_loadf16_f32, "fh*", "nU", "half-precision")
+TARGET_BUILTIN(__builtin_wasm_storef16_f32, "vfh*", "nU", "half-precision")
 
 // Reference Types builtins
 // Some builtins are custom type-checked - see 't' as part of the third 
argument,
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e8a6bd050e17e..abb644d8eb506 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -21308,6 +21308,12 @@ Value 
*CodeGenFunction::EmitWebAssemblyBuiltinExpr(unsigned BuiltinID,
 Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_loadf16_f32);
 return Builder.CreateCall(Callee, {Addr});
   }
+  case WebAssembly::BI__builtin_wasm_storef16_f32: {
+Value *Val = EmitScalarExpr(E->getArg(0));
+Value *Addr = EmitScalarExpr(E->getArg(1));
+Function *Callee = CGM.getIntrinsic(Intrinsic::wasm_storef16_f32);
+return Builder.CreateCall(Callee, {Val, Addr});
+  }
   case WebAssembly::BI__builtin_wasm_table_get: {
 assert(E->getArg(0)->getType()->isArrayType());
 Value *Table = EmitArrayToPointerDecay(E->getArg(0)).emitRawPointer(*this);
diff --git a/clang/test/CodeGen/builtins-wasm.c 
b/clang/test/CodeGen/builtins-wasm.c
index ab1c6cd494ae5..bcb15969de1c5 100644
--- a/clang/test/CodeGen/builtins-wasm.c
+++ b/clang/test/CodeGen/builtins-wasm.c
@@ -807,6 +807,12 @@ float load_f16_f32(__fp16 *addr) {
   // WEBASSEMBLY: call float @llvm.wasm.loadf16.f32(ptr %{{.*}})
 }
 
+void store_f16_f32(float val, __fp16 *addr) {
+  return __builtin_wasm_storef16_f32(val, addr);
+  // WEBASSEMBLY: tail call void @llvm.wasm.storef16.f32(float %val, ptr 
%{{.*}})
+  // WEBASSEMBLY-NEXT: ret
+}
+
 __externref_t externref_null() {
   return __builtin_wasm_ref_null_extern();
   // WEBASSEMBLY: tail call ptr addrspace(10) @llvm.wasm.ref.null.extern()
diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td 
b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
index f8142a8ca9e93..572d334ac9552 100644
--- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
+++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td
@@ -332,6 +332,11 @@ def int_wasm_loadf16_f32:
 [llvm_ptr_ty],
 [IntrReadMem, IntrArgMemOnly],
  "", [SDNPMemOperand]>;
+def int_wasm_storef16_f32:
+  Intrinsic<[],
+[llvm_float_ty, llvm_ptr_ty],
+[IntrWriteMem, IntrArgMemOnly],
+ "", [SDNPMemOperand]>;
 
 
 
//===--===//
diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h 
b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
index d3b496ae59179..d4e9fb057c44d 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
@@ -207,6 +207,7 @@ inline unsigned GetDefaultP2

[clang] [llvm] [InstallAPI] Support mutually exclusive parse options (PR #90686)

2024-05-08 Thread Zixu Wang via cfe-commits

https://github.com/zixu-w approved this pull request.


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


[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-08 Thread via cfe-commits


@@ -494,6 +494,29 @@ def CC_AArch64_GHC : CallingConv<[
   CCIfType<[i64], CCAssignToReg<[X19, X20, X21, X22, X23, X24, X25, X26, X27, 
X28]>>
 ]>;
 
+let Entry = 1 in
+def CC_AArch64_Preserve_None : CallingConv<[
+// We only preserve:
+// - X18, which is used for the 'nest' parameter.
+// - X29, the frame pointer
+// - X30, the link register
+// All other registers can be used to pass arguments.
+// Non-volatile registers are used first, so functions may call
+// normal functions without saving and reloading arguments.
+CCIfType<[i32], CCAssignToReg<[W19, W20, W21, W22, W23,
+   W24, W25, W26, W27, W28,
+   W0, W1, W2, W3, W4, W5,
+   W6, W7, W8, W9, W10, W11,
+   W12, W13, W14, W15, W16, W17]>>,
+CCIfType<[i64], CCAssignToReg<[X19, X20, X21, X22, X23,
+   X24, X25, X26, X27, X28,
+   X0, X1, X2, X3, X4, X5,
+   X6, X7, X8, X9, X10, X11,

weiguozhi wrote:

X8 is used to pass SRet parameter in AArch64_Common, so it can not be used as a 
general argument register.

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


[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-08 Thread via cfe-commits

https://github.com/weiguozhi requested changes to this pull request.


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


[clang] [llvm] [AArch64] Support preserve_none calling convention (PR #91046)

2024-05-08 Thread via cfe-commits

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


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-08 Thread Helena Kotas via cfe-commits

hekota wrote:

Ping

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


[clang] [clang-format] Handle Java switch expressions (PR #91112)

2024-05-08 Thread via cfe-commits

https://github.com/mydeveloperday commented:

Looks good

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


[clang] [driver] Only check for unused plugin options (PR #91522)

2024-05-08 Thread Hubert Tong via cfe-commits


@@ -23,5 +23,5 @@
 
 // Plugins are only relevant for the -cc1 phase. No warning should be raised
 // when only using the assembler. See GH #88173.
-// RUN: %clang -c -fpass-plugin=bar.so -fplugin=bar.so -fplugin-arg-bar-option 
-Werror -x assembler %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-PLUGIN-ASM
-// CHECK-PLUGIN-ASM-NOT: argument unused during compilation
+// RUN: %clang -c -fpass-plugin=bar.so -fplugin=bar.so -fplugin-arg-bar-option 
-Wunused-command-line-argument -x assembler %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-PLUGIN-ASM
+// CHECK-PLUGIN-ASM-NOT: argument unused during compilation: 
'-f{{[a-z-]*-plugin[^']*}}'

hubert-reinterpretcast wrote:

Sorry for my mistake "offline"; we want to catch `-fplugin*` too:
```suggestion
// CHECK-PLUGIN-ASM-NOT: argument unused during compilation: 
'-f{{[a-z-]*plugin[^']*}}'
```

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


[clang] [Sema] Don't drop weak_import from a declaration that follows a declaration directly contained in a linkage-specification (PR #85886)

2024-05-08 Thread John McCall via cfe-commits

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


[clang] [Sema] Don't drop weak_import from a declaration that follows a declaration directly contained in a linkage-specification (PR #85886)

2024-05-08 Thread John McCall via cfe-commits

https://github.com/rjmccall commented:

I think you're right about the intended logic being to check for a definition, 
especially given the wording of the warning.  IIRC, we didn't have some of 
these high-level checks at the time.

With that said, I think you need to check if a definition exists at all and not 
just whether the last declaration is that definition.

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/91498

>From 60d2030216403c7cfa8272396497d31aed314288 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 8 May 2024 12:18:49 -0400
Subject: [PATCH 1/5] [Clang][Sema] Fix lookup of dependent operator= outside
 of complete-class contexts

---
 clang/lib/Sema/SemaLookup.cpp   | 28 +---
 clang/lib/Sema/SemaTemplate.cpp |  7 ++-
 2 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index e63da5875d2c..6bd5932212b9 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1269,19 +1269,19 @@ struct FindLocalExternScope {
 };
 } // end anonymous namespace
 
+static bool isDependentAssignmentOperator(DeclarationName Name,
+  DeclContext *LookupContext) {
+  auto *LookupRecord = dyn_cast_if_present(LookupContext);
+  return Name.getCXXOverloadedOperator() == OO_Equal && LookupRecord &&
+ !LookupRecord->isBeingDefined() && LookupRecord->isDependentContext();
+}
+
 bool Sema::CppLookupName(LookupResult &R, Scope *S) {
   assert(getLangOpts().CPlusPlus && "Can perform only C++ lookup");
 
   DeclarationName Name = R.getLookupName();
   Sema::LookupNameKind NameKind = R.getLookupKind();
 
-  // If this is the name of an implicitly-declared special member function,
-  // go through the scope stack to implicitly declare
-  if (isImplicitlyDeclaredMemberFunctionName(Name)) {
-for (Scope *PreS = S; PreS; PreS = PreS->getParent())
-  if (DeclContext *DC = PreS->getEntity())
-DeclareImplicitMemberFunctionsWithName(*this, Name, R.getNameLoc(), 
DC);
-  }
   // C++23 [temp.dep.general]p2:
   //   The component name of an unqualified-id is dependent if
   //   - it is a conversion-function-id whose conversion-type-id
@@ -1299,9 +1299,8 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
   if (isImplicitlyDeclaredMemberFunctionName(Name)) {
 for (Scope *PreS = S; PreS; PreS = PreS->getParent())
   if (DeclContext *DC = PreS->getEntity()) {
-if (DC->isDependentContext() && isa(DC) &&
-Name.getCXXOverloadedOperator() == OO_Equal &&
-!R.isTemplateNameLookup()) {
+if (!R.isTemplateNameLookup() &&
+isDependentAssignmentOperator(Name, DC)) {
   R.setNotFoundInCurrentInstantiation();
   return false;
 }
@@ -2472,8 +2471,6 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 }
   } QL(LookupCtx);
 
-  bool TemplateNameLookup = R.isTemplateNameLookup();
-  CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
   if (!InUnqualifiedLookup && !R.isForRedeclaration()) {
 // C++23 [temp.dep.type]p5:
 //   A qualified name is dependent if
@@ -2486,13 +2483,14 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 if (DeclarationName Name = R.getLookupName();
 (Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
  Name.getCXXNameType()->isDependentType()) ||
-(Name.getCXXOverloadedOperator() == OO_Equal && LookupRec &&
- LookupRec->isDependentContext() && !TemplateNameLookup)) {
+(!R.isTemplateNameLookup() &&
+ isDependentAssignmentOperator(Name, LookupCtx))) {
   R.setNotFoundInCurrentInstantiation();
   return false;
 }
   }
 
+  CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
   if (LookupDirect(*this, R, LookupCtx)) {
 R.resolveKind();
 if (LookupRec)
@@ -2604,7 +2602,7 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 //   template, and if the name is used as a template-name, the
 //   reference refers to the class template itself and not a
 //   specialization thereof, and is not ambiguous.
-if (TemplateNameLookup)
+if (R.isTemplateNameLookup())
   if (auto *TD = getAsTemplateNameDecl(ND))
 ND = TD;
 
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 7e57fa069672..480bc74c2001 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -726,7 +726,7 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
  const DeclarationNameInfo &NameInfo,
  bool isAddressOfOperand,
const TemplateArgumentListInfo *TemplateArgs) {
-  DeclContext *DC = getFunctionLevelDeclContext();
+  QualType ThisType = getCurrentThisType();
 
   // C++11 [expr.prim.general]p12:
   //   An id-expression that denotes a non-static data member or non-static
@@ -748,10 +748,7 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
 IsEnum = isa_and_nonnull(NNS->getAsType());
 
   if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum &&
-  isa(DC) &&
-  cast(DC)->isImplicitObjectMemberFunction()) {
-Q

[clang] [clang] Enable C++17 relaxed template template argument matching by default (PR #89807)

2024-05-08 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Here's a preprocessed file: 
> [repro.zip](https://github.com/llvm/llvm-project/files/15250584/repro.zip)
> 
> I tried to reduce, and got rid of most of the test code and some of the 
> stdexec code, but there's still a lot left. I hit the end of my timebox on 
> that. Maybe creduce can do better.

That crashes with released clang 18.1.4 as well, same stack trace it seems.
```
Homebrew clang version 18.1.4
Target: arm64-apple-darwin23.4.0
```

Is it possible you may have reduced into a different bug?
It's always helpful in that case to keep testing with known good compiler while 
reducing.

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


[clang] [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (PR #91534)

2024-05-08 Thread Krystian Stasiowski via cfe-commits


@@ -5485,20 +5485,40 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
   switch (TPOC) {
   case TPOC_Call:
 for (unsigned I = 0, N = Args2.size(); I != N; ++I)
-  ::MarkUsedTemplateParameters(S.Context, Args2[I], false,
-   TemplateParams->getDepth(),
-   UsedParameters);
+  ::MarkUsedTemplateParameters(S.Context, Args2[I], /*OnlyDeduced=*/false,
+   TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Conversion:
-::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(), false,
+::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(),
+ /*OnlyDeduced=*/false,
  TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Other:
-::MarkUsedTemplateParameters(S.Context, FD2->getType(), false,
- TemplateParams->getDepth(),
- UsedParameters);
+// We do not deduce template arguments from the exception specification
+// when determining the primary template of a function template
+// specialization or when taking the address of a function template.
+// Therefore, we do not mark template parameters in the exception
+// specification as used during partial ordering to prevent the following
+// from being ambiguous:
+//
+//   template
+//   void f(U) noexcept(noexcept(T())); // #1
+//
+//   template
+//   void f(T*) noexcept; // #2
+//
+//   template<>
+//   void f(int*) noexcept; // explicit specialization of #2
+//
+// Although there is no corresponding wording in the standard, this seems

sdkrystian wrote:

I'll open it tomorrow 

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


[clang] [Clang][HLSL] Add environment parameter to availability attribute (PR #89809)

2024-05-08 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/89809

>From 22b67d30ca087d6a912183039c87fd1790eedfe4 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Tue, 23 Apr 2024 00:49:28 -0700
Subject: [PATCH 1/6] Add environment parameter to clang availability attribute

---
 clang/include/clang/Basic/Attr.td |  33 +-
 clang/include/clang/Basic/AttrDocs.td |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|   5 +-
 clang/include/clang/Parse/Parser.h|   3 +
 clang/include/clang/Sema/ParsedAttr.h |  40 ---
 clang/include/clang/Sema/Sema.h   |   5 +-
 clang/lib/AST/DeclBase.cpp|  27 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  |  13 ++-
 clang/lib/Index/CommentToXML.cpp  |   3 +
 clang/lib/Parse/ParseDecl.cpp |  20 +++-
 clang/lib/Sema/SemaAPINotes.cpp   |   3 +-
 clang/lib/Sema/SemaAvailability.cpp   | 109 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  34 --
 15 files changed, 232 insertions(+), 69 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022d..1b07f4eb40809 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -956,7 +956,7 @@ def Availability : InheritableAttr {
   VersionArgument<"deprecated">, VersionArgument<"obsoleted">,
   BoolArgument<"unavailable">, StringArgument<"message">,
   BoolArgument<"strict">, StringArgument<"replacement">,
-  IntArgument<"priority">];
+  IntArgument<"priority">, IdentifierArgument<"environment">];
   let AdditionalMembers =
 [{static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
 return llvm::StringSwitch(Platform)
@@ -976,7 +976,7 @@ def Availability : InheritableAttr {
  .Case("xros", "visionOS")
  .Case("xros_app_extension", "visionOS (App Extension)")
  .Case("swift", "Swift")
- .Case("shadermodel", "HLSL ShaderModel")
+ .Case("shadermodel", "HLSL Shader Model")
  .Case("ohos", "OpenHarmony OS")
  .Default(llvm::StringRef());
 }
@@ -1016,7 +1016,34 @@ static llvm::StringRef 
canonicalizePlatformName(llvm::StringRef Platform) {
  .Case("visionos_app_extension", "xros_app_extension")
  .Case("ShaderModel", "shadermodel")
  .Default(Platform);
-} }];
+}
+static llvm::StringRef getPrettyEnviromentName(llvm::StringRef Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", "pixel shader")
+ .Case("vertex", "vertex shader")
+ .Case("geometry", "geometry shader")
+ .Case("hull", "hull shader")
+ .Case("domain", "domain shader")
+ .Case("compute", "compute shader")
+ .Case("mesh", "mesh shader")
+ .Case("amplification", "amplification shader")
+ .Case("library", "shader library")
+ .Default(Environment);
+}
+static llvm::Triple::EnvironmentType getEnvironmentType(llvm::StringRef 
Environment) {
+return llvm::StringSwitch(Environment)
+ .Case("pixel", llvm::Triple::Pixel)
+ .Case("vertex", llvm::Triple::Vertex)
+ .Case("geometry", llvm::Triple::Geometry)
+ .Case("hull", llvm::Triple::Hull)
+ .Case("domain", llvm::Triple::Domain)
+ .Case("compute", llvm::Triple::Compute)
+ .Case("mesh", llvm::Triple::Mesh)
+ .Case("amplification", llvm::Triple::Amplification)
+ .Case("library", llvm::Triple::Library)
+ .Default(llvm::Triple::UnknownEnvironment);
+}
+}];
   let HasCustomParsing = 1;
   let InheritEvenIfAlreadyPresent = 1;
   let Subjects = SubjectList<[Named]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index a0bbe5861c572..a81163df35ca8 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1593,6 +1593,8 @@ replacement=\ *string-literal*
   a warning about use of a deprecated declaration. The Fix-It will replace
   the deprecated declaration with the new declaration specified.
 
+// HEKOTA TODO add docs here
+
 Multiple availability attributes can be placed on a declaration, which may
 correspond to different platforms. For most platforms, the availability
 attribute with the platform corresponding to the target platform will be used;
diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 66405095d51de..631dc8880fcfc 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1103,6 +1103,8 @@ def e

[clang] [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (PR #91534)

2024-05-08 Thread Erich Keane via cfe-commits


@@ -5485,20 +5485,40 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
   switch (TPOC) {
   case TPOC_Call:
 for (unsigned I = 0, N = Args2.size(); I != N; ++I)
-  ::MarkUsedTemplateParameters(S.Context, Args2[I], false,
-   TemplateParams->getDepth(),
-   UsedParameters);
+  ::MarkUsedTemplateParameters(S.Context, Args2[I], /*OnlyDeduced=*/false,
+   TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Conversion:
-::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(), false,
+::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(),
+ /*OnlyDeduced=*/false,
  TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Other:
-::MarkUsedTemplateParameters(S.Context, FD2->getType(), false,
- TemplateParams->getDepth(),
- UsedParameters);
+// We do not deduce template arguments from the exception specification
+// when determining the primary template of a function template
+// specialization or when taking the address of a function template.
+// Therefore, we do not mark template parameters in the exception
+// specification as used during partial ordering to prevent the following
+// from being ambiguous:
+//
+//   template
+//   void f(U) noexcept(noexcept(T())); // #1
+//
+//   template
+//   void f(T*) noexcept; // #2
+//
+//   template<>
+//   void f(int*) noexcept; // explicit specialization of #2
+//
+// Although there is no corresponding wording in the standard, this seems

erichkeane wrote:

Please file a core issue here!  It would be great to get this fixed in CWG.  
@Endilll or @shafik  can help with that if you need it.  Also, put the CWG 
issue # in this comment once we have it.

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


[clang] [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (PR #91534)

2024-05-08 Thread Erich Keane via cfe-commits

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

This probably also needs a release note.

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


[clang] [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (PR #91534)

2024-05-08 Thread Erich Keane via cfe-commits

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Erich Keane via cfe-commits

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


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


[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-05-08 Thread Alex Voicu via cfe-commits


@@ -0,0 +1,111 @@
+// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -triple spirv64-amd-amdhsa -fsyntax-only -verify %s
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+kernel void test () {
+
+  int sgpr = 0, vgpr = 0, imm = 0;
+
+  // sgpr constraints
+  __asm__ ("s_mov_b32 %0, %1" : "=s" (sgpr) : "s" (imm) : );
+
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exec}" (imm) : );
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exe" (imm) : ); // 
expected-error {{invalid input constraint '{exe' in asm}}
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exec" (imm) : ); // 
expected-error {{invalid input constraint '{exec' in asm}}
+  __asm__ ("s_mov_b32 %0, %1" : "={s1}" (sgpr) : "{exec}a" (imm) : ); // 
expected-error {{invalid input constraint '{exec}a' in asm}}

AlexVlx wrote:

We can use non-flavoured SPIRV for that, no? Once the rest of the toolchain 
bits are in place, that'll work as well, and will offer neither ASM nor 
builtins. Surely, if there's actual some groundswell of opposition to ASM, 
folks will organically migrate. I'd say that's preferable to trying to force 
users to do anything, which seldom works well.

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


[clang] [llvm] [RISCV] Allow extra underscores in parseNormalizedArchString and parseArchString. (PR #91532)

2024-05-08 Thread Craig Topper via cfe-commits

topperc wrote:

> This one seems lazy, avoiding trailing or duplicate underscores is easy.

Yeah I don't really expect anyone to use it. It seemed like an unnecessary 
complication in our parsing code.

I was considering getting rid of split call before the loop and make the loop 
work directly on the raw string. Not having to care about extra underscores 
makes that easier.

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


[clang] [llvm] [RISCV] Allow extra underscores in parseNormalizedArchString and parseArchString. (PR #91532)

2024-05-08 Thread Craig Topper via cfe-commits

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

>From 6bccebc9415034680426921fcc84d404ff32245d Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Wed, 8 May 2024 13:40:31 -0700
Subject: [PATCH 1/2] [RISCV] Allow extra underscores in
 parseNormalizedArchString and parseArchString.

Allow double underscores and trailing underscores. gcc and binutils
allow extra underscores without error.
---
 clang/test/Driver/riscv-arch.c|  5 
 llvm/lib/TargetParser/RISCVISAInfo.cpp| 29 ++-
 .../TargetParser/RISCVISAInfoTest.cpp | 14 +
 3 files changed, 4 insertions(+), 44 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index ddf617bbb6237..418d8e91595de 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -308,11 +308,6 @@
 // RV32-SMINOR0: error: invalid arch name 'rv32ist2p0',
 // RV32-SMINOR0: unsupported standard supervisor-level extension 'st'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_ -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
-// RV32-XSEP: error: invalid arch name 'rv32ixabc_',
-// RV32-XSEP: extension name missing after separator '_'
-
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
 // RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp 
b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 96590745b2ebc..dda2eeb515666 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -452,7 +452,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   // and separated by _. Split by _ and then extract the name and version
   // information for each extension.
   SmallVector Split;
-  Arch.split(Split, '_');
+  Arch.split(Split, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
   for (StringRef Ext : Split) {
 StringRef Prefix, MinorVersionStr;
 std::tie(Prefix, MinorVersionStr) = Ext.rsplit('p');
@@ -500,24 +500,6 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
-static Error splitExtsByUnderscore(StringRef Exts,
-   std::vector &SplitExts) {
-  SmallVector Split;
-  if (Exts.empty())
-return Error::success();
-
-  Exts.split(Split, "_");
-
-  for (auto Ext : Split) {
-if (Ext.empty())
-  return createStringError(errc::invalid_argument,
-   "extension name missing after separator '_'");
-
-SplitExts.push_back(Ext.str());
-  }
-  return Error::success();
-}
-
 static Error processMultiLetterExtension(
 StringRef RawExt,
 MapVector SplitExts;
-  if (auto E = splitExtsByUnderscore(Exts, SplitExts))
-return std::move(E);
+  SmallVector SplitExts;
+  Exts.split(SplitExts, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
   for (auto &Ext : SplitExts) {
 StringRef CurrExt = Ext;
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp 
b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index f9e386a85fea8..95a03b2a90ec6 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -39,7 +39,7 @@ TEST(ParseNormalizedArchString, RejectsInvalidBaseISA) {
 
 TEST(ParseNormalizedArchString, RejectsMalformedInputs) {
   for (StringRef Input :
-   {"rv64i2p0_", "rv32i2p0__a2p0", "rv64e2p", "rv32i", "rv64ip1"}) {
+   {"rv64e2p", "rv32i", "rv64ip1"}) {
 EXPECT_EQ(
 toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
 "extension lacks version in expected format");
@@ -518,18 +518,6 @@ TEST(ParseArchString,
   "unsupported standard user-level extension 'zba1p0m'");
 }
 
-TEST(ParseArchString, RejectsDoubleOrTrailingUnderscore) {
-  EXPECT_EQ(
-  toString(RISCVISAInfo::parseArchString("rv64i__m", true).takeError()),
-  "extension name missing after separator '_'");
-
-  for (StringRef Input :
-   {"rv32ezicsr__zifencei", "rv32i_", "rv32izicsr_", "rv64im_"}) {
-EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-  "extension name missing after separator '_'");
-  }
-}
-
 TEST(ParseArchString, RejectsDuplicateExtensionNames) {
   EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ii", 
true).takeError()),
 "invalid standard user-level extension 'i'");

>From 25a67862c7d032ef57049642d0d30fd170e5d7f3 Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Wed, 8 May 2024 14:06:52 -0700
Subject: [PATCH 2/2] fixup! clang-format

---
 llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp 
b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 95a03b2a90ec6..dc2a8b44cf15d 100644
--- a/llvm/unittests/Targ

[clang] [llvm] [clang][SPIR-V] Add support for AMDGCN flavoured SPIRV (PR #89796)

2024-05-08 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/89796

>From 662f160418c704f45e57e751168903d774b74303 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Tue, 23 Apr 2024 17:41:25 +0100
Subject: [PATCH 1/7] Add initial support for AMDGCN flavoured SPIRV.

---
 clang/lib/Basic/Targets.cpp   |   6 +-
 clang/lib/Basic/Targets/SPIR.cpp  | 288 +
 clang/lib/Basic/Targets/SPIR.h|  51 +++
 clang/lib/CodeGen/CGBuiltin.cpp   |   7 +
 clang/test/CodeGen/target-data.c  |   4 +
 .../test/CodeGenCUDA/builtins-spirv-amdgcn.cu | 294 ++
 ...tins-unsafe-atomics-spirv-amdgcn-gfx90a.cu |  31 ++
 clang/test/CodeGenCUDA/long-double.cu |   4 +
 clang/test/CodeGenCUDA/spirv-amdgcn-bf16.cu   | 129 
 .../test/CodeGenCXX/spirv-amdgcn-float16.cpp  |  38 +++
 clang/test/CodeGenHIP/spirv-amdgcn-ballot.cpp |  27 ++
 .../spirv-amdgcn-dpp-const-fold.hip   |  46 +++
 clang/test/CodeGenHIP/spirv-amdgcn-half.hip   |  15 +
 .../predefined-macros-no-warnings.c   |   1 +
 clang/test/Preprocessor/predefined-macros.c   |  10 +
 ...in-spirv-amdgcn-atomic-inc-dec-failure.cpp |  25 ++
 .../Sema/inline-asm-validate-spirv-amdgcn.cl  | 111 +++
 clang/test/SemaCUDA/allow-int128.cu   |   3 +
 clang/test/SemaCUDA/amdgpu-f128.cu|   1 +
 clang/test/SemaCUDA/float16.cu|   1 +
 clang/test/SemaCUDA/fp16-arg-return.cu|   1 +
 .../test/SemaCUDA/spirv-amdgcn-atomic-ops.cu  |  86 +
 22 files changed, 1178 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCUDA/builtins-spirv-amdgcn.cu
 create mode 100644 
clang/test/CodeGenCUDA/builtins-unsafe-atomics-spirv-amdgcn-gfx90a.cu
 create mode 100644 clang/test/CodeGenCUDA/spirv-amdgcn-bf16.cu
 create mode 100644 clang/test/CodeGenCXX/spirv-amdgcn-float16.cpp
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-ballot.cpp
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-dpp-const-fold.hip
 create mode 100644 clang/test/CodeGenHIP/spirv-amdgcn-half.hip
 create mode 100644 
clang/test/Sema/builtin-spirv-amdgcn-atomic-inc-dec-failure.cpp
 create mode 100644 clang/test/Sema/inline-asm-validate-spirv-amdgcn.cl
 create mode 100644 clang/test/SemaCUDA/spirv-amdgcn-atomic-ops.cu

diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index e3283510c6aac..04a13e3385d1f 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -673,8 +673,12 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   }
   case llvm::Triple::spirv64: {
 if (os != llvm::Triple::UnknownOS ||
-Triple.getEnvironment() != llvm::Triple::UnknownEnvironment)
+Triple.getEnvironment() != llvm::Triple::UnknownEnvironment) {
+  if (os == llvm::Triple::OSType::AMDHSA)
+return std::make_unique(Triple, Opts);
+
   return nullptr;
+}
 return std::make_unique(Triple, Opts);
   }
   case llvm::Triple::wasm32:
diff --git a/clang/lib/Basic/Targets/SPIR.cpp b/clang/lib/Basic/Targets/SPIR.cpp
index dc920177d3a91..d7d232ac9484f 100644
--- a/clang/lib/Basic/Targets/SPIR.cpp
+++ b/clang/lib/Basic/Targets/SPIR.cpp
@@ -12,6 +12,8 @@
 
 #include "SPIR.h"
 #include "Targets.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/TargetBuiltins.h"
 
 using namespace clang;
 using namespace clang::targets;
@@ -54,3 +56,289 @@ void SPIRV64TargetInfo::getTargetDefines(const LangOptions 
&Opts,
   BaseSPIRVTargetInfo::getTargetDefines(Opts, Builder);
   DefineStd(Builder, "SPIRV64", Opts);
 }
+
+static constexpr Builtin::Info BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS)   
\
+  {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE)   
\
+  {#ID, TYPE, ATTRS, FEATURE, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#include "clang/Basic/BuiltinsAMDGPU.def"
+};
+
+namespace {
+const char *AMDGPUGCCRegNames[] = {
+  "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8",
+  "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17",
+  "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26",
+  "v27", "v28", "v29", "v30", "v31", "v32", "v33", "v34", "v35",
+  "v36", "v37", "v38", "v39", "v40", "v41", "v42", "v43", "v44",
+  "v45", "v46", "v47", "v48", "v49", "v50", "v51", "v52", "v53",
+  "v54", "v55", "v56", "v57", "v58", "v59", "v60", "v61", "v62",
+  "v63", "v64", "v65", "v66", "v67", "v68", "v69", "v70", "v71",
+  "v72", "v73", "v74", "v75", "v76", "v77", "v78", "v79", "v80",
+  "v81", "v82", "v83", "v84", "v85", "v86", "v87", "v88", "v89",
+  "v90", "v91", "v92", "v93", "v94", "v95", "v96", "v97", "v98",
+  "v99", "v100", "v101", "v102", "v103", "v104", "v105", "v106", "v107",
+  "v108", "v109", "v110", "v111", "v112", "v113", "v114", "v115", "v116",
+  "v117", "v118", "v119", "v120", "v121", "v122", "v123", "v124", "v125"

[clang] [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (PR #91534)

2024-05-08 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)


Changes

We do not deduce template arguments from the exception specification when 
determining the primary template of a function template specialization or when 
taking the address of a function template. Therefore, this patch changes 
`isAtLeastAsSpecializedAs` such that we do not mark template parameters in the 
exception specification as 'used' during partial ordering (per 
[[temp.deduct.partial] p12](http://eel.is/c++draft/temp.deduct.partial#12)) to prevent the following from being ambiguous:

```cpp
template
void f(U) noexcept(noexcept(T())); // #1

template
void f(T*) noexcept; // #2

template<>
void f(int*) noexcept; // currently ambiguous, selects #2 
with this patch applied 
```

Although there is no corresponding wording in the standard, this seems to be 
the intended behavior given the definition of _deduction substitution loci_ in 
[[temp.deduct.general] p7](http://eel.is/c++draft/temp.deduct.general#7) (and EDG does the same thing). 

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+28-8) 
- (added) 
clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp (+72) 


``diff
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index fe7e35d841510..c17c5838803a8 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5453,7 +5453,7 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
 // is used.
 if (DeduceTemplateArgumentsByTypeMatch(
 S, TemplateParams, FD2->getType(), FD1->getType(), Info, Deduced,
-TDF_None,
+TDF_AllowCompatibleFunctionType,
 /*PartialOrdering=*/true) != TemplateDeductionResult::Success)
   return false;
 break;
@@ -5485,20 +5485,40 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
   switch (TPOC) {
   case TPOC_Call:
 for (unsigned I = 0, N = Args2.size(); I != N; ++I)
-  ::MarkUsedTemplateParameters(S.Context, Args2[I], false,
-   TemplateParams->getDepth(),
-   UsedParameters);
+  ::MarkUsedTemplateParameters(S.Context, Args2[I], /*OnlyDeduced=*/false,
+   TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Conversion:
-::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(), false,
+::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(),
+ /*OnlyDeduced=*/false,
  TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Other:
-::MarkUsedTemplateParameters(S.Context, FD2->getType(), false,
- TemplateParams->getDepth(),
- UsedParameters);
+// We do not deduce template arguments from the exception specification
+// when determining the primary template of a function template
+// specialization or when taking the address of a function template.
+// Therefore, we do not mark template parameters in the exception
+// specification as used during partial ordering to prevent the following
+// from being ambiguous:
+//
+//   template
+//   void f(U) noexcept(noexcept(T())); // #1
+//
+//   template
+//   void f(T*) noexcept; // #2
+//
+//   template<>
+//   void f(int*) noexcept; // explicit specialization of #2
+//
+// Although there is no corresponding wording in the standard, this seems
+// to be the intended behavior given the definition of
+// 'deduction substitution loci' in [temp.deduct].
+::MarkUsedTemplateParameters(
+S.Context,
+S.Context.getFunctionTypeWithExceptionSpec(FD2->getType(), EST_None),
+/*OnlyDeduced=*/false, TemplateParams->getDepth(), UsedParameters);
 break;
   }
 
diff --git 
a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp 
b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp
new file mode 100644
index 0..cc1d4ecda2ecc
--- /dev/null
+++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template
+struct A { };
+
+constexpr A a;
+constexpr A b;
+
+constexpr int* x = nullptr;
+constexpr short* y = nullptr;
+
+namespace ExplicitArgs {
+  template
+  constexpr int f(U) noexcept(noexcept(T())) {
+return 0;
+  }
+
+  template
+  constexpr int f(T*) noexcept {
+return 1;
+  }
+
+  template<>
+  constexpr int f(int*) noexcept {
+return 2;
+  }
+
+  static_assert(f(1) == 0);
+  static_assert(f(y) == 1);
+  static_assert(f(x) == 2);

[clang] [Clang][Sema] Do not mark template parameters in the exception specification as used during partial ordering (PR #91534)

2024-05-08 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian created 
https://github.com/llvm/llvm-project/pull/91534

We do not deduce template arguments from the exception specification when 
determining the primary template of a function template specialization or when 
taking the address of a function template. Therefore, this patch changes 
`isAtLeastAsSpecializedAs` such that we do not mark template parameters in the 
exception specification as 'used' during partial ordering (per 
[[temp.deduct.partial] p12](http://eel.is/c++draft/temp.deduct.partial#12)) to 
prevent the following from being ambiguous:

```cpp
template
void f(U) noexcept(noexcept(T())); // #1

template
void f(T*) noexcept; // #2

template<>
void f(int*) noexcept; // currently ambiguous, selects #2 with this patch 
applied 
```

Although there is no corresponding wording in the standard, this seems to be 
the intended behavior given the definition of _deduction substitution loci_ in 
[[temp.deduct.general] p7](http://eel.is/c++draft/temp.deduct.general#7) (and 
EDG does the same thing). 

>From 0ef86c6bdf8fc89e771039a0e4bae88a8ebb2702 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 8 May 2024 08:43:23 -0400
Subject: [PATCH] [Clang][Sema] Do not mark template parameters in the
 exception specification as used during partial ordering

---
 clang/lib/Sema/SemaTemplateDeduction.cpp  | 36 +++---
 .../temp.deduct/temp.deduct.partial/p3.cpp| 72 +++
 2 files changed, 100 insertions(+), 8 deletions(-)
 create mode 100644 
clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp

diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index fe7e35d841510..c17c5838803a8 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -5453,7 +5453,7 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
 // is used.
 if (DeduceTemplateArgumentsByTypeMatch(
 S, TemplateParams, FD2->getType(), FD1->getType(), Info, Deduced,
-TDF_None,
+TDF_AllowCompatibleFunctionType,
 /*PartialOrdering=*/true) != TemplateDeductionResult::Success)
   return false;
 break;
@@ -5485,20 +5485,40 @@ static bool isAtLeastAsSpecializedAs(Sema &S, 
SourceLocation Loc,
   switch (TPOC) {
   case TPOC_Call:
 for (unsigned I = 0, N = Args2.size(); I != N; ++I)
-  ::MarkUsedTemplateParameters(S.Context, Args2[I], false,
-   TemplateParams->getDepth(),
-   UsedParameters);
+  ::MarkUsedTemplateParameters(S.Context, Args2[I], /*OnlyDeduced=*/false,
+   TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Conversion:
-::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(), false,
+::MarkUsedTemplateParameters(S.Context, Proto2->getReturnType(),
+ /*OnlyDeduced=*/false,
  TemplateParams->getDepth(), UsedParameters);
 break;
 
   case TPOC_Other:
-::MarkUsedTemplateParameters(S.Context, FD2->getType(), false,
- TemplateParams->getDepth(),
- UsedParameters);
+// We do not deduce template arguments from the exception specification
+// when determining the primary template of a function template
+// specialization or when taking the address of a function template.
+// Therefore, we do not mark template parameters in the exception
+// specification as used during partial ordering to prevent the following
+// from being ambiguous:
+//
+//   template
+//   void f(U) noexcept(noexcept(T())); // #1
+//
+//   template
+//   void f(T*) noexcept; // #2
+//
+//   template<>
+//   void f(int*) noexcept; // explicit specialization of #2
+//
+// Although there is no corresponding wording in the standard, this seems
+// to be the intended behavior given the definition of
+// 'deduction substitution loci' in [temp.deduct].
+::MarkUsedTemplateParameters(
+S.Context,
+S.Context.getFunctionTypeWithExceptionSpec(FD2->getType(), EST_None),
+/*OnlyDeduced=*/false, TemplateParams->getDepth(), UsedParameters);
 break;
   }
 
diff --git 
a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp 
b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp
new file mode 100644
index 0..cc1d4ecda2ecc
--- /dev/null
+++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p3.cpp
@@ -0,0 +1,72 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template
+struct A { };
+
+constexpr A a;
+constexpr A b;
+
+constexpr int* x = nullptr;
+constexpr short* y = nullptr;
+
+namespace ExplicitArgs {
+  template
+  constexpr int f(U) noexcept(noexcept(T())) {
+ret

[clang] [llvm] [RISCV] Allow extra underscores in parseNormalizedArchString and parseArchString. (PR #91532)

2024-05-08 Thread Jessica Clarke via cfe-commits

jrtc27 wrote:

This one seems lazy, avoiding trailing or duplicate underscores is easy.

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


[clang] [llvm] [RISCV] Allow extra underscores in parseNormalizedArchString and parseArchString. (PR #91532)

2024-05-08 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 e3938f4d71493673033f6190454e7e19d5411ea7 
6bccebc9415034680426921fcc84d404ff32245d -- clang/test/Driver/riscv-arch.c 
llvm/lib/TargetParser/RISCVISAInfo.cpp 
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp 
b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 95a03b2a90..dc2a8b44cf 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -38,8 +38,7 @@ TEST(ParseNormalizedArchString, RejectsInvalidBaseISA) {
 }
 
 TEST(ParseNormalizedArchString, RejectsMalformedInputs) {
-  for (StringRef Input :
-   {"rv64e2p", "rv32i", "rv64ip1"}) {
+  for (StringRef Input : {"rv64e2p", "rv32i", "rv64ip1"}) {
 EXPECT_EQ(
 toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
 "extension lacks version in expected format");

``




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


[clang] [llvm] [RISCV] Allow extra underscores in parseNormalizedArchString and parseArchString. (PR #91532)

2024-05-08 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang-driver

Author: Craig Topper (topperc)


Changes

Allow double underscores and trailing underscores. gcc and binutils allow extra 
underscores without error.

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


3 Files Affected:

- (modified) clang/test/Driver/riscv-arch.c (-5) 
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+3-26) 
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+1-13) 


``diff
diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index ddf617bbb6237..418d8e91595de 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -308,11 +308,6 @@
 // RV32-SMINOR0: error: invalid arch name 'rv32ist2p0',
 // RV32-SMINOR0: unsupported standard supervisor-level extension 'st'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_ -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
-// RV32-XSEP: error: invalid arch name 'rv32ixabc_',
-// RV32-XSEP: extension name missing after separator '_'
-
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
 // RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp 
b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 96590745b2ebc..dda2eeb515666 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -452,7 +452,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   // and separated by _. Split by _ and then extract the name and version
   // information for each extension.
   SmallVector Split;
-  Arch.split(Split, '_');
+  Arch.split(Split, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
   for (StringRef Ext : Split) {
 StringRef Prefix, MinorVersionStr;
 std::tie(Prefix, MinorVersionStr) = Ext.rsplit('p');
@@ -500,24 +500,6 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
-static Error splitExtsByUnderscore(StringRef Exts,
-   std::vector &SplitExts) {
-  SmallVector Split;
-  if (Exts.empty())
-return Error::success();
-
-  Exts.split(Split, "_");
-
-  for (auto Ext : Split) {
-if (Ext.empty())
-  return createStringError(errc::invalid_argument,
-   "extension name missing after separator '_'");
-
-SplitExts.push_back(Ext.str());
-  }
-  return Error::success();
-}
-
 static Error processMultiLetterExtension(
 StringRef RawExt,
 MapVector SplitExts;
-  if (auto E = splitExtsByUnderscore(Exts, SplitExts))
-return std::move(E);
+  SmallVector SplitExts;
+  Exts.split(SplitExts, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
   for (auto &Ext : SplitExts) {
 StringRef CurrExt = Ext;
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp 
b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index f9e386a85fea8..95a03b2a90ec6 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -39,7 +39,7 @@ TEST(ParseNormalizedArchString, RejectsInvalidBaseISA) {
 
 TEST(ParseNormalizedArchString, RejectsMalformedInputs) {
   for (StringRef Input :
-   {"rv64i2p0_", "rv32i2p0__a2p0", "rv64e2p", "rv32i", "rv64ip1"}) {
+   {"rv64e2p", "rv32i", "rv64ip1"}) {
 EXPECT_EQ(
 toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
 "extension lacks version in expected format");
@@ -518,18 +518,6 @@ TEST(ParseArchString,
   "unsupported standard user-level extension 'zba1p0m'");
 }
 
-TEST(ParseArchString, RejectsDoubleOrTrailingUnderscore) {
-  EXPECT_EQ(
-  toString(RISCVISAInfo::parseArchString("rv64i__m", true).takeError()),
-  "extension name missing after separator '_'");
-
-  for (StringRef Input :
-   {"rv32ezicsr__zifencei", "rv32i_", "rv32izicsr_", "rv64im_"}) {
-EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-  "extension name missing after separator '_'");
-  }
-}
-
 TEST(ParseArchString, RejectsDuplicateExtensionNames) {
   EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ii", 
true).takeError()),
 "invalid standard user-level extension 'i'");

``




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


[clang] [llvm] [RISCV] Allow extra underscores in parseNormalizedArchString and parseArchString. (PR #91532)

2024-05-08 Thread Craig Topper via cfe-commits

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

Allow double underscores and trailing underscores. gcc and binutils allow extra 
underscores without error.

>From 6bccebc9415034680426921fcc84d404ff32245d Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Wed, 8 May 2024 13:40:31 -0700
Subject: [PATCH] [RISCV] Allow extra underscores in parseNormalizedArchString
 and parseArchString.

Allow double underscores and trailing underscores. gcc and binutils
allow extra underscores without error.
---
 clang/test/Driver/riscv-arch.c|  5 
 llvm/lib/TargetParser/RISCVISAInfo.cpp| 29 ++-
 .../TargetParser/RISCVISAInfoTest.cpp | 14 +
 3 files changed, 4 insertions(+), 44 deletions(-)

diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index ddf617bbb6237..418d8e91595de 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -308,11 +308,6 @@
 // RV32-SMINOR0: error: invalid arch name 'rv32ist2p0',
 // RV32-SMINOR0: unsupported standard supervisor-level extension 'st'
 
-// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_ -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-XSEP %s
-// RV32-XSEP: error: invalid arch name 'rv32ixabc_',
-// RV32-XSEP: extension name missing after separator '_'
-
 // RUN: not %clang --target=riscv32-unknown-elf -march=rv32ixabc_a -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-PREFIX %s
 // RV32-PREFIX: error: invalid arch name 'rv32ixabc_a',
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp 
b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 96590745b2ebc..dda2eeb515666 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -452,7 +452,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   // and separated by _. Split by _ and then extract the name and version
   // information for each extension.
   SmallVector Split;
-  Arch.split(Split, '_');
+  Arch.split(Split, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
   for (StringRef Ext : Split) {
 StringRef Prefix, MinorVersionStr;
 std::tie(Prefix, MinorVersionStr) = Ext.rsplit('p');
@@ -500,24 +500,6 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) {
   return std::move(ISAInfo);
 }
 
-static Error splitExtsByUnderscore(StringRef Exts,
-   std::vector &SplitExts) {
-  SmallVector Split;
-  if (Exts.empty())
-return Error::success();
-
-  Exts.split(Split, "_");
-
-  for (auto Ext : Split) {
-if (Ext.empty())
-  return createStringError(errc::invalid_argument,
-   "extension name missing after separator '_'");
-
-SplitExts.push_back(Ext.str());
-  }
-  return Error::success();
-}
-
 static Error processMultiLetterExtension(
 StringRef RawExt,
 MapVector SplitExts;
-  if (auto E = splitExtsByUnderscore(Exts, SplitExts))
-return std::move(E);
+  SmallVector SplitExts;
+  Exts.split(SplitExts, '_', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
 
   for (auto &Ext : SplitExts) {
 StringRef CurrExt = Ext;
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp 
b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index f9e386a85fea8..95a03b2a90ec6 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -39,7 +39,7 @@ TEST(ParseNormalizedArchString, RejectsInvalidBaseISA) {
 
 TEST(ParseNormalizedArchString, RejectsMalformedInputs) {
   for (StringRef Input :
-   {"rv64i2p0_", "rv32i2p0__a2p0", "rv64e2p", "rv32i", "rv64ip1"}) {
+   {"rv64e2p", "rv32i", "rv64ip1"}) {
 EXPECT_EQ(
 toString(RISCVISAInfo::parseNormalizedArchString(Input).takeError()),
 "extension lacks version in expected format");
@@ -518,18 +518,6 @@ TEST(ParseArchString,
   "unsupported standard user-level extension 'zba1p0m'");
 }
 
-TEST(ParseArchString, RejectsDoubleOrTrailingUnderscore) {
-  EXPECT_EQ(
-  toString(RISCVISAInfo::parseArchString("rv64i__m", true).takeError()),
-  "extension name missing after separator '_'");
-
-  for (StringRef Input :
-   {"rv32ezicsr__zifencei", "rv32i_", "rv32izicsr_", "rv64im_"}) {
-EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
-  "extension name missing after separator '_'");
-  }
-}
-
 TEST(ParseArchString, RejectsDuplicateExtensionNames) {
   EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64ii", 
true).takeError()),
 "invalid standard user-level extension 'i'");

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


[clang] [analyzer] MallocChecker: Recognize std::atomics in smart pointer suppression. (PR #90918)

2024-05-08 Thread Gábor Horváth via cfe-commits


@@ -3479,13 +3479,24 @@ PathDiagnosticPieceRef 
MallocBugVisitor::VisitNode(const ExplodedNode *N,
   // original reference count is positive, we should not report use-after-frees
   // on objects deleted in such destructors. This can probably be improved
   // through better shared pointer modeling.
-  if (ReleaseDestructorLC) {
+  if (ReleaseDestructorLC && (ReleaseDestructorLC == CurrentLC ||
+  ReleaseDestructorLC->isParentOf(CurrentLC))) {
 if (const auto *AE = dyn_cast(S)) {
+  // Check for manual use of atomic builtins.
   AtomicExpr::AtomicOp Op = AE->getOp();
   if (Op == AtomicExpr::AO__c11_atomic_fetch_add ||
   Op == AtomicExpr::AO__c11_atomic_fetch_sub) {
-if (ReleaseDestructorLC == CurrentLC ||
-ReleaseDestructorLC->isParentOf(CurrentLC)) {
+BR.markInvalid(getTag(), S);
+  }
+} else if (const auto *CE = dyn_cast(S)) {
+  // Check for `std::atomic` and such. This covers both regular method 
calls
+  // and operator calls.
+  if (const auto *MD =
+  dyn_cast_or_null(CE->getDirectCallee())) {
+const CXXRecordDecl *RD = MD->getParent();
+// A bit wobbly with ".contains()" because it may be like
+// "__atomic_base" or something.
+if (StringRef(RD->getNameAsString()).contains("atomic")) {

Xazax-hun wrote:

> Though, I'm very open to changing my mind about this :)

I do not insist :) I am OK with the code as is. 

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


[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

2024-05-08 Thread via cfe-commits

llvmbot wrote:




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

Author: Donát Nagy (NagyDonat)


Changes

There are many environments where `errno` is a macro that expands to something 
like `(*__errno())` (different standard library implementations use different 
names instead of "__errno").

In these environments the ErrnoModeling checker creates a symbolic region which 
will be used to represent the return value of this "get the location of errno" 
function.

Previously this symbol was only created when the checker was able to find the 
declaration of the "get the location of errno" function; but this commit 
eliminates the complex logic that was responsible for this and always creates 
the symbolic region when `errno` is not available as a "regular" global 
variable.

This significantly simplifies a code and only introduces a minimal performance 
reduction (one extra symbol) in the unlikely case when `errno` is not declared 
(neither as a variable nor as a function), but the `ErrnoModeling` checker is 
enabled.

In addition to this simplification, this commit specifies that the 
`CallDescription`s for the "get the location of errno" functions are matched in 
`CDM::CLibrary` mode. (This was my original goal, but I was sidetracked by 
resolving a FIXME above the `CallDescriptionSet` in `ErrnoModeling.cpp`.)

This change is very close to being NFC, but it fixes weird corner cases like 
the handling of a C++ method that happens to be named "__errno()" (previously 
it could've been recognized as an errno location getter function).

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


4 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp (+1-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp (+40-87) 
- (modified) clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.h (+3-6) 
- (modified) clang/test/Analysis/memory-model.cpp (+9-9) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
index 18e718e085536..72fd6781a7561 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
@@ -205,7 +205,7 @@ void ErrnoChecker::checkPreCall(const CallEvent &Call,
   // Probably 'strerror'?
   if (CallF->isExternC() && CallF->isGlobal() &&
   C.getSourceManager().isInSystemHeader(CallF->getLocation()) &&
-  !isErrno(CallF)) {
+  !isErrnoLocationCall(Call)) {
 if (getErrnoState(C.getState()) == MustBeChecked) {
   std::optional ErrnoLoc = getErrnoLoc(C.getState());
   assert(ErrnoLoc && "ErrnoLoc should exist if an errno state is set.");
diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
index 1b34ea0e056e5..0612cd4c87248 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
@@ -39,10 +39,15 @@ namespace {
 // Name of the "errno" variable.
 // FIXME: Is there a system where it is not called "errno" but is a variable?
 const char *ErrnoVarName = "errno";
+
 // Names of functions that return a location of the "errno" value.
 // FIXME: Are there other similar function names?
-const char *ErrnoLocationFuncNames[] = {"__errno_location", "___errno",
-"__errno", "_errno", "__error"};
+CallDescriptionSet ErrnoLocationCalls{
+{CDM::SimpleFunc, {"__errno_location"}, 0, 0},
+{CDM::SimpleFunc, {"___errno"}, 0, 0},
+{CDM::SimpleFunc, {"__errno"}, 0, 0},
+{CDM::SimpleFunc, {"_errno"}, 0, 0},
+{CDM::SimpleFunc, {"__error"}, 0, 0}};
 
 class ErrnoModeling
 : public Checker, check::BeginFunction,
@@ -54,16 +59,10 @@ class ErrnoModeling
   void checkLiveSymbols(ProgramStateRef State, SymbolReaper &SR) const;
   bool evalCall(const CallEvent &Call, CheckerContext &C) const;
 
-  // The declaration of an "errno" variable or "errno location" function.
-  mutable const Decl *ErrnoDecl = nullptr;
-
 private:
-  // FIXME: Names from `ErrnoLocationFuncNames` are used to build this set.
-  CallDescriptionSet ErrnoLocationCalls{{{"__errno_location"}, 0, 0},
-{{"___errno"}, 0, 0},
-{{"__errno"}, 0, 0},
-{{"_errno"}, 0, 0},
-{{"__error"}, 0, 0}};
+  // The declaration of an "errno" variable on systems where errno is
+  // represented by a variable (and not a function that queries its location).
+  mutable const Decl *ErrnoDecl = nullptr;
 };
 
 } // namespace
@@ -74,9 +73,13 @@ REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoRegion, const 
MemRegion *)
 
 REGISTER_TRAIT_WITH_PROGRAMSTATE(ErrnoState, errno_modeling::ErrnoCheckState)
 
-/// Search for a variable called "errno" in the AST.
-/// Return nullptr if not found.
-static const VarDecl *getErrnoVar(ASTContext &ACtx) {
+void E

[clang] [analyzer] Refactor recognition of the errno getter functions (PR #91531)

2024-05-08 Thread Donát Nagy via cfe-commits

https://github.com/NagyDonat created 
https://github.com/llvm/llvm-project/pull/91531

There are many environments where `errno` is a macro that expands to something 
like `(*__errno())` (different standard library implementations use different 
names instead of "__errno").

In these environments the ErrnoModeling checker creates a symbolic region which 
will be used to represent the return value of this "get the location of errno" 
function.

Previously this symbol was only created when the checker was able to find the 
declaration of the "get the location of errno" function; but this commit 
eliminates the complex logic that was responsible for this and always creates 
the symbolic region when `errno` is not available as a "regular" global 
variable.

This significantly simplifies a code and only introduces a minimal performance 
reduction (one extra symbol) in the unlikely case when `errno` is not declared 
(neither as a variable nor as a function), but the `ErrnoModeling` checker is 
enabled.

In addition to this simplification, this commit specifies that the 
`CallDescription`s for the "get the location of errno" functions are matched in 
`CDM::CLibrary` mode. (This was my original goal, but I was sidetracked by 
resolving a FIXME above the `CallDescriptionSet` in `ErrnoModeling.cpp`.)

This change is very close to being NFC, but it fixes weird corner cases like 
the handling of a C++ method that happens to be named "__errno()" (previously 
it could've been recognized as an errno location getter function).

From 07dc4dd5c60c8a04637cce686b379e195deb5b67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Don=C3=A1t=20Nagy?= 
Date: Wed, 8 May 2024 20:01:57 +0200
Subject: [PATCH] [analyzer] Refactor recognition of the errno getter functions

There are many environments where `errno` is a macro that expands to
something like `(*__errno())` (different standard library
implementations use different names instead of "__errno").

In these environments the ErrnoModeling checker creates a symbolic
region which will be used to represent the return value of this "get the
location of errno" function.

Previously this symbol was only created when the checker was able to
find the declaration of the "get the location of errno" function; but
this commit eliminates the complex logic that was responsible for this
and always creates the symbolic region when `errno` is not available as
a "regular" global variable.

This significantly simplifies a code and only introduces a minimal
performance reduction (one extra symbol) in the unlikely case when
`errno` is not declared (neither as a variable nor as a function), but
the `ErrnoModeling` checker is enabled.

In addition to this simplification, this commit specifies that the
`CallDescription`s for the "get the location of errno" functions are
matched in `CDM::CLibrary` mode. (This was my original goal, but I was
sidetracked by resolving a FIXME above the `CallDescriptionSet` in
`ErrnoModeling.cpp`.)

This change is very close to being NFC, but it fixes weird corner
cases like the handling of a C++ method that happens to be named
"__errno()" (previously it could've been recognized as an errno
location getter function).
---
 .../StaticAnalyzer/Checkers/ErrnoChecker.cpp  |   2 +-
 .../StaticAnalyzer/Checkers/ErrnoModeling.cpp | 127 ++
 .../StaticAnalyzer/Checkers/ErrnoModeling.h   |   9 +-
 clang/test/Analysis/memory-model.cpp  |  18 +--
 4 files changed, 53 insertions(+), 103 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
index 18e718e085536..72fd6781a7561 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoChecker.cpp
@@ -205,7 +205,7 @@ void ErrnoChecker::checkPreCall(const CallEvent &Call,
   // Probably 'strerror'?
   if (CallF->isExternC() && CallF->isGlobal() &&
   C.getSourceManager().isInSystemHeader(CallF->getLocation()) &&
-  !isErrno(CallF)) {
+  !isErrnoLocationCall(Call)) {
 if (getErrnoState(C.getState()) == MustBeChecked) {
   std::optional ErrnoLoc = getErrnoLoc(C.getState());
   assert(ErrnoLoc && "ErrnoLoc should exist if an errno state is set.");
diff --git a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp 
b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
index 1b34ea0e056e5..0612cd4c87248 100644
--- a/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/ErrnoModeling.cpp
@@ -39,10 +39,15 @@ namespace {
 // Name of the "errno" variable.
 // FIXME: Is there a system where it is not called "errno" but is a variable?
 const char *ErrnoVarName = "errno";
+
 // Names of functions that return a location of the "errno" value.
 // FIXME: Are there other similar function names?
-const char *ErrnoLocationFuncNames[] = {"__errno_location", "___errno",
-"__errno", "_errno", "__error"};
+CallDescriptionSet E

[clang] [compiler-rt] PREVIEW: Introduce realtime sanitizer backend (PR #91529)

2024-05-08 Thread Chris Apple via cfe-commits

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


[clang] [analyzer] Support determining origins in a conditional operator in WebKit checkers. (PR #91143)

2024-05-08 Thread Artem Dergachev via cfe-commits

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

Aha ok this aligns with my understanding. LGTM!

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


[clang] [analyzer] Support determining origins in a conditional operator in WebKit checkers. (PR #91143)

2024-05-08 Thread Artem Dergachev via cfe-commits


@@ -27,12 +28,18 @@ tryToFindPtrOrigin(const Expr *E, bool 
StopAtFirstRefCountedObj) {
   E = tempExpr->getSubExpr();
   continue;
 }
+if (auto *Expr = dyn_cast(E)) {
+  return tryToFindPtrOrigin(Expr->getTrueExpr(), StopAtFirstRefCountedObj,
+callback) &&
+ tryToFindPtrOrigin(Expr->getFalseExpr(), StopAtFirstRefCountedObj,

haoNoQ wrote:

Aha makes sense then!

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


[clang] [analyzer] Support determining origins in a conditional operator in WebKit checkers. (PR #91143)

2024-05-08 Thread Artem Dergachev via cfe-commits

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/91498

>From 60d2030216403c7cfa8272396497d31aed314288 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 8 May 2024 12:18:49 -0400
Subject: [PATCH 1/5] [Clang][Sema] Fix lookup of dependent operator= outside
 of complete-class contexts

---
 clang/lib/Sema/SemaLookup.cpp   | 28 +---
 clang/lib/Sema/SemaTemplate.cpp |  7 ++-
 2 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index e63da5875d2c9..6bd5932212b92 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1269,19 +1269,19 @@ struct FindLocalExternScope {
 };
 } // end anonymous namespace
 
+static bool isDependentAssignmentOperator(DeclarationName Name,
+  DeclContext *LookupContext) {
+  auto *LookupRecord = dyn_cast_if_present(LookupContext);
+  return Name.getCXXOverloadedOperator() == OO_Equal && LookupRecord &&
+ !LookupRecord->isBeingDefined() && LookupRecord->isDependentContext();
+}
+
 bool Sema::CppLookupName(LookupResult &R, Scope *S) {
   assert(getLangOpts().CPlusPlus && "Can perform only C++ lookup");
 
   DeclarationName Name = R.getLookupName();
   Sema::LookupNameKind NameKind = R.getLookupKind();
 
-  // If this is the name of an implicitly-declared special member function,
-  // go through the scope stack to implicitly declare
-  if (isImplicitlyDeclaredMemberFunctionName(Name)) {
-for (Scope *PreS = S; PreS; PreS = PreS->getParent())
-  if (DeclContext *DC = PreS->getEntity())
-DeclareImplicitMemberFunctionsWithName(*this, Name, R.getNameLoc(), 
DC);
-  }
   // C++23 [temp.dep.general]p2:
   //   The component name of an unqualified-id is dependent if
   //   - it is a conversion-function-id whose conversion-type-id
@@ -1299,9 +1299,8 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
   if (isImplicitlyDeclaredMemberFunctionName(Name)) {
 for (Scope *PreS = S; PreS; PreS = PreS->getParent())
   if (DeclContext *DC = PreS->getEntity()) {
-if (DC->isDependentContext() && isa(DC) &&
-Name.getCXXOverloadedOperator() == OO_Equal &&
-!R.isTemplateNameLookup()) {
+if (!R.isTemplateNameLookup() &&
+isDependentAssignmentOperator(Name, DC)) {
   R.setNotFoundInCurrentInstantiation();
   return false;
 }
@@ -2472,8 +2471,6 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 }
   } QL(LookupCtx);
 
-  bool TemplateNameLookup = R.isTemplateNameLookup();
-  CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
   if (!InUnqualifiedLookup && !R.isForRedeclaration()) {
 // C++23 [temp.dep.type]p5:
 //   A qualified name is dependent if
@@ -2486,13 +2483,14 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 if (DeclarationName Name = R.getLookupName();
 (Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
  Name.getCXXNameType()->isDependentType()) ||
-(Name.getCXXOverloadedOperator() == OO_Equal && LookupRec &&
- LookupRec->isDependentContext() && !TemplateNameLookup)) {
+(!R.isTemplateNameLookup() &&
+ isDependentAssignmentOperator(Name, LookupCtx))) {
   R.setNotFoundInCurrentInstantiation();
   return false;
 }
   }
 
+  CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
   if (LookupDirect(*this, R, LookupCtx)) {
 R.resolveKind();
 if (LookupRec)
@@ -2604,7 +2602,7 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 //   template, and if the name is used as a template-name, the
 //   reference refers to the class template itself and not a
 //   specialization thereof, and is not ambiguous.
-if (TemplateNameLookup)
+if (R.isTemplateNameLookup())
   if (auto *TD = getAsTemplateNameDecl(ND))
 ND = TD;
 
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 7e57fa0696725..480bc74c2001a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -726,7 +726,7 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
  const DeclarationNameInfo &NameInfo,
  bool isAddressOfOperand,
const TemplateArgumentListInfo *TemplateArgs) {
-  DeclContext *DC = getFunctionLevelDeclContext();
+  QualType ThisType = getCurrentThisType();
 
   // C++11 [expr.prim.general]p12:
   //   An id-expression that denotes a non-static data member or non-static
@@ -748,10 +748,7 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
 IsEnum = isa_and_nonnull(NNS->getAsType());
 
   if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum &&
-  isa(DC) &&
-  cast(DC)->isImplicitObjectMemberFunction()) {
- 

[clang] [compiler-rt] PREVIEW: Introduce realtime sanitizer backend (PR #91529)

2024-05-08 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: Chris Apple (cjappl)


Changes



This introduces a nice self contained piece

All interceptors
All infrastructure "boilerplate" cmake
All unit tests (no lit tests)
Minimal meddling in clang, just to get the tests running

Unit tests for this RUN which I think is what makes this a great chunk.


---

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


30 Files Affected:

- (modified) clang/include/clang/Basic/Sanitizers.def (+3) 
- (modified) clang/include/clang/Driver/SanitizerArgs.h (+1) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+6) 
- (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+8) 
- (modified) clang/lib/Driver/ToolChains/Linux.cpp (+1) 
- (modified) clang/runtime/CMakeLists.txt (+1) 
- (modified) compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake (+3) 
- (modified) compiler-rt/cmake/config-ix.cmake (+11-1) 
- (added) compiler-rt/lib/radsan/CMakeLists.txt (+92) 
- (added) compiler-rt/lib/radsan/radsan.cpp (+38) 
- (added) compiler-rt/lib/radsan/radsan.h (+76) 
- (added) compiler-rt/lib/radsan/radsan_context.cpp (+82) 
- (added) compiler-rt/lib/radsan/radsan_context.h (+38) 
- (added) compiler-rt/lib/radsan/radsan_interceptors.cpp (+412) 
- (added) compiler-rt/lib/radsan/radsan_interceptors.h (+15) 
- (added) compiler-rt/lib/radsan/radsan_preinit.cpp (+23) 
- (added) compiler-rt/lib/radsan/radsan_stack.cpp (+52) 
- (added) compiler-rt/lib/radsan/radsan_stack.h (+15) 
- (added) compiler-rt/lib/radsan/tests/CMakeLists.txt (+103) 
- (added) compiler-rt/lib/radsan/tests/radsan_test.cpp (+203) 
- (added) compiler-rt/lib/radsan/tests/radsan_test_context.cpp (+69) 
- (added) compiler-rt/lib/radsan/tests/radsan_test_interceptors.cpp (+454) 
- (added) compiler-rt/lib/radsan/tests/radsan_test_main.cpp (+17) 
- (added) compiler-rt/lib/radsan/tests/radsan_test_utilities.h (+49) 
- (added) compiler-rt/test/radsan/CMakeLists.txt (+47) 
- (added) compiler-rt/test/radsan/Unit/lit.site.cfg.py.in (+25) 
- (added) compiler-rt/test/radsan/lit.cfg.py (+69) 
- (added) compiler-rt/test/radsan/lit.site.cfg.py.in (+17) 
- (modified) compiler-rt/test/sanitizer_common/CMakeLists.txt (+1-1) 
- (modified) compiler-rt/test/sanitizer_common/lit.common.cfg.py (+3) 


``diff
diff --git a/clang/include/clang/Basic/Sanitizers.def 
b/clang/include/clang/Basic/Sanitizers.def
index b228ffd07ee74..ffb23974fe371 100644
--- a/clang/include/clang/Basic/Sanitizers.def
+++ b/clang/include/clang/Basic/Sanitizers.def
@@ -37,6 +37,9 @@
 #endif
 
 
+// RealtimeSanitizer
+SANITIZER("realtime", Realtime)
+
 // AddressSanitizer
 SANITIZER("address", Address)
 
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 07070ec4fc065..dd7c128232772 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -79,6 +79,7 @@ class SanitizerArgs {
   bool needsStableAbi() const { return StableABI; }
 
   bool needsMemProfRt() const { return NeedsMemProfRt; }
+  bool needsRadsanRt() const { return Sanitizers.has(SanitizerKind::Realtime); 
}
   bool needsAsanRt() const { return Sanitizers.has(SanitizerKind::Address); }
   bool needsHwasanRt() const {
 return Sanitizers.has(SanitizerKind::HWAddress);
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 6796b43a15502..6508c4ca690b5 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1357,6 +1357,8 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
   if (!Args.hasArg(options::OPT_shared))
 HelperStaticRuntimes.push_back("hwasan-preinit");
 }
+if (SanArgs.needsRadsanRt() && SanArgs.linkRuntimes())
+  SharedRuntimes.push_back("radsan");
   }
 
   // The stats_client library is also statically linked into DSOs.
@@ -1382,6 +1384,10 @@ collectSanitizerRuntimes(const ToolChain &TC, const 
ArgList &Args,
   StaticRuntimes.push_back("asan_cxx");
   }
 
+  if (!SanArgs.needsSharedRt() && SanArgs.needsRadsanRt() && 
SanArgs.linkRuntimes()) {
+StaticRuntimes.push_back("radsan");
+  }
+
   if (!SanArgs.needsSharedRt() && SanArgs.needsMemProfRt()) {
 StaticRuntimes.push_back("memprof");
 if (SanArgs.linkCXXRuntimes())
diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index caf6c4a444fdc..cb96f9992ab7f 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1487,6 +1487,8 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 const char *sanitizer = nullptr;
 if (Sanitize.needsUbsanRt()) {
   sanitizer = "UndefinedBehaviorSanitizer";
+} else if (Sanitize.needsRadsanRt()) {
+  sanitizer = "RealtimeSanitizer";
 } else if (Sanitize.needs

[clang] [compiler-rt] PREVIEW: Introduce realtime sanitizer backend (PR #91529)

2024-05-08 Thread Chris Apple via cfe-commits

cjappl wrote:

Sorry, premature!!

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Allow trivial operator++ (PR #91102)

2024-05-08 Thread Artem Dergachev via cfe-commits

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


[clang] [compiler-rt] PREVIEW: Introduce realtime sanitizer backend (PR #91529)

2024-05-08 Thread Chris Apple via cfe-commits

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Allow trivial operator++ (PR #91102)

2024-05-08 Thread Artem Dergachev via cfe-commits

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

LGTM now thanks!

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Allow trivial operator++ (PR #91102)

2024-05-08 Thread Artem Dergachev via cfe-commits

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Allow trivial operator++ (PR #91102)

2024-05-08 Thread Artem Dergachev via cfe-commits


@@ -309,21 +309,8 @@ class TrivialFunctionAnalysisVisitor
   bool VisitDefaultStmt(const DefaultStmt *DS) { return VisitChildren(DS); }
 
   bool VisitUnaryOperator(const UnaryOperator *UO) {
-// Operator '*' and '!' are allowed as long as the operand is trivial.
-auto op = UO->getOpcode();
-if (op == UO_Deref || op == UO_AddrOf || op == UO_LNot || op == UO_Not)
-  return Visit(UO->getSubExpr());
-
-if (UO->isIncrementOp() || UO->isDecrementOp()) {
-  // Allow increment or decrement of a POD type.
-  if (auto *RefExpr = dyn_cast(UO->getSubExpr())) {
-if (auto *Decl = dyn_cast(RefExpr->getDecl()))
-  return Decl->isLocalVarDeclOrParm() &&
- Decl->getType().isPODType(Decl->getASTContext());
-  }
-}
-// Other operators are non-trivial.
-return false;
+// Unary operators are trivial if its operand is trivial.
+return Visit(UO->getSubExpr());

haoNoQ wrote:

When blanket-approving all operators, it's probably a good idea to go through 
the current list to see if any exceptions need  to be made. Eg. for unary 
operators it's 
https://github.com/llvm/llvm-project/blob/llvmorg-18-init/clang/include/clang/AST/OperationKinds.def#L417
 and binary operators are just above that. But I don't immediately see anything 
problematic in that list. (Is `co_await` blessed?)

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


[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

2024-05-08 Thread Justin Cady via cfe-commits


@@ -578,6 +579,13 @@ llvm::Regex 
*ClangTidyDiagnosticConsumer::getHeaderFilter() {
   return HeaderFilter.get();
 }
 
+llvm::Regex *ClangTidyDiagnosticConsumer::getExcludeHeaderFilter() {
+  if (!ExcludeHeaderFilter)
+ExcludeHeaderFilter = std::make_unique(
+*Context.getOptions().ExcludeHeaderFilterRegex);

justincady wrote:

I just pushed a commit that omits the check when `ExcludeHeaderFilter` is not 
set by the user. Please let me know if this aligns with your idea.

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


[clang-tools-extra] Add option to exclude headers from clang-tidy analysis (PR #91400)

2024-05-08 Thread Justin Cady via cfe-commits

https://github.com/justincady updated 
https://github.com/llvm/llvm-project/pull/91400

>From a5de583aa94ef794a083c8b27df6dc6fc0762cb7 Mon Sep 17 00:00:00 2001
From: Justin Cady 
Date: Tue, 7 May 2024 16:54:35 -0400
Subject: [PATCH 1/2] Add option to exclude headers from clang-tidy analysis

This is a renewed attempt to land @toddlipcon's D34654. The comments on
that patch indicate a broad desire for some ability to ignore headers.

After considering various options, including migrating to std::regex, I
believe this is the best path forward. It's intuitive to have separate
regexes for including headers versus excluding them, and this approach
has the added benefit of being completely opt-in. No existing configs
will break, regardless of existing HeaderFilterRegex values.

This functionality is useful for improving performance when analyzing a
targeted subset of code, as well as in cases where some collection of
headers cannot be modified (third party source, for example).
---
 .../clang-tidy/ClangTidyDiagnosticConsumer.cpp   | 10 +-
 .../clang-tidy/ClangTidyDiagnosticConsumer.h |  5 +
 .../clang-tidy/ClangTidyOptions.cpp  |  4 
 clang-tools-extra/clang-tidy/ClangTidyOptions.h  |  4 
 .../clang-tidy/tool/ClangTidyMain.cpp| 16 
 .../clang-tidy/infrastructure/file-filter.cpp|  7 +++
 6 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index de2a3b51422a5..3cde0d2d68874 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -564,7 +564,8 @@ void 
ClangTidyDiagnosticConsumer::checkFilters(SourceLocation Location,
   StringRef FileName(File->getName());
   LastErrorRelatesToUserCode = LastErrorRelatesToUserCode ||
Sources.isInMainFile(Location) ||
-   getHeaderFilter()->match(FileName);
+   (getHeaderFilter()->match(FileName) &&
+!getExcludeHeaderFilter()->match(FileName));
 
   unsigned LineNumber = Sources.getExpansionLineNumber(Location);
   LastErrorPassesLineFilter =
@@ -578,6 +579,13 @@ llvm::Regex 
*ClangTidyDiagnosticConsumer::getHeaderFilter() {
   return HeaderFilter.get();
 }
 
+llvm::Regex *ClangTidyDiagnosticConsumer::getExcludeHeaderFilter() {
+  if (!ExcludeHeaderFilter)
+ExcludeHeaderFilter = std::make_unique(
+*Context.getOptions().ExcludeHeaderFilterRegex);
+  return ExcludeHeaderFilter.get();
+}
+
 void ClangTidyDiagnosticConsumer::removeIncompatibleErrors() {
   // Each error is modelled as the set of intervals in which it applies
   // replacements. To detect overlapping replacements, we use a sweep line
diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
index 9280eb1e1f218..a3add5d52778d 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -299,6 +299,10 @@ class ClangTidyDiagnosticConsumer : public 
DiagnosticConsumer {
   /// context.
   llvm::Regex *getHeaderFilter();
 
+  /// \brief Returns the \c ExcludeHeaderFilter constructed for the options set
+  /// in the context.
+  llvm::Regex *getExcludeHeaderFilter();
+
   /// Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
   /// according to the diagnostic \p Location.
   void checkFilters(SourceLocation Location, const SourceManager &Sources);
@@ -313,6 +317,7 @@ class ClangTidyDiagnosticConsumer : public 
DiagnosticConsumer {
   bool EnableNolintBlocks;
   std::vector Errors;
   std::unique_ptr HeaderFilter;
+  std::unique_ptr ExcludeHeaderFilter;
   bool LastErrorRelatesToUserCode = false;
   bool LastErrorPassesLineFilter = false;
   bool LastErrorWasIgnored = false;
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index cbf21a0e2ae34..254ce7fc60fc9 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -170,6 +170,8 @@ template <> struct MappingTraits {
 IO.mapOptional("ImplementationFileExtensions",
Options.ImplementationFileExtensions);
 IO.mapOptional("HeaderFilterRegex", Options.HeaderFilterRegex);
+IO.mapOptional("ExcludeHeaderFilterRegex",
+   Options.ExcludeHeaderFilterRegex);
 IO.mapOptional("FormatStyle", Options.FormatStyle);
 IO.mapOptional("User", Options.User);
 IO.mapOptional("CheckOptions", Options.CheckOptions);
@@ -192,6 +194,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
   Options.HeaderFileExtensions = {"", "h", "hh", "hpp", "hxx"};
   Options.ImplementationFileExtensions = {"c", "cc", "cpp", "cxx"};
   Optio

[clang-tools-extra] [clang-tidy] support expect no diagnosis test (PR #91293)

2024-05-08 Thread Danny Mösch via cfe-commits

SimplyDanny wrote:

Why can the tests not just accept reference files that do not contain any 
`CHECK-*` comments? Then, no separate argument would be needed. In fact, I 
still sometimes struggle to find the correct options, command line and 
`CHECK-*` syntax. More options further complicate the setup.

Also, isn't there the `// RUN: not %check_clang_tidy` (note the `not`) command 
to claim a test file doesn't trigger the specified checks?

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


[clang] [Clang][Sema] Fix lookup of dependent operator= named by using-declaration (PR #91503)

2024-05-08 Thread Erich Keane via cfe-commits


@@ -137,17 +137,16 @@ namespace InhCtor {
   int n = b.T(); // expected-error {{'T' is a protected member of 
'InhCtor::A'}}
  // expected-note@-15 {{declared protected here}}
 
-  // FIXME: EDG and GCC reject this too, but it's not clear why it would be
-  // ill-formed.
   template
   struct S : T {
-struct U : S { // expected-note 6{{candidate}}
+// FIXME: S is incomplete here and we should diagnose this!
+struct U : S {

erichkeane wrote:

Ah, this is githubs fault :)  I mean the OLD 'FIXME' that you removed.  I was 
wondering if it has a CWG issue.

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


[clang] [Clang][Sema] Fix lookup of dependent operator= named by using-declaration (PR #91503)

2024-05-08 Thread Krystian Stasiowski via cfe-commits


@@ -137,17 +137,16 @@ namespace InhCtor {
   int n = b.T(); // expected-error {{'T' is a protected member of 
'InhCtor::A'}}
  // expected-note@-15 {{declared protected here}}
 
-  // FIXME: EDG and GCC reject this too, but it's not clear why it would be
-  // ill-formed.
   template
   struct S : T {
-struct U : S { // expected-note 6{{candidate}}
+// FIXME: S is incomplete here and we should diagnose this!
+struct U : S {

sdkrystian wrote:

The FIXME wasn't fixed, it's just broken in a different way that's consistent 
with other "current instantiation broken-ness" related things. I'm going to 
submit a patch (probably this week) which diagnoses cases where the current 
instantiation is used in a context which requires a complete type.

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Erich Keane via cfe-commits


@@ -1248,6 +1248,13 @@ static DeclContext *findOuterContext(Scope *S) {
   return nullptr;
 }
 
+static bool isDependentAssignmentOperator(DeclarationName Name,

erichkeane wrote:

Ah, perhaps I was confusing... i'd like this inside the `namespace {`, now 
below.

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Erich Keane via cfe-commits


@@ -1248,6 +1248,13 @@ static DeclContext *findOuterContext(Scope *S) {
   return nullptr;
 }
 
+static bool isDependentAssignmentOperator(DeclarationName Name,

erichkeane wrote:

a comment on this function similar to what you replied to me before woudl also 
be appreciated.

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Krystian Stasiowski via cfe-commits

https://github.com/sdkrystian updated 
https://github.com/llvm/llvm-project/pull/91498

>From 60d2030216403c7cfa8272396497d31aed314288 Mon Sep 17 00:00:00 2001
From: Krystian Stasiowski 
Date: Wed, 8 May 2024 12:18:49 -0400
Subject: [PATCH 1/4] [Clang][Sema] Fix lookup of dependent operator= outside
 of complete-class contexts

---
 clang/lib/Sema/SemaLookup.cpp   | 28 +---
 clang/lib/Sema/SemaTemplate.cpp |  7 ++-
 2 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index e63da5875d2c9..6bd5932212b92 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1269,19 +1269,19 @@ struct FindLocalExternScope {
 };
 } // end anonymous namespace
 
+static bool isDependentAssignmentOperator(DeclarationName Name,
+  DeclContext *LookupContext) {
+  auto *LookupRecord = dyn_cast_if_present(LookupContext);
+  return Name.getCXXOverloadedOperator() == OO_Equal && LookupRecord &&
+ !LookupRecord->isBeingDefined() && LookupRecord->isDependentContext();
+}
+
 bool Sema::CppLookupName(LookupResult &R, Scope *S) {
   assert(getLangOpts().CPlusPlus && "Can perform only C++ lookup");
 
   DeclarationName Name = R.getLookupName();
   Sema::LookupNameKind NameKind = R.getLookupKind();
 
-  // If this is the name of an implicitly-declared special member function,
-  // go through the scope stack to implicitly declare
-  if (isImplicitlyDeclaredMemberFunctionName(Name)) {
-for (Scope *PreS = S; PreS; PreS = PreS->getParent())
-  if (DeclContext *DC = PreS->getEntity())
-DeclareImplicitMemberFunctionsWithName(*this, Name, R.getNameLoc(), 
DC);
-  }
   // C++23 [temp.dep.general]p2:
   //   The component name of an unqualified-id is dependent if
   //   - it is a conversion-function-id whose conversion-type-id
@@ -1299,9 +1299,8 @@ bool Sema::CppLookupName(LookupResult &R, Scope *S) {
   if (isImplicitlyDeclaredMemberFunctionName(Name)) {
 for (Scope *PreS = S; PreS; PreS = PreS->getParent())
   if (DeclContext *DC = PreS->getEntity()) {
-if (DC->isDependentContext() && isa(DC) &&
-Name.getCXXOverloadedOperator() == OO_Equal &&
-!R.isTemplateNameLookup()) {
+if (!R.isTemplateNameLookup() &&
+isDependentAssignmentOperator(Name, DC)) {
   R.setNotFoundInCurrentInstantiation();
   return false;
 }
@@ -2472,8 +2471,6 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 }
   } QL(LookupCtx);
 
-  bool TemplateNameLookup = R.isTemplateNameLookup();
-  CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
   if (!InUnqualifiedLookup && !R.isForRedeclaration()) {
 // C++23 [temp.dep.type]p5:
 //   A qualified name is dependent if
@@ -2486,13 +2483,14 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 if (DeclarationName Name = R.getLookupName();
 (Name.getNameKind() == DeclarationName::CXXConversionFunctionName &&
  Name.getCXXNameType()->isDependentType()) ||
-(Name.getCXXOverloadedOperator() == OO_Equal && LookupRec &&
- LookupRec->isDependentContext() && !TemplateNameLookup)) {
+(!R.isTemplateNameLookup() &&
+ isDependentAssignmentOperator(Name, LookupCtx))) {
   R.setNotFoundInCurrentInstantiation();
   return false;
 }
   }
 
+  CXXRecordDecl *LookupRec = dyn_cast(LookupCtx);
   if (LookupDirect(*this, R, LookupCtx)) {
 R.resolveKind();
 if (LookupRec)
@@ -2604,7 +2602,7 @@ bool Sema::LookupQualifiedName(LookupResult &R, 
DeclContext *LookupCtx,
 //   template, and if the name is used as a template-name, the
 //   reference refers to the class template itself and not a
 //   specialization thereof, and is not ambiguous.
-if (TemplateNameLookup)
+if (R.isTemplateNameLookup())
   if (auto *TD = getAsTemplateNameDecl(ND))
 ND = TD;
 
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 7e57fa0696725..480bc74c2001a 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -726,7 +726,7 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
  const DeclarationNameInfo &NameInfo,
  bool isAddressOfOperand,
const TemplateArgumentListInfo *TemplateArgs) {
-  DeclContext *DC = getFunctionLevelDeclContext();
+  QualType ThisType = getCurrentThisType();
 
   // C++11 [expr.prim.general]p12:
   //   An id-expression that denotes a non-static data member or non-static
@@ -748,10 +748,7 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS,
 IsEnum = isa_and_nonnull(NNS->getAsType());
 
   if (!MightBeCxx11UnevalField && !isAddressOfOperand && !IsEnum &&
-  isa(DC) &&
-  cast(DC)->isImplicitObjectMemberFunction()) {
- 

[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Krystian Stasiowski via cfe-commits


@@ -1269,19 +1269,19 @@ struct FindLocalExternScope {
 };
 } // end anonymous namespace
 
+static bool isDependentAssignmentOperator(DeclarationName Name,
+  DeclContext *LookupContext) {
+  auto *LookupRecord = dyn_cast_if_present(LookupContext);
+  return Name.getCXXOverloadedOperator() == OO_Equal && LookupRecord &&
+ !LookupRecord->isBeingDefined() && LookupRecord->isDependentContext();

sdkrystian wrote:

(I'll add a test which calls `operator=` with a non-dependent argument -- in 
that case it will be diagnosed before the template is instantiated)

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Krystian Stasiowski via cfe-commits


@@ -1269,19 +1269,19 @@ struct FindLocalExternScope {
 };
 } // end anonymous namespace
 
+static bool isDependentAssignmentOperator(DeclarationName Name,
+  DeclContext *LookupContext) {
+  auto *LookupRecord = dyn_cast_if_present(LookupContext);
+  return Name.getCXXOverloadedOperator() == OO_Equal && LookupRecord &&
+ !LookupRecord->isBeingDefined() && LookupRecord->isDependentContext();

sdkrystian wrote:

The reason `operator=` is dependent when the current class is a templated 
entity is because each specialization declares its own set of special member 
functions, and according to [[special] 
p1](http://eel.is/c++draft/special#1.sentence-4), they are "declared at the 
closing `}` of the _class-specifier_". When instantiating a templated class, 
they are declared after all other member declarations are instantiated.

If the lookup context is the current instantiation and the current 
instantiation is incomplete (e.g. because `operator=` is named outside a 
complete-class context), we will never find the implicitly declared copy/move 
assignment operators because they are always declared last (neither in the 
template definition context, nor in the template instantiation context). So, we 
just treat it like any other unqualified name during lookup.

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


[clang] [Clang][Sema] Fix lookup of dependent operator= named by using-declaration (PR #91503)

2024-05-08 Thread Vlad Serebrennikov via cfe-commits


@@ -137,17 +137,16 @@ namespace InhCtor {
   int n = b.T(); // expected-error {{'T' is a protected member of 
'InhCtor::A'}}
  // expected-note@-15 {{declared protected here}}
 
-  // FIXME: EDG and GCC reject this too, but it's not clear why it would be
-  // ill-formed.
   template
   struct S : T {
-struct U : S { // expected-note 6{{candidate}}
+// FIXME: S is incomplete here and we should diagnose this!
+struct U : S {

Endilll wrote:

This rings a bell. I've put something similar in our DR tests, probably in a PR 
about complete-class context. I'm running out of time today, but I'll look into 
this tomorrow if Shafik doesn't beat me to it. 

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


[clang-tools-extra] [clang-tidy] Ignore unevaluated context in bugprone-optional-value-conversion (PR #90410)

2024-05-08 Thread Piotr Zegar via cfe-commits

PiotrZSL wrote:

@5chmidti 
I did some testing with this. And in example that you provided there is no 
issue.
This is because if optional will be uninitialized, then this code won't compile 
regardless if .value() or operator * is used.
Compiler will simply complain that expression is not constexpr.

When used normally, you will get undefined behavior or exception.

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


[clang] [Clang][Sema] Fix lookup of dependent operator= named by using-declaration (PR #91503)

2024-05-08 Thread Erich Keane via cfe-commits


@@ -137,17 +137,16 @@ namespace InhCtor {
   int n = b.T(); // expected-error {{'T' is a protected member of 
'InhCtor::A'}}
  // expected-note@-15 {{declared protected here}}
 
-  // FIXME: EDG and GCC reject this too, but it's not clear why it would be
-  // ill-formed.
   template
   struct S : T {
-struct U : S { // expected-note 6{{candidate}}
+// FIXME: S is incomplete here and we should diagnose this!
+struct U : S {

erichkeane wrote:

Did the FIXME ever get a core issue?  Perhaps we need to run that down a bit?  
@Endilll or @shafik , any chance the 'FIXME" that we just 'fixed' looks 
familiar?

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Erich Keane via cfe-commits


@@ -1269,19 +1269,19 @@ struct FindLocalExternScope {
 };
 } // end anonymous namespace
 
+static bool isDependentAssignmentOperator(DeclarationName Name,
+  DeclContext *LookupContext) {
+  auto *LookupRecord = dyn_cast_if_present(LookupContext);

erichkeane wrote:

```suggestion
  const auto *LookupRecord = dyn_cast_if_present(LookupContext);
```

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Erich Keane via cfe-commits


@@ -1269,19 +1269,19 @@ struct FindLocalExternScope {
 };
 } // end anonymous namespace
 
+static bool isDependentAssignmentOperator(DeclarationName Name,
+  DeclContext *LookupContext) {
+  auto *LookupRecord = dyn_cast_if_present(LookupContext);
+  return Name.getCXXOverloadedOperator() == OO_Equal && LookupRecord &&
+ !LookupRecord->isBeingDefined() && LookupRecord->isDependentContext();

erichkeane wrote:

Why the `!isBeingDefined`?  That seems weird given the name of this function.

Also, instead of making it static, can you just toss it in the anonymous NS 
above?

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

few little things?  Mostly looks ok.

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


[clang] [Clang][Sema] Fix lookup of dependent operator= outside of complete-class contexts (PR #91498)

2024-05-08 Thread Erich Keane via cfe-commits

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


  1   2   3   4   >