[clang] [llvm] [PowerPC] Add restriction for rldimi builtin (PR #85040)

2024-03-13 Thread Chen Zheng via cfe-commits


@@ -24,13 +24,17 @@ void test_trap(void) {
   __tw(ia, ib, 0); //expected-error {{argument value 0 is outside the valid 
range [1, 31]}}
 }
 
+#ifdef __PPC64__
 void test_builtin_ppc_rldimi() {
   unsigned int shift;
   unsigned long long mask;
   unsigned long long res = __builtin_ppc_rldimi(ull, ull, shift, 7); // 
expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
   res = __builtin_ppc_rldimi(ull, ull, 63, mask);// 
expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
   res = __builtin_ppc_rldimi(ull, ull, 63, 0x0F00);  // 
expected-error {{argument 3 value should represent a contiguous bit field}}
+  res = __builtin_ppc_rldimi(ull, ull, 63, 0x0F00);  // 
expected-error {{argument 3 value should represent a contiguous bit field}}

chenzheng1030 wrote:

Miss a case for shift value > 63?

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


[clang] [llvm] [PowerPC] Add restriction for rldimi builtin (PR #85040)

2024-03-13 Thread Chen Zheng via cfe-commits


@@ -5093,9 +5094,33 @@ bool Sema::CheckPPCBuiltinFunctionCall(const TargetInfo 
, unsigned BuiltinID,
   case PPC::BI__builtin_ppc_rlwnm:
 return SemaValueIsRunOfOnes(TheCall, 2);
   case PPC::BI__builtin_ppc_rlwimi:
-  case PPC::BI__builtin_ppc_rldimi:
 return SemaBuiltinConstantArg(TheCall, 2, Result) ||
SemaValueIsRunOfOnes(TheCall, 3);
+  case PPC::BI__builtin_ppc_rldimi: {
+llvm::APSInt SH;
+if (SemaBuiltinConstantArg(TheCall, 2, SH) ||
+SemaBuiltinConstantArg(TheCall, 3, Result))
+  return true;
+if (SH > 63)
+  return Diag(TheCall->getBeginLoc(), diag::err_argument_invalid_range)
+ << toString(Result, 10) << 0 << 63 << TheCall->getSourceRange();
+unsigned MB = 0, ML = 0;
+if (Result.isShiftedMask(MB, ML)) {
+  MB = 64 - MB - ML;
+} else if ((~Result).isShiftedMask(MB, ML)) {
+  MB = 64 - MB;
+  ML = 64 - ML;
+} else {
+  return Diag(TheCall->getBeginLoc(),
+  diag::err_argument_not_contiguous_bit_field)
+ << 3 << TheCall->getSourceRange();
+}
+if ((MB + ML - 1) % 64 != 63 - SH.getZExtValue())

chenzheng1030 wrote:

I am a little worried about this check. This adds more restriction on the 
__rldimi builtin than IBM XLC does. And what do you expect the mask looks like 
if the mask is wrapped? i.e., MB > 64 -SH.

How about we accept all continuous 1 masks, and in the backend while lowering 
the intrinsic if the mask matches the `rlwinm` instruction encoding 
requirement, we use only one rlwinm instructions. Otherwise we use two 
instructions, like:

```
__rldimi(a, b, SH, mask)
```
->
```
rldicl rx,a,SH,0
rldimib,rx,0,mask
```

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


[clang] [llvm] [PowerPC] Add restriction for rldimi builtin (PR #85040)

2024-03-13 Thread Chen Zheng via cfe-commits


@@ -24,13 +24,17 @@ void test_trap(void) {
   __tw(ia, ib, 0); //expected-error {{argument value 0 is outside the valid 
range [1, 31]}}
 }
 
+#ifdef __PPC64__
 void test_builtin_ppc_rldimi() {
   unsigned int shift;
   unsigned long long mask;
   unsigned long long res = __builtin_ppc_rldimi(ull, ull, shift, 7); // 
expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
   res = __builtin_ppc_rldimi(ull, ull, 63, mask);// 
expected-error {{argument to '__builtin_ppc_rldimi' must be a constant integer}}
   res = __builtin_ppc_rldimi(ull, ull, 63, 0x0F00);  // 
expected-error {{argument 3 value should represent a contiguous bit field}}
+  res = __builtin_ppc_rldimi(ull, ull, 63, 0x0F00);  // 
expected-error {{argument 3 value should represent a contiguous bit field}}

chenzheng1030 wrote:

This case seems same with above one?

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


[clang] [llvm] [PowerPC] Rename symbols references by tls-local-dynamic model on AIX (PR #84132)

2024-03-13 Thread Felix via cfe-commits

https://github.com/orcguru updated 
https://github.com/llvm/llvm-project/pull/84132

>From 92ab84000b638e206106bf5b1e9e2e842f5bcf2b Mon Sep 17 00:00:00 2001
From: Ting Wang 
Date: Wed, 6 Mar 2024 02:51:40 -0500
Subject: [PATCH 1/4] [PowerPC] Rename symbols references by tls-local-dynamic
 model

On AIX, rename those tls-local-dynamic referenced TOC symbols, so that in
following patches we can switch between different TLS models (local-dynamic
or initial-exec) for the same TLS GV in different functions within the same
module.
---
 .../CodeGen/TargetLoweringObjectFileImpl.h|   5 +-
 llvm/include/llvm/MC/MCContext.h  |   3 +-
 .../llvm/Target/TargetLoweringObjectFile.h|   6 +-
 .../CodeGen/TargetLoweringObjectFileImpl.cpp  |   8 +-
 llvm/lib/MC/MCContext.cpp |   5 +-
 llvm/lib/MC/MCSymbolXCOFF.cpp |   6 +-
 .../PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp  |  15 +-
 llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp |   6 +-
 .../test/CodeGen/PowerPC/aix-tls-gd-double.ll |  12 +-
 llvm/test/CodeGen/PowerPC/aix-tls-gd-int.ll   |  12 +-
 .../CodeGen/PowerPC/aix-tls-gd-longlong.ll|  24 +-
 .../PowerPC/aix-tls-ld-unqualified-symbols.ll | 362 ++
 .../CodeGen/PowerPC/aix-tls-local-dynamic.ll  |  39 +-
 13 files changed, 460 insertions(+), 43 deletions(-)
 create mode 100644 llvm/test/CodeGen/PowerPC/aix-tls-ld-unqualified-symbols.ll

diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h 
b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
index 8eef45ce565deb..1aa25e98423afa 100644
--- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -279,8 +279,9 @@ class TargetLoweringObjectFileXCOFF : public 
TargetLoweringObjectFile {
   MCSection *
   getSectionForFunctionDescriptor(const Function *F,
   const TargetMachine ) const override;
-  MCSection *getSectionForTOCEntry(const MCSymbol *Sym,
-   const TargetMachine ) const override;
+  MCSection *
+  getSectionForTOCEntry(const MCSymbol *Sym, const TargetMachine ,
+const MCSymbolRefExpr::VariantKind VK) const override;
 
   /// For external functions, this will always return a function descriptor
   /// csect.
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index 68d6f3e59d2d41..5e1473b7f78eb8 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -678,7 +678,8 @@ class MCContext {
   std::optional CsectProp = std::nullopt,
   bool MultiSymbolsAllowed = false, const char *BeginSymName = nullptr,
   std::optional DwarfSubtypeFlags =
-  std::nullopt);
+  std::nullopt,
+  StringRef RenamePrefix = StringRef());
 
   // Create and save a copy of STI and return a reference to the copy.
   MCSubtargetInfo (const MCSubtargetInfo );
diff --git a/llvm/include/llvm/Target/TargetLoweringObjectFile.h 
b/llvm/include/llvm/Target/TargetLoweringObjectFile.h
index 0c09cfe684783b..31a466a18d77a2 100644
--- a/llvm/include/llvm/Target/TargetLoweringObjectFile.h
+++ b/llvm/include/llvm/Target/TargetLoweringObjectFile.h
@@ -14,6 +14,7 @@
 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
 
+#include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/MC/MCRegister.h"
 #include 
@@ -256,8 +257,9 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
   /// On targets that support TOC entries, return a section for the entry given
   /// the symbol it refers to.
   /// TODO: Implement this interface for existing ELF targets.
-  virtual MCSection *getSectionForTOCEntry(const MCSymbol *S,
-   const TargetMachine ) const {
+  virtual MCSection *
+  getSectionForTOCEntry(const MCSymbol *S, const TargetMachine ,
+const MCSymbolRefExpr::VariantKind VK) const {
 return nullptr;
   }
 
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp 
b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 6943ce261d9d9c..ec17ceb9c83ece 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2679,7 +2679,8 @@ MCSection 
*TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
 }
 
 MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
-const MCSymbol *Sym, const TargetMachine ) const {
+const MCSymbol *Sym, const TargetMachine ,
+const MCSymbolRefExpr::VariantKind VK) const {
   // Use TE storage-mapping class when large code model is enabled so that
   // the chance of needing -bbigtoc is decreased. Also, the toc-entry for
   // EH info is never referenced directly using instructions so it can be
@@ -2694,7 +2695,10 @@ MCSection 
*TargetLoweringObjectFileXCOFF::getSectionForTOCEntry(
cast(Sym)->isEHInfo())
   

[clang] Rough first stab at addressing #85120 (PR #85147)

2024-03-13 Thread Doug Wyatt via cfe-commits

dougsonos wrote:

> @dougsonos I may have some time to look into this since there are probably 
> (as always) some annoying edge cases—particularly w/ templates. Would you be 
> fine with me committing to this branch or would it be easier for you if I 
> made a separate branch for that? Either is fine by me.

It might be simplest if you make your own branch, borrowing whatever from mine 
helps. Thanks.

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


[clang] [llvm] Adapted MemRegion::getDescriptiveName to handle ElementRegions (PR #85104)

2024-03-13 Thread via cfe-commits

T-Gruber wrote:

Hello @steakhal, I have just looked through the changes again. What is the 
advantage of using checkPreCall instead of checkLocation? I would very much 
appreciate some background information. Thanks for your help!

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


[clang] nolock/noalloc attributes (PR #84983)

2024-03-13 Thread Shafik Yaghmour via cfe-commits


@@ -4181,6 +4185,127 @@ class FunctionNoProtoType : public FunctionType, public 
llvm::FoldingSetNode {
   }
 };
 
+class FunctionEffect;
+class FunctionEffectSet;
+
+// It is the user's responsibility to keep this in set form: elements are
+// ordered and unique.
+// We could hide the mutating methods which are capable of breaking the
+// invariant, but they're needed and safe when used with STL set algorithms.
+class MutableFunctionEffectSet : public SmallVector 
{
+public:
+  using SmallVector::insert;
+  using SmallVector::SmallVector;
+
+  /// Maintains order/uniquenesss.
+  void insert(const FunctionEffect *effect);
+
+  MutableFunctionEffectSet |=(FunctionEffectSet rhs);
+};
+
+class FunctionEffectSet {
+public:
+  // These sets will tend to be very small (1 element), so represent them as
+  // sorted vectors, which are compatible with the STL set algorithms. Using an
+  // array or vector also means the elements are contiguous, keeping iterators
+  // simple.
+
+private:
+  // 'Uniqued' refers to the set itself being uniqued. Storage is allocated
+  // separately. Use ArrayRef for its iterators. Subclass so as to be able to
+  // compare (it seems ArrayRef would silently convert itself to a vector for
+  // comparison?!).
+  class UniquedAndSortedFX : public llvm::ArrayRef {
+  public:
+using Base = llvm::ArrayRef;
+
+UniquedAndSortedFX(Base Array) : Base(Array) {}
+UniquedAndSortedFX(const FunctionEffect **Ptr, size_t Len)
+: Base(Ptr, Len) {}
+
+bool operator<(const UniquedAndSortedFX ) const;
+  };
+
+  // Could have used a TinyPtrVector if it were unique-able.
+  // Empty set has a null Impl.
+  llvm::PointerUnion Impl;
+
+  explicit FunctionEffectSet(const FunctionEffect *Single) : Impl(Single) {}
+  explicit FunctionEffectSet(const UniquedAndSortedFX *Multi) : Impl(Multi) {}
+
+public:
+  using Differences =
+  SmallVector>;

shafik wrote:

This is consistent with 
[bugprone-argument-comment](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html)
 which we use. I don't think it catches this case but consistency is nice.

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


[clang] nolock/noalloc attributes (PR #84983)

2024-03-13 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Quick drive by comment

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


[clang] nolock/noalloc attributes (PR #84983)

2024-03-13 Thread Shafik Yaghmour via cfe-commits


@@ -4181,6 +4185,127 @@ class FunctionNoProtoType : public FunctionType, public 
llvm::FoldingSetNode {
   }
 };
 
+class FunctionEffect;
+class FunctionEffectSet;
+
+// It is the user's responsibility to keep this in set form: elements are
+// ordered and unique.
+// We could hide the mutating methods which are capable of breaking the
+// invariant, but they're needed and safe when used with STL set algorithms.
+class MutableFunctionEffectSet : public SmallVector 
{
+public:
+  using SmallVector::insert;
+  using SmallVector::SmallVector;
+
+  /// Maintains order/uniquenesss.
+  void insert(const FunctionEffect *effect);
+
+  MutableFunctionEffectSet |=(FunctionEffectSet rhs);
+};
+
+class FunctionEffectSet {
+public:
+  // These sets will tend to be very small (1 element), so represent them as
+  // sorted vectors, which are compatible with the STL set algorithms. Using an
+  // array or vector also means the elements are contiguous, keeping iterators
+  // simple.
+
+private:
+  // 'Uniqued' refers to the set itself being uniqued. Storage is allocated
+  // separately. Use ArrayRef for its iterators. Subclass so as to be able to
+  // compare (it seems ArrayRef would silently convert itself to a vector for
+  // comparison?!).
+  class UniquedAndSortedFX : public llvm::ArrayRef {
+  public:
+using Base = llvm::ArrayRef;
+
+UniquedAndSortedFX(Base Array) : Base(Array) {}
+UniquedAndSortedFX(const FunctionEffect **Ptr, size_t Len)
+: Base(Ptr, Len) {}
+
+bool operator<(const UniquedAndSortedFX ) const;
+  };
+
+  // Could have used a TinyPtrVector if it were unique-able.
+  // Empty set has a null Impl.
+  llvm::PointerUnion Impl;
+
+  explicit FunctionEffectSet(const FunctionEffect *Single) : Impl(Single) {}
+  explicit FunctionEffectSet(const UniquedAndSortedFX *Multi) : Impl(Multi) {}
+
+public:
+  using Differences =
+  SmallVector>;

shafik wrote:

```suggestion
  SmallVector>;
```

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


[clang] nolock/noalloc attributes (PR #84983)

2024-03-13 Thread Shafik Yaghmour via cfe-commits

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


[clang] [llvm] [HLSL] Add -HV option translation to clang-dxc.exe (PR #83938)

2024-03-13 Thread Joshua Batista via cfe-commits

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


[clang] 162180d - [HLSL] Add -HV option translation to clang-dxc.exe (#83938)

2024-03-13 Thread via cfe-commits

Author: Joshua Batista
Date: 2024-03-13T21:55:09-07:00
New Revision: 162180decf532acd31c9aa4b876804848d1761c0

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

LOG: [HLSL] Add -HV option translation to clang-dxc.exe (#83938)

Previously, clang-dxc.exe would not recognize -HV as a valid argument to
DXC, and would be unable to translate the argument to a legal clang
argument. This PR implements a translation of the HV option and its
value to the appropriate clang flag and the appropriate value. It adds a
test by using the -### option to spit out the translated options, and
checks to see that the correct option was generated.
Fixes #83479

-

Co-authored-by: Chris B 

Added: 
clang/test/Options/HV.hlsl

Modified: 
clang/include/clang/Basic/LangStandard.h
clang/include/clang/Driver/Options.td
clang/lib/Basic/LangStandards.cpp
clang/lib/Driver/ToolChains/HLSL.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index bc49669a82ad2d..199e24c6731603 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -139,6 +139,7 @@ struct LangStandard {
   bool isOpenCL() const { return Flags & OpenCL; }
 
   static Kind getLangKind(StringRef Name);
+  static Kind getHLSLLangKind(StringRef Name);
   static const LangStandard (Kind K);
   static const LangStandard *getLangStandardForName(StringRef Name);
 };

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1fac7b6f0093d8..a7e43b4d179a4d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -8578,6 +8578,11 @@ def dxc_entrypoint : Option<["--", "/", "-"], "E", 
KIND_JOINED_OR_SEPARATE>,
  Group,
  Visibility<[DXCOption]>,
  HelpText<"Entry point name">;
+def dxc_hlsl_version : Option<["/", "-"], "HV", KIND_JOINED_OR_SEPARATE>,
+ Group,
+ Visibility<[DXCOption]>,
+ HelpText<"HLSL Version">,
+ Values<"2016, 2017, 2018, 2021, 202x">;
 def dxc_validator_path_EQ : Joined<["--"], "dxv-path=">, Group,
   HelpText<"DXIL validator installation path">;
 def dxc_disable_validation : DXCFlag<"Vd">,

diff  --git a/clang/lib/Basic/LangStandards.cpp 
b/clang/lib/Basic/LangStandards.cpp
index ab09c7221dda92..cb2c0772349982 100644
--- a/clang/lib/Basic/LangStandards.cpp
+++ b/clang/lib/Basic/LangStandards.cpp
@@ -69,6 +69,16 @@ LangStandard::Kind LangStandard::getLangKind(StringRef Name) 
{
   .Default(lang_unspecified);
 }
 
+LangStandard::Kind LangStandard::getHLSLLangKind(StringRef Name) {
+  return llvm::StringSwitch(Name)
+  .Case("2016", LangStandard::lang_hlsl2016)
+  .Case("2017", LangStandard::lang_hlsl2017)
+  .Case("2018", LangStandard::lang_hlsl2018)
+  .Case("2021", LangStandard::lang_hlsl2021)
+  .Case("202x", LangStandard::lang_hlsl202x)
+  .Default(LangStandard::lang_unspecified);
+}
+
 const LangStandard *LangStandard::getLangStandardForName(StringRef Name) {
   Kind K = getLangKind(Name);
   if (K == lang_unspecified)

diff  --git a/clang/lib/Driver/ToolChains/HLSL.cpp 
b/clang/lib/Driver/ToolChains/HLSL.cpp
index c6ad862b229420..05aac9caa7fb29 100644
--- a/clang/lib/Driver/ToolChains/HLSL.cpp
+++ b/clang/lib/Driver/ToolChains/HLSL.cpp
@@ -226,6 +226,21 @@ HLSLToolChain::TranslateArgs(const DerivedArgList , 
StringRef BoundArch,
   A->claim();
   continue;
 }
+if (A->getOption().getID() == options::OPT_dxc_hlsl_version) {
+  // Translate -HV into -std for llvm
+  // depending on the value given
+  LangStandard::Kind LangStd = 
LangStandard::getHLSLLangKind(A->getValue());
+  if (LangStd != LangStandard::lang_unspecified) {
+LangStandard l = LangStandard::getLangStandardForKind(LangStd);
+DAL->AddSeparateArg(nullptr, Opts.getOption(options::OPT_std_EQ),
+l.getName());
+  } else {
+getDriver().Diag(diag::err_drv_invalid_value) << "HV" << A->getValue();
+  }
+
+  A->claim();
+  continue;
+}
 DAL->append(A);
   }
 

diff  --git a/clang/test/Options/HV.hlsl b/clang/test/Options/HV.hlsl
new file mode 100644
index 00..9f7e1ebc02f251
--- /dev/null
+++ b/clang/test/Options/HV.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_dxc -T lib_6_4 -HV 2016 %s 2>&1 -###   | FileCheck 
-check-prefix=2016 %s
+// RUN: %clang_dxc -T lib_6_4 -HV 2017 %s 2>&1 -###   | FileCheck 
-check-prefix=2017 %s
+// RUN: %clang_dxc -T lib_6_4 /HV 2018 %s 2>&1 -###   | FileCheck 
-check-prefix=2018 %s
+// RUN: %clang_dxc -T lib_6_4 /HV 2021 %s 2>&1 -###   | FileCheck 
-check-prefix=2021 

[clang] [clang-format][NFC] Eliminate the IsCpp parameter in all functions (PR #84599)

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

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

>From 43238d58ff490073c13ff621faddceb89b05b22e Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 8 Mar 2024 19:47:54 -0800
Subject: [PATCH 1/2] [clang-format][NFC] Eliminate the IsCpp parameter in all
 functions

---
 clang/include/clang/Format/Format.h  |  3 ++
 clang/lib/Format/ContinuationIndenter.cpp| 12 +++--
 clang/lib/Format/Format.cpp  |  2 +
 clang/lib/Format/FormatToken.cpp |  6 +--
 clang/lib/Format/FormatToken.h   |  6 +--
 clang/lib/Format/FormatTokenLexer.cpp|  5 +-
 clang/lib/Format/QualifierAlignmentFixer.cpp | 29 ++--
 clang/lib/Format/QualifierAlignmentFixer.h   |  5 +-
 clang/lib/Format/TokenAnnotator.cpp  | 48 ++--
 clang/lib/Format/TokenAnnotator.h|  6 +--
 clang/lib/Format/UnwrappedLineParser.cpp | 22 +
 clang/lib/Format/UnwrappedLineParser.h   |  1 -
 12 files changed, 74 insertions(+), 71 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 590297fd89a398..a72c1b171c3e18 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5228,6 +5228,9 @@ extern const char *DefaultFormatStyle;
 /// Different builds can modify the value to the preferred styles.
 extern const char *DefaultFallbackStyle;
 
+/// Whether the language is C/C++/Objective-C/Objective-C++.
+extern bool IsCpp;
+
 /// Construct a FormatStyle based on ``StyleName``.
 ///
 /// ``StyleName`` can take several forms:
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index df44e6994c4784..506e21725ba9f7 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -241,7 +241,9 @@ ContinuationIndenter::ContinuationIndenter(const 
FormatStyle ,
 : Style(Style), Keywords(Keywords), SourceMgr(SourceMgr),
   Whitespaces(Whitespaces), Encoding(Encoding),
   BinPackInconclusiveFunctions(BinPackInconclusiveFunctions),
-  CommentPragmasRegex(Style.CommentPragmas), RawStringFormats(Style) {}
+  CommentPragmasRegex(Style.CommentPragmas), RawStringFormats(Style) {
+  IsCpp = Style.isCpp();
+}
 
 LineState ContinuationIndenter::getInitialState(unsigned FirstIndent,
 unsigned FirstStartColumn,
@@ -406,7 +408,7 @@ bool ContinuationIndenter::mustBreak(const LineState 
) {
   }
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
(Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
-State.Line->First->isNot(TT_AttributeSquare) && Style.isCpp() &&
+State.Line->First->isNot(TT_AttributeSquare) && IsCpp &&
 // FIXME: This is a temporary workaround for the case where 
clang-format
 // sets BreakBeforeParameter to avoid bin packing and this creates a
 // completely unnecessary line break after a template type that isn't
@@ -677,8 +679,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   auto  = State.Stack.back();
 
   bool DisallowLineBreaksOnThisLine =
-  Style.LambdaBodyIndentation == FormatStyle::LBI_Signature &&
-  Style.isCpp() && [] {
+  Style.LambdaBodyIndentation == FormatStyle::LBI_Signature && IsCpp &&
+  [] {
 // Deal with lambda arguments in C++. The aim here is to ensure that we
 // don't over-indent lambda function bodies when lambdas are passed as
 // arguments to function calls. We do this by ensuring that either all
@@ -1091,7 +1093,7 @@ unsigned 
ContinuationIndenter::addTokenOnNewLine(LineState ,
   // Any break on this level means that the parent level has been broken
   // and we need to avoid bin packing there.
   bool NestedBlockSpecialCase =
-  (!Style.isCpp() && Current.is(tok::r_brace) && State.Stack.size() > 1 &&
+  (!IsCpp && Current.is(tok::r_brace) && State.Stack.size() > 1 &&
State.Stack[State.Stack.size() - 2].NestedBlockInlined) ||
   (Style.Language == FormatStyle::LK_ObjC && Current.is(tok::r_brace) &&
State.Stack.size() > 1 && !Style.ObjCBreakBeforeNestedBlockParam);
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index e64ba7eebc1ce8..00182f75560a2c 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3943,6 +3943,8 @@ const char *DefaultFormatStyle = "file";
 
 const char *DefaultFallbackStyle = "LLVM";
 
+bool IsCpp = false;
+
 llvm::ErrorOr>
 loadAndParseConfigFile(StringRef ConfigFile, llvm::vfs::FileSystem *FS,
FormatStyle *Style, bool AllowUnknownOptions) {
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index 4fb70ffac706d0..665b2e43259b21 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -78,15 +78,15 @@ static SmallVector 

[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-13 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 437fcc6eed99694a9f9486d29ead6a3d3275ede9 
a74a9bbd2ff2c6589db4c9756cf809c22e98fa64 -- 
clang/lib/Driver/ToolChains/Arch/Mips.cpp clang/test/Driver/mips-features.c 
llvm/lib/Target/Mips/MipsISelLowering.cpp 
llvm/lib/Target/Mips/MipsSEISelLowering.cpp 
llvm/lib/Target/Mips/MipsSubtarget.cpp llvm/lib/Target/Mips/MipsSubtarget.h
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsISelLowering.cpp
index 0a0d40751f..e089eb79e1 100644
--- a/llvm/lib/Target/Mips/MipsISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp
@@ -366,11 +366,11 @@ MipsTargetLowering::MipsTargetLowering(const 
MipsTargetMachine ,
 setOperationAction(ISD::ConstantPool,   MVT::i64,   Custom);
 setOperationAction(ISD::SELECT, MVT::i64,   Custom);
 if (Subtarget.hasMips64r6()) {
-  setOperationAction(ISD::LOAD,   MVT::i64,   Legal);
-  setOperationAction(ISD::STORE,  MVT::i64,   Legal);
+  setOperationAction(ISD::LOAD, MVT::i64, Legal);
+  setOperationAction(ISD::STORE, MVT::i64, Legal);
 } else {
-  setOperationAction(ISD::LOAD,   MVT::i64,   Custom);
-  setOperationAction(ISD::STORE,  MVT::i64,   Custom);
+  setOperationAction(ISD::LOAD, MVT::i64, Custom);
+  setOperationAction(ISD::STORE, MVT::i64, Custom);
 }
 setOperationAction(ISD::FP_TO_SINT, MVT::i64,   Custom);
 setOperationAction(ISD::SHL_PARTS,  MVT::i64,   Custom);
diff --git a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp 
b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
index 5c8d64e3b6..ebaf0746d6 100644
--- a/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelLowering.cpp
@@ -198,11 +198,11 @@ MipsSETargetLowering::MipsSETargetLowering(const 
MipsTargetMachine ,
   setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
   setOperationAction(ISD::ATOMIC_FENCE,   MVT::Other, Custom);
   if (Subtarget.hasMips32r6()) {
-setOperationAction(ISD::LOAD,   MVT::i32, Legal);
-setOperationAction(ISD::STORE,  MVT::i32, Legal);
+setOperationAction(ISD::LOAD, MVT::i32, Legal);
+setOperationAction(ISD::STORE, MVT::i32, Legal);
   } else {
-setOperationAction(ISD::LOAD,   MVT::i32, Custom);
-setOperationAction(ISD::STORE,  MVT::i32, Custom);
+setOperationAction(ISD::LOAD, MVT::i32, Custom);
+setOperationAction(ISD::STORE, MVT::i32, Custom);
   }
 
   setTargetDAGCombine(ISD::MUL);
diff --git a/llvm/lib/Target/Mips/MipsSubtarget.cpp 
b/llvm/lib/Target/Mips/MipsSubtarget.cpp
index 29b277f5f3..3c67d156a6 100644
--- a/llvm/lib/Target/Mips/MipsSubtarget.cpp
+++ b/llvm/lib/Target/Mips/MipsSubtarget.cpp
@@ -79,11 +79,11 @@ MipsSubtarget::MipsSubtarget(const Triple , StringRef 
CPU, StringRef FS,
   HasMips3_32(false), HasMips3_32r2(false), HasMips4_32(false),
   HasMips4_32r2(false), HasMips5_32r2(false), InMips16Mode(false),
   InMips16HardFloat(Mips16HardFloat), InMicroMipsMode(false), 
HasDSP(false),
-  HasDSPR2(false), HasDSPR3(false), AllowMixed16_32(Mixed16_32 || 
Mips_Os16),
-  Os16(Mips_Os16), HasMSA(false), UseTCCInDIV(false), HasSym32(false),
-  HasEVA(false), DisableMadd4(false), HasMT(false), HasCRC(false),
-  HasVirt(false), HasGINV(false), UseIndirectJumpsHazard(false),
-  NoUnalignedAccess(false),
+  HasDSPR2(false), HasDSPR3(false),
+  AllowMixed16_32(Mixed16_32 || Mips_Os16), Os16(Mips_Os16), HasMSA(false),
+  UseTCCInDIV(false), HasSym32(false), HasEVA(false), DisableMadd4(false),
+  HasMT(false), HasCRC(false), HasVirt(false), HasGINV(false),
+  UseIndirectJumpsHazard(false), NoUnalignedAccess(false),
   StackAlignOverride(StackAlignOverride), TM(TM), TargetTriple(TT),
   TSInfo(), InstrInfo(MipsInstrInfo::create(
 initializeSubtargetDependencies(CPU, FS, TM))),

``




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


[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: YunQiang Su (wzssyqa)


Changes

MIPSr6 ISA requires normal load/store instructions support misunaligned memory 
access, while it is not always do so by hardware. On some microarchitectures or 
some corner cases it may need support by OS.

Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't support them, 
instead, r6 requires lw instruction support misunaligned memory access. So, if 
-mno-unaligned-access is used for pre-R6, lwl/lwr won't be disabled.

If -mno-unaligned-access is used for r6 and the access is not well aligned, 
some lb/lh instructions will be used to replace lw. This is useful for OS 
kernels.

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


10 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+2-2) 
- (modified) clang/lib/Driver/ToolChains/Arch/Mips.cpp (+2) 
- (modified) clang/test/Driver/mips-features.c (+26) 
- (modified) llvm/lib/Target/Mips/Mips.td (+4) 
- (modified) llvm/lib/Target/Mips/MipsISelLowering.cpp (+13-3) 
- (modified) llvm/lib/Target/Mips/MipsSEISelLowering.cpp (+9-2) 
- (modified) llvm/lib/Target/Mips/MipsSubtarget.cpp (+1) 
- (modified) llvm/lib/Target/Mips/MipsSubtarget.h (+6-1) 
- (modified) llvm/test/CodeGen/Mips/msa/f16-llvm-ir.ll (+6-4) 
- (added) llvm/test/CodeGen/Mips/no-unaligned-access-r6.ll (+69) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1fac7b6f0093d8..6d3645f0a66828 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4696,9 +4696,9 @@ def mrvv_vector_bits_EQ : Joined<["-"], 
"mrvv-vector-bits=">, Group,
 " (RISC-V only)")>;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
-  HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
+  HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/MIPS/RISC-V only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group,
-  HelpText<"Force all memory accesses to be aligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
+  HelpText<"Force all memory accesses to be aligned 
(AArch32/AArch64/LoongArch/MIPS/RISC-V only)">;
 def munaligned_symbols : Flag<["-"], "munaligned-symbols">, Group,
   HelpText<"Expect external char-aligned symbols to be without ABI alignment 
(SystemZ only)">;
 def mno_unaligned_symbols : Flag<["-"], "mno-unaligned-symbols">, 
Group,
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index fe9d112b8800b1..1de11811dccbc1 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -341,6 +341,8 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
"dspr2");
   AddTargetFeature(Args, Features, options::OPT_mmsa, options::OPT_mno_msa,
"msa");
+  AddTargetFeature(Args, Features, options::OPT_mno_unaligned_access,
+   options::OPT_munaligned_access, "no-unaligned-access");
 
   // Add the last -mfp32/-mfpxx/-mfp64, if none are given and the ABI is O32
   // pass -mfpxx, or if none are given and fp64a is default, pass fp64 and
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fd06b1400c3123..9e724b34e869d4 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -462,3 +462,29 @@
 // RUN: -mrelax-pic-calls -mno-relax-pic-calls 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-RELAX-PIC-CALLS %s
 // CHECK-NO-RELAX-PIC-CALLS: "-mllvm" "-mips-jalr-reloc=0"
+//
+// -mno-unaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mno-unaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// CHECK-NO-UNALIGNED-ACCESS: "-target-feature" "+no-unaligned-access"
+//
+// -munaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-unaligned-access -mstrict-align \
+// RUN: -munaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s
+// CHECK-UNALIGNED-ACCESS: "-target-feature" "-no-unaligned-access"
+//
+// -mstrict-align
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mstrict-align 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+//
+// -mno-strict-align
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-unaligned-access -mstrict-align \
+// RUN: -mno-strict-align 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-UNALIGNED-ACCESS %s
diff --git a/llvm/lib/Target/Mips/Mips.td b/llvm/lib/Target/Mips/Mips.td
index dbff25dfa0f36c..e768394dbc8192 100644
--- a/llvm/lib/Target/Mips/Mips.td
+++ b/llvm/lib/Target/Mips/Mips.td
@@ -208,6 +208,10 

[clang] [llvm] MIPS: Support -m(no-)unaligned-access for r6 (PR #85174)

2024-03-13 Thread YunQiang Su via cfe-commits

https://github.com/wzssyqa created 
https://github.com/llvm/llvm-project/pull/85174

MIPSr6 ISA requires normal load/store instructions support misunaligned memory 
access, while it is not always do so by hardware. On some microarchitectures or 
some corner cases it may need support by OS.

Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't support them, 
instead, r6 requires lw instruction support misunaligned memory access. So, if 
-mno-unaligned-access is used for pre-R6, lwl/lwr won't be disabled.

If -mno-unaligned-access is used for r6 and the access is not well aligned, 
some lb/lh instructions will be used to replace lw. This is useful for OS 
kernels.

>From a74a9bbd2ff2c6589db4c9756cf809c22e98fa64 Mon Sep 17 00:00:00 2001
From: YunQiang Su 
Date: Thu, 14 Mar 2024 11:48:36 +0800
Subject: [PATCH] MIPS: Support -m(no-)unaligned-access for r6

MIPSr6 ISA requires normal load/store instructions support
misunaligned memory access, while it is not always do so
by hardware. On some microarchitectures or some corner cases
it may need support by OS.

Don't confuse with pre-R6's lwl/lwr famlily: MIPSr6 doesn't
support them, instead, r6 requires lw instruction support
misunaligned memory access. So, if -mno-unaligned-access is
used for pre-R6, lwl/lwr won't be disabled.

If -mno-unaligned-access is used for r6 and the access is
not well aligned, some lb/lh instructions will be used to replace
lw. This is useful for OS kernels.
---
 clang/include/clang/Driver/Options.td |  4 +-
 clang/lib/Driver/ToolChains/Arch/Mips.cpp |  2 +
 clang/test/Driver/mips-features.c | 26 +++
 llvm/lib/Target/Mips/Mips.td  |  4 ++
 llvm/lib/Target/Mips/MipsISelLowering.cpp | 16 -
 llvm/lib/Target/Mips/MipsSEISelLowering.cpp   | 11 ++-
 llvm/lib/Target/Mips/MipsSubtarget.cpp|  1 +
 llvm/lib/Target/Mips/MipsSubtarget.h  |  7 +-
 llvm/test/CodeGen/Mips/msa/f16-llvm-ir.ll | 10 +--
 .../CodeGen/Mips/no-unaligned-access-r6.ll| 69 +++
 10 files changed, 138 insertions(+), 12 deletions(-)
 create mode 100644 llvm/test/CodeGen/Mips/no-unaligned-access-r6.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 1fac7b6f0093d8..6d3645f0a66828 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4696,9 +4696,9 @@ def mrvv_vector_bits_EQ : Joined<["-"], 
"mrvv-vector-bits=">, Group,
 " (RISC-V only)")>;
 
 def munaligned_access : Flag<["-"], "munaligned-access">, Group,
-  HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
+  HelpText<"Allow memory accesses to be unaligned 
(AArch32/AArch64/LoongArch/MIPS/RISC-V only)">;
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group,
-  HelpText<"Force all memory accesses to be aligned 
(AArch32/AArch64/LoongArch/RISC-V only)">;
+  HelpText<"Force all memory accesses to be aligned 
(AArch32/AArch64/LoongArch/MIPS/RISC-V only)">;
 def munaligned_symbols : Flag<["-"], "munaligned-symbols">, Group,
   HelpText<"Expect external char-aligned symbols to be without ABI alignment 
(SystemZ only)">;
 def mno_unaligned_symbols : Flag<["-"], "mno-unaligned-symbols">, 
Group,
diff --git a/clang/lib/Driver/ToolChains/Arch/Mips.cpp 
b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
index fe9d112b8800b1..1de11811dccbc1 100644
--- a/clang/lib/Driver/ToolChains/Arch/Mips.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -341,6 +341,8 @@ void mips::getMIPSTargetFeatures(const Driver , const 
llvm::Triple ,
"dspr2");
   AddTargetFeature(Args, Features, options::OPT_mmsa, options::OPT_mno_msa,
"msa");
+  AddTargetFeature(Args, Features, options::OPT_mno_unaligned_access,
+   options::OPT_munaligned_access, "no-unaligned-access");
 
   // Add the last -mfp32/-mfpxx/-mfp64, if none are given and the ABI is O32
   // pass -mfpxx, or if none are given and fp64a is default, pass fp64 and
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fd06b1400c3123..9e724b34e869d4 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -462,3 +462,29 @@
 // RUN: -mrelax-pic-calls -mno-relax-pic-calls 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-RELAX-PIC-CALLS %s
 // CHECK-NO-RELAX-PIC-CALLS: "-mllvm" "-mips-jalr-reloc=0"
+//
+// -mno-unaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -munaligned-access -mno-strict-align \
+// RUN: -mno-unaligned-access 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// CHECK-NO-UNALIGNED-ACCESS: "-target-feature" "+no-unaligned-access"
+//
+// -munaligned-access
+// RUN: %clang -target mips-unknown-linux-gnu -### -c %s \
+// RUN: -mno-unaligned-access -mstrict-align \
+// RUN: -munaligned-access 2>&1 \
+// RUN:   | FileCheck 

[clang] [DRAFT][RISCV] Emit arch string macro to facilitate ASM programming (PR #85063)

2024-03-13 Thread Jessica Clarke via cfe-commits

jrtc27 wrote:

Attributes are added automatically, unless you override it with your own 
.attribute arch.

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


[clang] [clang] Define SwiftInfo for RISCVTargetCodeGenInfo (PR #82152)

2024-03-13 Thread Jessica Clarke via cfe-commits

jrtc27 wrote:

What purpose does this serve if swiftcall doesn't work? Given the tests only 
test that you can produce IR from Clang, that suggests that it doesn't actually 
do anything useful?.. (And if it does do something useful, *that* should be 
being tested)

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


[clang] [DRAFT][RISCV] Emit arch string macro to facilitate ASM programming (PR #85063)

2024-03-13 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

I think we will add attributes automatically?
```shell
~/workspace# cat a.S
.globl  foo 
.p2align1
.type   foo,@function
foo:
   ret
~/workspace# clang -march=rv64gcv -c a.S
~/workspace# llvm-readobj -A a.o
File: a.o
Format: elf64-littleriscv
Arch: riscv64
AddressSize: 64bit
LoadName: 
BuildAttributes {
  FormatVersion: 0x41
  Section 1 {
SectionLength: 157
Vendor: riscv
Tag: Tag_File (0x1)
Size: 147
FileAttributes {
  Attribute {
Tag: 5
TagName: arch
Value: 
rv64i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_v1p0_zicsr2p0_zifencei2p0_zve32f1p0_zve32x1p0_zve64d1p0_zve64f1p0_zve64x1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0

  }
}
  }
}
```

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


[clang] [clang] Define SwiftInfo for RISCVTargetCodeGenInfo (PR #82152)

2024-03-13 Thread Kuba Mracek via cfe-commits

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


[clang] b84ce99 - [clang] Define SwiftInfo for RISCVTargetCodeGenInfo (#82152)

2024-03-13 Thread via cfe-commits

Author: Kuba (Brecka) Mracek
Date: 2024-03-13T20:04:30-07:00
New Revision: b84ce9979990283aa4398ad5a654b8b283baa532

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

LOG: [clang] Define SwiftInfo for RISCVTargetCodeGenInfo (#82152)

For Embedded Swift, let's unblock building for RISC-V boards (e.g.
ESP32-C6). This isn't trying to add full RISC-V support to Swift /
Embedded Swift, it's just fixing the immediate blocker (not having
SwiftInfo defined blocks all compilations).

Added: 


Modified: 
clang/lib/CodeGen/Targets/RISCV.cpp
clang/test/CodeGenCXX/arm-swiftcall.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/RISCV.cpp 
b/clang/lib/CodeGen/Targets/RISCV.cpp
index dec6540230a60f..9a79424c4612ce 100644
--- a/clang/lib/CodeGen/Targets/RISCV.cpp
+++ b/clang/lib/CodeGen/Targets/RISCV.cpp
@@ -529,7 +529,10 @@ class RISCVTargetCodeGenInfo : public TargetCodeGenInfo {
   RISCVTargetCodeGenInfo(CodeGen::CodeGenTypes , unsigned XLen,
  unsigned FLen, bool EABI)
   : TargetCodeGenInfo(
-std::make_unique(CGT, XLen, FLen, EABI)) {}
+std::make_unique(CGT, XLen, FLen, EABI)) {
+SwiftInfo =
+std::make_unique(CGT, /*SwiftErrorInRegister=*/false);
+  }
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule ) const override {

diff  --git a/clang/test/CodeGenCXX/arm-swiftcall.cpp 
b/clang/test/CodeGenCXX/arm-swiftcall.cpp
index e60c1482700a4b..45eea7bfd853b9 100644
--- a/clang/test/CodeGenCXX/arm-swiftcall.cpp
+++ b/clang/test/CodeGenCXX/arm-swiftcall.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -triple armv7-apple-darwin9 -emit-llvm -o - %s 
-Wno-return-type-c-linkage -std=c++03 | FileCheck %s -check-prefixes=CHECK
 
+// For now just check that the RISC-V triples are accepted, but don't check 
the IR, as swiftcall is not yet supported.
+// RUN: %clang_cc1 -triple riscv32-unknown-linux-gnu -emit-llvm -o - %s 
-Wno-return-type-c-linkage -std=c++03
+// RUN: %clang_cc1 -triple riscv64-unknown-linux-gnu -emit-llvm -o - %s 
-Wno-return-type-c-linkage -std=c++03
+
 // This isn't really testing anything ARM-specific; it's just a convenient
 // 32-bit platform.
 



___
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-13 Thread Kees Cook via cfe-commits


@@ -1,13 +1,58 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only
 // RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
 // RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=microsoft -fsyntax-only -fms-compatibility 
-Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */

kees wrote:

Ah-ha! I think I see what you mean now. I will work on constructing some 
negative tests cases.

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

2024-03-13 Thread Brandon Wu via cfe-commits


@@ -854,6 +895,30 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
  "string must be lowercase");
   }
 
+  bool IsProfile = Arch.starts_with("rvi") || Arch.starts_with("rva") ||
+   Arch.starts_with("rvb") || Arch.starts_with("rvm");
+  std::string NewArch;

4vtomat wrote:

`NewArch` might be assigned twice, I'm wondering whether we can pre-reserve a 
chunk of memory beforehand to prevent 1 more memory allocation?

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


[clang] [clang-tools-extra] [concepts] Preserve the FoundDecl of ConceptReference properly (PR #85032)

2024-03-13 Thread Younan Zhang via cfe-commits

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


[clang-tools-extra] c1c8a0c - [concepts] Preserve the FoundDecl of ConceptReference properly (#85032)

2024-03-13 Thread via cfe-commits

Author: Younan Zhang
Date: 2024-03-14T10:09:47+08:00
New Revision: c1c8a0cb17468bcece489adea2b31df6920c96cb

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

LOG: [concepts] Preserve the FoundDecl of ConceptReference properly (#85032)

The `ConceptReference`'s `FoundDecl` claims it "can differ from
`NamedConcept` when, for example, the concept was found through a
`UsingShadowDecl`", but such the contract was not previously respected.

Fixes https://github.com/llvm/llvm-project/issues/82628

Added: 


Modified: 
clang-tools-extra/clangd/unittests/SelectionTests.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaType.cpp
clang/test/AST/ast-dump-concepts.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp 
b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
index 754e8c287c5148..db516a1f62a357 100644
--- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp
@@ -10,6 +10,7 @@
 #include "SourceCode.h"
 #include "TestTU.h"
 #include "support/TestTracer.h"
+#include "clang/AST/ASTConcept.h"
 #include "clang/AST/Decl.h"
 #include "llvm/Support/Casting.h"
 #include "gmock/gmock.h"
@@ -893,6 +894,33 @@ TEST(SelectionTest, DeclContextLambda) {
   EXPECT_TRUE(ST.commonAncestor()->getDeclContext().isFunctionOrMethod());
 }
 
+TEST(SelectionTest, UsingConcepts) {
+  llvm::Annotations Test(R"cpp(
+namespace ns {
+template 
+concept Foo = true;
+}
+
+using ns::Foo;
+
+template 
+auto Func(Fo^o auto V) -> Fo^o decltype(auto) {
+  Fo^o auto W = V;
+  return W;
+}
+)cpp");
+  auto TU = TestTU::withCode(Test.code());
+  TU.ExtraArgs.emplace_back("-std=c++2c");
+  auto AST = TU.build();
+  for (auto Point : Test.points()) {
+auto ST = SelectionTree::createRight(AST.getASTContext(), AST.getTokens(),
+ Point, Point);
+auto *C = ST.commonAncestor()->ASTNode.get();
+EXPECT_TRUE(C && C->getFoundDecl() &&
+C->getFoundDecl()->getKind() == Decl::UsingShadow);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang

diff  --git a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
index 5dc88157e13af0..dac3f39e1a6584 100644
--- a/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -548,9 +548,7 @@ TEST(WalkAST, Concepts) {
   testWalk(Concept, "template requires ^Foo void func() {}");
   testWalk(Concept, "template void func() requires ^Foo {}");
   testWalk(Concept, "void func(^Foo auto x) {}");
-  // FIXME: Foo should be explicitly referenced.
-  testWalk("template concept Foo = true;",
-   "void func() { ^Foo auto x = 1; }");
+  testWalk(Concept, "void func() { ^Foo auto x = 1; }");
 }
 
 TEST(WalkAST, FriendDecl) {

diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5fe3fd066df235..0a963d121fd354 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -379,6 +379,7 @@ Bug Fixes to C++ Support
 
 Bug Fixes to AST Handling
 ^
+- Clang now properly preserves ``FoundDecls`` within a ``ConceptReference``. 
(#GH82628)
 
 Miscellaneous Bug Fixes
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4a853119a2bb8f..69d5709e5e2f06 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9215,7 +9215,7 @@ class Sema final {
 
   bool AttachTypeConstraint(NestedNameSpecifierLoc NS,
 DeclarationNameInfo NameInfo,
-ConceptDecl *NamedConcept,
+ConceptDecl *NamedConcept, NamedDecl *FoundDecl,
 const TemplateArgumentListInfo *TemplateArgs,
 TemplateTypeParmDecl *ConstrainedParameter,
 SourceLocation EllipsisLoc);

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1f4a041e88dfff..5850cd0ab6b9aa 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1192,9 +1192,13 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, 
CXXScopeSpec ,
 return ParsedType::make(T);
   }
 
-  if (isa(FirstDecl))
+  if (isa(FirstDecl)) {
+// We want to preserve the UsingShadowDecl for concepts.
+if (auto *USD = dyn_cast(Result.getRepresentativeDecl()))
+  return 

[clang] [clang-tools-extra] [concepts] Preserve the FoundDecl of ConceptReference properly (PR #85032)

2024-03-13 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

CI failure was an unrelated format issue.

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


[clang] [clang][Sema] Skip the RequiresExprBodyDecls for lambda dependencies (PR #83997)

2024-03-13 Thread Younan Zhang via cfe-commits

zyn0217 wrote:

> I have a reduced test case, which is accepted by clang 18, but fails with 
> this patch: https://gcc.godbolt.org/z/zMbKvsf7K
> A bit more compact one: https://gcc.godbolt.org/z/4rzYPKaze

Your case is rejected by all mainstream compilers as of now: 
https://gcc.godbolt.org/z/nrMf3zvfY
Again, it was an accept-invalid before because of the constant evaluation on 
dependent expressions, which **is** an assertion failure if you compile it with 
debug mode. https://gcc.godbolt.org/z/eascd7j1G

To clarify why the requirement should be evaluated to false:

> The enclosing _requires-expression_ will evaluate to false if substitution of 
> template arguments into the expression fails.

https://eel.is/c++draft/expr.prim.req#simple-1.sentence-2


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


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

2024-03-13 Thread Brandon Wu via cfe-commits


@@ -854,6 +895,30 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool 
EnableExperimentalExtension,
  "string must be lowercase");
   }
 
+  bool IsProfile = Arch.starts_with("rvi") || Arch.starts_with("rva") ||
+   Arch.starts_with("rvb") || Arch.starts_with("rvm");
+  std::string NewArch;
+  if (IsProfile) {
+const auto *FoundProfile =
+llvm::find_if(SupportedProfiles, [&](const RISCVProfile ) {
+  return Arch.starts_with(Profile.Name);
+});
+
+if (FoundProfile == std::end(SupportedProfiles))
+  return createStringError(errc::invalid_argument, "unsupported profile");
+
+NewArch = FoundProfile->MArch;
+StringRef ArchWithoutProfile = Arch.substr(strlen(FoundProfile->Name));
+if (!ArchWithoutProfile.empty()) {
+  if (!ArchWithoutProfile.starts_with("_"))
+return createStringError(
+errc::invalid_argument,
+"additional extensions must be after separator '_'");
+  NewArch = NewArch + ArchWithoutProfile.str();

4vtomat wrote:

Maybe `NewArch += ArchWithoutProfile.str()` to reduce 1 redundant copy?

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


[clang] [clang-tools-extra] [CLANGD] Do not crash on designator initialization of union (PR #83369)

2024-03-13 Thread via cfe-commits

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


[clang] [clang-tools-extra] [CLANGD] Do not crash on designator initialization of union (PR #83369)

2024-03-13 Thread via cfe-commits


@@ -4601,8 +4601,15 @@ SourceRange 
DesignatedInitExpr::getDesignatorsSourceRange() const {
 SourceLocation DesignatedInitExpr::getBeginLoc() const {
   auto *DIE = const_cast(this);
   Designator  = *DIE->getDesignator(0);
-  if (First.isFieldDesignator())
-return GNUSyntax ? First.getFieldLoc() : First.getDotLoc();
+  if (First.isFieldDesignator()) {
+for (unsigned int i = 0; i < DIE->size(); i++) {

alirezamoshtaghi wrote:

I ended up using EXPECT_UNAVAILABLE because it still fails for crashing case.

but when I use EXPECT_AVAILABLE, it complains as:
Expected equality of these values:
  true
  isAvailable(AST, R)
Which is: false

struct A {
  struct {
int x;
  };
};
struct B {
  int y;
};
void foo(struct B *b) {
  struct A a = {.[[x]]=b->y};
}


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


[clang] [clang-tools-extra] [CLANGD] Do not crash on designator initialization of union (PR #83369)

2024-03-13 Thread via cfe-commits

https://github.com/alirezamoshtaghi updated 
https://github.com/llvm/llvm-project/pull/83369

>From 3d6afe011221ac239bb668b375ed3f6c356fc47d Mon Sep 17 00:00:00 2001
From: alirezamoshtaghi 
Date: Wed, 28 Feb 2024 13:55:11 -0800
Subject: [PATCH 1/4] [CLANGD] Do not crash on designator initialization of
 union

---
 .../clangd/test/designator_init.test  | 31 +++
 clang/lib/AST/Expr.cpp| 14 +++--
 2 files changed, 43 insertions(+), 2 deletions(-)
 create mode 100644 clang-tools-extra/clangd/test/designator_init.test

diff --git a/clang-tools-extra/clangd/test/designator_init.test 
b/clang-tools-extra/clangd/test/designator_init.test
new file mode 100644
index 00..739f2bfab54bcf
--- /dev/null
+++ b/clang-tools-extra/clangd/test/designator_init.test
@@ -0,0 +1,31 @@
+//# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
+//# RUN: echo '[{"directory": "%/t.dir", "command": "clang -x c -c %s", 
"file": "%s"}]' > %t.dir/compile_commands.json
+//# RUN: clangd --compile-commands-dir=%t.dir --check=%s 2>&1 | FileCheck %s
+
+typedef struct S {
+  unsigned char id;
+  union {
+unsigned int mask;
+struct {
+  unsigned int unused:10;
+  unsigned int reserved:3;
+  unsigned int rest:19;
+};
+  };
+} __attribute__((packed)) S_t;
+
+typedef struct H {
+  unsigned char hid;
+  unsigned int val;
+} handler_t;
+
+struct S
+get_foo (handler_t *h)
+{
+  S_t retval =
+{.id=h->hid,
+ .mask=h->val};
+  return retval;
+}
+
+// CHECK: All checks completed, 0 errors
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index b4de2155adcebd..33eeeda89fe7a5 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4601,11 +4601,21 @@ SourceRange 
DesignatedInitExpr::getDesignatorsSourceRange() const {
 SourceLocation DesignatedInitExpr::getBeginLoc() const {
   auto *DIE = const_cast(this);
   Designator  = *DIE->getDesignator(0);
-  if (First.isFieldDesignator())
-return GNUSyntax ? First.getFieldLoc() : First.getDotLoc();
+  if (First.isFieldDesignator()) {
+/* search all designators in case the first one is not
+   initialized */
+for (unsigned int i=0; isize(); i++) {
+  Designator  = *DIE->getDesignator(i);
+  SourceLocation retval = GNUSyntax ? Des.getFieldLoc() : Des.getDotLoc();
+  if (!retval.isValid ())
+   continue;
+  return retval;
+}
+  }
   return First.getLBracketLoc();
 }
 
+
 SourceLocation DesignatedInitExpr::getEndLoc() const {
   return getInit()->getEndLoc();
 }

>From 397f6cd893a6a07426d39f1dabd7ad27282435af Mon Sep 17 00:00:00 2001
From: alirezamoshtaghi 
Date: Mon, 4 Mar 2024 11:54:56 -0800
Subject: [PATCH 2/4] fix formatting errors

---
 clang/lib/AST/Expr.cpp | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 33eeeda89fe7a5..2e7170ecac0618 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4602,20 +4602,17 @@ SourceLocation DesignatedInitExpr::getBeginLoc() const {
   auto *DIE = const_cast(this);
   Designator  = *DIE->getDesignator(0);
   if (First.isFieldDesignator()) {
-/* search all designators in case the first one is not
-   initialized */
-for (unsigned int i=0; isize(); i++) {
+for (unsigned int i = 0; i < DIE->size(); i++) {
   Designator  = *DIE->getDesignator(i);
   SourceLocation retval = GNUSyntax ? Des.getFieldLoc() : Des.getDotLoc();
-  if (!retval.isValid ())
-   continue;
+  if (!retval.isValid())
+continue;
   return retval;
 }
   }
   return First.getLBracketLoc();
 }
 
-
 SourceLocation DesignatedInitExpr::getEndLoc() const {
   return getInit()->getEndLoc();
 }

>From d1d1458809e0b27dc05c70ef449ebbe6896437d4 Mon Sep 17 00:00:00 2001
From: alirezamoshtaghi 
Date: Tue, 5 Mar 2024 00:04:52 -0800
Subject: [PATCH 3/4] dont test designator on Windows

---
 clang-tools-extra/clangd/test/designator_init.test | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/test/designator_init.test 
b/clang-tools-extra/clangd/test/designator_init.test
index 739f2bfab54bcf..4009945ed81fd4 100644
--- a/clang-tools-extra/clangd/test/designator_init.test
+++ b/clang-tools-extra/clangd/test/designator_init.test
@@ -1,7 +1,7 @@
 //# RUN: rm -rf %t.dir/* && mkdir -p %t.dir
 //# RUN: echo '[{"directory": "%/t.dir", "command": "clang -x c -c %s", 
"file": "%s"}]' > %t.dir/compile_commands.json
 //# RUN: clangd --compile-commands-dir=%t.dir --check=%s 2>&1 | FileCheck %s
-
+//# UNSUPPORTED: system-windows
 typedef struct S {
   unsigned char id;
   union {

>From a792acd4eec0f549bdbf9779dce14aca5357c2db Mon Sep 17 00:00:00 2001
From: alirezamoshtaghi 
Date: Wed, 13 Mar 2024 18:51:38 -0700
Subject: [PATCH 4/4] Move the test to clangd unit tests

---
 .../clangd/test/designator_init.test  | 31 ---
 .../unittests/tweaks/ExtractVariableTests.cpp | 16 ++
 

[clang] [compiler-rt] [asan][windows] Eliminate the static asan runtime on windows (PR #81677)

2024-03-13 Thread Charlie Barto via cfe-commits

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


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

2024-03-13 Thread Brandon Wu via cfe-commits


@@ -36,6 +36,11 @@ struct RISCVSupportedExtension {
   }
 };
 
+struct RISCVProfile {

4vtomat wrote:

Very minor too, if you use std::pair, could you add the comments describing 
what the fields represent?

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


[clang] [llvm] [BPF] rename 'arena' to 'address_space' (PR #85161)

2024-03-13 Thread via cfe-commits


@@ -517,13 +517,13 @@ bool BPFCheckAndAdjustIR::insertASpaceCasts(Module ) {
 Changed |= !CastsCache.empty();
   }
   // Merge all globals within same address space into single
-  // .arena. section
+  // .address_space. section
   for (GlobalVariable  : M.globals()) {
 if (G.getAddressSpace() == 0 || G.hasSection())
   continue;
 SmallString<16> SecName;
 raw_svector_ostream OS(SecName);
-OS << ".arena." << G.getAddressSpace();
+OS << ".address_space." << G.getAddressSpace();

4ast wrote:

since instruction is called "addr_space" let's name the section name the same 
".addr_space." ?
and __BPF_FEATURE_ADDR_SPACE_CAST too ?

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


[clang] [llvm] [BPF] rename 'arena' to 'address_space' (PR #85161)

2024-03-13 Thread via cfe-commits

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


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


[clang] [llvm] [BPF] rename 'arena' to 'address_space' (PR #85161)

2024-03-13 Thread via cfe-commits

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


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

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

yamt wrote:

> If possible, can you not force-push? It's hard to track changes between 
> commits with force-pushes. Thank you!

i had to rebase for some unrelated reasons. i will avoid it next time.


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] [llvm] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #83204)

2024-03-13 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 55d4816393f897054a4721920502d45c645edf1d 
cb86c3c12959513309ccf97592d602ba4da36d1d -- 
clang/test/CodeGen/object-size-sub-object.c clang/lib/CodeGen/CGBuiltin.cpp 
clang/lib/CodeGen/CGExpr.cpp clang/test/CodeGen/attr-counted-by.c 
clang/test/CodeGen/catch-undef-behavior.c clang/test/CodeGen/object-size.c 
clang/test/CodeGen/object-size.cpp clang/test/CodeGen/pass-object-size.c 
clang/test/CodeGen/sanitize-recover.c 
llvm/include/llvm/Analysis/MemoryBuiltins.h 
llvm/lib/Analysis/MemoryBuiltins.cpp llvm/lib/IR/AutoUpgrade.cpp 
llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index d8d4aa5288..7461d0ee00 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1244,8 +1244,8 @@ CodeGenFunction::emitBuiltinObjectSize(const Expr *E, 
unsigned Type,
   // it's set, a closest surrounding subobject is considered the object a
   // pointer points to.
   Value *WholeObj = Builder.getInt1((Type & 1) == 0);
-  return Builder.CreateCall(F, {Ptr, Min, NullIsUnknown, Dynamic, WholeObj,
-SubobjectSize});
+  return Builder.CreateCall(
+  F, {Ptr, Min, NullIsUnknown, Dynamic, WholeObj, SubobjectSize});
 }
 
 namespace {
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index b0aa3579bd..d94a775cab 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -750,8 +750,8 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, 
SourceLocation Loc,
   llvm::Value *WholeObj = Builder.getTrue();
   llvm::Value *SubobjectSize = Builder.getInt64(0);
   llvm::Value *LargeEnough = Builder.CreateICmpUGE(
-  Builder.CreateCall(F, {Ptr, Min, NullIsUnknown, Dynamic, WholeObj,
- SubobjectSize}),
+  Builder.CreateCall(
+  F, {Ptr, Min, NullIsUnknown, Dynamic, WholeObj, SubobjectSize}),
   Size);
   Checks.push_back(std::make_pair(LargeEnough, SanitizerKind::ObjectSize));
 }

``




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


[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-13 Thread Juergen Ributzka via cfe-commits

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


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


[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-13 Thread Juergen Ributzka via cfe-commits




ributzka wrote:

Do you think this file is necessary?

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


[clang] [InstallAPI] Add installapi specific options & diagnostics (PR #85100)

2024-03-13 Thread Juergen Ributzka via cfe-commits

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


[clang] [Clang][Sema] Fix a bug on type constraint checking (PR #84671)

2024-03-13 Thread Qizhi Hu via cfe-commits

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

>From 849db0cede4d0fe108ec7cf530974606a426b9db Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 10 Mar 2024 16:11:18 +0800
Subject: [PATCH] [Clang][Sema] Fix a bug on type constraint checking

---
 clang/docs/ReleaseNotes.rst|  2 ++
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp |  1 +
 clang/test/Sema/PR84368.cpp| 16 
 3 files changed, 19 insertions(+)
 create mode 100644 clang/test/Sema/PR84368.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5fe3fd066df235..cede0deb179d5c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -376,6 +376,8 @@ Bug Fixes to C++ Support
 - Fixed a crash in constant evaluation when trying to access a
   captured ``this`` pointer in a lambda with an explicit object parameter.
   Fixes (#GH80997)
+- Fix an issue where missing set friend declaration in template class 
instantiation.
+  Fixes (#GH84368).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 8ef8bfdf2a7b56..dc972018e7b281 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1727,6 +1727,7 @@ Decl 
*TemplateDeclInstantiator::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 assert(!Owner->isDependentContext());
 Inst->setLexicalDeclContext(Owner);
 RecordInst->setLexicalDeclContext(Owner);
+Inst->setObjectOfFriendDecl();
 
 if (PrevClassTemplate) {
   Inst->setCommonPtr(PrevClassTemplate->getCommonPtr());
diff --git a/clang/test/Sema/PR84368.cpp b/clang/test/Sema/PR84368.cpp
new file mode 100644
index 00..6551df29358920
--- /dev/null
+++ b/clang/test/Sema/PR84368.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++23 -verify %s
+// expected-no-diagnostics
+
+template concept IsOk = requires() { typename T::Float; };
+
+template struct Thing;
+
+template struct Foobar {
+  template struct Inner {
+template friend struct Thing;
+  };
+};
+
+struct MyType { using Float=float; };
+Foobar::Inner<0> foobar;

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


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

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


@@ -0,0 +1,61 @@
+// RUN: %clang -fsanitize=implicit-bitfield-conversion -target x86_64-linux -S 
-emit-llvm -o - %s | FileCheck %s 
--check-prefixes=CHECK,CHECK-BITFIELD-CONVERSION

efriedma-quic wrote:

I'd like to see some testcases that run in C++ mode.

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


[clang] [llvm] [BPF] rename 'arena' to 'address_space' (PR #85161)

2024-03-13 Thread via cfe-commits

eddyz87 wrote:

I also tested this change using 
[this](https://gist.github.com/eddyz87/1921247819138a9ed70d77db40db8a7c) kernel 
patch and arena tests are passing.

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


[clang] [llvm] [BPF] rename 'arena' to 'address_space' (PR #85161)

2024-03-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (eddyz87)


Changes

There are a few places where `arena` name is used for pointers in non-zero 
address space in BPF backend, rename these to use a more generic 
`address_space`:
- macro `__BPF_FEATURE_ARENA_CAST` - `__BPF_FEATURE_ADDRESS_SPACE_CAST
- name for arena global variables section `.arena.N` - `.address_space.N`

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


5 Files Affected:

- (modified) clang/lib/Basic/Targets/BPF.cpp (+1-1) 
- (modified) clang/test/Preprocessor/bpf-predefined-macros.c (+1-1) 
- (modified) llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp (+5-5) 
- (modified) llvm/test/CodeGen/BPF/addr-space-globals.ll (+1-1) 
- (modified) llvm/test/CodeGen/BPF/addr-space-globals2.ll (+2-2) 


``diff
diff --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp
index 26a54f631fcfc4..9a1188acab944c 100644
--- a/clang/lib/Basic/Targets/BPF.cpp
+++ b/clang/lib/Basic/Targets/BPF.cpp
@@ -36,7 +36,7 @@ void BPFTargetInfo::getTargetDefines(const LangOptions ,
 return;
   }
 
-  Builder.defineMacro("__BPF_FEATURE_ARENA_CAST");
+  Builder.defineMacro("__BPF_FEATURE_ADDRESS_SPACE_CAST");
 
   if (CPU.empty() || CPU == "generic" || CPU == "v1") {
 Builder.defineMacro("__BPF_CPU_VERSION__", "1");
diff --git a/clang/test/Preprocessor/bpf-predefined-macros.c 
b/clang/test/Preprocessor/bpf-predefined-macros.c
index fea24d1ea0ff7b..b6928c5c6ff4b4 100644
--- a/clang/test/Preprocessor/bpf-predefined-macros.c
+++ b/clang/test/Preprocessor/bpf-predefined-macros.c
@@ -61,7 +61,7 @@ int r;
 #ifdef __BPF_FEATURE_ST
 int s;
 #endif
-#ifdef __BPF_FEATURE_ARENA_CAST
+#ifdef __BPF_FEATURE_ADDRESS_SPACE_CAST
 int t;
 #endif
 
diff --git a/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp 
b/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
index edd59aaa6d01d2..070dd1ff4c5784 100644
--- a/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
+++ b/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
@@ -15,7 +15,7 @@
 //   - remove llvm.bpf.getelementptr.and.load builtins.
 //   - remove llvm.bpf.getelementptr.and.store builtins.
 //   - for loads and stores with base addresses from non-zero address space
-// cast base address to zero address space (support for BPF arenas).
+// cast base address to zero address space (support for BPF address 
spaces).
 //
 
//===--===//
 
@@ -482,7 +482,7 @@ static void aspaceWrapOperand(DenseMap 
, Instruction *I,
   }
 }
 
-// Support for BPF arenas:
+// Support for BPF address spaces:
 // - for each function in the module M, update pointer operand of
 //   each memory access instruction (load/store/cmpxchg/atomicrmw)
 //   by casting it from non-zero address space to zero address space, e.g:
@@ -490,7 +490,7 @@ static void aspaceWrapOperand(DenseMap 
, Instruction *I,
 //   (load (ptr addrspace (N) %p) ...)
 // -> (load (addrspacecast ptr addrspace (N) %p to ptr))
 //
-// - assign section with name .arena.N for globals defined in
+// - assign section with name .address_space.N for globals defined in
 //   non-zero address space N
 bool BPFCheckAndAdjustIR::insertASpaceCasts(Module ) {
   bool Changed = false;
@@ -517,13 +517,13 @@ bool BPFCheckAndAdjustIR::insertASpaceCasts(Module ) {
 Changed |= !CastsCache.empty();
   }
   // Merge all globals within same address space into single
-  // .arena. section
+  // .address_space. section
   for (GlobalVariable  : M.globals()) {
 if (G.getAddressSpace() == 0 || G.hasSection())
   continue;
 SmallString<16> SecName;
 raw_svector_ostream OS(SecName);
-OS << ".arena." << G.getAddressSpace();
+OS << ".address_space." << G.getAddressSpace();
 G.setSection(SecName);
 // Prevent having separate section for constants
 G.setConstant(false);
diff --git a/llvm/test/CodeGen/BPF/addr-space-globals.ll 
b/llvm/test/CodeGen/BPF/addr-space-globals.ll
index 878ba0dfce6cd1..9848b1bbcd4f35 100644
--- a/llvm/test/CodeGen/BPF/addr-space-globals.ll
+++ b/llvm/test/CodeGen/BPF/addr-space-globals.ll
@@ -18,7 +18,7 @@
 
 ; Verify that a,b,c reside in the same section
 
-; CHECK: .section .arena.272,"aw",@progbits
+; CHECK: .section .address_space.272,"aw",@progbits
 ; CHECK-NOT: .section
 ; CHECK: .globl  a
 ; CHECK: .ascii  "\001\002"
diff --git a/llvm/test/CodeGen/BPF/addr-space-globals2.ll 
b/llvm/test/CodeGen/BPF/addr-space-globals2.ll
index d1e2318948751e..816741e2e834eb 100644
--- a/llvm/test/CodeGen/BPF/addr-space-globals2.ll
+++ b/llvm/test/CodeGen/BPF/addr-space-globals2.ll
@@ -14,12 +14,12 @@
 
 ; Verify that a,b reside in separate sections
 
-; CHECK: .section .arena.1,"aw",@progbits
+; CHECK: .section .address_space.1,"aw",@progbits
 ; CHECK-NOT: .section
 ; CHECK: .globl  a
 ; CHECK: .ascii  "\001\002"
 
-; CHECK: .section .arena.2,"aw",@progbits
+; CHECK: .section .address_space.2,"aw",@progbits
 ; CHECK-NOT: 

[clang] [llvm] [BPF] rename 'arena' to 'address_space' (PR #85161)

2024-03-13 Thread via cfe-commits

https://github.com/eddyz87 created 
https://github.com/llvm/llvm-project/pull/85161

There are a few places where `arena` name is used for pointers in non-zero 
address space in BPF backend, rename these to use a more generic 
`address_space`:
- macro `__BPF_FEATURE_ARENA_CAST` -> `__BPF_FEATURE_ADDRESS_SPACE_CAST
- name for arena global variables section `.arena.N` -> `.address_space.N`

>From d309957bc26f3f9d4afba6a1d0b6bd3ddffbfee7 Mon Sep 17 00:00:00 2001
From: Eduard Zingerman 
Date: Thu, 14 Mar 2024 01:56:18 +0200
Subject: [PATCH] [BPF] rename 'arena' to 'address_space'

There are a few places where 'arena' name is used for pointers in
non-zero address space in BPF backend, rename these to use a more
generic 'address_space':
- macro __BPF_FEATURE_ARENA_CAST -> __BPF_FEATURE_ADDRESS_SPACE_CAST
- name for arena global variables section .arena.N -> .address_space.N
---
 clang/lib/Basic/Targets/BPF.cpp |  2 +-
 clang/test/Preprocessor/bpf-predefined-macros.c |  2 +-
 llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp | 10 +-
 llvm/test/CodeGen/BPF/addr-space-globals.ll |  2 +-
 llvm/test/CodeGen/BPF/addr-space-globals2.ll|  4 ++--
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Basic/Targets/BPF.cpp b/clang/lib/Basic/Targets/BPF.cpp
index 26a54f631fcfc4..9a1188acab944c 100644
--- a/clang/lib/Basic/Targets/BPF.cpp
+++ b/clang/lib/Basic/Targets/BPF.cpp
@@ -36,7 +36,7 @@ void BPFTargetInfo::getTargetDefines(const LangOptions ,
 return;
   }
 
-  Builder.defineMacro("__BPF_FEATURE_ARENA_CAST");
+  Builder.defineMacro("__BPF_FEATURE_ADDRESS_SPACE_CAST");
 
   if (CPU.empty() || CPU == "generic" || CPU == "v1") {
 Builder.defineMacro("__BPF_CPU_VERSION__", "1");
diff --git a/clang/test/Preprocessor/bpf-predefined-macros.c 
b/clang/test/Preprocessor/bpf-predefined-macros.c
index fea24d1ea0ff7b..b6928c5c6ff4b4 100644
--- a/clang/test/Preprocessor/bpf-predefined-macros.c
+++ b/clang/test/Preprocessor/bpf-predefined-macros.c
@@ -61,7 +61,7 @@ int r;
 #ifdef __BPF_FEATURE_ST
 int s;
 #endif
-#ifdef __BPF_FEATURE_ARENA_CAST
+#ifdef __BPF_FEATURE_ADDRESS_SPACE_CAST
 int t;
 #endif
 
diff --git a/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp 
b/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
index edd59aaa6d01d2..070dd1ff4c5784 100644
--- a/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
+++ b/llvm/lib/Target/BPF/BPFCheckAndAdjustIR.cpp
@@ -15,7 +15,7 @@
 //   - remove llvm.bpf.getelementptr.and.load builtins.
 //   - remove llvm.bpf.getelementptr.and.store builtins.
 //   - for loads and stores with base addresses from non-zero address space
-// cast base address to zero address space (support for BPF arenas).
+// cast base address to zero address space (support for BPF address 
spaces).
 //
 
//===--===//
 
@@ -482,7 +482,7 @@ static void aspaceWrapOperand(DenseMap 
, Instruction *I,
   }
 }
 
-// Support for BPF arenas:
+// Support for BPF address spaces:
 // - for each function in the module M, update pointer operand of
 //   each memory access instruction (load/store/cmpxchg/atomicrmw)
 //   by casting it from non-zero address space to zero address space, e.g:
@@ -490,7 +490,7 @@ static void aspaceWrapOperand(DenseMap 
, Instruction *I,
 //   (load (ptr addrspace (N) %p) ...)
 // -> (load (addrspacecast ptr addrspace (N) %p to ptr))
 //
-// - assign section with name .arena.N for globals defined in
+// - assign section with name .address_space.N for globals defined in
 //   non-zero address space N
 bool BPFCheckAndAdjustIR::insertASpaceCasts(Module ) {
   bool Changed = false;
@@ -517,13 +517,13 @@ bool BPFCheckAndAdjustIR::insertASpaceCasts(Module ) {
 Changed |= !CastsCache.empty();
   }
   // Merge all globals within same address space into single
-  // .arena. section
+  // .address_space. section
   for (GlobalVariable  : M.globals()) {
 if (G.getAddressSpace() == 0 || G.hasSection())
   continue;
 SmallString<16> SecName;
 raw_svector_ostream OS(SecName);
-OS << ".arena." << G.getAddressSpace();
+OS << ".address_space." << G.getAddressSpace();
 G.setSection(SecName);
 // Prevent having separate section for constants
 G.setConstant(false);
diff --git a/llvm/test/CodeGen/BPF/addr-space-globals.ll 
b/llvm/test/CodeGen/BPF/addr-space-globals.ll
index 878ba0dfce6cd1..9848b1bbcd4f35 100644
--- a/llvm/test/CodeGen/BPF/addr-space-globals.ll
+++ b/llvm/test/CodeGen/BPF/addr-space-globals.ll
@@ -18,7 +18,7 @@
 
 ; Verify that a,b,c reside in the same section
 
-; CHECK: .section .arena.272,"aw",@progbits
+; CHECK: .section .address_space.272,"aw",@progbits
 ; CHECK-NOT: .section
 ; CHECK: .globl  a
 ; CHECK: .ascii  "\001\002"
diff --git a/llvm/test/CodeGen/BPF/addr-space-globals2.ll 
b/llvm/test/CodeGen/BPF/addr-space-globals2.ll
index d1e2318948751e..816741e2e834eb 100644
--- a/llvm/test/CodeGen/BPF/addr-space-globals2.ll

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

2024-03-13 Thread Heejin Ahn via cfe-commits


@@ -198,9 +198,18 @@
 ///
 /// If there are calls to setjmp()
 ///
-/// 2) and 3): The same as 2) and 3) in Emscripten SjLj.
-/// (setjmpTable/setjmpTableSize initialization + setjmp callsite
-/// transformation)
+/// 2) In the function entry that calls setjmp, initialize
+///functionInvocationId as follows:
+///
+///functionInvocationId = alloca()
+///
+/// 3) Lower
+///  setjmp(env)
+///into
+///  __wasm_setjmp(env, label, functionInvocationId)
+///
+///A BB with setjmp is split into two after setjmp call in order to
+///make the post-setjmp BB the possible destination of longjmp BB.

aheejin wrote:

As I said in the emscripten PR, I think we can use your libraries in both 
Emscripten SjLj and Wasm SjLj. The only reason we have 
`handleLongjmpableCallsForEmscriptenSjLj` and 
`handleLongjmpableCallsForEmscriptenSjLj` separately is how we transform code 
is different and not because the way we use `saveSetjmp` and `testSetjmp` is 
any different.

So we can remove all uses of the current `saveSetjmp` and `testSetjmp` in this 
file and fix test accordingly, and move this comment block to `Emscripten 
setjmp/longjmp handling` part and leave this Wasm side comment as is.

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] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-13 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin edited 
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] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-13 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin commented:

If possible, can you not force-push? It's hard to track changes between commits 
with force-pushes. Thank you!

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] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

I looked at this a bit and the change that increases the constexpr restrictions 
is that `ext_defaulted_comparison_constexpr_mismatch` (which was added in 
https://reviews.llvm.org/D146090) became 
`err_incorrect_defaulted_comparison_constexpr`?

https://github.com/llvm/llvm-project/pull/77753
___
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-13 Thread Harald van Dijk via cfe-commits


@@ -1,13 +1,58 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only
 // RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
 // RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=microsoft -fsyntax-only -fms-compatibility 
-Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */

hvdijk wrote:

I do not see any obvious cases where the code does the wrong thing, sure, I 
agree with you on that, but as far as I can find, we do not have *any* test for 
"initialization of flexible array member is not allowed" being correctly 
emitted for nested unions containing flexible array members, either currently 
or after this PR. `flexible-array-init.c` contains tests for this for nested 
structs containing flexible array members, but not for unions. Previously, 
these would have implicitly been handled by flexible array members being 
disallowed in unions in the first place, at least for C, but as you are 
enabling them now, that no longer applies.

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] [Clang][BPF] Allow sign extension for call parameters with int types (PR #84874)

2024-03-13 Thread via cfe-commits

4ast wrote:

> Just uploaded a new revision which targets 'Int' type only, i.e, v1.

Looks like it's a bug in risc-v JIT. We never promised that kfunc call from bpf 
calling convention into native cpu calling convention will be free on all 
architectures. That's why we have btf_func_model and JITs suppose to use it 
when calling conventions don't match. It seems risc-v JIT needs to emit sign 
extension when 'int' argument is passed into kfunc.
Simple stuff, comparing to what we do in 32-bit x86 JIT where 64-bit bpf 
program can call into 32-bit x86 kfunc.

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


[clang] Rough first stab at addressing #85120 (PR #85147)

2024-03-13 Thread via cfe-commits

Sirraide wrote:

> a subsequent crash involving lambdas

There definitely is a crash involving templated lambdas on trunk: 
https://github.com/llvm/llvm-project/issues/85154

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


[clang] [Driver,CrossWindows] Remove -isystem-after (PR #84121)

2024-03-13 Thread Saleem Abdulrasool via cfe-commits

compnerd wrote:

I don't see why removing the help text is not sufficient to handle the issue? 
Even if no major players are using it, I think that there are people using it. 
It is a fairly self-contained bit of support.

https://github.com/llvm/llvm-project/pull/84121
___
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-13 Thread via cfe-commits

https://github.com/goldsteinn closed 
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] d80d5b9 - [InstCombine] Canonicalize `(sitofp x)` -> `(uitofp x)` if `x >= 0`

2024-03-13 Thread Noah Goldstein via cfe-commits

Author: Noah Goldstein
Date: 2024-03-13T18:26:21-05:00
New Revision: d80d5b923c6f611590a12543bdb33e0c16044d44

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

LOG: [InstCombine] Canonicalize `(sitofp x)` -> `(uitofp x)` if `x >= 0`

Just a standard canonicalization.

Proofs: https://alive2.llvm.org/ce/z/9W4VFm

Closes #82404

Added: 


Modified: 
clang/test/Headers/__clang_hip_math.hip
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/add-sitofp.ll
llvm/test/Transforms/InstCombine/binop-itofp.ll
llvm/test/Transforms/InstCombine/clamp-to-minmax.ll
llvm/test/Transforms/InstCombine/fpcast.ll
llvm/test/Transforms/InstCombine/minmax-fold.ll
llvm/test/Transforms/InstCombine/minmax-fp.ll
llvm/test/Transforms/InstCombine/pr27236.ll
llvm/test/Transforms/LoopVectorize/X86/float-induction-x86.ll
llvm/test/Transforms/LoopVectorize/float-induction.ll

Removed: 




diff  --git a/clang/test/Headers/__clang_hip_math.hip 
b/clang/test/Headers/__clang_hip_math.hip
index 37099de74fb8ec..701f93853ab93c 100644
--- a/clang/test/Headers/__clang_hip_math.hip
+++ b/clang/test/Headers/__clang_hip_math.hip
@@ -1685,7 +1685,7 @@ extern "C" __device__ double test_j1(double x) {
 // DEFAULT-NEXT:[[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // DEFAULT-NEXT:[[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // DEFAULT-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// DEFAULT-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
+// DEFAULT-NEXT:[[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
 // DEFAULT-NEXT:[[DIV_I:%.*]] = fdiv contract float [[CONV_I]], [[Y]]
 // DEFAULT-NEXT:[[MUL8_I:%.*]] = fmul contract float [[__X1_0_I3]], 
[[DIV_I]]
 // DEFAULT-NEXT:[[SUB_I]] = fsub contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -1718,7 +1718,7 @@ extern "C" __device__ double test_j1(double x) {
 // FINITEONLY-NEXT:[[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // FINITEONLY-NEXT:[[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // FINITEONLY-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// FINITEONLY-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
+// FINITEONLY-NEXT:[[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
 // FINITEONLY-NEXT:[[DIV_I:%.*]] = fdiv nnan ninf contract float 
[[CONV_I]], [[Y]]
 // FINITEONLY-NEXT:[[MUL8_I:%.*]] = fmul nnan ninf contract float 
[[__X1_0_I3]], [[DIV_I]]
 // FINITEONLY-NEXT:[[SUB_I]] = fsub nnan ninf contract float [[MUL8_I]], 
[[__X0_0_I2]]
@@ -1751,7 +1751,7 @@ extern "C" __device__ double test_j1(double x) {
 // APPROX-NEXT:[[__X1_0_I3:%.*]] = phi float [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // APPROX-NEXT:[[__X0_0_I2:%.*]] = phi float [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // APPROX-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// APPROX-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to float
+// APPROX-NEXT:[[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to float
 // APPROX-NEXT:[[DIV_I:%.*]] = fdiv contract float [[CONV_I]], [[Y]]
 // APPROX-NEXT:[[MUL8_I:%.*]] = fmul contract float [[__X1_0_I3]], 
[[DIV_I]]
 // APPROX-NEXT:[[SUB_I]] = fsub contract float [[MUL8_I]], [[__X0_0_I2]]
@@ -1788,7 +1788,7 @@ extern "C" __device__ float test_jnf(int x, float y) {
 // DEFAULT-NEXT:[[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // DEFAULT-NEXT:[[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // DEFAULT-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// DEFAULT-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
+// DEFAULT-NEXT:[[CONV_I:%.*]] = uitofp i32 [[MUL_I]] to double
 // DEFAULT-NEXT:[[DIV_I:%.*]] = fdiv contract double [[CONV_I]], [[Y]]
 // DEFAULT-NEXT:[[MUL8_I:%.*]] = fmul contract double [[__X1_0_I3]], 
[[DIV_I]]
 // DEFAULT-NEXT:[[SUB_I]] = fsub contract double [[MUL8_I]], [[__X0_0_I2]]
@@ -1821,7 +1821,7 @@ extern "C" __device__ float test_jnf(int x, float y) {
 // FINITEONLY-NEXT:[[__X1_0_I3:%.*]] = phi double [ [[SUB_I:%.*]], 
[[FOR_BODY_I]] ], [ [[CALL_I21_I]], [[IF_END4_I]] ]
 // FINITEONLY-NEXT:[[__X0_0_I2:%.*]] = phi double [ [[__X1_0_I3]], 
[[FOR_BODY_I]] ], [ [[CALL_I_I]], [[IF_END4_I]] ]
 // FINITEONLY-NEXT:[[MUL_I:%.*]] = shl nuw nsw i32 [[__I_0_I4]], 1
-// FINITEONLY-NEXT:[[CONV_I:%.*]] = sitofp i32 [[MUL_I]] to double
+// FINITEONLY-NEXT:[[CONV_I:%.*]] = 

[clang] Rough first stab at addressing #85120 (PR #85147)

2024-03-13 Thread via cfe-commits

Sirraide wrote:

@dougsonos I may have some time to look into this since there are probably (as 
always) some annoying edge cases—particularly w/ templates. Would you be fine 
with me committing to this branch or would it be easier for you if I made a 
separate branch for that? Either is fine by me.

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


[clang] f9a1478 - Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136) (#85145)

2024-03-13 Thread via cfe-commits

Author: Amy Huang
Date: 2024-03-13T23:15:01Z
New Revision: f9a14782000e6aa2c4031bc97b20c351a9f281c3

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

LOG: Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136) (#85145)

This reverts commit 003e292f9895a9cf4e30688269efa668d1fcbb09 because
there were dependent changes in the codebase that now fail.

Added: 
clang/test/SemaCXX/cxx23-invalid-constexpr.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/DeclCXX.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/AST/Interp/cxx23.cpp
clang/test/CXX/class/class.compare/class.compare.default/p3.cpp
clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp
clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
clang/test/CXX/drs/dr13xx.cpp
clang/test/CXX/drs/dr14xx.cpp
clang/test/CXX/drs/dr15xx.cpp
clang/test/CXX/drs/dr16xx.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/test/CXX/expr/expr.const/p5-26.cpp
clang/test/CXX/special/class.copy/p13-0x.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaCXX/constant-expression-cxx2b.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp
clang/test/SemaCXX/deduced-return-type-cxx14.cpp
clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e018d38355945f..5fe3fd066df235 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -102,6 +102,8 @@ C++23 Feature Support
   materialize temporary object which is a prvalue in discarded-value 
expression.
 - Implemented `P1774R8: Portable assumptions `_.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+
 C++2c Feature Support
 ^
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 605fbc52701df0..d7ab1635cf12bc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9617,13 +9617,10 @@ def err_defaulted_copy_assign_not_ref : Error<
   "the parameter for an explicitly-defaulted copy assignment operator must be 
an "
   "lvalue reference type">;
 def err_incorrect_defaulted_constexpr : Error<
-  "defaulted definition of %sub{select_special_member_kind}0 "
-  "is not constexpr">;
+  "defaulted definition of %sub{select_special_member_kind}0 cannot be marked 
%select{constexpr|consteval}1 "
+  "before C++23">;
 def err_incorrect_defaulted_constexpr_with_vb: Error<
   "%sub{select_special_member_kind}0 cannot be 'constexpr' in a class with 
virtual base class">;
-def err_incorrect_defaulted_consteval : Error<
-  "defaulted declaration of %sub{select_special_member_kind}0 "
-  "cannot be consteval because implicit definition is not constexpr">;
 def warn_defaulted_method_deleted : Warning<
   "explicitly defaulted %sub{select_special_member_kind}0 is implicitly "
   "deleted">, InGroup;
@@ -9734,21 +9731,12 @@ def 
note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
   "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
-def ext_defaulted_comparison_constexpr_mismatch : Extension<
+def err_defaulted_comparison_constexpr_mismatch : Error<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
-  "three-way comparison operator}0 that is "
-  "declared %select{constexpr|consteval}2 but"
-  "%select{|for which the corresponding implicit 'operator==' }0 "
-  "invokes a non-constexpr comparison function is a C++23 extension">,
-  InGroup>;
-def warn_cxx23_compat_defaulted_comparison_constexpr_mismatch : Warning<
-  "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
-  "three-way comparison operator}0 that is "
-  "declared %select{constexpr|consteval}2 but"
-  "%select{|for which the corresponding implicit 'operator==' }0 "
-  "invokes a non-constexpr comparison function is incompatible with C++ "
-  "standards before C++23">,
-  InGroup, DefaultIgnore;
+  "three-way comparison operator}0 cannot be "
+  "declared %select{constexpr|consteval}2 because "
+  "%select{it|for which the corresponding implicit 'operator==' }0 "
+  "invokes a 

[clang] Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136) (PR #85145)

2024-03-13 Thread Amy Huang via cfe-commits

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


[clang] Rough first stab at addressing #85120 (PR #85147)

2024-03-13 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 ad23127222fe23e28ac3deaa16f3ae64d13b7b6f 
613f04e311f083c129acaa4598cbfd9894fe3805 -- 
clang/include/clang/AST/ASTContext.h clang/lib/AST/ASTContext.cpp 
clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/TreeTransform.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index ca90417c9b..adffdc00f6 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1303,8 +1303,9 @@ public:
 
   /// Transform a function type to have the provided result type, preserving
   /// AttributedType and MacroQualifiedType sugar.
-  QualType getFunctionTypeWithResultType(QualType OrigFuncType, QualType 
ResultType,
-const FunctionProtoType::ExtProtoInfo ) const;
+  QualType getFunctionTypeWithResultType(
+  QualType OrigFuncType, QualType ResultType,
+  const FunctionProtoType::ExtProtoInfo ) const;
 
   /// Get a function type and produce the equivalent function type with the
   /// specified exception specification. Type sugar that can be present on a
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 035dc19ba7..04ea684b13 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3140,17 +3140,18 @@ const FunctionType 
*ASTContext::adjustFunctionType(const FunctionType *T,
   return cast(Result.getTypePtr());
 }
 
-// EPI is provided by the caller because in the case of 
adjustDeducedFunctionResultType, it
-// is copied entirely from the previous FunctionType, but with a block 
(ActOnBlockStmtExpr),
-// it is more complicated...
-QualType ASTContext::getFunctionTypeWithResultType(QualType OrigFuncType, 
QualType ResultType,
-  const FunctionProtoType::ExtProtoInfo ) const
-{
+// EPI is provided by the caller because in the case of
+// adjustDeducedFunctionResultType, it is copied entirely from the previous
+// FunctionType, but with a block (ActOnBlockStmtExpr), it is more
+// complicated...
+QualType ASTContext::getFunctionTypeWithResultType(
+QualType OrigFuncType, QualType ResultType,
+const FunctionProtoType::ExtProtoInfo ) const {
   // Might be wrapped in a macro qualified type.
   if (const auto *MQT = dyn_cast(OrigFuncType)) {
-return getMacroQualifiedType(
-getFunctionTypeWithResultType(MQT->getUnderlyingType(), ResultType, 
EPI),
-MQT->getMacroIdentifier());
+return getMacroQualifiedType(getFunctionTypeWithResultType(
+ MQT->getUnderlyingType(), ResultType, 
EPI),
+ MQT->getMacroIdentifier());
   }
 
   // Might have a calling-convention attribute.
@@ -3158,10 +3159,12 @@ QualType 
ASTContext::getFunctionTypeWithResultType(QualType OrigFuncType, QualTy
 return getAttributedType(
 AT->getAttrKind(),
 getFunctionTypeWithResultType(AT->getModifiedType(), ResultType, EPI),
-getFunctionTypeWithResultType(AT->getEquivalentType(), ResultType, 
EPI));
+getFunctionTypeWithResultType(AT->getEquivalentType(), ResultType,
+  EPI));
   }
-  
-  // Anything else must be a function type. Rebuild it with the new return 
value.
+
+  // Anything else must be a function type. Rebuild it with the new return
+  // value.
   const auto *FPT = OrigFuncType->castAs();
   return getFunctionType(ResultType, FPT->getParamTypes(), EPI);
 }
@@ -3191,15 +3194,20 @@ void 
ASTContext::adjustDeducedFunctionResultType(FunctionDecl *FD,
 const auto *FPT = OrigFuncType->castAs();
 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
 #if 1 // my new way
-QualType NewFuncType = getFunctionTypeWithResultType(OrigFuncType, 
ResultType, EPI);
+QualType NewFuncType =
+getFunctionTypeWithResultType(OrigFuncType, ResultType, EPI);
 #else // original way
-QualType NewFuncType = getFunctionType(ResultType, FPT->getParamTypes(), 
EPI);
+QualType NewFuncType =
+getFunctionType(ResultType, FPT->getParamTypes(), EPI);
 #endif
-/*llvm::outs() << "transform " << OrigFuncType << " -> " << NewFuncType << 
"\n";
-llvm::outs() << " isConstQualified " << OrigFuncType.isConstQualified() << 
NewFuncType.isConstQualified() << "\n";
-llvm::outs() << " isLocalConstQualified " << 
OrigFuncType.isLocalConstQualified() << NewFuncType.isLocalConstQualified() << 
"\n";
-llvm::outs() << " const method " << FPT->isConst() << 
NewFuncType->castAs()->isConst() << "\n";
-llvm::outs() << " canonical " << NewFuncType.getCanonicalType() << "\n";*/
+/*llvm::outs() << "transform " << OrigFuncType << " -> " << NewFuncType <<
+"\n"; llvm::outs() << " isConstQualified " <<
+OrigFuncType.isConstQualified() << 

[clang] Rough first stab at addressing #85120 (PR #85147)

2024-03-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Doug Wyatt (dougsonos)


Changes

I pointed out this issue in the review for nolock/noalloc, and @Sirraide opened #85120 

Here are some (very rough) bits of code I'd written to try to address the loss 
of type sugar, plus a subsequent crash involving lambdas (can't remember 
details now, and the crash may not exist any more on main).

Just in case it helps.

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


4 Files Affected:

- (modified) clang/include/clang/AST/ASTContext.h (+5) 
- (modified) clang/lib/AST/ASTContext.cpp (+60-2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+1-1) 
- (modified) clang/lib/Sema/TreeTransform.h (+59-2) 


``diff
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index ff6b64c7f72d57..ca90417c9bf70b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1301,6 +1301,11 @@ class ASTContext : public RefCountedBase {
   /// Change the result type of a function type once it is deduced.
   void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType);
 
+  /// Transform a function type to have the provided result type, preserving
+  /// AttributedType and MacroQualifiedType sugar.
+  QualType getFunctionTypeWithResultType(QualType OrigFuncType, QualType 
ResultType,
+const FunctionProtoType::ExtProtoInfo ) const;
+
   /// Get a function type and produce the equivalent function type with the
   /// specified exception specification. Type sugar that can be present on a
   /// declaration of a function with an exception specification is permitted
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a8fae76a43a4d..035dc19ba7011d 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3140,13 +3140,71 @@ const FunctionType 
*ASTContext::adjustFunctionType(const FunctionType *T,
   return cast(Result.getTypePtr());
 }
 
+// EPI is provided by the caller because in the case of 
adjustDeducedFunctionResultType, it
+// is copied entirely from the previous FunctionType, but with a block 
(ActOnBlockStmtExpr),
+// it is more complicated...
+QualType ASTContext::getFunctionTypeWithResultType(QualType OrigFuncType, 
QualType ResultType,
+  const FunctionProtoType::ExtProtoInfo ) const
+{
+  // Might be wrapped in a macro qualified type.
+  if (const auto *MQT = dyn_cast(OrigFuncType)) {
+return getMacroQualifiedType(
+getFunctionTypeWithResultType(MQT->getUnderlyingType(), ResultType, 
EPI),
+MQT->getMacroIdentifier());
+  }
+
+  // Might have a calling-convention attribute.
+  if (const auto *AT = dyn_cast(OrigFuncType)) {
+return getAttributedType(
+AT->getAttrKind(),
+getFunctionTypeWithResultType(AT->getModifiedType(), ResultType, EPI),
+getFunctionTypeWithResultType(AT->getEquivalentType(), ResultType, 
EPI));
+  }
+  
+  // Anything else must be a function type. Rebuild it with the new return 
value.
+  const auto *FPT = OrigFuncType->castAs();
+  return getFunctionType(ResultType, FPT->getParamTypes(), EPI);
+}
+
+#if 0
+static void examineType(const char* prefix, QualType QT, const char* term)
+{
+  llvm::outs() << prefix;
+  if (const auto *MQT = dyn_cast(QT)) {
+examineType( "MacroQualifiedType <", MQT->getUnderlyingType(), ">");
+  } else if (const auto *AT = dyn_cast(QT)) {
+examineType("AttributedType <", AT->getEquivalentType(), ">");
+  } else {
+const auto *FPT = QT->castAs();
+assert(FPT);
+llvm::outs() << QT;
+  }
+  llvm::outs() << term;
+}
+#endif
+
 void ASTContext::adjustDeducedFunctionResultType(FunctionDecl *FD,
  QualType ResultType) {
   FD = FD->getMostRecentDecl();
   while (true) {
-const auto *FPT = FD->getType()->castAs();
+QualType OrigFuncType = FD->getType();
+const auto *FPT = OrigFuncType->castAs();
 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
-FD->setType(getFunctionType(ResultType, FPT->getParamTypes(), EPI));
+#if 1 // my new way
+QualType NewFuncType = getFunctionTypeWithResultType(OrigFuncType, 
ResultType, EPI);
+#else // original way
+QualType NewFuncType = getFunctionType(ResultType, FPT->getParamTypes(), 
EPI);
+#endif
+/*llvm::outs() << "transform " << OrigFuncType << " -> " << NewFuncType << 
"\n";
+llvm::outs() << " isConstQualified " << OrigFuncType.isConstQualified() << 
NewFuncType.isConstQualified() << "\n";
+llvm::outs() << " isLocalConstQualified " << 
OrigFuncType.isLocalConstQualified() << NewFuncType.isLocalConstQualified() << 
"\n";
+llvm::outs() << " const method " << FPT->isConst() << 
NewFuncType->castAs()->isConst() << "\n";
+llvm::outs() << " canonical " << NewFuncType.getCanonicalType() << "\n";*/
+
+/*examineType("original ", OrigFuncType, "\n");
+examineType("deduced ", NewFuncType, "\n");*/
+
+

[clang] Rough first stab at addressing #85120 (PR #85147)

2024-03-13 Thread Doug Wyatt via cfe-commits

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


[clang] Rough first stab at addressing #85120 (PR #85147)

2024-03-13 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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

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

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


[clang] Rough first stab at addressing #85120 (PR #85147)

2024-03-13 Thread Doug Wyatt via cfe-commits

https://github.com/dougsonos created 
https://github.com/llvm/llvm-project/pull/85147

I pointed out this issue in the review for nolock/noalloc, and @Sirraide opened 
#85120 

Here are some (very rough) bits of code I'd written to try to address the loss 
of type sugar, plus a subsequent crash involving lambdas (can't remember 
details now, and the crash may not exist any more on main).

Just in case it helps.

>From 613f04e311f083c129acaa4598cbfd9894fe3805 Mon Sep 17 00:00:00 2001
From: Doug Wyatt 
Date: Wed, 13 Mar 2024 16:02:14 -0700
Subject: [PATCH] Rough first stab at addressing #85120

---
 clang/include/clang/AST/ASTContext.h |  5 +++
 clang/lib/AST/ASTContext.cpp | 62 +++-
 clang/lib/Sema/SemaExpr.cpp  |  2 +-
 clang/lib/Sema/TreeTransform.h   | 61 ++-
 4 files changed, 125 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index ff6b64c7f72d57..ca90417c9bf70b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1301,6 +1301,11 @@ class ASTContext : public RefCountedBase {
   /// Change the result type of a function type once it is deduced.
   void adjustDeducedFunctionResultType(FunctionDecl *FD, QualType ResultType);
 
+  /// Transform a function type to have the provided result type, preserving
+  /// AttributedType and MacroQualifiedType sugar.
+  QualType getFunctionTypeWithResultType(QualType OrigFuncType, QualType 
ResultType,
+const FunctionProtoType::ExtProtoInfo ) const;
+
   /// Get a function type and produce the equivalent function type with the
   /// specified exception specification. Type sugar that can be present on a
   /// declaration of a function with an exception specification is permitted
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a8fae76a43a4d..035dc19ba7011d 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3140,13 +3140,71 @@ const FunctionType 
*ASTContext::adjustFunctionType(const FunctionType *T,
   return cast(Result.getTypePtr());
 }
 
+// EPI is provided by the caller because in the case of 
adjustDeducedFunctionResultType, it
+// is copied entirely from the previous FunctionType, but with a block 
(ActOnBlockStmtExpr),
+// it is more complicated...
+QualType ASTContext::getFunctionTypeWithResultType(QualType OrigFuncType, 
QualType ResultType,
+  const FunctionProtoType::ExtProtoInfo ) const
+{
+  // Might be wrapped in a macro qualified type.
+  if (const auto *MQT = dyn_cast(OrigFuncType)) {
+return getMacroQualifiedType(
+getFunctionTypeWithResultType(MQT->getUnderlyingType(), ResultType, 
EPI),
+MQT->getMacroIdentifier());
+  }
+
+  // Might have a calling-convention attribute.
+  if (const auto *AT = dyn_cast(OrigFuncType)) {
+return getAttributedType(
+AT->getAttrKind(),
+getFunctionTypeWithResultType(AT->getModifiedType(), ResultType, EPI),
+getFunctionTypeWithResultType(AT->getEquivalentType(), ResultType, 
EPI));
+  }
+  
+  // Anything else must be a function type. Rebuild it with the new return 
value.
+  const auto *FPT = OrigFuncType->castAs();
+  return getFunctionType(ResultType, FPT->getParamTypes(), EPI);
+}
+
+#if 0
+static void examineType(const char* prefix, QualType QT, const char* term)
+{
+  llvm::outs() << prefix;
+  if (const auto *MQT = dyn_cast(QT)) {
+examineType( "MacroQualifiedType <", MQT->getUnderlyingType(), ">");
+  } else if (const auto *AT = dyn_cast(QT)) {
+examineType("AttributedType <", AT->getEquivalentType(), ">");
+  } else {
+const auto *FPT = QT->castAs();
+assert(FPT);
+llvm::outs() << QT;
+  }
+  llvm::outs() << term;
+}
+#endif
+
 void ASTContext::adjustDeducedFunctionResultType(FunctionDecl *FD,
  QualType ResultType) {
   FD = FD->getMostRecentDecl();
   while (true) {
-const auto *FPT = FD->getType()->castAs();
+QualType OrigFuncType = FD->getType();
+const auto *FPT = OrigFuncType->castAs();
 FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
-FD->setType(getFunctionType(ResultType, FPT->getParamTypes(), EPI));
+#if 1 // my new way
+QualType NewFuncType = getFunctionTypeWithResultType(OrigFuncType, 
ResultType, EPI);
+#else // original way
+QualType NewFuncType = getFunctionType(ResultType, FPT->getParamTypes(), 
EPI);
+#endif
+/*llvm::outs() << "transform " << OrigFuncType << " -> " << NewFuncType << 
"\n";
+llvm::outs() << " isConstQualified " << OrigFuncType.isConstQualified() << 
NewFuncType.isConstQualified() << "\n";
+llvm::outs() << " isLocalConstQualified " << 
OrigFuncType.isLocalConstQualified() << NewFuncType.isLocalConstQualified() << 
"\n";
+llvm::outs() << " const method " << FPT->isConst() << 
NewFuncType->castAs()->isConst() << "\n";
+llvm::outs() << " canonical " << 

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

2024-03-13 Thread Heejin Ahn via cfe-commits


@@ -198,9 +198,18 @@
 ///
 /// If there are calls to setjmp()
 ///
-/// 2) and 3): The same as 2) and 3) in Emscripten SjLj.
-/// (setjmpTable/setjmpTableSize initialization + setjmp callsite
-/// transformation)
+/// 2) In the function entry that calls setjmp, initialize
+///functionInvocationId as follows:
+///
+///functionInvocationId = alloca()

aheejin wrote:

Yes. The combination of function invocation ID + callsite determines the unique 
`setjmp` call, in my understanding.

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] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-13 Thread Heejin Ahn via cfe-commits


@@ -1291,19 +1327,29 @@ bool 
WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function ) {
   Type *IntPtrTy = getAddrIntType();
   Constant *size = ConstantInt::get(IntPtrTy, 40);
   IRB.SetInsertPoint(SetjmpTableSize);
-  auto *SetjmpTable = IRB.CreateMalloc(IntPtrTy, IRB.getInt32Ty(), size,
-   nullptr, nullptr, "setjmpTable");
-  SetjmpTable->setDebugLoc(FirstDL);
-  // CallInst::CreateMalloc may return a bitcast instruction if the result 
types
-  // mismatch. We need to set the debug loc for the original call too.
-  auto *MallocCall = SetjmpTable->stripPointerCasts();
-  if (auto *MallocCallI = dyn_cast(MallocCall)) {
-MallocCallI->setDebugLoc(FirstDL);
+  Instruction *SetjmpTable;
+  if (EnableWasmAltSjLj) {
+// This alloca'ed pointer is used by the runtime to identify function
+// inovactions. It's just for pointer comparisons. It will never
+// be dereferenced.
+SetjmpTable = IRB.CreateAlloca(IRB.getInt32Ty());
+SetjmpTable->setDebugLoc(FirstDL);
+SetjmpTableInsts.push_back(SetjmpTable);

aheejin wrote:

I think https://github.com/llvm/llvm-project/pull/84137#discussion_r1524006476 
answers it too

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] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-13 Thread Heejin Ahn via cfe-commits


@@ -1291,19 +1327,29 @@ bool 
WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function ) {
   Type *IntPtrTy = getAddrIntType();
   Constant *size = ConstantInt::get(IntPtrTy, 40);
   IRB.SetInsertPoint(SetjmpTableSize);
-  auto *SetjmpTable = IRB.CreateMalloc(IntPtrTy, IRB.getInt32Ty(), size,
-   nullptr, nullptr, "setjmpTable");
-  SetjmpTable->setDebugLoc(FirstDL);
-  // CallInst::CreateMalloc may return a bitcast instruction if the result 
types
-  // mismatch. We need to set the debug loc for the original call too.
-  auto *MallocCall = SetjmpTable->stripPointerCasts();
-  if (auto *MallocCallI = dyn_cast(MallocCall)) {
-MallocCallI->setDebugLoc(FirstDL);
+  Instruction *SetjmpTable;

aheejin wrote:

Now we don't need to support the old and new options simultaneously we don't 
need to share this. Also Emscripten SjLj can use your functions too, so it 
doesn't need it either.

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] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-13 Thread Heejin Ahn via cfe-commits


@@ -999,25 +1017,43 @@ bool 
WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module ) {
   // Register __wasm_longjmp function, which calls __builtin_wasm_longjmp.
   FunctionType *FTy = FunctionType::get(
   IRB.getVoidTy(), {Int8PtrTy, IRB.getInt32Ty()}, false);
-  WasmLongjmpF = getEmscriptenFunction(FTy, "__wasm_longjmp", );
+  if (EnableWasmAltSjLj) {
+WasmLongjmpF = getEmscriptenFunction(FTy, "__wasm_sjlj_longjmp", );

aheejin wrote:

I think we discussed this in the emscripten PR.

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] [llvm] [WebAssembly] Implement an alternative translation for -wasm-enable-sjlj (PR #84137)

2024-03-13 Thread Heejin Ahn via cfe-commits


@@ -1738,10 +1792,16 @@ void 
WebAssemblyLowerEmscriptenEHSjLj::handleLongjmpableCallsForWasmSjLj(
   BasicBlock *ThenBB = BasicBlock::Create(C, "if.then", );
   BasicBlock *EndBB = BasicBlock::Create(C, "if.end", );
   Value *EnvP = IRB.CreateBitCast(Env, getAddrPtrType(), "env.p");
-  Value *SetjmpID = IRB.CreateLoad(getAddrIntType(), EnvP, "setjmp.id");
-  Value *Label =
-  IRB.CreateCall(TestSetjmpF, {SetjmpID, SetjmpTable, SetjmpTableSize},
- OperandBundleDef("funclet", CatchPad), "label");
+  Value *Label;
+  if (EnableWasmAltSjLj) {
+Label = IRB.CreateCall(TestSetjmpF, {EnvP, SetjmpTable},
+   OperandBundleDef("funclet", CatchPad), "label");
+  } else {

aheejin wrote:

The reason I added all setjmp instructions in `SetjmpTableInsts` was to do the 
SSA update. Now we have a single `setjmpTable`, we don't need to do it and we 
don't need `SetjmpTableInsts`. (Sorry I missed this comment before)

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] Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136) (PR #85145)

2024-03-13 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Amy Huang (amykhuang)


Changes

This reverts commit 003e292f9895a9cf4e30688269efa668d1fcbb09 because there were 
dependent changes in the codebase that now fail. 

---

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


27 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+7-19) 
- (modified) clang/lib/AST/DeclCXX.cpp (+8-5) 
- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+52-41) 
- (modified) clang/test/AST/Interp/cxx23.cpp (+18-41) 
- (modified) clang/test/CXX/class/class.compare/class.compare.default/p3.cpp 
(+21-19) 
- (modified) clang/test/CXX/class/class.compare/class.compare.default/p4.cpp 
(+10-10) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp (+4-4) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp (+4-6) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp (+9-9) 
- (modified) clang/test/CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp (+4-4) 
- (modified) clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp 
(+3-3) 
- (modified) clang/test/CXX/drs/dr13xx.cpp (+11-11) 
- (modified) clang/test/CXX/drs/dr14xx.cpp (+3-3) 
- (modified) clang/test/CXX/drs/dr15xx.cpp (+12-9) 
- (modified) clang/test/CXX/drs/dr16xx.cpp (+10-10) 
- (modified) clang/test/CXX/drs/dr6xx.cpp (+12-12) 
- (modified) clang/test/CXX/expr/expr.const/p5-26.cpp (+2-2) 
- (modified) clang/test/CXX/special/class.copy/p13-0x.cpp (+1-1) 
- (modified) clang/test/SemaCXX/constant-expression-cxx11.cpp (+20-18) 
- (modified) clang/test/SemaCXX/constant-expression-cxx14.cpp (+17-16) 
- (modified) clang/test/SemaCXX/constant-expression-cxx2b.cpp (+12-12) 
- (added) clang/test/SemaCXX/cxx23-invalid-constexpr.cpp (+159) 
- (modified) clang/test/SemaCXX/cxx2a-consteval.cpp (+1-1) 
- (modified) clang/test/SemaCXX/deduced-return-type-cxx14.cpp (+4-4) 
- (modified) clang/test/SemaOpenCLCXX/addrspace-constructors.clcpp (+1-1) 
- (modified) clang/www/cxx_status.html (+1-8) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e018d38355945f..5fe3fd066df235 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -102,6 +102,8 @@ C++23 Feature Support
   materialize temporary object which is a prvalue in discarded-value 
expression.
 - Implemented `P1774R8: Portable assumptions `_.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 605fbc52701df0..d7ab1635cf12bc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9617,13 +9617,10 @@ def err_defaulted_copy_assign_not_ref : Error<
   "the parameter for an explicitly-defaulted copy assignment operator must be 
an "
   "lvalue reference type">;
 def err_incorrect_defaulted_constexpr : Error<
-  "defaulted definition of %sub{select_special_member_kind}0 "
-  "is not constexpr">;
+  "defaulted definition of %sub{select_special_member_kind}0 cannot be marked 
%select{constexpr|consteval}1 "
+  "before C++23">;
 def err_incorrect_defaulted_constexpr_with_vb: Error<
   "%sub{select_special_member_kind}0 cannot be 'constexpr' in a class with 
virtual base class">;
-def err_incorrect_defaulted_consteval : Error<
-  "defaulted declaration of %sub{select_special_member_kind}0 "
-  "cannot be consteval because implicit definition is not constexpr">;
 def warn_defaulted_method_deleted : Warning<
   "explicitly defaulted %sub{select_special_member_kind}0 is implicitly "
   "deleted">, InGroup;
@@ -9734,21 +9731,12 @@ def 
note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
   "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
-def ext_defaulted_comparison_constexpr_mismatch : Extension<
+def err_defaulted_comparison_constexpr_mismatch : Error<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
-  "three-way comparison operator}0 that is "
-  "declared %select{constexpr|consteval}2 but"
-  "%select{|for which the corresponding implicit 'operator==' }0 "
-  "invokes a non-constexpr comparison function is a C++23 extension">,
-  InGroup>;
-def warn_cxx23_compat_defaulted_comparison_constexpr_mismatch : Warning<
-  "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
-  "three-way comparison operator}0 that is "
-  "declared %select{constexpr|consteval}2 but"
-  "%select{|for which the corresponding implicit 'operator==' }0 "
-  "invokes a non-constexpr comparison function is incompatible with C++ "
-  

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

Whoops, not very familiar with git pull requests, I guess. actually reapplying 
the commit now

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


[clang] [compiler-rt] [clang][UBSan] Add implicit conversion check for bitfields (PR #75481)

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


@@ -147,6 +147,7 @@ struct ImplicitConversionData {
   const TypeDescriptor 
   const TypeDescriptor 
   /* ImplicitConversionCheckKind */ unsigned char Kind;
+  unsigned int BitfieldBits;

efriedma-quic wrote:

Do we have an ABI stability policy for UBsan?  Is the change allowed under it?

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


[clang] Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136) (PR #85145)

2024-03-13 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/85145

This reverts commit 003e292f9895a9cf4e30688269efa668d1fcbb09 because there were 
dependent changes in the codebase that now fail. 

>From d8f21288633aefd1528133ccdf46c5dc790e4f1f Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Wed, 13 Mar 2024 22:55:31 +
Subject: [PATCH] Reapply "[Clang][C++23] Implement P2448R2 ..." (#85136)

This reverts commit 003e292f9895a9cf4e30688269efa668d1fcbb09.
---
 clang/docs/ReleaseNotes.rst   |   2 +
 .../clang/Basic/DiagnosticSemaKinds.td|  26 +--
 clang/lib/AST/DeclCXX.cpp |  13 +-
 clang/lib/Sema/SemaDeclCXX.cpp|  93 +-
 clang/test/AST/Interp/cxx23.cpp   |  59 ++-
 .../class.compare.default/p3.cpp  |  40 ++---
 .../class.compare.default/p4.cpp  |  20 +--
 .../dcl.dcl/dcl.spec/dcl.constexpr/dtor.cpp   |   8 +-
 .../dcl.dcl/dcl.spec/dcl.constexpr/p3-2b.cpp  |  10 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p3.cpp |  18 +-
 .../CXX/dcl.dcl/dcl.spec/dcl.constexpr/p4.cpp |   8 +-
 .../dcl.fct.def/dcl.fct.def.default/p2.cpp|   6 +-
 clang/test/CXX/drs/dr13xx.cpp |  22 +--
 clang/test/CXX/drs/dr14xx.cpp |   6 +-
 clang/test/CXX/drs/dr15xx.cpp |  21 ++-
 clang/test/CXX/drs/dr16xx.cpp |  20 +--
 clang/test/CXX/drs/dr6xx.cpp  |  24 +--
 clang/test/CXX/expr/expr.const/p5-26.cpp  |   4 +-
 clang/test/CXX/special/class.copy/p13-0x.cpp  |   2 +-
 .../SemaCXX/constant-expression-cxx11.cpp |  38 +++--
 .../SemaCXX/constant-expression-cxx14.cpp |  33 ++--
 .../SemaCXX/constant-expression-cxx2b.cpp |  24 +--
 .../test/SemaCXX/cxx23-invalid-constexpr.cpp  | 159 ++
 clang/test/SemaCXX/cxx2a-consteval.cpp|   2 +-
 .../SemaCXX/deduced-return-type-cxx14.cpp |   8 +-
 .../addrspace-constructors.clcpp  |   2 +-
 clang/www/cxx_status.html |   9 +-
 27 files changed, 408 insertions(+), 269 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx23-invalid-constexpr.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e018d38355945f..5fe3fd066df235 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -102,6 +102,8 @@ C++23 Feature Support
   materialize temporary object which is a prvalue in discarded-value 
expression.
 - Implemented `P1774R8: Portable assumptions `_.
 
+- Implemented `P2448R2: Relaxing some constexpr restrictions 
`_.
+
 C++2c Feature Support
 ^
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 605fbc52701df0..d7ab1635cf12bc 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9617,13 +9617,10 @@ def err_defaulted_copy_assign_not_ref : Error<
   "the parameter for an explicitly-defaulted copy assignment operator must be 
an "
   "lvalue reference type">;
 def err_incorrect_defaulted_constexpr : Error<
-  "defaulted definition of %sub{select_special_member_kind}0 "
-  "is not constexpr">;
+  "defaulted definition of %sub{select_special_member_kind}0 cannot be marked 
%select{constexpr|consteval}1 "
+  "before C++23">;
 def err_incorrect_defaulted_constexpr_with_vb: Error<
   "%sub{select_special_member_kind}0 cannot be 'constexpr' in a class with 
virtual base class">;
-def err_incorrect_defaulted_consteval : Error<
-  "defaulted declaration of %sub{select_special_member_kind}0 "
-  "cannot be consteval because implicit definition is not constexpr">;
 def warn_defaulted_method_deleted : Warning<
   "explicitly defaulted %sub{select_special_member_kind}0 is implicitly "
   "deleted">, InGroup;
@@ -9734,21 +9731,12 @@ def 
note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
   "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
-def ext_defaulted_comparison_constexpr_mismatch : Extension<
+def err_defaulted_comparison_constexpr_mismatch : Error<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
-  "three-way comparison operator}0 that is "
-  "declared %select{constexpr|consteval}2 but"
-  "%select{|for which the corresponding implicit 'operator==' }0 "
-  "invokes a non-constexpr comparison function is a C++23 extension">,
-  InGroup>;
-def warn_cxx23_compat_defaulted_comparison_constexpr_mismatch : Warning<
-  "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
-  "three-way comparison operator}0 that is "
-  "declared %select{constexpr|consteval}2 but"
-  "%select{|for which the corresponding implicit 'operator==' }0 "
-  "invokes a non-constexpr comparison function is 

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread via cfe-commits

dyung wrote:

> Nevermind, unreverted since there appear to be newer tests that use this 
> patch.

@amykhuang your unrevert (9bfa506d69b9177ced00b69bf94b28038b063d6d) appears to 
be an empty commit? Was that intended?

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


[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)

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


@@ -0,0 +1,115 @@
+//===--- UEFI.h - UEFI ToolChain Implementations --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UEFI.h"
+#include "CommonArgs.h"
+#include "Darwin.h"
+#include "clang/Basic/CharInfo.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/TargetParser/Host.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang;
+using namespace llvm::opt;
+
+UEFI::UEFI(const Driver , const llvm::Triple , const ArgList )
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)
+getProgramPaths().push_back(getDriver().Dir);
+}
+
+Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); }
+
+void tools::uefi::Linker::ConstructJob(Compilation , const JobAction ,
+   const InputInfo ,
+   const InputInfoList ,
+   const ArgList ,
+   const char *LinkingOutput) const {
+  ArgStringList CmdArgs;
+
+  auto  = static_cast(getToolChain());
+
+  assert((Output.isFilename() || Output.isNothing()) && "invalid output");
+  if (Output.isFilename())
+CmdArgs.push_back(
+Args.MakeArgString(std::string("-out:") + Output.getFilename()));
+
+  CmdArgs.push_back("-nologo");
+
+  // TODO: Other UEFI binary subsystems that are currently unsupported:
+  // efi_boot_service_driver, efi_rom, efi_runtime_driver.
+  CmdArgs.push_back("-subsystem:efi_application");
+
+  // Default entry function name according to the TianoCore reference
+  // implementation is EfiMain.
+  // TODO: Provide a flag to override the entry function name.
+  CmdArgs.push_back("-entry:EfiMain");
+
+  // "Terminal Service Aware" flag is not needed for UEFI applications.
+  CmdArgs.push_back("-tsaware:no");
+
+  // EFI_APPLICATION to be linked as DLL by default.
+  CmdArgs.push_back("-dll");
+
+  if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
+CmdArgs.push_back("-debug");

MaskRay wrote:

This logic from MSVC.cpp seems incorrect to me. If the intention is for  `-g` 
to enable `-debug`, then `-g -g0` should be able to remove `-debug`.

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


[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)

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


@@ -0,0 +1,92 @@
+//===--- UEFI.h - UEFI ToolChain Implementations --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UEFI.h"
+#include "CommonArgs.h"
+#include "Darwin.h"
+#include "clang/Basic/CharInfo.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/TargetParser/Host.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang;
+using namespace llvm::opt;
+
+UEFI::UEFI(const Driver , const llvm::Triple , const ArgList )
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)
+getProgramPaths().push_back(getDriver().Dir);
+}
+
+Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); }
+
+void tools::uefi::Linker::ConstructJob(Compilation , const JobAction ,
+   const InputInfo ,
+   const InputInfoList ,
+   const ArgList ,
+   const char *LinkingOutput) const {
+  ArgStringList CmdArgs;
+  auto  = static_cast(getToolChain());
+
+  assert((Output.isFilename() || Output.isNothing()) && "invalid output");
+  if (Output.isFilename())
+CmdArgs.push_back(
+Args.MakeArgString(std::string("-out:") + Output.getFilename()));
+
+  CmdArgs.push_back("-nologo");
+
+  // TODO: Other UEFI binary subsystems that are currently unsupported:
+  // efi_boot_service_driver, efi_rom, efi_runtime_driver.
+  CmdArgs.push_back("-subsystem:efi_application");
+
+  // Default entry function name according to the TianoCore reference
+  // implementation is EfiMain.
+  // TODO: Provide a flag to override the entry function name.
+  CmdArgs.push_back("-entry:EfiMain");
+
+  // "Terminal Service Aware" flag is not needed for UEFI applications.
+  CmdArgs.push_back("-tsaware:no");
+
+  // EFI_APPLICATION to be linked as DLL by default.
+  CmdArgs.push_back("-dll");
+
+  if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
+CmdArgs.push_back("-debug");
+
+  Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
+
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  // This should ideally be handled by ToolChain::GetLinkerPath but we need
+  // to special case some linker paths. In the case of lld, we need to
+  // translate 'lld' into 'lld-link'.
+  StringRef Linker =
+  Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
+  if (Linker.empty() || Linker.equals("lld"))
+Linker = "lld-link";
+
+  auto LinkerPath = TC.GetProgramPath(Linker.str().c_str());
+  auto LinkCmd = std::make_unique(
+  JA, *this, ResponseFileSupport::AtFileUTF16(),

MaskRay wrote:

Is this intended to be UTF-16 like MSVC?

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


[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)

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


@@ -0,0 +1,92 @@
+//===--- UEFI.h - UEFI ToolChain Implementations --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UEFI.h"
+#include "CommonArgs.h"
+#include "Darwin.h"
+#include "clang/Basic/CharInfo.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/TargetParser/Host.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang;
+using namespace llvm::opt;
+
+UEFI::UEFI(const Driver , const llvm::Triple , const ArgList )
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)
+getProgramPaths().push_back(getDriver().Dir);
+}
+
+Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); }
+
+void tools::uefi::Linker::ConstructJob(Compilation , const JobAction ,
+   const InputInfo ,
+   const InputInfoList ,
+   const ArgList ,
+   const char *LinkingOutput) const {
+  ArgStringList CmdArgs;
+  auto  = static_cast(getToolChain());
+
+  assert((Output.isFilename() || Output.isNothing()) && "invalid output");
+  if (Output.isFilename())
+CmdArgs.push_back(
+Args.MakeArgString(std::string("-out:") + Output.getFilename()));
+
+  CmdArgs.push_back("-nologo");
+
+  // TODO: Other UEFI binary subsystems that are currently unsupported:
+  // efi_boot_service_driver, efi_rom, efi_runtime_driver.
+  CmdArgs.push_back("-subsystem:efi_application");
+
+  // Default entry function name according to the TianoCore reference
+  // implementation is EfiMain.
+  // TODO: Provide a flag to override the entry function name.
+  CmdArgs.push_back("-entry:EfiMain");
+
+  // "Terminal Service Aware" flag is not needed for UEFI applications.
+  CmdArgs.push_back("-tsaware:no");
+
+  // EFI_APPLICATION to be linked as DLL by default.
+  CmdArgs.push_back("-dll");
+
+  if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
+CmdArgs.push_back("-debug");
+
+  Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
+
+  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+
+  // This should ideally be handled by ToolChain::GetLinkerPath but we need
+  // to special case some linker paths. In the case of lld, we need to
+  // translate 'lld' into 'lld-link'.
+  StringRef Linker =
+  Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
+  if (Linker.empty() || Linker.equals("lld"))

MaskRay wrote:

Nit: Prefer `==` to `equals`

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


[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)

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


@@ -0,0 +1,92 @@
+//===--- UEFI.h - UEFI ToolChain Implementations --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UEFI.h"
+#include "CommonArgs.h"
+#include "Darwin.h"
+#include "clang/Basic/CharInfo.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/TargetParser/Host.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang;
+using namespace llvm::opt;
+
+UEFI::UEFI(const Driver , const llvm::Triple , const ArgList )
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)
+getProgramPaths().push_back(getDriver().Dir);
+}
+
+Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); }
+
+void tools::uefi::Linker::ConstructJob(Compilation , const JobAction ,
+   const InputInfo ,
+   const InputInfoList ,
+   const ArgList ,
+   const char *LinkingOutput) const {
+  ArgStringList CmdArgs;
+  auto  = static_cast(getToolChain());
+
+  assert((Output.isFilename() || Output.isNothing()) && "invalid output");
+  if (Output.isFilename())
+CmdArgs.push_back(
+Args.MakeArgString(std::string("-out:") + Output.getFilename()));
+
+  CmdArgs.push_back("-nologo");
+
+  // TODO: Other UEFI binary subsystems that are currently unsupported:
+  // efi_boot_service_driver, efi_rom, efi_runtime_driver.
+  CmdArgs.push_back("-subsystem:efi_application");
+
+  // Default entry function name according to the TianoCore reference
+  // implementation is EfiMain.
+  // TODO: Provide a flag to override the entry function name.
+  CmdArgs.push_back("-entry:EfiMain");
+
+  // "Terminal Service Aware" flag is not needed for UEFI applications.
+  CmdArgs.push_back("-tsaware:no");
+
+  // EFI_APPLICATION to be linked as DLL by default.
+  CmdArgs.push_back("-dll");
+
+  if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
+CmdArgs.push_back("-debug");
+
+  Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);

MaskRay wrote:

We need tests for this.

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


[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)

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


@@ -0,0 +1,92 @@
+//===--- UEFI.h - UEFI ToolChain Implementations --*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UEFI.h"
+#include "CommonArgs.h"
+#include "Darwin.h"
+#include "clang/Basic/CharInfo.h"
+#include "clang/Basic/Version.h"
+#include "clang/Config/config.h"
+#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/Options.h"
+#include "clang/Driver/SanitizerArgs.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Option/Arg.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
+#include "llvm/TargetParser/Host.h"
+
+using namespace clang::driver;
+using namespace clang::driver::toolchains;
+using namespace clang;
+using namespace llvm::opt;
+
+UEFI::UEFI(const Driver , const llvm::Triple , const ArgList )
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != getDriver().Dir)

MaskRay wrote:

I have removed getInstalledDir in #80527 and follow-ups. This needs an update.

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


[clang] [Driver,CrossWindows] Remove -isystem-after (PR #84121)

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

MaskRay wrote:

> > Facebook was using it at one point (can't say if they are currently), I 
> > know that Sony had some interested users as well.
> > Yes, the order matters - that was the reason that the flag was implemented 
> > in the first place.
> 
> Cc @smeenai @pogo59 on whether this option is used.
> 
> In addition, is `*-windows-itanium` used?

Most updates to CrossWindows are actually updates to other `ToolChain`s and the 
author happened to notice that CrossWindows needs an update as well.
There has been no specific update to CrossWindows, since at least 2017.

The 2017 change to CrossWindows (https://reviews.llvm.org/D36364) was really 
for mingw.

https://github.com/llvm/llvm-project/pull/84121
___
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-13 Thread Nikita Popov via cfe-commits

nikic wrote:

@goldsteinn Doesn't seem worthwhile.

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] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

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

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


[clang] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

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


@@ -0,0 +1,105 @@
+; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
+
+; Make sure dxil operation function calls for any are generated for float and 
half.
+
+; CHECK:icmp ne i1 %{{.*}}, false

farzonl wrote:

That was my thinking as well, but all the other tests in this directory lacked 
the space and I didn't want to go against the the grain.

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


[clang] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

2024-03-13 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,105 @@
+; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
+
+; Make sure dxil operation function calls for any are generated for float and 
half.
+
+; CHECK:icmp ne i1 %{{.*}}, false

bogner wrote:

Folks usually put a space between `CHECK:` and the thing being checked (`CHECK: 
icmp ...`). I find that slightly more readable.

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


[clang] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

2024-03-13 Thread Justin Bogner via cfe-commits

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

A couple more very minor notes on the tests, then this LGTM

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


[clang] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

2024-03-13 Thread Justin Bogner via cfe-commits


@@ -0,0 +1,105 @@
+; RUN: opt -S -dxil-op-lower < %s | FileCheck %s
+
+; Make sure dxil operation function calls for any are generated for float and 
half.
+
+; CHECK:icmp ne i1 %{{.*}}, false
+define noundef i1 @any_bool(i1 noundef %p0) {

bogner wrote:

Probably worth adding a `; CHECK-LABEL: define {{.*}} @any_bool` or so to make 
sure these checks are looking at the right functions and also potentially 
improve the error message if they fail

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


[clang] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

2024-03-13 Thread Justin Bogner via cfe-commits

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


[clang] Unrevert "[Clang][C++23] Implement P2448R2: Relaxing some constexpr re… (PR #85140)

2024-03-13 Thread Amy Huang via cfe-commits

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


[clang] [Driver,CrossWindows] Remove -isystem-after (PR #84121)

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

MaskRay wrote:

> Facebook was using it at one point (can't say if they are currently), I know 
> that Sony had some interested users as well.
> 
> Yes, the order matters - that was the reason that the flag was implemented in 
> the first place.

Cc @smeenai @pogo59 on whether this option is used.

In addition, is `*-windows-itanium` used?

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


[clang] [llvm] [HLSL] Implement `rsqrt` intrinsic (PR #84820)

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

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/84820

>From a46ecdee6356e744a80f3c29748e7c3482a89760 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Mon, 11 Mar 2024 15:17:35 -0400
Subject: [PATCH 1/3] [HLSL] Implement `rsqrt` intrinsic This change implements
 #70074 - `hlsl_intrinsics.h - add the rsqrt api - `DXIL.td` add the llvm
 intrinsic to DXIL op lowering map. - `Builtins.td` - add an hlsl builtin for
 rsqrt. - `CGBuiltin.cpp` add the ir generation for the rsqrt intrinsic. -
 `SemaChecking.cpp` - reuse the one arg float only  checks. -
 `IntrinsicsDirectX.td -add an `rsqrt` intrinsic.

---
 clang/include/clang/Basic/Builtins.td |  6 +++
 clang/lib/CodeGen/CGBuiltin.cpp   |  8 +++
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 32 +++
 clang/lib/Sema/SemaChecking.cpp   |  1 +
 clang/test/CodeGenHLSL/builtins/rsqrt.hlsl| 53 +++
 clang/test/SemaHLSL/BuiltIns/dot-warning.ll   | 49 +
 .../test/SemaHLSL/BuiltIns/rsqrt-errors.hlsl  | 27 ++
 llvm/include/llvm/IR/IntrinsicsDirectX.td |  1 +
 llvm/lib/Target/DirectX/DXIL.td   |  3 ++
 llvm/test/CodeGen/DirectX/rsqrt.ll| 31 +++
 10 files changed, 211 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/rsqrt.hlsl
 create mode 100644 clang/test/SemaHLSL/BuiltIns/dot-warning.ll
 create mode 100644 clang/test/SemaHLSL/BuiltIns/rsqrt-errors.hlsl
 create mode 100644 llvm/test/CodeGen/DirectX/rsqrt.ll

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 9c703377ca8d3e..de0cfb4e46b8bd 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4590,6 +4590,12 @@ def HLSLRcp : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLRSqrt : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_elementwise_rsqrt"];
+  let Attributes = [NoThrow, Const, CustomTypeChecking];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 20c35757939152..d2c83a5e405f42 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18077,6 +18077,14 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 /*ReturnType=*/Op0->getType(), Intrinsic::dx_rcp,
 ArrayRef{Op0}, nullptr, "dx.rcp");
   }
+  case Builtin::BI__builtin_hlsl_elementwise_rsqrt: {
+Value *Op0 = EmitScalarExpr(E->getArg(0));
+if (!E->getArg(0)->getType()->hasFloatingRepresentation())
+  llvm_unreachable("rsqrt operand must have a float representation");
+return Builder.CreateIntrinsic(
+/*ReturnType=*/Op0->getType(), Intrinsic::dx_rsqrt,
+ArrayRef{Op0}, nullptr, "dx.rsqrt");
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 45f8544392584e..71238a4f268ede 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1153,6 +1153,38 @@ double3 rcp(double3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rcp)
 double4 rcp(double4);
 
+//===--===//
+// rsqrt builtins
+//===--===//
+
+/// \fn T rsqrt(T x)
+/// \brief RReturns the reciprocal of the square root of the specified value \a
+/// x. \param x The specified input value.
+///
+/// This function uses the following formula: 1 / sqrt(x).
+
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rsqrt)
+half rsqrt(half);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rsqrt)
+half2 rsqrt(half2);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rsqrt)
+half3 rsqrt(half3);
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rsqrt)
+half4 rsqrt(half4);
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rsqrt)
+float rsqrt(float);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rsqrt)
+float2 rsqrt(float2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rsqrt)
+float3 rsqrt(float3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_rsqrt)
+float4 rsqrt(float4);
+
 
//===--===//
 // round builtins
 
//===--===//
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a5f42b630c3fa2..0dafff47ab4040 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5285,6 +5285,7 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr 

[clang] [Clang][C++23] Implement P2448R2: Relaxing some constexpr restrictions (PR #77753)

2024-03-13 Thread Amy Huang via cfe-commits

amykhuang wrote:

Nevermind, unreverted since there appear to be newer tests that use this patch. 

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


[clang] Unrevert "[Clang][C++23] Implement P2448R2: Relaxing some constexpr re… (PR #85140)

2024-03-13 Thread Amy Huang via cfe-commits

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


[clang] [llvm] [AIX][TOC] Add -mtocdata/-mno-tocdata options on AIX (PR #67999)

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


@@ -404,6 +404,15 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// List of pass builder callbacks.
   std::vector> PassBuilderCallbacks;
 
+  /// List of global variables explicitly specified by the user as toc-data.
+  std::vector TocDataVarsUserSpecified;
+
+  /// List of global variables that over-ride the toc-data default.
+  std::vector NoTocDataVars;
+
+  /// Flag for all global variables to be treated as toc-data.
+  bool AllTocData;

MaskRay wrote:

The uninitialized `AllTocData` would cause memorysanitizer failures.
booleans and enums should be moved to `CodeGenOptionsBase` using 
`clang/Basic/CodeGenOptions.def`.
I fixed this in 605abe0689dfd28aadc9413306f33a4494cf3fb8

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


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

2024-03-13 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/3] 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 

[clang] 605abe0 - [clang] Initialize AllTocData after #67999

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

Author: Fangrui Song
Date: 2024-03-13T15:06:55-07:00
New Revision: 605abe0689dfd28aadc9413306f33a4494cf3fb8

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

LOG: [clang] Initialize AllTocData after #67999

Added: 


Modified: 
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h

Removed: 




diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 6ad05031962562..340b08dd7e2a33 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -59,6 +59,7 @@ CODEGENOPT(UniqueBasicBlockSectionNames, 1, 1) ///< Set for 
-funique-basic-block
///< basic block sections.
 CODEGENOPT(EnableAIXExtendedAltivecABI, 1, 0) ///< Set for -mabi=vec-extabi. 
Enables the extended Altivec ABI on AIX.
 CODEGENOPT(XCOFFReadOnlyPointers, 1, 0) ///< Set for -mxcoff-roptr.
+CODEGENOPT(AllTocData, 1, 0) ///< AIX -mtocdata
 ENUM_CODEGENOPT(FramePointer, FramePointerKind, 2, FramePointerKind::None) /// 
frame-pointer: all,non-leaf,none
 
 CODEGENOPT(ClearASTBeforeBackend , 1, 0) ///< Free the AST before running 
backend code generation. Only works with -disable-free.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index cf29e576ef3209..9469a424045bb0 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -410,9 +410,6 @@ class CodeGenOptions : public CodeGenOptionsBase {
   /// List of global variables that over-ride the toc-data default.
   std::vector NoTocDataVars;
 
-  /// Flag for all global variables to be treated as toc-data.
-  bool AllTocData;
-
   /// Path to allowlist file specifying which objects
   /// (files, functions) should exclusively be instrumented
   /// by sanitizer coverage pass.



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


[clang] [clang][analyzer] Fix crash in loop unrolling (PR #82089)

2024-03-13 Thread Balazs Benics via cfe-commits

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

>From 2802ef4b9ed88da3cacb16ab7738907ee806 Mon Sep 17 00:00:00 2001
From: huang-me 
Date: Sat, 17 Feb 2024 10:43:48 +0800
Subject: [PATCH 1/8] Fix crash on StaticAnalyzer loop unrolling

---
 clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp 
b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index a80352816be613..4001268bde6677 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -226,6 +226,17 @@ static bool isPossiblyEscaped(ExplodedNode *N, const 
DeclRefExpr *DR) {
   return false;
   }
 }
+
+if (const SwitchStmt *SS = dyn_cast(S)) {
+  for (const Stmt *CB : dyn_cast(SS->getBody())->body()) {
+for (const Decl *D : dyn_cast(CB)->decls()) {
+  // Once we reach the declaration of the VD we can return.
+  if (D->getCanonicalDecl() == VD)
+return false;
+}
+  }
+}
+
 // Check the usage of the pass-by-ref function calls and adress-of operator
 // on VD and reference initialized by VD.
 ASTContext  =

>From e9e195e4462da7f3ca2317096ddace6ce3e88d13 Mon Sep 17 00:00:00 2001
From: huang-me 
Date: Mon, 19 Feb 2024 18:17:27 +0800
Subject: [PATCH 2/8] Check if dynamic cast get pointer to valid elements

---
 clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp 
b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index 4001268bde6677..093e9bbf4ce5e0 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -228,11 +228,15 @@ static bool isPossiblyEscaped(ExplodedNode *N, const 
DeclRefExpr *DR) {
 }
 
 if (const SwitchStmt *SS = dyn_cast(S)) {
-  for (const Stmt *CB : dyn_cast(SS->getBody())->body()) {
-for (const Decl *D : dyn_cast(CB)->decls()) {
-  // Once we reach the declaration of the VD we can return.
-  if (D->getCanonicalDecl() == VD)
-return false;
+  if (const CompoundStmt *CST = dyn_cast(SS->getBody())) {
+for (const Stmt *CB : CST->body()) {
+  if (const DeclStmt *DST = dyn_cast(CB)) {
+for (const Decl *D : DST->decls()) {
+  // Once we reach the declaration of the VD we can return.
+  if (D->getCanonicalDecl() == VD)
+return false;
+}
+  }
 }
   }
 }

>From 6ed9ea88865e91f1727077b1a3a24d7b110060fd Mon Sep 17 00:00:00 2001
From: huang-me 
Date: Tue, 20 Feb 2024 11:31:23 +0800
Subject: [PATCH 3/8] Add testcase for finding declaration within SwitchStmt

---
 .../test-escaping-on-var-before-switch-case.c | 11 +++
 1 file changed, 11 insertions(+)
 create mode 100644 
clang/test/Analysis/test-escaping-on-var-before-switch-case.c

diff --git a/clang/test/Analysis/test-escaping-on-var-before-switch-case.c 
b/clang/test/Analysis/test-escaping-on-var-before-switch-case.c
new file mode 100644
index 00..95aed8cab06b55
--- /dev/null
+++ b/clang/test/Analysis/test-escaping-on-var-before-switch-case.c
@@ -0,0 +1,11 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config 
unroll-loops=true -verify %s
+
+void test_escaping_on_var_before_switch_case_no_crash(int c) {
+  switch (c) {
+int i; // expected error{{Reached root without finding the declaration of 
VD}}
+case 0: {
+  for (i = 0; i < 16; i++) {}
+  break;
+}
+  }
+}

>From 294b7c960233cbef8ee0d8721c60792fd1e6a064 Mon Sep 17 00:00:00 2001
From: huang-me 
Date: Thu, 22 Feb 2024 21:04:06 +0800
Subject: [PATCH 4/8] Hoist duplicated code into function

---
 .../lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 29 ++-
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp 
b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index 093e9bbf4ce5e0..697e811470e708 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -190,6 +190,17 @@ static bool isCapturedByReference(ExplodedNode *N, const 
DeclRefExpr *DR) {
   return FD->getType()->isReferenceType();
 }
 
+static bool isFoundInStmt(const Stmt *S, const VarDecl *VD) {
+  if (const DeclStmt *DS = dyn_cast(S)) {
+for (const Decl *D : DS->decls()) {
+  // Once we reach the declaration of the VD we can return.
+  if (D->getCanonicalDecl() == VD)
+return true;
+}
+  }
+  return false;
+}
+
 // A loop counter is considered escaped if:
 // case 1: It is a global variable.
 // case 2: It is a reference parameter or a reference capture.
@@ -219,24 +230,16 @@ static bool isPossiblyEscaped(ExplodedNode *N, const 
DeclRefExpr *DR) {
   

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

2024-03-13 Thread via cfe-commits

goldsteinn wrote:

@nikic, what do you think about adding `nneg` for `uitofp`?

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] [llvm] [DXIL] `exp`, `any`, `lerp`, & `rcp` Intrinsic Lowering (PR #84526)

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

https://github.com/farzonl updated 
https://github.com/llvm/llvm-project/pull/84526

>From 7dde8faaad046b715027a0f9fb772af90b6ffb30 Mon Sep 17 00:00:00 2001
From: Farzon Lotfi 
Date: Thu, 7 Mar 2024 20:48:46 -0500
Subject: [PATCH 1/4] [DXIL] exp, any, lerp, & rcp Intrinsic Lowering This
 change implements lowering for #70076, #70100, #70072, & #70102 CGBuiltin.cpp
 - - simplify lerp intrinsic IntrinsicsDirectX.td - simplify lerp intrinsic
 SemaChecking.cpp - remove unnecessary check DXILIntrinsicExpansion.* - add
 intrinsic to instruction expansion cases DXILOpLowering.cpp -  make sure
 DXILIntrinsicExpansion happens first DirectX.h - changes to support new pass
 DirectXTargetMachine.cpp - changes to support new pass

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  35 +---
 clang/lib/Sema/SemaChecking.cpp   |   2 -
 clang/test/CodeGenHLSL/builtins/lerp.hlsl |  13 +-
 llvm/include/llvm/IR/IntrinsicsDirectX.td |   5 +-
 llvm/lib/Target/DirectX/CMakeLists.txt|   1 +
 .../Target/DirectX/DXILIntrinsicExpansion.cpp | 187 ++
 .../Target/DirectX/DXILIntrinsicExpansion.h   |  33 
 llvm/lib/Target/DirectX/DXILOpLowering.cpp|   6 +-
 llvm/lib/Target/DirectX/DirectX.h |   6 +
 .../Target/DirectX/DirectXTargetMachine.cpp   |   2 +
 llvm/test/CodeGen/DirectX/any.ll  | 133 +
 llvm/test/CodeGen/DirectX/exp-vec.ll  |  23 +++
 llvm/test/CodeGen/DirectX/exp.ll  |  38 
 llvm/test/CodeGen/DirectX/lerp.ll |  64 ++
 llvm/test/CodeGen/DirectX/rcp.ll  |  63 ++
 15 files changed, 564 insertions(+), 47 deletions(-)
 create mode 100644 llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
 create mode 100644 llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h
 create mode 100644 llvm/test/CodeGen/DirectX/any.ll
 create mode 100644 llvm/test/CodeGen/DirectX/exp-vec.ll
 create mode 100644 llvm/test/CodeGen/DirectX/exp.ll
 create mode 100644 llvm/test/CodeGen/DirectX/lerp.ll
 create mode 100644 llvm/test/CodeGen/DirectX/rcp.ll

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 93ab465079777b..25e4793c3e22d8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18015,38 +18015,11 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 Value *X = EmitScalarExpr(E->getArg(0));
 Value *Y = EmitScalarExpr(E->getArg(1));
 Value *S = EmitScalarExpr(E->getArg(2));
-llvm::Type *Xty = X->getType();
-llvm::Type *Yty = Y->getType();
-llvm::Type *Sty = S->getType();
-if (!Xty->isVectorTy() && !Yty->isVectorTy() && !Sty->isVectorTy()) {
-  if (Xty->isFloatingPointTy()) {
-auto V = Builder.CreateFSub(Y, X);
-V = Builder.CreateFMul(S, V);
-return Builder.CreateFAdd(X, V, "dx.lerp");
-  }
-  llvm_unreachable("Scalar Lerp is only supported on floats.");
-}
-// A VectorSplat should have happened
-assert(Xty->isVectorTy() && Yty->isVectorTy() && Sty->isVectorTy() &&
-   "Lerp of vector and scalar is not supported.");
-
-[[maybe_unused]] auto *XVecTy =
-E->getArg(0)->getType()->getAs();
-[[maybe_unused]] auto *YVecTy =
-E->getArg(1)->getType()->getAs();
-[[maybe_unused]] auto *SVecTy =
-E->getArg(2)->getType()->getAs();
-// A HLSLVectorTruncation should have happend
-assert(XVecTy->getNumElements() == YVecTy->getNumElements() &&
-   XVecTy->getNumElements() == SVecTy->getNumElements() &&
-   "Lerp requires vectors to be of the same size.");
-assert(XVecTy->getElementType()->isRealFloatingType() &&
-   XVecTy->getElementType() == YVecTy->getElementType() &&
-   XVecTy->getElementType() == SVecTy->getElementType() &&
-   "Lerp requires float vectors to be of the same type.");
+if (!E->getArg(0)->getType()->hasFloatingRepresentation())
+  llvm_unreachable("lerp operand must have a float representation");
 return Builder.CreateIntrinsic(
-/*ReturnType=*/Xty, Intrinsic::dx_lerp, ArrayRef{X, Y, S},
-nullptr, "dx.lerp");
+/*ReturnType=*/X->getType(), Intrinsic::dx_lerp,
+ArrayRef{X, Y, S}, nullptr, "dx.lerp");
   }
   case Builtin::BI__builtin_hlsl_elementwise_frac: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index a5f42b630c3fa2..8a2b7384a0b0d5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5300,8 +5300,6 @@ bool Sema::CheckHLSLBuiltinFunctionCall(unsigned 
BuiltinID, CallExpr *TheCall) {
   return true;
 if (SemaBuiltinElementwiseTernaryMath(TheCall))
   return true;
-if (CheckAllArgsHaveFloatRepresentation(this, TheCall))
-  return true;
 break;
   }
   case Builtin::BI__builtin_hlsl_mad: {
diff --git a/clang/test/CodeGenHLSL/builtins/lerp.hlsl 

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

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


@@ -1,13 +1,58 @@
-// RUN: %clang_cc1 %s -verify=c -fsyntax-only
+// RUN: %clang_cc1 %s -verify -fsyntax-only
 // RUN: %clang_cc1 %s -verify -fsyntax-only -x c++
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility
 // RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -x c++
+// RUN: %clang_cc1 %s -verify=gnu -fsyntax-only 
-Wgnu-flexible-array-union-member -Wgnu-empty-struct
+// RUN: %clang_cc1 %s -verify=microsoft -fsyntax-only -fms-compatibility 
-Wmicrosoft
 
 // The test checks that an attempt to initialize union with flexible array
 // member with an initializer list doesn't crash clang.
 
 
-union { char x[]; } r = {0}; // c-error {{flexible array member 'x' in a union 
is not allowed}}
+union { char x[]; } r = {0}; /* gnu-warning {{flexible array member 'x' in a 
union is a GNU extension}}
+microsoft-warning {{flexible array member 'x' 
in a union is a Microsoft extension}}
+  */

kees wrote:

Clang's initialization for flexible arrays works for all the cases I've 
checked. Part of Linux's migration to C99 flex arrays uncovered a 
`__builtin_object_size()` bug that has was fixed in Clang 17 via commit 
804af933f7310f78d91e13ad8a13b64b00249614 which includes several initialization 
tests beyond the ones that are touched in this PR. As a result I have 
confidence in this having appropriate test coverage, though if more is needed, 
it should be trivial to add.

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][analyzer] Fix crash in loop unrolling (PR #82089)

2024-03-13 Thread Balazs Benics via cfe-commits


@@ -1,5 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
-analyzer-config unroll-loops=true,cfg-loopexit=true -verify -std=c++14 
-analyzer-config exploration_strategy=unexplored_first_queue %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
-analyzer-config unroll-loops=true,cfg-loopexit=true,exploration_strategy=dfs 
-verify -std=c++14 -DDFS=1 %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config 
unroll-loops=true -verify %s
+// expected-no-diagnostics

steakhal wrote:

```suggestion
```

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


  1   2   3   4   5   >