[clang] [RISCV][FMV] Support target_clones (PR #85786)

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

BeMg wrote:

The proposal can be found at the 
https://github.com/riscv-non-isa/riscv-c-api-doc/pull/48.

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


[clang] [RISCV][FMV] Support target_clones (PR #85786)

2024-03-20 Thread via cfe-commits

llvmbot wrote:




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

Author: Piyou Chen (BeMg)


Changes

This patch enable the function multiversion(FMV) and `target_clones` attribute 
for RISC-V target. 

It will emit the IFUNC resolver function to select appropriate function during 
runtime.

---

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


12 Files Affected:

- (modified) clang/include/clang/Basic/TargetInfo.h (+2-1) 
- (modified) clang/lib/AST/ASTContext.cpp (+9) 
- (modified) clang/lib/Basic/Targets/RISCV.cpp (+8-2) 
- (modified) clang/lib/Basic/Targets/RISCV.h (+2) 
- (modified) clang/lib/CodeGen/CodeGenFunction.cpp (+101-1) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+3) 
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+2) 
- (modified) clang/lib/CodeGen/Targets/RISCV.cpp (+23) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+22) 
- (added) clang/test/CodeGen/attr-target-clones-riscv.c (+135) 
- (added) clang/test/CodeGenCXX/attr-target-clones-riscv.cpp (+136) 
- (added) clang/test/SemaCXX/attr-target-clones-riscv.cpp (+28) 


``diff
diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 374595edd2ce4a..aa48596fbce07d 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1445,7 +1445,8 @@ class TargetInfo : public TransferrableTargetInfo,
   /// Identify whether this target supports multiversioning of functions,
   /// which requires support for cpu_supports and cpu_is functionality.
   bool supportsMultiVersioning() const {
-return getTriple().isX86() || getTriple().isAArch64();
+return getTriple().isX86() || getTriple().isAArch64() ||
+   getTriple().isRISCV();
   }
 
   /// Identify whether this target supports IFuncs.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a8fae76a43a4d..0fd75e0b36b123 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13636,6 +13636,15 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Features.insert(Features.begin(),
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
+} else if (Target->getTriple().isRISCV()) {
+  if (VersionStr != "default") {
+ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(VersionStr);
+Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+ParsedAttr.Features.end());
+  }
+  Features.insert(Features.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.end());
 } else {
   if (VersionStr.starts_with("arch="))
 TargetCPU = VersionStr.drop_front(sizeof("arch=") - 1);
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index a6d4af2b88111a..8e9132c9191a3c 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -257,7 +257,7 @@ bool RISCVTargetInfo::initFeatureMap(
 
   // If a target attribute specified a full arch string, override all the ISA
   // extension target features.
-  const auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
+  const auto I = llvm::find(FeaturesVec, "+__RISCV_TargetAttrNeedOverride");
   if (I != FeaturesVec.end()) {
 std::vector OverrideFeatures(std::next(I), FeaturesVec.end());
 
@@ -366,6 +366,12 @@ bool 
RISCVTargetInfo::handleTargetFeatures(std::vector &Features,
   return true;
 }
 
+bool RISCVTargetInfo::isValidFeatureName(StringRef Feature) const {
+  if (Feature.starts_with("__RISCV_TargetAttrNeedOverride"))
+return true;
+  return llvm::RISCVISAInfo::isSupportedExtensionFeature(Feature);
+}
+
 bool RISCVTargetInfo::isValidCPUName(StringRef Name) const {
   bool Is64Bit = getTriple().isArch64Bit();
   return llvm::RISCV::parseCPU(Name, Is64Bit);
@@ -390,7 +396,7 @@ void RISCVTargetInfo::fillValidTuneCPUList(
 
 static void handleFullArchString(StringRef FullArchStr,
  std::vector &Features) {
-  Features.push_back("__RISCV_TargetAttrNeedOverride");
+  Features.push_back("+__RISCV_TargetAttrNeedOverride");
   auto RII = llvm::RISCVISAInfo::parseArchString(
   FullArchStr, /* EnableExperimentalExtension */ true);
   if (llvm::errorToBool(RII.takeError())) {
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index bfbdafb682c851..ef8f59185d753c 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -106,6 +106,8 @@ class RISCVTargetInfo : public TargetInfo {
   bool handleTargetFeatures(std::vector &Features,
 DiagnosticsEngine &Diags) override;
 
+  bool isValidFeatureName(StringRef Feature) const override;
+
   bool hasBitIntType() const override { return true

[clang] [RISCV][FMV] Support target_clones (PR #85786)

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

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


[clang] [RISCV][FMV] Support target_clones (PR #85786)

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

https://github.com/BeMg updated https://github.com/llvm/llvm-project/pull/85786

>From 239b404203c66ab5336ffdfb45969a50c439a1c0 Mon Sep 17 00:00:00 2001
From: Piyou Chen 
Date: Tue, 19 Mar 2024 06:22:17 -0700
Subject: [PATCH 1/2] [RISCV][FMV] Support target_clones

---
 clang/include/clang/Basic/TargetInfo.h|   3 +-
 clang/lib/AST/ASTContext.cpp  |   9 ++
 clang/lib/Basic/Targets/RISCV.cpp |  10 +-
 clang/lib/Basic/Targets/RISCV.h   |   2 +
 clang/lib/CodeGen/CodeGenFunction.cpp | 102 -
 clang/lib/CodeGen/CodeGenFunction.h   |   3 +
 clang/lib/CodeGen/CodeGenModule.cpp   |   2 +
 clang/lib/CodeGen/Targets/RISCV.cpp   |  23 +++
 clang/lib/Sema/SemaDeclAttr.cpp   |  22 +++
 clang/test/CodeGen/attr-target-clones-riscv.c | 135 +
 .../CodeGenCXX/attr-target-clones-riscv.cpp   | 136 ++
 .../test/SemaCXX/attr-target-clones-riscv.cpp |  19 +++
 12 files changed, 462 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-target-clones-riscv.c
 create mode 100644 clang/test/CodeGenCXX/attr-target-clones-riscv.cpp
 create mode 100644 clang/test/SemaCXX/attr-target-clones-riscv.cpp

diff --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 374595edd2ce4a..aa48596fbce07d 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1445,7 +1445,8 @@ class TargetInfo : public TransferrableTargetInfo,
   /// Identify whether this target supports multiversioning of functions,
   /// which requires support for cpu_supports and cpu_is functionality.
   bool supportsMultiVersioning() const {
-return getTriple().isX86() || getTriple().isAArch64();
+return getTriple().isX86() || getTriple().isAArch64() ||
+   getTriple().isRISCV();
   }
 
   /// Identify whether this target supports IFuncs.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a8fae76a43a4d..0fd75e0b36b123 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -13636,6 +13636,15 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   Features.insert(Features.begin(),
   Target->getTargetOpts().FeaturesAsWritten.begin(),
   Target->getTargetOpts().FeaturesAsWritten.end());
+} else if (Target->getTriple().isRISCV()) {
+  if (VersionStr != "default") {
+ParsedTargetAttr ParsedAttr = Target->parseTargetAttr(VersionStr);
+Features.insert(Features.begin(), ParsedAttr.Features.begin(),
+ParsedAttr.Features.end());
+  }
+  Features.insert(Features.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.begin(),
+  Target->getTargetOpts().FeaturesAsWritten.end());
 } else {
   if (VersionStr.starts_with("arch="))
 TargetCPU = VersionStr.drop_front(sizeof("arch=") - 1);
diff --git a/clang/lib/Basic/Targets/RISCV.cpp 
b/clang/lib/Basic/Targets/RISCV.cpp
index a6d4af2b88111a..8e9132c9191a3c 100644
--- a/clang/lib/Basic/Targets/RISCV.cpp
+++ b/clang/lib/Basic/Targets/RISCV.cpp
@@ -257,7 +257,7 @@ bool RISCVTargetInfo::initFeatureMap(
 
   // If a target attribute specified a full arch string, override all the ISA
   // extension target features.
-  const auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride");
+  const auto I = llvm::find(FeaturesVec, "+__RISCV_TargetAttrNeedOverride");
   if (I != FeaturesVec.end()) {
 std::vector OverrideFeatures(std::next(I), FeaturesVec.end());
 
@@ -366,6 +366,12 @@ bool 
RISCVTargetInfo::handleTargetFeatures(std::vector &Features,
   return true;
 }
 
+bool RISCVTargetInfo::isValidFeatureName(StringRef Feature) const {
+  if (Feature.starts_with("__RISCV_TargetAttrNeedOverride"))
+return true;
+  return llvm::RISCVISAInfo::isSupportedExtensionFeature(Feature);
+}
+
 bool RISCVTargetInfo::isValidCPUName(StringRef Name) const {
   bool Is64Bit = getTriple().isArch64Bit();
   return llvm::RISCV::parseCPU(Name, Is64Bit);
@@ -390,7 +396,7 @@ void RISCVTargetInfo::fillValidTuneCPUList(
 
 static void handleFullArchString(StringRef FullArchStr,
  std::vector &Features) {
-  Features.push_back("__RISCV_TargetAttrNeedOverride");
+  Features.push_back("+__RISCV_TargetAttrNeedOverride");
   auto RII = llvm::RISCVISAInfo::parseArchString(
   FullArchStr, /* EnableExperimentalExtension */ true);
   if (llvm::errorToBool(RII.takeError())) {
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index bfbdafb682c851..ef8f59185d753c 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -106,6 +106,8 @@ class RISCVTargetInfo : public TargetInfo {
   bool handleTargetFeatures(std::vector &Features,
 DiagnosticsEngine &Diags) override;
 
+  bool is

[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-20 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> because we don't yet support non-zero initialization (as described in commit 
> [5955a0f](https://github.com/llvm/llvm-project/commit/5955a0f9375a8c0b134eeb4a8de5155dcce7c94f))

I'm confused.  We support non-zero init, and there are tests for non-zero init 
in that commit. The commit message mentions dynamic initialization, but that's 
not non-zero; that's "requires code to run at program startup".

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


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

2024-03-20 Thread Kai Luo via cfe-commits


@@ -329,6 +329,12 @@ def FeatureAIXLocalExecTLS :
"Produce a TOC-free local-exec TLS sequence for this 
function "
"for 64-bit AIX">;
 
+def FeatureAIXSharedLibraryTLSModelHeuristic :
+  SubtargetFeature<"aix-shared-library-tls-model-heuristic",

bzEq wrote:

This should be an optimization, maybe rename to 
`aix-shared-library-tls-model-opt`, we perform optimization based on some 
heuristics.

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


[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-03-20 Thread Abhin P Jose via cfe-commits

Abhinkop wrote:

> I believe this patch is causing some issues on two PPC bots. Would you be 
> able to help take a look? 
> https://lab.llvm.org/buildbot/#/builders/57/builds/33601/steps/5/logs/stdio 
> https://lab.llvm.org/buildbot/#/builders/36/builds/43759/steps/12/logs/stdio

I guess adding this flag (-Wno-cast-function-type-strict) will make the error 
go away. But it is caused by the conversion of the second argument "void*" to 
"siginfo_t *" when casting from "SignalHandlerType" i.e. "void 
(*__sanitizer::SignalHandlerType)(int, void *, void *);" to "void 
(*sa_sigaction) (int, siginfo_t *, void *);". If you are sure that this 
conversion is valid, I guess we can add this file. Might be similar for others.

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


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

2024-03-20 Thread Kai Luo via cfe-commits


@@ -3369,6 +3369,48 @@ SDValue 
PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
   bool Is64Bit = Subtarget.isPPC64();
   bool HasAIXSmallLocalExecTLS = Subtarget.hasAIXSmallLocalExecTLS();
   TLSModel::Model Model = getTargetMachine().getTLSModel(GV);
+  // Initialize heuristic setting lazily:
+  // (1) Use initial-exec for single TLS var reference within current function.
+  // (2) Use local-dynamic for multiple TLS var references within current func.
+  PPCFunctionInfo *FuncInfo =
+  DAG.getMachineFunction().getInfo();
+  if (Subtarget.hasAIXShLibTLSModelHeuristic() &&
+  !FuncInfo->isAIXFuncUseInitDone()) {
+std::set TLSGV;

bzEq wrote:

```suggestion
SmallPtrSet TLSGV;
```

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


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

2024-03-20 Thread Kai Luo via cfe-commits


@@ -3369,6 +3369,48 @@ SDValue 
PPCTargetLowering::LowerGlobalTLSAddressAIX(SDValue Op,
   bool Is64Bit = Subtarget.isPPC64();
   bool HasAIXSmallLocalExecTLS = Subtarget.hasAIXSmallLocalExecTLS();
   TLSModel::Model Model = getTargetMachine().getTLSModel(GV);
+  // Initialize heuristic setting lazily:
+  // (1) Use initial-exec for single TLS var reference within current function.
+  // (2) Use local-dynamic for multiple TLS var references within current func.
+  PPCFunctionInfo *FuncInfo =
+  DAG.getMachineFunction().getInfo();
+  if (Subtarget.hasAIXShLibTLSModelHeuristic() &&
+  !FuncInfo->isAIXFuncUseInitDone()) {
+std::set TLSGV;
+for (SDNode &Node : DAG.allnodes()) {

bzEq wrote:

One DAG is mapped to a single basic block, I notice your description is about 
whole function. So the size of `TLSGV` is smaller than what you really want to 
count.

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


[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)

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

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

>From e19f49ca2660cbcd64fb81aae0428e899d61cac6 Mon Sep 17 00:00:00 2001
From: Roberto Bampi 
Date: Thu, 7 Mar 2024 18:10:56 +0100
Subject: [PATCH 1/3] [clang-format] Add --fail-on-incomplete-format.

At the moment clang-format will return exit code 0 on incomplete
results. In scripts it would sometimes be useful if clang-format would
instead fail in those cases, signalling that there was something wrong
with the code being formatted.
---
 clang/docs/ClangFormat.rst   |  1 +
 clang/test/Format/fail-on-incomplete.cpp |  4 
 clang/tools/clang-format/ClangFormat.cpp | 14 +++---
 3 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/Format/fail-on-incomplete.cpp

diff --git a/clang/docs/ClangFormat.rst b/clang/docs/ClangFormat.rst
index 819d9ee9f9cde1..80dc38a075c8fc 100644
--- a/clang/docs/ClangFormat.rst
+++ b/clang/docs/ClangFormat.rst
@@ -61,6 +61,7 @@ to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# 
code.
 --dry-run  - If set, do not actually make the 
formatting changes
 --dump-config  - Dump configuration options to stdout and 
exit.
  Can be used with -style option.
+--fail-on-incomplete-format- If set, fail with exit code 1 on 
incomplete format.
 --fallback-style=  - The name of the predefined style used as a
  fallback in case clang-format is invoked 
with
  -style=file, but can not find the 
.clang-format
diff --git a/clang/test/Format/fail-on-incomplete.cpp 
b/clang/test/Format/fail-on-incomplete.cpp
new file mode 100644
index 00..42ddea66faf6ee
--- /dev/null
+++ b/clang/test/Format/fail-on-incomplete.cpp
@@ -0,0 +1,4 @@
+// RUN: not clang-format %s -style=LLVM -fail-on-incomplete-format
+// RUN: clang-format %s -style=LLVM
+int a(
+
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index e122cea50f7268..58027af5d9e091 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -205,6 +205,11 @@ static cl::list FileNames(cl::Positional,
cl::desc("[@] [ ...]"),
cl::cat(ClangFormatCategory));
 
+static cl::opt FailOnIncompleteFormat(
+"fail-on-incomplete-format",
+cl::desc("If set, fail with exit code 1 on incomplete format."),
+cl::init(false), cl::cat(ClangFormatCategory));
+
 namespace clang {
 namespace format {
 
@@ -399,7 +404,7 @@ class ClangFormatDiagConsumer : public DiagnosticConsumer {
 };
 
 // Returns true on error.
-static bool format(StringRef FileName) {
+static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
   const bool IsSTDIN = FileName == "-";
   if (!OutputXML && Inplace && IsSTDIN) {
 errs() << "error: cannot use -i when reading from stdin.\n";
@@ -535,6 +540,9 @@ static bool format(StringRef FileName) {
   Rewrite.getEditBuffer(ID).write(outs());
 }
   }
+  if (ErrorOnIncompleteFormat && !Status.FormatComplete)
+return true;
+
   return false;
 }
 
@@ -699,7 +707,7 @@ int main(int argc, const char **argv) {
   }
 
   if (FileNames.empty())
-return clang::format::format("-");
+return clang::format::format("-", FailOnIncompleteFormat);
 
   if (FileNames.size() > 1 &&
   (!Offsets.empty() || !Lengths.empty() || !LineRanges.empty())) {
@@ -717,7 +725,7 @@ int main(int argc, const char **argv) {
   errs() << "Formatting [" << FileNo++ << "/" << FileNames.size() << "] "
  << FileName << "\n";
 }
-Error |= clang::format::format(FileName);
+Error |= clang::format::format(FileName, FailOnIncompleteFormat);
   }
   return Error ? 1 : 0;
 }

>From af442672b7957593d37a1640b316fa4d8ec00467 Mon Sep 17 00:00:00 2001
From: Roberto Bampi 
Date: Fri, 8 Mar 2024 14:51:49 +0100
Subject: [PATCH 2/3] Update clang/tools/clang-format/ClangFormat.cpp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Björn Schäpers 
---
 clang/tools/clang-format/ClangFormat.cpp | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 58027af5d9e091..ed401135ad8433 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -540,10 +540,7 @@ static bool format(StringRef FileName, bool 
ErrorOnIncompleteFormat = false) {
   Rewrite.getEditBuffer(ID).write(outs());
 }
   }
-  if (ErrorOnIncompleteFormat && !Status.FormatComplete)
-return true;
-
-  return false;
+  return ErrorOnIncompleteFormat && !Status.FormatComplete;
 }
 
 } // namespace format

>From f181f24ef9dff3d978eaa13aae273f670cbdaaa8 Mon Sep 17 00:00:00 2001
Fr

[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-20 Thread Kees Cook via cfe-commits

https://github.com/kees updated https://github.com/llvm/llvm-project/pull/84428

>From eb5138b45fa450737600050ad8dabdcb27513d42 Mon Sep 17 00:00:00 2001
From: Kees Cook 
Date: Thu, 7 Mar 2024 17:03:09 -0800
Subject: [PATCH 1/6] [Clang][Sema]: Allow flexible arrays in unions and alone
 in structs

GNU and MSVC have extensions where flexible array members (or their
equivalent) can be in unions or alone in structs. This is already fully
supported in Clang through the 0-sized array ("fake flexible array")
extension or when C99 flexible array members have been syntactically
obfuscated.

Clang needs to explicitly allow these extensions directly for C99
flexible arrays, since they are common code patterns in active use by the
Linux kernel (and other projects). Such projects have been using either
0-sized arrays (which is considered deprecated in favor of C99 flexible
array members) or via obfuscated syntax, both of which complicate their
code bases.

For example, these do not error by default:

union one {
int a;
int b[0];
};

union two {
int a;
struct {
struct { } __empty;
int b[];
};
};

But this does:

union three {
int a;
int b[];
};

Remove the default error diagnostics for this but continue to provide
warnings under Microsoft or GNU extensions checks. This will allow for
a seamless transition for code bases away from 0-sized arrays without
losing existing code patterns. Add explicit checking for the warnings
under various constructions.

Fixes #84565
---
 clang/docs/ReleaseNotes.rst   |  3 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  5 --
 clang/lib/Sema/SemaDecl.cpp   |  8 +--
 clang/test/C/drs/dr5xx.c  |  2 +-
 clang/test/Sema/flexible-array-in-union.c | 53 +--
 clang/test/Sema/transparent-union.c   |  4 +-
 6 files changed, 57 insertions(+), 18 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1b901a27fd19d1..960ab7e021cf2f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -214,6 +214,9 @@ Improvements to Clang's diagnostics
 - Clang now diagnoses lambda function expressions being implicitly cast to 
boolean values, under ``-Wpointer-bool-conversion``.
   Fixes #GH82512.
 
+- ``-Wmicrosoft`` or ``-Wgnu`` is now required to diagnose C99 flexible
+  array members in a union or alone in a struct.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c8dfdc08f5ea07..f09121b8c7ec8f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6447,9 +6447,6 @@ def ext_c99_flexible_array_member : Extension<
 def err_flexible_array_virtual_base : Error<
   "flexible array member %0 not allowed in "
   "%select{struct|interface|union|class|enum}1 which has a virtual base 
class">;
-def err_flexible_array_empty_aggregate : Error<
-  "flexible array member %0 not allowed in otherwise empty "
-  "%select{struct|interface|union|class|enum}1">;
 def err_flexible_array_has_nontrivial_dtor : Error<
   "flexible array member %0 of type %1 with non-trivial destruction">;
 def ext_flexible_array_in_struct : Extension<
@@ -6464,8 +6461,6 @@ def ext_flexible_array_empty_aggregate_ms : Extension<
   "flexible array member %0 in otherwise empty "
   "%select{struct|interface|union|class|enum}1 is a Microsoft extension">,
   InGroup;
-def err_flexible_array_union : Error<
-  "flexible array member %0 in a union is not allowed">;
 def ext_flexible_array_union_ms : Extension<
   "flexible array member %0 in a union is a Microsoft extension">,
   InGroup;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 67e56a917a51de..053122b588246b 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19357,15 +19357,11 @@ void Sema::ActOnFields(Scope *S, SourceLocation 
RecLoc, Decl *EnclosingDecl,
 } else if (Record->isUnion())
   DiagID = getLangOpts().MicrosoftExt
? diag::ext_flexible_array_union_ms
-   : getLangOpts().CPlusPlus
- ? diag::ext_flexible_array_union_gnu
- : diag::err_flexible_array_union;
+   : diag::ext_flexible_array_union_gnu;
 else if (NumNamedMembers < 1)
   DiagID = getLangOpts().MicrosoftExt
? diag::ext_flexible_array_empty_aggregate_ms
-   : getLangOpts().CPlusPlus
- ? diag::ext_flexible_array_empty_aggregate_gnu
- : diag::err_flexible_array_empty_aggregate;
+   : diag::ext_flexible_array_empty_aggregate_gnu;
 
 if (DiagID)
   Diag(FD->getLocatio

[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-20 Thread Kees Cook via cfe-commits

kees wrote:

> `InitListChecker::CheckStructUnionTypes` never calls 
> `StructuredList->setInitializedFieldInUnion`

Ah-ha, thank you for the pointer. I think I've figured this out: initialization 
was avoiding flexible arrays because we don't yet support non-zero 
initialization (as described in commit 
5955a0f9375a8c0b134eeb4a8de5155dcce7c94f). However, we _do_ want to allow zero 
initialization. This fixes the Assert and the sketchy `undef`s in the codegen 
output. Now we get zero inits:

```diff
-// If we've hit the flexible array member at the end, we're done.
-if (Field->getType()->isIncompleteArrayType())
+// If we've hit a flexible array member, only allow zero initialization.
+// Other values are not yet supported. See commit 5955a0f9375a.
+if (Field->getType()->isIncompleteArrayType() && !IsZeroInitializer(Init))
```

> I think things can be simplified a bit further

Ah yes! That's much nicer. Since we're processing the Union, we can just return 
completely instead of continuing the loop. Thanks!


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


[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)

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

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


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


[clang] [clang-format] Add --fail-on-incomplete-format. (PR #84346)

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


@@ -0,0 +1,5 @@
+// RUN: cat %s | not clang-format --fail-on-incomplete-format | FileCheck %s
+// RUN: cat %s | clang-format | FileCheck %s
+int a([) {}
+
+// CHECK: int a([) {}

owenca wrote:

> Done. It took me quite a while but `-style=LLVM` is also required as the 
> .clang-format in the parent directory sets DisableFormat to true. Before I 
> didn't notice because the `cat %s | clang-format` was bypassing the lookup 
> for the config file.

It seems that `-style=LLVM` is needed whether the input comes from the stdin or 
a file.

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


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

2024-03-20 Thread Kai Luo via cfe-commits


@@ -80,6 +80,7 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   bool IsISA3_0 = false;
   bool IsISA3_1 = false;
   bool HasQuadwordAtomics = false;
+  bool HasAIXShLibTLSModelHeuristic = false;

bzEq wrote:

This looks redundant. Frontend doesn't read this flag to change behavior.

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


[clang] [llvm] [InstCombine] Canonicalize `(sitofp x)` -> `(uitofp x)` if `x >= 0` (PR #82404)

2024-03-20 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

> Apart from the correctness issues, we've seen some regressions on various 
> benchmarks from LLVM Test Suite after this patch. Specifically, around 3-5% 
> regression on x86-64 in various metrics of the 
> [Interpolation](https://github.com/llvm/llvm-test-suite/tree/main/MicroBenchmarks/ImageProcessing/Interpolation)
>  benchmarks, and up to 30% regression on a number of floating point-centric 
> benchmarks from 
> https://github.com/llvm/llvm-test-suite/tree/main/SingleSource/Benchmarks/Misc
>  (flops-4.c, flops-5.c, flops-6.c, flops-8.c, fp-convert.c). The numbers vary 
> depending on the microarchitecture, with Skylake being less affected (on the 
> order of ~10%) and AMD Rome showing larger regressions (up to 30%).

FYI this patch saves ~3% instructions for some benchmarks from LLVM-test-suite 
on RISC-V.
https://github.com/dtcxzyw/llvm-ci/issues/1115
https://github.com/dtcxzyw/llvm-ci/issues/1114

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


[clang] [CMake] Change GCC_INSTALL_PREFIX from warning to fatal error (PR #85891)

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

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


[clang] [clang][Sema] Refine unused-member-function diagnostic message for constructors (PR #84515)

2024-03-20 Thread Takuya Shimizu via cfe-commits

hazohelet wrote:

Please add a release note line to `clang/docs/ReleaseNotes.rst` because this 
patch changes the diagnostic behavior of clang

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


[clang] d59730d - [CMake] Change GCC_INSTALL_PREFIX from warning to fatal error (#85891)

2024-03-20 Thread via cfe-commits

Author: Fangrui Song
Date: 2024-03-20T22:45:38-07:00
New Revision: d59730d7060f33dd1607be1fd7813be78759a953

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

LOG: [CMake] Change GCC_INSTALL_PREFIX from warning to fatal error (#85891)

unless USE_DEPRECATED_GCC_INSTALL_PREFIX (temporary escape hatch) is
set. Setting GCC_INSTALL_PREFIX leads to a warning for Clang 18.1
(#77537) and will be completely removed for Clang 20.

Link:
discourse.llvm.org/t/add-gcc-install-dir-deprecate-gcc-toolchain-and-remove-gcc-install-prefix/65091
Link:
discourse.llvm.org/t/correct-cmake-parameters-for-building-clang-and-lld-for-riscv/72833

Added: 


Modified: 
clang/CMakeLists.txt
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index 47fc2e4886cfc2..761dab8c28c134 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -190,11 +190,12 @@ set(CLANG_RESOURCE_DIR "" CACHE STRING
 set(C_INCLUDE_DIRS "" CACHE STRING
   "Colon separated list of directories clang will search for headers.")
 
+set(USE_DEPRECATED_GCC_INSTALL_PREFIX OFF CACHE BOOL "Temporary workaround 
before GCC_INSTALL_PREFIX is completely removed")
 set(GCC_INSTALL_PREFIX "" CACHE PATH "Directory where gcc is installed." )
 set(DEFAULT_SYSROOT "" CACHE STRING
   "Default  to all compiler invocations for --sysroot=." )
-if(GCC_INSTALL_PREFIX)
-  message(WARNING "GCC_INSTALL_PREFIX is deprecated and will be removed. Use "
+if(GCC_INSTALL_PREFIX AND NOT USE_DEPRECATED_GCC_INSTALL_PREFIX)
+  message(FATAL_ERROR "GCC_INSTALL_PREFIX is deprecated and will be removed. 
Use "
 "configuration files 
(https://clang.llvm.org/docs/UsersManual.html#configuration-files)"
 "to specify the default --gcc-install-dir= or --gcc-triple=. 
--gcc-toolchain= is discouraged. "
 "See https://github.com/llvm/llvm-project/pull/77537 for detail.")

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c0b0c8a8a3ea85..a9c55ef662a0b9 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -37,6 +37,9 @@ These changes are ones which we think may surprise users when 
upgrading to
 Clang |release| because of the opportunity they pose for disruption to existing
 code bases.
 
+- Setting the deprecated CMake variable ``GCC_INSTALL_PREFIX`` (which sets the
+  default ``--gcc-toolchain=``) now leads to a fatal error.
+
 C/C++ Language Potentially Breaking Changes
 ---
 



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


[clang] [llvm] Move MLIR before clang for in the list of external projects (PR #86085)

2024-03-20 Thread Nathan Lanza via cfe-commits

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


[clang] [llvm] Move MLIR before clang for in the list of external projects (PR #86085)

2024-03-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nathan Lanza (lanza)


Changes

clang now depends on MLIR and thus we need to include it first for it's
dependencies to be added properly.


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


2 Files Affected:

- (added) clang/test/CIR/CodeGen/basic.c (+1) 
- (modified) llvm/tools/CMakeLists.txt (+1-2) 


``diff
diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c
new file mode 100644
index 00..5c103141a2
--- /dev/null
+++ b/clang/test/CIR/CodeGen/basic.c
@@ -0,0 +1 @@
+// RUN: true
diff --git a/llvm/tools/CMakeLists.txt b/llvm/tools/CMakeLists.txt
index c6116ac81d12b2..ef4ac1eff6eba0 100644
--- a/llvm/tools/CMakeLists.txt
+++ b/llvm/tools/CMakeLists.txt
@@ -37,11 +37,10 @@ add_llvm_tool_subdirectory(llvm-profdata)
 
 # Projects supported via LLVM_EXTERNAL_*_SOURCE_DIR need to be explicitly
 # specified.
+add_llvm_external_project(mlir)
 add_llvm_external_project(clang)
 add_llvm_external_project(lld)
 add_llvm_external_project(lldb)
-add_llvm_external_project(mlir)
-# Flang depends on mlir, so place it afterward
 add_llvm_external_project(flang)
 add_llvm_external_project(bolt)
 

``




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


[clang] [llvm] Move MLIR before clang for in the list of external projects (PR #86085)

2024-03-20 Thread Nathan Lanza via cfe-commits

https://github.com/lanza created https://github.com/llvm/llvm-project/pull/86085

clang now depends on MLIR and thus we need to include it first for it's
dependencies to be added properly.


>From af55dfdb1fa18413179306f42946183ba66517a1 Mon Sep 17 00:00:00 2001
From: Nathan Lanza 
Date: Thu, 21 Mar 2024 05:22:53 +
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/test/CIR/CodeGen/basic.c | 1 +
 llvm/tools/CMakeLists.txt  | 3 +--
 2 files changed, 2 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CIR/CodeGen/basic.c

diff --git a/clang/test/CIR/CodeGen/basic.c b/clang/test/CIR/CodeGen/basic.c
new file mode 100644
index 00..5c103141a2
--- /dev/null
+++ b/clang/test/CIR/CodeGen/basic.c
@@ -0,0 +1 @@
+// RUN: true
diff --git a/llvm/tools/CMakeLists.txt b/llvm/tools/CMakeLists.txt
index c6116ac81d12b2..ef4ac1eff6eba0 100644
--- a/llvm/tools/CMakeLists.txt
+++ b/llvm/tools/CMakeLists.txt
@@ -37,11 +37,10 @@ add_llvm_tool_subdirectory(llvm-profdata)
 
 # Projects supported via LLVM_EXTERNAL_*_SOURCE_DIR need to be explicitly
 # specified.
+add_llvm_external_project(mlir)
 add_llvm_external_project(clang)
 add_llvm_external_project(lld)
 add_llvm_external_project(lldb)
-add_llvm_external_project(mlir)
-# Flang depends on mlir, so place it afterward
 add_llvm_external_project(flang)
 add_llvm_external_project(bolt)
 

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


[clang] [X86_64] fix arg pass error in struct. (PR #85394)

2024-03-20 Thread Longsheng Mou via cfe-commits

CoTinker wrote:

Which is more appropriate to pass this structure through, memory or register?

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


[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-03-20 Thread via cfe-commits

https://github.com/wheatman updated 
https://github.com/llvm/llvm-project/pull/78742

>From a1275f9711d9e0c485c14e605c677446c4366393 Mon Sep 17 00:00:00 2001
From: Brian Wheatman 
Date: Fri, 19 Jan 2024 11:13:33 -0500
Subject: [PATCH] [clang][Sema] Fix for overflow in enumerators(#24667)

Enums which do not have a specified type can only grow to bigger types
which contain more bits than the prior types.  This means that the
largest signed integer type cannot grow to the largest unsigned integer types.

In the process also implements N3029 Improved Normal Enumerations and
patially implements N3030 Enhancements to Enumerations which brings C enums
more inline with C++ enums.

Fixes #24667
---
 clang/docs/ReleaseNotes.rst |   8 +++
 clang/lib/Sema/SemaDecl.cpp |  90 +++--
 clang/test/C/C2x/n3029.c|  81 ++
 clang/test/C/C2x/n3030.c| 130 
 clang/test/Sema/enum.c  |  43 ++--
 clang/test/SemaCXX/enum.cpp |   2 +
 6 files changed, 329 insertions(+), 25 deletions(-)
 create mode 100644 clang/test/C/C2x/n3029.c
 create mode 100644 clang/test/C/C2x/n3030.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a74c070ff9ffe..9ae53d3a400ad5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -159,6 +159,12 @@ C23 Feature Support
   ``__TYPE_FMTb__`` (e.g., ``__UINT_FAST64_FMTB__``) in C23 mode for use with
   macros typically exposed from , such as ``PRIb8``.
   (`#81896: `_).
+- Enumerations should allow values greater than ``INT_MAX`` and smaller than
+  ``INT_MIN``, in order to provide a value-preserved set of integer constants. 
`N3029 Improved Normal Enumerations 
`_
+
+- Enumerations should have the ability to specify the underlying type to aid
+  in portability and usability across platforms, across ABIs, and across
+  languages (for serialization and similar purposes). `N3030 Enhancements to 
Enumerations `_
 
 - Clang now supports `N3018 The constexpr specifier for object definitions`
   `_.
@@ -300,6 +306,8 @@ Bug Fixes in This Version
 
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
+- Fixes a miscompilation when an enum has a specified value such that the 
automatic
+  increment overflows a ``signed long``. Fixes #GH24667.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5850cd0ab6b9aa..de672237e676e0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19881,6 +19881,18 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // - If an initializer is specified for an enumerator, the
   //   initializing value has the same type as the expression.
   EltTy = Val->getType();
+} else if (getLangOpts().C23) {
+  // C23 6.7.2.2p11 b4
+  // int, if given explicitly with = and the value of the
+  // integer constant expression is representable by an int
+  //
+  // C23 6.7.2.2p11 b5
+  // the type of the integer constant expression, if given
+  // explicitly with = and if the value of the integer
+  // constant expression is not representable by int;
+  if (isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
+Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
+  EltTy = Val->getType();
 } else {
   // C99 6.7.2.2p2:
   //   The expression that defines the value of an enumeration constant
@@ -19890,8 +19902,8 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // Complain if the value is not representable in an int.
   if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
 Diag(IdLoc, diag::ext_enum_value_not_int)
-  << toString(EnumVal, 10) << Val->getSourceRange()
-  << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
+<< toString(EnumVal, 10) << Val->getSourceRange()
+<< (EnumVal.isUnsigned() || EnumVal.isNonNegative());
   else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
 // Force the type of the expression to 'int'.
 Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
@@ -19939,20 +19951,28 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
 //   sufficient to contain the incremented value. If no such type
 //   exists, the program is ill-formed.
 QualType T = getNextLargerIntegralType(Context, EltTy);
-if (T.isNull() || Enum->isFixed()) {
+if (En

[clang] [X86_32] Teach X86_32 va_arg to ignore empty structs. (PR #86075)

2024-03-20 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Longsheng Mou (CoTinker)


Changes

Empty structs are ignored for parameter passing purposes, but va_arg was 
incrementing the pointer anyway for that the size of empty struct in c++ is 1 
byte, which could lead to va_list getting out of sync. Fix #86057.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/X86.cpp (+4) 
- (added) clang/test/CodeGenCXX/x86_32-vaarg.cpp (+20) 


``diff
diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 1ec0f159ebcb8a..7931f56ad6835f 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1069,6 +1069,10 @@ Address X86_32ABIInfo::EmitVAArg(CodeGenFunction &CGF,
 
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
 
+  // Empty records are ignored for parameter passing purposes on non-Windows.
+  if (!IsWin32StructABI && isEmptyRecord(getContext(), Ty, true))
+return CGF.CreateMemTemp(Ty);
+
   // x86-32 changes the alignment of certain arguments on the stack.
   //
   // Just messing with TypeInfo like this works because we never pass
diff --git a/clang/test/CodeGenCXX/x86_32-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_32-vaarg.cpp
new file mode 100644
index 00..23eac1164118c6
--- /dev/null
+++ b/clang/test/CodeGenCXX/x86_32-vaarg.cpp
@@ -0,0 +1,20 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple i386-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple i386-linux-gnu -emit-llvm -x c -o - %s | FileCheck 
%s
+
+typedef struct {} empty;
+
+// CHECK-LABEL: @{{.*}}empty_record_test
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RESULT_PTR:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[LIST:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_EMPTY:%.*]], align 1
+// CHECK-NEXT:store ptr [[AGG_RESULT:%.*]], ptr [[RESULT_PTR]], align 4
+// CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4
+// CHECK-NEXT:call void @llvm.va_start(ptr [[LIST]])
+empty empty_record_test(int z, ...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, z);
+  return __builtin_va_arg(list, empty);
+}

``




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


[clang] [X86_32] Teach X86_32 va_arg to ignore empty structs. (PR #86075)

2024-03-20 Thread Longsheng Mou via cfe-commits

https://github.com/CoTinker created 
https://github.com/llvm/llvm-project/pull/86075

Empty structs are ignored for parameter passing purposes, but va_arg was 
incrementing the pointer anyway for that the size of empty struct in c++ is 1 
byte, which could lead to va_list getting out of sync. Fix #86057.

>From 944259ba90fc13c04b6bbd44ec1737fbbb56b2d1 Mon Sep 17 00:00:00 2001
From: Longsheng Mou 
Date: Thu, 21 Mar 2024 11:23:56 +0800
Subject: [PATCH] [X86_32] Teach X86_32 va_arg to ignore empty structs.

Empty structs are ignored for parameter passing purposes, but va_arg was
incrementing the pointer anyway for that the size of empty struct in c++
is 1 byte, which could lead to va_list getting out of sync.
---
 clang/lib/CodeGen/Targets/X86.cpp  |  4 
 clang/test/CodeGenCXX/x86_32-vaarg.cpp | 20 
 2 files changed, 24 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/x86_32-vaarg.cpp

diff --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 1ec0f159ebcb8a..7931f56ad6835f 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1069,6 +1069,10 @@ Address X86_32ABIInfo::EmitVAArg(CodeGenFunction &CGF,
 
   auto TypeInfo = getContext().getTypeInfoInChars(Ty);
 
+  // Empty records are ignored for parameter passing purposes on non-Windows.
+  if (!IsWin32StructABI && isEmptyRecord(getContext(), Ty, true))
+return CGF.CreateMemTemp(Ty);
+
   // x86-32 changes the alignment of certain arguments on the stack.
   //
   // Just messing with TypeInfo like this works because we never pass
diff --git a/clang/test/CodeGenCXX/x86_32-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_32-vaarg.cpp
new file mode 100644
index 00..23eac1164118c6
--- /dev/null
+++ b/clang/test/CodeGenCXX/x86_32-vaarg.cpp
@@ -0,0 +1,20 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple i386-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple i386-linux-gnu -emit-llvm -x c -o - %s | FileCheck 
%s
+
+typedef struct {} empty;
+
+// CHECK-LABEL: @{{.*}}empty_record_test
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RESULT_PTR:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[LIST:%.*]] = alloca ptr, align 4
+// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_EMPTY:%.*]], align 1
+// CHECK-NEXT:store ptr [[AGG_RESULT:%.*]], ptr [[RESULT_PTR]], align 4
+// CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4
+// CHECK-NEXT:call void @llvm.va_start(ptr [[LIST]])
+empty empty_record_test(int z, ...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, z);
+  return __builtin_va_arg(list, empty);
+}

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


[clang] [CIR][Basic][NFC] Add the CIR language to the Language enum (PR #86072)

2024-03-20 Thread Nathan Lanza via cfe-commits

https://github.com/lanza created https://github.com/llvm/llvm-project/pull/86072

Add the CIR language to the Language enum and the standard usages of it.

commit-id:fd12b2c2


>From 115f1dcca7b20dacdc5beef0e73819aef94f0ec1 Mon Sep 17 00:00:00 2001
From: Nathan Lanza 
Date: Thu, 21 Mar 2024 03:24:54 +
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 clang/include/clang/Basic/LangStandard.h|  1 +
 clang/include/clang/Driver/Types.def|  1 +
 clang/lib/Basic/LangStandards.cpp   |  3 +++
 .../Serialization/SymbolGraphSerializer.cpp |  1 +
 clang/lib/Frontend/CompilerInvocation.cpp   | 13 +++--
 clang/lib/Frontend/FrontendActions.cpp  |  1 +
 clang/lib/Frontend/FrontendOptions.cpp  |  1 +
 7 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 199e24c6731603..ed9572672f0563 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -41,6 +41,7 @@ enum class Language : uint8_t {
   RenderScript,
   HIP,
   HLSL,
+  CIR,
   ///@}
 };
 StringRef languageToString(Language L);
diff --git a/clang/include/clang/Driver/Types.def 
b/clang/include/clang/Driver/Types.def
index f72c27e1ee7019..0e0cae5fb7068d 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -90,6 +90,7 @@ TYPE("ir",   LLVM_BC,  INVALID,   
  "bc", phases
 TYPE("lto-ir",   LTO_IR,   INVALID, "s",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("lto-bc",   LTO_BC,   INVALID, "o",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
+TYPE("cir",  CIR,  INVALID, "cir",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 // Misc.
 TYPE("ast",  AST,  INVALID, "ast",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("ifs",  IFS,  INVALID, "ifs",
phases::IfsMerge)
diff --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index cb2c0772349982..c8c9292abcb22b 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -21,6 +21,8 @@ StringRef clang::languageToString(Language L) {
 return "Asm";
   case Language::LLVM_IR:
 return "LLVM IR";
+  case Language::CIR:
+return "ClangIR";
   case Language::C:
 return "C";
   case Language::CXX:
@@ -92,6 +94,7 @@ LangStandard::Kind 
clang::getDefaultLanguageStandard(clang::Language Lang,
   switch (Lang) {
   case Language::Unknown:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("Invalid input kind!");
   case Language::OpenCL:
 return LangStandard::lang_opencl12;
diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 349b93e2a2326f..545860acb7db80 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -208,6 +208,7 @@ StringRef getLanguageName(Language Lang) {
   case Language::Unknown:
   case Language::Asm:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("Unsupported language kind");
   }
 
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 0df6a82ccd8933..7bd91d4791ecf0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2757,6 +2757,9 @@ static void GenerateFrontendArgs(const FrontendOptions 
&Opts,
 case Language::HLSL:
   Lang = "hlsl";
   break;
+case Language::CIR:
+  Lang = "cir";
+  break;
 }
 
 GenerateArg(Consumer, OPT_x,
@@ -2958,6 +2961,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
   .Cases("ast", "pcm", "precompiled-header",
  InputKind(Language::Unknown, InputKind::Precompiled))
   .Case("ir", Language::LLVM_IR)
+  .Case("cir", Language::CIR)
   .Default(Language::Unknown);
 
 if (DashX.isUnknown())
@@ -3323,6 +3327,7 @@ static bool IsInputCompatibleWithStandard(InputKind IK,
   switch (IK.getLanguage()) {
   case Language::Unknown:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("should not parse language flags for this input");
 
   case Language::C:
@@ -3388,6 +3393,8 @@ static StringRef GetInputKindName(InputKind IK) {
 return "Asm";
   case Language::LLVM_IR:
 return "LLVM I

[clang] [clang] move -Wcast-function-type under -Wextra (PR #77178)

2024-03-20 Thread Amy Kwan via cfe-commits

amy-kwan wrote:

I believe this patch is causing some issues on two PPC bots. Would you be able 
to help take a look?
https://lab.llvm.org/buildbot/#/builders/57/builds/33601/steps/5/logs/stdio
https://lab.llvm.org/buildbot/#/builders/36/builds/43759/steps/12/logs/stdio

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


[clang] [llvm] Add Float `Dot` Intrinsic Lowering (PR #86071)

2024-03-20 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-llvm-ir

Author: Farzon Lotfi (farzonl)


Changes

Completes #83626
- `CGBuiltin.cpp` - modify `getDotProductIntrinsic` to be able to emit `dot2`, 
`dot3`, and `dot4` intrinsics based on element count
- `IntrinsicsDirectX.td` - for floating point add `dot2`, `dot3`, and `dot4` 
inntrinsics -`DXIL.td` add dxilop intrinsic lowering for `dot2`, `dot3`, & 
`dot4`. 
- `DXILOpLowering.cpp` - add vector arg flattening for dot product. 
- `DXILOpBuilder.h` - modify `createDXILOpCall` to take a smallVector instead 
of an iterator
- `DXILOpBuilder.cpp` - modify `createDXILOpCall` by moving the small vector up 
to the calling function in `DXILOpLowering.cpp`. 
  - Moving one function up gives us access to the `CallInst` and `Function` 
which were needed to distinguish the dot product intrinsics and get the 
operands without using the iterator.

---

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


11 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+16-9) 
- (modified) clang/test/CodeGenHLSL/builtins/dot.hlsl (+14-14) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+9-1) 
- (modified) llvm/lib/Target/DirectX/DXIL.td (+9) 
- (modified) llvm/lib/Target/DirectX/DXILOpBuilder.cpp (+3-5) 
- (modified) llvm/lib/Target/DirectX/DXILOpBuilder.h (+2-3) 
- (modified) llvm/lib/Target/DirectX/DXILOpLowering.cpp (+53-2) 
- (added) llvm/test/CodeGen/DirectX/dot2_error.ll (+10) 
- (added) llvm/test/CodeGen/DirectX/dot3_error.ll (+10) 
- (added) llvm/test/CodeGen/DirectX/dot4_error.ll (+10) 
- (added) llvm/test/CodeGen/DirectX/fdot.ll (+94) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 77cb269d43c5a8..a4b99181769326 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18036,15 +18036,22 @@ llvm::Value 
*CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
   return Arg;
 }
 
-Intrinsic::ID getDotProductIntrinsic(QualType QT) {
+Intrinsic::ID getDotProductIntrinsic(QualType QT, int elementCount) {
+  if (QT->hasFloatingRepresentation()) {
+switch (elementCount) {
+case 2:
+  return Intrinsic::dx_dot2;
+case 3:
+  return Intrinsic::dx_dot3;
+case 4:
+  return Intrinsic::dx_dot4;
+}
+  }
   if (QT->hasSignedIntegerRepresentation())
 return Intrinsic::dx_sdot;
-  if (QT->hasUnsignedIntegerRepresentation())
-return Intrinsic::dx_udot;
 
-  assert(QT->hasFloatingRepresentation());
-  return Intrinsic::dx_dot;
-  ;
+  assert(QT->hasUnsignedIntegerRepresentation());
+  return Intrinsic::dx_udot;
 }
 
 Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
@@ -18098,8 +18105,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 assert(T0->getScalarType() == T1->getScalarType() &&
"Dot product of vectors need the same element types.");
 
-[[maybe_unused]] auto *VecTy0 =
-E->getArg(0)->getType()->getAs();
+auto *VecTy0 = E->getArg(0)->getType()->getAs();
 [[maybe_unused]] auto *VecTy1 =
 E->getArg(1)->getType()->getAs();
 // A HLSLVectorTruncation should have happend
@@ -18108,7 +18114,8 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 
 return Builder.CreateIntrinsic(
 /*ReturnType=*/T0->getScalarType(),
-getDotProductIntrinsic(E->getArg(0)->getType()),
+getDotProductIntrinsic(E->getArg(0)->getType(),
+   VecTy0->getNumElements()),
 ArrayRef{Op0, Op1}, nullptr, "dx.dot");
   } break;
   case Builtin::BI__builtin_hlsl_lerp: {
diff --git a/clang/test/CodeGenHLSL/builtins/dot.hlsl 
b/clang/test/CodeGenHLSL/builtins/dot.hlsl
index 0f993193c00cce..307d71cce3cb6d 100644
--- a/clang/test/CodeGenHLSL/builtins/dot.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/dot.hlsl
@@ -110,21 +110,21 @@ uint64_t test_dot_ulong4(uint64_t4 p0, uint64_t4 p1) { 
return dot(p0, p1); }
 // NO_HALF: ret float %dx.dot
 half test_dot_half(half p0, half p1) { return dot(p0, p1); }
 
-// NATIVE_HALF: %dx.dot = call half @llvm.dx.dot.v2f16(<2 x half> %0, <2 x 
half> %1)
+// NATIVE_HALF: %dx.dot = call half @llvm.dx.dot2.v2f16(<2 x half> %0, <2 x 
half> %1)
 // NATIVE_HALF: ret half %dx.dot
-// NO_HALF: %dx.dot = call float @llvm.dx.dot.v2f32(<2 x float> %0, <2 x 
float> %1)
+// NO_HALF: %dx.dot = call float @llvm.dx.dot2.v2f32(<2 x float> %0, <2 x 
float> %1)
 // NO_HALF: ret float %dx.dot
 half test_dot_half2(half2 p0, half2 p1) { return dot(p0, p1); }
 
-// NATIVE_HALF: %dx.dot = call half @llvm.dx.dot.v3f16(<3 x half> %0, <3 x 
half> %1)
+// NATIVE_HALF: %dx.dot = call half @llvm.dx.dot3.v3f16(<3 x half> %0, <3 x 
half> %1)
 // NATIVE_HALF: ret half %dx.dot
-// NO_HALF: %dx.dot = call float @llvm.dx.dot.v3f32(<3 x float> %0, <3 x 
float> %1)
+// NO_HALF: %dx.dot = call float @llvm.dx.dot3.v3f32(<3 x float> %0, <3 x 
float

[clang] [CIR][Basic][NFC] Add the CIR language to the Language enum (PR #86072)

2024-03-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Nathan Lanza (lanza)


Changes

Add the CIR language to the Language enum and the standard usages of it.

commit-id:fd12b2c2


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


7 Files Affected:

- (modified) clang/include/clang/Basic/LangStandard.h (+1) 
- (modified) clang/include/clang/Driver/Types.def (+1) 
- (modified) clang/lib/Basic/LangStandards.cpp (+3) 
- (modified) clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp (+1) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+11-2) 
- (modified) clang/lib/Frontend/FrontendActions.cpp (+1) 
- (modified) clang/lib/Frontend/FrontendOptions.cpp (+1) 


``diff
diff --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 199e24c6731603..ed9572672f0563 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -41,6 +41,7 @@ enum class Language : uint8_t {
   RenderScript,
   HIP,
   HLSL,
+  CIR,
   ///@}
 };
 StringRef languageToString(Language L);
diff --git a/clang/include/clang/Driver/Types.def 
b/clang/include/clang/Driver/Types.def
index f72c27e1ee7019..0e0cae5fb7068d 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -90,6 +90,7 @@ TYPE("ir",   LLVM_BC,  INVALID,   
  "bc", phases
 TYPE("lto-ir",   LTO_IR,   INVALID, "s",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("lto-bc",   LTO_BC,   INVALID, "o",  
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
+TYPE("cir",  CIR,  INVALID, "cir",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 // Misc.
 TYPE("ast",  AST,  INVALID, "ast",
phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 TYPE("ifs",  IFS,  INVALID, "ifs",
phases::IfsMerge)
diff --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index cb2c0772349982..c8c9292abcb22b 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -21,6 +21,8 @@ StringRef clang::languageToString(Language L) {
 return "Asm";
   case Language::LLVM_IR:
 return "LLVM IR";
+  case Language::CIR:
+return "ClangIR";
   case Language::C:
 return "C";
   case Language::CXX:
@@ -92,6 +94,7 @@ LangStandard::Kind 
clang::getDefaultLanguageStandard(clang::Language Lang,
   switch (Lang) {
   case Language::Unknown:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("Invalid input kind!");
   case Language::OpenCL:
 return LangStandard::lang_opencl12;
diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 349b93e2a2326f..545860acb7db80 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -208,6 +208,7 @@ StringRef getLanguageName(Language Lang) {
   case Language::Unknown:
   case Language::Asm:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("Unsupported language kind");
   }
 
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 0df6a82ccd8933..7bd91d4791ecf0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2757,6 +2757,9 @@ static void GenerateFrontendArgs(const FrontendOptions 
&Opts,
 case Language::HLSL:
   Lang = "hlsl";
   break;
+case Language::CIR:
+  Lang = "cir";
+  break;
 }
 
 GenerateArg(Consumer, OPT_x,
@@ -2958,6 +2961,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, 
ArgList &Args,
   .Cases("ast", "pcm", "precompiled-header",
  InputKind(Language::Unknown, InputKind::Precompiled))
   .Case("ir", Language::LLVM_IR)
+  .Case("cir", Language::CIR)
   .Default(Language::Unknown);
 
 if (DashX.isUnknown())
@@ -3323,6 +3327,7 @@ static bool IsInputCompatibleWithStandard(InputKind IK,
   switch (IK.getLanguage()) {
   case Language::Unknown:
   case Language::LLVM_IR:
+  case Language::CIR:
 llvm_unreachable("should not parse language flags for this input");
 
   case Language::C:
@@ -3388,6 +3393,8 @@ static StringRef GetInputKindName(InputKind IK) {
 return "Asm";
   case Language::LLVM_IR:
 return "LLVM IR";
+  case Language::CIR:
+return "Clang IR";
 
   case Language::HLSL:
 return "HLSL";
@@ -3403,7 +3410,8 @@ void CompilerInvocationBase::GenerateLangArgs(const 
LangOptions &Opts,
   const llvm::Triple &T,

[clang] [llvm] Add Float `Dot` Intrinsic Lowering (PR #86071)

2024-03-20 Thread Farzon Lotfi via cfe-commits

https://github.com/farzonl created 
https://github.com/llvm/llvm-project/pull/86071

Completes #83626
- `CGBuiltin.cpp` - modify `getDotProductIntrinsic` to be able to emit `dot2`, 
`dot3`, and `dot4` intrinsics based on element count
- `IntrinsicsDirectX.td` - for floating point add `dot2`, `dot3`, and `dot4` 
inntrinsics -`DXIL.td` add dxilop intrinsic lowering for `dot2`, `dot3`, & 
`dot4`. 
- `DXILOpLowering.cpp` - add vector arg flattening for dot product. 
- `DXILOpBuilder.h` - modify `createDXILOpCall` to take a smallVector instead 
of an iterator
- `DXILOpBuilder.cpp` - modify `createDXILOpCall` by moving the small vector up 
to the calling function in `DXILOpLowering.cpp`. 
  - Moving one function up gives us access to the `CallInst` and `Function` 
which were needed to distinguish the dot product intrinsics and get the 
operands without using the iterator.

>From 7e794b6137d4ddb9d17a0412c637961cb622206a Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Tue, 19 Mar 2024 17:29:55 -0400
Subject: [PATCH] Add Float `Dot` Intrinsic Lowering Completes #83626 -
 `CGBuiltin.cpp` - modify `getDotProductIntrinsic` to be able to emit  
 `dot2`, `dot3`, and `dot4` intrinsics based on element count -
 `IntrinsicsDirectX.td` - for floating point add `dot2`,`dot3`, and `dot4`  
 inntrinsics -`DXIL.td` add dxilop intrinsic lowering for  `dot2`,`dot3`, &
 `dot4`. -`DXILOpLowering.cpp` - add vector arg flattening for dot product.
 -`DXILOpBuilder.h` - modify `createDXILOpCall` to take a smallVector instead
 of an iterator - `DXILOpBuilder.cpp` - modify createDXILOpCall by moving the
 small   vector up to the callee function  in `DXILOpLowering.cpp`. Moving one
   function up gives us access to the callInst and Function Which were  
 needed to distinguish the dot product intrinsics and get the operands  
 without using the iterator.

---
 clang/lib/CodeGen/CGBuiltin.cpp| 25 +++---
 clang/test/CodeGenHLSL/builtins/dot.hlsl   | 28 +++
 llvm/include/llvm/IR/IntrinsicsDirectX.td  | 10 ++-
 llvm/lib/Target/DirectX/DXIL.td|  9 +++
 llvm/lib/Target/DirectX/DXILOpBuilder.cpp  |  8 +-
 llvm/lib/Target/DirectX/DXILOpBuilder.h|  5 +-
 llvm/lib/Target/DirectX/DXILOpLowering.cpp | 55 -
 llvm/test/CodeGen/DirectX/dot2_error.ll| 10 +++
 llvm/test/CodeGen/DirectX/dot3_error.ll| 10 +++
 llvm/test/CodeGen/DirectX/dot4_error.ll| 10 +++
 llvm/test/CodeGen/DirectX/fdot.ll  | 94 ++
 11 files changed, 230 insertions(+), 34 deletions(-)
 create mode 100644 llvm/test/CodeGen/DirectX/dot2_error.ll
 create mode 100644 llvm/test/CodeGen/DirectX/dot3_error.ll
 create mode 100644 llvm/test/CodeGen/DirectX/dot4_error.ll
 create mode 100644 llvm/test/CodeGen/DirectX/fdot.ll

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 77cb269d43c5a8..a4b99181769326 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18036,15 +18036,22 @@ llvm::Value 
*CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
   return Arg;
 }
 
-Intrinsic::ID getDotProductIntrinsic(QualType QT) {
+Intrinsic::ID getDotProductIntrinsic(QualType QT, int elementCount) {
+  if (QT->hasFloatingRepresentation()) {
+switch (elementCount) {
+case 2:
+  return Intrinsic::dx_dot2;
+case 3:
+  return Intrinsic::dx_dot3;
+case 4:
+  return Intrinsic::dx_dot4;
+}
+  }
   if (QT->hasSignedIntegerRepresentation())
 return Intrinsic::dx_sdot;
-  if (QT->hasUnsignedIntegerRepresentation())
-return Intrinsic::dx_udot;
 
-  assert(QT->hasFloatingRepresentation());
-  return Intrinsic::dx_dot;
-  ;
+  assert(QT->hasUnsignedIntegerRepresentation());
+  return Intrinsic::dx_udot;
 }
 
 Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
@@ -18098,8 +18105,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 assert(T0->getScalarType() == T1->getScalarType() &&
"Dot product of vectors need the same element types.");
 
-[[maybe_unused]] auto *VecTy0 =
-E->getArg(0)->getType()->getAs();
+auto *VecTy0 = E->getArg(0)->getType()->getAs();
 [[maybe_unused]] auto *VecTy1 =
 E->getArg(1)->getType()->getAs();
 // A HLSLVectorTruncation should have happend
@@ -18108,7 +18114,8 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 
 return Builder.CreateIntrinsic(
 /*ReturnType=*/T0->getScalarType(),
-getDotProductIntrinsic(E->getArg(0)->getType()),
+getDotProductIntrinsic(E->getArg(0)->getType(),
+   VecTy0->getNumElements()),
 ArrayRef{Op0, Op1}, nullptr, "dx.dot");
   } break;
   case Builtin::BI__builtin_hlsl_lerp: {
diff --git a/clang/test/CodeGenHLSL/builtins/dot.hlsl 
b/clang/test/CodeGenHLSL/builtins/dot.hlsl
index 0f993193c00cce..307d71cce3cb6d 100644
--- a/clang/test/CodeGenHLSL/builtins/dot.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/dot.hlsl
@

[clang] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-20 Thread YAMAMOTO Takashi via cfe-commits

yamt wrote:

@aheejin may i rebase this PR as it now has conflicts?

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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-20 Thread via cfe-commits

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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-20 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/86018

>From 09ec2dd51e2decb76c1e8f6ea5a505016fa319d9 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Wed, 20 Mar 2024 14:57:32 -0700
Subject: [PATCH 1/4] [NFC][Clang] Fix static analyzer bugs with dereference
 after null checks

This patch fixes potential dereferences in 
::MappableExprsHandler::generateInfoForComponentList() for passing 
null pointer OASE to EmitOMPArraySectionExpr().
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e8a68dbcc68709..e89a5368fb2f71 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,7 +7431,7 @@ class MappableExprsHandler {
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
@@ -7444,7 +7444,7 @@ class MappableExprsHandler {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};

>From b55669044d397320a153c9b8940a4d1dc2f17af7 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Wed, 20 Mar 2024 15:07:39 -0700
Subject: [PATCH 2/4] Fix clang format errors

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e89a5368fb2f71..166f84d948fb91 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,9 +7431,9 @@ class MappableExprsHandler {
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
 if (IsFinalArraySection) {
-  Address HB = OASE &&
-  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
-  .getAddress(CGF);
+  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+  OASE, /*IsLowerBound=*/false)
+   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, LowestElem};
@@ -7444,9 +7444,9 @@ class MappableExprsHandler {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
 if (IsFinalArraySection) {
-  Address HB = OASE &&
-  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
-  .getAddress(CGF);
+  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+  OASE, /*IsLowerBound=*/false)
+   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, LowestElem};

>From b80a60e0bd8959a6e6835209c5f5bacc6f4fea02 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Wed, 20 Mar 2024 19:14:21 -0700
Subject: [PATCH 3/4] Fix build failures

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 166f84d948fb91..6ebdbde80430e9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7430,10 +7430,10 @@ class MappableExprsHandler {
   // Update info about the lowest and highest elements for this struct
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
-if (IsFinalArraySection) {
-  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
-  OASE, /*IsLowerBound=*/false)
-   .getAddress(CGF);
+   if (OASE && IsFinalArraySection) {
+  Address HB =
+  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
+  .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, Lo

[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-20 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/86018

>From 09ec2dd51e2decb76c1e8f6ea5a505016fa319d9 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Wed, 20 Mar 2024 14:57:32 -0700
Subject: [PATCH 1/3] [NFC][Clang] Fix static analyzer bugs with dereference
 after null checks

This patch fixes potential dereferences in 
::MappableExprsHandler::generateInfoForComponentList() for passing 
null pointer OASE to EmitOMPArraySectionExpr().
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e8a68dbcc68709..e89a5368fb2f71 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,7 +7431,7 @@ class MappableExprsHandler {
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
@@ -7444,7 +7444,7 @@ class MappableExprsHandler {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};

>From b55669044d397320a153c9b8940a4d1dc2f17af7 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Wed, 20 Mar 2024 15:07:39 -0700
Subject: [PATCH 2/3] Fix clang format errors

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e89a5368fb2f71..166f84d948fb91 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,9 +7431,9 @@ class MappableExprsHandler {
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
 if (IsFinalArraySection) {
-  Address HB = OASE &&
-  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
-  .getAddress(CGF);
+  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+  OASE, /*IsLowerBound=*/false)
+   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, LowestElem};
@@ -7444,9 +7444,9 @@ class MappableExprsHandler {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
 if (IsFinalArraySection) {
-  Address HB = OASE &&
-  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
-  .getAddress(CGF);
+  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+  OASE, /*IsLowerBound=*/false)
+   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, LowestElem};

>From b80a60e0bd8959a6e6835209c5f5bacc6f4fea02 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Wed, 20 Mar 2024 19:14:21 -0700
Subject: [PATCH 3/3] Fix build failures

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 166f84d948fb91..6ebdbde80430e9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7430,10 +7430,10 @@ class MappableExprsHandler {
   // Update info about the lowest and highest elements for this struct
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
-if (IsFinalArraySection) {
-  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
-  OASE, /*IsLowerBound=*/false)
-   .getAddress(CGF);
+   if (OASE && IsFinalArraySection) {
+  Address HB =
+  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
+  .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, Lo

[clang] 631248d - [X86_64] fix empty structure vaarg in c++ (#77907)

2024-03-20 Thread via cfe-commits

Author: hstk30-hw
Date: 2024-03-21T09:25:24+08:00
New Revision: 631248dcd26fdec772cedb569be94ff8f12d0901

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

LOG: [X86_64] fix empty structure vaarg in c++ (#77907)

SizeInBytes of empty structure is 0 in C, while 1 in C++. And empty
structure argument of the function is ignored in X86_64 backend.As a
result, the value of variable arguments in C++ is incorrect. fix #77036

Co-authored-by: Longsheng Mou 

Added: 
clang/test/CodeGenCXX/x86_64-vaarg.cpp

Modified: 
clang/lib/CodeGen/Targets/X86.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/X86.cpp 
b/clang/lib/CodeGen/Targets/X86.cpp
index 2291c991fb1107..1ec0f159ebcb8a 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -3019,6 +3019,10 @@ Address X86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, 
Address VAListAddr,
   ABIArgInfo AI = classifyArgumentType(Ty, 0, neededInt, neededSSE,
/*isNamedArg*/false);
 
+  // Empty records are ignored for parameter passing purposes.
+  if (AI.isIgnore())
+return CGF.CreateMemTemp(Ty);
+
   // AMD64-ABI 3.5.7p5: Step 1. Determine whether type may be passed
   // in the registers. If not go to step 7.
   if (!neededInt && !neededSSE)

diff  --git a/clang/test/CodeGenCXX/x86_64-vaarg.cpp 
b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
new file mode 100644
index 00..f0177906a09a81
--- /dev/null
+++ b/clang/test/CodeGenCXX/x86_64-vaarg.cpp
@@ -0,0 +1,23 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -x c -o - %s | 
FileCheck %s
+
+typedef struct { struct {} a; } empty;
+
+// CHECK-LABEL: @{{.*}}empty_record_test
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca [[STRUCT_EMPTY:%.*]], align 1
+// CHECK-NEXT:[[Z_ADDR:%.*]] = alloca i32, align 4
+// CHECK-NEXT:[[LIST:%.*]] = alloca [1 x %struct.__va_list_tag], align 16
+// CHECK-NEXT:[[TMP:%.*]] = alloca [[STRUCT_EMPTY]], align 1
+// CHECK-NEXT:store i32 [[Z:%.*]], ptr [[Z_ADDR]], align 4
+// CHECK-NEXT:[[ARRAYDECAY:%.*]] = getelementptr inbounds [1 x 
%struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.va_start(ptr [[ARRAYDECAY]])
+// CHECK-NEXT:[[ARRAYDECAY1:%.*]] = getelementptr inbounds [1 x 
%struct.__va_list_tag], ptr [[LIST]], i64 0, i64 0
+// CHECK-NEXT:call void @llvm.memcpy.p0.p0.i64(ptr align 1 [[RETVAL]], ptr 
align 1 [[TMP]], i64 {{.*}}, i1 false)
+// CHECK-NEXT:ret void
+empty empty_record_test(int z, ...) {
+  __builtin_va_list list;
+  __builtin_va_start(list, z);
+  return __builtin_va_arg(list, empty);
+}



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


[clang] Use timeTraceAsyncProfilerBegin for Source span (PR #83961)

2024-03-20 Thread Takuto Ikuta via cfe-commits

https://github.com/atetubou updated 
https://github.com/llvm/llvm-project/pull/83961

>From e61cf0ec2caa594fe915711477083875dc8bf449 Mon Sep 17 00:00:00 2001
From: Takuto Ikuta 
Date: Mon, 4 Mar 2024 17:02:05 +0900
Subject: [PATCH] Use timeTraceAsyncProfilerBegin for Source span

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

diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index cd0c42d5ffbacd..36762b217c9faa 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -135,6 +135,7 @@ namespace sema {
 class SemaPPCallbacks : public PPCallbacks {
   Sema *S = nullptr;
   llvm::SmallVector IncludeStack;
+  llvm::SmallVector ProfilerStack;
 
 public:
   void set(Sema &S) { this->S = &S; }
@@ -153,8 +154,8 @@ class SemaPPCallbacks : public PPCallbacks {
   if (IncludeLoc.isValid()) {
 if (llvm::timeTraceProfilerEnabled()) {
   OptionalFileEntryRef FE = SM.getFileEntryRefForID(SM.getFileID(Loc));
-  llvm::timeTraceProfilerBegin("Source", FE ? FE->getName()
-: StringRef(""));
+  ProfilerStack.push_back(llvm::timeTraceAsyncProfilerBegin(
+  "Source", FE ? FE->getName() : StringRef("")));
 }
 
 IncludeStack.push_back(IncludeLoc);
@@ -166,8 +167,9 @@ class SemaPPCallbacks : public PPCallbacks {
 }
 case ExitFile:
   if (!IncludeStack.empty()) {
-if (llvm::timeTraceProfilerEnabled())
-  llvm::timeTraceProfilerEnd();
+if (llvm::timeTraceProfilerEnabled()) {
+  llvm::timeTraceProfilerEnd(ProfilerStack.pop_back_val());
+}
 
 S->DiagnoseNonDefaultPragmaAlignPack(
 Sema::PragmaAlignPackDiagnoseKind::ChangedStateAtExit,

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-20 Thread Dan Liew via cfe-commits


@@ -3379,6 +3379,60 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``

delcypher wrote:

@ahatanak Is this in the wrong place in the document? `__builtin_verbose_trap` 
is lexicographically after `__builtin_nondeterministic_value`

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


[clang] [X86][Headers] Specify result of NaN comparisons (PR #85862)

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

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

LGTM.

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-03-20 Thread via cfe-commits

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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-20 Thread via cfe-commits

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


[clang] [llvm] [CodeGen][LLVM] Make the `va_list` related intrinsics generic. (PR #85460)

2024-03-20 Thread Alex Voicu via cfe-commits


@@ -700,10 +700,13 @@ class MSBuiltin {
 //===--- Variable Argument Handling Intrinsics 
===//
 //
 
-def int_vastart : DefaultAttrsIntrinsic<[], [llvm_ptr_ty], [], 
"llvm.va_start">;
-def int_vacopy  : DefaultAttrsIntrinsic<[], [llvm_ptr_ty, llvm_ptr_ty], [],
-"llvm.va_copy">;
-def int_vaend   : DefaultAttrsIntrinsic<[], [llvm_ptr_ty], [], "llvm.va_end">;
+def int_vastart : DefaultAttrsIntrinsic<[],
+[llvm_anyptr_ty], [], "llvm.va_start">;
+def int_vacopy  : DefaultAttrsIntrinsic<[],
+[llvm_anyptr_ty, llvm_anyptr_ty], [],
+"llvm.va_copy">;

AlexVlx wrote:

Hmm, I did struggle a bit with this and admit that I'm not (yet) entirely 
convinced a valid (albeit hypothetical and admittedly odd) case couldn't be 
constructed. Consider e.g. having a `__builtin_va_list` declared at namespace / 
global scope. If a target uses an explicit, non-generic, AS, for globals, then 
the copy would be to/from a pointer to generic (or pointer to private) from/to 
a pointer to global. I _believe_ this should work, and making `va_copy` 
mono-parameter would break it, would it not?

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


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-20 Thread Harald van Dijk via cfe-commits

hvdijk wrote:

The problem with `union { char x[]; } x = {0};` is in 
`ConstStructBuilder::Build` ( `clang/lib/CodeGen/CGExprConstant.cpp`). It does:
```diff
// If this is a union, skip all the fields that aren't being initialized.
if (RD->isUnion() &&
!declaresSameEntity(ILE->getInitializedFieldInUnion(), Field))
  continue;
```
But `ILE->getInitializedFieldInUnion()` returns `nullptr` so this skips all 
fields. `nullptr` is returned because `InitListChecker::CheckStructUnionTypes` 
never calls `StructuredList->setInitializedFieldInUnion`. If that gets called, 
then things work.

I think things can be simplified a bit further: if we do
```diff
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 79cf2eed46fe..3fcdf9118468 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2332,7 +2332,7 @@ void InitListChecker::CheckStructUnionTypes(
 
 // We've already initialized a member of a union. We're done.
 if (InitializedSomething && RD->isUnion())
-  break;
+  return;
 
 // If we've hit the flexible array member at the end, we're done.
 if (Field->getType()->isIncompleteArrayType())
```
Then the tests still pass and we can remove or simplify some of the later 
checks for unions.

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type convertible to `std::coroutine_handle<>` (PR #85684)

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

ChuanqiXu9 wrote:

> > I am confused. If we don't need to check whether a type can be converted to 
> > std::coroutine_handle, why do we still need EvaluateBinaryTypeTraits or 
> > similar things.
> 
> I thought your previous comment was to show concern about exposing 
> `EvaluateBinaryTypeTraits` contained a bunch of nonfunctional changes.

Yes, this is the intention.

> Do you think it's good?

For the issue we have, it is not. We're introducing a lot of nonfunctional 
change for a non-standard and unimportant feature... So I may feel better if we 
can avoid that.


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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type convertible to `std::coroutine_handle<>` (PR #85684)

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

ChuanqiXu9 wrote:

> In SemaExprCXX.cpp there's EvaluateBinaryTypeTraits that I needed to expose 
> as suggested by the comment in SemaCoroutine. Is there an alternative way to 
> do type coercion/equivalence checks?

I am confused. If we don't need to check whether a type can be converted to 
`std::coroutine_handle`, why do we still need EvaluateBinaryTypeTraits or 
similar things.

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


[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type convertible to `std::coroutine_handle<>` (PR #85684)

2024-03-20 Thread Yuxuan Chen via cfe-commits

yuxuanchen1997 wrote:

> I am confused. If we don't need to check whether a type can be converted to 
> std::coroutine_handle, why do we still need EvaluateBinaryTypeTraits or 
> similar things.

I thought your previous comment was to show concern about exposing 
`EvaluateBinaryTypeTraits` contained a bunch of nonfunctional changes. Do you 
think it's good?

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


[clang] [clang][SPIRV] Ignore -mcmodel (PR #86039)

2024-03-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Arthur Eubanks (aeubanks)


Changes

The code model doesn't affect the sub-compilation, so don't check it.

Followup to #70740.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+1-1) 
- (modified) clang/test/Driver/unsupported-option-gpu.c (+1) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 055884d275ce1b..035bfa35299756 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5804,7 +5804,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 } else if (Triple.getArch() == llvm::Triple::x86_64) {
   Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
   CM);
-} else if (Triple.isNVPTX() || Triple.isAMDGPU()) {
+} else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
   // NVPTX/AMDGPU does not care about the code model and will accept
   // whatever works for the host.
   Ok = true;
diff --git a/clang/test/Driver/unsupported-option-gpu.c 
b/clang/test/Driver/unsupported-option-gpu.c
index f23cb71ebfb08e..5618b2cba72e16 100644
--- a/clang/test/Driver/unsupported-option-gpu.c
+++ b/clang/test/Driver/unsupported-option-gpu.c
@@ -2,4 +2,5 @@
 // DEFINE: %{check} = %clang -### --target=x86_64-linux-gnu -c -mcmodel=medium
 
 // RUN: %{check} -x cuda %s --cuda-path=%S/Inputs/CUDA/usr/local/cuda 
--offload-arch=sm_60 --no-cuda-version-check -fbasic-block-sections=all
+// RUN: %{check} -x hip %s --offload=spirv64 -nogpulib -nogpuinc
 // RUN: %{check} -x hip %s --rocm-path=%S/Inputs/rocm -nogpulib -nogpuinc

``




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


[clang] [clang][SPIRV] Ignore -mcmodel (PR #86039)

2024-03-20 Thread Arthur Eubanks via cfe-commits

https://github.com/aeubanks created 
https://github.com/llvm/llvm-project/pull/86039

The code model doesn't affect the sub-compilation, so don't check it.

Followup to #70740.

>From bba8e4003c4ccc36497e62ad1696197e6987525c Mon Sep 17 00:00:00 2001
From: Arthur Eubanks 
Date: Wed, 20 Mar 2024 23:36:35 +
Subject: [PATCH] [clang][SPIRV] Ignore -mcmodel

The code model doesn't affect the sub-compilation, so don't check it.

Followup to #70740.
---
 clang/lib/Driver/ToolChains/Clang.cpp  | 2 +-
 clang/test/Driver/unsupported-option-gpu.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 055884d275ce1b..035bfa35299756 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5804,7 +5804,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 } else if (Triple.getArch() == llvm::Triple::x86_64) {
   Ok = llvm::is_contained({"small", "kernel", "medium", "large", "tiny"},
   CM);
-} else if (Triple.isNVPTX() || Triple.isAMDGPU()) {
+} else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
   // NVPTX/AMDGPU does not care about the code model and will accept
   // whatever works for the host.
   Ok = true;
diff --git a/clang/test/Driver/unsupported-option-gpu.c 
b/clang/test/Driver/unsupported-option-gpu.c
index f23cb71ebfb08e..5618b2cba72e16 100644
--- a/clang/test/Driver/unsupported-option-gpu.c
+++ b/clang/test/Driver/unsupported-option-gpu.c
@@ -2,4 +2,5 @@
 // DEFINE: %{check} = %clang -### --target=x86_64-linux-gnu -c -mcmodel=medium
 
 // RUN: %{check} -x cuda %s --cuda-path=%S/Inputs/CUDA/usr/local/cuda 
--offload-arch=sm_60 --no-cuda-version-check -fbasic-block-sections=all
+// RUN: %{check} -x hip %s --offload=spirv64 -nogpulib -nogpuinc
 // RUN: %{check} -x hip %s --rocm-path=%S/Inputs/rocm -nogpulib -nogpuinc

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


[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-20 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86025

>From 9c75bb6dac672fedef114618500cd8600501f8aa Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 20 Mar 2024 15:50:01 -0700
Subject: [PATCH 1/2] [InstallAPI] Report exports discovered in binary but not
 in interface

This patch completes the classes of errors installapi can detect.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |   1 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  13 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 160 +-
 clang/test/InstallAPI/diagnostics-cpp.test|   3 +
 .../mismatching-objc-class-symbols.test   | 269 
 clang/test/InstallAPI/symbol-flags.test   | 290 ++
 .../clang-installapi/ClangInstallAPI.cpp  |   2 +-
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp |   7 +-
 8 files changed, 724 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/InstallAPI/mismatching-objc-class-symbols.test
 create mode 100644 clang/test/InstallAPI/symbol-flags.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a7b62891100a84 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..49de24763f1f93 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -128,6 +131,14 @@ class DylibVerifier {
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
 
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext &SymCtx);
+
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
+
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..2f71cd1a8044f8 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metaclass of 

[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-03-20 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/73376

>From 4d0e485f11fc352ff138268698f776d08c2136b1 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Sat, 25 Nov 2023 04:00:57 +0100
Subject: [PATCH] [clang] Accept lambdas in C++03 as an extensions

This is a fairly simple extension, but makes the life for people who
have to support C++03 a lot easier. As a nice bonus, this also improves
diagnostics, since lambdas are now properly recognized when parsing
C++03 code.
---
 clang/docs/LanguageExtensions.rst |  73 ++-
 clang/docs/ReleaseNotes.rst   |   2 +
 .../clang/Basic/DiagnosticParseKinds.td   |   1 +
 clang/include/clang/Basic/Features.def|   1 +
 clang/lib/Parse/ParseExpr.cpp |   2 +-
 clang/lib/Parse/ParseExprCXX.cpp  |   9 +-
 clang/lib/Parse/ParseInit.cpp |   2 +-
 clang/lib/Sema/SemaDecl.cpp   |   2 +-
 clang/lib/Sema/SemaDeclCXX.cpp|   3 +-
 clang/test/Lexer/has_extension_cxx.cpp|   5 +
 .../OpenMP/declare_reduction_messages.cpp |  14 +--
 clang/test/OpenMP/openmp_check.cpp|   2 +-
 clang/test/Parser/cxx03-lambda-extension.cpp  |   5 +
 .../test/Parser/cxx0x-lambda-expressions.cpp  | 116 +++---
 clang/test/Parser/cxx2b-lambdas.cpp   |  45 +--
 .../Parser/objcxx-lambda-expressions-neg.mm   |   9 +-
 clang/test/ParserHLSL/group_shared.hlsl   |   4 +-
 clang/test/SemaCXX/cxx2a-template-lambdas.cpp |  26 ++--
 clang/test/SemaCXX/lambda-expressions.cpp |  64 ++
 .../SemaCXX/lambda-implicit-this-capture.cpp  |   1 +
 clang/test/SemaCXX/lambda-invalid-capture.cpp |   1 +
 clang/test/SemaCXX/new-delete.cpp |   7 +-
 22 files changed, 213 insertions(+), 181 deletions(-)
 create mode 100644 clang/test/Parser/cxx03-lambda-extension.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 13d7261d83d7f1..201a4c27f7dd8b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1459,40 +1459,45 @@ More information could be found `here 

 Language Extensions Back-ported to Previous Standards
 =
 
-==  
= =
-FeatureFeature Test Macro   
Introduced In Backported To
-==  
= =
-variadic templates __cpp_variadic_templates C++11  
   C++03
-Alias templates__cpp_alias_templatesC++11  
   C++03
-Non-static data member initializers__cpp_nsdmi  C++11  
   C++03
-Range-based ``for`` loop   __cpp_range_based_forC++11  
   C++03
-RValue references  __cpp_rvalue_references  C++11  
   C++03
-Attributes __cpp_attributes C++11  
   C++03
-variable templates __cpp_variable_templates C++14  
   C++03
-Binary literals__cpp_binary_literalsC++14  
   C++03
-Relaxed constexpr  __cpp_constexpr  C++14  
   C++11
-``if constexpr``   __cpp_if_constexpr   C++17  
   C++11
-fold expressions   __cpp_fold_expressions   C++17  
   C++03
-Lambda capture of \*this by value  __cpp_capture_star_this  C++17  
   C++11
-Attributes on enums__cpp_enumerator_attributes  C++17  
   C++03
-Guaranteed copy elision__cpp_guaranteed_copy_elisionC++17  
   C++03
-Hexadecimal floating literals  __cpp_hex_float  C++17  
   C++03
-``inline`` variables   __cpp_inline_variables   C++17  
   C++03
-Attributes on namespaces   __cpp_namespace_attributes   C++17  
   C++11
-Structured bindings__cpp_structured_bindingsC++17  
   C++03
-template template arguments__cpp_template_template_args C++17  
   C++03
-``static operator[]``  __cpp_multidimensional_subscript C++20  
   C++03
-Designated initializers__cpp_designated_initializersC++20  
   C++03
-Conditional ``explicit``   __cpp_conditional_explicit   C++20  
   C++03
-``using enum`` __cpp_using_enum C++20  
   C++03
-``if consteval``   __cpp_if_consteval   C++23  
   C++20
-``static operator()``  __cpp_static_call_operator   C++23  
   C++03
-Attributes on L

[clang] [llvm] [Clang][ARM][AArch64] Alway emit protection attributes for functions. (PR #82819)

2024-03-20 Thread Daniel Kiss via cfe-commits


@@ -2314,7 +2314,7 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, 
AttributeList Attrs,
 
   if (auto A = Attrs.getFnAttr("sign-return-address"); A.isValid()) {
 StringRef S = A.getValueAsString();
-if (S != "none" && S != "all" && S != "non-leaf")

DanielKristofKiss wrote:

This isn't right, to support\import the old format the old values and nothing 
need to accepted here.

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


[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-20 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida updated 
https://github.com/llvm/llvm-project/pull/86025

>From 9c75bb6dac672fedef114618500cd8600501f8aa Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Wed, 20 Mar 2024 15:50:01 -0700
Subject: [PATCH] [InstallAPI] Report exports discovered in binary but not in
 interface

This patch completes the classes of errors installapi can detect.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |   1 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  13 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 160 +-
 clang/test/InstallAPI/diagnostics-cpp.test|   3 +
 .../mismatching-objc-class-symbols.test   | 269 
 clang/test/InstallAPI/symbol-flags.test   | 290 ++
 .../clang-installapi/ClangInstallAPI.cpp  |   2 +-
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp |   7 +-
 8 files changed, 724 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/InstallAPI/mismatching-objc-class-symbols.test
 create mode 100644 clang/test/InstallAPI/symbol-flags.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a7b62891100a84 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..49de24763f1f93 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -128,6 +131,14 @@ class DylibVerifier {
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
 
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext &SymCtx);
+
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
+
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
bool ValidSourceLoc = true);
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..2f71cd1a8044f8 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metaclass of " + 

[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-20 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 927308a52bc51ae786db1bd645ad5ef5889fdb2a 
b01001d6420bd21dbd332930c4aae82d00958016 -- 
clang/include/clang/InstallAPI/DylibVerifier.h 
clang/lib/InstallAPI/DylibVerifier.cpp 
clang/tools/clang-installapi/ClangInstallAPI.cpp 
llvm/lib/TextAPI/BinaryReader/DylibReader.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index 20e31c87b7..49de24763f 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -130,10 +130,10 @@ private:
 
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
-  
+
   /// Shared implementation for verifying exported symbols in dylib.
-  void visitSymbolInDylib(const Record &R, SymbolContext& SymCtx);
-  
+  void visitSymbolInDylib(const Record &R, SymbolContext &SymCtx);
+
   void visitGlobal(const GlobalRecord &R) override;
   void visitObjCInterface(const ObjCInterfaceRecord &R) override;
   void visitObjCCategory(const ObjCCategoryRecord &R) override;
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 0cc6a4bad9..2f71cd1a80 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -524,8 +524,7 @@ static bool shouldIgnoreCpp(StringRef Name, bool IsWeakDef) 
{
   return (IsWeakDef &&
   (Name.starts_with("__ZTI") || Name.starts_with("__ZTS")));
 }
-void DylibVerifier::visitSymbolInDylib(const Record &R,
-SymbolContext &SymCtx) {
+void DylibVerifier::visitSymbolInDylib(const Record &R, SymbolContext &SymCtx) 
{
   if (R.isUndefined()) {
 updateState(Result::Valid);
 return;
@@ -538,7 +537,8 @@ void DylibVerifier::visitSymbolInDylib(const Record &R,
   const StringRef SymbolName(SymCtx.SymbolName);
   // Allow zippered symbols with potentially mismatching availability
   // between macOS and macCatalyst in the final text file.
-  if (const Symbol *Sym = Exports->findSymbol(SymCtx.Kind, SymCtx.SymbolName, 
SymCtx.ObjCIFKind)) {
+  if (const Symbol *Sym = Exports->findSymbol(SymCtx.Kind, SymCtx.SymbolName,
+  SymCtx.ObjCIFKind)) {
 if (Sym->hasArchitecture(Ctx.Target.Arch)) {
   updateState(Result::Ignore);
   return;
@@ -551,7 +551,7 @@ void DylibVerifier::visitSymbolInDylib(const Record &R,
   }
 
   // All checks at the point classify as some kind of violation that should be
-  // reported. 
+  // reported.
   if (SymbolName.starts_with("$ld$")) {
 Ctx.emitDiag([&]() {
   Ctx.Diag->Report(diag::err_header_symbol_missing)
diff --git a/llvm/lib/TextAPI/BinaryReader/DylibReader.cpp 
b/llvm/lib/TextAPI/BinaryReader/DylibReader.cpp
index cf18e78bf6..2e36d4a8b9 100644
--- a/llvm/lib/TextAPI/BinaryReader/DylibReader.cpp
+++ b/llvm/lib/TextAPI/BinaryReader/DylibReader.cpp
@@ -296,7 +296,7 @@ static Error readSymbols(MachOObjectFile *Obj, RecordsSlice 
&Slice,
 if (Flags & SymbolRef::SF_Undefined) {
   if (Opt.Undefineds)
 Linkage = RecordLinkage::Undefined;
-  else 
+  else
 continue;
   if (Flags & SymbolRef::SF_Weak)
 RecordFlags |= SymbolFlags::WeakReferenced;

``




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


[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Cyndy Ishida (cyndyishida)


Changes

This patch completes the classes of errors installapi can detect.

---

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


8 Files Affected:

- (modified) clang/include/clang/Basic/DiagnosticInstallAPIKinds.td (+1) 
- (modified) clang/include/clang/InstallAPI/DylibVerifier.h (+12-1) 
- (modified) clang/lib/InstallAPI/DylibVerifier.cpp (+143-17) 
- (modified) clang/test/InstallAPI/diagnostics-cpp.test (+3) 
- (added) clang/test/InstallAPI/mismatching-objc-class-symbols.test (+269) 
- (added) clang/test/InstallAPI/symbol-flags.test (+290) 
- (modified) clang/tools/clang-installapi/ClangInstallAPI.cpp (+1-1) 
- (modified) llvm/lib/TextAPI/BinaryReader/DylibReader.cpp (+5-2) 


``diff
diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a7b62891100a84 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..20e31c87b75ad2 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -127,6 +130,14 @@ class DylibVerifier {
 
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
+  
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext& SymCtx);
+  
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
 
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..0cc6a4bad91a25 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metaclass of " + PrettyName;
+  case ObjCIFSymbolKind::Class:
+return Annotation + "Class of " + PrettyName;
   }
 
   // Only print symbol type prefix or leading "_" if there is no source 
location
@@ -90,9 +88,6 @@ std::string DylibVerifier::getAnnotatedName(c

[clang] [llvm] [InstallAPI] Report exports discovered in binary but not in interface (PR #86025)

2024-03-20 Thread Cyndy Ishida via cfe-commits

https://github.com/cyndyishida created 
https://github.com/llvm/llvm-project/pull/86025

This patch completes the classes of errors installapi can detect.

>From b01001d6420bd21dbd332930c4aae82d00958016 Mon Sep 17 00:00:00 2001
From: Cyndy Ishida 
Date: Tue, 19 Mar 2024 06:44:26 -0700
Subject: [PATCH] [InstallAPI] Report exports discovered in binary but not in
 interface

This patch completes the classes of errors installapi can detect.
---
 .../clang/Basic/DiagnosticInstallAPIKinds.td  |   1 +
 .../include/clang/InstallAPI/DylibVerifier.h  |  13 +-
 clang/lib/InstallAPI/DylibVerifier.cpp| 160 +-
 clang/test/InstallAPI/diagnostics-cpp.test|   3 +
 .../mismatching-objc-class-symbols.test   | 269 
 clang/test/InstallAPI/symbol-flags.test   | 290 ++
 .../clang-installapi/ClangInstallAPI.cpp  |   2 +-
 llvm/lib/TextAPI/BinaryReader/DylibReader.cpp |   7 +-
 8 files changed, 724 insertions(+), 21 deletions(-)
 create mode 100644 clang/test/InstallAPI/mismatching-objc-class-symbols.test
 create mode 100644 clang/test/InstallAPI/symbol-flags.test

diff --git a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td 
b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
index f99a5fca64cb46..a7b62891100a84 100644
--- a/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
+++ b/clang/include/clang/Basic/DiagnosticInstallAPIKinds.td
@@ -26,6 +26,7 @@ def warn_library_hidden_symbol : Warning<"declaration has 
external linkage, but
 def warn_header_hidden_symbol : Warning<"symbol exported in dynamic library, 
but marked hidden in declaration '%0'">, InGroup;
 def err_header_hidden_symbol : Error<"symbol exported in dynamic library, but 
marked hidden in declaration '%0'">;
 def err_header_symbol_missing : Error<"no declaration found for exported 
symbol '%0' in dynamic library">;
+def warn_header_symbol_missing : Warning<"no declaration was found for 
exported symbol '%0' in dynamic library">;
 def warn_header_availability_mismatch : Warning<"declaration '%0' is marked 
%select{available|unavailable}1,"
   " but symbol is %select{not |}2exported in dynamic library">, 
InGroup;
 def err_header_availability_mismatch : Error<"declaration '%0' is marked 
%select{available|unavailable}1,"
diff --git a/clang/include/clang/InstallAPI/DylibVerifier.h 
b/clang/include/clang/InstallAPI/DylibVerifier.h
index bbfa8711313e47..20e31c87b75ad2 100644
--- a/clang/include/clang/InstallAPI/DylibVerifier.h
+++ b/clang/include/clang/InstallAPI/DylibVerifier.h
@@ -28,7 +28,7 @@ enum class VerificationMode {
 /// lifetime of InstallAPI.
 /// As declarations are collected during AST traversal, they are
 /// compared as symbols against what is available in the binary dylib.
-class DylibVerifier {
+class DylibVerifier : llvm::MachO::RecordVisitor {
 private:
   struct SymbolContext;
 
@@ -72,6 +72,9 @@ class DylibVerifier {
   Result verify(ObjCIVarRecord *R, const FrontendAttrs *FA,
 const StringRef SuperClass);
 
+  // Scan through dylib slices and report any remaining missing exports.
+  Result verifyRemainingSymbols();
+
   /// Initialize target for verification.
   void setTarget(const Target &T);
 
@@ -127,6 +130,14 @@ class DylibVerifier {
 
   /// Find matching dylib slice for target triple that is being parsed.
   void assignSlice(const Target &T);
+  
+  /// Shared implementation for verifying exported symbols in dylib.
+  void visitSymbolInDylib(const Record &R, SymbolContext& SymCtx);
+  
+  void visitGlobal(const GlobalRecord &R) override;
+  void visitObjCInterface(const ObjCInterfaceRecord &R) override;
+  void visitObjCCategory(const ObjCCategoryRecord &R) override;
+  void visitObjCIVar(const ObjCIVarRecord &R, const StringRef Super);
 
   /// Gather annotations for symbol for error reporting.
   std::string getAnnotatedName(const Record *R, SymbolContext &SymCtx,
diff --git a/clang/lib/InstallAPI/DylibVerifier.cpp 
b/clang/lib/InstallAPI/DylibVerifier.cpp
index 24e0d0addf2f46..0cc6a4bad91a25 100644
--- a/clang/lib/InstallAPI/DylibVerifier.cpp
+++ b/clang/lib/InstallAPI/DylibVerifier.cpp
@@ -66,17 +66,15 @@ std::string DylibVerifier::getAnnotatedName(const Record *R,
 Annotation += "(tlv) ";
 
   // Check if symbol represents only part of a @interface declaration.
-  const bool IsAnnotatedObjCClass =
-  ((SymCtx.ObjCIFKind != ObjCIFSymbolKind::None) &&
-   (SymCtx.ObjCIFKind <= ObjCIFSymbolKind::EHType));
-
-  if (IsAnnotatedObjCClass) {
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::EHType)
-  Annotation += "Exception Type of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::MetaClass)
-  Annotation += "Metaclass of ";
-if (SymCtx.ObjCIFKind == ObjCIFSymbolKind::Class)
-  Annotation += "Class of ";
+  switch (SymCtx.ObjCIFKind) {
+  default:
+break;
+  case ObjCIFSymbolKind::EHType:
+return Annotation + "Exception Type of " + PrettyName;
+  case ObjCIFSymbolKind::MetaClass:
+return Annotation + "Metac

[clang] [clang][Sema] Fix for enums overflowing (#24667) (PR #78742)

2024-03-20 Thread via cfe-commits

https://github.com/wheatman updated 
https://github.com/llvm/llvm-project/pull/78742

>From 8b82e3ecf1332880eb6eb2b257533bd86fa3582f Mon Sep 17 00:00:00 2001
From: Brian Wheatman 
Date: Fri, 19 Jan 2024 11:13:33 -0500
Subject: [PATCH] [clang][Sema] Fix for overflow in enumerators(#24667)

Enums which do not have a specified type can only grow to bigger types
which contain more bits than the prior types.  This means that the
largest signed integer type cannot grow to the largest unsigned integer types.

In the process also implements N3029 Improved Normal Enumerations and patially 
implements N3030
Enhancements to Enumerations which brings C enums more inline with C++ enums.

Fixes #24667
---
 clang/docs/ReleaseNotes.rst |   8 +++
 clang/lib/Sema/SemaDecl.cpp |  90 +++--
 clang/test/C/C2x/n3029.c|  81 ++
 clang/test/C/C2x/n3030.c| 130 
 clang/test/Sema/enum.c  |  43 ++--
 clang/test/SemaCXX/enum.cpp |   2 +
 6 files changed, 329 insertions(+), 25 deletions(-)
 create mode 100644 clang/test/C/C2x/n3029.c
 create mode 100644 clang/test/C/C2x/n3030.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3a74c070ff9ffe..9ae53d3a400ad5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -159,6 +159,12 @@ C23 Feature Support
   ``__TYPE_FMTb__`` (e.g., ``__UINT_FAST64_FMTB__``) in C23 mode for use with
   macros typically exposed from , such as ``PRIb8``.
   (`#81896: `_).
+- Enumerations should allow values greater than ``INT_MAX`` and smaller than
+  ``INT_MIN``, in order to provide a value-preserved set of integer constants. 
`N3029 Improved Normal Enumerations 
`_
+
+- Enumerations should have the ability to specify the underlying type to aid
+  in portability and usability across platforms, across ABIs, and across
+  languages (for serialization and similar purposes). `N3030 Enhancements to 
Enumerations `_
 
 - Clang now supports `N3018 The constexpr specifier for object definitions`
   `_.
@@ -300,6 +306,8 @@ Bug Fixes in This Version
 
 - Fixes an assertion failure on invalid code when trying to define member
   functions in lambdas.
+- Fixes a miscompilation when an enum has a specified value such that the 
automatic
+  increment overflows a ``signed long``. Fixes #GH24667.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5850cd0ab6b9aa..de672237e676e0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -19881,6 +19881,18 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // - If an initializer is specified for an enumerator, the
   //   initializing value has the same type as the expression.
   EltTy = Val->getType();
+} else if (getLangOpts().C23) {
+  // C23 6.7.2.2p11 b4
+  // int, if given explicitly with = and the value of the
+  // integer constant expression is representable by an int
+  //
+  // C23 6.7.2.2p11 b5
+  // the type of the integer constant expression, if given
+  // explicitly with = and if the value of the integer
+  // constant expression is not representable by int;
+  if (isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
+Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
+  EltTy = Val->getType();
 } else {
   // C99 6.7.2.2p2:
   //   The expression that defines the value of an enumeration constant
@@ -19890,8 +19902,8 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
   // Complain if the value is not representable in an int.
   if (!isRepresentableIntegerValue(Context, EnumVal, Context.IntTy))
 Diag(IdLoc, diag::ext_enum_value_not_int)
-  << toString(EnumVal, 10) << Val->getSourceRange()
-  << (EnumVal.isUnsigned() || EnumVal.isNonNegative());
+<< toString(EnumVal, 10) << Val->getSourceRange()
+<< (EnumVal.isUnsigned() || EnumVal.isNonNegative());
   else if (!Context.hasSameType(Val->getType(), Context.IntTy)) {
 // Force the type of the expression to 'int'.
 Val = ImpCastExprToType(Val, Context.IntTy, CK_IntegralCast).get();
@@ -19939,20 +19951,28 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl 
*Enum,
 //   sufficient to contain the incremented value. If no such type
 //   exists, the program is ill-formed.
 QualType T = getNextLargerIntegralType(Context, EltTy);
-if (T.isNull() || Enum->isFixed()) {
+if (E

[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-20 Thread via cfe-commits

https://github.com/smanna12 updated 
https://github.com/llvm/llvm-project/pull/86018

>From 09ec2dd51e2decb76c1e8f6ea5a505016fa319d9 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Wed, 20 Mar 2024 14:57:32 -0700
Subject: [PATCH 1/2] [NFC][Clang] Fix static analyzer bugs with dereference
 after null checks

This patch fixes potential dereferences in 
::MappableExprsHandler::generateInfoForComponentList() for passing 
null pointer OASE to EmitOMPArraySectionExpr().
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e8a68dbcc68709..e89a5368fb2f71 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,7 +7431,7 @@ class MappableExprsHandler {
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
@@ -7444,7 +7444,7 @@ class MappableExprsHandler {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};

>From b55669044d397320a153c9b8940a4d1dc2f17af7 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Wed, 20 Mar 2024 15:07:39 -0700
Subject: [PATCH 2/2] Fix clang format errors

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e89a5368fb2f71..166f84d948fb91 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,9 +7431,9 @@ class MappableExprsHandler {
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
 if (IsFinalArraySection) {
-  Address HB = OASE &&
-  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
-  .getAddress(CGF);
+  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+  OASE, /*IsLowerBound=*/false)
+   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, LowestElem};
@@ -7444,9 +7444,9 @@ class MappableExprsHandler {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
 if (IsFinalArraySection) {
-  Address HB = OASE &&
-  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
-  .getAddress(CGF);
+  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+  OASE, /*IsLowerBound=*/false)
+   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, LowestElem};

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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-20 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 de0abc0983d355bbd971c5c571ba4c209a0c63ea 
09ec2dd51e2decb76c1e8f6ea5a505016fa319d9 -- 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e89a5368fb..166f84d948 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,9 +7431,9 @@ private:
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
 if (IsFinalArraySection) {
-  Address HB = OASE &&
-  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
-  .getAddress(CGF);
+  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+  OASE, /*IsLowerBound=*/false)
+   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, LowestElem};
@@ -7444,9 +7444,9 @@ private:
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
 if (IsFinalArraySection) {
-  Address HB = OASE &&
-  CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
-  .getAddress(CGF);
+  Address HB = OASE && CGF.EmitOMPArraySectionExpr(
+  OASE, /*IsLowerBound=*/false)
+   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
 } else {
   PartialStruct.HighestElem = {FieldIndex, LowestElem};

``




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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-20 Thread via cfe-commits

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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: None (smanna12)


Changes

This patch fixes potential dereferences in 
::MappableExprsHandler::generateInfoForComponentList() for 
passing null pointer OASE to EmitOMPArraySectionExpr().

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


1 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntime.cpp (+2-2) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e8a68dbcc68709..e89a5368fb2f71 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,7 +7431,7 @@ class MappableExprsHandler {
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
@@ -7444,7 +7444,7 @@ class MappableExprsHandler {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};

``




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


[clang] [NFC][Clang] Fix static analyzer bugs with dereference after null checks (PR #86018)

2024-03-20 Thread via cfe-commits

https://github.com/smanna12 created 
https://github.com/llvm/llvm-project/pull/86018

This patch fixes potential dereferences in 
::MappableExprsHandler::generateInfoForComponentList() for passing 
null pointer OASE to EmitOMPArraySectionExpr().

>From 09ec2dd51e2decb76c1e8f6ea5a505016fa319d9 Mon Sep 17 00:00:00 2001
From: "Manna, Soumi" 
Date: Wed, 20 Mar 2024 14:57:32 -0700
Subject: [PATCH] [NFC][Clang] Fix static analyzer bugs with dereference after
 null checks

This patch fixes potential dereferences in 
::MappableExprsHandler::generateInfoForComponentList() for passing 
null pointer OASE to EmitOMPArraySectionExpr().
---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e8a68dbcc68709..e89a5368fb2f71 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7431,7 +7431,7 @@ class MappableExprsHandler {
   if (!PartialStruct.Base.isValid()) {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};
@@ -7444,7 +7444,7 @@ class MappableExprsHandler {
 PartialStruct.LowestElem = {FieldIndex, LowestElem};
   } else if (FieldIndex > PartialStruct.HighestElem.first) {
 if (IsFinalArraySection) {
-  Address HB =
+  Address HB = OASE &&
   CGF.EmitOMPArraySectionExpr(OASE, /*IsLowerBound=*/false)
   .getAddress(CGF);
   PartialStruct.HighestElem = {FieldIndex, HB};

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


[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-20 Thread Nathan Chancellor via cfe-commits

nathanchance wrote:

Thanks, this resolves my reported issue!

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


[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-20 Thread Yeoul Na via cfe-commits

https://github.com/rapidsna updated 
https://github.com/llvm/llvm-project/pull/86017

>From abfcb60e7b65e755733f4d41795aa9cfd44e0cc3 Mon Sep 17 00:00:00 2001
From: Yeoul Na 
Date: Thu, 21 Mar 2024 06:47:05 +0900
Subject: [PATCH 1/2] Unwrap CountAttributed for debug info

Fix crash caused by 3eb9ff30959a670559bcba03d149d4c51bf7c9c9
---
 clang/lib/CodeGen/CGDebugInfo.cpp  |  3 +++
 .../test/CodeGen/attr-counted-by-debug-info.c  | 18 ++
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/CodeGen/attr-counted-by-debug-info.c

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 07ecaa81c47d84..7453ed14aef414 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3463,6 +3463,9 @@ static QualType UnwrapTypeForDebugInfo(QualType T, const 
ASTContext &C) {
 case Type::BTFTagAttributed:
   T = cast(T)->getWrappedType();
   break;
+case Type::CountAttributed:
+  T = cast(T)->desugar();
+  break;
 case Type::Elaborated:
   T = cast(T)->getNamedType();
   break;
diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c 
b/clang/test/CodeGen/attr-counted-by-debug-info.c
new file mode 100644
index 00..f3e7897e12d667
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -0,0 +1,18 @@
+// RUN: %clang -emit-llvm -DCOUNTED_BY -S -g %s -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g %s -o - | FileCheck %s
+
+#ifdef COUNTED_BY
+#define __counted_by(member)__attribute__((__counted_by__(member)))
+#else
+#define __counted_by(member)
+#endif
+
+struct {
+  int num_counters;
+  long value[] __counted_by(num_counters);
+} agent_send_response_port_num;
+
+// CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], 
elements: ![[ELEMENTS:.*]])
+// ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
+// ![[ELEMENTS]] = !{![[COUNT]]}
+// ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file

>From 5bb879be895b90dc942d160fbe9dfe657e73db1d Mon Sep 17 00:00:00 2001
From: Yeoul Na 
Date: Thu, 21 Mar 2024 06:59:11 +0900
Subject: [PATCH 2/2] Add missing CHECKs

---
 clang/test/CodeGen/attr-counted-by-debug-info.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c 
b/clang/test/CodeGen/attr-counted-by-debug-info.c
index f3e7897e12d667..15197f79e4370c 100644
--- a/clang/test/CodeGen/attr-counted-by-debug-info.c
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -13,6 +13,6 @@ struct {
 } agent_send_response_port_num;
 
 // CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], 
elements: ![[ELEMENTS:.*]])
-// ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
-// ![[ELEMENTS]] = !{![[COUNT]]}
-// ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file
+// CHECK: ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: 
DW_ATE_signed)
+// CHECK: ![[ELEMENTS]] = !{![[COUNT:.*]]}
+// CHECK: ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file

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


[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-20 Thread Dan Liew via cfe-commits

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

LGTM. Thanks for the quick fix.

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


[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-20 Thread Yeoul Na via cfe-commits

rapidsna wrote:

Fix crash in https://github.com/llvm/llvm-project/pull/78000

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


[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-20 Thread Yeoul Na via cfe-commits

rapidsna wrote:

Thanks @nathanchance. Opened PR to fix the crash. 
https://github.com/llvm/llvm-project/pull/86017

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


[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-20 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Yeoul Na (rapidsna)


Changes

Fix crash caused by 3eb9ff30959a670559bcba03d149d4c51bf7c9c9

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+3) 
- (added) clang/test/CodeGen/attr-counted-by-debug-info.c (+18) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 07ecaa81c47d84..7453ed14aef414 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3463,6 +3463,9 @@ static QualType UnwrapTypeForDebugInfo(QualType T, const 
ASTContext &C) {
 case Type::BTFTagAttributed:
   T = cast(T)->getWrappedType();
   break;
+case Type::CountAttributed:
+  T = cast(T)->desugar();
+  break;
 case Type::Elaborated:
   T = cast(T)->getNamedType();
   break;
diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c 
b/clang/test/CodeGen/attr-counted-by-debug-info.c
new file mode 100644
index 00..f3e7897e12d667
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -0,0 +1,18 @@
+// RUN: %clang -emit-llvm -DCOUNTED_BY -S -g %s -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g %s -o - | FileCheck %s
+
+#ifdef COUNTED_BY
+#define __counted_by(member)__attribute__((__counted_by__(member)))
+#else
+#define __counted_by(member)
+#endif
+
+struct {
+  int num_counters;
+  long value[] __counted_by(num_counters);
+} agent_send_response_port_num;
+
+// CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], 
elements: ![[ELEMENTS:.*]])
+// ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
+// ![[ELEMENTS]] = !{![[COUNT]]}
+// ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file

``




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


[clang] Unwrap CountAttributed for debug info (PR #86017)

2024-03-20 Thread Yeoul Na via cfe-commits

https://github.com/rapidsna created 
https://github.com/llvm/llvm-project/pull/86017

Fix crash caused by 3eb9ff30959a670559bcba03d149d4c51bf7c9c9

>From abfcb60e7b65e755733f4d41795aa9cfd44e0cc3 Mon Sep 17 00:00:00 2001
From: Yeoul Na 
Date: Thu, 21 Mar 2024 06:47:05 +0900
Subject: [PATCH] Unwrap CountAttributed for debug info

Fix crash caused by 3eb9ff30959a670559bcba03d149d4c51bf7c9c9
---
 clang/lib/CodeGen/CGDebugInfo.cpp  |  3 +++
 .../test/CodeGen/attr-counted-by-debug-info.c  | 18 ++
 2 files changed, 21 insertions(+)
 create mode 100644 clang/test/CodeGen/attr-counted-by-debug-info.c

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 07ecaa81c47d84..7453ed14aef414 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -3463,6 +3463,9 @@ static QualType UnwrapTypeForDebugInfo(QualType T, const 
ASTContext &C) {
 case Type::BTFTagAttributed:
   T = cast(T)->getWrappedType();
   break;
+case Type::CountAttributed:
+  T = cast(T)->desugar();
+  break;
 case Type::Elaborated:
   T = cast(T)->getNamedType();
   break;
diff --git a/clang/test/CodeGen/attr-counted-by-debug-info.c 
b/clang/test/CodeGen/attr-counted-by-debug-info.c
new file mode 100644
index 00..f3e7897e12d667
--- /dev/null
+++ b/clang/test/CodeGen/attr-counted-by-debug-info.c
@@ -0,0 +1,18 @@
+// RUN: %clang -emit-llvm -DCOUNTED_BY -S -g %s -o - | FileCheck %s
+// RUN: %clang -emit-llvm -S -g %s -o - | FileCheck %s
+
+#ifdef COUNTED_BY
+#define __counted_by(member)__attribute__((__counted_by__(member)))
+#else
+#define __counted_by(member)
+#endif
+
+struct {
+  int num_counters;
+  long value[] __counted_by(num_counters);
+} agent_send_response_port_num;
+
+// CHECK: !DICompositeType(tag: DW_TAG_array_type, baseType: ![[BT:.*]], 
elements: ![[ELEMENTS:.*]])
+// ![[BT]] = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
+// ![[ELEMENTS]] = !{![[COUNT]]}
+// ![[COUNT]] = !DISubrange(count: -1)
\ No newline at end of file

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


[clang] [clang] Implement __builtin_{clzg,ctzg} (PR #83431)

2024-03-20 Thread via cfe-commits

https://github.com/overmighty updated 
https://github.com/llvm/llvm-project/pull/83431

>From 5e37b3b2f57c7683686b8ac64aa1566855826a9f Mon Sep 17 00:00:00 2001
From: OverMighty 
Date: Thu, 29 Feb 2024 14:23:40 +
Subject: [PATCH 1/3] [clang] Implement __builtin_{clzg,ctzg}

Fixes #83075, fixes #83076.
---
 clang/docs/LanguageExtensions.rst |  41 
 clang/include/clang/Basic/Builtins.td |  12 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  15 +-
 clang/lib/CodeGen/CGBuiltin.cpp   |  40 +++-
 clang/lib/Sema/SemaChecking.cpp   |  53 +
 clang/test/CodeGen/builtins.c | 204 ++
 clang/test/CodeGen/ubsan-builtin-checks.c |   6 +
 clang/test/Sema/builtin-popcountg.c   |  23 --
 clang/test/Sema/count-builtins.c  |  87 
 9 files changed, 445 insertions(+), 36 deletions(-)
 delete mode 100644 clang/test/Sema/builtin-popcountg.c
 create mode 100644 clang/test/Sema/count-builtins.c

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index bcd69198eafdbe..3d73d772f698ba 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3504,6 +3504,47 @@ argument can be of any unsigned integer type.
 ``__builtin_popcount{,l,ll}`` builtins, with support for other integer types,
 such as ``unsigned __int128`` and C23 ``unsigned _BitInt(N)``.
 
+``__builtin_clzg`` and ``__builtin_ctzg``
+-
+
+``__builtin_clzg`` (respectively ``__builtin_ctzg``) returns the number of
+leading (respectively trailing) 0 bits in the first argument. The first 
argument
+can be of any unsigned integer type.
+
+If the first argument is 0 and an optional second argument of ``int`` type is
+provided, then the second argument is returned. If the first argument is 0, but
+only one argument is provided, then the returned value is undefined.
+
+**Syntax**:
+
+.. code-block:: c++
+
+  int __builtin_clzg(type x[, int fallback])
+  int __builtin_ctzg(type x[, int fallback])
+
+**Examples**:
+
+.. code-block:: c++
+
+  unsigned int x = 1;
+  int x_lz = __builtin_clzg(x);
+  int x_tz = __builtin_ctzg(x);
+
+  unsigned long y = 2;
+  int y_lz = __builtin_clzg(y);
+  int y_tz = __builtin_ctzg(y);
+
+  unsigned _BitInt(128) z = 4;
+  int z_lz = __builtin_clzg(z);
+  int z_tz = __builtin_ctzg(z);
+
+**Description**:
+
+``__builtin_clzg`` (respectively ``__builtin_ctzg``) is meant to be a
+type-generic alternative to the ``__builtin_clz{,l,ll}`` (respectively
+``__builtin_ctz{,l,ll}``) builtins, with support for other integer types, such
+as ``unsigned __int128`` and C23 ``unsigned _BitInt(N)``.
+
 Multiprecision Arithmetic Builtins
 --
 
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 2c83dca248fb7d..206ccaf1bdaa13 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -662,6 +662,12 @@ def Clz : Builtin, BitShort_Int_Long_LongLongTemplate {
 
 // FIXME: Add int clzimax(uintmax_t)
 
+def Clzg : Builtin {
+  let Spellings = ["__builtin_clzg"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "int(...)";
+}
+
 def Ctz : Builtin, BitShort_Int_Long_LongLongTemplate {
   let Spellings = ["__builtin_ctz"];
   let Attributes = [NoThrow, Const, Constexpr];
@@ -670,6 +676,12 @@ def Ctz : Builtin, BitShort_Int_Long_LongLongTemplate {
 
 // FIXME: Add int ctzimax(uintmax_t)
 
+def Ctzg : Builtin {
+  let Spellings = ["__builtin_ctzg"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "int(...)";
+}
+
 def FFS : Builtin, BitInt_Long_LongLongTemplate {
   let Spellings = ["__builtin_ffs"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, Const, Constexpr];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 91105d4231f06a..a65052e2b54f29 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11978,13 +11978,14 @@ def err_builtin_launder_invalid_arg : Error<
   "'__builtin_launder' is not allowed">;
 
 def err_builtin_invalid_arg_type: Error <
-  "%ordinal0 argument must be a "
-  "%select{vector, integer or floating point type|matrix|"
-  "pointer to a valid matrix element type|"
-  "signed integer or floating point type|vector type|"
-  "floating point type|"
-  "vector of integers|"
-  "type of unsigned integer}1 (was %2)">;
+  "%ordinal0 argument must be "
+  "%select{a vector, integer or floating point type|a matrix|"
+  "a pointer to a valid matrix element type|"
+  "a signed integer or floating point type|a vector type|"
+  "a floating point type|"
+  "a vector of integers|"
+  "an unsigned integer|"
+  "an 'int'}1 (was %2)">;
 
 def err_builtin_matrix_disabled: Error<
   "matrix types extension is disabled. Pass -fenable-matrix to ena

[clang] Rebase swiftasynccall's musttail support onto the [[clang::musttail]] logic (PR #86011)

2024-03-20 Thread John McCall via cfe-commits

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


[clang] de4ce5d - Rebase swiftasynccall's musttail support onto the [[clang::musttail]] logic (#86011)

2024-03-20 Thread via cfe-commits

Author: John McCall
Date: 2024-03-20T17:21:37-04:00
New Revision: de4ce5dd2bde7f9d7cbfe47a542a308779c43ce3

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

LOG: Rebase swiftasynccall's musttail support onto the [[clang::musttail]] 
logic (#86011)

The old logic expects the call to be the last thing we emitted, and
since it kicks in before we emit cleanups, and since `swiftasynccall`
functions always return void, that's likely to be true. "Likely" isn't
very reassuring when we're talking about slapping attributes on random
calls, though. And indeed, while I can't find any way to break the logic
directly in current main, our previous (ongoing?) experiments with
shortening argument temporary lifetimes definitely broke it wide open.
So while this commit is prophylactic for now, it's clearly the right
thing to do, and it can cherry-picked to other branches to fix problems.

Added: 


Modified: 
clang/lib/CodeGen/CGStmt.cpp
clang/test/CodeGen/swift-async-call-conv.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 8898e3f22a7df6..cb5a004e4f4a6c 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1341,10 +1341,8 @@ struct SaveRetExprRAII {
 };
 } // namespace
 
-/// If we have 'return f(...);', where both caller and callee are SwiftAsync,
-/// codegen it as 'tail call ...; ret void;'.
-static void makeTailCallIfSwiftAsync(const CallExpr *CE, CGBuilderTy &Builder,
- const CGFunctionInfo *CurFnInfo) {
+/// Determine if the given call uses the swiftasync calling convention.
+static bool isSwiftAsyncCallee(const CallExpr *CE) {
   auto calleeQualType = CE->getCallee()->getType();
   const FunctionType *calleeType = nullptr;
   if (calleeQualType->isFunctionPointerType() ||
@@ -1359,18 +1357,12 @@ static void makeTailCallIfSwiftAsync(const CallExpr 
*CE, CGBuilderTy &Builder,
   // getMethodDecl() doesn't handle member pointers at the moment.
   calleeType = methodDecl->getType()->castAs();
 } else {
-  return;
+  return false;
 }
   } else {
-return;
-  }
-  if (calleeType->getCallConv() == CallingConv::CC_SwiftAsync &&
-  (CurFnInfo->getASTCallingConvention() == CallingConv::CC_SwiftAsync)) {
-auto CI = cast(&Builder.GetInsertBlock()->back());
-CI->setTailCallKind(llvm::CallInst::TCK_MustTail);
-Builder.CreateRetVoid();
-Builder.ClearInsertionPoint();
+return false;
   }
+  return calleeType->getCallConv() == CallingConv::CC_SwiftAsync;
 }
 
 /// EmitReturnStmt - Note that due to GCC extensions, this can have an operand
@@ -1410,6 +1402,19 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt 
&S) {
   RunCleanupsScope cleanupScope(*this);
   if (const auto *EWC = dyn_cast_or_null(RV))
 RV = EWC->getSubExpr();
+
+  // If we're in a swiftasynccall function, and the return expression is a
+  // call to a swiftasynccall function, mark the call as the musttail call.
+  std::optional> SaveMustTail;
+  if (RV && CurFnInfo &&
+  CurFnInfo->getASTCallingConvention() == CallingConv::CC_SwiftAsync) {
+if (auto CE = dyn_cast(RV)) {
+  if (isSwiftAsyncCallee(CE)) {
+SaveMustTail.emplace(MustTailCall, CE);
+  }
+}
+  }
+
   // FIXME: Clean this up by using an LValue for ReturnTemp,
   // EmitStoreThroughLValue, and EmitAnyExpr.
   // Check if the NRVO candidate was not globalized in OpenMP mode.
@@ -1432,8 +1437,6 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) 
{
 // for side effects.
 if (RV) {
   EmitAnyExpr(RV);
-  if (auto *CE = dyn_cast(RV))
-makeTailCallIfSwiftAsync(CE, Builder, CurFnInfo);
 }
   } else if (!RV) {
 // Do nothing (return value is left uninitialized)

diff  --git a/clang/test/CodeGen/swift-async-call-conv.c 
b/clang/test/CodeGen/swift-async-call-conv.c
index ce32c22fe80984..39511698bbae9d 100644
--- a/clang/test/CodeGen/swift-async-call-conv.c
+++ b/clang/test/CodeGen/swift-async-call-conv.c
@@ -182,3 +182,19 @@ SWIFTASYNCCALL void async_struct_field_and_methods(int i, 
S &sref, S *sptr) {
 // CPPONLY-LABEL: define{{.*}} swifttailcc void @{{.*}}async_nonleaf_method2
 // CPPONLY: musttail call swifttailcc void @{{.*}}async_leaf_method
 #endif
+
+// Passing this as an argument requires a coerce-and-expand operation,
+// which requires a temporary.  Make sure that cleaning up that temporary
+// doesn't mess around with the musttail handling.
+struct coerce_and_expand {
+  char a,b,c,d;
+};
+struct coerce_and_expand return_coerced(void);
+SWIFTASYNCCALL void take_coerced_async(struct coerce_and_expand);
+
+// CHECK-LABEL: swifttailcc void @{{.*}}test_coerced
+SWIFTASYNCCALL void test_coerced() {
+  // CHECK:  musttail call swifttailcc 

[clang] Rebase swiftasynccall's musttail support onto the [[clang::musttail]] logic (PR #86011)

2024-03-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: John McCall (rjmccall)


Changes

The old logic expects the call to be the last thing we emitted, and since it 
kicks in before we emit cleanups, and since `swiftasynccall` functions always 
return void, that's likely to be true.  "Likely" isn't very reassuring when 
we're talking about slapping attributes on random calls, though.  And indeed, 
while I can't find any way to break the logic directly in current main, our 
previous (ongoing?) experiments with shortening argument temporary lifetimes 
definitely broke it wide open.  So while this commit is prophylactic for now, 
it's clearly the right thing to do, and it can cherry-picked to other branches 
to fix problems.

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGStmt.cpp (+18-15) 
- (modified) clang/test/CodeGen/swift-async-call-conv.c (+16) 


``diff
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 8898e3f22a7df6..cb5a004e4f4a6c 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1341,10 +1341,8 @@ struct SaveRetExprRAII {
 };
 } // namespace
 
-/// If we have 'return f(...);', where both caller and callee are SwiftAsync,
-/// codegen it as 'tail call ...; ret void;'.
-static void makeTailCallIfSwiftAsync(const CallExpr *CE, CGBuilderTy &Builder,
- const CGFunctionInfo *CurFnInfo) {
+/// Determine if the given call uses the swiftasync calling convention.
+static bool isSwiftAsyncCallee(const CallExpr *CE) {
   auto calleeQualType = CE->getCallee()->getType();
   const FunctionType *calleeType = nullptr;
   if (calleeQualType->isFunctionPointerType() ||
@@ -1359,18 +1357,12 @@ static void makeTailCallIfSwiftAsync(const CallExpr 
*CE, CGBuilderTy &Builder,
   // getMethodDecl() doesn't handle member pointers at the moment.
   calleeType = methodDecl->getType()->castAs();
 } else {
-  return;
+  return false;
 }
   } else {
-return;
-  }
-  if (calleeType->getCallConv() == CallingConv::CC_SwiftAsync &&
-  (CurFnInfo->getASTCallingConvention() == CallingConv::CC_SwiftAsync)) {
-auto CI = cast(&Builder.GetInsertBlock()->back());
-CI->setTailCallKind(llvm::CallInst::TCK_MustTail);
-Builder.CreateRetVoid();
-Builder.ClearInsertionPoint();
+return false;
   }
+  return calleeType->getCallConv() == CallingConv::CC_SwiftAsync;
 }
 
 /// EmitReturnStmt - Note that due to GCC extensions, this can have an operand
@@ -1410,6 +1402,19 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt 
&S) {
   RunCleanupsScope cleanupScope(*this);
   if (const auto *EWC = dyn_cast_or_null(RV))
 RV = EWC->getSubExpr();
+
+  // If we're in a swiftasynccall function, and the return expression is a
+  // call to a swiftasynccall function, mark the call as the musttail call.
+  std::optional> SaveMustTail;
+  if (RV && CurFnInfo &&
+  CurFnInfo->getASTCallingConvention() == CallingConv::CC_SwiftAsync) {
+if (auto CE = dyn_cast(RV)) {
+  if (isSwiftAsyncCallee(CE)) {
+SaveMustTail.emplace(MustTailCall, CE);
+  }
+}
+  }
+
   // FIXME: Clean this up by using an LValue for ReturnTemp,
   // EmitStoreThroughLValue, and EmitAnyExpr.
   // Check if the NRVO candidate was not globalized in OpenMP mode.
@@ -1432,8 +1437,6 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) 
{
 // for side effects.
 if (RV) {
   EmitAnyExpr(RV);
-  if (auto *CE = dyn_cast(RV))
-makeTailCallIfSwiftAsync(CE, Builder, CurFnInfo);
 }
   } else if (!RV) {
 // Do nothing (return value is left uninitialized)
diff --git a/clang/test/CodeGen/swift-async-call-conv.c 
b/clang/test/CodeGen/swift-async-call-conv.c
index ce32c22fe80984..39511698bbae9d 100644
--- a/clang/test/CodeGen/swift-async-call-conv.c
+++ b/clang/test/CodeGen/swift-async-call-conv.c
@@ -182,3 +182,19 @@ SWIFTASYNCCALL void async_struct_field_and_methods(int i, 
S &sref, S *sptr) {
 // CPPONLY-LABEL: define{{.*}} swifttailcc void @{{.*}}async_nonleaf_method2
 // CPPONLY: musttail call swifttailcc void @{{.*}}async_leaf_method
 #endif
+
+// Passing this as an argument requires a coerce-and-expand operation,
+// which requires a temporary.  Make sure that cleaning up that temporary
+// doesn't mess around with the musttail handling.
+struct coerce_and_expand {
+  char a,b,c,d;
+};
+struct coerce_and_expand return_coerced(void);
+SWIFTASYNCCALL void take_coerced_async(struct coerce_and_expand);
+
+// CHECK-LABEL: swifttailcc void @{{.*}}test_coerced
+SWIFTASYNCCALL void test_coerced() {
+  // CHECK:  musttail call swifttailcc void @{{.*}}take_coerced_async
+  // CHECK-NEXT: ret void
+  return take_coerced_async(return_coerced());
+}

``




https://github.com/llvm/llvm-project/pull/86011
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
ht

[clang] Rebase swiftasynccall's musttail support onto the [[clang::musttail]] logic (PR #86011)

2024-03-20 Thread John McCall via cfe-commits

https://github.com/rjmccall created 
https://github.com/llvm/llvm-project/pull/86011

The old logic expects the call to be the last thing we emitted, and since it 
kicks in before we emit cleanups, and since `swiftasynccall` functions always 
return void, that's likely to be true.  "Likely" isn't very reassuring when 
we're talking about slapping attributes on random calls, though.  And indeed, 
while I can't find any way to break the logic directly in current main, our 
previous (ongoing?) experiments with shortening argument temporary lifetimes 
definitely broke it wide open.  So while this commit is prophylactic for now, 
it's clearly the right thing to do, and it can cherry-picked to other branches 
to fix problems.

>From 22ee234b13d5adec71627e9df8912b551bbb0b8e Mon Sep 17 00:00:00 2001
From: John McCall 
Date: Wed, 20 Mar 2024 17:04:28 -0400
Subject: [PATCH] Rebase swiftasynccall's musttail support onto the
 [[clang::musttail]] logic

The old logic expects the call to be the last thing we emitted, and since
it kicks in before we emit cleanups, and since swiftasynccall functions
always return void, that's likely to be true.  "Likely" isn't very
reassuring when we're talking about slapping attributes on random calls,
though.  And indeed, while I can't find any way to break the logic directly
in current main, our previous (ongoing?) experiments with shortening
argument temporary lifetimes definitely broke it wide open.  So while
this commit is prophylactic for now, it's clearly the right thing to do,
and it can cherry-picked to other branches to fix problems.
---
 clang/lib/CodeGen/CGStmt.cpp   | 33 --
 clang/test/CodeGen/swift-async-call-conv.c | 16 +++
 2 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index 8898e3f22a7df6..cb5a004e4f4a6c 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -1341,10 +1341,8 @@ struct SaveRetExprRAII {
 };
 } // namespace
 
-/// If we have 'return f(...);', where both caller and callee are SwiftAsync,
-/// codegen it as 'tail call ...; ret void;'.
-static void makeTailCallIfSwiftAsync(const CallExpr *CE, CGBuilderTy &Builder,
- const CGFunctionInfo *CurFnInfo) {
+/// Determine if the given call uses the swiftasync calling convention.
+static bool isSwiftAsyncCallee(const CallExpr *CE) {
   auto calleeQualType = CE->getCallee()->getType();
   const FunctionType *calleeType = nullptr;
   if (calleeQualType->isFunctionPointerType() ||
@@ -1359,18 +1357,12 @@ static void makeTailCallIfSwiftAsync(const CallExpr 
*CE, CGBuilderTy &Builder,
   // getMethodDecl() doesn't handle member pointers at the moment.
   calleeType = methodDecl->getType()->castAs();
 } else {
-  return;
+  return false;
 }
   } else {
-return;
-  }
-  if (calleeType->getCallConv() == CallingConv::CC_SwiftAsync &&
-  (CurFnInfo->getASTCallingConvention() == CallingConv::CC_SwiftAsync)) {
-auto CI = cast(&Builder.GetInsertBlock()->back());
-CI->setTailCallKind(llvm::CallInst::TCK_MustTail);
-Builder.CreateRetVoid();
-Builder.ClearInsertionPoint();
+return false;
   }
+  return calleeType->getCallConv() == CallingConv::CC_SwiftAsync;
 }
 
 /// EmitReturnStmt - Note that due to GCC extensions, this can have an operand
@@ -1410,6 +1402,19 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt 
&S) {
   RunCleanupsScope cleanupScope(*this);
   if (const auto *EWC = dyn_cast_or_null(RV))
 RV = EWC->getSubExpr();
+
+  // If we're in a swiftasynccall function, and the return expression is a
+  // call to a swiftasynccall function, mark the call as the musttail call.
+  std::optional> SaveMustTail;
+  if (RV && CurFnInfo &&
+  CurFnInfo->getASTCallingConvention() == CallingConv::CC_SwiftAsync) {
+if (auto CE = dyn_cast(RV)) {
+  if (isSwiftAsyncCallee(CE)) {
+SaveMustTail.emplace(MustTailCall, CE);
+  }
+}
+  }
+
   // FIXME: Clean this up by using an LValue for ReturnTemp,
   // EmitStoreThroughLValue, and EmitAnyExpr.
   // Check if the NRVO candidate was not globalized in OpenMP mode.
@@ -1432,8 +1437,6 @@ void CodeGenFunction::EmitReturnStmt(const ReturnStmt &S) 
{
 // for side effects.
 if (RV) {
   EmitAnyExpr(RV);
-  if (auto *CE = dyn_cast(RV))
-makeTailCallIfSwiftAsync(CE, Builder, CurFnInfo);
 }
   } else if (!RV) {
 // Do nothing (return value is left uninitialized)
diff --git a/clang/test/CodeGen/swift-async-call-conv.c 
b/clang/test/CodeGen/swift-async-call-conv.c
index ce32c22fe80984..39511698bbae9d 100644
--- a/clang/test/CodeGen/swift-async-call-conv.c
+++ b/clang/test/CodeGen/swift-async-call-conv.c
@@ -182,3 +182,19 @@ SWIFTASYNCCALL void async_struct_field_and_methods(int i, 
S &sref, S *sptr) {
 // CPPONLY-LABEL: define{{.*}} swifttailcc void @{{.*}}async_nonleaf_method2
 // CPPONLY: musttail call swif

[clang] [PAC][clang] Define `PointerAuthQualifier` and `PointerAuthenticationMode` (PR #84384)

2024-03-20 Thread Daniil Kovalev via cfe-commits

kovdan01 wrote:

A kind reminder regarding the PR - would be glad to see feedback from everyone 
interested.

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


[clang] [X86_64] fix empty structure vaarg in c++ (PR #77907)

2024-03-20 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

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


[clang] [llvm] [clang][HLSL][SPRI-V] Add convergence intrinsics (PR #80680)

2024-03-20 Thread Chris B via cfe-commits
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= ,
Nathan =?utf-8?q?Gauër?= 
Message-ID:
In-Reply-To: 



@@ -1295,11 +1295,13 @@ double4 trunc(double4);
 /// true, across all active lanes in the current wave.
 _HLSL_AVAILABILITY(shadermodel, 6.0)
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_wave_active_count_bits)
+__attribute__((convergent))

llvm-beanz wrote:

I'm not sure I entirely agree with @arsenm here.

>From the LLVM-IR and compiler implementation perspective it is helpful to be 
>able to expect that convergent is the default expected behavior, but from the 
>language perspective for HLSL it is preferable to imply that convergence is 
>the outlier because in the common case convergence isn't required.

I really don't want to tie the implementation of HLSL to a 4.5 year old PR that 
isn't merged.

@bogner, do you have thoughts here?

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


[clang] 294a6c3 - [clang] Fix a warning

2024-03-20 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-03-20T13:38:26-07:00
New Revision: 294a6c3b650d2411e50487b287b24b7d85847162

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

LOG: [clang] Fix a warning

This patch fixes:

  clang/lib/CodeGen/CGExprComplex.cpp:1037:14: error: unused variable
  'ComplexElementTy' [-Werror,-Wunused-variable]

Added: 


Modified: 
clang/lib/CodeGen/CGExprComplex.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprComplex.cpp 
b/clang/lib/CodeGen/CGExprComplex.cpp
index 27ddaacc28f522..b873bc6737bb0a 100644
--- a/clang/lib/CodeGen/CGExprComplex.cpp
+++ b/clang/lib/CodeGen/CGExprComplex.cpp
@@ -1034,7 +1034,6 @@ ComplexPairTy ComplexExprEmitter::EmitBinDiv(const 
BinOpInfo &Op) {
 llvm::Value *OrigLHSi = LHSi;
 if (!LHSi)
   LHSi = llvm::Constant::getNullValue(RHSi->getType());
-QualType ComplexElementTy = Op.Ty->castAs()->getElementType();
 if (Op.FPFeatures.getComplexRange() == LangOptions::CX_Improved ||
 (Op.FPFeatures.getComplexRange() == LangOptions::CX_Promoted &&
  FPHasBeenPromoted))



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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-20 Thread Akira Hatanaka via cfe-commits


@@ -3424,6 +3445,26 @@ llvm::DIMacroFile 
*CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent,
   return DBuilder.createTempMacroFile(Parent, Line, FName);
 }
 
+llvm::DILocation *CGDebugInfo::CreateTrapFailureMessageFor(

ahatanak wrote:

@dwblaikie what do you think? `-fbounds-safety` is currently being upstreamed 
and there is going to be another caller of the function in the not-too-distant 
future.

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


[clang] Turn 'counted_by' into a type attribute and parse it into 'CountAttributedType' (PR #78000)

2024-03-20 Thread Dan Liew via cfe-commits

delcypher wrote:

@nathanchance Thanks for reporting this. I'm going to have a quick go at 
reproducing this to see if fixing this is straight forward. If it is not I will 
revert this PR and then we can re-land this change with the problem you 
reported fixed.

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


[clang] [clang][CodeGen] Allow memcpy replace with trivial auto var init (PR #84230)

2024-03-20 Thread via cfe-commits

https://github.com/serge-sans-paille approved this pull request.


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


[clang] [AArch64][PAC][clang][ELF] Support PAuth ABI compatibility tag (PR #85235)

2024-03-20 Thread Daniil Kovalev via cfe-commits

https://github.com/kovdan01 updated 
https://github.com/llvm/llvm-project/pull/85235

>From 919af72c09216838bfe586c3da503f5d74104a7d Mon Sep 17 00:00:00 2001
From: Daniil Kovalev 
Date: Tue, 19 Mar 2024 23:57:06 +0300
Subject: [PATCH 1/3] [PAC][clang] Define ptrauth driver flags and preprocessor
 features

Define the following clang driver flags:

- `-fptrauth-intrinsics`: `PointerAuth.intrinsics()` in `LangOptions`,
  `ptrauth_intrinsics` preprocessor feature;

- `-fptrauth-calls`: `PointerAuth.calls()` in `LangOptions`, `ptrauth_calls` and
  and `ptrauth_member_function_pointer_type_discrimination` preprocessor
  features;

- `-fptrauth-returns`: `PointerAuth.returns()` in `LangOptions`,
  `ptrauth_returns` preprocessor feature;

- `-fptrauth-auth-traps`: `PointerAuth.authTraps()` in `LangOptions`;

- `-fptrauth-vtable-pointer-address-discrimination`:
  `PointerAuth.vtptrAddressDiscrimination()` in `LangOptions`,
  `ptrauth_vtable_pointer_address_discrimination` preprocessor feature;

- `-fptrauth-vtable-pointer-type-discrimination`:
  `PointerAuth.vtptrTypeDiscrimination()` in `LangOptions`,
  `ptrauth_vtable_pointer_type_discrimination` preprocessor feature;

- `-fptrauth-init-fini`: `PointerAuth.initFini()` in `LangOptions`,
  `ptrauth_init_fini` preprocessor feature.

The patch only defines the flags and having corresponding `LangOptions`
set does not affect codegen yet.

Co-authored-by: Ahmed Bougacha 
---
 clang/include/clang/Basic/Features.def|   6 ++
 clang/include/clang/Basic/LangOptions.def |   6 ++
 clang/include/clang/Driver/Options.td |  18 
 clang/lib/Driver/ToolChains/Clang.cpp |  27 ++
 clang/lib/Frontend/CompilerInvocation.cpp |  20 
 clang/test/Driver/ptrauth.c   |  32 +++
 clang/test/Preprocessor/ptrauth_feature.c | 107 +-
 7 files changed, 214 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/ptrauth.c

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index eeed5f4751f2f4..1c6236aa4f9748 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -102,6 +102,12 @@ FEATURE(thread_sanitizer, 
LangOpts.Sanitize.has(SanitizerKind::Thread))
 FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
 FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
 FEATURE(ptrauth_intrinsics, LangOpts.PointerAuthIntrinsics)
+FEATURE(ptrauth_calls, LangOpts.PointerAuthCalls)
+FEATURE(ptrauth_returns, LangOpts.PointerAuthReturns)
+FEATURE(ptrauth_vtable_pointer_address_discrimination, 
LangOpts.PointerAuthVTPtrAddressDiscrimination)
+FEATURE(ptrauth_vtable_pointer_type_discrimination, 
LangOpts.PointerAuthVTPtrTypeDiscrimination)
+FEATURE(ptrauth_member_function_pointer_type_discrimination, 
LangOpts.PointerAuthCalls)
+FEATURE(ptrauth_init_fini, LangOpts.PointerAuthInitFini)
 FEATURE(swiftasynccc,
   PP.getTargetInfo().checkCallingConvention(CC_SwiftAsync) ==
   clang::TargetInfo::CCCR_OK)
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 8ef6700ecdc78e..4b99e70298462f 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -162,6 +162,12 @@ LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed 
matching of template t
 LANGOPT(ExperimentalLibrary, 1, 0, "enable unstable and experimental library 
features")
 
 LANGOPT(PointerAuthIntrinsics, 1, 0, "pointer authentication intrinsics")
+LANGOPT(PointerAuthCalls  , 1, 0, "function pointer authentication")
+LANGOPT(PointerAuthReturns, 1, 0, "return pointer authentication")
+LANGOPT(PointerAuthAuthTraps, 1, 0, "pointer authentication failure traps")
+LANGOPT(PointerAuthVTPtrAddressDiscrimination, 1, 0, "incorporate address 
discrimination in authenticated vtable pointers")
+LANGOPT(PointerAuthVTPtrTypeDiscrimination, 1, 0, "incorporate type 
discrimination in authenticated vtable pointers")
+LANGOPT(PointerAuthInitFini, 1, 0, "sign function pointers in init/fini 
arrays")
 
 LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 29c226f4bd8da7..e624eed2a15316 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4110,8 +4110,26 @@ let Group = f_Group in {
   let Visibility = [ClangOption,CC1Option] in {
 def fptrauth_intrinsics : Flag<["-"], "fptrauth-intrinsics">,
   HelpText<"Enable pointer authentication intrinsics">;
+def fptrauth_calls : Flag<["-"], "fptrauth-calls">,
+  HelpText<"Enable signing and authentication of all indirect calls">;
+def fptrauth_returns : Flag<["-"], "fptrauth-returns">,
+  HelpText<"Enable signing and authentication of return addresses">;
+def fptrauth_auth_traps : Flag<["-"], "fptrauth-auth-traps">,
+  Hel

[clang] [llvm] Add option to generate additional debug info for expression dereferencing pointer to pointers. (PR #81545)

2024-03-20 Thread William Junda Huang via cfe-commits

https://github.com/huangjd updated 
https://github.com/llvm/llvm-project/pull/81545

>From f2c82758e1cba7773e41d941d2812c829c339675 Mon Sep 17 00:00:00 2001
From: William Huang 
Date: Mon, 12 Feb 2024 02:27:13 -0500
Subject: [PATCH 1/9] Add option to generate additional info for expression
 containing pointer of pointers.

Such expression does correspond to a variable in the source code thus
does not have a debug location. However the user may want to collect
sampling counter for memory accesses to analyze usage frequency of class
members. By enabling -fdebug_info_for_pointer_type a psuedo variable and
its debug info is generated in place whenever there's an intermediate
expression with pointer access.
---
 clang/include/clang/Basic/DebugOptions.def |  4 ++
 clang/include/clang/Driver/Options.td  |  4 ++
 clang/lib/CodeGen/CGDebugInfo.cpp  | 16 +
 clang/lib/CodeGen/CGDebugInfo.h|  6 ++
 clang/lib/CodeGen/CGDecl.cpp   |  4 ++
 clang/lib/CodeGen/CGExpr.cpp   | 79 ++
 clang/lib/CodeGen/CodeGenFunction.h|  5 ++
 clang/lib/Driver/ToolChains/Clang.cpp  |  3 +
 8 files changed, 121 insertions(+)

diff --git a/clang/include/clang/Basic/DebugOptions.def 
b/clang/include/clang/Basic/DebugOptions.def
index 7cd3edf08a17ea..6dd09f46842077 100644
--- a/clang/include/clang/Basic/DebugOptions.def
+++ b/clang/include/clang/Basic/DebugOptions.def
@@ -129,6 +129,10 @@ DEBUGOPT(CodeViewCommandLine, 1, 0)
 /// Whether emit extra debug info for sample pgo profile collection.
 DEBUGOPT(DebugInfoForProfiling, 1, 0)
 
+/// Whether to generate pseudo variables and their debug info for intermediate
+/// pointer accesses.
+DEBUGOPT(DebugInfoForPointerType, 1, 0)
+
 /// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
 DEBUGOPT(DebugNameTable, 2, 0)
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748faca..96b22d3f7640dd 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1675,6 +1675,10 @@ defm debug_info_for_profiling : 
BoolFOption<"debug-info-for-profiling",
   PosFlag,
   NegFlag>;
+def fdebug_info_for_pointer_type : Flag<["-"], "fdebug-info-for-pointer-type">,
+  Group, Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Generate pseudo variables and their debug info for intermediate 
pointer accesses">,
+  MarshallingInfoFlag>;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Visibility<[ClangOption, CLOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0f3f684d61dc94..6ce40da22dc97d 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -5636,6 +5636,22 @@ void 
CGDebugInfo::EmitExternalVariable(llvm::GlobalVariable *Var,
   Var->addDebugInfo(GVE);
 }
 
+void CGDebugInfo::EmitPseudoVariable(llvm::AllocaInst *Alloca, QualType Ty,
+ SourceLocation Loc) {
+  llvm::DIFile *Unit = getOrCreateFile(Loc);
+  unsigned Line = getLineNumber(Loc);
+  unsigned Column = getColumnNumber(Loc);
+  llvm::DILocalVariable *D = DBuilder.createAutoVariable(
+  LexicalBlockStack.back(), Alloca->getName(), getOrCreateFile(Loc), Line,
+  getOrCreateType(Ty, Unit));
+  llvm::DILocation *DIL =
+  llvm::DILocation::get(CGM.getLLVMContext(), Line, Column,
+LexicalBlockStack.back(), CurInlinedAt);
+  SmallVector Expr;
+  DBuilder.insertDeclare(Alloca, D, DBuilder.createExpression(Expr), DIL,
+ Alloca->getParent());
+}
+
 void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
   const GlobalDecl GD) {
 
diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 7b60e94555d060..a2c484f50b2bc5 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -529,6 +529,12 @@ class CGDebugInfo {
   /// Emit information about an external variable.
   void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
 
+  /// Emit debug information for a pseudo variable assigned to the value of an
+  /// intermediate expression, so that a performance counter can track the 
usage
+  /// of a specific expression of interest.
+  void EmitPseudoVariable(llvm::AllocaInst *Alloca, QualType Ty,
+  SourceLocation Loc);
+
   /// Emit information about global variable alias.
   void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl);
 
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index bbe14ef4c17244..5f7b2529179003 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -793,6 +793,10 @@ void CodeGenFunct

[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-20 Thread Akira Hatanaka via cfe-commits


@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -std=c++20 -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s

ahatanak wrote:

In that case, we can use `-disable-llvm-passes` or `-disable-llvm-optzns` to 
avoid running the llvm optimization passes.

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-20 Thread Akira Hatanaka via cfe-commits

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

>From 678cd8ea37f1d02c70fd09b7107542c8301c3bd2 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Tue, 16 Jan 2024 13:18:09 -0800
Subject: [PATCH 01/12] Add support for builtin_verbose_trap

The builtin causes the program to stop its execution abnormally and shows a
human-readable description of the reason for the termination when a debugger is
attached or in a symbolicated crash log.

The motivation for the builtin is explained in the following RFC:

https://discourse.llvm.org/t/rfc-adding-builtin-verbose-trap-string-literal/75845
---
 clang/docs/LanguageExtensions.rst | 48 ++
 clang/include/clang/AST/Expr.h|  5 ++
 clang/include/clang/Basic/Builtins.td |  6 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +
 clang/lib/AST/ExprConstant.cpp| 18 +--
 clang/lib/CodeGen/CGBuiltin.cpp   | 12 +
 clang/lib/CodeGen/CGDebugInfo.cpp | 42 
 clang/lib/CodeGen/CGDebugInfo.h   | 20 
 clang/lib/Sema/SemaChecking.cpp   | 22 +
 .../CodeGenCXX/debug-info-verbose-trap.cpp| 49 +++
 clang/test/SemaCXX/verbose-trap.cpp   | 28 +++
 11 files changed, 249 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenCXX/debug-info-verbose-trap.cpp
 create mode 100644 clang/test/SemaCXX/verbose-trap.cpp

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index c1420079f75118..4526bc2df53e42 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -3379,6 +3379,54 @@ Query for this feature with 
``__has_builtin(__builtin_debugtrap)``.
 
 Query for this feature with ``__has_builtin(__builtin_trap)``.
 
+``__builtin_verbose_trap``
+--
+
+``__builtin_verbose_trap`` causes the program to stop its execution abnormally
+and shows a human-readable description of the reason for the termination when a
+debugger is attached or in a symbolicated crash log.
+
+**Syntax**:
+
+.. code-block:: c++
+
+__builtin_verbose_trap(const char *reason)
+
+**Description**
+
+``__builtin_verbose_trap`` is lowered to the ` ``llvm.trap`` 
`_ builtin.
+Additionally, clang emits debug metadata that represents an artificial inline
+frame whose name encodes the string passed to the builtin, prefixed by a 
"magic"
+prefix.
+
+For example, consider the following code:
+
+.. code-block:: c++
+
+void foo(int* p) {
+  if (p == nullptr)
+__builtin_verbose_trap("Argument_must_not_be_null");
+}
+
+The debug metadata would look as if it were produced for the following code:
+
+.. code-block:: c++
+
+__attribute__((always_inline))
+inline void "__llvm_verbose_trap: Argument_must_not_be_null"() {
+  __builtin_trap();
+}
+
+void foo(int* p) {
+  if (p == nullptr)
+"__llvm_verbose_trap: Argument_must_not_be_null"();
+}
+
+However, the LLVM IR would not actually contain a call to the artificial
+function — it only exists in the debug metadata.
+
+Query for this feature with ``__has_builtin(__builtin_verbose_trap)``.
+
 ``__builtin_nondeterministic_value``
 
 
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 59f0aee2c0cedd..68447b19a4a107 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -775,6 +775,11 @@ class Expr : public ValueStmt {
  const Expr *PtrExpression, ASTContext &Ctx,
  EvalResult &Status) const;
 
+  /// If the current Expr can be evaluated to a pointer to a null-terminated
+  /// constant string, return the constant string (without the terminating 
null)
+  /// in Result. Return true if it succeeds.
+  bool tryEvaluateString(std::string &Result, ASTContext &Ctx) const;
+
   /// Enumeration used to describe the kind of Null pointer constant
   /// returned from \c isNullPointerConstant().
   enum NullPointerConstantKind {
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 22e616e6cde599..217c09e85a55cc 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -1096,6 +1096,12 @@ def Trap : Builtin {
   let Prototype = "void()";
 }
 
+def VerboseTrap : Builtin {
+  let Spellings = ["__builtin_verbose_trap"];
+  let Attributes = [NoThrow, NoReturn];
+  let Prototype = "void(char const*)";
+}
+
 def Debugtrap : Builtin {
   let Spellings = ["__builtin_debugtrap"];
   let Attributes = [NoThrow];
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a1c32abb4dcd88..40482a964b39d5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic

[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-20 Thread zhijian lin via cfe-commits

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-20 Thread zhijian lin via cfe-commits

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


[clang] [clang][PowerPC] Add flag to enable compatibility with GNU for complex arguments (PR #77732)

2024-03-20 Thread zhijian lin via cfe-commits

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-20 Thread Dan Liew via cfe-commits

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


[clang] Add support for builtin_verbose_trap (PR #79230)

2024-03-20 Thread Dan Liew via cfe-commits


@@ -0,0 +1,49 @@
+// RUN: %clang_cc1 -triple arm64-apple-ios -std=c++20 -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s

delcypher wrote:

@pogo59 @ahatanak Thanks for the explanation.

A slight issue with that is some cases Clang will generate different 
(unoptimized IR) depending on the optimization level (see 
`CodeGenFunction::EmitTrapCheck`) so in those cases you have to test Clang's 
optimizing behavior. You're not using that here so that's fine

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


[clang] Disable driver tests on macosx that are currently disabled on darwin (PR #85990)

2024-03-20 Thread Akira Hatanaka via cfe-commits

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

>From ae75aa6994ebc9d2daaa5fcc4cb18bd857214291 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Wed, 20 Mar 2024 11:57:03 -0700
Subject: [PATCH] Disable driver tests on macosx that are currently disabled on
 darwin

macosx and darwin in triples are equivalent.

rdar://124246653
---
 clang/test/Driver/clang-offload-bundler-asserts-on.c  | 2 +-
 clang/test/Driver/clang-offload-bundler-standardize.c | 2 +-
 clang/test/Driver/clang-offload-bundler.c | 2 +-
 clang/test/Driver/fat-archive-unbundle-ext.c  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/clang-offload-bundler-asserts-on.c 
b/clang/test/Driver/clang-offload-bundler-asserts-on.c
index 521c8641ff5468..eb11d5fbbee4a7 100644
--- a/clang/test/Driver/clang-offload-bundler-asserts-on.c
+++ b/clang/test/Driver/clang-offload-bundler-asserts-on.c
@@ -1,6 +1,6 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: asserts
-// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, 
target={{.*}}-aix{{.*}}
 
 // Generate the file we can bundle.
 // RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.o
diff --git a/clang/test/Driver/clang-offload-bundler-standardize.c 
b/clang/test/Driver/clang-offload-bundler-standardize.c
index 6a24968c30efd6..91dc8947aabb9a 100644
--- a/clang/test/Driver/clang-offload-bundler-standardize.c
+++ b/clang/test/Driver/clang-offload-bundler-standardize.c
@@ -1,6 +1,6 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: asserts
-// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, 
target={{.*}}-aix{{.*}}
 // REQUIRES: asserts
 
 // Generate the file we can bundle.
diff --git a/clang/test/Driver/clang-offload-bundler.c 
b/clang/test/Driver/clang-offload-bundler.c
index f3cd2493e05277..a56a5424abf88d 100644
--- a/clang/test/Driver/clang-offload-bundler.c
+++ b/clang/test/Driver/clang-offload-bundler.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, 
target={{.*}}-aix{{.*}}
 
 //
 // Generate all the types of files we can bundle.
diff --git a/clang/test/Driver/fat-archive-unbundle-ext.c 
b/clang/test/Driver/fat-archive-unbundle-ext.c
index b409aa6313b1ea..e98b872f0c0c31 100644
--- a/clang/test/Driver/fat-archive-unbundle-ext.c
+++ b/clang/test/Driver/fat-archive-unbundle-ext.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// UNSUPPORTED: target={{.*-windows.*}}, target={{.*-darwin.*}}, 
target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*-windows.*}}, target={{.*}}-macosx{{.*}}, 
target={{.*-darwin.*}}, target={{.*}}-aix{{.*}}
 
 // Generate dummy fat object
 // RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.host.o

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


[clang] [clang][CodeGen] Allow memcpy replace with trivial auto var init (PR #84230)

2024-03-20 Thread via cfe-commits

serge-sans-paille wrote:

LGTM too. It's a bit sad that we couldn't make the optimization part of LLVM 
better instead of generating ad-hoc pattern, but as I couldn't find the time to 
work more on this, I'm not going to complain!

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


[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

2024-03-20 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

The code in question is comparing what Sema thinks the size of a variable 
should be, versus the size of the variable we're actually emitting into LLVM 
IR.  So try dumping the value of "Init".  If it looks wrong, we need to fix 
constant emission.  If it's right, probably something is going wrong in 
getFlexibleArrayInitChars().

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


[clang] [clang][CodeGen] Allow memcpy replace with trivial auto var init (PR #84230)

2024-03-20 Thread Eli Friedman via cfe-commits

https://github.com/efriedma-quic approved this pull request.

LGTM

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


[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)

2024-03-20 Thread via cfe-commits

isidorostsa wrote:

Currently, [HPX](https://github.com/STEllAR-GROUP/hpx) implements the P1144 
interface. We have our own implementation of the is_trivially_relocatable 
trait, but it cannot recursively figure out if a type is relocatable based on 
its components. It would be great for us to let the compiler handle that, as it 
would lead to optimizations for many more types.

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


[clang] [X86][Headers] Specify result of NaN comparisons (PR #85862)

2024-03-20 Thread Paul T Robinson via cfe-commits


@@ -513,7 +526,7 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS 
_mm_cmpge_pd(__m128d __a,
 ///operand are ordered with respect to those in the second operand.
 ///
 ///A pair of double-precision values are "ordered" with respect to each

pogo59 wrote:

Done

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


[clang] [CLANG] Full support of complex multiplication and division. (PR #81514)

2024-03-20 Thread Zahira Ammarguellat via cfe-commits

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


[clang] 7955bde - [C11] Add test coverage for N1310 and claim conformance

2024-03-20 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2024-03-20T15:08:43-04:00
New Revision: 7955bde64ef9aebbcaf6b6308a25fac31041ea9a

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

LOG: [C11] Add test coverage for N1310 and claim conformance

This is about the best I could do for testing that `signed char` does
not have any padding bits.

Added: 
clang/test/C/C11/n1310.c

Modified: 
clang/www/c_status.html

Removed: 




diff  --git a/clang/test/C/C11/n1310.c b/clang/test/C/C11/n1310.c
new file mode 100644
index 00..7f8dd754f74631
--- /dev/null
+++ b/clang/test/C/C11/n1310.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -verify -std=c89 %s
+// RUN: %clang_cc1 -verify -std=c99 %s
+// RUN: %clang_cc1 -verify -std=c11 %s
+// RUN: %clang_cc1 -verify -std=c17 %s
+// RUN: %clang_cc1 -verify -std=c23 %s
+// expected-no-diagnostics
+
+/* WG14 N1310: Yes
+ * Requiring signed char to have no padding bits
+ */
+
+/* This is shockingly hard to test, but we're trying our best by checking that
+ * setting each bit of an unsigned char, then bit-casting it to signed char,
+ * results in a value we expect to see. If we have padding bits, then it's
+ * possible (but not mandatory) for the value to not be as we expect, so a
+ * failing assertion means the implementation is broken but a passing test does
+ * not *prove* there aren't padding bits.
+ */
+_Static_assert(__CHAR_BIT__ == 8, "");
+_Static_assert(sizeof(signed char) == 1, "");
+
+#define TEST(Bit, Expected) __builtin_bit_cast(signed char, (unsigned char)(1 
<< Bit)) == Expected
+_Static_assert(TEST(0, 1), "");
+_Static_assert(TEST(1, 2), "");
+_Static_assert(TEST(2, 4), "");
+_Static_assert(TEST(3, 8), "");
+_Static_assert(TEST(4, 16), "");
+_Static_assert(TEST(5, 32), "");
+_Static_assert(TEST(6, 64), "");
+_Static_assert(TEST(7, (signed char)128), "");
+

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 9e4600b3e66acb..b1f5ab4cbc4f07 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -411,7 +411,7 @@ C11 implementation status
 
   Requiring signed char to have no padding bits
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1310.htm";>N1310
-  Unknown
+  Yes
 
 
   Initializing static or external variables



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


[clang] Disable driver tests on macosx that are currently disabled on darwin (PR #85990)

2024-03-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Akira Hatanaka (ahatanak)


Changes

macosx and darwin in triples are equivalent.

rdar://124246653

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


4 Files Affected:

- (modified) clang/test/Driver/clang-offload-bundler-asserts-on.c (+1-1) 
- (modified) clang/test/Driver/clang-offload-bundler-standardize.c (+1-1) 
- (modified) clang/test/Driver/clang-offload-bundler.c (+1-1) 
- (modified) clang/test/Driver/fat-archive-unbundle-ext.c (+1-1) 


``diff
diff --git a/clang/test/Driver/clang-offload-bundler-asserts-on.c 
b/clang/test/Driver/clang-offload-bundler-asserts-on.c
index 521c8641ff5468..eb11d5fbbee4a7 100644
--- a/clang/test/Driver/clang-offload-bundler-asserts-on.c
+++ b/clang/test/Driver/clang-offload-bundler-asserts-on.c
@@ -1,6 +1,6 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: asserts
-// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, 
target={{.*}}-aix{{.*}}
 
 // Generate the file we can bundle.
 // RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.o
diff --git a/clang/test/Driver/clang-offload-bundler-standardize.c 
b/clang/test/Driver/clang-offload-bundler-standardize.c
index 6a24968c30efd6..91dc8947aabb9a 100644
--- a/clang/test/Driver/clang-offload-bundler-standardize.c
+++ b/clang/test/Driver/clang-offload-bundler-standardize.c
@@ -1,6 +1,6 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: asserts
-// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, 
target={{.*}}-aix{{.*}}
 // REQUIRES: asserts
 
 // Generate the file we can bundle.
diff --git a/clang/test/Driver/clang-offload-bundler.c 
b/clang/test/Driver/clang-offload-bundler.c
index f3cd2493e05277..a56a5424abf88d 100644
--- a/clang/test/Driver/clang-offload-bundler.c
+++ b/clang/test/Driver/clang-offload-bundler.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, 
target={{.*}}-aix{{.*}}
 
 //
 // Generate all the types of files we can bundle.
diff --git a/clang/test/Driver/fat-archive-unbundle-ext.c 
b/clang/test/Driver/fat-archive-unbundle-ext.c
index b409aa6313b1ea..e98b872f0c0c31 100644
--- a/clang/test/Driver/fat-archive-unbundle-ext.c
+++ b/clang/test/Driver/fat-archive-unbundle-ext.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// UNSUPPORTED: target={{.*-windows.*}}, target={{.*-darwin.*}}, 
target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*-windows.*}}, target={{.*}}-macosx{{.*}}, 
target={{.*-darwin.*}}, target={{.*}}-aix{{.*}}
 
 // Generate dummy fat object
 // RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.host.o

``




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


[clang] Disable driver tests on macosx that are currently disabled on darwin (PR #85990)

2024-03-20 Thread Akira Hatanaka via cfe-commits

https://github.com/ahatanak created 
https://github.com/llvm/llvm-project/pull/85990

macosx and darwin in triples are equivalent.

rdar://124246653

>From 8a576b862aef20fd857ea4c9be8d1fdf7c0d8e4b Mon Sep 17 00:00:00 2001
From: Akira Hatanaka 
Date: Wed, 20 Mar 2024 11:57:03 -0700
Subject: [PATCH] Disable driver tests on macosx that are currently disabled on
 darwin

macosx and darwin in triples are equivalent.

rdar://124246653
---
 clang/test/Driver/clang-offload-bundler-asserts-on.c  | 2 +-
 clang/test/Driver/clang-offload-bundler-standardize.c | 2 +-
 clang/test/Driver/clang-offload-bundler.c | 2 +-
 clang/test/Driver/fat-archive-unbundle-ext.c  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/test/Driver/clang-offload-bundler-asserts-on.c 
b/clang/test/Driver/clang-offload-bundler-asserts-on.c
index 521c8641ff5468..eb11d5fbbee4a7 100644
--- a/clang/test/Driver/clang-offload-bundler-asserts-on.c
+++ b/clang/test/Driver/clang-offload-bundler-asserts-on.c
@@ -1,6 +1,6 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: asserts
-// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, 
target={{.*}}-aix{{.*}}
 
 // Generate the file we can bundle.
 // RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.o
diff --git a/clang/test/Driver/clang-offload-bundler-standardize.c 
b/clang/test/Driver/clang-offload-bundler-standardize.c
index 6a24968c30efd6..91dc8947aabb9a 100644
--- a/clang/test/Driver/clang-offload-bundler-standardize.c
+++ b/clang/test/Driver/clang-offload-bundler-standardize.c
@@ -1,6 +1,6 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: asserts
-// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, 
target={{.*}}-aix{{.*}}
 // REQUIRES: asserts
 
 // Generate the file we can bundle.
diff --git a/clang/test/Driver/clang-offload-bundler.c 
b/clang/test/Driver/clang-offload-bundler.c
index f3cd2493e05277..a56a5424abf88d 100644
--- a/clang/test/Driver/clang-offload-bundler.c
+++ b/clang/test/Driver/clang-offload-bundler.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// UNSUPPORTED: target={{.*}}-darwin{{.*}}, target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*}}-macosx{{.*}}, target={{.*}}-darwin{{.*}}, 
target={{.*}}-aix{{.*}}
 
 //
 // Generate all the types of files we can bundle.
diff --git a/clang/test/Driver/fat-archive-unbundle-ext.c 
b/clang/test/Driver/fat-archive-unbundle-ext.c
index b409aa6313b1ea..e98b872f0c0c31 100644
--- a/clang/test/Driver/fat-archive-unbundle-ext.c
+++ b/clang/test/Driver/fat-archive-unbundle-ext.c
@@ -1,5 +1,5 @@
 // REQUIRES: x86-registered-target
-// UNSUPPORTED: target={{.*-windows.*}}, target={{.*-darwin.*}}, 
target={{.*}}-aix{{.*}}
+// UNSUPPORTED: target={{.*-windows.*}}, target={{.*}}-macosx{{.*}}, 
target={{.*-darwin.*}}, target={{.*}}-aix{{.*}}
 
 // Generate dummy fat object
 // RUN: %clang -O0 -target %itanium_abi_triple %s -c -o %t.host.o

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


[clang] [llvm] [InstCombine] Canonicalize `(sitofp x)` -> `(uitofp x)` if `x >= 0` (PR #82404)

2024-03-20 Thread via cfe-commits

goldsteinn wrote:

> Well, I'm not sure how proper that wold be as a reproducer,
> 
> I extracted the mentioned test to a program:
> 
> ```
> #include 
> 
> #include "third_party/swiftshader/src/Reactor/Coroutine.hpp"
> #include "third_party/swiftshader/src/Reactor/Reactor.hpp"
> 
> using float4 = float[4];
> using int4 = int[4];
> 
> static std::string testName() { return "test name"; }
> 
> using namespace rr;
> 
> int main() {
>   Function, Pointer)> function;
>   {
> Pointer x = function.Arg<0>();
> Pointer y = function.Arg<1>();
> 
> *y = Abs(*x);
>   }
> 
>   auto routine = function(testName().c_str());
>   auto callable = (void (*)(int4 *, int4 *))routine->getEntry();
> 
>   int input[] = {1, -1, 0, (int)0x8000};
> 
>   for (int x : input) {
> int4 v_in = {x, x, x, x};
> int4 v_out = {0};
> 
> callable(&v_in, &v_out);
> 
> float expected = abs(x);
> if (v_out[0] != expected) {
>   return 10;
> }
>   }
> }
> ```
> 
> Before the change program exits with 0, after it exists with 10. More 
> precisely: `v_out[0]` is: -2147483648, `expected` is: 2.14748365e+09
> 
> [out_at.txt](https://github.com/llvm/llvm-project/files/14670227/out_at.txt) 
> [out_before.txt](https://github.com/llvm/llvm-project/files/14670228/out_before.txt)
> 
> I attached the generated IR before and after the change. It's only one line 
> diff:
> 
> ```
>call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 
> dereferenceable(16) %9, i8 0, i64 16, i1 false)
>call void %49(ptr noundef nonnull %8, ptr noundef nonnull %9) #16
>%61 = call i32 @llvm.abs.i32(i32 %60, i1 true)
> -  %62 = sitofp i32 %61 to float
> +  %62 = uitofp i32 %61 to float
>%63 = load i32, ptr %9, align 16
>%64 = sitofp i32 %63 to float
>%65 = fcmp une float %64, %62
> ```
> 
> generation command is `clang -O1 -fsized-deallocation '-std=gnu++20' -c 
> pre.ii -emit-llvm -S -o /tmp/ir_before.ll`
> 
> I'm trying to reduce the preprocessed file, tho not sure i'll keep the 
> semantics of the failure.

This should be sufficient, thank you!

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


  1   2   3   4   >