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

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

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

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

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

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

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

2023-12-26 Thread Piotr Zegar via cfe-commits

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

LGTM

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


[llvm] [clang] Revert "InstCombine: Fold is.fpclass(x, fcInf) to fabs+fcmp" (PR #76338)

2023-12-26 Thread Matt Arsenault via cfe-commits

arsenm wrote:

I still think fabs+fcmp is a better canonical form. Between some targets 
offering free fabs, and other combines between fabs and sources/sinks, I think 
it's better to split out this way. Any codegen regression should be addressed 
in the backend.

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


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

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

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

>From ed8ebdb6f2133f84d1f5a8d2cd580dba4ceed922 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Tue, 26 Dec 2023 15:58:10 +0800
Subject: [PATCH 1/4] [RISCV][NFC] Use RISCVISAInfo instead of string
 comparison

The arch string may not start with rv32/rv64 if we have supported
profiles in `-march`.
---
 clang/lib/Driver/Driver.cpp | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..671a11f9811f5b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -86,6 +86,7 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
@@ -670,10 +671,15 @@ static llvm::Triple computeTargetTriple(const Driver ,
 if (Args.hasArg(options::OPT_march_EQ) ||
 Args.hasArg(options::OPT_mcpu_EQ)) {
   StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
-  if (ArchName.starts_with_insensitive("rv32"))
-Target.setArch(llvm::Triple::riscv32);
-  else if (ArchName.starts_with_insensitive("rv64"))
-Target.setArch(llvm::Triple::riscv64);
+  auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
+  ArchName, /*EnableExperimentalExtensions=*/true);
+  if (ISAInfo) {
+unsigned XLen = (*ISAInfo)->getXLen();
+if (XLen == 32)
+  Target.setArch(llvm::Triple::riscv32);
+else if (XLen == 64)
+  Target.setArch(llvm::Triple::riscv64);
+  }
 }
   }
 

>From 24f77edf357eb5f6fef207ab79d8df725a1ec27f Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Tue, 26 Dec 2023 17:16:00 +0800
Subject: [PATCH 2/4] Handle the error case

---
 clang/lib/Driver/Driver.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 671a11f9811f5b..a8b7d0587c2f3f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -673,7 +673,10 @@ static llvm::Triple computeTargetTriple(const Driver ,
   StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
   auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
   ArchName, /*EnableExperimentalExtensions=*/true);
-  if (ISAInfo) {
+  if (!ISAInfo) {
+// Ignore any error here, we assume it will be handled in another 
place.
+consumeError(ISAInfo.takeError());
+  } else {
 unsigned XLen = (*ISAInfo)->getXLen();
 if (XLen == 32)
   Target.setArch(llvm::Triple::riscv32);

>From 9574308a1032fb4da3d5db61d144b51f832f6000 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Wed, 27 Dec 2023 14:30:00 +0800
Subject: [PATCH 3/4] Use llvm::errorToBool

---
 clang/lib/Driver/Driver.cpp | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a8b7d0587c2f3f..ed1169ac45029f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -77,6 +77,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ExitCodes.h"
 #include "llvm/Support/FileSystem.h"
@@ -673,10 +674,7 @@ static llvm::Triple computeTargetTriple(const Driver ,
   StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
   auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
   ArchName, /*EnableExperimentalExtensions=*/true);
-  if (!ISAInfo) {
-// Ignore any error here, we assume it will be handled in another 
place.
-consumeError(ISAInfo.takeError());
-  } else {
+  if (!llvm::errorToBool(ISAInfo.takeError())) {
 unsigned XLen = (*ISAInfo)->getXLen();
 if (XLen == 32)
   Target.setArch(llvm::Triple::riscv32);

>From 0d9385c6507f8118615ac4715bba2cde1ca426ed Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Wed, 27 Dec 2023 15:06:58 +0800
Subject: [PATCH 4/4] Remove unnecessary include

---
 clang/lib/Driver/Driver.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ed1169ac45029f..9b2f2a37480983 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -77,7 +77,6 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ExitCodes.h"
 #include "llvm/Support/FileSystem.h"

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


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

2023-12-26 Thread via cfe-commits

llvmbot wrote:




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

Author: Wang Pengcheng (wangpc-pp)


Changes

To reduce calls to `consumeError`.


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


4 Files Affected:

- (modified) clang/lib/Basic/Targets/RISCV.cpp (+1-2) 
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+2-4) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2-5) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+4-8) 


``diff
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 685462961ee35a..6bc57a83a2d5ae 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -416,8 +416,7 @@ static void handleFullArchString(StringRef FullArchStr,
   Features.push_back("__RISCV_TargetAttrNeedOverride");
   auto RII = llvm::RISCVISAInfo::parseArchString(
   FullArchStr, /* EnableExperimentalExtension */ true);
-  if (!RII) {
-consumeError(RII.takeError());
+  if (llvm::errorToBool(RII.takeError())) {
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 8ae47d1680bd22..0717e3b813e1e2 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -215,10 +215,8 @@ StringRef riscv::getRISCVABI(const ArgList , const 
llvm::Triple ) {
 
   auto ParseResult = llvm::RISCVISAInfo::parseArchString(
   Arch, /* EnableExperimentalExtension */ true);
-  if (!ParseResult)
-// Ignore parsing error, just go 3rd step.
-consumeError(ParseResult.takeError());
-  else
+  // Ignore parsing error, just go 3rd step.
+  if (!llvm::errorToBool(ParseResult.takeError()))
 return (*ParseResult)->computeDefaultABI();
 
   // 3. Choose a default based on the triple
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 70dc7e54aca125..acfa119805068d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2072,12 +2072,9 @@ void Clang::AddRISCVTargetArgs(const ArgList ,
 StringRef Arch = riscv::getRISCVArch(Args, Triple);
 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
 Arch, /*EnableExperimentalExtensions*/ true);
-if (!ISAInfo) {
-  // Ignore parsing error.
-  consumeError(ISAInfo.takeError());
-} else {
+// Ignore parsing error.
+if (!errorToBool(ISAInfo.takeError()))
   MinVLen = (*ISAInfo)->getMinVLen();
-}
 
 // If the value is "zvl", use MinVLen from march. Otherwise, try to parse
 // as integer as long as we have a MinVLen.
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 38361d6889a1c8..a610a94a39a2b4 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1741,11 +1741,9 @@ selectRISCVMultilib(const MultilibSet , 
StringRef Arch,
   llvm::RISCVISAInfo::parseArchString(
   Arch, /*EnableExperimentalExtension=*/true,
   /*ExperimentalExtensionVersionCheck=*/false);
-  if (!ParseResult) {
-// Ignore any error here, we assume it will be handled in another place.
-consumeError(ParseResult.takeError());
+  // Ignore any error here, we assume it will be handled in another place.
+  if (llvm::errorToBool(ParseResult.takeError()))
 return false;
-  }
 
   auto  = *ParseResult;
 
@@ -1780,10 +1778,8 @@ selectRISCVMultilib(const MultilibSet , 
StringRef Arch,
   llvm::RISCVISAInfo::parseArchString(
   Flag, /*EnableExperimentalExtension=*/true,
   /*ExperimentalExtensionVersionCheck=*/false);
-  if (!MLConfigParseResult) {
-// Ignore any error here, we assume it will handled in another place.
-llvm::consumeError(MLConfigParseResult.takeError());
-
+  // Ignore any error here, we assume it will handled in another place.
+  if (llvm::errorToBool(MLConfigParseResult.takeError())) {
 // We might get a parsing error if rv32e in the list, we could just 
skip
 // that and process the rest of multi-lib configs.
 Skip = true;

``




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


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

2023-12-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Wang Pengcheng (wangpc-pp)


Changes

To reduce calls to `consumeError`.


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


4 Files Affected:

- (modified) clang/lib/Basic/Targets/RISCV.cpp (+1-2) 
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+2-4) 
- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2-5) 
- (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+4-8) 


``diff
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 685462961ee35a..6bc57a83a2d5ae 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -416,8 +416,7 @@ static void handleFullArchString(StringRef FullArchStr,
   Features.push_back("__RISCV_TargetAttrNeedOverride");
   auto RII = llvm::RISCVISAInfo::parseArchString(
   FullArchStr, /* EnableExperimentalExtension */ true);
-  if (!RII) {
-consumeError(RII.takeError());
+  if (llvm::errorToBool(RII.takeError())) {
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 8ae47d1680bd22..0717e3b813e1e2 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -215,10 +215,8 @@ StringRef riscv::getRISCVABI(const ArgList , const 
llvm::Triple ) {
 
   auto ParseResult = llvm::RISCVISAInfo::parseArchString(
   Arch, /* EnableExperimentalExtension */ true);
-  if (!ParseResult)
-// Ignore parsing error, just go 3rd step.
-consumeError(ParseResult.takeError());
-  else
+  // Ignore parsing error, just go 3rd step.
+  if (!llvm::errorToBool(ParseResult.takeError()))
 return (*ParseResult)->computeDefaultABI();
 
   // 3. Choose a default based on the triple
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 70dc7e54aca125..acfa119805068d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2072,12 +2072,9 @@ void Clang::AddRISCVTargetArgs(const ArgList ,
 StringRef Arch = riscv::getRISCVArch(Args, Triple);
 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
 Arch, /*EnableExperimentalExtensions*/ true);
-if (!ISAInfo) {
-  // Ignore parsing error.
-  consumeError(ISAInfo.takeError());
-} else {
+// Ignore parsing error.
+if (!errorToBool(ISAInfo.takeError()))
   MinVLen = (*ISAInfo)->getMinVLen();
-}
 
 // If the value is "zvl", use MinVLen from march. Otherwise, try to parse
 // as integer as long as we have a MinVLen.
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 38361d6889a1c8..a610a94a39a2b4 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1741,11 +1741,9 @@ selectRISCVMultilib(const MultilibSet , 
StringRef Arch,
   llvm::RISCVISAInfo::parseArchString(
   Arch, /*EnableExperimentalExtension=*/true,
   /*ExperimentalExtensionVersionCheck=*/false);
-  if (!ParseResult) {
-// Ignore any error here, we assume it will be handled in another place.
-consumeError(ParseResult.takeError());
+  // Ignore any error here, we assume it will be handled in another place.
+  if (llvm::errorToBool(ParseResult.takeError()))
 return false;
-  }
 
   auto  = *ParseResult;
 
@@ -1780,10 +1778,8 @@ selectRISCVMultilib(const MultilibSet , 
StringRef Arch,
   llvm::RISCVISAInfo::parseArchString(
   Flag, /*EnableExperimentalExtension=*/true,
   /*ExperimentalExtensionVersionCheck=*/false);
-  if (!MLConfigParseResult) {
-// Ignore any error here, we assume it will handled in another place.
-llvm::consumeError(MLConfigParseResult.takeError());
-
+  // Ignore any error here, we assume it will handled in another place.
+  if (llvm::errorToBool(MLConfigParseResult.takeError())) {
 // We might get a parsing error if rv32e in the list, we could just 
skip
 // that and process the rest of multi-lib configs.
 Skip = true;

``




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


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

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

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

To reduce calls to `consumeError`.


>From 0d8426ffb1202ceca97b25c0dd47d516c1be280e Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Wed, 27 Dec 2023 14:41:30 +0800
Subject: [PATCH] [RISCV][NFC] Use errorToBool

To reduce calls to `consumeError`.
---
 clang/lib/Basic/Targets/RISCV.cpp  |  3 +--
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp |  6 ++
 clang/lib/Driver/ToolChains/Clang.cpp  |  7 ++-
 clang/lib/Driver/ToolChains/Gnu.cpp| 12 
 4 files changed, 9 insertions(+), 19 deletions(-)

diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index 685462961ee35a..6bc57a83a2d5ae 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -416,8 +416,7 @@ static void handleFullArchString(StringRef FullArchStr,
   Features.push_back("__RISCV_TargetAttrNeedOverride");
   auto RII = llvm::RISCVISAInfo::parseArchString(
   FullArchStr, /* EnableExperimentalExtension */ true);
-  if (!RII) {
-consumeError(RII.takeError());
+  if (llvm::errorToBool(RII.takeError())) {
 // Forward the invalid FullArchStr.
 Features.push_back("+" + FullArchStr.str());
   } else {
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 8ae47d1680bd22..0717e3b813e1e2 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -215,10 +215,8 @@ StringRef riscv::getRISCVABI(const ArgList , const 
llvm::Triple ) {
 
   auto ParseResult = llvm::RISCVISAInfo::parseArchString(
   Arch, /* EnableExperimentalExtension */ true);
-  if (!ParseResult)
-// Ignore parsing error, just go 3rd step.
-consumeError(ParseResult.takeError());
-  else
+  // Ignore parsing error, just go 3rd step.
+  if (!llvm::errorToBool(ParseResult.takeError()))
 return (*ParseResult)->computeDefaultABI();
 
   // 3. Choose a default based on the triple
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 70dc7e54aca125..acfa119805068d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2072,12 +2072,9 @@ void Clang::AddRISCVTargetArgs(const ArgList ,
 StringRef Arch = riscv::getRISCVArch(Args, Triple);
 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
 Arch, /*EnableExperimentalExtensions*/ true);
-if (!ISAInfo) {
-  // Ignore parsing error.
-  consumeError(ISAInfo.takeError());
-} else {
+// Ignore parsing error.
+if (!errorToBool(ISAInfo.takeError()))
   MinVLen = (*ISAInfo)->getMinVLen();
-}
 
 // If the value is "zvl", use MinVLen from march. Otherwise, try to parse
 // as integer as long as we have a MinVLen.
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 38361d6889a1c8..a610a94a39a2b4 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -1741,11 +1741,9 @@ selectRISCVMultilib(const MultilibSet , 
StringRef Arch,
   llvm::RISCVISAInfo::parseArchString(
   Arch, /*EnableExperimentalExtension=*/true,
   /*ExperimentalExtensionVersionCheck=*/false);
-  if (!ParseResult) {
-// Ignore any error here, we assume it will be handled in another place.
-consumeError(ParseResult.takeError());
+  // Ignore any error here, we assume it will be handled in another place.
+  if (llvm::errorToBool(ParseResult.takeError()))
 return false;
-  }
 
   auto  = *ParseResult;
 
@@ -1780,10 +1778,8 @@ selectRISCVMultilib(const MultilibSet , 
StringRef Arch,
   llvm::RISCVISAInfo::parseArchString(
   Flag, /*EnableExperimentalExtension=*/true,
   /*ExperimentalExtensionVersionCheck=*/false);
-  if (!MLConfigParseResult) {
-// Ignore any error here, we assume it will handled in another place.
-llvm::consumeError(MLConfigParseResult.takeError());
-
+  // Ignore any error here, we assume it will handled in another place.
+  if (llvm::errorToBool(MLConfigParseResult.takeError())) {
 // We might get a parsing error if rv32e in the list, we could just 
skip
 // that and process the rest of multi-lib configs.
 Skip = true;

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


[clang] [Clang] support vector subscript expressions in constant evaluator (WIP) (PR #76379)

2023-12-26 Thread Yuanfang Chen via cfe-commits

yuanfang-chen wrote:

#72607

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


[clang] [clang]get non-injected-class before finding instantiated decl (PR #70886)

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

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


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

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

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/75061

>From c3938da3a94ed9a9cc86d006d4b39dc5b73e7114 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Mon, 11 Dec 2023 23:32:32 +0800
Subject: [PATCH] [clang-tidy][misleading-indentation]ignore false-positives
 for line started with empty macro

Fixes: #71767
---
 .../MisleadingIndentationCheck.cpp| 22 ---
 .../readability/MisleadingIndentationCheck.h  |  3 ++-
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../readability/misleading-indentation.cpp|  9 
 4 files changed, 34 insertions(+), 4 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
index 2c011f5c0e6904..e32f79589a059b 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "MisleadingIndentationCheck.h"
+#include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
@@ -51,8 +52,20 @@ void MisleadingIndentationCheck::danglingElseCheck(const 
SourceManager ,
 diag(ElseLoc, "different indentation for 'if' and corresponding 'else'");
 }
 
-void MisleadingIndentationCheck::missingBracesCheck(const SourceManager ,
-const CompoundStmt *CStmt) 
{
+static bool isAtStartOfLineIncludingEmptyMacro(SourceLocation NextLoc,
+   const SourceManager ,
+   const LangOptions ) {
+  const SourceLocation BeforeLoc =
+  utils::lexer::getPreviousTokenAndStart(NextLoc, SM, LangOpts).second;
+  if (BeforeLoc.isInvalid())
+return false;
+  return SM.getExpansionLineNumber(BeforeLoc) !=
+ SM.getExpansionLineNumber(NextLoc);
+}
+
+void MisleadingIndentationCheck::missingBracesCheck(
+const SourceManager , const CompoundStmt *CStmt,
+const LangOptions ) {
   const static StringRef StmtNames[] = {"if", "for", "while"};
   for (unsigned int I = 0; I < CStmt->size() - 1; I++) {
 const Stmt *CurrentStmt = CStmt->body_begin()[I];
@@ -92,6 +105,8 @@ void MisleadingIndentationCheck::missingBracesCheck(const 
SourceManager ,
 
 if (NextLoc.isInvalid() || NextLoc.isMacroID())
   continue;
+if (!isAtStartOfLineIncludingEmptyMacro(NextLoc, SM, LangOpts))
+  continue;
 
 if (SM.getExpansionColumnNumber(InnerLoc) ==
 SM.getExpansionColumnNumber(NextLoc)) {
@@ -117,7 +132,8 @@ void MisleadingIndentationCheck::check(const 
MatchFinder::MatchResult ) {
 danglingElseCheck(*Result.SourceManager, Result.Context, If);
 
   if (const auto *CStmt = Result.Nodes.getNodeAs("compound"))
-missingBracesCheck(*Result.SourceManager, CStmt);
+missingBracesCheck(*Result.SourceManager, CStmt,
+   Result.Context->getLangOpts());
 }
 
 } // namespace clang::tidy::readability
diff --git 
a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h 
b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
index c336abbc7c4a91..9c92fc1e18b6f3 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
@@ -32,7 +32,8 @@ class MisleadingIndentationCheck : public ClangTidyCheck {
 private:
   void danglingElseCheck(const SourceManager , ASTContext *Context,
  const IfStmt *If);
-  void missingBracesCheck(const SourceManager , const CompoundStmt *CStmt);
+  void missingBracesCheck(const SourceManager , const CompoundStmt *CStmt,
+  const LangOptions );
 };
 
 } // namespace clang::tidy::readability
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fe7f40d95fe6ca..571808a51596a8 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -465,6 +465,10 @@ Changes in existing checks
   `AllowPointerConditions` options. It also now provides more consistent
   suggestions when parentheses are added to the return value.
 
+- Improved :doc:`readability-misleading-indentation
+  ` check to ignore
+  false-positives for line started with empty macro.
+
 - Improved :doc:`readability-non-const-parameter
   ` check to ignore
   false-positives in initializer list of record.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
index aea0618d120db6..5d4d60f5f1a351 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/misleading-indentation.cpp
+++ 

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

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

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

>From ed8ebdb6f2133f84d1f5a8d2cd580dba4ceed922 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Tue, 26 Dec 2023 15:58:10 +0800
Subject: [PATCH 1/3] [RISCV][NFC] Use RISCVISAInfo instead of string
 comparison

The arch string may not start with rv32/rv64 if we have supported
profiles in `-march`.
---
 clang/lib/Driver/Driver.cpp | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..671a11f9811f5b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -86,6 +86,7 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/StringSaver.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
@@ -670,10 +671,15 @@ static llvm::Triple computeTargetTriple(const Driver ,
 if (Args.hasArg(options::OPT_march_EQ) ||
 Args.hasArg(options::OPT_mcpu_EQ)) {
   StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
-  if (ArchName.starts_with_insensitive("rv32"))
-Target.setArch(llvm::Triple::riscv32);
-  else if (ArchName.starts_with_insensitive("rv64"))
-Target.setArch(llvm::Triple::riscv64);
+  auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
+  ArchName, /*EnableExperimentalExtensions=*/true);
+  if (ISAInfo) {
+unsigned XLen = (*ISAInfo)->getXLen();
+if (XLen == 32)
+  Target.setArch(llvm::Triple::riscv32);
+else if (XLen == 64)
+  Target.setArch(llvm::Triple::riscv64);
+  }
 }
   }
 

>From 24f77edf357eb5f6fef207ab79d8df725a1ec27f Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Tue, 26 Dec 2023 17:16:00 +0800
Subject: [PATCH 2/3] Handle the error case

---
 clang/lib/Driver/Driver.cpp | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 671a11f9811f5b..a8b7d0587c2f3f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -673,7 +673,10 @@ static llvm::Triple computeTargetTriple(const Driver ,
   StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
   auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
   ArchName, /*EnableExperimentalExtensions=*/true);
-  if (ISAInfo) {
+  if (!ISAInfo) {
+// Ignore any error here, we assume it will be handled in another 
place.
+consumeError(ISAInfo.takeError());
+  } else {
 unsigned XLen = (*ISAInfo)->getXLen();
 if (XLen == 32)
   Target.setArch(llvm::Triple::riscv32);

>From 9574308a1032fb4da3d5db61d144b51f832f6000 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Wed, 27 Dec 2023 14:30:00 +0800
Subject: [PATCH 3/3] Use llvm::errorToBool

---
 clang/lib/Driver/Driver.cpp | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a8b7d0587c2f3f..ed1169ac45029f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -77,6 +77,7 @@
 #include "llvm/Option/OptTable.h"
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ExitCodes.h"
 #include "llvm/Support/FileSystem.h"
@@ -673,10 +674,7 @@ static llvm::Triple computeTargetTriple(const Driver ,
   StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
   auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
   ArchName, /*EnableExperimentalExtensions=*/true);
-  if (!ISAInfo) {
-// Ignore any error here, we assume it will be handled in another 
place.
-consumeError(ISAInfo.takeError());
-  } else {
+  if (!llvm::errorToBool(ISAInfo.takeError())) {
 unsigned XLen = (*ISAInfo)->getXLen();
 if (XLen == 32)
   Target.setArch(llvm::Triple::riscv32);

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


[clang] [RISCV] Remove redundant variable Log2LMUL from vset intrinsic. NFC (PR #76422)

2023-12-26 Thread Jim Lin via cfe-commits

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


[clang] 039d9aa - [RISCV] Remove redundant variable Log2LMUL from vset intrinsic. NFC (#76422)

2023-12-26 Thread via cfe-commits

Author: Jim Lin
Date: 2023-12-27T14:14:50+08:00
New Revision: 039d9aa56e9432e119c4b62e575f74fcf3cacb82

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

LOG: [RISCV] Remove redundant variable Log2LMUL from vset intrinsic. NFC 
(#76422)

Added: 


Modified: 
clang/include/clang/Basic/riscv_vector.td

Removed: 




diff  --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index f2dde7f540fb74..e7d78b03511fe9 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2441,11 +2441,9 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 return Builder.CreateInsertVector(ResultType, Ops[0], Ops[2], Ops[1]);
   }
   }] in {
-let Log2LMUL = [0, 1, 2] in {
-  foreach dst_lmul = ["(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", 
"(LFixedLog2LMUL:3)"] in {
-def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "v" # dst_lmul # 
"vKzv", "csilxfd">;
-def : RVVBuiltin<"Uv" # dst_lmul # "Uv", dst_lmul # "Uv" # dst_lmul 
#"UvKzUv", "csil">;
-  }
+foreach dst_lmul = ["(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", 
"(LFixedLog2LMUL:3)"] in {
+  def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "v" # dst_lmul # 
"vKzv", "csilxfd">;
+  def : RVVBuiltin<"Uv" # dst_lmul # "Uv", dst_lmul # "Uv" # dst_lmul 
#"UvKzUv", "csil">;
 }
 foreach nf = NFList in {
   defvar T = "(Tuple:" # nf # ")";



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


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

2023-12-26 Thread via cfe-commits

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

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

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

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

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

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

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

[clang-tools-extra] [clang] [flang] [libcxx] [compiler-rt] [llvm] [Clang][Sema] Fix qualifier restriction of overriden methods (PR #71696)

2023-12-26 Thread Qiu Chaofan via cfe-commits

ecnelises wrote:

Ping

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


[clang] [Driver] Hook up Haiku PowerPC support (PR #69134)

2023-12-26 Thread Brad Smith via cfe-commits

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


[clang] Avoid printing overly large integer. (PR #75902)

2023-12-26 Thread Nhat Nguyen via cfe-commits

changkhothuychung wrote:

Thanks everyone for the comments! I will address as soon as I can. 

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


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

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


@@ -670,10 +671,18 @@ static llvm::Triple computeTargetTriple(const Driver ,
 if (Args.hasArg(options::OPT_march_EQ) ||
 Args.hasArg(options::OPT_mcpu_EQ)) {
   StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
-  if (ArchName.starts_with_insensitive("rv32"))
-Target.setArch(llvm::Triple::riscv32);
-  else if (ArchName.starts_with_insensitive("rv64"))
-Target.setArch(llvm::Triple::riscv64);
+  auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
+  ArchName, /*EnableExperimentalExtensions=*/true);
+  if (!ISAInfo) {

topperc wrote:

Use `errorToBool` to avoid the call to consumeError?

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


[clang] [RISCV] Remove redundant variable Log2LMUL from vset intrinsic. NFC (PR #76422)

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

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

LGTM.

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


[clang] [RISCV] Remove redundant variable Log2LMUL from vset intrinsic. NFC (PR #76422)

2023-12-26 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: Jim Lin (tclin914)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/Basic/riscv_vector.td (+3-5) 


``diff
diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index f2dde7f540fb74..e7d78b03511fe9 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2441,11 +2441,9 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 return Builder.CreateInsertVector(ResultType, Ops[0], Ops[2], Ops[1]);
   }
   }] in {
-let Log2LMUL = [0, 1, 2] in {
-  foreach dst_lmul = ["(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", 
"(LFixedLog2LMUL:3)"] in {
-def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "v" # dst_lmul # 
"vKzv", "csilxfd">;
-def : RVVBuiltin<"Uv" # dst_lmul # "Uv", dst_lmul # "Uv" # dst_lmul 
#"UvKzUv", "csil">;
-  }
+foreach dst_lmul = ["(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", 
"(LFixedLog2LMUL:3)"] in {
+  def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "v" # dst_lmul # 
"vKzv", "csilxfd">;
+  def : RVVBuiltin<"Uv" # dst_lmul # "Uv", dst_lmul # "Uv" # dst_lmul 
#"UvKzUv", "csil">;
 }
 foreach nf = NFList in {
   defvar T = "(Tuple:" # nf # ")";

``




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


[clang] [RISCV] Remove redundant variable Log2LMUL from vset intrinsic. NFC (PR #76422)

2023-12-26 Thread Jim Lin via cfe-commits

https://github.com/tclin914 created 
https://github.com/llvm/llvm-project/pull/76422

None

>From 460d1b9ece1fb208047a8c35088bd5dcb12279b2 Mon Sep 17 00:00:00 2001
From: Jim Lin 
Date: Wed, 27 Dec 2023 11:19:21 +0800
Subject: [PATCH] [RISCV] Remove redundant variable Log2LMUL for vset
 intrinsic. NFC

---
 clang/include/clang/Basic/riscv_vector.td | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index f2dde7f540fb74..e7d78b03511fe9 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2441,11 +2441,9 @@ let HasMasked = false, HasVL = false, IRName = "" in {
 return Builder.CreateInsertVector(ResultType, Ops[0], Ops[2], Ops[1]);
   }
   }] in {
-let Log2LMUL = [0, 1, 2] in {
-  foreach dst_lmul = ["(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", 
"(LFixedLog2LMUL:3)"] in {
-def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "v" # dst_lmul # 
"vKzv", "csilxfd">;
-def : RVVBuiltin<"Uv" # dst_lmul # "Uv", dst_lmul # "Uv" # dst_lmul 
#"UvKzUv", "csil">;
-  }
+foreach dst_lmul = ["(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", 
"(LFixedLog2LMUL:3)"] in {
+  def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "v" # dst_lmul # 
"vKzv", "csilxfd">;
+  def : RVVBuiltin<"Uv" # dst_lmul # "Uv", dst_lmul # "Uv" # dst_lmul 
#"UvKzUv", "csil">;
 }
 foreach nf = NFList in {
   defvar T = "(Tuple:" # nf # ")";

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


[clang] [llvm] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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

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

>From 20fd01b09bb196cf53807b44161482d56a43920b Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Tue, 26 Dec 2023 20:46:13 +0800
Subject: [PATCH 1/3] [RISCV][MC] Add support for experimental Zcmop extension

This implements experimental support for the Zcmop extension as
specified here: 
https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc.

This change adds only MC support.
---
 .../test/Preprocessor/riscv-target-features.c |  9 
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/lib/Support/RISCVISAInfo.cpp |  2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|  7 
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |  1 +
 llvm/lib/Target/RISCV/RISCVInstrInfoZcmop.td  | 30 +
 llvm/test/CodeGen/RISCV/attributes.ll |  4 ++
 llvm/test/MC/RISCV/rv32zcmop-invalid.s|  7 
 llvm/test/MC/RISCV/rvzcmop-valid.s| 42 +++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |  1 +
 10 files changed, 106 insertions(+)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoZcmop.td
 create mode 100644 llvm/test/MC/RISCV/rv32zcmop-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rvzcmop-valid.s

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 2111b3f1c5832b..661f1fb55159c7 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -121,6 +121,7 @@
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
 // CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zimop {{.*$}}
+// CHECK-NOT: __riscv_zcmop {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvbb {{.*$}}
 // CHECK-NOT: __riscv_zvbc {{.*$}}
@@ -1080,6 +1081,14 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZIMOP-EXT %s
 // CHECK-ZIMOP-EXT: __riscv_zimop  1000{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zcmop0p2 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZCMOP-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv32i_zcmop0p2 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZCMOP-EXT %s
+// CHECK-ZCMOP-EXT: __riscv_zcmop  2000{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
 // RUN: -march=rv32iztso0p1 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZTSO-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 3125f2d7c9cfdb..836a4e9ff08e55 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -224,6 +224,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zimop``
   LLVM implements the `v0.1 proposed specification 
`__.
 
+``experimental-zcmop``
+  LLVM implements the `v0.2 proposed specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index e71e96e3417e46..36d453a53c1057 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -191,6 +191,8 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
 {"zacas", RISCVExtensionVersion{1, 0}},
 
+{"zcmop", RISCVExtensionVersion{0, 2}},
+
 {"zfbfmin", RISCVExtensionVersion{0, 8}},
 
 {"zicfilp", RISCVExtensionVersion{0, 4}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index a6e7c15b50e978..adf3c84b586a25 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -693,6 +693,13 @@ def HasStdExtZimop : 
Predicate<"Subtarget->hasStdExtZimop()">,
AssemblerPredicate<(all_of FeatureStdExtZimop),
"'Zimop' (May-Be-Operations)">;
 
+def FeatureStdExtZcmop : SubtargetFeature<"experimental-zcmop", 
"HasStdExtZcmop", "true",
+  "'Zcmop' (Compressed 
May-Be-Operations)",
+  [FeatureStdExtZca]>;
+def HasStdExtZcmop : Predicate<"Subtarget->hasStdExtZcmop()">,
+   

[clang] [llvm] [X86] Remove RAO-INT from Grandridge (PR #76420)

2023-12-26 Thread Shengchen Kan via cfe-commits

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

LGTM

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


[clang] [llvm] [X86] Remove RAO-INT from Grandridge (PR #76420)

2023-12-26 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-clang

Author: Freddy Ye (FreddyLeaf)


Changes

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


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


3 Files Affected:

- (modified) clang/test/Preprocessor/predefined-arch-macros.c (+2-4) 
- (modified) llvm/lib/Target/X86/X86.td (+3-8) 
- (modified) llvm/lib/TargetParser/X86TargetParser.cpp (+1-3) 


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

``





[clang] [llvm] [X86] Remove RAO-INT from Grandridge (PR #76420)

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

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

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


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

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

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

[clang] [llvm] [X86] Correct operand order of UWRMSR. (PR #76389)

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

FreddyLeaf wrote:

https://github.com/llvm/llvm-project/assets/64940021/9b7acece-cbbe-453e-b913-9b13a6f79b56;>
CCMP is already disclosed in https://cdrdv2.intel.com/v1/dl/getContent/784266 

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


[clang] [RISCV][Clang] Remove -save-restore from default features. (PR #76390)

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

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


[clang] ce0c149 - [RISCV][Clang] Remove -save-restore from default features. (#76390)

2023-12-26 Thread via cfe-commits

Author: Yeting Kuo
Date: 2023-12-27T09:12:35+08:00
New Revision: ce0c149f65d9fe708b91610fb94d3db443247262

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

LOG: [RISCV][Clang] Remove -save-restore from default features. (#76390)

It's unnecessary to defaultly pass feature `-save-restore`, since risc-v
backend defaultly disables save-restore functionality.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/test/Driver/riscv-default-features.c
clang/test/Driver/riscv-features.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 25b43cefce6b57..8ae47d1680bd22 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -167,13 +167,6 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("-relax");
   }
 
-  // GCC Compatibility: -mno-save-restore is default, unless -msave-restore is
-  // specified.
-  if (Args.hasFlag(options::OPT_msave_restore, options::OPT_mno_save_restore, 
false))
-Features.push_back("+save-restore");
-  else
-Features.push_back("-save-restore");
-
   // -mno-unaligned-access is default, unless -munaligned-access is specified.
   AddTargetFeature(Args, Features, options::OPT_munaligned_access,
options::OPT_mno_unaligned_access, "fast-unaligned-access");

diff  --git a/clang/test/Driver/riscv-default-features.c 
b/clang/test/Driver/riscv-default-features.c
index 6e48f7cc37dcb0..4c3883c1cc1184 100644
--- a/clang/test/Driver/riscv-default-features.c
+++ b/clang/test/Driver/riscv-default-features.c
@@ -2,9 +2,7 @@
 // RUN: %clang --target=riscv64-unknown-elf -S -emit-llvm %s -o - | FileCheck 
%s -check-prefix=RV64
 
 // RV32: "target-features"="+32bit,+a,+c,+m,+relax,
-// RV32-SAME: -save-restore
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,
-// RV64-SAME: -save-restore
 
 // Dummy function
 int foo(void){

diff  --git a/clang/test/Driver/riscv-features.c 
b/clang/test/Driver/riscv-features.c
index 716f3f6da57b88..d3700f71aa7e1d 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -24,7 +24,7 @@
 
 // SAVE-RESTORE: "-target-feature" "+save-restore"
 // NO-SAVE-RESTORE: "-target-feature" "-save-restore"
-// DEFAULT: "-target-feature" "-save-restore"
+// DEFAULT-NOT: "-target-feature" "-save-restore"
 // DEFAULT-NOT: "-target-feature" "+save-restore"
 
 // RUN: %clang --target=riscv32-unknown-elf -### %s -munaligned-access 2>&1 | 
FileCheck %s -check-prefix=FAST-UNALIGNED-ACCESS



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


[clang] [llvm] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

2023-12-26 Thread Kito Cheng via cfe-commits


@@ -693,6 +693,13 @@ def HasStdExtZimop : 
Predicate<"Subtarget->hasStdExtZimop()">,
AssemblerPredicate<(all_of FeatureStdExtZimop),
"'Zimop' (May-Be-Operations)">;
 
+def FeatureStdExtZcmop : SubtargetFeature<"experimental-zcmop", 
"HasStdExtZcmop", "true",
+  "'Zcmop' (Compressed 
May-Be-Operations)",
+  [FeatureStdExtZca]>;

kito-cheng wrote:

My understanding for those terminology on RISC-V ISA spec is: imply == depend 
== require

See comment from Krste and Andrew in this issue: 
https://github.com/riscv/riscv-v-spec/issues/723#issuecomment-922153867

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


[llvm] [clang] [X86] Correct operand order of UWRMSR. (PR #76389)

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

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


[clang] 8ddb0fc - [X86] Correct operand order of UWRMSR. (#76389)

2023-12-26 Thread via cfe-commits

Author: Freddy Ye
Date: 2023-12-27T09:01:55+08:00
New Revision: 8ddb0fcff9ec73aeef20b1288b4ab5e03cd0bd56

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

LOG: [X86] Correct operand order of UWRMSR. (#76389)

Added: 


Modified: 
clang/lib/Headers/usermsrintrin.h
llvm/lib/Target/X86/X86InstrSystem.td
llvm/test/CodeGen/X86/usermsr-intrinsics.ll

Removed: 




diff  --git a/clang/lib/Headers/usermsrintrin.h 
b/clang/lib/Headers/usermsrintrin.h
index 6d1424ad3b2edd..61388376706dc6 100644
--- a/clang/lib/Headers/usermsrintrin.h
+++ b/clang/lib/Headers/usermsrintrin.h
@@ -14,12 +14,33 @@
 #define __USERMSRINTRIN_H
 #ifdef __x86_64__
 
+/// Reads the contents of a 64-bit MSR specified in \a __A into \a dst.
+///
+/// This intrinsic corresponds to the  URDMSR  instruction.
+/// \param __A
+///An unsigned long long.
+///
+/// \code{.operation}
+///DEST := MSR[__A]
+/// \endcode
 static __inline__ unsigned long long
 __attribute__((__always_inline__, __nodebug__, __target__("usermsr")))
 _urdmsr(unsigned long long __A) {
   return __builtin_ia32_urdmsr(__A);
 }
 
+/// Writes the contents of \a __B into the 64-bit MSR specified in \a __A.
+///
+/// This intrinsic corresponds to the  UWRMSR  instruction.
+///
+/// \param __A
+///An unsigned long long.
+/// \param __B
+///An unsigned long long.
+///
+/// \code{.operation}
+///MSR[__A] := __B
+/// \endcode
 static __inline__ void
 __attribute__((__always_inline__, __nodebug__, __target__("usermsr")))
 _uwrmsr(unsigned long long __A, unsigned long long __B) {

diff  --git a/llvm/lib/Target/X86/X86InstrSystem.td 
b/llvm/lib/Target/X86/X86InstrSystem.td
index efb58c6102dd1d..699e5847e63fb9 100644
--- a/llvm/lib/Target/X86/X86InstrSystem.td
+++ b/llvm/lib/Target/X86/X86InstrSystem.td
@@ -446,11 +446,11 @@ let Predicates = [HasUSERMSR], mayLoad = 1 in {
 }
 let Predicates = [HasUSERMSR], mayStore = 1 in {
   def UWRMSRrr : I<0xf8, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
-"uwrmsr\t{$src1, $src2|$src2, $src1}",
+"uwrmsr\t{$src2, $src1|$src1, $src2}",
 [(int_x86_uwrmsr GR64:$src1, GR64:$src2)]>, T8, XS;
   def UWRMSRir : Ii32<0xf8, MRM0r, (outs), (ins GR64:$src, i64i32imm:$imm),
 "uwrmsr\t{$src, $imm|$imm, $src}",
-[(int_x86_uwrmsr GR64:$src, i64immSExt32_su:$imm)]>, T_MAP7, 
XS, VEX;
+[(int_x86_uwrmsr i64immSExt32_su:$imm, GR64:$src)]>, T_MAP7, 
XS, VEX;
 }
 let Defs = [RAX, RDX], Uses = [ECX] in
 def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", []>, TB;

diff  --git a/llvm/test/CodeGen/X86/usermsr-intrinsics.ll 
b/llvm/test/CodeGen/X86/usermsr-intrinsics.ll
index 29801a494f498f..fa569affdd9ff3 100644
--- a/llvm/test/CodeGen/X86/usermsr-intrinsics.ll
+++ b/llvm/test/CodeGen/X86/usermsr-intrinsics.ll
@@ -35,7 +35,7 @@ declare i64 @llvm.x86.urdmsr(i64 %A)
 define void @test_int_x86_uwrmsr(i64 %A, i64 %B) nounwind {
 ; X64-LABEL: test_int_x86_uwrmsr:
 ; X64:   # %bb.0:
-; X64-NEXT:uwrmsr %rdi, %rsi # encoding: [0xf3,0x0f,0x38,0xf8,0xfe]
+; X64-NEXT:uwrmsr %rsi, %rdi # encoding: [0xf3,0x0f,0x38,0xf8,0xfe]
 ; X64-NEXT:retq # encoding: [0xc3]
   call void @llvm.x86.uwrmsr(i64 %A, i64 %B)
   ret void
@@ -46,7 +46,7 @@ define void @test_int_x86_uwrmsr_const(i64 %A) nounwind {
 ; X64:   # %bb.0:
 ; X64-NEXT:uwrmsr %rdi, $123 # encoding: 
[0xc4,0xe7,0x7a,0xf8,0xc7,0x7b,0x00,0x00,0x00]
 ; X64-NEXT:retq # encoding: [0xc3]
-  call void @llvm.x86.uwrmsr(i64 %A, i64 123)
+  call void @llvm.x86.uwrmsr(i64 123, i64 %A)
   ret void
 }
 
@@ -55,9 +55,9 @@ define void @test_int_x86_uwrmsr_const_i64(i64 %A) nounwind {
 ; X64:   # %bb.0:
 ; X64-NEXT:movabsq $8589934591, %rax # encoding: 
[0x48,0xb8,0xff,0xff,0xff,0xff,0x01,0x00,0x00,0x00]
 ; X64-NEXT:# imm = 0x1
-; X64-NEXT:uwrmsr %rdi, %rax # encoding: [0xf3,0x0f,0x38,0xf8,0xf8]
+; X64-NEXT:uwrmsr %rdi, %rax # encoding: [0xf3,0x0f,0x38,0xf8,0xc7]
 ; X64-NEXT:retq # encoding: [0xc3]
-  call void @llvm.x86.uwrmsr(i64 %A, i64 8589934591)
+  call void @llvm.x86.uwrmsr(i64 8589934591, i64 %A)
   ret void
 }
 



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


[clang] [clang-cl] document correct defaults for `-fms-compatibility-version` / `-fmsc-version` (PR #76418)

2023-12-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (h-vetinari)


Changes

The UserManual states wrongly (AFAICT) that these default are not being defined 
for clang-cl, whereas further up the opposite is stated:

https://github.com/llvm/llvm-project/blob/c86fe3ee0b92934f5d18394d9a0cdc1d3f0eef64/clang/docs/UsersManual.rst#L3375-L3382

I've chosen to follow that wording, as it's the latest related update.

CC @RIscRIpt who recently touched this in 
b3e6ff331925dde24a4707452d657da0fdf7f588
CC @AaronBallman who cared about this, c.f. 
8fc0dcf036bf199b2af2e10a4f81215dbd706daf

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


2 Files Affected:

- (modified) clang/docs/CommandGuide/clang.rst (+1-1) 
- (modified) clang/docs/UsersManual.rst (+2-2) 


``diff
diff --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index e1c872cdc55396..643365215f8759 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -302,7 +302,7 @@ Language Selection and Mode Options
 .. option:: -fmsc-version=
 
  Set ``_MSC_VER``. When on Windows, this defaults to either the same value as
- the currently installed version of cl.exe, or ``1920``. Not set otherwise.
+ the currently installed version of cl.exe, or ``1933``. Not set otherwise.
 
 .. option:: -fborland-extensions
 
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 7c30570437e8b0..32f25be54f5d54 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -4382,11 +4382,11 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   -fmerge-all-constants   Allow merging of constants
   -fms-compatibility-version=
   Dot-separated value representing the Microsoft 
compiler version
-  number to report in _MSC_VER (0 = don't define 
it (default))
+  number to report in _MSC_VER (0 = don't define 
it; default is same value as installed cl.exe, or 1933)
   -fms-compatibility  Enable full Microsoft Visual C++ compatibility
   -fms-extensions Accept some non-standard constructs supported by 
the Microsoft compiler
   -fmsc-version=   Microsoft compiler version number to report in 
_MSC_VER
-  (0 = don't define it (default))
+  (0 = don't define it; default is same value as 
installed cl.exe, or 1933)
   -fno-addrsigDon't emit an address-significance table
   -fno-builtin-Disable implicit builtin knowledge of a specific 
function
   -fno-builtinDisable implicit builtin knowledge of functions

``




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


[clang] [clang-cl] document correct defaults for `-fms-compatibility-version` / `-fmsc-version` (PR #76418)

2023-12-26 Thread via cfe-commits

https://github.com/h-vetinari created 
https://github.com/llvm/llvm-project/pull/76418

The UserManual states wrongly (AFAICT) that these default are not being defined 
for clang-cl, whereas further up the opposite is stated:

https://github.com/llvm/llvm-project/blob/c86fe3ee0b92934f5d18394d9a0cdc1d3f0eef64/clang/docs/UsersManual.rst#L3375-L3382

I've chosen to follow that wording, as it's the latest related update.

CC @RIscRIpt who recently touched this in 
b3e6ff331925dde24a4707452d657da0fdf7f588
CC @AaronBallman who cared about this, c.f. 
8fc0dcf036bf199b2af2e10a4f81215dbd706daf

>From fe16613834b12fc8fc358ba02bc198fa24fa9e3e Mon Sep 17 00:00:00 2001
From: "H. Vetinari" 
Date: Wed, 27 Dec 2023 10:58:20 +1100
Subject: [PATCH] [clang-cl] document correct defaults for
 `-fms-compatibility-version` / `-fmsc-version`

---
 clang/docs/CommandGuide/clang.rst | 2 +-
 clang/docs/UsersManual.rst| 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index e1c872cdc55396..643365215f8759 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -302,7 +302,7 @@ Language Selection and Mode Options
 .. option:: -fmsc-version=
 
  Set ``_MSC_VER``. When on Windows, this defaults to either the same value as
- the currently installed version of cl.exe, or ``1920``. Not set otherwise.
+ the currently installed version of cl.exe, or ``1933``. Not set otherwise.
 
 .. option:: -fborland-extensions
 
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 7c30570437e8b0..32f25be54f5d54 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -4382,11 +4382,11 @@ Execute ``clang-cl /?`` to see a list of supported 
options:
   -fmerge-all-constants   Allow merging of constants
   -fms-compatibility-version=
   Dot-separated value representing the Microsoft 
compiler version
-  number to report in _MSC_VER (0 = don't define 
it (default))
+  number to report in _MSC_VER (0 = don't define 
it; default is same value as installed cl.exe, or 1933)
   -fms-compatibility  Enable full Microsoft Visual C++ compatibility
   -fms-extensions Accept some non-standard constructs supported by 
the Microsoft compiler
   -fmsc-version=   Microsoft compiler version number to report in 
_MSC_VER
-  (0 = don't define it (default))
+  (0 = don't define it; default is same value as 
installed cl.exe, or 1933)
   -fno-addrsigDon't emit an address-significance table
   -fno-builtin-Disable implicit builtin knowledge of a specific 
function
   -fno-builtinDisable implicit builtin knowledge of functions

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


[clang] [llvm] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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


@@ -0,0 +1,30 @@
+//===-- RISCVInstrInfoZcmop.td -*- tablegen 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file describes the RISC-V instructions from the standard Compressed
+// May-Be-Operations Extension (Zcmop).
+// This version is still experimental as the 'Zcmop' extension hasn't been
+// ratified yet. It is based on v0.2 of the specification.
+//
+//===--===//
+
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
+class CMOPInst imm3, string opcodestr>
+: RVInst16CI<0b011, 0b01, (outs), (ins), opcodestr, ""> {
+  let Inst{6-2} = 0;
+  let Inst{7} = 1;
+  let Inst{10-8} = imm3;
+  let Inst{12-11} = 0;
+}
+
+foreach i = 0...7 in {
+let Predicates = [HasStdExtZcmop, HasStdExtCOrZca] in {

topperc wrote:

Reduce indentation to 2 spaces

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


[clang] [llvm] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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


@@ -693,6 +693,13 @@ def HasStdExtZimop : 
Predicate<"Subtarget->hasStdExtZimop()">,
AssemblerPredicate<(all_of FeatureStdExtZimop),
"'Zimop' (May-Be-Operations)">;
 
+def FeatureStdExtZcmop : SubtargetFeature<"experimental-zcmop", 
"HasStdExtZcmop", "true",
+  "'Zcmop' (Compressed 
May-Be-Operations)",
+  [FeatureStdExtZca]>;

topperc wrote:

Any features implications in RISCV.td must also exist in RISCVISAInfo.cpp.

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


[clang] [llvm] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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


@@ -693,6 +693,13 @@ def HasStdExtZimop : 
Predicate<"Subtarget->hasStdExtZimop()">,
AssemblerPredicate<(all_of FeatureStdExtZimop),
"'Zimop' (May-Be-Operations)">;
 
+def FeatureStdExtZcmop : SubtargetFeature<"experimental-zcmop", 
"HasStdExtZcmop", "true",
+  "'Zcmop' (Compressed 
May-Be-Operations)",
+  [FeatureStdExtZca]>;

topperc wrote:

I think so. The specs have been very inconsistent on terminology. The 
fundamental issue is that the specs define hardware and don't think about how 
`-march` in tools works. What the spec is saying is that if your hardware 
supports Zcmop, it must support Zca.

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


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

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

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


[clang] [RISCV][Clang] Remove -save-restore from default features. (PR #76390)

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

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

LGTM

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


[clang] [clang][StaticAnalyzer] adding timingasafe* api calls interception. (PR #76414)

2023-12-26 Thread via cfe-commits

llvmbot wrote:



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

@llvm/pr-subscribers-clang

Author: David CARLIER (devnexen)


Changes

timingsafe_bcmp and timingsafe_memcmp have the same signature as their 
counterparts.

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


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp (+4) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 31f5b03dcdeba8..ee51bc5c10a126 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -134,6 +134,8 @@ class CStringChecker : public Checker< eval::Call,
std::bind(::evalMempcpy, _1, _2, _3, CK_Wide)},
   {{CDF_MaybeBuiltin, {"memcmp"}, 3},
std::bind(::evalMemcmp, _1, _2, _3, CK_Regular)},
+  {{CDF_MaybeBuiltin, {"timingsafe_memcmp"}, 3},
+   std::bind(::evalMemcmp, _1, _2, _3, CK_Regular)},
   {{CDF_MaybeBuiltin, {"wmemcmp"}, 3},
std::bind(::evalMemcmp, _1, _2, _3, CK_Wide)},
   {{CDF_MaybeBuiltin, {"memmove"}, 3},
@@ -162,6 +164,8 @@ class CStringChecker : public Checker< eval::Call,
   {{CDF_MaybeBuiltin, {"bcopy"}, 3}, ::evalBcopy},
   {{CDF_MaybeBuiltin, {"bcmp"}, 3},
std::bind(::evalMemcmp, _1, _2, _3, CK_Regular)},
+  {{CDF_MaybeBuiltin, {"timingsafe_bcmp"}, 3},
+   std::bind(::evalMemcmp, _1, _2, _3, CK_Regular)},
   {{CDF_MaybeBuiltin, {"bzero"}, 2}, ::evalBzero},
   {{CDF_MaybeBuiltin, {"explicit_bzero"}, 2}, ::evalBzero},
   {{CDF_MaybeBuiltin, {"sprintf"}, 2}, ::evalSprintf},

``




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


[clang] [clang][StaticAnalyzer] adding timingasafe* api calls interception. (PR #76414)

2023-12-26 Thread David CARLIER via cfe-commits

https://github.com/devnexen created 
https://github.com/llvm/llvm-project/pull/76414

timingsafe_bcmp and timingsafe_memcmp have the same signature as their 
counterparts.

>From eacd951c068cdc25b025a4234bc34e846a3676b1 Mon Sep 17 00:00:00 2001
From: David Carlier 
Date: Tue, 26 Dec 2023 22:22:32 +
Subject: [PATCH] [clang][StaticAnalyzer] adding timingasafe* api calls
 interception.

timingsafe_bcmp and timingsafe_memcmp have the same signature
as their counterparts.
---
 clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 31f5b03dcdeba8..ee51bc5c10a126 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -134,6 +134,8 @@ class CStringChecker : public Checker< eval::Call,
std::bind(::evalMempcpy, _1, _2, _3, CK_Wide)},
   {{CDF_MaybeBuiltin, {"memcmp"}, 3},
std::bind(::evalMemcmp, _1, _2, _3, CK_Regular)},
+  {{CDF_MaybeBuiltin, {"timingsafe_memcmp"}, 3},
+   std::bind(::evalMemcmp, _1, _2, _3, CK_Regular)},
   {{CDF_MaybeBuiltin, {"wmemcmp"}, 3},
std::bind(::evalMemcmp, _1, _2, _3, CK_Wide)},
   {{CDF_MaybeBuiltin, {"memmove"}, 3},
@@ -162,6 +164,8 @@ class CStringChecker : public Checker< eval::Call,
   {{CDF_MaybeBuiltin, {"bcopy"}, 3}, ::evalBcopy},
   {{CDF_MaybeBuiltin, {"bcmp"}, 3},
std::bind(::evalMemcmp, _1, _2, _3, CK_Regular)},
+  {{CDF_MaybeBuiltin, {"timingsafe_bcmp"}, 3},
+   std::bind(::evalMemcmp, _1, _2, _3, CK_Regular)},
   {{CDF_MaybeBuiltin, {"bzero"}, 2}, ::evalBzero},
   {{CDF_MaybeBuiltin, {"explicit_bzero"}, 2}, ::evalBzero},
   {{CDF_MaybeBuiltin, {"sprintf"}, 2}, ::evalSprintf},

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


[lld] [mlir] [clang] [llvm] [compiler-rt] [hwasan] Make stack variables output consistent with globals (PR #76197)

2023-12-26 Thread Vitaly Buka via cfe-commits

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


[clang] [clang-format] Fix handling of C-Style variable definition of a struct (PR #76344)

2023-12-26 Thread via cfe-commits

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


[clang] [clang-format] Fix handling of C-Style variable definition of a struct (PR #76344)

2023-12-26 Thread via cfe-commits

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


[clang-tools-extra] [clangd][SymbolCollector] Treat ObjC methods as spelled (PR #76410)

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

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

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

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

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

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

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

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

[clang-tools-extra] [clangd][SymbolCollector] Treat ObjC methods as spelled (PR #76410)

2023-12-26 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 8b485070844d03cda467e75aa8c924184ba671cf 
4caf5b3c779bf18236b4b0be5bc7147d10339f2b -- 
clang-tools-extra/clangd/index/SymbolCollector.cpp 
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp 
b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
index 1d4e1c1d75..5c20b950e4 100644
--- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
@@ -560,10 +560,12 @@ TEST_F(SymbolCollectorTest, ObjCRefs) {
   haveRanges(Main.ranges("talk");
   EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, "Person::say:").ID,
   haveRanges(Main.ranges("say");
-  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::categoryMethod").ID,
-  ElementsAre(isSpelled();
-  EXPECT_THAT(Refs, Contains(Pair(findSymbol(Symbols, 
"Person::multiArg:method:").ID,
-  ElementsAre(Not(isSpelled());
+  EXPECT_THAT(Refs,
+  Contains(Pair(findSymbol(Symbols, "Person::categoryMethod").ID,
+ElementsAre(isSpelled();
+  EXPECT_THAT(Refs,
+  Contains(Pair(findSymbol(Symbols, "Person::multiArg:method:").ID,
+ElementsAre(Not(isSpelled());
 }
 
 TEST_F(SymbolCollectorTest, ObjCSymbols) {

``




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


[clang-tools-extra] [clangd][SymbolCollector] Treat ObjC methods as spelled (PR #76410)

2023-12-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd

Author: David Goldman (DavidGoldman)


Changes

We'll treat multi-arg methods as spelled once we have full rename support for 
them.

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


2 Files Affected:

- (modified) clang-tools-extra/clangd/index/SymbolCollector.cpp (+5-1) 
- (modified) clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp (+42) 


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

``




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


[clang-tools-extra] [clangd][SymbolCollector] Treat ObjC methods as spelled (PR #76410)

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

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

We'll treat multi-arg methods as spelled once we have full rename support for 
them.

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

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

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

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


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

2023-12-26 Thread Jordan R AW via cfe-commits

ajordanr-google wrote:

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

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


[llvm] [libcxx] [clang] [mlir] [compiler-rt] [sanitizers] Optimize locking StackDepotBase for fork (PR #76280)

2023-12-26 Thread Vitaly Buka via cfe-commits

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


[clang] [llvm] [FuncAttrs] Infer `norecurse` for funcs with calls to `nocallback` callees (PR #76372)

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

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


[clang] 4358e6e - [FuncAttrs] Infer `norecurse` for funcs with calls to `nocallback` callees (#76372)

2023-12-26 Thread via cfe-commits

Author: Yingwei Zheng
Date: 2023-12-27T03:16:43+08:00
New Revision: 4358e6e0c5b1f08de60b6b2fb015a06ab6760ee7

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

LOG: [FuncAttrs] Infer `norecurse` for funcs with calls to `nocallback` callees 
(#76372)

This patch adds missing `norecurse` attrs to funcs that only call intrinsics 
with `nocallback` attrs.
Fixes the regression found in 
https://github.com/dtcxzyw/llvm-opt-benchmark/pull/45#discussion_r1436148743.
The function loses `norecurse` attr because it calls `@llvm.fabs.f64`, which is 
not marked as `norecurse`.

Since `norecurse` is not a default attribute of intrinsics and it is
ambiguous for intrinsics, I decided to use the existing `callback`
attributes.

> nocallback
This attribute indicates that the function is only allowed to jump back
into caller’s module by a return or an exception, and is not allowed to
jump back by invoking a callback function, a direct, possibly
transitive, external function call, use of longjmp, or other means. It
is a compiler hint that is used at module level to improve dataflow
analysis, dropped during linking, and has no effect on functions defined
in the current module.

See also https://llvm.org/docs/LangRef.html#function-attributes.

Added: 


Modified: 
clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
llvm/test/Transforms/FunctionAttrs/argmemonly.ll
llvm/test/Transforms/FunctionAttrs/convergent.ll
llvm/test/Transforms/FunctionAttrs/int_sideeffect.ll
llvm/test/Transforms/FunctionAttrs/make-buffer-rsrc.ll
llvm/test/Transforms/FunctionAttrs/nocapture.ll
llvm/test/Transforms/FunctionAttrs/nofree-attributor.ll
llvm/test/Transforms/FunctionAttrs/norecurse.ll
llvm/test/Transforms/FunctionAttrs/nosync.ll
llvm/test/Transforms/FunctionAttrs/readattrs.ll
llvm/test/Transforms/FunctionAttrs/writeonly.ll

Removed: 




diff  --git a/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c
index 9d95acc33dddcd..582d5fd812bc34 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c
@@ -21,19 +21,19 @@ unsigned long test_vlenb(void) {
   return __riscv_vlenb();
 }
 //.
-// RV32: attributes #0 = { mustprogress nofree noinline nosync nounwind 
willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" 
"target-features"="+32bit,+d,+f,+v,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
-// RV32: attributes #1 = { mustprogress nocallback nofree nosync nounwind 
willreturn memory(read) }
+// RV32: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree noinline 
norecurse nosync nounwind willreturn memory(read) vscale_range(2,1024) 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+32bit,+d,+f,+v,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
+// RV32: attributes #[[ATTR1:[0-9]+]] = { mustprogress nocallback nofree 
nosync nounwind willreturn memory(read) }
 //.
-// RV64: attributes #0 = { mustprogress nofree noinline nosync nounwind 
willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" 
"target-features"="+64bit,+d,+f,+v,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
-// RV64: attributes #1 = { mustprogress nocallback nofree nosync nounwind 
willreturn memory(read) }
+// RV64: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree noinline 
norecurse nosync nounwind willreturn memory(read) vscale_range(2,1024) 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+64bit,+d,+f,+v,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
+// RV64: attributes #[[ATTR1:[0-9]+]] = { mustprogress nocallback nofree 
nosync nounwind willreturn memory(read) }
 //.
-// RV32: !0 = !{i32 1, !"wchar_size", i32 4}
-// RV32: !1 = !{i32 1, !"target-abi", !"ilp32d"}
-// RV32: !2 = !{i32 8, !"SmallDataLimit", i32 0}
-// RV32: !3 = !{!"vlenb"}
+// RV32: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// RV32: [[META1:![0-9]+]] = !{i32 1, !"target-abi", !"ilp32d"}
+// RV32: [[META2:![0-9]+]] = !{i32 8, !"SmallDataLimit", i32 0}
+// RV32: [[META3]] = !{!"vlenb"}
 //.
-// RV64: !0 = !{i32 1, !"wchar_size", i32 4}
-// RV64: !1 = !{i32 1, !"target-abi", !"lp64d"}
-// RV64: !2 = !{i32 8, !"SmallDataLimit", i32 0}
-// RV64: !3 = !{!"vlenb"}
+// RV64: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// RV64: [[META1:![0-9]+]] = !{i32 1, !"target-abi", !"lp64d"}
+// RV64: 

[clang] [libcxx] [llvm] [mlir] [compiler-rt] [sanitizers] Optimize locking StackDepotBase for fork (PR #76280)

2023-12-26 Thread Kirill Stoimenov via cfe-commits

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


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


[libcxx] [clang] [mlir] [clang-tools-extra] [flang] [libc] [compiler-rt] [llvm] [mlir][Linalg] Support dynamic tiles in `lower_pack` transform (PR #76003)

2023-12-26 Thread via cfe-commits

https://github.com/srcarroll updated 
https://github.com/llvm/llvm-project/pull/76003

>From 860a2f794bdf12ff1f08d4802570757e805264b0 Mon Sep 17 00:00:00 2001
From: Sam 
Date: Mon, 18 Dec 2023 15:53:41 -0600
Subject: [PATCH 1/8] [mlir][Linalg] Support dynamic sizes in `lower_pack`
 transform

---
 .../Linalg/TransformOps/LinalgTransformOps.td |  3 +-
 .../Dialect/Linalg/Transforms/Transforms.h|  2 +-
 .../Dialect/Linalg/Transforms/Transforms.cpp  | 69 +--
 .../Dialect/Linalg/transform-lower-pack.mlir  | 20 ++
 4 files changed, 70 insertions(+), 24 deletions(-)

diff --git 
a/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td 
b/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
index 77ed9db5e71bd1..4abd3740b57105 100644
--- a/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
+++ b/mlir/include/mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td
@@ -498,7 +498,8 @@ def LowerPackOp : Op:$target);
   let results = (outs Transform_ConcreteOpType<"tensor.pad">:$pad_op,
-  
Transform_ConcreteOpType<"tensor.expand_shape">:$expand_shape_op,
+  
Type.predicate,
+   
Transform_ConcreteOpType<"tensor.reshape">.predicate]>>:$expand_shape_op,
   
Transform_ConcreteOpType<"linalg.transpose">:$transpose_op);
   let assemblyFormat = [{
 $target attr-dict `:` functional-type(operands, results)
diff --git a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h 
b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
index a848d12fbbb50e..344e801835ccc9 100644
--- a/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
+++ b/mlir/include/mlir/Dialect/Linalg/Transforms/Transforms.h
@@ -1089,7 +1089,7 @@ collapseOpIterationDims(LinalgType op,
 
 struct LowerPackResult {
   tensor::PadOp padOp;
-  tensor::ExpandShapeOp expandShapeOp;
+  Operation *expandShapeOp;
   linalg::TransposeOp transposeOp;
 };
 
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp 
b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
index 9d230e2c2e5749..359274866748fc 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
@@ -218,21 +218,11 @@ struct PackedOperandsDimList {
 
 FailureOr linalg::lowerPack(RewriterBase ,
  tensor::PackOp packOp) {
-  // 1. Filter out NYI cases.
-  auto packedTensorType =
-  cast(packOp->getResultTypes().front());
-  if (llvm::any_of(packOp.getStaticInnerTiles(),
-   [](int64_t size) { return ShapedType::isDynamic(size); })) {
-return rewriter.notifyMatchFailure(
-packOp,
-"non-static shape NYI, needs a more powerful tensor.expand_shape op");
-  }
-
   Location loc = packOp->getLoc();
   OpBuilder::InsertionGuard g(rewriter);
   rewriter.setInsertionPoint(packOp);
 
-  // 2. Compute the permutation vector to shuffle packed shape into the shape
+  // 1. Compute the permutation vector to shuffle packed shape into the shape.
   // before any outer or inner permutations have been applied. The permutation
   // can be obtained from two permutations:
   //   a) Compute the permutation vector to move the last `numPackedDims` into
@@ -240,6 +230,8 @@ FailureOr linalg::lowerPack(RewriterBase 
,
   //   b) Compute the permutation vector to move outer dims if the pack op
   //  has outer_dims_perm.
   // Apply (b) permutation on (a) permutation to get the final permutation.
+  auto packedTensorType =
+  cast(packOp->getResultTypes().front());
   int64_t numPackedDims = packOp.getInnerDimsPos().size();
   int64_t packedRank = packedTensorType.getRank();
   auto lastDims = llvm::to_vector(
@@ -259,12 +251,12 @@ FailureOr linalg::lowerPack(RewriterBase 
,
   SmallVector packedToStripMinedShapePerm = innerPositionsPerm;
   applyPermutationToVector(packedToStripMinedShapePerm, outerPositionPerm);
 
-  // 3. Compute the stripMinedShape: this is the packed shape before any outer
+  // 2. Compute the stripMinedShape: this is the packed shape before any outer.
   // or inner permutations have been applied.
   SmallVector stripMinedShape(packedTensorType.getShape());
   applyPermutationToVector(stripMinedShape, packedToStripMinedShapePerm);
 
-  // 4. Pad the source of packOp to a shape we can expand into stripMinedShape.
+  // 3. Pad the source of packOp to a shape we can expand into stripMinedShape.
   SmallVector lows(packOp.getSourceRank(),
  rewriter.getIndexAttr(0));
   SmallVector highs(packOp.getSourceRank(),
@@ -351,24 +343,57 @@ FailureOr linalg::lowerPack(RewriterBase 
,
  /*transposeOp=*/nullptr};
 }
   }
-  // 5. Expand from the padded result to the stripMinedShape.
-  auto reshapeOp = rewriter.create(
-  loc,
-  RankedTensorType::Builder(packedTensorType).setShape(stripMinedShape),
-  padOp.getResult(), 

[clang] [clang-format] Fix handling of C-Style variable definition of a struct (PR #76344)

2023-12-26 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/76344

>From a55c720f344645bdad3838aaa39b136c8b8ee6dc Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sun, 24 Dec 2023 20:18:02 -0300
Subject: [PATCH 1/3] [clang-format] Fix handling of C-Style variable
 definition of a struct

---
 clang/lib/Format/UnwrappedLineParser.cpp  | 8 
 clang/unittests/Format/FormatTest.cpp | 1 +
 clang/unittests/Format/TokenAnnotatorTest.cpp | 6 ++
 3 files changed, 15 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 684609747a5513..9cacb0d175adae 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3873,6 +3873,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   const FormatToken  = *FormatTok;
   nextToken();
 
+  int NonMacroIdentifierCount = 0;
   // The actual identifier can be a nested name specifier, and in macros
   // it is often token-pasted.
   // An [[attribute]] can be before the identifier.
@@ -3898,6 +3899,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 FormatTok->is(tok::identifier) &&
 FormatTok->TokenText != FormatTok->TokenText.upper();
 nextToken();
+if (IsNonMacroIdentifier)
+  ++NonMacroIdentifierCount;
 // We can have macros in between 'class' and the class name.
 if (!IsNonMacroIdentifier && FormatTok->is(tok::l_paren))
   parseParens();
@@ -3960,6 +3963,11 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 }
   };
   if (FormatTok->is(tok::l_brace)) {
+// Handles C-Style variable declaration of a struct
+if (Style.isCpp() && NonMacroIdentifierCount == 2) {
+  parseBracedList();
+  return;
+}
 auto [OpenBraceType, ClosingBraceType] = GetBraceTypes(InitialToken);
 FormatTok->setFinalizedType(OpenBraceType);
 if (ParseAsExpr) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 762fc8254bdfc9..d37d1f58b51a4a 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14548,6 +14548,7 @@ TEST_F(FormatTest, 
UnderstandContextOfRecordTypeKeywords) {
   verifyFormat("struct foo f() {}\nint n;");
   verifyFormat("class foo f() {}\nint n;");
   verifyFormat("union foo f() {}\nint n;");
+  verifyFormat("struct MACRO foo f{};");
 
   // Templates.
   verifyFormat("template  void f() {}\nint n;");
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 2cafc0438ffb46..568574bf73a872 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -503,6 +503,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsVariables) {
   annotate("inline bool var = is_integral_v && is_signed_v;");
   EXPECT_EQ(Tokens.size(), 15u) << Tokens;
   EXPECT_TOKEN(Tokens[8], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("struct Foo f{};");
+  EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_StartOfName);
+  EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_Unknown);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsVariableTemplates) {

>From 9e2e88495e86f040aeca2a0f0bc69bff3e6986e4 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Tue, 26 Dec 2023 14:11:09 -0300
Subject: [PATCH 2/3] Added support for templated structs

---
 clang/lib/Format/UnwrappedLineParser.cpp  | 13 +
 clang/unittests/Format/FormatTest.cpp |  3 ++-
 clang/unittests/Format/TokenAnnotatorTest.cpp |  6 ++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 9cacb0d175adae..e79eefd530451b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3917,6 +3917,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   // (this would still leave us with an ambiguity between template function
   // and class declarations).
   if (FormatTok->isOneOf(tok::colon, tok::less)) {
+int AngleNestingLevel = 0;
+bool ColonFound = false;
 do {
   if (FormatTok->is(tok::l_brace)) {
 calculateBraceTypes(/*ExpectClassBody=*/true);
@@ -3944,6 +3946,17 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 parseCSharpGenericTypeConstraint();
 break;
   }
+  // Do not count identifiers inside a template angle brackets
+  if(FormatTok->is(tok::colon))
+ColonFound = true;
+  if (FormatTok->is(tok::less))
+++AngleNestingLevel;
+  else if (FormatTok->is(tok::greater))
+--AngleNestingLevel;
+  if (AngleNestingLevel == 0 && !ColonFound && 
FormatTok->is(tok::identifier) &&
+  FormatTok->TokenText != FormatTok->TokenText.upper()) {
+++NonMacroIdentifierCount;

[clang] [clang-format] Fix handling of C-Style variable definition of a struct (PR #76344)

2023-12-26 Thread via cfe-commits

https://github.com/XDeme updated https://github.com/llvm/llvm-project/pull/76344

>From a55c720f344645bdad3838aaa39b136c8b8ee6dc Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Sun, 24 Dec 2023 20:18:02 -0300
Subject: [PATCH 1/2] [clang-format] Fix handling of C-Style variable
 definition of a struct

---
 clang/lib/Format/UnwrappedLineParser.cpp  | 8 
 clang/unittests/Format/FormatTest.cpp | 1 +
 clang/unittests/Format/TokenAnnotatorTest.cpp | 6 ++
 3 files changed, 15 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 684609747a5513..9cacb0d175adae 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3873,6 +3873,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   const FormatToken  = *FormatTok;
   nextToken();
 
+  int NonMacroIdentifierCount = 0;
   // The actual identifier can be a nested name specifier, and in macros
   // it is often token-pasted.
   // An [[attribute]] can be before the identifier.
@@ -3898,6 +3899,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 FormatTok->is(tok::identifier) &&
 FormatTok->TokenText != FormatTok->TokenText.upper();
 nextToken();
+if (IsNonMacroIdentifier)
+  ++NonMacroIdentifierCount;
 // We can have macros in between 'class' and the class name.
 if (!IsNonMacroIdentifier && FormatTok->is(tok::l_paren))
   parseParens();
@@ -3960,6 +3963,11 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 }
   };
   if (FormatTok->is(tok::l_brace)) {
+// Handles C-Style variable declaration of a struct
+if (Style.isCpp() && NonMacroIdentifierCount == 2) {
+  parseBracedList();
+  return;
+}
 auto [OpenBraceType, ClosingBraceType] = GetBraceTypes(InitialToken);
 FormatTok->setFinalizedType(OpenBraceType);
 if (ParseAsExpr) {
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 762fc8254bdfc9..d37d1f58b51a4a 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -14548,6 +14548,7 @@ TEST_F(FormatTest, 
UnderstandContextOfRecordTypeKeywords) {
   verifyFormat("struct foo f() {}\nint n;");
   verifyFormat("class foo f() {}\nint n;");
   verifyFormat("union foo f() {}\nint n;");
+  verifyFormat("struct MACRO foo f{};");
 
   // Templates.
   verifyFormat("template  void f() {}\nint n;");
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 2cafc0438ffb46..568574bf73a872 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -503,6 +503,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsVariables) {
   annotate("inline bool var = is_integral_v && is_signed_v;");
   EXPECT_EQ(Tokens.size(), 15u) << Tokens;
   EXPECT_TOKEN(Tokens[8], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("struct Foo f{};");
+  EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[1], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_StartOfName);
+  EXPECT_TOKEN(Tokens[3], tok::l_brace, TT_Unknown);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsVariableTemplates) {

>From 9e2e88495e86f040aeca2a0f0bc69bff3e6986e4 Mon Sep 17 00:00:00 2001
From: XDeme 
Date: Tue, 26 Dec 2023 14:11:09 -0300
Subject: [PATCH 2/2] Added support for templated structs

---
 clang/lib/Format/UnwrappedLineParser.cpp  | 13 +
 clang/unittests/Format/FormatTest.cpp |  3 ++-
 clang/unittests/Format/TokenAnnotatorTest.cpp |  6 ++
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 9cacb0d175adae..e79eefd530451b 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3917,6 +3917,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
   // (this would still leave us with an ambiguity between template function
   // and class declarations).
   if (FormatTok->isOneOf(tok::colon, tok::less)) {
+int AngleNestingLevel = 0;
+bool ColonFound = false;
 do {
   if (FormatTok->is(tok::l_brace)) {
 calculateBraceTypes(/*ExpectClassBody=*/true);
@@ -3944,6 +3946,17 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
 parseCSharpGenericTypeConstraint();
 break;
   }
+  // Do not count identifiers inside a template angle brackets
+  if(FormatTok->is(tok::colon))
+ColonFound = true;
+  if (FormatTok->is(tok::less))
+++AngleNestingLevel;
+  else if (FormatTok->is(tok::greater))
+--AngleNestingLevel;
+  if (AngleNestingLevel == 0 && !ColonFound && 
FormatTok->is(tok::identifier) &&
+  FormatTok->TokenText != FormatTok->TokenText.upper()) {
+++NonMacroIdentifierCount;

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

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

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

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

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

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

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

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


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

owenca wrote:

```suggestion
  Path = convert_to_slash(IgnoreDir);
  append(Path, Style::posix, Pattern);
  remove_dots(Path, /*remove_dot_dot=*/true, Style::posix);
  Pattern = Path.str();
```

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


[llvm] [clang] [FuncAttrs] Infer `norecurse` for funcs with calls to `nocallback` callees (PR #76372)

2023-12-26 Thread Nikita Popov via cfe-commits

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

LGTM

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


[clang-tools-extra] [clang-tidy] Treat fields in anonymous records as names in enclosing scope when checking name styles (PR #75701)

2023-12-26 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] aca3727 - [clang-tidy] Treat fields in anonymous records as names in enclosing scope when checking name styles (#75701)

2023-12-26 Thread via cfe-commits

Author: Sirui Mu
Date: 2023-12-26T15:49:41+01:00
New Revision: aca3727e97bced3e98f8e0719de95c93034a97d2

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

LOG: [clang-tidy] Treat fields in anonymous records as names in enclosing scope 
when checking name styles (#75701)

Currently, fields in anonymous records are treated as normal record
members during naming style check. This can be undesirable in certain
situations since these fields are used just like names in their
enclosing scopes:

```c++
class Foo {
  union {
int iv_;// warning: invalid case style for public member 'iv_'
float fv_;  // warning: invalid case style for public member 'fv_'
  };
};
```

`iv_` and `fv_` are used in the code like private members of `Foo` but
their naming style comes from rules for public members.

This PR changes this behavior. It adds a new option
`CheckAnonFieldInParent` to `readability-identifier-naming`. When set to
`true`, fields in anonymous records will be treated as names in their
enclosing scopes when checking name styles. Specifically:

- If the anonymous record is defined within the file scope or in a
namespace scope, treat its fields as global variables when checking name
styles;
- If the anonymous record is defined within a function, treat its fields
as local variables when checking name styles;
- If the anonymous record is defined within a non-anonymous record,
treat its fields as non-static record members when checking name styles.

Added: 

clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-anon-record-fields.cpp

Modified: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
clang-tools-extra/clang-tidy/utils/ASTUtils.cpp
clang-tools-extra/clang-tidy/utils/ASTUtils.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 03dcfa5f811095..e6f44dd51b4596 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -9,6 +9,7 @@
 #include "IdentifierNamingCheck.h"
 
 #include "../GlobList.h"
+#include "../utils/ASTUtils.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
@@ -286,7 +287,9 @@ IdentifierNamingCheck::FileStyle 
IdentifierNamingCheck::getFileStyleFromOptions(
 HPTOpt.value_or(IdentifierNamingCheck::HPT_Off));
   }
   bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);
-  return {std::move(Styles), std::move(HNOption), IgnoreMainLike};
+  bool CheckAnonFieldInParent = Options.get("CheckAnonFieldInParent", false);
+  return {std::move(Styles), std::move(HNOption), IgnoreMainLike,
+  CheckAnonFieldInParent};
 }
 
 std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
@@ -859,6 +862,8 @@ void 
IdentifierNamingCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "IgnoreFailedSplit", IgnoreFailedSplit);
   Options.store(Opts, "IgnoreMainLikeFunctions",
 MainFileStyle->isIgnoringMainLikeFunction());
+  Options.store(Opts, "CheckAnonFieldInParent",
+MainFileStyle->isCheckingAnonFieldInParentScope());
 }
 
 bool IdentifierNamingCheck::matchesStyle(
@@ -,7 +1116,7 @@ std::string IdentifierNamingCheck::fixupWithStyle(
 StyleKind IdentifierNamingCheck::findStyleKind(
 const NamedDecl *D,
 ArrayRef> NamingStyles,
-bool IgnoreMainLikeFunctions) const {
+bool IgnoreMainLikeFunctions, bool CheckAnonFieldInParentScope) const {
   assert(D && D->getIdentifier() && !D->getName().empty() && !D->isImplicit() 
&&
  "Decl must be an explicit identifier with a name.");
 
@@ -1185,29 +1190,14 @@ StyleKind IdentifierNamingCheck::findStyleKind(
   }
 
   if (const auto *Decl = dyn_cast(D)) {
-QualType Type = Decl->getType();
-
-if (!Type.isNull() && Type.isConstQualified()) {
-  if (NamingStyles[SK_ConstantMember])
-return SK_ConstantMember;
-
-  if (NamingStyles[SK_Constant])
-return SK_Constant;
+if (CheckAnonFieldInParentScope) {
+  const RecordDecl *Record = Decl->getParent();
+  if (Record->isAnonymousStructOrUnion()) {
+return findStyleKindForAnonField(Decl, NamingStyles);
+  }
 }
 
-if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMember])
-  return SK_PrivateMember;
-
-if (Decl->getAccess() == AS_protected && NamingStyles[SK_ProtectedMember])
-  

[clang] [llvm] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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


@@ -693,6 +693,13 @@ def HasStdExtZimop : 
Predicate<"Subtarget->hasStdExtZimop()">,
AssemblerPredicate<(all_of FeatureStdExtZimop),
"'Zimop' (May-Be-Operations)">;
 
+def FeatureStdExtZcmop : SubtargetFeature<"experimental-zcmop", 
"HasStdExtZcmop", "true",
+  "'Zcmop' (Compressed 
May-Be-Operations)",
+  [FeatureStdExtZca]>;

yetingk wrote:

The spec says Zcmop requires Zca. Is this means Zcmop imply Zca? I am not sure 
with this.

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


[llvm] [clang] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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

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


[clang] [llvm] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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

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


[clang] [llvm] [FuncAttrs] Infer `norecurse` for funcs with calls to `nocallback` callees (PR #76372)

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

dtcxzyw wrote:

> There is a failing clang test.

Fixed.

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


[clang] [llvm] [FuncAttrs] Infer `norecurse` for funcs with calls to `nocallback` callees (PR #76372)

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

https://github.com/dtcxzyw updated 
https://github.com/llvm/llvm-project/pull/76372

>From 5ceb22715cdcfc52b77b451110295ea083c09327 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Tue, 26 Dec 2023 05:10:06 +0800
Subject: [PATCH] [FuncAttrs] Infer `norecurse` for funcs with calls to
 `nocallback` callees

---
 .../RISCV/rvv-intrinsics-handcrafted/vlenb.c  | 24 +--
 llvm/lib/Transforms/IPO/FunctionAttrs.cpp |  5 +++-
 .../TypeBasedAliasAnalysis/functionattrs.ll   | 12 --
 .../Transforms/FunctionAttrs/argmemonly.ll|  6 ++---
 .../Transforms/FunctionAttrs/convergent.ll|  2 +-
 .../FunctionAttrs/int_sideeffect.ll   |  4 ++--
 .../FunctionAttrs/make-buffer-rsrc.ll |  2 +-
 .../Transforms/FunctionAttrs/nocapture.ll | 16 ++---
 .../FunctionAttrs/nofree-attributor.ll|  4 ++--
 .../Transforms/FunctionAttrs/norecurse.ll | 17 ++---
 llvm/test/Transforms/FunctionAttrs/nosync.ll  |  6 ++---
 .../Transforms/FunctionAttrs/readattrs.ll |  4 ++--
 .../Transforms/FunctionAttrs/writeonly.ll | 18 +++---
 13 files changed, 61 insertions(+), 59 deletions(-)

diff --git a/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c
index 9d95acc33dddcd..582d5fd812bc34 100644
--- a/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c
+++ b/clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/vlenb.c
@@ -21,19 +21,19 @@ unsigned long test_vlenb(void) {
   return __riscv_vlenb();
 }
 //.
-// RV32: attributes #0 = { mustprogress nofree noinline nosync nounwind 
willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" 
"target-features"="+32bit,+d,+f,+v,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
-// RV32: attributes #1 = { mustprogress nocallback nofree nosync nounwind 
willreturn memory(read) }
+// RV32: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree noinline 
norecurse nosync nounwind willreturn memory(read) vscale_range(2,1024) 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+32bit,+d,+f,+v,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
+// RV32: attributes #[[ATTR1:[0-9]+]] = { mustprogress nocallback nofree 
nosync nounwind willreturn memory(read) }
 //.
-// RV64: attributes #0 = { mustprogress nofree noinline nosync nounwind 
willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" 
"target-features"="+64bit,+d,+f,+v,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
-// RV64: attributes #1 = { mustprogress nocallback nofree nosync nounwind 
willreturn memory(read) }
+// RV64: attributes #[[ATTR0:[0-9]+]] = { mustprogress nofree noinline 
norecurse nosync nounwind willreturn memory(read) vscale_range(2,1024) 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-features"="+64bit,+d,+f,+v,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b"
 }
+// RV64: attributes #[[ATTR1:[0-9]+]] = { mustprogress nocallback nofree 
nosync nounwind willreturn memory(read) }
 //.
-// RV32: !0 = !{i32 1, !"wchar_size", i32 4}
-// RV32: !1 = !{i32 1, !"target-abi", !"ilp32d"}
-// RV32: !2 = !{i32 8, !"SmallDataLimit", i32 0}
-// RV32: !3 = !{!"vlenb"}
+// RV32: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// RV32: [[META1:![0-9]+]] = !{i32 1, !"target-abi", !"ilp32d"}
+// RV32: [[META2:![0-9]+]] = !{i32 8, !"SmallDataLimit", i32 0}
+// RV32: [[META3]] = !{!"vlenb"}
 //.
-// RV64: !0 = !{i32 1, !"wchar_size", i32 4}
-// RV64: !1 = !{i32 1, !"target-abi", !"lp64d"}
-// RV64: !2 = !{i32 8, !"SmallDataLimit", i32 0}
-// RV64: !3 = !{!"vlenb"}
+// RV64: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
+// RV64: [[META1:![0-9]+]] = !{i32 1, !"target-abi", !"lp64d"}
+// RV64: [[META2:![0-9]+]] = !{i32 8, !"SmallDataLimit", i32 0}
+// RV64: [[META3]] = !{!"vlenb"}
 //.
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp 
b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index 7c277518b21dbf..9ce9f8451a95fa 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -1629,7 +1629,10 @@ static void addNoRecurseAttrs(const SCCNodeSet ,
 for (auto  : BB.instructionsWithoutDebug())
   if (auto *CB = dyn_cast()) {
 Function *Callee = CB->getCalledFunction();
-if (!Callee || Callee == F || !Callee->doesNotRecurse())
+if (!Callee || Callee == F ||
+(!Callee->doesNotRecurse() &&
+ !(Callee->isDeclaration() &&
+   Callee->hasFnAttribute(Attribute::NoCallback
   // Function calls a potentially recursive function.
   return;
   }
diff --git a/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll 
b/llvm/test/Analysis/TypeBasedAliasAnalysis/functionattrs.ll
index 86e7f8c113d1d8..bea56a72bdeaef 

[clang] [llvm] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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

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


[clang] [llvm] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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


@@ -0,0 +1,30 @@
+//===-- RISCVInstrInfoZcmop.td -*- tablegen 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file describes the RISC-V instructions from the standard Compressed
+// May-Be-Operations Extension (Zcmop).
+// This version is still experimental as the 'Zcmop' extension hasn't been
+// ratified yet. It is based on v0.2 of the specification.
+//
+//===--===//
+
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
+class CMOPInst imm3, string opcodestr>
+: RVInst16CI<0b011, 0b01, (outs), (ins), opcodestr, ""> {
+  let Inst{6-2} = 0;
+  let Inst{7} = 1;
+  let Inst{10-8} = imm3;
+  let Inst{12-11} = 0;
+}
+
+foreach i = 0...7 in {
+let Predicates = [HasStdExtZcmop, HasStdExtCOrZca] in {

yetingk wrote:

`HasStdExtCOrZca` could be implied by `HasStdExtZcmop`, so I think you don't 
need list it.

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


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

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


@@ -0,0 +1,71 @@
+//===-- RISCVInstrInfoZicfiss.td - RISC-V Zicfiss -*- tablegen 
-*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+// Instruction class templates
+//===--===//
+
+class RVC_SSInst rs1val, RegisterClass reg_class, string opcodestr> :
+  RVInst16<(outs), (ins reg_class:$rs1), opcodestr, "$rs1", [], 
InstFormatOther> {
+  let Inst{15-13} = 0b011;
+  let Inst{12} = 0;
+  let Inst{11-7} = rs1val;
+  let Inst{6-2} = 0b0;
+  let Inst{1-0} = 0b01;
+  let DecoderMethod = "decodeCSSPushPopchk";
+}
+
+//===--===//
+// Instructions
+//===--===//
+
+let Predicates = [HasStdExtZicfiss] in {
+let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 1, mayStore = 0 
in
+def SSPOPCHK : RVInstI<0b100, OPC_SYSTEM, (outs), (ins GPRX1X5:$rs1), 
"sspopchk",

yetingk wrote:

Sorry, I will give a fix for this.

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


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

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


@@ -0,0 +1,71 @@
+//===-- RISCVInstrInfoZicfiss.td - RISC-V Zicfiss -*- tablegen 
-*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+// Instruction class templates
+//===--===//
+
+class RVC_SSInst rs1val, RegisterClass reg_class, string opcodestr> :
+  RVInst16<(outs), (ins reg_class:$rs1), opcodestr, "$rs1", [], 
InstFormatOther> {
+  let Inst{15-13} = 0b011;
+  let Inst{12} = 0;
+  let Inst{11-7} = rs1val;
+  let Inst{6-2} = 0b0;
+  let Inst{1-0} = 0b01;
+  let DecoderMethod = "decodeCSSPushPopchk";
+}
+
+//===--===//
+// Instructions
+//===--===//
+
+let Predicates = [HasStdExtZicfiss] in {
+let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 1, mayStore = 0 
in
+def SSPOPCHK : RVInstI<0b100, OPC_SYSTEM, (outs), (ins GPRX1X5:$rs1), 
"sspopchk",

wangpc-pp wrote:

I think I don't find any mistake, `sspush` uses `mop.rr` and `sspopchk` uses 
`mop.r`.
> The 25th bit of sspopchk is 0 but but the 25th bit of all mop.r is 1.

This is wrong as it's `{ bits:  4, name: 0x7 }`, so its value is `0b0111`.

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


[llvm] [clang] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

2023-12-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-support

Author: Wang Pengcheng (wangpc-pp)


Changes

This implements experimental support for the Zcmop extension as
specified here: 
https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc.

This change adds only MC support.


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


10 Files Affected:

- (modified) clang/test/Preprocessor/riscv-target-features.c (+9) 
- (modified) llvm/docs/RISCVUsage.rst (+3) 
- (modified) llvm/lib/Support/RISCVISAInfo.cpp (+2) 
- (modified) llvm/lib/Target/RISCV/RISCVFeatures.td (+7) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.td (+1) 
- (added) llvm/lib/Target/RISCV/RISCVInstrInfoZcmop.td (+30) 
- (modified) llvm/test/CodeGen/RISCV/attributes.ll (+4) 
- (added) llvm/test/MC/RISCV/rv32zcmop-invalid.s (+7) 
- (added) llvm/test/MC/RISCV/rvzcmop-valid.s (+42) 
- (modified) llvm/unittests/Support/RISCVISAInfoTest.cpp (+1) 


``diff
diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 2111b3f1c5832b..661f1fb55159c7 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -121,6 +121,7 @@
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
 // CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zimop {{.*$}}
+// CHECK-NOT: __riscv_zcmop {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvbb {{.*$}}
 // CHECK-NOT: __riscv_zvbc {{.*$}}
@@ -1080,6 +1081,14 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZIMOP-EXT %s
 // CHECK-ZIMOP-EXT: __riscv_zimop  1000{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zcmop0p2 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZCMOP-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv32i_zcmop0p2 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZCMOP-EXT %s
+// CHECK-ZCMOP-EXT: __riscv_zcmop  2000{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
 // RUN: -march=rv32iztso0p1 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZTSO-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 3125f2d7c9cfdb..836a4e9ff08e55 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -224,6 +224,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zimop``
   LLVM implements the `v0.1 proposed specification 
`__.
 
+``experimental-zcmop``
+  LLVM implements the `v0.2 proposed specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index e71e96e3417e46..36d453a53c1057 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -191,6 +191,8 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
 {"zacas", RISCVExtensionVersion{1, 0}},
 
+{"zcmop", RISCVExtensionVersion{0, 2}},
+
 {"zfbfmin", RISCVExtensionVersion{0, 8}},
 
 {"zicfilp", RISCVExtensionVersion{0, 4}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index a6e7c15b50e978..adf3c84b586a25 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -693,6 +693,13 @@ def HasStdExtZimop : 
Predicate<"Subtarget->hasStdExtZimop()">,
AssemblerPredicate<(all_of FeatureStdExtZimop),
"'Zimop' (May-Be-Operations)">;
 
+def FeatureStdExtZcmop : SubtargetFeature<"experimental-zcmop", 
"HasStdExtZcmop", "true",
+  "'Zcmop' (Compressed 
May-Be-Operations)",
+  [FeatureStdExtZca]>;
+def HasStdExtZcmop : Predicate<"Subtarget->hasStdExtZcmop()">,
+   AssemblerPredicate<(all_of FeatureStdExtZcmop),
+   "'Zcmop' (Compressed May-Be-Operations)">;
+
 def FeatureStdExtSmaia
 : SubtargetFeature<"smaia", "HasStdExtSmaia", "true",
"'Smaia' (Smaia encompasses all added CSRs and all "
diff --git 

[llvm] [clang] [RISCV][MC] Add support for experimental Zcmop extension (PR #76395)

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

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

This implements experimental support for the Zcmop extension as
specified here: 
https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc.

This change adds only MC support.


>From 20fd01b09bb196cf53807b44161482d56a43920b Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Tue, 26 Dec 2023 20:46:13 +0800
Subject: [PATCH] [RISCV][MC] Add support for experimental Zcmop extension

This implements experimental support for the Zcmop extension as
specified here: 
https://github.com/riscv/riscv-isa-manual/blob/main/src/zimop.adoc.

This change adds only MC support.
---
 .../test/Preprocessor/riscv-target-features.c |  9 
 llvm/docs/RISCVUsage.rst  |  3 ++
 llvm/lib/Support/RISCVISAInfo.cpp |  2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|  7 
 llvm/lib/Target/RISCV/RISCVInstrInfo.td   |  1 +
 llvm/lib/Target/RISCV/RISCVInstrInfoZcmop.td  | 30 +
 llvm/test/CodeGen/RISCV/attributes.ll |  4 ++
 llvm/test/MC/RISCV/rv32zcmop-invalid.s|  7 
 llvm/test/MC/RISCV/rvzcmop-valid.s| 42 +++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |  1 +
 10 files changed, 106 insertions(+)
 create mode 100644 llvm/lib/Target/RISCV/RISCVInstrInfoZcmop.td
 create mode 100644 llvm/test/MC/RISCV/rv32zcmop-invalid.s
 create mode 100644 llvm/test/MC/RISCV/rvzcmop-valid.s

diff --git a/clang/test/Preprocessor/riscv-target-features.c 
b/clang/test/Preprocessor/riscv-target-features.c
index 2111b3f1c5832b..661f1fb55159c7 100644
--- a/clang/test/Preprocessor/riscv-target-features.c
+++ b/clang/test/Preprocessor/riscv-target-features.c
@@ -121,6 +121,7 @@
 // CHECK-NOT: __riscv_zicfilp {{.*$}}
 // CHECK-NOT: __riscv_zicond {{.*$}}
 // CHECK-NOT: __riscv_zimop {{.*$}}
+// CHECK-NOT: __riscv_zcmop {{.*$}}
 // CHECK-NOT: __riscv_ztso {{.*$}}
 // CHECK-NOT: __riscv_zvbb {{.*$}}
 // CHECK-NOT: __riscv_zvbc {{.*$}}
@@ -1080,6 +1081,14 @@
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZIMOP-EXT %s
 // CHECK-ZIMOP-EXT: __riscv_zimop  1000{{$}}
 
+// RUN: %clang --target=riscv32 -menable-experimental-extensions \
+// RUN: -march=rv32i_zcmop0p2 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZCMOP-EXT %s
+// RUN: %clang --target=riscv64 -menable-experimental-extensions \
+// RUN: -march=rv32i_zcmop0p2 -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-ZCMOP-EXT %s
+// CHECK-ZCMOP-EXT: __riscv_zcmop  2000{{$}}
+
 // RUN: %clang --target=riscv32-unknown-linux-gnu 
-menable-experimental-extensions \
 // RUN: -march=rv32iztso0p1 -x c -E -dM %s \
 // RUN: -o - | FileCheck --check-prefix=CHECK-ZTSO-EXT %s
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 3125f2d7c9cfdb..836a4e9ff08e55 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -224,6 +224,9 @@ The primary goal of experimental support is to assist in 
the process of ratifica
 ``experimental-zimop``
   LLVM implements the `v0.1 proposed specification 
`__.
 
+``experimental-zcmop``
+  LLVM implements the `v0.2 proposed specification 
`__.
+
 To use an experimental extension from `clang`, you must add 
`-menable-experimental-extensions` to the command line, and specify the exact 
version of the experimental extension you are using.  To use an experimental 
extension with LLVM's internal developer tools (e.g. `llc`, `llvm-objdump`, 
`llvm-mc`), you must prefix the extension name with `experimental-`.  Note that 
you don't need to specify the version with internal tools, and shouldn't 
include the `experimental-` prefix with `clang`.
 
 Vendor Extensions
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp 
b/llvm/lib/Support/RISCVISAInfo.cpp
index e71e96e3417e46..36d453a53c1057 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -191,6 +191,8 @@ static const RISCVSupportedExtension SupportedExtensions[] 
= {
 static const RISCVSupportedExtension SupportedExperimentalExtensions[] = {
 {"zacas", RISCVExtensionVersion{1, 0}},
 
+{"zcmop", RISCVExtensionVersion{0, 2}},
+
 {"zfbfmin", RISCVExtensionVersion{0, 8}},
 
 {"zicfilp", RISCVExtensionVersion{0, 4}},
diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index a6e7c15b50e978..adf3c84b586a25 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -693,6 +693,13 @@ def HasStdExtZimop : 
Predicate<"Subtarget->hasStdExtZimop()">,
AssemblerPredicate<(all_of FeatureStdExtZimop),
"'Zimop' (May-Be-Operations)">;
 
+def FeatureStdExtZcmop : SubtargetFeature<"experimental-zcmop", 
"HasStdExtZcmop", "true",
+  "'Zcmop' (Compressed 

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

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


@@ -0,0 +1,71 @@
+//===-- RISCVInstrInfoZicfiss.td - RISC-V Zicfiss -*- tablegen 
-*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+// Instruction class templates
+//===--===//
+
+class RVC_SSInst rs1val, RegisterClass reg_class, string opcodestr> :
+  RVInst16<(outs), (ins reg_class:$rs1), opcodestr, "$rs1", [], 
InstFormatOther> {
+  let Inst{15-13} = 0b011;
+  let Inst{12} = 0;
+  let Inst{11-7} = rs1val;
+  let Inst{6-2} = 0b0;
+  let Inst{1-0} = 0b01;
+  let DecoderMethod = "decodeCSSPushPopchk";
+}
+
+//===--===//
+// Instructions
+//===--===//
+
+let Predicates = [HasStdExtZicfiss] in {
+let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 1, mayStore = 0 
in
+def SSPOPCHK : RVInstI<0b100, OPC_SYSTEM, (outs), (ins GPRX1X5:$rs1), 
"sspopchk",

wangpc-pp wrote:

Hmmm, I haven't looked at it in details, is this a document mistake? They 
should have the same encoding.

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


[clang] [RISCV][Clang] Remove -save-restore from default features. (PR #76390)

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

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

>From 71c202c4f16451f7d0d9e17239f95418ea315c0a Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 26 Dec 2023 02:11:30 -0800
Subject: [PATCH] [RISCV][Clang] Remove default feature -save-restore.

It's unnecessary to defaultly pass -save-restore, since riscv backend defaultly
disable save-restore functionality.
---
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp | 7 ---
 clang/test/Driver/riscv-default-features.c | 2 --
 clang/test/Driver/riscv-features.c | 2 +-
 3 files changed, 1 insertion(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 25b43cefce6b57..8ae47d1680bd22 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -167,13 +167,6 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 Features.push_back("-relax");
   }
 
-  // GCC Compatibility: -mno-save-restore is default, unless -msave-restore is
-  // specified.
-  if (Args.hasFlag(options::OPT_msave_restore, options::OPT_mno_save_restore, 
false))
-Features.push_back("+save-restore");
-  else
-Features.push_back("-save-restore");
-
   // -mno-unaligned-access is default, unless -munaligned-access is specified.
   AddTargetFeature(Args, Features, options::OPT_munaligned_access,
options::OPT_mno_unaligned_access, "fast-unaligned-access");
diff --git a/clang/test/Driver/riscv-default-features.c 
b/clang/test/Driver/riscv-default-features.c
index 6e48f7cc37dcb0..4c3883c1cc1184 100644
--- a/clang/test/Driver/riscv-default-features.c
+++ b/clang/test/Driver/riscv-default-features.c
@@ -2,9 +2,7 @@
 // RUN: %clang --target=riscv64-unknown-elf -S -emit-llvm %s -o - | FileCheck 
%s -check-prefix=RV64
 
 // RV32: "target-features"="+32bit,+a,+c,+m,+relax,
-// RV32-SAME: -save-restore
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,
-// RV64-SAME: -save-restore
 
 // Dummy function
 int foo(void){
diff --git a/clang/test/Driver/riscv-features.c 
b/clang/test/Driver/riscv-features.c
index 716f3f6da57b88..d3700f71aa7e1d 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -24,7 +24,7 @@
 
 // SAVE-RESTORE: "-target-feature" "+save-restore"
 // NO-SAVE-RESTORE: "-target-feature" "-save-restore"
-// DEFAULT: "-target-feature" "-save-restore"
+// DEFAULT-NOT: "-target-feature" "-save-restore"
 // DEFAULT-NOT: "-target-feature" "+save-restore"
 
 // RUN: %clang --target=riscv32-unknown-elf -### %s -munaligned-access 2>&1 | 
FileCheck %s -check-prefix=FAST-UNALIGNED-ACCESS

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


[clang] [RISCV][Clang] Remove -save-restore from default features. (PR #76390)

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

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


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

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


@@ -0,0 +1,71 @@
+//===-- RISCVInstrInfoZicfiss.td - RISC-V Zicfiss -*- tablegen 
-*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+// Instruction class templates
+//===--===//
+
+class RVC_SSInst rs1val, RegisterClass reg_class, string opcodestr> :
+  RVInst16<(outs), (ins reg_class:$rs1), opcodestr, "$rs1", [], 
InstFormatOther> {
+  let Inst{15-13} = 0b011;
+  let Inst{12} = 0;
+  let Inst{11-7} = rs1val;
+  let Inst{6-2} = 0b0;
+  let Inst{1-0} = 0b01;
+  let DecoderMethod = "decodeCSSPushPopchk";
+}
+
+//===--===//
+// Instructions
+//===--===//
+
+let Predicates = [HasStdExtZicfiss] in {
+let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 1, mayStore = 0 
in
+def SSPOPCHK : RVInstI<0b100, OPC_SYSTEM, (outs), (ins GPRX1X5:$rs1), 
"sspopchk",

yetingk wrote:

They should use same encoding as some instructions of Zimop, but currently, 
there is no `mop.r` could be fitted to `sspush` and `sspopchk`. The 24th bit of 
`sspush` is 0 but the 24th bit of all `mop.r` is 1. The 25th bit of `sspopchk` 
is 0 but but the 25th bit of all `mop.r` is 1.

ref:
https://github.com/riscv/riscv-isa-manual/blob/main/src/images/wavedrom/mop-r.adoc
https://github.com/riscv/riscv-cfi/blob/main/cfi_backward.adoc


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


[clang-tools-extra] [clang-tidy] Treat fields in anonymous records as names in enclosing scope when checking name styles (PR #75701)

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

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

>From 5d04ca8091fc81fad8e33355a0afcce290bf34f0 Mon Sep 17 00:00:00 2001
From: Sirui Mu 
Date: Sat, 16 Dec 2023 21:55:24 +0800
Subject: [PATCH 1/5] [clang-tidy] Check anonymous record field naming in
 enclosing scopes

Currently, fields in anonymous records are regarded as normal fields when
checking their name styles. Naming rules for class/struct/union member apply to
these fields. This commit changes this behavior:

- If the anonymous record is defined within the file scope or in a namespace
  scope, treat its fields as global variables when checking name styles;
- If the anonymous record is defined within a function, treat its fields as
  local variables when checking name styles;
- If the anonymous record is defined within a non-anonymous record, treat its
  fields as non-static record members when checking name styles.
---
 .../readability/IdentifierNamingCheck.cpp | 196 ++
 .../readability/IdentifierNamingCheck.h   |  13 ++
 .../clang-tidy/utils/ASTUtils.cpp |  24 +++
 clang-tools-extra/clang-tidy/utils/ASTUtils.h |   5 +
 .../identifier-naming-anon-record-fields.cpp  | 184 
 5 files changed, 341 insertions(+), 81 deletions(-)
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-anon-record-fields.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 03dcfa5f811095..0e18712fd27564 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -9,6 +9,7 @@
 #include "IdentifierNamingCheck.h"
 
 #include "../GlobList.h"
+#include "../utils/ASTUtils.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
@@ -1185,29 +1186,12 @@ StyleKind IdentifierNamingCheck::findStyleKind(
   }
 
   if (const auto *Decl = dyn_cast(D)) {
-QualType Type = Decl->getType();
-
-if (!Type.isNull() && Type.isConstQualified()) {
-  if (NamingStyles[SK_ConstantMember])
-return SK_ConstantMember;
-
-  if (NamingStyles[SK_Constant])
-return SK_Constant;
+const RecordDecl *Record = Decl->getParent();
+if (Record->isAnonymousStructOrUnion()) {
+  return findStyleKindForAnonField(Decl, NamingStyles);
 }
 
-if (Decl->getAccess() == AS_private && NamingStyles[SK_PrivateMember])
-  return SK_PrivateMember;
-
-if (Decl->getAccess() == AS_protected && NamingStyles[SK_ProtectedMember])
-  return SK_ProtectedMember;
-
-if (Decl->getAccess() == AS_public && NamingStyles[SK_PublicMember])
-  return SK_PublicMember;
-
-if (NamingStyles[SK_Member])
-  return SK_Member;
-
-return SK_Invalid;
+return findStyleKindForField(Decl, Decl->getType(), NamingStyles);
   }
 
   if (const auto *Decl = dyn_cast(D)) {
@@ -1244,66 +1228,7 @@ StyleKind IdentifierNamingCheck::findStyleKind(
   }
 
   if (const auto *Decl = dyn_cast(D)) {
-QualType Type = Decl->getType();
-
-if (Decl->isConstexpr() && NamingStyles[SK_ConstexprVariable])
-  return SK_ConstexprVariable;
-
-if (!Type.isNull() && Type.isConstQualified()) {
-  if (Decl->isStaticDataMember() && NamingStyles[SK_ClassConstant])
-return SK_ClassConstant;
-
-  if (Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() &&
-  NamingStyles[SK_GlobalConstantPointer])
-return SK_GlobalConstantPointer;
-
-  if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalConstant])
-return SK_GlobalConstant;
-
-  if (Decl->isStaticLocal() && NamingStyles[SK_StaticConstant])
-return SK_StaticConstant;
-
-  if (Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() &&
-  NamingStyles[SK_LocalConstantPointer])
-return SK_LocalConstantPointer;
-
-  if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalConstant])
-return SK_LocalConstant;
-
-  if (Decl->isFunctionOrMethodVarDecl() && NamingStyles[SK_LocalConstant])
-return SK_LocalConstant;
-
-  if (NamingStyles[SK_Constant])
-return SK_Constant;
-}
-
-if (Decl->isStaticDataMember() && NamingStyles[SK_ClassMember])
-  return SK_ClassMember;
-
-if (Decl->isFileVarDecl() && Type.getTypePtr()->isAnyPointerType() &&
-NamingStyles[SK_GlobalPointer])
-  return SK_GlobalPointer;
-
-if (Decl->isFileVarDecl() && NamingStyles[SK_GlobalVariable])
-  return SK_GlobalVariable;
-
-if (Decl->isStaticLocal() && NamingStyles[SK_StaticVariable])
-  return SK_StaticVariable;
-
-if (Decl->isLocalVarDecl() && Type.getTypePtr()->isAnyPointerType() &&
-NamingStyles[SK_LocalPointer])
-  return SK_LocalPointer;
-
-if (Decl->isLocalVarDecl() && NamingStyles[SK_LocalVariable])
-  

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

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


@@ -0,0 +1,71 @@
+//===-- RISCVInstrInfoZicfiss.td - RISC-V Zicfiss -*- tablegen 
-*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+// Instruction class templates
+//===--===//
+
+class RVC_SSInst rs1val, RegisterClass reg_class, string opcodestr> :
+  RVInst16<(outs), (ins reg_class:$rs1), opcodestr, "$rs1", [], 
InstFormatOther> {
+  let Inst{15-13} = 0b011;
+  let Inst{12} = 0;
+  let Inst{11-7} = rs1val;
+  let Inst{6-2} = 0b0;
+  let Inst{1-0} = 0b01;
+  let DecoderMethod = "decodeCSSPushPopchk";
+}
+
+//===--===//
+// Instructions
+//===--===//
+
+let Predicates = [HasStdExtZicfiss] in {
+let Uses = [SSP], Defs = [SSP], hasSideEffects = 0, mayLoad = 1, mayStore = 0 
in
+def SSPOPCHK : RVInstI<0b100, OPC_SYSTEM, (outs), (ins GPRX1X5:$rs1), 
"sspopchk",

wangpc-pp wrote:

Should these instructions be aliases of MOPs now?

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


[clang-tools-extra] [clang-tidy] Treat fields in anonymous records as names in enclosing scope when checking name styles (PR #75701)

2023-12-26 Thread Piotr Zegar via cfe-commits

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

LGTM

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


[clang-tools-extra] [clang-tidy] Treat fields in anonymous records as names in enclosing scope when checking name styles (PR #75701)

2023-12-26 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] [clang-tidy] Treat fields in anonymous records as names in enclosing scope when checking name styles (PR #75701)

2023-12-26 Thread Piotr Zegar via cfe-commits


@@ -207,6 +208,31 @@ After if AggressiveDependentMemberLookup is `true`:
   }
 };
 
+.. option:: CheckAnonFieldInParent
+
+When set to `true`, fields in anonymous records (i.e. anonymous
+unions and structs) will be treated as names in the enclosing scope
+rather than public members of the anonymous record for the purpose
+of name checking.
+
+For example:
+
+.. code-block:: c++
+
+class Foo {
+private:
+  union {
+int iv_;
+float fv_;
+  };
+};
+
+If CheckAnonFieldInParent is `false`, you may get warnings that ``iv_`` and

PiotrZSL wrote:

:option:`CheckAnonFieldInParent `

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


[clang-tools-extra] [clang-tidy] Treat fields in anonymous records as names in enclosing scope when checking name styles (PR #75701)

2023-12-26 Thread Piotr Zegar via cfe-commits


@@ -207,6 +208,31 @@ After if AggressiveDependentMemberLookup is `true`:
   }
 };
 
+.. option:: CheckAnonFieldInParent
+
+When set to `true`, fields in anonymous records (i.e. anonymous
+unions and structs) will be treated as names in the enclosing scope
+rather than public members of the anonymous record for the purpose
+of name checking.
+
+For example:
+
+.. code-block:: c++
+
+class Foo {
+private:
+  union {
+int iv_;
+float fv_;
+  };
+};
+
+If CheckAnonFieldInParent is `false`, you may get warnings that ``iv_`` and
+``fv_`` are not coherent to public member names, because ``iv_`` and ``fv_``
+are public members of the anonymous union. When CheckAnonFieldInParent is

PiotrZSL wrote:

:option:`CheckAnonFieldInParent`

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


[clang] [Clang] support vector subscript expressions in constant evaluator (WIP) (PR #76379)

2023-12-26 Thread Vikram Hegde via cfe-commits

https://github.com/vikramRH updated 
https://github.com/llvm/llvm-project/pull/76379

>From 89c79eea31d1a9ec0656fbf5c4eacf75b2471034 Mon Sep 17 00:00:00 2001
From: Vikram 
Date: Wed, 20 Dec 2023 05:36:40 +
Subject: [PATCH] [Clang] support vector subscript expressions in constant
 evaluator

---
 clang/lib/AST/ExprConstant.cpp   |  61 +-
 clang/test/CodeGenCXX/temporaries.cpp|  12 +-
 clang/test/SemaCXX/constexpr-vectors.cpp | 746 ++-
 3 files changed, 668 insertions(+), 151 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..390c5aef477105 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -221,6 +221,12 @@ namespace {
 ArraySize = 2;
 MostDerivedLength = I + 1;
 IsArray = true;
+  } else if (Type->isVectorType()) {
+const VectorType *CT = Type->castAs();
+Type = CT->getElementType();
+ArraySize = CT->getNumElements();
+MostDerivedLength = I + 1;
+IsArray = true;
   } else if (const FieldDecl *FD = getAsField(Path[I])) {
 Type = FD->getType();
 ArraySize = 0;
@@ -437,6 +443,15 @@ namespace {
   MostDerivedArraySize = 2;
   MostDerivedPathLength = Entries.size();
 }
+/// Update this designator to refer to the given vector component.
+void addVectorUnchecked(const VectorType *VecTy) {
+  Entries.push_back(PathEntry::ArrayIndex(0));
+
+  MostDerivedType = VecTy->getElementType();
+  MostDerivedIsArrayElement = true;
+  MostDerivedArraySize = VecTy->getNumElements();
+  MostDerivedPathLength = Entries.size();
+}
 void diagnoseUnsizedArrayPointerArithmetic(EvalInfo , const Expr *E);
 void diagnosePointerArithmetic(EvalInfo , const Expr *E,
const APSInt );
@@ -1732,6 +1747,10 @@ namespace {
   if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real))
 Designator.addComplexUnchecked(EltTy, Imag);
 }
+void addVector(EvalInfo , const Expr *E, const VectorType *VecTy) {
+  if (checkSubobject(Info, E, CSK_ArrayIndex))
+Designator.addVectorUnchecked(VecTy);
+}
 void clearIsNullPointer() {
   IsNullPtr = false;
 }
@@ -1890,6 +1909,8 @@ static bool EvaluateFixedPointOrInteger(const Expr *E, 
APFixedPoint ,
 static bool EvaluateFixedPoint(const Expr *E, APFixedPoint ,
EvalInfo );
 
+static bool EvaluateVector(const Expr *E, APValue , EvalInfo );
+
 
//===--===//
 // Misc utilities
 
//===--===//
@@ -3278,6 +3299,19 @@ static bool HandleLValueComplexElement(EvalInfo , 
const Expr *E,
   return true;
 }
 
+static bool HandeLValueVectorComponent(EvalInfo , const Expr *E,
+   LValue , const VectorType *VecTy,
+   APSInt ) {
+  LVal.addVector(Info, E, VecTy);
+
+  CharUnits SizeOfComponent;
+  if (!HandleSizeof(Info, E->getExprLoc(), VecTy->getElementType(),
+SizeOfComponent))
+return false;
+  LVal.adjustOffsetAndIndex(Info, E, Adjustment, SizeOfComponent);
+  return true;
+}
+
 /// Try to evaluate the initializer for a variable declaration.
 ///
 /// \param Info   Information about the ongoing evaluation.
@@ -3718,7 +3752,8 @@ findSubobject(EvalInfo , const Expr *E, const 
CompleteObject ,
 }
 
 // If this is our last pass, check that the final object type is OK.
-if (I == N || (I == N - 1 && ObjType->isAnyComplexType())) {
+if (I == N || (I == N - 1 &&
+   (ObjType->isAnyComplexType() || ObjType->isVectorType( {
   // Accesses to volatile objects are prohibited.
   if (ObjType.isVolatileQualified() && isFormalAccess(handler.AccessKind)) 
{
 if (Info.getLangOpts().CPlusPlus) {
@@ -3823,6 +3858,10 @@ findSubobject(EvalInfo , const Expr *E, const 
CompleteObject ,
 return handler.found(Index ? O->getComplexFloatImag()
: O->getComplexFloatReal(), ObjType);
   }
+} else if (ObjType->isVectorType()) {
+  // Next Subobject is a vector element
+  uint64_t Index = Sub.Entries[I].getAsArrayIndex();
+  O = >getVectorElt(Index);
 } else if (const FieldDecl *Field = getAsField(Sub.Entries[I])) {
   if (Field->isMutable() &&
   !Obj.mayAccessMutableMembers(Info, handler.AccessKind)) {
@@ -8756,14 +8795,28 @@ bool LValueExprEvaluator::VisitMemberExpr(const 
MemberExpr *E) {
 }
 
 bool LValueExprEvaluator::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) 
{
-  // FIXME: Deal with vectors as array subscript bases.
-  if (E->getBase()->getType()->isVectorType() ||
-  E->getBase()->getType()->isSveVLSBuiltinType())
+
+  if (E->getBase()->getType()->isSveVLSBuiltinType())
 return Error(E);
 
   

[clang] [llvm] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2023-12-26 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

@dwblaikie
Could you please take a look at this when you have a chance?

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


[clang] [RISCV][Clang] Remove default feature -save-restore. (PR #76390)

2023-12-26 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang

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

Author: Yeting Kuo (yetingk)


Changes

It's unnecessary to defaultly pass feature `-save-restore`, since risc-v 
backend defaultly disables save-restore functionality.

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


3 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+2-4) 
- (modified) clang/test/Driver/riscv-default-features.c (-2) 
- (modified) clang/test/Driver/riscv-features.c (+1-1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 25b43cefce6b57..f385a97eca991b 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -169,10 +169,8 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 
   // GCC Compatibility: -mno-save-restore is default, unless -msave-restore is
   // specified.
-  if (Args.hasFlag(options::OPT_msave_restore, options::OPT_mno_save_restore, 
false))
-Features.push_back("+save-restore");
-  else
-Features.push_back("-save-restore");
+  AddTargetFeature(Args, Features, options::OPT_msave_restore,
+   options::OPT_mno_save_restore, "save-restore");
 
   // -mno-unaligned-access is default, unless -munaligned-access is specified.
   AddTargetFeature(Args, Features, options::OPT_munaligned_access,
diff --git a/clang/test/Driver/riscv-default-features.c 
b/clang/test/Driver/riscv-default-features.c
index 6e48f7cc37dcb0..4c3883c1cc1184 100644
--- a/clang/test/Driver/riscv-default-features.c
+++ b/clang/test/Driver/riscv-default-features.c
@@ -2,9 +2,7 @@
 // RUN: %clang --target=riscv64-unknown-elf -S -emit-llvm %s -o - | FileCheck 
%s -check-prefix=RV64
 
 // RV32: "target-features"="+32bit,+a,+c,+m,+relax,
-// RV32-SAME: -save-restore
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,
-// RV64-SAME: -save-restore
 
 // Dummy function
 int foo(void){
diff --git a/clang/test/Driver/riscv-features.c 
b/clang/test/Driver/riscv-features.c
index 716f3f6da57b88..d3700f71aa7e1d 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -24,7 +24,7 @@
 
 // SAVE-RESTORE: "-target-feature" "+save-restore"
 // NO-SAVE-RESTORE: "-target-feature" "-save-restore"
-// DEFAULT: "-target-feature" "-save-restore"
+// DEFAULT-NOT: "-target-feature" "-save-restore"
 // DEFAULT-NOT: "-target-feature" "+save-restore"
 
 // RUN: %clang --target=riscv32-unknown-elf -### %s -munaligned-access 2>&1 | 
FileCheck %s -check-prefix=FAST-UNALIGNED-ACCESS

``




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


[clang] [RISCV][Clang] Remove default feature -save-restore. (PR #76390)

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

https://github.com/yetingk created 
https://github.com/llvm/llvm-project/pull/76390

It's unnecessary to defaultly pass feature `-save-restore`, since risc-v 
backend defaultly disables save-restore functionality.

>From 97fe56d808f1752ac4b7d26deecabb857e0a4208 Mon Sep 17 00:00:00 2001
From: Yeting Kuo 
Date: Tue, 26 Dec 2023 02:11:30 -0800
Subject: [PATCH] [RISCV][Clang] Remove default feature -save-restore.

It's unnecessary to defaultly pass -save-restore, since riscv backend defaultly
disable save-restore functionality.
---
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp | 6 ++
 clang/test/Driver/riscv-default-features.c | 2 --
 clang/test/Driver/riscv-features.c | 2 +-
 3 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 25b43cefce6b57..f385a97eca991b 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -169,10 +169,8 @@ void riscv::getRISCVTargetFeatures(const Driver , const 
llvm::Triple ,
 
   // GCC Compatibility: -mno-save-restore is default, unless -msave-restore is
   // specified.
-  if (Args.hasFlag(options::OPT_msave_restore, options::OPT_mno_save_restore, 
false))
-Features.push_back("+save-restore");
-  else
-Features.push_back("-save-restore");
+  AddTargetFeature(Args, Features, options::OPT_msave_restore,
+   options::OPT_mno_save_restore, "save-restore");
 
   // -mno-unaligned-access is default, unless -munaligned-access is specified.
   AddTargetFeature(Args, Features, options::OPT_munaligned_access,
diff --git a/clang/test/Driver/riscv-default-features.c 
b/clang/test/Driver/riscv-default-features.c
index 6e48f7cc37dcb0..4c3883c1cc1184 100644
--- a/clang/test/Driver/riscv-default-features.c
+++ b/clang/test/Driver/riscv-default-features.c
@@ -2,9 +2,7 @@
 // RUN: %clang --target=riscv64-unknown-elf -S -emit-llvm %s -o - | FileCheck 
%s -check-prefix=RV64
 
 // RV32: "target-features"="+32bit,+a,+c,+m,+relax,
-// RV32-SAME: -save-restore
 // RV64: "target-features"="+64bit,+a,+c,+m,+relax,
-// RV64-SAME: -save-restore
 
 // Dummy function
 int foo(void){
diff --git a/clang/test/Driver/riscv-features.c 
b/clang/test/Driver/riscv-features.c
index 716f3f6da57b88..d3700f71aa7e1d 100644
--- a/clang/test/Driver/riscv-features.c
+++ b/clang/test/Driver/riscv-features.c
@@ -24,7 +24,7 @@
 
 // SAVE-RESTORE: "-target-feature" "+save-restore"
 // NO-SAVE-RESTORE: "-target-feature" "-save-restore"
-// DEFAULT: "-target-feature" "-save-restore"
+// DEFAULT-NOT: "-target-feature" "-save-restore"
 // DEFAULT-NOT: "-target-feature" "+save-restore"
 
 // RUN: %clang --target=riscv32-unknown-elf -### %s -munaligned-access 2>&1 | 
FileCheck %s -check-prefix=FAST-UNALIGNED-ACCESS

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


[clang-tools-extra] 583a258 - [clang-tidy] Don't replace typedefs in extern c scope (#69102)

2023-12-26 Thread Piotr Zegar via cfe-commits

Author: Da-Viper
Date: 2023-12-26T09:36:07Z
New Revision: 583a2583bb5f53b7b2cbd3d2043c0b2ac286464f

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

LOG: [clang-tidy] Don't replace typedefs in extern c scope (#69102)

Added IgnoreExternC option to modernize-use-using check.
Fixes #35272

Added: 

clang-tools-extra/test/clang-tidy/checkers/modernize/use-using-ignore-extern-c.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index e6293ed48bfddb..f5fc3ad3fac68b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -11,26 +11,39 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
+namespace {
+
+AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
+  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
+}
+} // namespace
 
 namespace clang::tidy::modernize {
 
+static constexpr llvm::StringLiteral ExternCDeclName = "extern-c-decl";
 static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
 static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
 static constexpr llvm::StringLiteral TypedefName = "typedef";
 
 UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
+  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
+  IgnoreExternC(Options.get("IgnoreExternC", false)) {}
 
 void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+  Options.store(Opts, "IgnoreExternC", IgnoreExternC);
 }
 
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(typedefDecl(unless(isInstantiated()),
- hasParent(decl().bind(ParentDeclName)))
- .bind(TypedefName),
- this);
+  Finder->addMatcher(
+  typedefDecl(
+  unless(isInstantiated()),
+  optionally(hasAncestor(
+  linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
+  hasParent(decl().bind(ParentDeclName)))
+  .bind(TypedefName),
+  this);
 
   // This matcher is used to find tag declarations in source code within
   // typedefs. They appear in the AST just *prior* to the typedefs.
@@ -70,6 +83,11 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
) {
   if (MatchedDecl->getLocation().isInvalid())
 return;
 
+  const auto *ExternCDecl =
+  Result.Nodes.getNodeAs(ExternCDeclName);
+  if (ExternCDecl && IgnoreExternC)
+return;
+
   SourceLocation StartLoc = MatchedDecl->getBeginLoc();
 
   if (StartLoc.isMacroID() && IgnoreMacros)
@@ -122,7 +140,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
) {
   Type = FirstTypedefName + Type.substr(FirstTypedefType.size() + 1);
   }
   if (!ReplaceRange.getEnd().isMacroID()) {
-const SourceLocation::IntTy Offset = MatchedDecl->getFunctionType() ? 0 : 
Name.size();
+const SourceLocation::IntTy Offset =
+MatchedDecl->getFunctionType() ? 0 : Name.size();
 LastReplacementEnd = ReplaceRange.getEnd().getLocWithOffset(Offset);
   }
 

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
index 5c741a92d01310..7054778d84a0c6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
@@ -20,6 +20,7 @@ namespace clang::tidy::modernize {
 class UseUsingCheck : public ClangTidyCheck {
 
   const bool IgnoreMacros;
+  const bool IgnoreExternC;
   SourceLocation LastReplacementEnd;
   llvm::DenseMap LastTagDeclRanges;
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 00f570bcd21842..ce82063dbfe23e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -408,7 +408,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-using
   ` check to fix function pointer and
-  forward declared ``typedef`` correctly.
+  forward declared ``typedef`` correctly. Added option `IgnoreExternC` to 
ignore ``typedef``
+  declaration in ``extern "C"`` scope.
 
 - Improved :doc:`performance-faster-string-find
   ` check to properly 

[clang-tools-extra] 7a48039 - [clang-tidy] Fix compilation of modernize-use-using check

2023-12-26 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-26T10:20:10Z
New Revision: 7a48039eb79fc887f473e80618b6bc98effea077

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

LOG: [clang-tidy] Fix compilation of modernize-use-using check

Fix compilation issue introduced by #69102.

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index f5fc3ad3fac68b..bb05f206c717ce 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -14,7 +14,7 @@ using namespace clang::ast_matchers;
 namespace {
 
 AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
-  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
+  return Node.getLanguage() == clang::LinkageSpecLanguageIDs::C;
 }
 } // namespace
 



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


[llvm] [clang] [X86] Correct operand order of UWRMSR. (PR #76389)

2023-12-26 Thread Shengchen Kan via cfe-commits

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

LGTM

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


[clang-tools-extra] [libcxxabi] [libcxx] [llvm] [clang] [libc++] [libc++abi] Initialize exception directly in make_exception_ptr if __cxa_init_primary_exception is available in ABI-library (PR #65534)

2023-12-26 Thread via cfe-commits

itrofimow wrote:

I've addressed/answered inline comments and the build is finally green.

I'm not particularly in love with declaring `__cxa_allocate_exception`, 
`__cxa_free_exception` and `__cxa_init_primary_exception` in `exception_ptr.h`, 
but i find it's better than including whole `cxxabi.h` there.

Could you please have a look? @ldionne 

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


[clang-tools-extra] [libcxxabi] [libcxx] [llvm] [clang] [libc++] [libc++abi] Initialize exception directly in make_exception_ptr if __cxa_init_primary_exception is available in ABI-library (PR #65534)

2023-12-26 Thread via cfe-commits


@@ -51,11 +71,25 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
 template 
 _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
 #  ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+#if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION
+  using _Ep2 = __decay_t<_Ep>;
+  void* __ex = exception_ptr::__init_native_exception(
+  sizeof(_Ep), const_cast((_Ep)), 
exception_ptr::__dest_thunk<_Ep2>);

itrofimow wrote:

Using lambda here requires C++11, so i guarded all this with `__cplusplus >= 
201103L`

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


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

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

yetingk wrote:

Rebase.

> It seems that the author of Zimop implementation doesn't have commit access. 
> @yetingk Would you mind to commit it and rebase your PR on that? It will make 
> this PR simpler.

It's weird that `SSPUSH` and `SSPOPCHK` are not fit into `mop.r` instruction 
now.

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


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

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

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

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

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

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

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

[clang] [llvm] [X86] Correct operand order of UWRMSR. (PR #76389)

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

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

>From 36e618e3b4eb083510de80c9ee6c0732948f3bc5 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Tue, 26 Dec 2023 16:39:21 +0800
Subject: [PATCH 1/2] [X86] Correct operand order of UWRMSR.

---
 llvm/lib/Target/X86/X86InstrSystem.td   | 4 ++--
 llvm/test/CodeGen/X86/usermsr-intrinsics.ll | 8 
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/llvm/lib/Target/X86/X86InstrSystem.td 
b/llvm/lib/Target/X86/X86InstrSystem.td
index efb58c6102dd1d..699e5847e63fb9 100644
--- a/llvm/lib/Target/X86/X86InstrSystem.td
+++ b/llvm/lib/Target/X86/X86InstrSystem.td
@@ -446,11 +446,11 @@ let Predicates = [HasUSERMSR], mayLoad = 1 in {
 }
 let Predicates = [HasUSERMSR], mayStore = 1 in {
   def UWRMSRrr : I<0xf8, MRMSrcReg, (outs), (ins GR64:$src1, GR64:$src2),
-"uwrmsr\t{$src1, $src2|$src2, $src1}",
+"uwrmsr\t{$src2, $src1|$src1, $src2}",
 [(int_x86_uwrmsr GR64:$src1, GR64:$src2)]>, T8, XS;
   def UWRMSRir : Ii32<0xf8, MRM0r, (outs), (ins GR64:$src, i64i32imm:$imm),
 "uwrmsr\t{$src, $imm|$imm, $src}",
-[(int_x86_uwrmsr GR64:$src, i64immSExt32_su:$imm)]>, T_MAP7, 
XS, VEX;
+[(int_x86_uwrmsr i64immSExt32_su:$imm, GR64:$src)]>, T_MAP7, 
XS, VEX;
 }
 let Defs = [RAX, RDX], Uses = [ECX] in
 def RDPMC : I<0x33, RawFrm, (outs), (ins), "rdpmc", []>, TB;
diff --git a/llvm/test/CodeGen/X86/usermsr-intrinsics.ll 
b/llvm/test/CodeGen/X86/usermsr-intrinsics.ll
index 29801a494f498f..fa569affdd9ff3 100644
--- a/llvm/test/CodeGen/X86/usermsr-intrinsics.ll
+++ b/llvm/test/CodeGen/X86/usermsr-intrinsics.ll
@@ -35,7 +35,7 @@ declare i64 @llvm.x86.urdmsr(i64 %A)
 define void @test_int_x86_uwrmsr(i64 %A, i64 %B) nounwind {
 ; X64-LABEL: test_int_x86_uwrmsr:
 ; X64:   # %bb.0:
-; X64-NEXT:uwrmsr %rdi, %rsi # encoding: [0xf3,0x0f,0x38,0xf8,0xfe]
+; X64-NEXT:uwrmsr %rsi, %rdi # encoding: [0xf3,0x0f,0x38,0xf8,0xfe]
 ; X64-NEXT:retq # encoding: [0xc3]
   call void @llvm.x86.uwrmsr(i64 %A, i64 %B)
   ret void
@@ -46,7 +46,7 @@ define void @test_int_x86_uwrmsr_const(i64 %A) nounwind {
 ; X64:   # %bb.0:
 ; X64-NEXT:uwrmsr %rdi, $123 # encoding: 
[0xc4,0xe7,0x7a,0xf8,0xc7,0x7b,0x00,0x00,0x00]
 ; X64-NEXT:retq # encoding: [0xc3]
-  call void @llvm.x86.uwrmsr(i64 %A, i64 123)
+  call void @llvm.x86.uwrmsr(i64 123, i64 %A)
   ret void
 }
 
@@ -55,9 +55,9 @@ define void @test_int_x86_uwrmsr_const_i64(i64 %A) nounwind {
 ; X64:   # %bb.0:
 ; X64-NEXT:movabsq $8589934591, %rax # encoding: 
[0x48,0xb8,0xff,0xff,0xff,0xff,0x01,0x00,0x00,0x00]
 ; X64-NEXT:# imm = 0x1
-; X64-NEXT:uwrmsr %rdi, %rax # encoding: [0xf3,0x0f,0x38,0xf8,0xf8]
+; X64-NEXT:uwrmsr %rdi, %rax # encoding: [0xf3,0x0f,0x38,0xf8,0xc7]
 ; X64-NEXT:retq # encoding: [0xc3]
-  call void @llvm.x86.uwrmsr(i64 %A, i64 8589934591)
+  call void @llvm.x86.uwrmsr(i64 8589934591, i64 %A)
   ret void
 }
 

>From 81181956e2f222711074ef00d66f8ffc20ef33a9 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Tue, 26 Dec 2023 17:52:45 +0800
Subject: [PATCH 2/2] Add doxygen

---
 clang/lib/Headers/usermsrintrin.h | 21 +
 1 file changed, 21 insertions(+)

diff --git a/clang/lib/Headers/usermsrintrin.h 
b/clang/lib/Headers/usermsrintrin.h
index 6d1424ad3b2edd..61388376706dc6 100644
--- a/clang/lib/Headers/usermsrintrin.h
+++ b/clang/lib/Headers/usermsrintrin.h
@@ -14,12 +14,33 @@
 #define __USERMSRINTRIN_H
 #ifdef __x86_64__
 
+/// Reads the contents of a 64-bit MSR specified in \a __A into \a dst.
+///
+/// This intrinsic corresponds to the  URDMSR  instruction.
+/// \param __A
+///An unsigned long long.
+///
+/// \code{.operation}
+///DEST := MSR[__A]
+/// \endcode
 static __inline__ unsigned long long
 __attribute__((__always_inline__, __nodebug__, __target__("usermsr")))
 _urdmsr(unsigned long long __A) {
   return __builtin_ia32_urdmsr(__A);
 }
 
+/// Writes the contents of \a __B into the 64-bit MSR specified in \a __A.
+///
+/// This intrinsic corresponds to the  UWRMSR  instruction.
+///
+/// \param __A
+///An unsigned long long.
+/// \param __B
+///An unsigned long long.
+///
+/// \code{.operation}
+///MSR[__A] := __B
+/// \endcode
 static __inline__ void
 __attribute__((__always_inline__, __nodebug__, __target__("usermsr")))
 _uwrmsr(unsigned long long __A, unsigned long long __B) {

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


[clang-tools-extra] 34621aa - Revert "[clang-tidy] Don't replace typedefs in extern c scope (#69102)"

2023-12-26 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-26T09:35:18Z
New Revision: 34621aa81f63812b31d1356030e9d74ce59e56fc

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

LOG: Revert "[clang-tidy] Don't replace typedefs in extern c scope (#69102)"

This reverts commit 9dcc66578e12ad8e72c8ae7216122a1125976ac5.

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp

Removed: 

clang-tools-extra/test/clang-tidy/checkers/modernize/use-using-ignore-extern-c.cpp



diff  --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index f5fc3ad3fac68b..e6293ed48bfddb 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -11,39 +11,26 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
-namespace {
-
-AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
-  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
-}
-} // namespace
 
 namespace clang::tidy::modernize {
 
-static constexpr llvm::StringLiteral ExternCDeclName = "extern-c-decl";
 static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
 static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
 static constexpr llvm::StringLiteral TypedefName = "typedef";
 
 UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
-  IgnoreExternC(Options.get("IgnoreExternC", false)) {}
+  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
 
 void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
-  Options.store(Opts, "IgnoreExternC", IgnoreExternC);
 }
 
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  typedefDecl(
-  unless(isInstantiated()),
-  optionally(hasAncestor(
-  linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
-  hasParent(decl().bind(ParentDeclName)))
-  .bind(TypedefName),
-  this);
+  Finder->addMatcher(typedefDecl(unless(isInstantiated()),
+ hasParent(decl().bind(ParentDeclName)))
+ .bind(TypedefName),
+ this);
 
   // This matcher is used to find tag declarations in source code within
   // typedefs. They appear in the AST just *prior* to the typedefs.
@@ -83,11 +70,6 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
) {
   if (MatchedDecl->getLocation().isInvalid())
 return;
 
-  const auto *ExternCDecl =
-  Result.Nodes.getNodeAs(ExternCDeclName);
-  if (ExternCDecl && IgnoreExternC)
-return;
-
   SourceLocation StartLoc = MatchedDecl->getBeginLoc();
 
   if (StartLoc.isMacroID() && IgnoreMacros)
@@ -140,8 +122,7 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
) {
   Type = FirstTypedefName + Type.substr(FirstTypedefType.size() + 1);
   }
   if (!ReplaceRange.getEnd().isMacroID()) {
-const SourceLocation::IntTy Offset =
-MatchedDecl->getFunctionType() ? 0 : Name.size();
+const SourceLocation::IntTy Offset = MatchedDecl->getFunctionType() ? 0 : 
Name.size();
 LastReplacementEnd = ReplaceRange.getEnd().getLocWithOffset(Offset);
   }
 

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
index 7054778d84a0c6..5c741a92d01310 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
@@ -20,7 +20,6 @@ namespace clang::tidy::modernize {
 class UseUsingCheck : public ClangTidyCheck {
 
   const bool IgnoreMacros;
-  const bool IgnoreExternC;
   SourceLocation LastReplacementEnd;
   llvm::DenseMap LastTagDeclRanges;
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ce82063dbfe23e..00f570bcd21842 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -408,8 +408,7 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-using
   ` check to fix function pointer and
-  forward declared ``typedef`` correctly. Added option `IgnoreExternC` to 
ignore ``typedef``
-  declaration in ``extern "C"`` scope.
+  forward declared ``typedef`` correctly.
 
 - Improved :doc:`performance-faster-string-find
   ` check to 

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

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

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

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

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

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

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

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

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

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

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

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

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

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


@@ -0,0 +1,31 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir -p %t.dir/level1/level2
+
+// RUN: cd %t.dir
+// RUN: printf "%%s\n" "\*" "level*/*.c*" "*/*2/foo.*" > .clang-format-ignore

owenca wrote:

```suggestion
// RUN: echo "*" > .clang-format-ignore
// RUN: echo "level*/*.c*" >> .clang-format-ignore
// RUN: echo "*/*2/foo.*" >> .clang-format-ignore
```

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


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

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


@@ -0,0 +1,31 @@
+// RUN: rm -rf %t.dir
+// RUN: mkdir -p %t.dir/level1/level2
+
+// RUN: cd %t.dir
+// RUN: printf "%%s\n" "\*" "level*/*.c*" "*/*2/foo.*" > .clang-format-ignore
+// RUN: touch foo.cc
+// RUN: clang-format -verbose .clang-format-ignore foo.cc 2> %t.stderr
+// RUN: not grep Formatting %t.stderr
+
+// RUN: cd level1
+// RUN: touch bar.cc baz.c
+// RUN: clang-format -verbose bar.cc baz.c 2> %t.stderr
+// RUN: not grep Formatting %t.stderr
+
+// RUN: cd level2
+// RUN: touch foo.c foo.js
+// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
+// RUN: not grep Formatting %t.stderr
+
+// RUN: touch .clang-format-ignore
+// RUN: clang-format -verbose foo.c foo.js 2> %t.stderr
+// RUN: grep "Formatting \[1/2] foo.c" %t.stderr
+// RUN: grep "Formatting \[2/2] foo.js" %t.stderr
+
+// RUN: printf "%%s\n" "*.js" > .clang-format-ignore

owenca wrote:

```suggestion
// RUN: echo "*.js" > .clang-format-ignore
```

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


[llvm] [clang-tools-extra] [clang] Fix #35272: Don't replace typedefs in extern c scope (PR #69102)

2023-12-26 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 9dcc665 - [clang-tidy] Don't replace typedefs in extern c scope (#69102)

2023-12-26 Thread via cfe-commits

Author: Da-Viper
Date: 2023-12-26T10:27:10+01:00
New Revision: 9dcc66578e12ad8e72c8ae7216122a1125976ac5

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

LOG: [clang-tidy] Don't replace typedefs in extern c scope (#69102)

Added IgnoreExternC option to modernize-use-using check.
Fixes #35272

Added: 

clang-tools-extra/test/clang-tidy/checkers/modernize/use-using-ignore-extern-c.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/use-using.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-using.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
index e6293ed48bfddb..f5fc3ad3fac68b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
@@ -11,26 +11,39 @@
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
+namespace {
+
+AST_MATCHER(clang::LinkageSpecDecl, isExternCLinkage) {
+  return Node.getLanguage() == clang::LinkageSpecDecl::lang_c;
+}
+} // namespace
 
 namespace clang::tidy::modernize {
 
+static constexpr llvm::StringLiteral ExternCDeclName = "extern-c-decl";
 static constexpr llvm::StringLiteral ParentDeclName = "parent-decl";
 static constexpr llvm::StringLiteral TagDeclName = "tag-decl";
 static constexpr llvm::StringLiteral TypedefName = "typedef";
 
 UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
+  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
+  IgnoreExternC(Options.get("IgnoreExternC", false)) {}
 
 void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap ) {
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+  Options.store(Opts, "IgnoreExternC", IgnoreExternC);
 }
 
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(typedefDecl(unless(isInstantiated()),
- hasParent(decl().bind(ParentDeclName)))
- .bind(TypedefName),
- this);
+  Finder->addMatcher(
+  typedefDecl(
+  unless(isInstantiated()),
+  optionally(hasAncestor(
+  linkageSpecDecl(isExternCLinkage()).bind(ExternCDeclName))),
+  hasParent(decl().bind(ParentDeclName)))
+  .bind(TypedefName),
+  this);
 
   // This matcher is used to find tag declarations in source code within
   // typedefs. They appear in the AST just *prior* to the typedefs.
@@ -70,6 +83,11 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
) {
   if (MatchedDecl->getLocation().isInvalid())
 return;
 
+  const auto *ExternCDecl =
+  Result.Nodes.getNodeAs(ExternCDeclName);
+  if (ExternCDecl && IgnoreExternC)
+return;
+
   SourceLocation StartLoc = MatchedDecl->getBeginLoc();
 
   if (StartLoc.isMacroID() && IgnoreMacros)
@@ -122,7 +140,8 @@ void UseUsingCheck::check(const MatchFinder::MatchResult 
) {
   Type = FirstTypedefName + Type.substr(FirstTypedefType.size() + 1);
   }
   if (!ReplaceRange.getEnd().isMacroID()) {
-const SourceLocation::IntTy Offset = MatchedDecl->getFunctionType() ? 0 : 
Name.size();
+const SourceLocation::IntTy Offset =
+MatchedDecl->getFunctionType() ? 0 : Name.size();
 LastReplacementEnd = ReplaceRange.getEnd().getLocWithOffset(Offset);
   }
 

diff  --git a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h 
b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
index 5c741a92d01310..7054778d84a0c6 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
@@ -20,6 +20,7 @@ namespace clang::tidy::modernize {
 class UseUsingCheck : public ClangTidyCheck {
 
   const bool IgnoreMacros;
+  const bool IgnoreExternC;
   SourceLocation LastReplacementEnd;
   llvm::DenseMap LastTagDeclRanges;
 

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 00f570bcd21842..ce82063dbfe23e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -408,7 +408,8 @@ Changes in existing checks
 
 - Improved :doc:`modernize-use-using
   ` check to fix function pointer and
-  forward declared ``typedef`` correctly.
+  forward declared ``typedef`` correctly. Added option `IgnoreExternC` to 
ignore ``typedef``
+  declaration in ``extern "C"`` scope.
 
 - Improved :doc:`performance-faster-string-find
   ` check to 

  1   2   >