[clang] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-09-30 Thread via cfe-commits


@@ -375,6 +375,10 @@ Bug Fixes to C++ Support
 - Fixed a bug causing destructors of constant-evaluated structured bindings
   initialized by array elements to be called in the wrong evaluation context.
 
+- Fix crash where ill-formed code was being treated as a deduction guide and
+  we now produce a diagnostic. Fixes:
+  (`65522 `_)

cor3ntin wrote:

```suggestion
  (`#65522 `_)
```

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


[clang-tools-extra] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-09-30 Thread via cfe-commits

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

LGTM Modulo nit

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


[clang] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-09-30 Thread via cfe-commits

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


[clang-tools-extra] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-09-30 Thread via cfe-commits

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Giulio Eulisse via cfe-commits

ktf wrote:

Thanks! If I were younger I would probably know how to post a dancing banana 
emoji at this point... ;-)

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Nikita Popov via cfe-commits

nikic wrote:

Looks like this causes a compile-time regression: 
https://llvm-compile-time-tracker.com/compare.php?from=abcaebfe3aacb13d46be5e949fd6ed9b4321e2f6&to=4ae51570806ba5c5fcabe6d6dcbe52e3a5d5453b&stat=instructions%3Au
 About 0.5% at `O0`.

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> Looks like this causes a compile-time regression: 
> https://llvm-compile-time-tracker.com/compare.php?from=abcaebfe3aacb13d46be5e949fd6ed9b4321e2f6&to=4ae51570806ba5c5fcabe6d6dcbe52e3a5d5453b&stat=instructions%3Au
>  About 0.5% at `O0`.

It is probably the change in the `SourceManager.cpp` in non-modules mode that 
caused it. IIUC, this is a memory regression and probably comes by the larger 
page/slab that we allocate. What would be the best way to profile this?

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


[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-09-30 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 updated this revision to Diff 557504.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158540/new/

https://reviews.llvm.org/D158540

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp


Index: clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
===
--- clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
+++ clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
@@ -23,6 +23,15 @@
   NoCopyMove ncm;
 };
 
+struct Base {
+ constexpr Base() = default;
+};
+struct Derived : virtual Base { // expected-note 3{{virtual base class 
declared here}}
+  constexpr Derived() = default; // expected-error {{default constructor 
cannot be 'constexpr' in a class with virtual base class}}
+  constexpr Derived(const Derived&) = default; // expected-error {{copy 
constructor cannot be 'constexpr' in a class with virtual base class}}
+  constexpr Derived(Derived&&) = default; // expected-error {{move constructor 
cannot be 'constexpr' in a class with virtual base class}}
+};
+
 // If a function is explicitly defaulted on its first declaration
 //   -- it is implicitly considered to be constexpr if the implicit declaration
 //  would be
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -7800,10 +7800,17 @@
   : isa(MD))) &&
   MD->isConstexpr() && !Constexpr &&
   MD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) {
-Diag(MD->getBeginLoc(), MD->isConsteval()
-? diag::err_incorrect_defaulted_consteval
-: diag::err_incorrect_defaulted_constexpr)
-<< CSM;
+if (!MD->isConsteval() && RD->getNumVBases()) {
+  Diag(MD->getBeginLoc(), 
diag::err_incorrect_defaulted_constexpr_with_vb)
+  << CSM;
+  for (const auto &I : RD->vbases())
+Diag(I.getBeginLoc(), diag::note_constexpr_virtual_base_here);
+} else {
+  Diag(MD->getBeginLoc(), MD->isConsteval()
+  ? diag::err_incorrect_defaulted_consteval
+  : 
diag::err_incorrect_defaulted_constexpr)
+  << CSM;
+}
 // FIXME: Explain why the special member can't be constexpr.
 HadError = true;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9395,6 +9395,8 @@
 def err_incorrect_defaulted_constexpr : Error<
   "defaulted definition of %sub{select_special_member_kind}0 "
   "is not constexpr">;
+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">;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -144,6 +144,8 @@
   tautologies like ``x && !x`` and ``!x || x`` in expressions. This also
   makes ``-Winfinite-recursion`` diagnose more cases.
   (`#56035: `_).
+- Clang now displays an improved diagnostic and a note when defaulted special 
+  member is a contexpr in a class with virtual base class
 
 Bug Fixes in This Version
 -


Index: clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
===
--- clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
+++ clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
@@ -23,6 +23,15 @@
   NoCopyMove ncm;
 };
 
+struct Base {
+ constexpr Base() = default;
+};
+struct Derived : virtual Base { // expected-note 3{{virtual base class declared here}}
+  constexpr Derived() = default; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base class}}
+  constexpr Derived(const Derived&) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class with virtual base class}}
+  constexpr Derived(Derived&&) = default; // expected-error {{move constructor cannot be 'constexpr' in a class with virtual base class}}
+};
+
 // If a function is explicitly defaulted on its first declaration
 //   -- it is implicitly considered to be constexpr if the implicit declaration
 //  would be
Index: clang/lib/Sema/SemaDeclCXX.cpp
===

[clang] Qualify non-dependent types of a class template with its declaration (PR #67566)

2023-09-30 Thread Luca Di sera via cfe-commits

diseraluca wrote:

> > > > I gave it a quick try, and we would still end up with the same result 
> > > > in our codebase. But, generally, this would not probably be feasible 
> > > > for us as a solution.
> > > 
> > > 
> > > do you have an idea why? Can you show the diff of the changes you made? 
> > > Is the void specialization not explicit?
> > 
> > 
> > I did a quick test with this:
> > ```
> > diff --git a/clang/lib/AST/QualTypeNames.cpp 
> > b/clang/lib/AST/QualTypeNames.cpp
> > index 26aaa96a1dc6..8b882eda83bb 100644
> > --- a/clang/lib/AST/QualTypeNames.cpp
> > +++ b/clang/lib/AST/QualTypeNames.cpp
> > @@ -287,8 +287,13 @@ static NestedNameSpecifier 
> > *createNestedNameSpecifierForScopeOf(
> >  //
> >  // Make the situation is 'useable' but looking a bit odd by
> >  // picking a random instance as the declaring context.
> > -if (ClassTempl->spec_begin() != ClassTempl->spec_end()) {
> > -  Decl = *(ClassTempl->spec_begin());
> > +auto specialization_iterator = std::find_if(
> > +ClassTempl->spec_begin(), ClassTempl->spec_end(), [](auto a) {
> > +  return !a->isExplicitInstantiationOrSpecialization();
> > +});
> > +
> > +if (specialization_iterator != ClassTempl->spec_end()) {
> > +  Decl = *specialization_iterator;
> >Outer = dyn_cast(Decl);
> >OuterNS = dyn_cast(Decl);
> >  }
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > Do please let me know if this is incorrect or if I misunderstood your 
> > proposal.
> > We do have explicit references to the void specialization in the codebase 
> > so it would explain the previous choice. But I'm not aware of why it would 
> > be chosen as a non-explicit one too.
> > I can try to debug that on Monday if that can be useful. Albeit it might 
> > take some time.
> 
> You probably need 
> [isExplicitSpecialization](https://clang.llvm.org/doxygen/classclang_1_1ClassTemplateSpecializationDecl.html#acd75ba25d34249d2e21ebbecbb2ef70e)()

Wouldn't `isExplicitSpecializationOrInstantiation` be a stronger guarantee than 
isExplicitSpecialization, such that it would exclude a superset of what is 
excluded by `isExplicitSpecialization`? If I did not misunderstand their source 
code.

Nonetheless, I've made a test run with `isExplicitSpecialization`, but in Qt's 
codebase we still get the same result.

I generally don't think we can depend on this kind of behavior, especially as 
it is far too difficult to control for the kind of consistency we want.

I initially missed the fact that the intention of this was to produce 
compilable code. While similar to our use-case it has slightly different 
requirements and I feel that may not be compatible with ours.

I think that is fine, and I think we don't need to force it to work for all use 
cases,  especially because I really don't want to break other people code. My 
assumption was that this might be an improvement for other use-cases too, but I 
failed to see the "give me code that compiles" use case.

The only thing that comes to mind would be to condition the behavior to be 
there or not. Similar to how we have `WighGlobalNsPrefix` we might have another 
boolean or similar, so that the default behavior remains the same but it can be 
conditioned to avoid this case.

But I don't think that is a particularly good solution, so I'm pretty happy 
with maintaining our own version too.

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


[clang] Qualify non-dependent types of a class template with its declaration (PR #67566)

2023-09-30 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> Wouldn't isExplicitSpecializationOrInstantiation be a stronger guarantee than 
> isExplicitSpecialization, such that it would exclude a superset of what is 
> excluded by isExplicitSpecialization? If I did not misunderstand their source 
> code.

I wanted to filter out instantiations.

> I generally don't think we can depend on this kind of behavior, especially as 
> it is far too difficult to control for the kind of consistency we want.

I think we could make the template specializations consistent so that you at 
least cure the symptom of your problem.

> My assumption was that this might be an improvement for other use-cases too, 
> but I failed to see the "give me code that compiles" use case.

Understood. That's a pretty strong requirement for this case and we cannot 
really make a compromise. The idea is to offer an API which gives the user how 
would they reach certain AST node from within the global scope if they had to 
type it.

> The only thing that comes to mind would be to condition the behavior to be 
> there or not. Similar to how we have WighGlobalNsPrefix we might have another 
> boolean or similar, so that the default behavior remains the same but it can 
> be conditioned to avoid this case.

I would avoid doing that. In fact, I still do not see why the proposed solution 
would not work. If it solves the minimal case that you provided in the 
description of this PR, I am afraid that there is some bit from the Qt setup 
that we do not understand.



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


[clang] [Support] Add KnownBits::computeForSubBorrow (PR #67788)

2023-09-30 Thread Christian Kissig via cfe-commits

https://github.com/christiankissig updated 
https://github.com/llvm/llvm-project/pull/67788

>From 5d86936c3a48c613460983c980271fcab8128b75 Mon Sep 17 00:00:00 2001
From: Christian Kissig 
Date: Tue, 26 Sep 2023 12:18:59 +
Subject: [PATCH 1/5] [Support] Add KnownBits::computeForSubBorrow

* Implements computeForSubBorrow as alias for computeforAddCarry. Borrow
  is expected to be 1-bit wide.
* Adds exhaustive unit test.
---
 llvm/include/llvm/Support/KnownBits.h|  4 +++
 llvm/lib/Support/KnownBits.cpp   | 12 +
 llvm/unittests/Support/KnownBitsTest.cpp | 31 
 3 files changed, 47 insertions(+)

diff --git a/llvm/include/llvm/Support/KnownBits.h 
b/llvm/include/llvm/Support/KnownBits.h
index 8462aa11202d5d7..711ca8c12129a1b 100644
--- a/llvm/include/llvm/Support/KnownBits.h
+++ b/llvm/include/llvm/Support/KnownBits.h
@@ -332,6 +332,10 @@ struct KnownBits {
   static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS,
 KnownBits RHS);
 
+  /// Compute known bits results from subtracting RHS from LHS.
+  static KnownBits computeForSubBorrow(const KnownBits &LHS, KnownBits RHS,
+   const KnownBits &Borrow);
+
   /// Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
   static KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS);
 
diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp
index 097c22d33dd12ba..99ac50a34666fce 100644
--- a/llvm/lib/Support/KnownBits.cpp
+++ b/llvm/lib/Support/KnownBits.cpp
@@ -85,6 +85,18 @@ KnownBits KnownBits::computeForAddSub(bool Add, bool NSW,
   return KnownOut;
 }
 
+KnownBits KnownBits::computeForSubBorrow(const KnownBits &LHS, KnownBits RHS,
+ const KnownBits &Borrow) {
+  assert(Borrow.getBitWidth() == 1 && "Borrow must be 1-bit");
+
+  // LHS - RHS = LHS + ~RHS + 1
+  // Carry 1 - Borrow in ::computeForAddCarry
+  std::swap(RHS.Zero, RHS.One);
+  return ::computeForAddCarry(LHS, RHS,
+  /*CarryZero*/ Borrow.One.getBoolValue(),
+  /*CarryOne*/ Borrow.Zero.getBoolValue());
+}
+
 KnownBits KnownBits::sextInReg(unsigned SrcBitWidth) const {
   unsigned BitWidth = getBitWidth();
   assert(0 < SrcBitWidth && SrcBitWidth <= BitWidth &&
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp 
b/llvm/unittests/Support/KnownBitsTest.cpp
index 9d184beea3ba9e9..5597d69ab248d23 100644
--- a/llvm/unittests/Support/KnownBitsTest.cpp
+++ b/llvm/unittests/Support/KnownBitsTest.cpp
@@ -213,6 +213,37 @@ TEST(KnownBitsTest, AddSubExhaustive) {
   TestAddSubExhaustive(false);
 }
 
+TEST(KnownBitsTest, SubBorrowExhaustive) {
+  unsigned Bits = 4;
+  ForeachKnownBits(Bits, [&](const KnownBits &Known1) {
+ForeachKnownBits(Bits, [&](const KnownBits &Known2) {
+  ForeachKnownBits(1, [&](const KnownBits &KnownBorrow) {
+// Explicitly compute known bits of the addition by trying all
+// possibilities.
+KnownBits Known(Bits);
+Known.Zero.setAllBits();
+Known.One.setAllBits();
+ForeachNumInKnownBits(Known1, [&](const APInt &N1) {
+  ForeachNumInKnownBits(Known2, [&](const APInt &N2) {
+ForeachNumInKnownBits(KnownBorrow, [&](const APInt &Borrow) {
+  APInt Sub = N1 - N2;
+  if (Borrow.getBoolValue())
+--Sub;
+
+  Known.One &= Sub;
+  Known.Zero &= ~Sub;
+});
+  });
+});
+
+KnownBits KnownComputed =
+KnownBits::computeForSubBorrow(Known1, Known2, KnownBorrow);
+EXPECT_EQ(Known, KnownComputed);
+  });
+});
+  });
+}
+
 TEST(KnownBitsTest, BinaryExhaustive) {
   testBinaryOpExhaustive(
   [](const KnownBits &Known1, const KnownBits &Known2) {

>From f84c882cf429df238054d88ee07e41a08ae3fd6c Mon Sep 17 00:00:00 2001
From: Christian Kissig 
Date: Tue, 26 Sep 2023 18:02:49 +
Subject: [PATCH 2/5] [CodeGen] Implement USUBC, USUBO_CARRY, and SSUBO_CARRY
 with KnownBits::computeForSubBorrow

---
 .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 12 ++
 .../CodeGen/AArch64SelectionDAGTest.cpp   | 24 +++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp 
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index cd21af770e1a4d9..ab3e9b4bdc67402 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -3732,14 +3732,18 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, 
const APInt &DemandedElts,
 assert(Op.getResNo() == 0 &&
"We only compute knownbits for the difference here.");
 
-// TODO: Compute influence of the carry operand.
+// With UADDO_CARRY and SSUBO_CARRY a borrow bit may be added in.
+KnownBits Borrow(1);
 if (Opcode == ISD::USUBO_CARRY || Opcode == ISD:

[libunwind] [Support] Add KnownBits::computeForSubBorrow (PR #67788)

2023-09-30 Thread Christian Kissig via cfe-commits

https://github.com/christiankissig updated 
https://github.com/llvm/llvm-project/pull/67788

>From 5d86936c3a48c613460983c980271fcab8128b75 Mon Sep 17 00:00:00 2001
From: Christian Kissig 
Date: Tue, 26 Sep 2023 12:18:59 +
Subject: [PATCH 1/5] [Support] Add KnownBits::computeForSubBorrow

* Implements computeForSubBorrow as alias for computeforAddCarry. Borrow
  is expected to be 1-bit wide.
* Adds exhaustive unit test.
---
 llvm/include/llvm/Support/KnownBits.h|  4 +++
 llvm/lib/Support/KnownBits.cpp   | 12 +
 llvm/unittests/Support/KnownBitsTest.cpp | 31 
 3 files changed, 47 insertions(+)

diff --git a/llvm/include/llvm/Support/KnownBits.h 
b/llvm/include/llvm/Support/KnownBits.h
index 8462aa11202d5d7..711ca8c12129a1b 100644
--- a/llvm/include/llvm/Support/KnownBits.h
+++ b/llvm/include/llvm/Support/KnownBits.h
@@ -332,6 +332,10 @@ struct KnownBits {
   static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS,
 KnownBits RHS);
 
+  /// Compute known bits results from subtracting RHS from LHS.
+  static KnownBits computeForSubBorrow(const KnownBits &LHS, KnownBits RHS,
+   const KnownBits &Borrow);
+
   /// Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
   static KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS);
 
diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp
index 097c22d33dd12ba..99ac50a34666fce 100644
--- a/llvm/lib/Support/KnownBits.cpp
+++ b/llvm/lib/Support/KnownBits.cpp
@@ -85,6 +85,18 @@ KnownBits KnownBits::computeForAddSub(bool Add, bool NSW,
   return KnownOut;
 }
 
+KnownBits KnownBits::computeForSubBorrow(const KnownBits &LHS, KnownBits RHS,
+ const KnownBits &Borrow) {
+  assert(Borrow.getBitWidth() == 1 && "Borrow must be 1-bit");
+
+  // LHS - RHS = LHS + ~RHS + 1
+  // Carry 1 - Borrow in ::computeForAddCarry
+  std::swap(RHS.Zero, RHS.One);
+  return ::computeForAddCarry(LHS, RHS,
+  /*CarryZero*/ Borrow.One.getBoolValue(),
+  /*CarryOne*/ Borrow.Zero.getBoolValue());
+}
+
 KnownBits KnownBits::sextInReg(unsigned SrcBitWidth) const {
   unsigned BitWidth = getBitWidth();
   assert(0 < SrcBitWidth && SrcBitWidth <= BitWidth &&
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp 
b/llvm/unittests/Support/KnownBitsTest.cpp
index 9d184beea3ba9e9..5597d69ab248d23 100644
--- a/llvm/unittests/Support/KnownBitsTest.cpp
+++ b/llvm/unittests/Support/KnownBitsTest.cpp
@@ -213,6 +213,37 @@ TEST(KnownBitsTest, AddSubExhaustive) {
   TestAddSubExhaustive(false);
 }
 
+TEST(KnownBitsTest, SubBorrowExhaustive) {
+  unsigned Bits = 4;
+  ForeachKnownBits(Bits, [&](const KnownBits &Known1) {
+ForeachKnownBits(Bits, [&](const KnownBits &Known2) {
+  ForeachKnownBits(1, [&](const KnownBits &KnownBorrow) {
+// Explicitly compute known bits of the addition by trying all
+// possibilities.
+KnownBits Known(Bits);
+Known.Zero.setAllBits();
+Known.One.setAllBits();
+ForeachNumInKnownBits(Known1, [&](const APInt &N1) {
+  ForeachNumInKnownBits(Known2, [&](const APInt &N2) {
+ForeachNumInKnownBits(KnownBorrow, [&](const APInt &Borrow) {
+  APInt Sub = N1 - N2;
+  if (Borrow.getBoolValue())
+--Sub;
+
+  Known.One &= Sub;
+  Known.Zero &= ~Sub;
+});
+  });
+});
+
+KnownBits KnownComputed =
+KnownBits::computeForSubBorrow(Known1, Known2, KnownBorrow);
+EXPECT_EQ(Known, KnownComputed);
+  });
+});
+  });
+}
+
 TEST(KnownBitsTest, BinaryExhaustive) {
   testBinaryOpExhaustive(
   [](const KnownBits &Known1, const KnownBits &Known2) {

>From f84c882cf429df238054d88ee07e41a08ae3fd6c Mon Sep 17 00:00:00 2001
From: Christian Kissig 
Date: Tue, 26 Sep 2023 18:02:49 +
Subject: [PATCH 2/5] [CodeGen] Implement USUBC, USUBO_CARRY, and SSUBO_CARRY
 with KnownBits::computeForSubBorrow

---
 .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 12 ++
 .../CodeGen/AArch64SelectionDAGTest.cpp   | 24 +++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp 
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index cd21af770e1a4d9..ab3e9b4bdc67402 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -3732,14 +3732,18 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, 
const APInt &DemandedElts,
 assert(Op.getResNo() == 0 &&
"We only compute knownbits for the difference here.");
 
-// TODO: Compute influence of the carry operand.
+// With UADDO_CARRY and SSUBO_CARRY a borrow bit may be added in.
+KnownBits Borrow(1);
 if (Opcode == ISD::USUBO_CARRY || Opcode == ISD:

[clang] 36c1e56 - [clang-format][NFC] Simplify the UnwrappedLine constructor

2023-09-30 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-09-30T02:03:14-07:00
New Revision: 36c1e568bb4f8e482e3f713c8cb9460c5cf19863

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

LOG: [clang-format][NFC] Simplify the UnwrappedLine constructor

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.h

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index 8faa99bdb6b5c55..4138baaabe2693d 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -40,26 +40,26 @@ struct UnwrappedLineNode;
 /// \c UnwrappedLineFormatter. The key property is that changing the formatting
 /// within an unwrapped line does not affect any other unwrapped lines.
 struct UnwrappedLine {
-  UnwrappedLine();
+  UnwrappedLine() = default;
 
   /// The \c Tokens comprising this \c UnwrappedLine.
   std::list Tokens;
 
   /// The indent level of the \c UnwrappedLine.
-  unsigned Level;
+  unsigned Level = 0;
 
   /// The \c PPBranchLevel (adjusted for header guards) if this line is a
   /// \c InMacroBody line, and 0 otherwise.
-  unsigned PPLevel;
+  unsigned PPLevel = 0;
 
   /// Whether this \c UnwrappedLine is part of a preprocessor directive.
-  bool InPPDirective;
+  bool InPPDirective = false;
   /// Whether this \c UnwrappedLine is part of a pramga directive.
-  bool InPragmaDirective;
+  bool InPragmaDirective = false;
   /// Whether it is part of a macro body.
-  bool InMacroBody;
+  bool InMacroBody = false;
 
-  bool MustBeDeclaration;
+  bool MustBeDeclaration = false;
 
   /// \c True if this line should be indented by ContinuationIndent in
   /// addition to the normal indention level.
@@ -410,11 +410,6 @@ struct UnwrappedLineNode {
   SmallVector Children;
 };
 
-inline UnwrappedLine::UnwrappedLine()
-: Level(0), PPLevel(0), InPPDirective(false), InPragmaDirective(false),
-  InMacroBody(false), MustBeDeclaration(false),
-  MatchingOpeningBlockLineIndex(kInvalidIndex) {}
-
 } // end namespace format
 } // end namespace clang
 



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


[clang] 511662b - [clang-format][NFC] Don't call startsSequence() in the parser

2023-09-30 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-09-30T02:09:52-07:00
New Revision: 511662b88c36f8d5d02f0b758b15c1b84d4ee6c1

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

LOG: [clang-format][NFC] Don't call startsSequence() in the parser

It always returns false in the unwrapped line parser!

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 336e23dc6ff6aee..bf38ed73c4a0b4e 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2278,8 +2278,7 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
 }
 
 void UnwrappedLineParser::tryToParseJSFunction() {
-  assert(FormatTok->is(Keywords.kw_function) ||
- FormatTok->startsSequence(Keywords.kw_async, Keywords.kw_function));
+  assert(FormatTok->is(Keywords.kw_function));
   if (FormatTok->is(Keywords.kw_async))
 nextToken();
   // Consume "function".
@@ -2357,8 +2356,7 @@ bool UnwrappedLineParser::parseBracedList(bool 
ContinueOnSemicolons,
   continue;
 }
 if (Style.isJavaScript()) {
-  if (FormatTok->is(Keywords.kw_function) ||
-  FormatTok->startsSequence(Keywords.kw_async, Keywords.kw_function)) {
+  if (FormatTok->is(Keywords.kw_function)) {
 tryToParseJSFunction();
 continue;
   }
@@ -2511,14 +2509,10 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
 nextToken();
   break;
 case tok::identifier:
-  if (Style.isJavaScript() &&
-  (FormatTok->is(Keywords.kw_function) ||
-   FormatTok->startsSequence(Keywords.kw_async,
- Keywords.kw_function))) {
+  if (Style.isJavaScript() && (FormatTok->is(Keywords.kw_function)))
 tryToParseJSFunction();
-  } else {
+  else
 nextToken();
-  }
   break;
 case tok::kw_requires: {
   auto RequiresToken = FormatTok;



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


[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2023-09-30 Thread kleines Filmröllchen via cfe-commits

kleinesfilmroellchen wrote:

I investigated the test failures some more in the context of where the bug 
affects real uses and I'm unsure as to what's going on.
```yaml
Style:
  QuotedHeaders: ["blahblahblah"]
  AngledHeaders: ["AK/.*", "Userland/.*", "Kernel/.*", "Applications/.*", 
"Lib.*/.*"]
```
will match all regexes correctly.
```yaml
Style:
  AngledHeaders: ["AK/.*", "Userland/.*", "Kernel/.*", "Applications/.*", 
"Lib.*/.*"]
```
will make AngledHeaders completely disappear from the parsed and compiled 
config; apparently the dictionary key doesn't even exist anymore. Exactly this 
behavior makes a test fail on CI.
```yaml
Style:
  QuotedHeaders: ["blahblahblah"]
```
will keep QuotedHeaders in the parsed and compiled config and works as expected.
There is no apparent difference in how these two keys are handled, I have 
cross-checked my config parser and compiler code with existing code countless 
times. Really no clue what's happening here other than QuotedHeaders apparently 
needs to exist or AngledHeaders vanishes.
CC @HighCommander4 

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


[PATCH] D158266: [OpenMP] Patch for Support to loop bind clause : Checking Parent Region

2023-09-30 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 557506.
koops added a comment.

Moving checks of Work Sharing Directive in mapLoopConstruct to 
checkNestingOfRegions().


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158266/new/

https://reviews.llvm.org/D158266

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/loop_bind_messages.cpp
  clang/test/PCH/pragma-loop.cpp

Index: clang/test/PCH/pragma-loop.cpp
===
--- clang/test/PCH/pragma-loop.cpp
+++ clang/test/PCH/pragma-loop.cpp
@@ -116,9 +116,13 @@
 
   inline void run10(int *List, int Length) {
 int i = 0;
-#pragma omp loop bind(teams)
+int j = 0;
+#pragma omp teams
 for (int i = 0; i < Length; i++) {
-  List[i] = i;
+  #pragma omp loop bind(teams)
+  for (int j = 0; j < Length; j++) {
+List[i] = i+j;
+  }
 }
   }
 
Index: clang/test/OpenMP/loop_bind_messages.cpp
===
--- clang/test/OpenMP/loop_bind_messages.cpp
+++ clang/test/OpenMP/loop_bind_messages.cpp
@@ -4,6 +4,7 @@
 
 #define NNN 50
 int aaa[NNN];
+int aaa2[NNN][NNN];
 
 void parallel_loop() {
   #pragma omp parallel
@@ -15,6 +16,91 @@
}
 }
 
+void parallel_for_AND_loop_bind() {
+  #pragma omp parallel for
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void parallel_nowait() {
+  #pragma omp parallel
+  #pragma omp for nowait
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void parallel_for_with_nothing() {
+  #pragma omp parallel for
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp nothing
+#pragma omp loop // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void parallel_targetfor_with_loop_bind() {
+  #pragma omp target teams distribute parallel for 
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'target teams distribute parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void parallel_targetparallel_with_loop() {
+  #pragma omp target parallel
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(parallel)
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
+  }
+}
+
+void loop_bind_AND_loop_bind() {
+  #pragma omp parallel for
+  for (int i = 0; i < 100; ++i) {
+#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}} 
+for (int i = 0 ; i < NNN ; i++) {
+  #pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'loop' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}} 
+  for (int j = 0 ; j < NNN ; j++) {
+aaa[j] = j*NNN;
+  }
+}
+  }
+}
+
+void parallel_with_sections_loop() {
+  #pragma omp parallel
+  {
+ #pragma omp sections
+ {
+for (int i = 0 ; i < NNN ; i++) {
+  #pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
+  for (int j = 0 ; j < NNN ; j++) {
+aaa2[i][j] = i+j;
+  }
+}
+
+#pragma omp section
+	{
+  aaa[NNN-1] = NNN;
+}
+ }
+  }
+}
+
 void teams_loop() {
   int var1, var2;
 
@@ -34,17 +120,23 @@
}
 }
 
-void orphan_loop_with_bind() {
-  #pragma omp loop bind(parallel) 
-  for (int j = 0 ; j < NNN ; j++) {
-aaa[j] = j*NNN;
+void teams_targetteams_with_loop() {
+  #pragma omp target teams
+  for (int i = 0 ; i < NNN ; i++) {
+#pragma omp loop bind(teams)
+for (int j = 0 ; j < NNN ; j++) {
+  aaa2[i][j] = i+j;
+}
   }
 }
 
-void orphan_loop_no_bind() {
-  #pragma omp loop  // expected-error{{expected 'bind' clause for 'loop' construct without an enclosing OpenMP construct}}
-  for (int j = 0 ; j < NNN ; j++) {
-aaa[j] = j*NNN;
+void teams_targetfor_with_loop_bind() {
+  #pragma omp target teams distribute parallel for 
+  for (int i = 0 ; i < NNN ; i++) {

[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-09-30 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 updated this revision to Diff 557507.
NoumanAmir657 set the repository for this revision to rG LLVM Github Monorepo.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158540/new/

https://reviews.llvm.org/D158540

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp


Index: clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
===
--- clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
+++ clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
@@ -23,6 +23,15 @@
   NoCopyMove ncm;
 };
 
+struct Base {
+ constexpr Base() = default;
+};
+struct Derived : virtual Base { // expected-note 3{{virtual base class 
declared here}}
+  constexpr Derived() = default; // expected-error {{default constructor 
cannot be 'constexpr' in a class with virtual base class}}
+  constexpr Derived(const Derived&) = default; // expected-error {{copy 
constructor cannot be 'constexpr' in a class with virtual base class}}
+  constexpr Derived(Derived&&) = default; // expected-error {{move constructor 
cannot be 'constexpr' in a class with virtual base class}}
+};
+
 // If a function is explicitly defaulted on its first declaration
 //   -- it is implicitly considered to be constexpr if the implicit declaration
 //  would be
Index: clang/lib/Sema/SemaDeclCXX.cpp
===
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -7814,10 +7814,17 @@
   : isa(MD))) &&
   MD->isConstexpr() && !Constexpr &&
   MD->getTemplatedKind() == FunctionDecl::TK_NonTemplate) {
-Diag(MD->getBeginLoc(), MD->isConsteval()
-? diag::err_incorrect_defaulted_consteval
-: diag::err_incorrect_defaulted_constexpr)
-<< CSM;
+if (!MD->isConsteval() && RD->getNumVBases()) {
+  Diag(MD->getBeginLoc(), 
diag::err_incorrect_defaulted_constexpr_with_vb)
+  << CSM;
+  for (const auto &I : RD->vbases())
+Diag(I.getBeginLoc(), diag::note_constexpr_virtual_base_here);
+} else {
+  Diag(MD->getBeginLoc(), MD->isConsteval()
+  ? diag::err_incorrect_defaulted_consteval
+  : 
diag::err_incorrect_defaulted_constexpr)
+  << CSM;
+}
 // FIXME: Explain why the special member can't be constexpr.
 HadError = true;
   }
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9416,6 +9416,8 @@
 def err_incorrect_defaulted_constexpr : Error<
   "defaulted definition of %sub{select_special_member_kind}0 "
   "is not constexpr">;
+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">;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -208,6 +208,8 @@
   (`#54678: `_).
 - Clang now prints its 'note' diagnostic in cyan instead of black, to be more 
compatible
   with terminals with dark background colors. This is also more consistent 
with GCC.
+- Clang now displays an improved diagnostic and a note when defaulted special 
+  member is a contexpr in a class with virtual base class
 
 Bug Fixes in This Version
 -


Index: clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
===
--- clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
+++ clang/test/CXX/dcl.decl/dcl.fct.def/dcl.fct.def.default/p2.cpp
@@ -23,6 +23,15 @@
   NoCopyMove ncm;
 };
 
+struct Base {
+ constexpr Base() = default;
+};
+struct Derived : virtual Base { // expected-note 3{{virtual base class declared here}}
+  constexpr Derived() = default; // expected-error {{default constructor cannot be 'constexpr' in a class with virtual base class}}
+  constexpr Derived(const Derived&) = default; // expected-error {{copy constructor cannot be 'constexpr' in a class with virtual base class}}
+  constexpr Derived(Derived&&) = default; // expected-error {{move constructor cannot be 'constexpr' in a class with virtual base class}}
+};
+
 // If a function is explicitly defaulte

[PATCH] D158540: Improve error message for constexpr constructors of virtual base classes

2023-09-30 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 added a comment.

In D158540#4652051 , @aaron.ballman 
wrote:

> In D158540#4651859 , @NoumanAmir657 
> wrote:
>
>> @aaron.Ballman 
>> Do I need to make changes other than this? The virtual base diagnostic 
>> doesn't have a test case in files that would generate it. Should I add the 
>> above example as the test case?
>
> You'll need to add a test case to demonstrate the changes, and the example 
> you had above would work well for the tests. You should also add a release 
> note to `clang/docs/ReleaseNotes.rst` so users know about the improvement. 
> But I think that should basically be all that's left to do here.

Added tests and the release note.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158540/new/

https://reviews.llvm.org/D158540

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


[clang] 62205c2 - [clang] Remove uses of llvm::Type::getPointerTo() (NFC)

2023-09-30 Thread via cfe-commits

Author: JOE1994
Date: 2023-09-30T08:05:46-04:00
New Revision: 62205c2e60e375f1af7a498be370dd64ff6d8b2a

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

LOG: [clang] Remove uses of llvm::Type::getPointerTo() (NFC)

* Remove if its sole use is to support an unnecessary ptr-to-ptr bitcast
  (remove the bitcast as well)
* Replace with use of other APIs.

NFC opaque pointer cleanup effort.

Added: 


Modified: 
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index f55759581fa78ec..b7aa3a4cb6373c3 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -1958,9 +1958,8 @@ llvm::Constant *CGObjCMac::getNSConstantStringClassRef() {
 
   llvm::Type *PTy = llvm::ArrayType::get(CGM.IntTy, 0);
   auto GV = CGM.CreateRuntimeVariable(PTy, str);
-  auto V = llvm::ConstantExpr::getBitCast(GV, CGM.IntTy->getPointerTo());
-  ConstantStringClassRef = V;
-  return V;
+  ConstantStringClassRef = GV;
+  return GV;
 }
 
 llvm::Constant *CGObjCNonFragileABIMac::getNSConstantStringClassRef() {
@@ -1972,12 +1971,8 @@ llvm::Constant 
*CGObjCNonFragileABIMac::getNSConstantStringClassRef() {
 StringClass.empty() ? "OBJC_CLASS_$_NSConstantString"
 : "OBJC_CLASS_$_" + StringClass;
   llvm::Constant *GV = GetClassGlobal(str, NotForDefinition);
-
-  // Make sure the result is of the correct type.
-  auto V = llvm::ConstantExpr::getBitCast(GV, CGM.IntTy->getPointerTo());
-
-  ConstantStringClassRef = V;
-  return V;
+  ConstantStringClassRef = GV;
+  return GV;
 }
 
 ConstantAddress
@@ -1996,11 +1991,8 @@ CGObjCCommonMac::GenerateConstantNSString(const 
StringLiteral *Literal) {
   // If we don't already have it, construct the type for a constant NSString.
   if (!NSConstantStringType) {
 NSConstantStringType =
-  llvm::StructType::create({
-CGM.Int32Ty->getPointerTo(),
-CGM.Int8PtrTy,
-CGM.IntTy
-  }, "struct.__builtin_NSString");
+llvm::StructType::create({CGM.UnqualPtrTy, CGM.Int8PtrTy, CGM.IntTy},
+ "struct.__builtin_NSString");
   }
 
   ConstantInitBuilder Builder(CGM);

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 6073a2749449a6d..c96523c52562582 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3194,8 +3194,9 @@ llvm::Constant 
*CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
   if (GV->getAddressSpace() !=
   getDataLayout().getDefaultGlobalsAddressSpace()) {
 GVInGlobalsAS = llvm::ConstantExpr::getAddrSpaceCast(
-GV, GV->getValueType()->getPointerTo(
-getDataLayout().getDefaultGlobalsAddressSpace()));
+GV,
+llvm::PointerType::get(
+GV->getContext(), 
getDataLayout().getDefaultGlobalsAddressSpace()));
   }
 
   // Create the ConstantStruct for the global annotation.
@@ -3445,9 +3446,7 @@ ConstantAddress CodeGenModule::GetAddrOfMSGuidDecl(const 
MSGuidDecl *GD) {
   }
 
   llvm::Type *Ty = getTypes().ConvertTypeForMem(GD->getType());
-  llvm::Constant *Addr = llvm::ConstantExpr::getBitCast(
-  GV, Ty->getPointerTo(GV->getAddressSpace()));
-  return ConstantAddress(Addr, Ty, Alignment);
+  return ConstantAddress(GV, Ty, Alignment);
 }
 
 ConstantAddress CodeGenModule::GetAddrOfUnnamedGlobalConstantDecl(
@@ -3521,11 +3520,8 @@ ConstantAddress CodeGenModule::GetWeakRefReference(const 
ValueDecl *VD) {
 
   // See if there is already something with the target's name in the module.
   llvm::GlobalValue *Entry = GetGlobalValue(AA->getAliasee());
-  if (Entry) {
-unsigned AS = getTypes().getTargetAddressSpace(VD->getType());
-auto Ptr = llvm::ConstantExpr::getBitCast(Entry, DeclTy->getPointerTo(AS));
-return ConstantAddress(Ptr, DeclTy, Alignment);
-  }
+  if (Entry)
+return ConstantAddress(Entry, DeclTy, Alignment);
 
   llvm::Constant *Aliasee;
   if (isa(DeclTy))
@@ -4359,8 +4355,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
 // (If function is requested for a definition, we always need to create a 
new
 // function, not just return a bitcast.)
 if (!IsForDefinition)
-  return llvm::ConstantExpr::getBitCast(
-  Entry, Ty->getPointerTo(Entry->getAddressSpace()));
+  return Entry;
   }
 
   // This function doesn't have a complete type (for example, the return
@@ -4400,9 +4395,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
   Entry->removeDeadConstantUsers();
 }
 
-llvm::Constant *BC = llvm::ConstantExpr::getBitCast(
-F, Entry->getValueType()->getPointerTo(Entry->ge

[clang-tools-extra] [X86][RFC] Support AVX10 options (PR #67278)

2023-09-30 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang updated 
https://github.com/llvm/llvm-project/pull/67278

>From eaf36c8cac3fe6d9bb3dcb1387b0b4f1febf5ef7 Mon Sep 17 00:00:00 2001
From: Phoebe Wang 
Date: Mon, 25 Sep 2023 10:31:37 +0800
Subject: [PATCH 1/2] [X86][RFC] Support AVX10 options

AVX10 Architecture Specification: 
https://cdrdv2.intel.com/v1/dl/getContent/784267
AVX10 Technical Paper: https://cdrdv2.intel.com/v1/dl/getContent/784343
RFC: https://discourse.llvm.org/t/rfc-design-for-avx10-options-support/73672
---
 clang/docs/ReleaseNotes.rst   |  1 +
 clang/include/clang/Driver/Options.td |  9 +
 clang/lib/Basic/Targets/X86.cpp   | 37 +--
 clang/lib/Basic/Targets/X86.h |  2 +
 clang/lib/Driver/ToolChains/Arch/X86.cpp  | 30 +++
 clang/test/CodeGen/X86/avx512-error.c | 20 +++---
 clang/test/CodeGen/attr-target-x86.c  | 14 +--
 clang/test/CodeGen/target-avx-abi-diag.c  |  4 ++
 clang/test/Driver/x86-target-features.c   | 20 ++
 clang/test/Preprocessor/x86_target_features.c | 14 +++
 llvm/docs/ReleaseNotes.rst|  2 +
 .../llvm/TargetParser/X86TargetParser.def |  2 +
 llvm/lib/Target/X86/X86.td|  8 
 llvm/lib/Target/X86/X86InstrInfo.td   |  2 +
 llvm/lib/TargetParser/Host.cpp|  6 +++
 llvm/lib/TargetParser/X86TargetParser.cpp |  9 +
 16 files changed, 168 insertions(+), 12 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7abcb8d799e09dc..419bab7577cfad4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -387,6 +387,7 @@ X86 Support
 
 - Added option ``-m[no-]evex512`` to disable ZMM and 64-bit mask instructions
   for AVX512 features.
+- Support ISA of ``AVX10.1``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 0f93479170d73bc..dd44333e6cb30a7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -197,6 +197,9 @@ def m_wasm_Features_Driver_Group : OptionGroup<"">,
 def m_x86_Features_Group : OptionGroup<"">,
Group, Visibility<[ClangOption, CLOption]>,
DocName<"X86">;
+def m_x86_AVX10_Features_Group : OptionGroup<"">,
+ Group, Visibility<[ClangOption, 
CLOption]>,
+ DocName<"X86 AVX10">;
 def m_riscv_Features_Group : OptionGroup<"">,
  Group, DocName<"RISC-V">;
 def m_ve_Features_Group : OptionGroup<"">,
@@ -5693,6 +5696,12 @@ def msse4a : Flag<["-"], "msse4a">, 
Group;
 def mno_sse4a : Flag<["-"], "mno-sse4a">, Group;
 def mavx : Flag<["-"], "mavx">, Group;
 def mno_avx : Flag<["-"], "mno-avx">, Group;
+def mavx10_1_256 : Flag<["-"], "mavx10.1-256">, 
Group;
+def mno_avx10_1_256 : Flag<["-"], "mno-avx10.1-256">, 
Group;
+def mavx10_1_512 : Flag<["-"], "mavx10.1-512">, 
Group;
+def mno_avx10_1_512 : Flag<["-"], "mno-avx10.1-512">, 
Group;
+def mavx10_1 : Flag<["-"], "mavx10.1">, Alias;
+def mno_avx10_1 : Flag<["-"], "mno-avx10.1">, Alias;
 def mavx2 : Flag<["-"], "mavx2">, Group;
 def mno_avx2 : Flag<["-"], "mno-avx2">, Group;
 def mavx512f : Flag<["-"], "mavx512f">, Group;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 022d5753135e160..746414181926f7d 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -121,6 +121,7 @@ bool X86TargetInfo::initFeatureMap(
   std::vector UpdatedFeaturesVec;
   bool HasEVEX512 = true;
   bool HasAVX512F = false;
+  bool HasAVX10 = false;
   for (const auto &Feature : FeaturesVec) {
 // Expand general-regs-only to -x86, -mmx and -sse
 if (Feature == "+general-regs-only") {
@@ -130,17 +131,35 @@ bool X86TargetInfo::initFeatureMap(
   continue;
 }
 
-if (!HasAVX512F && Feature.substr(0, 7) == "+avx512")
+if (Feature.substr(0, 7) == "+avx10.") {
+  HasAVX10 = true;
   HasAVX512F = true;
-if (HasAVX512F && Feature == "-avx512f")
+  if (Feature.substr(Feature.size() - 3, 3) == "512") {
+HasEVEX512 = true;
+  } else if (Feature.substr(7, 2) == "1-") {
+HasEVEX512 = false;
+  }
+} else if (!HasAVX512F && Feature.substr(0, 7) == "+avx512") {
+  HasAVX512F = true;
+} else if (HasAVX512F && Feature == "-avx512f") {
+  HasAVX512F = false;
+} else if (HasAVX10 && Feature == "-avx10.1-256") {
+  HasAVX10 = false;
   HasAVX512F = false;
-if (HasEVEX512 && Feature == "-evex512")
+} else if (!HasEVEX512 && Feature == "+evex512") {
+  HasEVEX512 = true;
+} else if (HasEVEX512 && Feature == "-avx10.1-512") {
   HasEVEX512 = false;
+} else if (HasEVEX512 && Feature == "-evex512") {
+  HasEVEX512 = false;
+}
 
 UpdatedFeaturesVec.push_back(Feature);

[clang] [LLD]lld incorrectly handles .eh_frame when it has a non-zero offset within its output section. (PR #65966)

2023-09-30 Thread via cfe-commits

https://github.com/simpal01 updated 
https://github.com/llvm/llvm-project/pull/65966

>From 8b44aa203b97b8944f236701bfeb92f0b1e8f407 Mon Sep 17 00:00:00 2001
From: Simi Pallipurath 
Date: Mon, 11 Sep 2023 14:42:27 +0100
Subject: [PATCH 1/2] [LLD][AARCH64] lld incorrectly handles .eh_frame when it
 has a non-zero offset within its output section.

When the .eh_frame section is placed at a non-zero
offset within its output section, the relocation
value within .eh_frame are computed incorrectly.

We had similar issue in AArch32 and it has been
fixed already in https://reviews.llvm.org/D148033.

While applying the relocation using S+A-P, the value
of P (the location of the relocation) is getting wrong.
P is:
  P = SecAddr + rel.offset, But SecAddr points to the
starting address of the outputsection rather than the
starting address of the eh frame section within that
output section.
---
 lld/ELF/Arch/AArch64.cpp   |  3 ++
 lld/test/ELF/eh-frame-nonzero-offset.s | 55 ++
 2 files changed, 58 insertions(+)
 create mode 100644 lld/test/ELF/eh-frame-nonzero-offset.s

diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 174a0a3624f7765..09477141c777948 100644
--- a/lld/ELF/Arch/AArch64.cpp
+++ b/lld/ELF/Arch/AArch64.cpp
@@ -770,6 +770,9 @@ void AArch64::relocateAlloc(InputSectionBase &sec, uint8_t 
*buf) const {
   uint64_t secAddr = sec.getOutputSection()->addr;
   if (auto *s = dyn_cast(&sec))
 secAddr += s->outSecOff;
+  else if (auto *eh = dyn_cast(&sec))
+if (InputSection *isec = eh->getParent())
+  secAddr += isec->outSecOff;
   AArch64Relaxer relaxer(sec.relocs());
   for (size_t i = 0, size = sec.relocs().size(); i != size; ++i) {
 const Relocation &rel = sec.relocs()[i];
diff --git a/lld/test/ELF/eh-frame-nonzero-offset.s 
b/lld/test/ELF/eh-frame-nonzero-offset.s
new file mode 100644
index 000..ef086fcf670d81b
--- /dev/null
+++ b/lld/test/ELF/eh-frame-nonzero-offset.s
@@ -0,0 +1,55 @@
+// REQUIRES: aarch64
+// RUN: rm -rf %t && split-file %s %t
+
+// RUN: llvm-mc -filetype=obj -triple=aarch64 %t/a.s -o %t/a.o
+// RUN: ld.lld %t/a.o -T %t/eh-frame-non-zero-offset.t -o %t/non-zero
+// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame 
%t/non-zero | FileCheck --check-prefix=NONZERO %s
+// RUN: ld.lld %t/a.o -T %t/eh-frame-zero-offset.t -o %t/zero
+// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/zero 
| FileCheck --check-prefix=ZERO %s
+
+// NONZERO:  {{[0-9]+}}: 0080 {{.*}} __eh_frame_start
+// NONZERO-NEXT: {{[0-9]+}}: 00ac {{.*}} __eh_frame_end
+
+// NONZERO:  0x0078   1000 
+// NONZERO-NEXT: 0x0088 017a5200 017c1e01 1b0c1f00 1000
+// NONZERO-NEXT: 0x0098 1800 64ff 0800 
+// NONZERO-NEXT: 0x00a8 
+
+// ZERO:  {{[0-9]+}}: 0080 {{.*}} __eh_frame_start
+// ZERO-NEXT: {{[0-9]+}}: 00ac {{.*}} __eh_frame_end
+
+// ZERO:  0x0080 1000  017a5200 017c1e01
+// ZERO-NEXT: 0x0090 1b0c1f00 1000 1800 64ff
+// ZERO-NEXT: 0x00a0 0800  
+
+//--- eh-frame-non-zero-offset.t
+SECTIONS {
+  .text : { *(.text .text.*) }
+  .eh_frame : {
+  /* Alignment padding within .eh_frame */
+  . = ALIGN(128);
+  __eh_frame_start = .;
+  *(.eh_frame .eh_frame.*) ;
+  __eh_frame_end = .;
+  }
+}
+
+//--- eh-frame-zero-offset.t
+SECTIONS {
+  .text : { *(.text .text.*) }
+  .eh_frame : ALIGN(128) {
+  __eh_frame_start = .;
+  *(.eh_frame .eh_frame.*) ;
+  __eh_frame_end = .;
+  }
+}
+
+//--- a.s
+.section .text.01, "ax",%progbits
+.global f1
+.type f1, %function
+f1:
+.cfi_startproc
+   nop
+   nop
+.cfi_endproc

>From 2e3a0de9714856cb8fa992f1818e5de7053dd32b Mon Sep 17 00:00:00 2001
From: Simi Pallipurath 
Date: Mon, 18 Sep 2023 19:50:56 +0100
Subject: [PATCH 2/2] fixup! [LLD][AARCH64] lld incorrectly handles .eh_frame
 when it has a non-zero offset within its output section.

---
 lld/ELF/Arch/AArch64.cpp  |  7 ++-
 lld/ELF/Arch/PPC64.cpp|  4 ++
 lld/ELF/Arch/X86_64.cpp   |  4 ++
 lld/ELF/SyntheticSections.cpp |  7 ++-
 lld/ELF/Target.cpp|  4 ++
 ...et.s => eh-frame-nonzero-offset-aarch64.s} |  0
 lld/test/ELF/eh-frame-nonzero-offset-arm.s| 55 +++
 lld/test/ELF/eh-frame-nonzero-offset-ppc.s| 54 ++
 lld/test/ELF/eh-frame-nonzero-offset-x86.s| 54 ++
 9 files changed, 185 insertions(+), 4 deletions(-)
 rename lld/test/ELF/{eh-frame-nonzero-offset.s => 
eh-frame-nonzero-offset-aarch64.s} (100%)
 create mode 100644 lld/test/ELF/eh-frame-nonzero-offset-arm.s
 create mode 100644 lld/test/ELF/eh-frame-nonzero-offset-ppc.s
 create mode 100644 lld/test/ELF/eh-frame-nonzero-offset-x86.s

diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 09477141c777948

[clang-tools-extra] [LLD]lld incorrectly handles .eh_frame when it has a non-zero offset within its output section. (PR #65966)

2023-09-30 Thread via cfe-commits

https://github.com/simpal01 updated 
https://github.com/llvm/llvm-project/pull/65966

>From 8b44aa203b97b8944f236701bfeb92f0b1e8f407 Mon Sep 17 00:00:00 2001
From: Simi Pallipurath 
Date: Mon, 11 Sep 2023 14:42:27 +0100
Subject: [PATCH 1/2] [LLD][AARCH64] lld incorrectly handles .eh_frame when it
 has a non-zero offset within its output section.

When the .eh_frame section is placed at a non-zero
offset within its output section, the relocation
value within .eh_frame are computed incorrectly.

We had similar issue in AArch32 and it has been
fixed already in https://reviews.llvm.org/D148033.

While applying the relocation using S+A-P, the value
of P (the location of the relocation) is getting wrong.
P is:
  P = SecAddr + rel.offset, But SecAddr points to the
starting address of the outputsection rather than the
starting address of the eh frame section within that
output section.
---
 lld/ELF/Arch/AArch64.cpp   |  3 ++
 lld/test/ELF/eh-frame-nonzero-offset.s | 55 ++
 2 files changed, 58 insertions(+)
 create mode 100644 lld/test/ELF/eh-frame-nonzero-offset.s

diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 174a0a3624f7765..09477141c777948 100644
--- a/lld/ELF/Arch/AArch64.cpp
+++ b/lld/ELF/Arch/AArch64.cpp
@@ -770,6 +770,9 @@ void AArch64::relocateAlloc(InputSectionBase &sec, uint8_t 
*buf) const {
   uint64_t secAddr = sec.getOutputSection()->addr;
   if (auto *s = dyn_cast(&sec))
 secAddr += s->outSecOff;
+  else if (auto *eh = dyn_cast(&sec))
+if (InputSection *isec = eh->getParent())
+  secAddr += isec->outSecOff;
   AArch64Relaxer relaxer(sec.relocs());
   for (size_t i = 0, size = sec.relocs().size(); i != size; ++i) {
 const Relocation &rel = sec.relocs()[i];
diff --git a/lld/test/ELF/eh-frame-nonzero-offset.s 
b/lld/test/ELF/eh-frame-nonzero-offset.s
new file mode 100644
index 000..ef086fcf670d81b
--- /dev/null
+++ b/lld/test/ELF/eh-frame-nonzero-offset.s
@@ -0,0 +1,55 @@
+// REQUIRES: aarch64
+// RUN: rm -rf %t && split-file %s %t
+
+// RUN: llvm-mc -filetype=obj -triple=aarch64 %t/a.s -o %t/a.o
+// RUN: ld.lld %t/a.o -T %t/eh-frame-non-zero-offset.t -o %t/non-zero
+// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame 
%t/non-zero | FileCheck --check-prefix=NONZERO %s
+// RUN: ld.lld %t/a.o -T %t/eh-frame-zero-offset.t -o %t/zero
+// RUN: llvm-readelf --program-headers --unwind --symbols -x .eh_frame %t/zero 
| FileCheck --check-prefix=ZERO %s
+
+// NONZERO:  {{[0-9]+}}: 0080 {{.*}} __eh_frame_start
+// NONZERO-NEXT: {{[0-9]+}}: 00ac {{.*}} __eh_frame_end
+
+// NONZERO:  0x0078   1000 
+// NONZERO-NEXT: 0x0088 017a5200 017c1e01 1b0c1f00 1000
+// NONZERO-NEXT: 0x0098 1800 64ff 0800 
+// NONZERO-NEXT: 0x00a8 
+
+// ZERO:  {{[0-9]+}}: 0080 {{.*}} __eh_frame_start
+// ZERO-NEXT: {{[0-9]+}}: 00ac {{.*}} __eh_frame_end
+
+// ZERO:  0x0080 1000  017a5200 017c1e01
+// ZERO-NEXT: 0x0090 1b0c1f00 1000 1800 64ff
+// ZERO-NEXT: 0x00a0 0800  
+
+//--- eh-frame-non-zero-offset.t
+SECTIONS {
+  .text : { *(.text .text.*) }
+  .eh_frame : {
+  /* Alignment padding within .eh_frame */
+  . = ALIGN(128);
+  __eh_frame_start = .;
+  *(.eh_frame .eh_frame.*) ;
+  __eh_frame_end = .;
+  }
+}
+
+//--- eh-frame-zero-offset.t
+SECTIONS {
+  .text : { *(.text .text.*) }
+  .eh_frame : ALIGN(128) {
+  __eh_frame_start = .;
+  *(.eh_frame .eh_frame.*) ;
+  __eh_frame_end = .;
+  }
+}
+
+//--- a.s
+.section .text.01, "ax",%progbits
+.global f1
+.type f1, %function
+f1:
+.cfi_startproc
+   nop
+   nop
+.cfi_endproc

>From 2e3a0de9714856cb8fa992f1818e5de7053dd32b Mon Sep 17 00:00:00 2001
From: Simi Pallipurath 
Date: Mon, 18 Sep 2023 19:50:56 +0100
Subject: [PATCH 2/2] fixup! [LLD][AARCH64] lld incorrectly handles .eh_frame
 when it has a non-zero offset within its output section.

---
 lld/ELF/Arch/AArch64.cpp  |  7 ++-
 lld/ELF/Arch/PPC64.cpp|  4 ++
 lld/ELF/Arch/X86_64.cpp   |  4 ++
 lld/ELF/SyntheticSections.cpp |  7 ++-
 lld/ELF/Target.cpp|  4 ++
 ...et.s => eh-frame-nonzero-offset-aarch64.s} |  0
 lld/test/ELF/eh-frame-nonzero-offset-arm.s| 55 +++
 lld/test/ELF/eh-frame-nonzero-offset-ppc.s| 54 ++
 lld/test/ELF/eh-frame-nonzero-offset-x86.s| 54 ++
 9 files changed, 185 insertions(+), 4 deletions(-)
 rename lld/test/ELF/{eh-frame-nonzero-offset.s => 
eh-frame-nonzero-offset-aarch64.s} (100%)
 create mode 100644 lld/test/ELF/eh-frame-nonzero-offset-arm.s
 create mode 100644 lld/test/ELF/eh-frame-nonzero-offset-ppc.s
 create mode 100644 lld/test/ELF/eh-frame-nonzero-offset-x86.s

diff --git a/lld/ELF/Arch/AArch64.cpp b/lld/ELF/Arch/AArch64.cpp
index 09477141c777948

[clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2023-09-30 Thread Connor Sughrue via cfe-commits

https://github.com/cpsughrue updated 
https://github.com/llvm/llvm-project/pull/67562

>From 5def87462e3b48cfebafdc2526ac929f5cb9cea3 Mon Sep 17 00:00:00 2001
From: cpsughrue 
Date: Sun, 9 Jul 2023 23:19:58 -0400
Subject: [PATCH 1/3] [clang][MBD] set up module build daemon infrastructure

The module build daemon (mbd) will serve as a cc1 tool that helps convert
implicit module command lines to explicit module command lines. A clang
invocation will check to see if a mbd exists, if not the invocation will spawn
one. After the mbd is up and running and a handshake has successfully been
carried out between the mbd and clang invocation the clang invocation will
share it's command line with the mbd. The mbd will then scan the translation
unit and build all modular dependencies before returning a modified cc1 command
 line such that all arguments related to modules are converted from the
implicit option to their explicit option.

This commit sets up the basic mbd infrastructure. Including the ability to
spawn a mbd and carry out a handshake between the clang invocation and mbd.

RFC: 
https://discourse.llvm.org/t/rfc-modules-build-daemon-build-system-agnostic-support-for-explicitly-built-modules/71524
---
 clang/include/clang/Driver/Options.td |  12 +
 .../include/clang/Frontend/FrontendOptions.h  |   7 +
 .../clang/Tooling/ModuleBuildDaemon/Client.h  |  44 +++
 .../ModuleBuildDaemon/SocketMsgSupport.h  | 134 +
 .../Tooling/ModuleBuildDaemon/SocketSupport.h |  31 ++
 .../clang/Tooling/ModuleBuildDaemon/Utils.h   |  28 ++
 clang/lib/Driver/ToolChains/Clang.cpp |  14 +-
 clang/lib/Tooling/CMakeLists.txt  |   1 +
 .../Tooling/ModuleBuildDaemon/CMakeLists.txt  |   9 +
 .../lib/Tooling/ModuleBuildDaemon/Client.cpp  | 167 +++
 .../ModuleBuildDaemon/SocketSupport.cpp   | 128 +
 clang/lib/Tooling/ModuleBuildDaemon/Utils.cpp |  32 +++
 clang/test/Driver/unknown-arg.c   |   2 +-
 clang/test/ModuleBuildDaemon/handshake.c  |  18 ++
 clang/test/ModuleBuildDaemon/launch.c |  14 +
 clang/tools/driver/CMakeLists.txt |   3 +
 clang/tools/driver/cc1_main.cpp   |  28 +-
 clang/tools/driver/cc1modbuildd_main.cpp  | 267 ++
 clang/tools/driver/driver.cpp |  17 +-
 19 files changed, 947 insertions(+), 9 deletions(-)
 create mode 100644 clang/include/clang/Tooling/ModuleBuildDaemon/Client.h
 create mode 100644 
clang/include/clang/Tooling/ModuleBuildDaemon/SocketMsgSupport.h
 create mode 100644 
clang/include/clang/Tooling/ModuleBuildDaemon/SocketSupport.h
 create mode 100644 clang/include/clang/Tooling/ModuleBuildDaemon/Utils.h
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/CMakeLists.txt
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/Client.cpp
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/SocketSupport.cpp
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/Utils.cpp
 create mode 100644 clang/test/ModuleBuildDaemon/handshake.c
 create mode 100644 clang/test/ModuleBuildDaemon/launch.c
 create mode 100644 clang/tools/driver/cc1modbuildd_main.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index efd90942948af27..d31d28255e81a8a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2836,6 +2836,18 @@ defm declspec : BoolOption<"f", "declspec",
   NegFlag,
   BothFlags<[], [ClangOption, CC1Option],
   " __declspec as a keyword">>, Group;
+
+def fmodule_build_daemon : Flag<["-"], "fmodule-build-daemon">, Group,
+  Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Enables module build daemon functionality">,
+  MarshallingInfoFlag>;
+def fmodule_build_daemon_EQ : Joined<["-"], "fmodule-build-daemon=">, 
Group,
+  Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Enables module build daemon functionality and defines location of 
output files">,
+  MarshallingInfoString>;
+
 def fmodules_cache_path : Joined<["-"], "fmodules-cache-path=">, 
Group,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
   MetaVarName<"">,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 117e35de6f76c4c..8ce97a57d413c0b 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -350,6 +350,9 @@ class FrontendOptions {
   /// Whether to share the FileManager when building modules.
   unsigned ModulesShareFileManager : 1;
 
+  /// Connect to module build daemon
+  unsigned ModuleBuildDaemon : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.
@@ -435,6 +438,10 @@ class FrontendOptions {
   /// The output file, if any.
   std::string OutputFile;
 
+  /// If given, the path to the module build daemon's output files and socket
+  /// address
+  std::string ModuleB

[clang] [clang][Interp] Fix `ArrayInitLoopExpr` handling (PR #67886)

2023-09-30 Thread via cfe-commits

https://github.com/isuckatcs created 
https://github.com/llvm/llvm-project/pull/67886

This patch implements the changes from #67722 in Interp. 

>From df530e60872abc4a74e561b8479c4a28dfb39d85 Mon Sep 17 00:00:00 2001
From: isuckatcs <65320245+isucka...@users.noreply.github.com>
Date: Sat, 30 Sep 2023 17:05:02 +0200
Subject: [PATCH] implement fix in interp

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp |  1 +
 clang/test/AST/Interp/cxx20.cpp  | 10 --
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 46906377863bd74..1e2db3219865a53 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -803,6 +803,7 @@ bool ByteCodeExprGen::VisitArrayInitLoopExpr(
   // where the LHS is on the stack (the target array)
   // and the RHS is our SubExpr.
   for (size_t I = 0; I != Size; ++I) {
+BlockScope Scope(this);
 ArrayIndexScope IndexScope(this, I);
 
 if (ElemT) {
diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 197090b0a37d9df..5c0a88ce9612e1b 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -701,13 +701,12 @@ namespace ThreeWayCmp {
   static_assert(pa2 <=> pa1 == 1, "");
 }
 
-// FIXME: Interp should also be able to evaluate this snippet properly.
 namespace ConstexprArrayInitLoopExprDestructors
 {
   struct Highlander {
   int *p = 0;
   constexpr Highlander() {}
-  constexpr void set(int *p) { this->p = p; ++*p; if (*p != 1) throw 
"there can be only one"; } // expected-note {{not valid in a constant 
expression}}
+  constexpr void set(int *p) { this->p = p; ++*p; if (*p != 1) throw 
"there can be only one"; }
   constexpr ~Highlander() { --*p; }
   };
 
@@ -715,19 +714,18 @@ namespace ConstexprArrayInitLoopExprDestructors
   int *p;
   constexpr X(int *p) : p(p) {}
   constexpr X(const X &x, Highlander &&h = Highlander()) : p(x.p) {
-  h.set(p); // expected-note {{in call to '&Highlander()->set(&n)'}}
+  h.set(p);
   }
   };
 
   constexpr int f() {
   int n = 0;
   X x[3] = {&n, &n, &n};
-  auto [a, b, c] = x; // expected-note {{in call to 'X(x[0], 
Highlander())'}}
+  auto [a, b, c] = x;
   return n;
   }
 
-  static_assert(f() == 0); // expected-error {{not an integral constant 
expression}} \
-   // expected-note {{in call to 'f()'}}
+  static_assert(f() == 0);
 
   int main() {
   return f();

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


[clang] [clang][Interp] Fix `ArrayInitLoopExpr` handling (PR #67886)

2023-09-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

This patch implements the changes from #67722 in Interp. 

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/ByteCodeExprGen.cpp (+1) 
- (modified) clang/test/AST/Interp/cxx20.cpp (+4-6) 


``diff
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 46906377863bd74..1e2db3219865a53 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -803,6 +803,7 @@ bool ByteCodeExprGen::VisitArrayInitLoopExpr(
   // where the LHS is on the stack (the target array)
   // and the RHS is our SubExpr.
   for (size_t I = 0; I != Size; ++I) {
+BlockScope Scope(this);
 ArrayIndexScope IndexScope(this, I);
 
 if (ElemT) {
diff --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 197090b0a37d9df..5c0a88ce9612e1b 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -701,13 +701,12 @@ namespace ThreeWayCmp {
   static_assert(pa2 <=> pa1 == 1, "");
 }
 
-// FIXME: Interp should also be able to evaluate this snippet properly.
 namespace ConstexprArrayInitLoopExprDestructors
 {
   struct Highlander {
   int *p = 0;
   constexpr Highlander() {}
-  constexpr void set(int *p) { this->p = p; ++*p; if (*p != 1) throw 
"there can be only one"; } // expected-note {{not valid in a constant 
expression}}
+  constexpr void set(int *p) { this->p = p; ++*p; if (*p != 1) throw 
"there can be only one"; }
   constexpr ~Highlander() { --*p; }
   };
 
@@ -715,19 +714,18 @@ namespace ConstexprArrayInitLoopExprDestructors
   int *p;
   constexpr X(int *p) : p(p) {}
   constexpr X(const X &x, Highlander &&h = Highlander()) : p(x.p) {
-  h.set(p); // expected-note {{in call to '&Highlander()->set(&n)'}}
+  h.set(p);
   }
   };
 
   constexpr int f() {
   int n = 0;
   X x[3] = {&n, &n, &n};
-  auto [a, b, c] = x; // expected-note {{in call to 'X(x[0], 
Highlander())'}}
+  auto [a, b, c] = x;
   return n;
   }
 
-  static_assert(f() == 0); // expected-error {{not an integral constant 
expression}} \
-   // expected-note {{in call to 'f()'}}
+  static_assert(f() == 0);
 
   int main() {
   return f();

``




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


[clang] [clang-cl] Fix value of __FUNCTION__ and __func__ in MSVC mode. (PR #67592)

2023-09-30 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/67592

>From 55b67a58ef8b9856e5f0a8f535b8617f59711dec Mon Sep 17 00:00:00 2001
From: Ammarguellat 
Date: Wed, 27 Sep 2023 11:59:04 -0700
Subject: [PATCH 1/5] Fix value of __FUNCTION__ and __func__ in MSVC mode.

---
 clang/lib/AST/Expr.cpp|  9 ++-
 clang/lib/AST/TypePrinter.cpp | 21 +-
 clang/test/Analysis/eval-predefined-exprs.cpp |  4 +-
 .../CodeGenCXX/mangle-nttp-anon-union.cpp |  2 +-
 clang/test/CodeGenCXX/predefined-expr.cpp | 18 -
 clang/test/SemaCXX/source_location.cpp| 72 +++
 6 files changed, 99 insertions(+), 27 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index af82ca0784af413..49f3495c090f191 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -773,8 +773,8 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, const 
Decl *CurrentDecl) {
   }
   if (const FunctionDecl *FD = dyn_cast(CurrentDecl)) {
 const auto &LO = Context.getLangOpts();
-if (((IK == Func || IK == Function) && !LO.MicrosoftExt) ||
-(IK == LFunction && LO.MicrosoftExt))
+if (((IK == Function || IK == Func) && !LO.MicrosoftExt) ||
+((IK == LFunction || IK == Func) && LO.MicrosoftExt))
   return FD->getNameAsString();
 
 SmallString<256> Name;
@@ -804,7 +804,10 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, 
const Decl *CurrentDecl) {
 PrintingPolicy Policy(LO);
 PrettyCallbacks PrettyCB(LO);
 Policy.Callbacks = &PrettyCB;
-Policy.UseClassForTemplateArgument = LO.MicrosoftExt;
+if (IK == Function && LO.MicrosoftExt) {
+  Policy.UseClassForTemplateArgument = LO.MicrosoftExt;
+  Policy.MSVCFormatting = LO.MicrosoftExt;
+}
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 3771a29f26b173f..8a7cf85cdf126b6 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2195,6 +2195,7 @@ printTo(raw_ostream &OS, ArrayRef Args, const 
PrintingPolicy &Policy,
 llvm::SmallVector OrigArgs;
 for (const TA &A : Args)
   OrigArgs.push_back(getArgument(A));
+
 while (!Args.empty() && getArgument(Args.back()).getIsDefaulted())
   Args = Args.drop_back();
   }
@@ -2218,10 +2219,24 @@ printTo(raw_ostream &OS, ArrayRef Args, const 
PrintingPolicy &Policy,
 } else {
   if (!FirstArg)
 OS << Comma;
-  if (Policy.UseClassForTemplateArgument &&
-  Argument.getKind() == TemplateArgument::Type)
-OS << "class ";
 
+  if (Policy.MSVCFormatting && Policy.UseClassForTemplateArgument &&
+  Argument.getKind() == TemplateArgument::Type &&
+  !Argument.getAsType()->isBuiltinType()) {
+const Type *Ty = Argument.getAsType().getTypePtr();
+const char *kw;
+if (Ty->isStructureType())
+  kw = "struct ";
+else if (Ty->isClassType())
+  kw = "class ";
+else if (Ty->isUnionType())
+  kw = "union ";
+else if (Ty->isEnumeralType())
+  kw = "enum ";
+else
+  llvm_unreachable("argument type not expected");
+OS << kw;
+  }
   // Tries to print the argument with location info if exists.
   printArgument(Arg, Policy, ArgOS,
 TemplateParameterList::shouldIncludeTypeForArgument(
diff --git a/clang/test/Analysis/eval-predefined-exprs.cpp 
b/clang/test/Analysis/eval-predefined-exprs.cpp
index 7be441eb5bad943..a6bac5ee9d486d2 100644
--- a/clang/test/Analysis/eval-predefined-exprs.cpp
+++ b/clang/test/Analysis/eval-predefined-exprs.cpp
@@ -56,7 +56,7 @@ struct A {
 clang_analyzer_dump(__FUNCTION__);
 clang_analyzer_dump(__PRETTY_FUNCTION__);
 #ifdef ANALYZER_MS
-// expected-warning@-4 {{&Element{"A::A",0 S64b,char}}}
+// expected-warning@-4 {{&Element{"A",0 S64b,char}}}
 // expected-warning@-4 {{&Element{"A::A",0 S64b,char}}}
 #else
 // expected-warning@-7 {{&Element{"A",0 S64b,char}}}
@@ -80,7 +80,7 @@ struct A {
 clang_analyzer_dump(__FUNCTION__);
 clang_analyzer_dump(__PRETTY_FUNCTION__);
 #ifdef ANALYZER_MS
-// expected-warning@-4 {{&Element{"A::~A",0 S64b,char}}}
+// expected-warning@-4 {{&Element{"~A",0 S64b,char}}}
 // expected-warning@-4 {{&Element{"A::~A",0 S64b,char}}}
 #else
 // expected-warning@-7 {{&Element{"~A",0 S64b,char}}}
diff --git a/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp 
b/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp
index 78fa7c378c88d50..1982a3eeb941291 100644
--- a/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp
+++ b/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -std=c++20 -emit-llvm %s -o - -triple=x86_64-linux-gnu | 
FileCheck %s
-// RUN: %clang_cc1 -std=c++20 -emit-llvm %s -o - -triple=x86_64-linux-gnu | 
llvm-cxxfilt -n | FileCheck %s --check-pr

[clang-tools-extra] [clang-cl] Fix value of __FUNCTION__ and __func__ in MSVC mode. (PR #67592)

2023-09-30 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/67592

>From 55b67a58ef8b9856e5f0a8f535b8617f59711dec Mon Sep 17 00:00:00 2001
From: Ammarguellat 
Date: Wed, 27 Sep 2023 11:59:04 -0700
Subject: [PATCH 1/5] Fix value of __FUNCTION__ and __func__ in MSVC mode.

---
 clang/lib/AST/Expr.cpp|  9 ++-
 clang/lib/AST/TypePrinter.cpp | 21 +-
 clang/test/Analysis/eval-predefined-exprs.cpp |  4 +-
 .../CodeGenCXX/mangle-nttp-anon-union.cpp |  2 +-
 clang/test/CodeGenCXX/predefined-expr.cpp | 18 -
 clang/test/SemaCXX/source_location.cpp| 72 +++
 6 files changed, 99 insertions(+), 27 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index af82ca0784af413..49f3495c090f191 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -773,8 +773,8 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, const 
Decl *CurrentDecl) {
   }
   if (const FunctionDecl *FD = dyn_cast(CurrentDecl)) {
 const auto &LO = Context.getLangOpts();
-if (((IK == Func || IK == Function) && !LO.MicrosoftExt) ||
-(IK == LFunction && LO.MicrosoftExt))
+if (((IK == Function || IK == Func) && !LO.MicrosoftExt) ||
+((IK == LFunction || IK == Func) && LO.MicrosoftExt))
   return FD->getNameAsString();
 
 SmallString<256> Name;
@@ -804,7 +804,10 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, 
const Decl *CurrentDecl) {
 PrintingPolicy Policy(LO);
 PrettyCallbacks PrettyCB(LO);
 Policy.Callbacks = &PrettyCB;
-Policy.UseClassForTemplateArgument = LO.MicrosoftExt;
+if (IK == Function && LO.MicrosoftExt) {
+  Policy.UseClassForTemplateArgument = LO.MicrosoftExt;
+  Policy.MSVCFormatting = LO.MicrosoftExt;
+}
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 3771a29f26b173f..8a7cf85cdf126b6 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2195,6 +2195,7 @@ printTo(raw_ostream &OS, ArrayRef Args, const 
PrintingPolicy &Policy,
 llvm::SmallVector OrigArgs;
 for (const TA &A : Args)
   OrigArgs.push_back(getArgument(A));
+
 while (!Args.empty() && getArgument(Args.back()).getIsDefaulted())
   Args = Args.drop_back();
   }
@@ -2218,10 +2219,24 @@ printTo(raw_ostream &OS, ArrayRef Args, const 
PrintingPolicy &Policy,
 } else {
   if (!FirstArg)
 OS << Comma;
-  if (Policy.UseClassForTemplateArgument &&
-  Argument.getKind() == TemplateArgument::Type)
-OS << "class ";
 
+  if (Policy.MSVCFormatting && Policy.UseClassForTemplateArgument &&
+  Argument.getKind() == TemplateArgument::Type &&
+  !Argument.getAsType()->isBuiltinType()) {
+const Type *Ty = Argument.getAsType().getTypePtr();
+const char *kw;
+if (Ty->isStructureType())
+  kw = "struct ";
+else if (Ty->isClassType())
+  kw = "class ";
+else if (Ty->isUnionType())
+  kw = "union ";
+else if (Ty->isEnumeralType())
+  kw = "enum ";
+else
+  llvm_unreachable("argument type not expected");
+OS << kw;
+  }
   // Tries to print the argument with location info if exists.
   printArgument(Arg, Policy, ArgOS,
 TemplateParameterList::shouldIncludeTypeForArgument(
diff --git a/clang/test/Analysis/eval-predefined-exprs.cpp 
b/clang/test/Analysis/eval-predefined-exprs.cpp
index 7be441eb5bad943..a6bac5ee9d486d2 100644
--- a/clang/test/Analysis/eval-predefined-exprs.cpp
+++ b/clang/test/Analysis/eval-predefined-exprs.cpp
@@ -56,7 +56,7 @@ struct A {
 clang_analyzer_dump(__FUNCTION__);
 clang_analyzer_dump(__PRETTY_FUNCTION__);
 #ifdef ANALYZER_MS
-// expected-warning@-4 {{&Element{"A::A",0 S64b,char}}}
+// expected-warning@-4 {{&Element{"A",0 S64b,char}}}
 // expected-warning@-4 {{&Element{"A::A",0 S64b,char}}}
 #else
 // expected-warning@-7 {{&Element{"A",0 S64b,char}}}
@@ -80,7 +80,7 @@ struct A {
 clang_analyzer_dump(__FUNCTION__);
 clang_analyzer_dump(__PRETTY_FUNCTION__);
 #ifdef ANALYZER_MS
-// expected-warning@-4 {{&Element{"A::~A",0 S64b,char}}}
+// expected-warning@-4 {{&Element{"~A",0 S64b,char}}}
 // expected-warning@-4 {{&Element{"A::~A",0 S64b,char}}}
 #else
 // expected-warning@-7 {{&Element{"~A",0 S64b,char}}}
diff --git a/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp 
b/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp
index 78fa7c378c88d50..1982a3eeb941291 100644
--- a/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp
+++ b/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -std=c++20 -emit-llvm %s -o - -triple=x86_64-linux-gnu | 
FileCheck %s
-// RUN: %clang_cc1 -std=c++20 -emit-llvm %s -o - -triple=x86_64-linux-gnu | 
llvm-cxxfilt -n | FileCheck %s --check-pr

[clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2023-09-30 Thread Connor Sughrue via cfe-commits

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


Suffix l missing in C++ standard header

2023-09-30 Thread Helmut Burkhardt via cfe-commits
Dear llvm front end team

The clang precision of  mathematical constants is the same as for 


Please add the suffix l. Example :
template  inline constexpr _Tp e_v<_Tp>  = 
2.718281828459045235360287471352662;
—>
template  inline constexpr _Tp e_v<_Tp>  = 
2.718281828459045235360287471352662l;
and the following lines

to actually provide long double precision.

Kind regards
   Helmut Burkhardt

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


[PATCH] D154869: [Flang] [FlangRT] Introduce FlangRT project as solution to Flang's runtime LLVM integration

2023-09-30 Thread Mark Danial via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6403287eff71: [Flang] [FlangRT] Introduce FlangRT project as 
solution to Flang's runtime LLVM… (authored by pscoro, committed by 
madanial).

Changed prior to commit:
  https://reviews.llvm.org/D154869?vs=557468&id=557508#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154869/new/

https://reviews.llvm.org/D154869

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  flang-rt/CMakeLists.txt
  flang-rt/docs/GettingStarted.md
  flang-rt/test/CMakeLists.txt
  flang-rt/test/FortranRuntime/no-cpp-dep.c
  flang-rt/test/NonGtestUnit/lit.cfg.py
  flang-rt/test/NonGtestUnit/lit.site.cfg.py.in
  flang-rt/test/Unit/lit.cfg.py
  flang-rt/test/Unit/lit.site.cfg.py.in
  flang-rt/test/lit.cfg.py
  flang-rt/test/lit.site.cfg.py.in
  flang-rt/unittests/CMakeLists.txt
  flang-rt/unittests/FortranEvaluate/CMakeLists.txt
  flang-rt/unittests/FortranEvaluate/ISO-Fortran-binding.cpp
  flang-rt/unittests/FortranEvaluate/reshape.cpp
  flang-rt/unittests/FortranEvaluate/testing.cpp
  flang-rt/unittests/FortranEvaluate/testing.h
  flang-rt/unittests/FortranRuntime/Allocatable.cpp
  flang-rt/unittests/FortranRuntime/ArrayConstructor.cpp
  flang-rt/unittests/FortranRuntime/BufferTest.cpp
  flang-rt/unittests/FortranRuntime/CMakeLists.txt
  flang-rt/unittests/FortranRuntime/CharacterTest.cpp
  flang-rt/unittests/FortranRuntime/CommandTest.cpp
  flang-rt/unittests/FortranRuntime/Complex.cpp
  flang-rt/unittests/FortranRuntime/CrashHandlerFixture.cpp
  flang-rt/unittests/FortranRuntime/CrashHandlerFixture.h
  flang-rt/unittests/FortranRuntime/Derived.cpp
  flang-rt/unittests/FortranRuntime/ExternalIOTest.cpp
  flang-rt/unittests/FortranRuntime/Format.cpp
  flang-rt/unittests/FortranRuntime/Inquiry.cpp
  flang-rt/unittests/FortranRuntime/ListInputTest.cpp
  flang-rt/unittests/FortranRuntime/LogicalFormatTest.cpp
  flang-rt/unittests/FortranRuntime/Matmul.cpp
  flang-rt/unittests/FortranRuntime/MatmulTranspose.cpp
  flang-rt/unittests/FortranRuntime/MiscIntrinsic.cpp
  flang-rt/unittests/FortranRuntime/Namelist.cpp
  flang-rt/unittests/FortranRuntime/Numeric.cpp
  flang-rt/unittests/FortranRuntime/NumericalFormatTest.cpp
  flang-rt/unittests/FortranRuntime/Pointer.cpp
  flang-rt/unittests/FortranRuntime/Ragged.cpp
  flang-rt/unittests/FortranRuntime/Random.cpp
  flang-rt/unittests/FortranRuntime/Reduction.cpp
  flang-rt/unittests/FortranRuntime/RuntimeCrashTest.cpp
  flang-rt/unittests/FortranRuntime/Stop.cpp
  flang-rt/unittests/FortranRuntime/TemporaryStack.cpp
  flang-rt/unittests/FortranRuntime/Time.cpp
  flang-rt/unittests/FortranRuntime/Transformational.cpp
  flang-rt/unittests/FortranRuntime/tools.h
  flang/CMakeLists.txt
  flang/cmake/modules/AddFlang.cmake
  flang/cmake/modules/FlangConfig.cmake.in
  flang/lib/Decimal/CMakeLists.txt
  flang/runtime/CMakeLists.txt
  flang/runtime/sum.cpp
  flang/test/CMakeLists.txt
  flang/test/Driver/linker-flags.f90
  flang/test/lit.cfg.py
  flang/tools/flang-driver/CMakeLists.txt
  flang/unittests/CMakeLists.txt
  flang/unittests/Evaluate/CMakeLists.txt
  flang/unittests/Evaluate/ISO-Fortran-binding.cpp
  flang/unittests/Evaluate/reshape.cpp
  flang/unittests/Optimizer/CMakeLists.txt
  flang/unittests/Runtime/Allocatable.cpp
  flang/unittests/Runtime/ArrayConstructor.cpp
  flang/unittests/Runtime/BufferTest.cpp
  flang/unittests/Runtime/CMakeLists.txt
  flang/unittests/Runtime/CharacterTest.cpp
  flang/unittests/Runtime/CommandTest.cpp
  flang/unittests/Runtime/Complex.cpp
  flang/unittests/Runtime/CrashHandlerFixture.cpp
  flang/unittests/Runtime/CrashHandlerFixture.h
  flang/unittests/Runtime/Derived.cpp
  flang/unittests/Runtime/ExternalIOTest.cpp
  flang/unittests/Runtime/Format.cpp
  flang/unittests/Runtime/Inquiry.cpp
  flang/unittests/Runtime/ListInputTest.cpp
  flang/unittests/Runtime/LogicalFormatTest.cpp
  flang/unittests/Runtime/Matmul.cpp
  flang/unittests/Runtime/MatmulTranspose.cpp
  flang/unittests/Runtime/MiscIntrinsic.cpp
  flang/unittests/Runtime/Namelist.cpp
  flang/unittests/Runtime/Numeric.cpp
  flang/unittests/Runtime/NumericalFormatTest.cpp
  flang/unittests/Runtime/Pointer.cpp
  flang/unittests/Runtime/Ragged.cpp
  flang/unittests/Runtime/Random.cpp
  flang/unittests/Runtime/Reduction.cpp
  flang/unittests/Runtime/RuntimeCrashTest.cpp
  flang/unittests/Runtime/Stop.cpp
  flang/unittests/Runtime/TemporaryStack.cpp
  flang/unittests/Runtime/Time.cpp
  flang/unittests/Runtime/Transformational.cpp
  flang/unittests/Runtime/tools.h
  lld/COFF/MinGW.cpp
  llvm/CMakeLists.txt
  llvm/projects/CMakeLists.txt
  llvm/runtimes/CMakeLists.txt
  runtimes/CMakeLists.txt

Index: runtimes/CMakeLists.txt
===
--- runtimes/CMakeLists.txt
+++ runtime

[clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2023-09-30 Thread Connor Sughrue via cfe-commits

https://github.com/cpsughrue updated 
https://github.com/llvm/llvm-project/pull/67562

>From 5def87462e3b48cfebafdc2526ac929f5cb9cea3 Mon Sep 17 00:00:00 2001
From: cpsughrue 
Date: Sun, 9 Jul 2023 23:19:58 -0400
Subject: [PATCH 1/4] [clang][MBD] set up module build daemon infrastructure

The module build daemon (mbd) will serve as a cc1 tool that helps convert
implicit module command lines to explicit module command lines. A clang
invocation will check to see if a mbd exists, if not the invocation will spawn
one. After the mbd is up and running and a handshake has successfully been
carried out between the mbd and clang invocation the clang invocation will
share it's command line with the mbd. The mbd will then scan the translation
unit and build all modular dependencies before returning a modified cc1 command
 line such that all arguments related to modules are converted from the
implicit option to their explicit option.

This commit sets up the basic mbd infrastructure. Including the ability to
spawn a mbd and carry out a handshake between the clang invocation and mbd.

RFC: 
https://discourse.llvm.org/t/rfc-modules-build-daemon-build-system-agnostic-support-for-explicitly-built-modules/71524
---
 clang/include/clang/Driver/Options.td |  12 +
 .../include/clang/Frontend/FrontendOptions.h  |   7 +
 .../clang/Tooling/ModuleBuildDaemon/Client.h  |  44 +++
 .../ModuleBuildDaemon/SocketMsgSupport.h  | 134 +
 .../Tooling/ModuleBuildDaemon/SocketSupport.h |  31 ++
 .../clang/Tooling/ModuleBuildDaemon/Utils.h   |  28 ++
 clang/lib/Driver/ToolChains/Clang.cpp |  14 +-
 clang/lib/Tooling/CMakeLists.txt  |   1 +
 .../Tooling/ModuleBuildDaemon/CMakeLists.txt  |   9 +
 .../lib/Tooling/ModuleBuildDaemon/Client.cpp  | 167 +++
 .../ModuleBuildDaemon/SocketSupport.cpp   | 128 +
 clang/lib/Tooling/ModuleBuildDaemon/Utils.cpp |  32 +++
 clang/test/Driver/unknown-arg.c   |   2 +-
 clang/test/ModuleBuildDaemon/handshake.c  |  18 ++
 clang/test/ModuleBuildDaemon/launch.c |  14 +
 clang/tools/driver/CMakeLists.txt |   3 +
 clang/tools/driver/cc1_main.cpp   |  28 +-
 clang/tools/driver/cc1modbuildd_main.cpp  | 267 ++
 clang/tools/driver/driver.cpp |  17 +-
 19 files changed, 947 insertions(+), 9 deletions(-)
 create mode 100644 clang/include/clang/Tooling/ModuleBuildDaemon/Client.h
 create mode 100644 
clang/include/clang/Tooling/ModuleBuildDaemon/SocketMsgSupport.h
 create mode 100644 
clang/include/clang/Tooling/ModuleBuildDaemon/SocketSupport.h
 create mode 100644 clang/include/clang/Tooling/ModuleBuildDaemon/Utils.h
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/CMakeLists.txt
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/Client.cpp
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/SocketSupport.cpp
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/Utils.cpp
 create mode 100644 clang/test/ModuleBuildDaemon/handshake.c
 create mode 100644 clang/test/ModuleBuildDaemon/launch.c
 create mode 100644 clang/tools/driver/cc1modbuildd_main.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index efd90942948af27..d31d28255e81a8a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2836,6 +2836,18 @@ defm declspec : BoolOption<"f", "declspec",
   NegFlag,
   BothFlags<[], [ClangOption, CC1Option],
   " __declspec as a keyword">>, Group;
+
+def fmodule_build_daemon : Flag<["-"], "fmodule-build-daemon">, Group,
+  Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Enables module build daemon functionality">,
+  MarshallingInfoFlag>;
+def fmodule_build_daemon_EQ : Joined<["-"], "fmodule-build-daemon=">, 
Group,
+  Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Enables module build daemon functionality and defines location of 
output files">,
+  MarshallingInfoString>;
+
 def fmodules_cache_path : Joined<["-"], "fmodules-cache-path=">, 
Group,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
   MetaVarName<"">,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 117e35de6f76c4c..8ce97a57d413c0b 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -350,6 +350,9 @@ class FrontendOptions {
   /// Whether to share the FileManager when building modules.
   unsigned ModulesShareFileManager : 1;
 
+  /// Connect to module build daemon
+  unsigned ModuleBuildDaemon : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.
@@ -435,6 +438,10 @@ class FrontendOptions {
   /// The output file, if any.
   std::string OutputFile;
 
+  /// If given, the path to the module build daemon's output files and socket
+  /// address
+  std::string ModuleB

[clang-tools-extra] [clang-cl] Fix value of __FUNCTION__ and __func__ in MSVC mode. (PR #67592)

2023-09-30 Thread Zahira Ammarguellat via cfe-commits

https://github.com/zahiraam updated 
https://github.com/llvm/llvm-project/pull/67592

>From 55b67a58ef8b9856e5f0a8f535b8617f59711dec Mon Sep 17 00:00:00 2001
From: Ammarguellat 
Date: Wed, 27 Sep 2023 11:59:04 -0700
Subject: [PATCH 1/6] Fix value of __FUNCTION__ and __func__ in MSVC mode.

---
 clang/lib/AST/Expr.cpp|  9 ++-
 clang/lib/AST/TypePrinter.cpp | 21 +-
 clang/test/Analysis/eval-predefined-exprs.cpp |  4 +-
 .../CodeGenCXX/mangle-nttp-anon-union.cpp |  2 +-
 clang/test/CodeGenCXX/predefined-expr.cpp | 18 -
 clang/test/SemaCXX/source_location.cpp| 72 +++
 6 files changed, 99 insertions(+), 27 deletions(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index af82ca0784af413..49f3495c090f191 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -773,8 +773,8 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, const 
Decl *CurrentDecl) {
   }
   if (const FunctionDecl *FD = dyn_cast(CurrentDecl)) {
 const auto &LO = Context.getLangOpts();
-if (((IK == Func || IK == Function) && !LO.MicrosoftExt) ||
-(IK == LFunction && LO.MicrosoftExt))
+if (((IK == Function || IK == Func) && !LO.MicrosoftExt) ||
+((IK == LFunction || IK == Func) && LO.MicrosoftExt))
   return FD->getNameAsString();
 
 SmallString<256> Name;
@@ -804,7 +804,10 @@ std::string PredefinedExpr::ComputeName(IdentKind IK, 
const Decl *CurrentDecl) {
 PrintingPolicy Policy(LO);
 PrettyCallbacks PrettyCB(LO);
 Policy.Callbacks = &PrettyCB;
-Policy.UseClassForTemplateArgument = LO.MicrosoftExt;
+if (IK == Function && LO.MicrosoftExt) {
+  Policy.UseClassForTemplateArgument = LO.MicrosoftExt;
+  Policy.MSVCFormatting = LO.MicrosoftExt;
+}
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
diff --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 3771a29f26b173f..8a7cf85cdf126b6 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2195,6 +2195,7 @@ printTo(raw_ostream &OS, ArrayRef Args, const 
PrintingPolicy &Policy,
 llvm::SmallVector OrigArgs;
 for (const TA &A : Args)
   OrigArgs.push_back(getArgument(A));
+
 while (!Args.empty() && getArgument(Args.back()).getIsDefaulted())
   Args = Args.drop_back();
   }
@@ -2218,10 +2219,24 @@ printTo(raw_ostream &OS, ArrayRef Args, const 
PrintingPolicy &Policy,
 } else {
   if (!FirstArg)
 OS << Comma;
-  if (Policy.UseClassForTemplateArgument &&
-  Argument.getKind() == TemplateArgument::Type)
-OS << "class ";
 
+  if (Policy.MSVCFormatting && Policy.UseClassForTemplateArgument &&
+  Argument.getKind() == TemplateArgument::Type &&
+  !Argument.getAsType()->isBuiltinType()) {
+const Type *Ty = Argument.getAsType().getTypePtr();
+const char *kw;
+if (Ty->isStructureType())
+  kw = "struct ";
+else if (Ty->isClassType())
+  kw = "class ";
+else if (Ty->isUnionType())
+  kw = "union ";
+else if (Ty->isEnumeralType())
+  kw = "enum ";
+else
+  llvm_unreachable("argument type not expected");
+OS << kw;
+  }
   // Tries to print the argument with location info if exists.
   printArgument(Arg, Policy, ArgOS,
 TemplateParameterList::shouldIncludeTypeForArgument(
diff --git a/clang/test/Analysis/eval-predefined-exprs.cpp 
b/clang/test/Analysis/eval-predefined-exprs.cpp
index 7be441eb5bad943..a6bac5ee9d486d2 100644
--- a/clang/test/Analysis/eval-predefined-exprs.cpp
+++ b/clang/test/Analysis/eval-predefined-exprs.cpp
@@ -56,7 +56,7 @@ struct A {
 clang_analyzer_dump(__FUNCTION__);
 clang_analyzer_dump(__PRETTY_FUNCTION__);
 #ifdef ANALYZER_MS
-// expected-warning@-4 {{&Element{"A::A",0 S64b,char}}}
+// expected-warning@-4 {{&Element{"A",0 S64b,char}}}
 // expected-warning@-4 {{&Element{"A::A",0 S64b,char}}}
 #else
 // expected-warning@-7 {{&Element{"A",0 S64b,char}}}
@@ -80,7 +80,7 @@ struct A {
 clang_analyzer_dump(__FUNCTION__);
 clang_analyzer_dump(__PRETTY_FUNCTION__);
 #ifdef ANALYZER_MS
-// expected-warning@-4 {{&Element{"A::~A",0 S64b,char}}}
+// expected-warning@-4 {{&Element{"~A",0 S64b,char}}}
 // expected-warning@-4 {{&Element{"A::~A",0 S64b,char}}}
 #else
 // expected-warning@-7 {{&Element{"~A",0 S64b,char}}}
diff --git a/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp 
b/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp
index 78fa7c378c88d50..1982a3eeb941291 100644
--- a/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp
+++ b/clang/test/CodeGenCXX/mangle-nttp-anon-union.cpp
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -std=c++20 -emit-llvm %s -o - -triple=x86_64-linux-gnu | 
FileCheck %s
-// RUN: %clang_cc1 -std=c++20 -emit-llvm %s -o - -triple=x86_64-linux-gnu | 
llvm-cxxfilt -n | FileCheck %s --check-pr

[clang] [clang-cl] Fix value of __FUNCTION__ in MSVC mode. (PR #67592)

2023-09-30 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [clang][Interp] Handle variadic functions (PR #67814)

2023-09-30 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/67814

>From 64aae1cdf960f3edb34f1cf82ae3e66eb692247a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 29 Sep 2023 16:43:59 +0200
Subject: [PATCH 1/2] [clang][Interp] Handle variadic functions

Similarly to the code we already had for builtin functions, we need to
check the call expression for the arguments passed.
---
 clang/lib/AST/Interp/Function.cpp   |  2 +-
 clang/lib/AST/Interp/Function.h |  3 ++
 clang/lib/AST/Interp/Interp.cpp | 49 +++--
 clang/lib/AST/Interp/Interp.h   | 18 +++
 clang/test/AST/Interp/functions.cpp | 21 +
 5 files changed, 69 insertions(+), 24 deletions(-)

diff --git a/clang/lib/AST/Interp/Function.cpp 
b/clang/lib/AST/Interp/Function.cpp
index 0b7cfc4e28883f0..357aff7fe6229b9 100644
--- a/clang/lib/AST/Interp/Function.cpp
+++ b/clang/lib/AST/Interp/Function.cpp
@@ -24,7 +24,7 @@ Function::Function(Program &P, const FunctionDecl *F, 
unsigned ArgSize,
 : P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize),
   ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
   ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer),
-  HasRVO(HasRVO) {}
+  HasRVO(HasRVO), Variadic(F->isVariadic()) {}
 
 Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
   auto It = Params.find(Offset);
diff --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index 0bae314e97701d9..15bdd39dfde9d99 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -172,6 +172,8 @@ class Function final {
   /// Checks if the function is defined.
   bool isDefined() const { return Defined; }
 
+  bool isVariadic() const { return Variadic; }
+
   unsigned getBuiltinID() const { return F->getBuiltinID(); }
 
   bool isBuiltin() const { return F->getBuiltinID() != 0; }
@@ -250,6 +252,7 @@ class Function final {
   /// If we've already compiled the function's body.
   bool HasBody = false;
   bool Defined = false;
+  bool Variadic = false;
 
 public:
   /// Dumps the disassembled bytecode to \c llvm::errs().
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index e1951574edb6288..639ceb140e99de3 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -121,18 +121,47 @@ static bool CheckGlobal(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr) {
 
 namespace clang {
 namespace interp {
+static void popArg(InterpState &S, const Expr *Arg) {
+  PrimType Ty = S.getContext().classify(Arg->getType()).value_or(PT_Ptr);
+  TYPE_SWITCH(Ty, S.Stk.discard());
+}
+
+void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC) {
+  assert(S.Current);
+  const Function *CurFunc = S.Current->getFunction();
+  assert(CurFunc);
+
+  // Certain builtin functions are declared as func-name(...), so the
+  // parameters are checked in Sema and only available through the CallExpr.
+  // The interp::Function we create for them has 0 parameters, so we need to
+  // remove them from the stack by checking the CallExpr.
+  // FIXME: This is potentially just a special case and could be handled more
+  // generally with the code just below?
+  if (CurFunc->needsRuntimeArgPop(S.getCtx())) {
+const CallExpr *CE = cast(S.Current->getExpr(OpPC));
+for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
+  popArg(S, CE->getArg(I));
+}
+return;
+  }
 
-bool popBuiltinArgs(InterpState &S, CodePtr OpPC) {
-  assert(S.Current && 
S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()));
-  const Expr *E = S.Current->getExpr(OpPC);
-  assert(isa(E));
-  const CallExpr *CE = cast(E);
-  for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
-const Expr *A = CE->getArg(I);
-PrimType Ty = S.getContext().classify(A->getType()).value_or(PT_Ptr);
-TYPE_SWITCH(Ty, S.Stk.discard());
+  if (S.Current->Caller && CurFunc->isVariadic()) {
+// CallExpr we're look for is at the return PC of the current function, 
i.e.
+// in the caller.
+// This code path should be executed very rarely.
+const CallExpr *CE =
+cast(S.Current->Caller->getExpr(S.Current->getRetPC()));
+unsigned FixedParams = CurFunc->getNumParams();
+int32_t ArgsToPop = CE->getNumArgs() - FixedParams;
+assert(ArgsToPop >= 0);
+for (int32_t I = ArgsToPop - 1; I >= 0; --I) {
+  const Expr *A = CE->getArg(FixedParams + I);
+  popArg(S, A);
+}
   }
-  return true;
+  // And in any case, remove the fixed parameters (the non-variadic ones)
+  // at the end.
+  S.Current->popArgs();
 }
 
 bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index dd37150b63f6db0..d67b8b978031aac 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -200,8 

[clang] [clang][Interp] Handle variadic functions (PR #67814)

2023-09-30 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/67814

>From 64aae1cdf960f3edb34f1cf82ae3e66eb692247a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 29 Sep 2023 16:43:59 +0200
Subject: [PATCH] [clang][Interp] Handle variadic functions

Similarly to the code we already had for builtin functions, we need to
check the call expression for the arguments passed.
---
 clang/lib/AST/Interp/Function.cpp   |  2 +-
 clang/lib/AST/Interp/Function.h |  3 ++
 clang/lib/AST/Interp/Interp.cpp | 49 +++--
 clang/lib/AST/Interp/Interp.h   | 18 +++
 clang/test/AST/Interp/functions.cpp | 21 +
 5 files changed, 69 insertions(+), 24 deletions(-)

diff --git a/clang/lib/AST/Interp/Function.cpp 
b/clang/lib/AST/Interp/Function.cpp
index 0b7cfc4e28883f0..357aff7fe6229b9 100644
--- a/clang/lib/AST/Interp/Function.cpp
+++ b/clang/lib/AST/Interp/Function.cpp
@@ -24,7 +24,7 @@ Function::Function(Program &P, const FunctionDecl *F, 
unsigned ArgSize,
 : P(P), Loc(F->getBeginLoc()), F(F), ArgSize(ArgSize),
   ParamTypes(std::move(ParamTypes)), Params(std::move(Params)),
   ParamOffsets(std::move(ParamOffsets)), HasThisPointer(HasThisPointer),
-  HasRVO(HasRVO) {}
+  HasRVO(HasRVO), Variadic(F->isVariadic()) {}
 
 Function::ParamDescriptor Function::getParamDescriptor(unsigned Offset) const {
   auto It = Params.find(Offset);
diff --git a/clang/lib/AST/Interp/Function.h b/clang/lib/AST/Interp/Function.h
index 0bae314e97701d9..15bdd39dfde9d99 100644
--- a/clang/lib/AST/Interp/Function.h
+++ b/clang/lib/AST/Interp/Function.h
@@ -172,6 +172,8 @@ class Function final {
   /// Checks if the function is defined.
   bool isDefined() const { return Defined; }
 
+  bool isVariadic() const { return Variadic; }
+
   unsigned getBuiltinID() const { return F->getBuiltinID(); }
 
   bool isBuiltin() const { return F->getBuiltinID() != 0; }
@@ -250,6 +252,7 @@ class Function final {
   /// If we've already compiled the function's body.
   bool HasBody = false;
   bool Defined = false;
+  bool Variadic = false;
 
 public:
   /// Dumps the disassembled bytecode to \c llvm::errs().
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index e1951574edb6288..639ceb140e99de3 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -121,18 +121,47 @@ static bool CheckGlobal(InterpState &S, CodePtr OpPC, 
const Pointer &Ptr) {
 
 namespace clang {
 namespace interp {
+static void popArg(InterpState &S, const Expr *Arg) {
+  PrimType Ty = S.getContext().classify(Arg->getType()).value_or(PT_Ptr);
+  TYPE_SWITCH(Ty, S.Stk.discard());
+}
+
+void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC) {
+  assert(S.Current);
+  const Function *CurFunc = S.Current->getFunction();
+  assert(CurFunc);
+
+  // Certain builtin functions are declared as func-name(...), so the
+  // parameters are checked in Sema and only available through the CallExpr.
+  // The interp::Function we create for them has 0 parameters, so we need to
+  // remove them from the stack by checking the CallExpr.
+  // FIXME: This is potentially just a special case and could be handled more
+  // generally with the code just below?
+  if (CurFunc->needsRuntimeArgPop(S.getCtx())) {
+const CallExpr *CE = cast(S.Current->getExpr(OpPC));
+for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
+  popArg(S, CE->getArg(I));
+}
+return;
+  }
 
-bool popBuiltinArgs(InterpState &S, CodePtr OpPC) {
-  assert(S.Current && 
S.Current->getFunction()->needsRuntimeArgPop(S.getCtx()));
-  const Expr *E = S.Current->getExpr(OpPC);
-  assert(isa(E));
-  const CallExpr *CE = cast(E);
-  for (int32_t I = CE->getNumArgs() - 1; I >= 0; --I) {
-const Expr *A = CE->getArg(I);
-PrimType Ty = S.getContext().classify(A->getType()).value_or(PT_Ptr);
-TYPE_SWITCH(Ty, S.Stk.discard());
+  if (S.Current->Caller && CurFunc->isVariadic()) {
+// CallExpr we're look for is at the return PC of the current function, 
i.e.
+// in the caller.
+// This code path should be executed very rarely.
+const CallExpr *CE =
+cast(S.Current->Caller->getExpr(S.Current->getRetPC()));
+unsigned FixedParams = CurFunc->getNumParams();
+int32_t ArgsToPop = CE->getNumArgs() - FixedParams;
+assert(ArgsToPop >= 0);
+for (int32_t I = ArgsToPop - 1; I >= 0; --I) {
+  const Expr *A = CE->getArg(FixedParams + I);
+  popArg(S, A);
+}
   }
-  return true;
+  // And in any case, remove the fixed parameters (the non-variadic ones)
+  // at the end.
+  S.Current->popArgs();
 }
 
 bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index dd37150b63f6db0..d67b8b978031aac 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -200,8 +200,7 @@ enum class ArithOp { Add, Sub };
 // Returnin

[clang] 16b9e6f - [clang][Interp] Add IntegralAP for arbitrary-precision integers (#65844)

2023-09-30 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-09-30T20:08:22+02:00
New Revision: 16b9e6fbac4c0bd94c66e7670a41b5c266cf7bff

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

LOG: [clang][Interp] Add IntegralAP for arbitrary-precision integers (#65844)

This adds `IntegralAP` backing the two new primtypes `IntAP` (unsigned
arbitrary-precision int) and `IntAPS` (same but signed).

We use this for `int128` support (which isn't available on all host
systems we support AFAIK) and I think we can also use this for `_BitInt`
later.

Added: 
clang/lib/AST/Interp/IntegralAP.h

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpStack.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/PrimType.cpp
clang/lib/AST/Interp/PrimType.h
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 46906377863bd74..4b251931aa01d8a 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   return this->discard(SubExpr);
 std::optional FromT = classify(SubExpr->getType());
 std::optional ToT = classify(CE->getType());
+
 if (!FromT || !ToT)
   return false;
 
 if (!this->visit(SubExpr))
   return false;
 
-if (FromT == ToT)
+if (FromT == ToT) {
+  assert(ToT != PT_IntAP && ToT != PT_IntAPS);
   return true;
+}
 
 return this->emitCast(*FromT, *ToT, CE);
   }
@@ -1638,6 +1641,9 @@ bool 
ByteCodeExprGen::visitZeroInitializer(QualType QT,
 return this->emitZeroSint64(E);
   case PT_Uint64:
 return this->emitZeroUint64(E);
+  case PT_IntAP:
+  case PT_IntAPS:
+assert(false);
   case PT_Ptr:
 return this->emitNullPtr(E);
   case PT_FnPtr:
@@ -1877,6 +1883,9 @@ bool ByteCodeExprGen::emitConst(T Value, 
PrimType Ty, const Expr *E) {
 return this->emitConstSint64(Value, E);
   case PT_Uint64:
 return this->emitConstUint64(Value, E);
+  case PT_IntAP:
+  case PT_IntAPS:
+assert(false);
   case PT_Bool:
 return this->emitConstBool(Value, E);
   case PT_Ptr:

diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index e84c0f6aae7ee93..04710cd0f2c28ee 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -103,7 +103,7 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Sint8;
 default:
-  return std::nullopt;
+  return PT_IntAPS;
 }
   }
 
@@ -118,7 +118,7 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Uint8;
 default:
-  return std::nullopt;
+  return PT_IntAP;
 }
   }
 

diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index db49a569eff33ea..4ecb7466998e705 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -10,6 +10,7 @@
 #include "Boolean.h"
 #include "Floating.h"
 #include "FunctionPointer.h"
+#include "IntegralAP.h"
 #include "Pointer.h"
 #include "PrimType.h"
 #include "Record.h"
@@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) {
   // constructor called.
   if (Type == PT_Float)
 return ctorTy::T>;
+  if (Type == PT_IntAP)
+return ctorTy::T>;
+  if (Type == PT_IntAPS)
+return ctorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr);
 }
@@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) {
   // destructor called, since they might allocate memory.
   if (Type == PT_Float)
 return dtorTy::T>;
+  if (Type == PT_IntAP)
+return dtorTy::T>;
+  if (Type == PT_IntAPS)
+return dtorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }

diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index bdf800c60f1723f..f46ef1067cf52a0 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -9,6 +9,7 @@
 #include "EvalEmitter.h"
 #include "ByteCodeGenError.h"
 #include "Context.h"
+#include "IntegralAP.h"
 #include "Interp.h"
 #include "Opcode.h"
 #include "clang/AST/DeclCXX.h"

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 0295a9c3b5c898c..4dbe9c9bcb14b43 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -29,6 +29,8 @@ namespace interp {
 using APInt = llvm::APInt;
 using APSInt = llvm::APSInt;
 
+template  class 

[clang] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)

2023-09-30 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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


[clang] [Clang][OpenMP][OMPIRBuilder] Move Clang's OpenMP Member/MemberOf flag helpers into the OMPIRBuilder (PR #67844)

2023-09-30 Thread via cfe-commits

shraiysh wrote:

LGTM. Is it possible to add some tests for this? I think we might be able to 
add some in OpenMPIRBuilderTest.cpp. 

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


[clang] 4bae636 - Revert "[clang][Interp] Add IntegralAP for arbitrary-precision integers (#65844)"

2023-09-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-09-30T20:12:14+02:00
New Revision: 4bae636abfe4d9ef4b778fc3e4ea0a3fc33e2f37

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

LOG: Revert "[clang][Interp] Add IntegralAP for arbitrary-precision integers 
(#65844)"

This reverts commit 16b9e6fbac4c0bd94c66e7670a41b5c266cf7bff.

This breaks buildbots.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpStack.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/PrimType.cpp
clang/lib/AST/Interp/PrimType.h
clang/test/AST/Interp/literals.cpp

Removed: 
clang/lib/AST/Interp/IntegralAP.h



diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 4b251931aa01d8a..46906377863bd74 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -171,17 +171,14 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   return this->discard(SubExpr);
 std::optional FromT = classify(SubExpr->getType());
 std::optional ToT = classify(CE->getType());
-
 if (!FromT || !ToT)
   return false;
 
 if (!this->visit(SubExpr))
   return false;
 
-if (FromT == ToT) {
-  assert(ToT != PT_IntAP && ToT != PT_IntAPS);
+if (FromT == ToT)
   return true;
-}
 
 return this->emitCast(*FromT, *ToT, CE);
   }
@@ -1641,9 +1638,6 @@ bool 
ByteCodeExprGen::visitZeroInitializer(QualType QT,
 return this->emitZeroSint64(E);
   case PT_Uint64:
 return this->emitZeroUint64(E);
-  case PT_IntAP:
-  case PT_IntAPS:
-assert(false);
   case PT_Ptr:
 return this->emitNullPtr(E);
   case PT_FnPtr:
@@ -1883,9 +1877,6 @@ bool ByteCodeExprGen::emitConst(T Value, 
PrimType Ty, const Expr *E) {
 return this->emitConstSint64(Value, E);
   case PT_Uint64:
 return this->emitConstUint64(Value, E);
-  case PT_IntAP:
-  case PT_IntAPS:
-assert(false);
   case PT_Bool:
 return this->emitConstBool(Value, E);
   case PT_Ptr:

diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 04710cd0f2c28ee..e84c0f6aae7ee93 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -103,7 +103,7 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Sint8;
 default:
-  return PT_IntAPS;
+  return std::nullopt;
 }
   }
 
@@ -118,7 +118,7 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Uint8;
 default:
-  return PT_IntAP;
+  return std::nullopt;
 }
   }
 

diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index 4ecb7466998e705..db49a569eff33ea 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -10,7 +10,6 @@
 #include "Boolean.h"
 #include "Floating.h"
 #include "FunctionPointer.h"
-#include "IntegralAP.h"
 #include "Pointer.h"
 #include "PrimType.h"
 #include "Record.h"
@@ -183,10 +182,6 @@ static BlockCtorFn getCtorPrim(PrimType Type) {
   // constructor called.
   if (Type == PT_Float)
 return ctorTy::T>;
-  if (Type == PT_IntAP)
-return ctorTy::T>;
-  if (Type == PT_IntAPS)
-return ctorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr);
 }
@@ -196,10 +191,6 @@ static BlockDtorFn getDtorPrim(PrimType Type) {
   // destructor called, since they might allocate memory.
   if (Type == PT_Float)
 return dtorTy::T>;
-  if (Type == PT_IntAP)
-return dtorTy::T>;
-  if (Type == PT_IntAPS)
-return dtorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }

diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index f46ef1067cf52a0..bdf800c60f1723f 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -9,7 +9,6 @@
 #include "EvalEmitter.h"
 #include "ByteCodeGenError.h"
 #include "Context.h"
-#include "IntegralAP.h"
 #include "Interp.h"
 #include "Opcode.h"
 #include "clang/AST/DeclCXX.h"

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 4dbe9c9bcb14b43..0295a9c3b5c898c 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -29,8 +29,6 @@ namespace interp {
 using APInt = llvm::APInt;
 using APSInt = llvm::APSInt;
 
-template  class IntegralAP;
-
 // Helper structure to select the representation.
 template  struct Repr;
 template <> struct Repr<8, false> { using Type = uint8_t; };
@@ -63,8 +61,6 @@ template  cla

[clang] [clang][MBD] set up module build daemon infrastructure (PR #67562)

2023-09-30 Thread Connor Sughrue via cfe-commits

https://github.com/cpsughrue updated 
https://github.com/llvm/llvm-project/pull/67562

>From 5def87462e3b48cfebafdc2526ac929f5cb9cea3 Mon Sep 17 00:00:00 2001
From: cpsughrue 
Date: Sun, 9 Jul 2023 23:19:58 -0400
Subject: [PATCH 1/5] [clang][MBD] set up module build daemon infrastructure

The module build daemon (mbd) will serve as a cc1 tool that helps convert
implicit module command lines to explicit module command lines. A clang
invocation will check to see if a mbd exists, if not the invocation will spawn
one. After the mbd is up and running and a handshake has successfully been
carried out between the mbd and clang invocation the clang invocation will
share it's command line with the mbd. The mbd will then scan the translation
unit and build all modular dependencies before returning a modified cc1 command
 line such that all arguments related to modules are converted from the
implicit option to their explicit option.

This commit sets up the basic mbd infrastructure. Including the ability to
spawn a mbd and carry out a handshake between the clang invocation and mbd.

RFC: 
https://discourse.llvm.org/t/rfc-modules-build-daemon-build-system-agnostic-support-for-explicitly-built-modules/71524
---
 clang/include/clang/Driver/Options.td |  12 +
 .../include/clang/Frontend/FrontendOptions.h  |   7 +
 .../clang/Tooling/ModuleBuildDaemon/Client.h  |  44 +++
 .../ModuleBuildDaemon/SocketMsgSupport.h  | 134 +
 .../Tooling/ModuleBuildDaemon/SocketSupport.h |  31 ++
 .../clang/Tooling/ModuleBuildDaemon/Utils.h   |  28 ++
 clang/lib/Driver/ToolChains/Clang.cpp |  14 +-
 clang/lib/Tooling/CMakeLists.txt  |   1 +
 .../Tooling/ModuleBuildDaemon/CMakeLists.txt  |   9 +
 .../lib/Tooling/ModuleBuildDaemon/Client.cpp  | 167 +++
 .../ModuleBuildDaemon/SocketSupport.cpp   | 128 +
 clang/lib/Tooling/ModuleBuildDaemon/Utils.cpp |  32 +++
 clang/test/Driver/unknown-arg.c   |   2 +-
 clang/test/ModuleBuildDaemon/handshake.c  |  18 ++
 clang/test/ModuleBuildDaemon/launch.c |  14 +
 clang/tools/driver/CMakeLists.txt |   3 +
 clang/tools/driver/cc1_main.cpp   |  28 +-
 clang/tools/driver/cc1modbuildd_main.cpp  | 267 ++
 clang/tools/driver/driver.cpp |  17 +-
 19 files changed, 947 insertions(+), 9 deletions(-)
 create mode 100644 clang/include/clang/Tooling/ModuleBuildDaemon/Client.h
 create mode 100644 
clang/include/clang/Tooling/ModuleBuildDaemon/SocketMsgSupport.h
 create mode 100644 
clang/include/clang/Tooling/ModuleBuildDaemon/SocketSupport.h
 create mode 100644 clang/include/clang/Tooling/ModuleBuildDaemon/Utils.h
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/CMakeLists.txt
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/Client.cpp
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/SocketSupport.cpp
 create mode 100644 clang/lib/Tooling/ModuleBuildDaemon/Utils.cpp
 create mode 100644 clang/test/ModuleBuildDaemon/handshake.c
 create mode 100644 clang/test/ModuleBuildDaemon/launch.c
 create mode 100644 clang/tools/driver/cc1modbuildd_main.cpp

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index efd90942948af27..d31d28255e81a8a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2836,6 +2836,18 @@ defm declspec : BoolOption<"f", "declspec",
   NegFlag,
   BothFlags<[], [ClangOption, CC1Option],
   " __declspec as a keyword">>, Group;
+
+def fmodule_build_daemon : Flag<["-"], "fmodule-build-daemon">, Group,
+  Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Enables module build daemon functionality">,
+  MarshallingInfoFlag>;
+def fmodule_build_daemon_EQ : Joined<["-"], "fmodule-build-daemon=">, 
Group,
+  Flags<[NoXarchOption]>,
+  Visibility<[ClangOption, CC1Option]>,
+  HelpText<"Enables module build daemon functionality and defines location of 
output files">,
+  MarshallingInfoString>;
+
 def fmodules_cache_path : Joined<["-"], "fmodules-cache-path=">, 
Group,
   Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>,
   MetaVarName<"">,
diff --git a/clang/include/clang/Frontend/FrontendOptions.h 
b/clang/include/clang/Frontend/FrontendOptions.h
index 117e35de6f76c4c..8ce97a57d413c0b 100644
--- a/clang/include/clang/Frontend/FrontendOptions.h
+++ b/clang/include/clang/Frontend/FrontendOptions.h
@@ -350,6 +350,9 @@ class FrontendOptions {
   /// Whether to share the FileManager when building modules.
   unsigned ModulesShareFileManager : 1;
 
+  /// Connect to module build daemon
+  unsigned ModuleBuildDaemon : 1;
+
   CodeCompleteOptions CodeCompleteOpts;
 
   /// Specifies the output format of the AST.
@@ -435,6 +438,10 @@ class FrontendOptions {
   /// The output file, if any.
   std::string OutputFile;
 
+  /// If given, the path to the module build daemon's output files and socket
+  /// address
+  std::string ModuleB

[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)

2023-09-30 Thread Yingwei Zheng via cfe-commits

dtcxzyw wrote:

Ping.

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


[clang] Update GoogleTest to v1.14.0 (PR #65823)

2023-09-30 Thread Alexandre Ganea via cfe-commits

aganea wrote:

I managed to repro. It is actually this, still open, issue: 
https://github.com/microsoft/STL/issues/1066

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


[PATCH] D138846: MC/DC in LLVM Source-Based Code Coverage: LLVM back-end and compiler-rt

2023-09-30 Thread Alan Phipps via Phabricator via cfe-commits
alanphipps added a comment.

> I added steps to download the profile here: 
> https://bugs.chromium.org/p/chromium/issues/detail?id=1485303#c4 
> I think this should be reverted while being investigated: 
> https://github.com/llvm/llvm-project/commit/53a2923bf67bc164558d489493176630123abf7e

Thank you for the repro! It was a huge help. There was in fact a bug in 
InstrProfReader.cpp where the wrong profile format version was being checked 
before attempting to read MC/DC bitmap bytes.  The check was added to ensure 
backward compatibility with older versions.  I fixed that check and added a 
testcase to ensure v10 of the format can still be handled successfully.

> I just noticed this also broke some lit tests on mac: 
> https://bugs.chromium.org/p/chromium/issues/detail?id=1485487#c0
> That's also visible on greendragon: 
> https://green.lab.llvm.org/green/view/Clang/job/clang-stage1-RA/35721/testReport/

The Mac failures were due a missing adjustment in clang to ensure profile 
sections are properly page aligned.  When I separated out the patches to make 
the process easier, that change ended up in https://reviews.llvm.org/D138849 
with the other MC/DC clang changes when it should've been included in this 
patch.  I've added it and verified that the Mac tests pass with this patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138846/new/

https://reviews.llvm.org/D138846

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


[PATCH] D138846: MC/DC in LLVM Source-Based Code Coverage: LLVM back-end and compiler-rt

2023-09-30 Thread Alan Phipps via Phabricator via cfe-commits
alanphipps added a comment.

In D138846#4649609 , @w2yehia wrote:

> Please update InstrProfilingPlatformAIX.c as well, specifically add new dummy 
> vars for the new section.
> Edit: I can post the patch if you wish.

I just added the dummy vars, but you can have a look.  You're welcome to post 
the patch too and it would be great if you could assist in testing for AIX.   
Thank you!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138846/new/

https://reviews.llvm.org/D138846

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Vladimir Vereschaka via cfe-commits

vvereschaka wrote:

@vgvassilev ,
got failed tests: https://lab.llvm.org/buildbot/#/builders/86/builds/66095

* LLVM-Unit :: ADT/./ADTTests.exe/PagedVectorTest/EmptyTest
* LLVM-Unit :: ADT/./ADTTests.exe/PagedVectorTest/HalfPageFillingTest
* LLVM-Unit :: ADT/./ADTTests.exe/PagedVectorTest/ShrinkTest

would you take care of it?

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


[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)

2023-09-30 Thread Nikita Popov via cfe-commits


@@ -6380,7 +6380,71 @@ Instruction 
*InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) {
   Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE)
 return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y);
 
+  // icmp eq/ne X, (zext/sext (icmp eq/ne X, C))
+  ICmpInst::Predicate Pred1, Pred2;
   const APInt *C;
+  Instruction *ExtI;
+  if (match(&I, m_c_ICmp(Pred1, m_Value(X),
+ m_CombineAnd(m_Instruction(ExtI),
+  m_ZExtOrSExt(m_ICmp(Pred2, m_Deferred(X),
+  m_APInt(C))) {

nikic wrote:

As far as I can tell, nothing here checks that Pred1 and Pred2 are equality 
predicates, so all the "else" branches below assuming that "else" is eq/ne are 
wrong? I don't see any negative tests for non-equality predicates either.

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


[clang-tools-extra] [InstCombine] Simplify the pattern `a ne/eq (zext/sext (a ne/eq c))` (PR #65852)

2023-09-30 Thread Nikita Popov via cfe-commits


@@ -6380,7 +6380,71 @@ Instruction 
*InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) {
   Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE)
 return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y);
 
+  // icmp eq/ne X, (zext/sext (icmp eq/ne X, C))
+  ICmpInst::Predicate Pred1, Pred2;
   const APInt *C;
+  Instruction *ExtI;
+  if (match(&I, m_c_ICmp(Pred1, m_Value(X),
+ m_CombineAnd(m_Instruction(ExtI),
+  m_ZExtOrSExt(m_ICmp(Pred2, m_Deferred(X),
+  m_APInt(C))) {
+bool IsSExt = ExtI->getOpcode() == Instruction::SExt;
+bool HasOneUse = ExtI->hasOneUse() && ExtI->getOperand(0)->hasOneUse();
+auto CreateRangeCheck = [&] {
+  Value *CmpV1 =
+  Builder.CreateICmp(Pred1, X, Constant::getNullValue(X->getType()));
+  Value *CmpV2 = Builder.CreateICmp(
+  Pred1, X, ConstantInt::get(X->getType(), IsSExt ? -1 : 1));
+  return BinaryOperator::Create(
+  Pred1 == ICmpInst::ICMP_EQ ? Instruction::Or : Instruction::And,
+  CmpV1, CmpV2);
+};
+if (C->isZero()) {
+  if (Pred2 == ICmpInst::ICMP_EQ) {
+// icmp eq X, (zext/sext (icmp eq X, 0)) --> false
+// icmp ne X, (zext/sext (icmp eq X, 0)) --> true
+return replaceInstUsesWith(
+I, ConstantInt::getBool(I.getType(), Pred1 == ICmpInst::ICMP_NE));
+  } else if (!IsSExt || HasOneUse) {
+// icmp eq X, (zext (icmp ne X, 0)) --> X == 0 || X == 1
+// icmp ne X, (zext (icmp ne X, 0)) --> X != 0 && X != 1
+// icmp eq X, (sext (icmp ne X, 0)) --> X == 0 || X == -1
+// icmp ne X, (sext (icmp ne X, 0)) --> X != 0 && X == -1
+return CreateRangeCheck();
+  }
+} else if (IsSExt ? C->isAllOnes() : C->isOne()) {
+  if (Pred2 == ICmpInst::ICMP_NE) {
+// icmp eq X, (zext (icmp ne X, 1)) --> false
+// icmp ne X, (zext (icmp ne X, 1)) --> true
+// icmp eq X, (sext (icmp ne X, -1)) --> false
+// icmp ne X, (sext (icmp ne X, -1)) --> true
+return replaceInstUsesWith(
+I, ConstantInt::getBool(I.getType(), Pred1 == ICmpInst::ICMP_NE));
+  } else if (!IsSExt || HasOneUse) {
+// icmp eq X, (zext (icmp eq X, 1)) --> X == 0 || X == 1
+// icmp ne X, (zext (icmp eq X, 1)) --> X != 0 && X != 1
+// icmp eq X, (sext (icmp eq X, -1)) --> X == 0 || X == -1
+// icmp ne X, (sext (icmp eq X, -1)) --> X != 0 && X == -1
+return CreateRangeCheck();
+  }
+} else {
+  // when C != 0 && C != 1:
+  //   icmp eq X, (zext (icmp eq X, C)) --> icmp eq X, 0
+  //   icmp eq X, (zext (icmp ne X, C)) --> icmp eq X, 1
+  //   icmp ne X, (zext (icmp eq X, C)) --> icmp ne X, 0
+  //   icmp ne X, (zext (icmp ne X, C)) --> icmp ne X, 1
+  // when C != 0 && C != -1:
+  //   icmp eq X, (sext (icmp eq X, C)) --> icmp eq X, 0
+  //   icmp eq X, (sext (icmp ne X, C)) --> icmp eq X, -1
+  //   icmp ne X, (sext (icmp eq X, C)) --> icmp ne X, 0
+  //   icmp ne X, (sext (icmp ne X, C)) --> icmp ne X, -1
+  return ICmpInst::Create(
+  Instruction::ICmp, Pred1, X,
+  ConstantInt::get(X->getType(),
+   Pred2 == ICmpInst::ICMP_NE ? (IsSExt ? -1 : 1) : 
0));

nikic wrote:

This looks like something that will break with 128 bit integers.

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Jakub Kuderski via cfe-commits

kuhar wrote:

@vvereschaka I submitted a fix for death tests in 
https://github.com/llvm/llvm-project/commit/8580010672e9ff37b0744927296ca00dbcbef5be

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

@kuhar, thanks, you overtook me. Here is my diff:
```diff
diff --git a/llvm/unittests/ADT/PagedVectorTest.cpp 
b/llvm/unittests/ADT/PagedVectorTest.cpp
index e1b0c62d3395..c45df6d9e7e8 100644
--- a/llvm/unittests/ADT/PagedVectorTest.cpp
+++ b/llvm/unittests/ADT/PagedVectorTest.cpp
@@ -24,8 +24,8 @@ TEST(PagedVectorTest, EmptyTest) {
   EXPECT_EQ(V.materialized_end().getIndex(), 0ULL);
   EXPECT_EQ(std::distance(V.materialized_begin(), V.materialized_end()), 0LL);
 
-  EXPECT_DEATH(V[0], "Index < Size");
-  EXPECT_DEATH(PagedVector(nullptr), "Allocator cannot be null");
+  EXPECT_DEBUG_DEATH(V[0], "Index < Size");
+  EXPECT_DEBUG_DEATH(PagedVector(nullptr), "Allocator cannot be null");
 }
 
 TEST(PagedVectorTest, ExpandTest) {
@@ -69,7 +69,7 @@ TEST(PagedVectorTest, HalfPageFillingTest) {
   for (int I = 0; I < 5; ++I)
 EXPECT_EQ(V[I], I);
   for (int I = 5; I < 10; ++I)
-EXPECT_DEATH(V[I], "Index < Size");
+EXPECT_DEBUG_DEATH(V[I], "Index < Size");
 }
 
 TEST(PagedVectorTest, FillFullMultiPageTest) {
@@ -244,7 +244,7 @@ TEST(PagedVectorTest, ShrinkTest) {
   EXPECT_EQ(V.size(), 0ULL);
   EXPECT_EQ(V.capacity(), 0ULL);
   EXPECT_EQ(std::distance(V.materialized_begin(), V.materialized_end()), 0LL);
-  EXPECT_DEATH(V[0], "Index < Size");
+  EXPECT_DEBUG_DEATH(V[0], "Index < Size");
 }
 
 TEST(PagedVectorTest, FunctionalityTest) {
 ```
 
 Could you use `EXPECT_DEBUG_DEATH` in your fix?

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Jakub Kuderski via cfe-commits

kuhar wrote:

@vgvassilev I've seen other tests use the pattern from my fix. Feel free to 
overwrite with your version if that's preferred.

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Jakub Kuderski via cfe-commits

kuhar wrote:

Also, don't use have to guard that with `#ifdef EXPECT_DEBUG_DEATH`?

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

> @vgvassilev I've seen other tests use the pattern from my fix. Feel free to 
> overwrite with your version if that's preferred.

Too late in the night in my end and I closed my laptop already. I am fine with 
your fix - I find the use of the macro I proposed cleaner though. 

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


[clang] Introduce paged vector (PR #66430)

2023-09-30 Thread Jakub Kuderski via cfe-commits

kuhar wrote:

@vgvassilev 
> I find the use of the macro I proposed cleaner though.

Ideally, I think we could have an llvm-specific macro that combines the guard 
and the check (say `LLVM_EXPECT_DEATH`), so that it's less of a footgun. In any 
case, the failures should be resolved now, and we can iterate it further in the 
future.

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


[clang] [Clang][OpenMP][OMPIRBuilder] Move Clang's OpenMP Member/MemberOf flag helpers into the OMPIRBuilder (PR #67844)

2023-09-30 Thread Johannes Doerfert via cfe-commits

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

LG, tested via the clang tests.

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


[clang] [clang] [MinGW] Tolerate mingw specific linker options during compilation (PR #67891)

2023-09-30 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo created 
https://github.com/llvm/llvm-project/pull/67891

Prior to 591c4b64b3650884c2c68eb47d755ebb62981b99, the mingw specific linker 
options -mthreads, -mconsole, -mwindows and -mdll would be tolerated also at 
compile time, but generating a warning about being unused.

After that commit, they were marked as target specific, which means that it's 
an error if they're unused (which would consider them used for the wrong 
target). These specific options are only relevant when linking, but we want to 
tolerate them at compile time too, like before.

This was fixed for -mthreads in
a79995ca6004082774a87f7a58ab6be5343364b7, while the other options didn't seem 
to be commonly used during compilation.

After the 17.x release, we've got more reports about this actually being an 
issue, in #64464. Therefore, apply the same fix for them; marking them as 
tolerated for mingw targets during compilation, even if they're unused. Also 
add a testcase for -mthreads which was already handled.

Thus, this fixes #64464.

From 5aa262b7805c0d6b82d3216c2f53550c85bf443d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Sun, 1 Oct 2023 00:29:21 +0300
Subject: [PATCH] [clang] [MinGW] Tolerate mingw specific linker options during
 compilation

Prior to 591c4b64b3650884c2c68eb47d755ebb62981b99, the mingw
specific linker options -mthreads, -mconsole, -mwindows and -mdll
would be tolerated also at compile time, but generating a warning
about being unused.

After that commit, they were marked as target specific, which means
that it's an error if they're unused (which would consider them
used for the wrong target). These specific options are only relevant
when linking, but we want to tolerate them at compile time too,
like before.

This was fixed for -mthreads in
a79995ca6004082774a87f7a58ab6be5343364b7, while the other options
didn't seem to be commonly used during compilation.

After the 17.x release, we've got more reports about this
actually being an issue, in #64464. Therefore, apply the same
fix for them; marking them as tolerated for mingw targets during
compilation, even if they're unused.

Thus, this fixes #64464.
---
 clang/lib/Driver/ToolChains/MinGW.cpp|  7 +--
 clang/test/Driver/mingw-linker-options.c | 10 ++
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/mingw-linker-options.c

diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 5af7ea985a28a18..5872e13bda358f8 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -709,8 +709,11 @@ void toolchains::MinGW::addClangTargetOptions(
 }
   }
 
-  if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
-A->ignoreTargetSpecific();
+  for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
+   options::OPT_mconsole, options::OPT_mdll}) {
+if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))
+  A->ignoreTargetSpecific();
+  }
 }
 
 void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
diff --git a/clang/test/Driver/mingw-linker-options.c 
b/clang/test/Driver/mingw-linker-options.c
new file mode 100644
index 000..b4f1d05a719f3af
--- /dev/null
+++ b/clang/test/Driver/mingw-linker-options.c
@@ -0,0 +1,10 @@
+// RUN: %clang --target=x86_64-windows-gnu -c -mwindows %s -### 2>&1 | 
FileCheck %s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mconsole %s -### 2>&1 | 
FileCheck %s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mdll %s -### 2>&1 | FileCheck 
%s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mthreads %s -### 2>&1 | 
FileCheck %s --check-prefix=WARNING
+// RUN: not %clang --target=x86_64-windows-msvc -c -mwindows %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mconsole %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mdll %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mthreads %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// WARNING: warning: argument unused during compilation: '{{.*}}' 
[-Wunused-command-line-argument]
+// ERROR: error: unsupported option '{{.*}}' for target '{{.*}}'

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


[clang] [clang] [MinGW] Tolerate mingw specific linker options during compilation (PR #67891)

2023-09-30 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo updated 
https://github.com/llvm/llvm-project/pull/67891

From da64c467a35cf544df5346b512746715ffc3db32 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Sun, 1 Oct 2023 00:29:21 +0300
Subject: [PATCH] [clang] [MinGW] Tolerate mingw specific linker options during
 compilation

Prior to 591c4b64b3650884c2c68eb47d755ebb62981b99, the mingw
specific linker options -mthreads, -mconsole, -mwindows and -mdll
would be tolerated also at compile time, but generating a warning
about being unused.

After that commit, they were marked as target specific, which means
that it's an error if they're unused (which would consider them
used for the wrong target). These specific options are only relevant
when linking, but we want to tolerate them at compile time too,
like before.

This was fixed for -mthreads in
a79995ca6004082774a87f7a58ab6be5343364b7, while the other options
didn't seem to be commonly used during compilation.

After the 17.x release, we've got more reports about this
actually being an issue, in #64464. Therefore, apply the same
fix for them; marking them as tolerated for mingw targets during
compilation, even if they're unused. Also add a testcase for
-mthreads which was already handled.

Thus, this fixes #64464.
---
 clang/lib/Driver/ToolChains/MinGW.cpp|  7 +--
 clang/test/Driver/mingw-linker-options.c | 10 ++
 2 files changed, 15 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/mingw-linker-options.c

diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 5af7ea985a28a18..5872e13bda358f8 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -709,8 +709,11 @@ void toolchains::MinGW::addClangTargetOptions(
 }
   }
 
-  if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
-A->ignoreTargetSpecific();
+  for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
+   options::OPT_mconsole, options::OPT_mdll}) {
+if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))
+  A->ignoreTargetSpecific();
+  }
 }
 
 void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
diff --git a/clang/test/Driver/mingw-linker-options.c 
b/clang/test/Driver/mingw-linker-options.c
new file mode 100644
index 000..b4f1d05a719f3af
--- /dev/null
+++ b/clang/test/Driver/mingw-linker-options.c
@@ -0,0 +1,10 @@
+// RUN: %clang --target=x86_64-windows-gnu -c -mwindows %s -### 2>&1 | 
FileCheck %s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mconsole %s -### 2>&1 | 
FileCheck %s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mdll %s -### 2>&1 | FileCheck 
%s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mthreads %s -### 2>&1 | 
FileCheck %s --check-prefix=WARNING
+// RUN: not %clang --target=x86_64-windows-msvc -c -mwindows %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mconsole %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mdll %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mthreads %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// WARNING: warning: argument unused during compilation: '{{.*}}' 
[-Wunused-command-line-argument]
+// ERROR: error: unsupported option '{{.*}}' for target '{{.*}}'

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


[clang] [clang] [MinGW] Tolerate mingw specific linker options during compilation (PR #67891)

2023-09-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-platform-windows


Changes

Prior to 591c4b64b3650884c2c68eb47d755ebb62981b99, the mingw specific linker 
options -mthreads, -mconsole, -mwindows and -mdll would be tolerated also at 
compile time, but generating a warning about being unused.

After that commit, they were marked as target specific, which means that it's 
an error if they're unused (which would consider them used for the wrong 
target). These specific options are only relevant when linking, but we want to 
tolerate them at compile time too, like before.

This was fixed for -mthreads in
a79995ca6004082774a87f7a58ab6be5343364b7, while the other options didn't seem 
to be commonly used during compilation.

After the 17.x release, we've got more reports about this actually being an 
issue, in #64464. Therefore, apply the same fix for them; marking them 
as tolerated for mingw targets during compilation, even if they're unused. Also 
add a testcase for -mthreads which was already handled.

Thus, this fixes #64464.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/MinGW.cpp (+5-2) 
- (added) clang/test/Driver/mingw-linker-options.c (+10) 


``diff
diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp 
b/clang/lib/Driver/ToolChains/MinGW.cpp
index 5af7ea985a28a18..5872e13bda358f8 100644
--- a/clang/lib/Driver/ToolChains/MinGW.cpp
+++ b/clang/lib/Driver/ToolChains/MinGW.cpp
@@ -709,8 +709,11 @@ void toolchains::MinGW::addClangTargetOptions(
 }
   }
 
-  if (Arg *A = DriverArgs.getLastArgNoClaim(options::OPT_mthreads))
-A->ignoreTargetSpecific();
+  for (auto Opt : {options::OPT_mthreads, options::OPT_mwindows,
+   options::OPT_mconsole, options::OPT_mdll}) {
+if (Arg *A = DriverArgs.getLastArgNoClaim(Opt))
+  A->ignoreTargetSpecific();
+  }
 }
 
 void toolchains::MinGW::AddClangCXXStdlibIncludeArgs(
diff --git a/clang/test/Driver/mingw-linker-options.c 
b/clang/test/Driver/mingw-linker-options.c
new file mode 100644
index 000..b4f1d05a719f3af
--- /dev/null
+++ b/clang/test/Driver/mingw-linker-options.c
@@ -0,0 +1,10 @@
+// RUN: %clang --target=x86_64-windows-gnu -c -mwindows %s -### 2>&1 | 
FileCheck %s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mconsole %s -### 2>&1 | 
FileCheck %s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mdll %s -### 2>&1 | FileCheck 
%s --check-prefix=WARNING
+// RUN: %clang --target=x86_64-windows-gnu -c -mthreads %s -### 2>&1 | 
FileCheck %s --check-prefix=WARNING
+// RUN: not %clang --target=x86_64-windows-msvc -c -mwindows %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mconsole %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mdll %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// RUN: not %clang --target=x86_64-windows-msvc -c -mthreads %s -### 2>&1 | 
FileCheck %s --check-prefix=ERROR
+// WARNING: warning: argument unused during compilation: '{{.*}}' 
[-Wunused-command-line-argument]
+// ERROR: error: unsupported option '{{.*}}' for target '{{.*}}'

``




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


[clang] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-09-30 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik updated 
https://github.com/llvm/llvm-project/pull/67373

>From beab5db738483795ecb0bace2842acdbb1c9869a Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Mon, 25 Sep 2023 13:56:43 -0700
Subject: [PATCH 1/2] [Clang] Fix crash when ill-formed code is treated as a
 deduction guide

In some cases where ill-formed code could be interpreted as a deduction guide
we can crash because we reach an unreachable path. This fixes this issue by
introducing a diagnostic instead.

Fixes: https://github.com/llvm/llvm-project/issues/65522
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp   |  4 +++-
 clang/test/SemaCXX/gh65522.cpp   | 11 +++
 3 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/gh65522.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f4eb02fd9570c2f..c3c1810fd7934a2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5414,6 +5414,8 @@ def note_constraint_normalization_here : Note<
 def note_parameter_mapping_substitution_here : Note<
   "while substituting into concept arguments here; substitution failures not "
   "allowed in concept arguments">;
+def note_building_deduction_guide_here : Note<
+  "while building implicit deduction guide first needed here">;
 def note_lambda_substitution_here : Note<
   "while substituting into a lambda expression here">;
 def note_instantiation_contexts_suppressed : Note<
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 00a36696cf90450..1ed3df5a011bcb6 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1075,7 +1075,9 @@ void Sema::PrintInstantiationStack() {
   << Active->InstantiationRange;
   break;
 case CodeSynthesisContext::BuildingDeductionGuides:
-  llvm_unreachable("unexpected deduction guide in instantiation stack");
+  Diags.Report(Active->PointOfInstantiation,
+   diag::note_building_deduction_guide_here);
+  break;
 }
   }
 }
diff --git a/clang/test/SemaCXX/gh65522.cpp b/clang/test/SemaCXX/gh65522.cpp
new file mode 100644
index 000..2d6331b0372a31d
--- /dev/null
+++ b/clang/test/SemaCXX/gh65522.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c++20 -Wc++17-compat -verify -Wno-unused %s
+
+class X {};
+
+template
+class B3 { // expected-note {{candidate template ignored: could not match 
'B3' against 'int'}}
+  template B3(T); // expected-warning 2{{non-type template parameter of 
type 'X' is incompatible with C++ standards before C++20}} \
+   // expected-note {{candidate template ignored: couldn't 
infer template argument 'x'}}
+};
+B3 b3 = 0; // expected-error {{no viable constructor or deduction guide for 
deduction of template arguments of 'B3'}} \
+   // expected-note {{while building implicit deduction guide first 
needed here}}

>From 32d948f9cd73ef7fc7e6900ac4ccdb204ffd3298 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Sat, 30 Sep 2023 15:08:04 -0700
Subject: [PATCH 2/2] Fix release note

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 58753884ec0cc2e..79c495d072b2dd3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -377,7 +377,7 @@ Bug Fixes to C++ Support
 
 - Fix crash where ill-formed code was being treated as a deduction guide and
   we now produce a diagnostic. Fixes:
-  (`65522 `_)
+  (`#65522 `_)
 
 Bug Fixes to AST Handling
 ^

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


[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-30 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav updated this revision to Diff 557513.
chaitanyav added a comment.

rebase upstream changes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147844/new/

https://reviews.llvm.org/D147844

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Analysis/uninit-vals.c
  clang/test/Sema/integer-overflow.c
  clang/test/Sema/parentheses.c
  clang/test/Sema/parentheses.cpp
  clang/test/SemaCXX/array-bounds.cpp
  clang/test/SemaCXX/integer-overflow.cpp
  libcxx/include/__chrono/duration.h
  libcxx/include/strstream
  libcxx/test/libcxx/algorithms/nth_element_stability.pass.cpp
  libcxx/test/libcxx/algorithms/partial_sort_stability.pass.cpp
  libcxx/test/libcxx/algorithms/sort_stability.pass.cpp
  libcxx/test/std/containers/unord/unord.map/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
  libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
  libcxxabi/src/cxa_personality.cpp

Index: libcxxabi/src/cxa_personality.cpp
===
--- libcxxabi/src/cxa_personality.cpp
+++ libcxxabi/src/cxa_personality.cpp
@@ -718,9 +718,7 @@
 if (actionEntry == 0)
 {
 // Found a cleanup
-results.reason = actions & _UA_SEARCH_PHASE
- ? _URC_CONTINUE_UNWIND
- : _URC_HANDLER_FOUND;
+results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
 return;
 }
 // Convert 1-based byte offset into
@@ -832,9 +830,8 @@
 // End of action list. If this is phase 2 and we have found
 // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
 // otherwise return _URC_CONTINUE_UNWIND.
-results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
- ? _URC_HANDLER_FOUND
- : _URC_CONTINUE_UNWIND;
+results.reason =
+(hasCleanup && (actions & _UA_CLEANUP_PHASE)) ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
 return;
 }
 // Go to next action
@@ -1250,10 +1247,9 @@
 {
 const __shim_type_info* excpType =
 static_cast(new_exception_header->exceptionType);
-adjustedPtr =
-__getExceptionClass(&new_exception_header->unwindHeader) == kOurDependentExceptionClass ?
-((__cxa_dependent_exception*)new_exception_header)->primaryException :
-new_exception_header + 1;
+adjustedPtr = (__getExceptionClass(&new_exception_header->unwindHeader) == kOurDependentExceptionClass)
+  ? ((__cxa_dependent_exception*)new_exception_header)->primaryException
+  : new_exception_header + 1;
 if (!exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding,
   excpType, adjustedPtr,
   unwind_exception, base))
Index: libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.set/eq.different_hash.pass.cpp
@@ -40,7 +40,7 @@
 }
 template 
 std::size_t hash_even(T val) {
-  return val & 1 ? 1 : 0;
+  return (val & 1) ? 1 : 0;
 }
 template 
 std::size_t hash_same(T /*val*/) {
@@ -61,7 +61,7 @@
 }
 template 
 size_t hash_even(T* val) {
-  return *val & 1 ? 1 : 0;
+  return (*val & 1) ? 1 : 0;
 }
 
 template 
Index: libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.multiset/eq.different_hash.pass.cpp
@@ -40,7 +40,7 @@
 }
 template 
 std::size_t hash_even(T val) {
-  return val & 1 ? 1 : 0;
+  return (val & 1) ? 1 : 0;
 }
 template 
 std::size_t hash_same(T /*val*/) {
@@ -61,7 +61,7 @@
 }
 template 
 std::size_t hash_even(T* val) {
-  return *val & 1 ? 1 : 0;
+  return (*val & 1) ? 1 : 0;
 }
 
 template 
Index: libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
===
--- libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
+++ libcxx/test/std/containers/unord/unord.multimap/eq.different_hash.pass.cpp
@@ -41,7 +41,7 @@
 }
 template 
 std::

[PATCH] D147844: [clang][Sema]Print diagnostic warning about precedence when integer expression is used without parentheses in an conditional operator expression

2023-09-30 Thread NagaChaitanya Vellanki via Phabricator via cfe-commits
chaitanyav marked an inline comment as done.
chaitanyav added a comment.

Ran llvm with the boolean and operator change. attaching the log file with 
errors .F29524460: llvm.txt 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147844/new/

https://reviews.llvm.org/D147844

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


[libunwind] [libunwind] Add Unwind-wasm.c to CMakeLists.txt (PR #67770)

2023-09-30 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin updated 
https://github.com/llvm/llvm-project/pull/67770

>From 3277e2c8058c5d9b0afcc073d711646ebbf7ed62 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Thu, 28 Sep 2023 23:43:26 -0700
Subject: [PATCH 1/5] [libunwind] Add Unwind-wasm.c to CMakeLists.txt

This was missing when the file was added.
---
 libunwind/src/CMakeLists.txt | 1 +
 libunwind/src/Unwind-wasm.c  | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 452d988c3726b5e..abb019b88ebabd7 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -16,6 +16,7 @@ set(LIBUNWIND_C_SOURCES
 UnwindLevel1.c
 UnwindLevel1-gcc-ext.c
 Unwind-sjlj.c
+Unwind-wasm.c
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 35f2f9aeab08048..47c79b0d14d37b7 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -10,12 +10,13 @@
 //
 
//===--===//
 
+#ifdef __USING_WASM_EXCEPTIONS__
+
 #include "config.h"
 #include "unwind.h"
 #include 
 #include 
 
-#ifdef __USING_WASM_EXCEPTIONS__
 
 _Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action 
actions,
 uint64_t exceptionClass,

>From 784fd43b2a58b55d838afce420c04598e3e37efa Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Fri, 29 Sep 2023 00:01:54 -0700
Subject: [PATCH 2/5] Remove newline

---
 libunwind/src/Unwind-wasm.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 47c79b0d14d37b7..96af603d666128a 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 
-
 _Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action 
actions,
 uint64_t exceptionClass,
 _Unwind_Exception 
*unwind_exception,

>From 921cad7d2db034cdc9f6c80e6dcbad614661fac8 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Fri, 29 Sep 2023 11:20:45 -0700
Subject: [PATCH 3/5] File needs to have at least one declaration

---
 libunwind/src/Unwind-wasm.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 96af603d666128a..efbc0762f6349f9 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -10,12 +10,12 @@
 //
 
//===--===//
 
-#ifdef __USING_WASM_EXCEPTIONS__
-
-#include "config.h"
-#include "unwind.h"
 #include 
 #include 
+#include "config.h"
+#include "unwind.h"
+
+#ifdef __USING_WASM_EXCEPTIONS__
 
 _Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action 
actions,
 uint64_t exceptionClass,
@@ -118,4 +118,4 @@ _Unwind_GetRegionStart(struct _Unwind_Context *context) {
   return 0;
 }
 
-#endif
+#endif // defined(__USING_WASM_EXCEPTIONS__)

>From 66b224100087cbfb46ee5acf76c34afa9553c119 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Fri, 29 Sep 2023 11:38:38 -0700
Subject: [PATCH 4/5] Make clang-format happy

---
 libunwind/src/Unwind-wasm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index efbc0762f6349f9..403a381fc1d96b7 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -12,6 +12,7 @@
 
 #include 
 #include 
+
 #include "config.h"
 #include "unwind.h"
 

>From ba3b1feb17d96e6e06039e8abd7ab643676b63e3 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Sat, 30 Sep 2023 17:48:58 -0700
Subject: [PATCH 5/5] thread.h doesn't exist in other platforms

---
 libunwind/src/Unwind-wasm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 403a381fc1d96b7..502187e395f5bb0 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -11,13 +11,14 @@
 
//===--===//
 
 #include 
-#include 
 
 #include "config.h"
 #include "unwind.h"
 
 #ifdef __USING_WASM_EXCEPTIONS__
 
+#include 
+
 _Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action 
actions,
 uint64_t exceptionClass,
 _Unwind_Exception 
*unwind_exception,

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


[libunwind] [libunwind] Add Unwind-wasm.c to CMakeLists.txt (PR #67770)

2023-09-30 Thread Heejin Ahn via cfe-commits

https://github.com/aheejin updated 
https://github.com/llvm/llvm-project/pull/67770

>From 3277e2c8058c5d9b0afcc073d711646ebbf7ed62 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Thu, 28 Sep 2023 23:43:26 -0700
Subject: [PATCH 1/6] [libunwind] Add Unwind-wasm.c to CMakeLists.txt

This was missing when the file was added.
---
 libunwind/src/CMakeLists.txt | 1 +
 libunwind/src/Unwind-wasm.c  | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libunwind/src/CMakeLists.txt b/libunwind/src/CMakeLists.txt
index 452d988c3726b5e..abb019b88ebabd7 100644
--- a/libunwind/src/CMakeLists.txt
+++ b/libunwind/src/CMakeLists.txt
@@ -16,6 +16,7 @@ set(LIBUNWIND_C_SOURCES
 UnwindLevel1.c
 UnwindLevel1-gcc-ext.c
 Unwind-sjlj.c
+Unwind-wasm.c
 )
 set_source_files_properties(${LIBUNWIND_C_SOURCES}
 PROPERTIES
diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 35f2f9aeab08048..47c79b0d14d37b7 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -10,12 +10,13 @@
 //
 
//===--===//
 
+#ifdef __USING_WASM_EXCEPTIONS__
+
 #include "config.h"
 #include "unwind.h"
 #include 
 #include 
 
-#ifdef __USING_WASM_EXCEPTIONS__
 
 _Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action 
actions,
 uint64_t exceptionClass,

>From 784fd43b2a58b55d838afce420c04598e3e37efa Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Fri, 29 Sep 2023 00:01:54 -0700
Subject: [PATCH 2/6] Remove newline

---
 libunwind/src/Unwind-wasm.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 47c79b0d14d37b7..96af603d666128a 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -17,7 +17,6 @@
 #include 
 #include 
 
-
 _Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action 
actions,
 uint64_t exceptionClass,
 _Unwind_Exception 
*unwind_exception,

>From 921cad7d2db034cdc9f6c80e6dcbad614661fac8 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Fri, 29 Sep 2023 11:20:45 -0700
Subject: [PATCH 3/6] File needs to have at least one declaration

---
 libunwind/src/Unwind-wasm.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 96af603d666128a..efbc0762f6349f9 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -10,12 +10,12 @@
 //
 
//===--===//
 
-#ifdef __USING_WASM_EXCEPTIONS__
-
-#include "config.h"
-#include "unwind.h"
 #include 
 #include 
+#include "config.h"
+#include "unwind.h"
+
+#ifdef __USING_WASM_EXCEPTIONS__
 
 _Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action 
actions,
 uint64_t exceptionClass,
@@ -118,4 +118,4 @@ _Unwind_GetRegionStart(struct _Unwind_Context *context) {
   return 0;
 }
 
-#endif
+#endif // defined(__USING_WASM_EXCEPTIONS__)

>From 66b224100087cbfb46ee5acf76c34afa9553c119 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Fri, 29 Sep 2023 11:38:38 -0700
Subject: [PATCH 4/6] Make clang-format happy

---
 libunwind/src/Unwind-wasm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index efbc0762f6349f9..403a381fc1d96b7 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -12,6 +12,7 @@
 
 #include 
 #include 
+
 #include "config.h"
 #include "unwind.h"
 

>From ba3b1feb17d96e6e06039e8abd7ab643676b63e3 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Sat, 30 Sep 2023 17:48:58 -0700
Subject: [PATCH 5/6] thread.h doesn't exist in other platforms

---
 libunwind/src/Unwind-wasm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 403a381fc1d96b7..502187e395f5bb0 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -11,13 +11,14 @@
 
//===--===//
 
 #include 
-#include 
 
 #include "config.h"
 #include "unwind.h"
 
 #ifdef __USING_WASM_EXCEPTIONS__
 
+#include 
+
 _Unwind_Reason_Code __gxx_personality_wasm0(int version, _Unwind_Action 
actions,
 uint64_t exceptionClass,
 _Unwind_Exception 
*unwind_exception,

>From 525bf727bae62d25b4431aea85122ecd44c075a4 Mon Sep 17 00:00:00 2001
From: Heejin Ahn 
Date: Sat, 30 Sep 2023 18:08:01 -0700
Subject: [PATCH 6/6] reorder

---
 libunwind/src/Unwind-wasm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index 5

[libunwind] [libunwind] Add Unwind-wasm.c to CMakeLists.txt (PR #67770)

2023-09-30 Thread Heejin Ahn via cfe-commits

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


[PATCH] D155610: [Clang][Sema] Fix display of characters on static assertion failure

2023-09-30 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet abandoned this revision.
hazohelet added a comment.

Thank you so much to everyone for guiding this patch onto the right track! I'll 
submit GitHub PR after making suggested changes.
Since Phabricator is going to be shutdown, I mark this differential as 
abandoned.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155610/new/

https://reviews.llvm.org/D155610

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


[clang] e7247f1 - [profiling] Move option declarations into headers

2023-09-30 Thread Tom Stellard via cfe-commits

Author: Tom Stellard
Date: 2023-09-30T18:51:28-07:00
New Revision: e7247f1010b546ca4d98a6ee40414d2d1cae0381

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

LOG: [profiling] Move option declarations into headers

This will make it possible to add visibility attributes to these
variables.  This also fixes some type mismatches between the
declaration and the definition.

Reviewed By: bogner, huangjd

Differential Revision: https://reviews.llvm.org/D156599

Added: 


Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/ProfileData/ProfileCommon.h
llvm/include/llvm/Transforms/IPO/SampleProfile.h
llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
llvm/lib/Analysis/ProfileSummaryInfo.cpp
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/tools/llvm-profgen/CSPreInliner.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index ccaf1e97e8e1b4a..b0fe8e03aa0f5f0 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -70,6 +70,7 @@
 #include "llvm/Transforms/Instrumentation/KCFI.h"
 #include "llvm/Transforms/Instrumentation/MemProfiler.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
+#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
 #include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
@@ -90,7 +91,6 @@ using namespace llvm;
 #include "llvm/Support/Extension.def"
 
 namespace llvm {
-extern cl::opt DebugInfoCorrelate;
 extern cl::opt PrintPipelinePasses;
 
 // Experiment to move sanitizers earlier.

diff  --git a/llvm/include/llvm/ProfileData/ProfileCommon.h 
b/llvm/include/llvm/ProfileData/ProfileCommon.h
index 4fe92cef4d72605..eaab59484c947a7 100644
--- a/llvm/include/llvm/ProfileData/ProfileCommon.h
+++ b/llvm/include/llvm/ProfileData/ProfileCommon.h
@@ -28,6 +28,14 @@
 
 namespace llvm {
 
+extern cl::opt UseContextLessSummary;
+extern cl::opt ProfileSummaryCutoffHot;
+extern cl::opt ProfileSummaryCutoffCold;
+extern cl::opt ProfileSummaryHugeWorkingSetSizeThreshold;
+extern cl::opt ProfileSummaryLargeWorkingSetSizeThreshold;
+extern cl::opt ProfileSummaryHotCount;
+extern cl::opt ProfileSummaryColdCount;
+
 namespace sampleprof {
 
 class FunctionSamples;

diff  --git a/llvm/include/llvm/Transforms/IPO/SampleProfile.h 
b/llvm/include/llvm/Transforms/IPO/SampleProfile.h
index 2ef55949e236556..e94f6ba55cd0dd4 100644
--- a/llvm/include/llvm/Transforms/IPO/SampleProfile.h
+++ b/llvm/include/llvm/Transforms/IPO/SampleProfile.h
@@ -17,12 +17,20 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
 #include 
 
 namespace llvm {
 
 class Module;
 
+extern cl::opt SampleHotCallSiteThreshold;
+extern cl::opt SampleColdCallSiteThreshold;
+extern cl::opt ProfileInlineGrowthLimit;
+extern cl::opt ProfileInlineLimitMin;
+extern cl::opt ProfileInlineLimitMax;
+extern cl::opt SortProfiledSCC;
+
 namespace vfs {
 class FileSystem;
 } // namespace vfs

diff  --git a/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h 
b/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
index c77d3214ed010d7..5b1977b7de9a2ae 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
@@ -18,11 +18,14 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/Support/CommandLine.h"
 #include 
 #include 
 
 namespace llvm {
 
+extern cl::opt DebugInfoCorrelate;
+
 class Function;
 class Instruction;
 class Module;

diff  --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp 
b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
index 203f1e42733f3dc..fdad14571dfe4f4 100644
--- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -23,16 +23,6 @@
 #include 
 using namespace llvm;
 
-// Knobs for profile summary based thresholds.
-namespace llvm {
-extern cl::opt ProfileSummaryCutoffHot;
-extern cl::opt ProfileSummaryCutoffCold;
-extern cl::opt ProfileSummaryHugeWorkingSetSizeThreshold;
-extern cl::opt ProfileSummaryLargeWorkingSetSizeThreshold;
-extern cl::opt ProfileSummaryHotCount;
-extern cl::opt ProfileSummaryColdCount;
-} // namespace llvm
-
 static cl::opt PartialProfile(
 "partial-profile", cl::Hidden, cl::init(false),
 cl::desc("Specify the current profile is used as a partial profile."));

diff  --git a/llvm/lib/Transforms/Instrumentat

[PATCH] D156599: [profiling] Move option declarations into headers

2023-09-30 Thread Tom Stellard via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7247f1010b5: [profiling] Move option declarations into 
headers (authored by tstellar).

Changed prior to commit:
  https://reviews.llvm.org/D156599?vs=545375&id=557514#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156599/new/

https://reviews.llvm.org/D156599

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/ProfileData/ProfileCommon.h
  llvm/include/llvm/Transforms/IPO/SampleProfile.h
  llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
  llvm/lib/Analysis/ProfileSummaryInfo.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
  llvm/tools/llvm-profgen/CSPreInliner.cpp

Index: llvm/tools/llvm-profgen/CSPreInliner.cpp
===
--- llvm/tools/llvm-profgen/CSPreInliner.cpp
+++ llvm/tools/llvm-profgen/CSPreInliner.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/SCCIterator.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
+#include "llvm/Transforms/IPO/SampleProfile.h"
 #include 
 #include 
 
@@ -35,13 +36,6 @@
 // TODO: the actual threshold to be tuned here because the size here is based
 // on machine code not LLVM IR.
 namespace llvm {
-extern cl::opt SampleHotCallSiteThreshold;
-extern cl::opt SampleColdCallSiteThreshold;
-extern cl::opt ProfileInlineGrowthLimit;
-extern cl::opt ProfileInlineLimitMin;
-extern cl::opt ProfileInlineLimitMax;
-extern cl::opt SortProfiledSCC;
-
 cl::opt EnableCSPreInliner(
 "csspgo-preinliner", cl::Hidden, cl::init(true),
 cl::desc("Run a global pre-inliner to merge context profile based on "
Index: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===
--- llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -327,7 +327,6 @@
 // Defined in Analysis/BlockFrequencyInfo.cpp:  -view-bfi-func-name=
 extern cl::opt ViewBlockFreqFuncName;
 
-extern cl::opt DebugInfoCorrelate;
 } // namespace llvm
 
 static cl::opt
Index: llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
===
--- llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -47,6 +47,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/TargetParser/Triple.h"
+#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include "llvm/Transforms/Utils/SSAUpdater.h"
 #include 
Index: llvm/lib/Analysis/ProfileSummaryInfo.cpp
===
--- llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -23,16 +23,6 @@
 #include 
 using namespace llvm;
 
-// Knobs for profile summary based thresholds.
-namespace llvm {
-extern cl::opt ProfileSummaryCutoffHot;
-extern cl::opt ProfileSummaryCutoffCold;
-extern cl::opt ProfileSummaryHugeWorkingSetSizeThreshold;
-extern cl::opt ProfileSummaryLargeWorkingSetSizeThreshold;
-extern cl::opt ProfileSummaryHotCount;
-extern cl::opt ProfileSummaryColdCount;
-} // namespace llvm
-
 static cl::opt PartialProfile(
 "partial-profile", cl::Hidden, cl::init(false),
 cl::desc("Specify the current profile is used as a partial profile."));
Index: llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
===
--- llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
+++ llvm/include/llvm/Transforms/Instrumentation/PGOInstrumentation.h
@@ -18,11 +18,14 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/IR/PassManager.h"
+#include "llvm/Support/CommandLine.h"
 #include 
 #include 
 
 namespace llvm {
 
+extern cl::opt DebugInfoCorrelate;
+
 class Function;
 class Instruction;
 class Module;
Index: llvm/include/llvm/Transforms/IPO/SampleProfile.h
===
--- llvm/include/llvm/Transforms/IPO/SampleProfile.h
+++ llvm/include/llvm/Transforms/IPO/SampleProfile.h
@@ -17,12 +17,20 @@
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/CommandLine.h"
 #include 
 
 namespace llvm {
 
 class Module;
 
+extern cl::opt SampleHotCallSiteThreshold;
+extern cl::opt SampleColdCallSiteThreshold;
+extern cl::opt ProfileInlineGrowthLimit;
+extern cl::opt ProfileInlineLimitMin;
+extern cl::opt ProfileInlineLimitMax;
+extern cl::opt SortProfiledSCC;
+
 namespace vfs {
 class FileSystem;
 } // namespace vfs
Index: llvm/in

[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)

2023-09-30 Thread via cfe-commits


@@ -483,6 +483,72 @@ struct FragmentCompiler {
 FullyQualifiedNamespaces.begin(), FullyQualifiedNamespaces.end());
   });
 }
+
+// TODO: Share this code with Diagnostics.Includes.IgnoreHeader
+#ifdef CLANGD_PATH_CASE_INSENSITIVE
+static llvm::Regex::RegexFlags Flags = llvm::Regex::IgnoreCase;
+#else
+static llvm::Regex::RegexFlags Flags = llvm::Regex::NoFlags;
+#endif
+{
+  auto Filters = std::make_shared>();
+  for (auto &HeaderPattern : F.AngledHeaders) {
+// Anchor on the right.
+std::string AnchoredPattern = "(" + *HeaderPattern + ")$";
+llvm::Regex CompiledRegex(AnchoredPattern, Flags);
+std::string RegexError;
+if (!CompiledRegex.isValid(RegexError)) {
+  diag(Warning,
+   llvm::formatv("Invalid regular expression '{0}': {1}",
+ *HeaderPattern, RegexError)
+   .str(),
+   HeaderPattern.Range);
+  continue;
+}
+Filters->push_back(std::move(CompiledRegex));
+  }
+  if (Filters->empty())
+return;

zyn0217 wrote:

I think this is why you're seeing the puzzling behavior: You've bailed out of 
parsing the `QuotedHeaders` block if don't see any `AngledHeaders` field. 
Perhaps extract these two blocks into separate functions?

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


[clang] remove duplicate ModuleId alias (PR #67899)

2023-09-30 Thread David Stone via cfe-commits

https://github.com/davidstone created 
https://github.com/llvm/llvm-project/pull/67899

- [ADT] Guard PagedVector death tests
- [InstSimplify] Avoid use of ConstantExpr::getICmp. NFC (#67873)
- [RISCV][MC] Recognise that fcvt.d.s with frm != 0b000 is valid (#67555)
- [lipo] Support creating Universal 64 bit Mach-O files. (#67737)
- Fix -Wcovered-switch-default in MachOUniversalWriter.cpp (NFC)
- [lldb][windows] Cover more symbols in LLDB_EXPORT_ALL_SYMBOLS
- [clang] Remove duplicate `ModuleId` alias


>From 60646e9e3bf60cef57c97f7ded56520c8088bf58 Mon Sep 17 00:00:00 2001
From: David Stone 
Date: Sat, 30 Sep 2023 17:43:55 -0600
Subject: [PATCH] [clang] Remove duplicate `ModuleId` alias

---
 clang/lib/Lex/ModuleMap.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index e8437572ebf4bf6..f65a5f145c04395 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1551,8 +1551,6 @@ namespace clang {
 /// (or the end of the file).
 void skipUntil(MMToken::TokenKind K);
 
-using ModuleId = SmallVector, 2>;
-
 bool parseModuleId(ModuleId &Id);
 void parseModuleDecl();
 void parseExternModuleDecl();

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


[clang] remove duplicate ModuleId alias (PR #67899)

2023-09-30 Thread David Stone via cfe-commits

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


[clang] remove duplicate ModuleId alias (PR #67899)

2023-09-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules


Changes

[clang] Remove duplicate `ModuleId` alias


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


1 Files Affected:

- (modified) clang/lib/Lex/ModuleMap.cpp (-2) 


``diff
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index e8437572ebf4bf6..f65a5f145c04395 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1551,8 +1551,6 @@ namespace clang {
 /// (or the end of the file).
 void skipUntil(MMToken::TokenKind K);
 
-using ModuleId = SmallVector, 2>;
-
 bool parseModuleId(ModuleId &Id);
 void parseModuleDecl();
 void parseExternModuleDecl();

``




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


[clang] remove duplicate ModuleId alias (PR #67899)

2023-09-30 Thread David Stone via cfe-commits

https://github.com/davidstone updated 
https://github.com/llvm/llvm-project/pull/67899

>From 9bce0ece5bf8adaa094475305c44bcd06cd79e7f Mon Sep 17 00:00:00 2001
From: David Stone 
Date: Sat, 30 Sep 2023 22:30:29 -0600
Subject: [PATCH] [clang] Remove duplicate `ModuleId` alias

This alias is already defined in `clang/Basic/Module.h` to the same value.
---
 clang/lib/Lex/ModuleMap.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index e8437572ebf4bf6..f65a5f145c04395 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -1551,8 +1551,6 @@ namespace clang {
 /// (or the end of the file).
 void skipUntil(MMToken::TokenKind K);
 
-using ModuleId = SmallVector, 2>;
-
 bool parseModuleId(ModuleId &Id);
 void parseModuleDecl();
 void parseExternModuleDecl();

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


[clang] remove duplicate ModuleId alias (PR #67899)

2023-09-30 Thread David Stone via cfe-commits

davidstone wrote:

The description got a little messed up somehow, but should be fixed.

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


[clang] [clang][Modules] Make `Module::Requirement` a struct (PR #67900)

2023-09-30 Thread David Stone via cfe-commits

https://github.com/davidstone created 
https://github.com/llvm/llvm-project/pull/67900

`Module::Requirement` was defined as a `std::pair`. This 
required a comment to explain what the data members mean and makes the usage 
harder to understand. Replace this with a struct with two members, 
`FeatureName` and `RequiredState`.

>From 0253be550776631980d77e7847c6337786d64911 Mon Sep 17 00:00:00 2001
From: David Stone 
Date: Sat, 30 Sep 2023 22:57:34 -0600
Subject: [PATCH] [clang][Modules] Make `Module::Requirement` a struct

`Module::Requirement` was defined as a `std::pair`. This 
required a comment to explain what the data members mean and makes the usage 
harder to understand. Replace this with a struct with two members, 
`FeatureName` and `RequiredState`.
---
 clang/include/clang/Basic/Module.h|  7 ---
 clang/lib/Basic/Module.cpp| 10 +-
 clang/lib/Lex/PPDirectives.cpp|  2 +-
 clang/lib/Serialization/ASTWriter.cpp |  4 ++--
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 676fd372493a3aa..0a134b53d3d9801 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -281,9 +281,10 @@ class alignas(8) Module {
   /// found on the file system.
   SmallVector MissingHeaders;
 
-  /// An individual requirement: a feature name and a flag indicating
-  /// the required state of that feature.
-  using Requirement = std::pair;
+  struct Requirement {
+std::string FeatureName;
+bool RequiredState;
+  };
 
   /// The set of language features required to use this module.
   ///
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 0455304ef7f2b1a..fff0067bc9f818f 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -140,8 +140,8 @@ bool Module::isUnimportable(const LangOptions &LangOpts,
   return true;
 }
 for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) {
-  if (hasFeature(Current->Requirements[I].first, LangOpts, Target) !=
-  Current->Requirements[I].second) {
+  if (hasFeature(Current->Requirements[I].FeatureName, LangOpts, Target) !=
+  Current->Requirements[I].RequiredState) {
 Req = Current->Requirements[I];
 return true;
   }
@@ -312,7 +312,7 @@ bool Module::directlyUses(const Module *Requested) {
 void Module::addRequirement(StringRef Feature, bool RequiredState,
 const LangOptions &LangOpts,
 const TargetInfo &Target) {
-  Requirements.push_back(Requirement(std::string(Feature), RequiredState));
+  Requirements.push_back(Requirement{std::string(Feature), RequiredState});
 
   // If this feature is currently available, we're done.
   if (hasFeature(Feature, LangOpts, Target) == RequiredState)
@@ -497,9 +497,9 @@ void Module::print(raw_ostream &OS, unsigned Indent, bool 
Dump) const {
 for (unsigned I = 0, N = Requirements.size(); I != N; ++I) {
   if (I)
 OS << ", ";
-  if (!Requirements[I].second)
+  if (!Requirements[I].RequiredState)
 OS << "!";
-  OS << Requirements[I].first;
+  OS << Requirements[I].FeatureName;
 }
 OS << "\n";
   }
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 7899bfa1c4f5842..579836d47201355 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1915,7 +1915,7 @@ bool Preprocessor::checkModuleIsAvailable(const 
LangOptions &LangOpts,
 // FIXME: Track the location at which the requirement was specified, and
 // use it here.
 Diags.Report(M->DefinitionLoc, diag::err_module_unavailable)
-<< M->getFullModuleName() << Requirement.second << Requirement.first;
+<< M->getFullModuleName() << Requirement.RequiredState << 
Requirement.FeatureName;
   }
   return true;
 }
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 201e2fcaaec91aa..f03b47ec3214d1b 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2896,8 +2896,8 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
 
 // Emit the requirements.
 for (const auto &R : Mod->Requirements) {
-  RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second};
-  Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first);
+  RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.RequiredState};
+  Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.FeatureName);
 }
 
 // Emit the umbrella header, if there is one.

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


[clang] [clang][Modules] Make `Module::Requirement` a struct (PR #67900)

2023-09-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

`Module::Requirement` was defined as a `std::pair`. 
This required a comment to explain what the data members mean and makes the 
usage harder to understand. Replace this with a struct with two members, 
`FeatureName` and `RequiredState`.

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


4 Files Affected:

- (modified) clang/include/clang/Basic/Module.h (+4-3) 
- (modified) clang/lib/Basic/Module.cpp (+5-5) 
- (modified) clang/lib/Lex/PPDirectives.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+2-2) 


``diff
diff --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 676fd372493a3aa..0a134b53d3d9801 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -281,9 +281,10 @@ class alignas(8) Module {
   /// found on the file system.
   SmallVector MissingHeaders;
 
-  /// An individual requirement: a feature name and a flag indicating
-  /// the required state of that feature.
-  using Requirement = std::pair;
+  struct Requirement {
+std::string FeatureName;
+bool RequiredState;
+  };
 
   /// The set of language features required to use this module.
   ///
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 0455304ef7f2b1a..fff0067bc9f818f 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -140,8 +140,8 @@ bool Module::isUnimportable(const LangOptions &LangOpts,
   return true;
 }
 for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) {
-  if (hasFeature(Current->Requirements[I].first, LangOpts, Target) !=
-  Current->Requirements[I].second) {
+  if (hasFeature(Current->Requirements[I].FeatureName, LangOpts, Target) !=
+  Current->Requirements[I].RequiredState) {
 Req = Current->Requirements[I];
 return true;
   }
@@ -312,7 +312,7 @@ bool Module::directlyUses(const Module *Requested) {
 void Module::addRequirement(StringRef Feature, bool RequiredState,
 const LangOptions &LangOpts,
 const TargetInfo &Target) {
-  Requirements.push_back(Requirement(std::string(Feature), RequiredState));
+  Requirements.push_back(Requirement{std::string(Feature), RequiredState});
 
   // If this feature is currently available, we're done.
   if (hasFeature(Feature, LangOpts, Target) == RequiredState)
@@ -497,9 +497,9 @@ void Module::print(raw_ostream &OS, unsigned Indent, bool 
Dump) const {
 for (unsigned I = 0, N = Requirements.size(); I != N; ++I) {
   if (I)
 OS << ", ";
-  if (!Requirements[I].second)
+  if (!Requirements[I].RequiredState)
 OS << "!";
-  OS << Requirements[I].first;
+  OS << Requirements[I].FeatureName;
 }
 OS << "\n";
   }
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 7899bfa1c4f5842..579836d47201355 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1915,7 +1915,7 @@ bool Preprocessor::checkModuleIsAvailable(const 
LangOptions &LangOpts,
 // FIXME: Track the location at which the requirement was specified, and
 // use it here.
 Diags.Report(M->DefinitionLoc, diag::err_module_unavailable)
-<< M->getFullModuleName() << Requirement.second << Requirement.first;
+<< M->getFullModuleName() << Requirement.RequiredState << 
Requirement.FeatureName;
   }
   return true;
 }
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 201e2fcaaec91aa..f03b47ec3214d1b 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2896,8 +2896,8 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
 
 // Emit the requirements.
 for (const auto &R : Mod->Requirements) {
-  RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second};
-  Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first);
+  RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.RequiredState};
+  Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.FeatureName);
 }
 
 // Emit the umbrella header, if there is one.

``




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


[clang] [clang][Modules] Make `Module::Requirement` a struct (PR #67900)

2023-09-30 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 e7247f1010b546ca4d98a6ee40414d2d1cae0381 
0253be550776631980d77e7847c6337786d64911 -- clang/include/clang/Basic/Module.h 
clang/lib/Basic/Module.cpp clang/lib/Lex/PPDirectives.cpp 
clang/lib/Serialization/ASTWriter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index fff0067bc..97511ce9a 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -141,7 +141,7 @@ bool Module::isUnimportable(const LangOptions &LangOpts,
 }
 for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) {
   if (hasFeature(Current->Requirements[I].FeatureName, LangOpts, Target) !=
-  Current->Requirements[I].RequiredState) {
+  Current->Requirements[I].RequiredState) {
 Req = Current->Requirements[I];
 return true;
   }
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 579836d47..c55ce4ce6 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1915,7 +1915,8 @@ bool Preprocessor::checkModuleIsAvailable(const 
LangOptions &LangOpts,
 // FIXME: Track the location at which the requirement was specified, and
 // use it here.
 Diags.Report(M->DefinitionLoc, diag::err_module_unavailable)
-<< M->getFullModuleName() << Requirement.RequiredState << 
Requirement.FeatureName;
+<< M->getFullModuleName() << Requirement.RequiredState
+<< Requirement.FeatureName;
   }
   return true;
 }

``




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


[clang] [clang][Modules] Make `Module::Requirement` a struct (PR #67900)

2023-09-30 Thread David Stone via cfe-commits

https://github.com/davidstone updated 
https://github.com/llvm/llvm-project/pull/67900

>From 0253be550776631980d77e7847c6337786d64911 Mon Sep 17 00:00:00 2001
From: David Stone 
Date: Sat, 30 Sep 2023 22:57:34 -0600
Subject: [PATCH 1/2] [clang][Modules] Make `Module::Requirement` a struct

`Module::Requirement` was defined as a `std::pair`. This 
required a comment to explain what the data members mean and makes the usage 
harder to understand. Replace this with a struct with two members, 
`FeatureName` and `RequiredState`.
---
 clang/include/clang/Basic/Module.h|  7 ---
 clang/lib/Basic/Module.cpp| 10 +-
 clang/lib/Lex/PPDirectives.cpp|  2 +-
 clang/lib/Serialization/ASTWriter.cpp |  4 ++--
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 676fd372493a3aa..0a134b53d3d9801 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -281,9 +281,10 @@ class alignas(8) Module {
   /// found on the file system.
   SmallVector MissingHeaders;
 
-  /// An individual requirement: a feature name and a flag indicating
-  /// the required state of that feature.
-  using Requirement = std::pair;
+  struct Requirement {
+std::string FeatureName;
+bool RequiredState;
+  };
 
   /// The set of language features required to use this module.
   ///
diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp
index 0455304ef7f2b1a..fff0067bc9f818f 100644
--- a/clang/lib/Basic/Module.cpp
+++ b/clang/lib/Basic/Module.cpp
@@ -140,8 +140,8 @@ bool Module::isUnimportable(const LangOptions &LangOpts,
   return true;
 }
 for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) {
-  if (hasFeature(Current->Requirements[I].first, LangOpts, Target) !=
-  Current->Requirements[I].second) {
+  if (hasFeature(Current->Requirements[I].FeatureName, LangOpts, Target) !=
+  Current->Requirements[I].RequiredState) {
 Req = Current->Requirements[I];
 return true;
   }
@@ -312,7 +312,7 @@ bool Module::directlyUses(const Module *Requested) {
 void Module::addRequirement(StringRef Feature, bool RequiredState,
 const LangOptions &LangOpts,
 const TargetInfo &Target) {
-  Requirements.push_back(Requirement(std::string(Feature), RequiredState));
+  Requirements.push_back(Requirement{std::string(Feature), RequiredState});
 
   // If this feature is currently available, we're done.
   if (hasFeature(Feature, LangOpts, Target) == RequiredState)
@@ -497,9 +497,9 @@ void Module::print(raw_ostream &OS, unsigned Indent, bool 
Dump) const {
 for (unsigned I = 0, N = Requirements.size(); I != N; ++I) {
   if (I)
 OS << ", ";
-  if (!Requirements[I].second)
+  if (!Requirements[I].RequiredState)
 OS << "!";
-  OS << Requirements[I].first;
+  OS << Requirements[I].FeatureName;
 }
 OS << "\n";
   }
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 7899bfa1c4f5842..579836d47201355 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1915,7 +1915,7 @@ bool Preprocessor::checkModuleIsAvailable(const 
LangOptions &LangOpts,
 // FIXME: Track the location at which the requirement was specified, and
 // use it here.
 Diags.Report(M->DefinitionLoc, diag::err_module_unavailable)
-<< M->getFullModuleName() << Requirement.second << Requirement.first;
+<< M->getFullModuleName() << Requirement.RequiredState << 
Requirement.FeatureName;
   }
   return true;
 }
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 201e2fcaaec91aa..f03b47ec3214d1b 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -2896,8 +2896,8 @@ void ASTWriter::WriteSubmodules(Module *WritingModule) {
 
 // Emit the requirements.
 for (const auto &R : Mod->Requirements) {
-  RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.second};
-  Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.first);
+  RecordData::value_type Record[] = {SUBMODULE_REQUIRES, R.RequiredState};
+  Stream.EmitRecordWithBlob(RequiresAbbrev, Record, R.FeatureName);
 }
 
 // Emit the umbrella header, if there is one.

>From 46e59890368f66ae4ba6b1d242d08c1a7ec7676a Mon Sep 17 00:00:00 2001
From: David Stone 
Date: Sat, 30 Sep 2023 23:08:58 -0600
Subject: [PATCH 2/2] amend! [clang][Modules] Make `Module::Requirement` a
 struct

[clang][Modules] Make `Module::Requirement` a struct

`Module::Requirement` was defined as a `std::pair`. This 
required a comment to explain what the data members mean and makes the usage 
harder to understand. Replace this with a struct with two members, 
`FeatureName` and `RequiredState`.
---
 clang/lib/Basic/Module.cpp | 2 +-
 clang

[clang] 18461dc - [clang][Interp] Add IntegralAP for arbitrary-precision integers (#65844)

2023-09-30 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-01T07:11:07+02:00
New Revision: 18461dc45483f6f589de143a287ca80a832ab260

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

LOG: [clang][Interp] Add IntegralAP for arbitrary-precision integers (#65844)

Added: 
clang/lib/AST/Interp/IntegralAP.h

Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Context.cpp
clang/lib/AST/Interp/Descriptor.cpp
clang/lib/AST/Interp/EvalEmitter.cpp
clang/lib/AST/Interp/Integral.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpStack.h
clang/lib/AST/Interp/Opcodes.td
clang/lib/AST/Interp/PrimType.cpp
clang/lib/AST/Interp/PrimType.h
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 46906377863bd74..e266804a4e75dea 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -171,14 +171,17 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   return this->discard(SubExpr);
 std::optional FromT = classify(SubExpr->getType());
 std::optional ToT = classify(CE->getType());
+
 if (!FromT || !ToT)
   return false;
 
 if (!this->visit(SubExpr))
   return false;
 
-if (FromT == ToT)
+if (FromT == ToT) {
+  assert(ToT != PT_IntAP && ToT != PT_IntAPS);
   return true;
+}
 
 return this->emitCast(*FromT, *ToT, CE);
   }
@@ -1638,6 +1641,10 @@ bool 
ByteCodeExprGen::visitZeroInitializer(QualType QT,
 return this->emitZeroSint64(E);
   case PT_Uint64:
 return this->emitZeroUint64(E);
+  case PT_IntAP:
+  case PT_IntAPS:
+assert(false);
+return false;
   case PT_Ptr:
 return this->emitNullPtr(E);
   case PT_FnPtr:
@@ -1877,6 +1884,10 @@ bool ByteCodeExprGen::emitConst(T Value, 
PrimType Ty, const Expr *E) {
 return this->emitConstSint64(Value, E);
   case PT_Uint64:
 return this->emitConstUint64(Value, E);
+  case PT_IntAP:
+  case PT_IntAPS:
+assert(false);
+return false;
   case PT_Bool:
 return this->emitConstBool(Value, E);
   case PT_Ptr:

diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index e84c0f6aae7ee93..04710cd0f2c28ee 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -103,7 +103,7 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Sint8;
 default:
-  return std::nullopt;
+  return PT_IntAPS;
 }
   }
 
@@ -118,7 +118,7 @@ std::optional Context::classify(QualType T) const 
{
 case 8:
   return PT_Uint8;
 default:
-  return std::nullopt;
+  return PT_IntAP;
 }
   }
 

diff  --git a/clang/lib/AST/Interp/Descriptor.cpp 
b/clang/lib/AST/Interp/Descriptor.cpp
index db49a569eff33ea..4ecb7466998e705 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -10,6 +10,7 @@
 #include "Boolean.h"
 #include "Floating.h"
 #include "FunctionPointer.h"
+#include "IntegralAP.h"
 #include "Pointer.h"
 #include "PrimType.h"
 #include "Record.h"
@@ -182,6 +183,10 @@ static BlockCtorFn getCtorPrim(PrimType Type) {
   // constructor called.
   if (Type == PT_Float)
 return ctorTy::T>;
+  if (Type == PT_IntAP)
+return ctorTy::T>;
+  if (Type == PT_IntAPS)
+return ctorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return ctorTy, return nullptr);
 }
@@ -191,6 +196,10 @@ static BlockDtorFn getDtorPrim(PrimType Type) {
   // destructor called, since they might allocate memory.
   if (Type == PT_Float)
 return dtorTy::T>;
+  if (Type == PT_IntAP)
+return dtorTy::T>;
+  if (Type == PT_IntAPS)
+return dtorTy::T>;
 
   COMPOSITE_TYPE_SWITCH(Type, return dtorTy, return nullptr);
 }

diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp 
b/clang/lib/AST/Interp/EvalEmitter.cpp
index bdf800c60f1723f..f46ef1067cf52a0 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -9,6 +9,7 @@
 #include "EvalEmitter.h"
 #include "ByteCodeGenError.h"
 #include "Context.h"
+#include "IntegralAP.h"
 #include "Interp.h"
 #include "Opcode.h"
 #include "clang/AST/DeclCXX.h"

diff  --git a/clang/lib/AST/Interp/Integral.h b/clang/lib/AST/Interp/Integral.h
index 0295a9c3b5c898c..4dbe9c9bcb14b43 100644
--- a/clang/lib/AST/Interp/Integral.h
+++ b/clang/lib/AST/Interp/Integral.h
@@ -29,6 +29,8 @@ namespace interp {
 using APInt = llvm::APInt;
 using APSInt = llvm::APSInt;
 
+template  class IntegralAP;
+
 // Helper structure to select the representation.
 template  struct Repr;
 template <> struct Repr<8, false> { using Type = uint8_t; };
@@ -61,6 +63,8 @@ template  class Integral final {
   template  explicit Integral(T V) :

[PATCH] D158069: [clang][Interp] Fix getIndex() for composite array elements

2023-09-30 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Pointer.h:81-88
+  /// Equality operators are just for tests.
+  bool operator==(const Pointer &P) const {
+return Pointee == P.Pointee && Base == P.Base && Offset == P.Offset;
+  }
+
+  bool operator!=(const Pointer &P) const {
+return Pointee != P.Pointee || Base != P.Base || Offset != P.Offset;

aaron.ballman wrote:
> Same here -- can these be private and friended?
Don't you need a class to friend something? I only have the `TEST(...)` 
function in the unit test, so I can't do that, right?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158069/new/

https://reviews.llvm.org/D158069

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


[clang] -fsanitize=alignment: check memcpy/memmove arguments (PR #67766)

2023-09-30 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Thanks for the comment.

> I think the choice we're making here is probably worth it, though we should 
> probably document it better. I think you can remove the alignment assumption 
> by explicitly casting the operands to char* before passing them to memcpy; if 
> you can't, I'd be more worried that we're doing something problematic here. 

Yes. The correct implementation correctly drops the alignment check on the dst 
parameter for `memcpy((char *)a, b, sz);`

> Also, it'd seem like a good idea to make the sanitizer message as clear as 
> possible for this case, because Clang's behavior here is surprising.

@zygoloid 
Is reusing the message for regular stores clear (current behavior) enough?
```
// CHECK-MEMCPY-STORE: misaligned.cpp:[[#@LINE+4]]{{(:12)?}}: runtime error: 
store to misaligned address [[PTR:0x[0-9a-f]*]] for type 'int *', which 
requires 4 byte alignment
```


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


[clang] [clang][Modules] `checkModuleIsAvailable` should use a const & parameter instead of pointer (PR #67902)

2023-09-30 Thread David Stone via cfe-commits

https://github.com/davidstone created 
https://github.com/llvm/llvm-project/pull/67902

The `Module` parameter to `checkModuleIsAvailable` is currently passed by 
pointer to non-const. However, it requires only const access and it cannot be 
null. Change this to be a reference to const instead.

This then makes it obvious that it is an input-only parameter, so move it to be 
before the in-out parameter for diagnostics.

>From 3b7cf88ddf78a1f7fbb15e51a288d7265e262b0d Mon Sep 17 00:00:00 2001
From: David Stone 
Date: Sun, 1 Oct 2023 00:41:34 -0600
Subject: [PATCH] [clang][Modules] `checkModuleIsAvailable` should use a const
 & parameter instead of pointer

The `Module` parameter to `checkModuleIsAvailable` is currently passed by 
pointer to non-const. However, it requires only const access and it cannot be 
null. Change this to be a reference to const instead.

This then makes it obvious that it is an input-only parameter, so move it to be 
before the in-out parameter for diagnostics.
---
 clang/include/clang/Lex/Preprocessor.h  |  2 +-
 clang/lib/Frontend/CompilerInstance.cpp |  2 +-
 clang/lib/Frontend/FrontendAction.cpp   |  4 ++--
 clang/lib/Lex/PPDirectives.cpp  | 18 ++
 clang/lib/Lex/Pragma.cpp|  2 +-
 5 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index e88164f196c1f7c..b9423640d62f741 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2697,7 +2697,7 @@ class Preprocessor {
   /// \c false if the module appears to be usable.
   static bool checkModuleIsAvailable(const LangOptions &LangOpts,
  const TargetInfo &TargetInfo,
- DiagnosticsEngine &Diags, Module *M);
+ const Module &M, DiagnosticsEngine 
&Diags);
 
   // Module inclusion testing.
   /// Find the module that owns the source or header file that
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index d18371f21a9d86e..d749195585eca5b 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -2116,7 +2116,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
 
 // Check whether this module is available.
 if (Preprocessor::checkModuleIsAvailable(getLangOpts(), getTarget(),
- getDiagnostics(), Module)) {
+ *Module, getDiagnostics())) {
   getDiagnostics().Report(ImportLoc, diag::note_module_import_here)
 << SourceRange(Path.front().second, Path.back().second);
   LastModuleImportLoc = ImportLoc;
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 60eac0c6d353048..eb8a96627bb7076 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -510,8 +510,8 @@ static Module *prepareToBuildModule(CompilerInstance &CI,
   }
 
   // Check whether we can build this module at all.
-  if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(),
-   CI.getDiagnostics(), M))
+  if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(), 
*M,
+   CI.getDiagnostics()))
 return nullptr;
 
   // Inform the preprocessor that includes from within the input buffer should
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 7899bfa1c4f5842..e3065c17dc70b43 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1896,26 +1896,27 @@ static bool trySimplifyPath(SmallVectorImpl 
&Components,
 
 bool Preprocessor::checkModuleIsAvailable(const LangOptions &LangOpts,
   const TargetInfo &TargetInfo,
-  DiagnosticsEngine &Diags, Module *M) 
{
+  const Module &M,
+  DiagnosticsEngine &Diags) {
   Module::Requirement Requirement;
   Module::UnresolvedHeaderDirective MissingHeader;
   Module *ShadowingModule = nullptr;
-  if (M->isAvailable(LangOpts, TargetInfo, Requirement, MissingHeader,
- ShadowingModule))
+  if (M.isAvailable(LangOpts, TargetInfo, Requirement, MissingHeader,
+ShadowingModule))
 return false;
 
   if (MissingHeader.FileNameLoc.isValid()) {
 Diags.Report(MissingHeader.FileNameLoc, diag::err_module_header_missing)
 << MissingHeader.IsUmbrella << MissingHeader.FileName;
   } else if (ShadowingModule) {
-Diags.Report(M->DefinitionLoc, diag::err_module_shadowed) << M->Name;
+Diags.Report(M.DefinitionLoc, diag::err_module_shadowed) << M.Name;
 Diags.Report(ShadowingModule->DefinitionLoc,

[clang] [clang][Modules] `checkModuleIsAvailable` should use a const & parameter instead of pointer (PR #67902)

2023-09-30 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

The `Module` parameter to `checkModuleIsAvailable` is currently passed by 
pointer to non-const. However, it requires only const access and it cannot be 
null. Change this to be a reference to const instead.

This then makes it obvious that it is an input-only parameter, so move it to be 
before the in-out parameter for diagnostics.

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


5 Files Affected:

- (modified) clang/include/clang/Lex/Preprocessor.h (+1-1) 
- (modified) clang/lib/Frontend/CompilerInstance.cpp (+1-1) 
- (modified) clang/lib/Frontend/FrontendAction.cpp (+2-2) 
- (modified) clang/lib/Lex/PPDirectives.cpp (+10-8) 
- (modified) clang/lib/Lex/Pragma.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index e88164f196c1f7c..b9423640d62f741 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2697,7 +2697,7 @@ class Preprocessor {
   /// \c false if the module appears to be usable.
   static bool checkModuleIsAvailable(const LangOptions &LangOpts,
  const TargetInfo &TargetInfo,
- DiagnosticsEngine &Diags, Module *M);
+ const Module &M, DiagnosticsEngine 
&Diags);
 
   // Module inclusion testing.
   /// Find the module that owns the source or header file that
diff --git a/clang/lib/Frontend/CompilerInstance.cpp 
b/clang/lib/Frontend/CompilerInstance.cpp
index d18371f21a9d86e..d749195585eca5b 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -2116,7 +2116,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
 
 // Check whether this module is available.
 if (Preprocessor::checkModuleIsAvailable(getLangOpts(), getTarget(),
- getDiagnostics(), Module)) {
+ *Module, getDiagnostics())) {
   getDiagnostics().Report(ImportLoc, diag::note_module_import_here)
 << SourceRange(Path.front().second, Path.back().second);
   LastModuleImportLoc = ImportLoc;
diff --git a/clang/lib/Frontend/FrontendAction.cpp 
b/clang/lib/Frontend/FrontendAction.cpp
index 60eac0c6d353048..eb8a96627bb7076 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -510,8 +510,8 @@ static Module *prepareToBuildModule(CompilerInstance &CI,
   }
 
   // Check whether we can build this module at all.
-  if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(),
-   CI.getDiagnostics(), M))
+  if (Preprocessor::checkModuleIsAvailable(CI.getLangOpts(), CI.getTarget(), 
*M,
+   CI.getDiagnostics()))
 return nullptr;
 
   // Inform the preprocessor that includes from within the input buffer should
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 7899bfa1c4f5842..e3065c17dc70b43 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -1896,26 +1896,27 @@ static bool trySimplifyPath(SmallVectorImpl 
&Components,
 
 bool Preprocessor::checkModuleIsAvailable(const LangOptions &LangOpts,
   const TargetInfo &TargetInfo,
-  DiagnosticsEngine &Diags, Module *M) 
{
+  const Module &M,
+  DiagnosticsEngine &Diags) {
   Module::Requirement Requirement;
   Module::UnresolvedHeaderDirective MissingHeader;
   Module *ShadowingModule = nullptr;
-  if (M->isAvailable(LangOpts, TargetInfo, Requirement, MissingHeader,
- ShadowingModule))
+  if (M.isAvailable(LangOpts, TargetInfo, Requirement, MissingHeader,
+ShadowingModule))
 return false;
 
   if (MissingHeader.FileNameLoc.isValid()) {
 Diags.Report(MissingHeader.FileNameLoc, diag::err_module_header_missing)
 << MissingHeader.IsUmbrella << MissingHeader.FileName;
   } else if (ShadowingModule) {
-Diags.Report(M->DefinitionLoc, diag::err_module_shadowed) << M->Name;
+Diags.Report(M.DefinitionLoc, diag::err_module_shadowed) << M.Name;
 Diags.Report(ShadowingModule->DefinitionLoc,
  diag::note_previous_definition);
   } else {
 // FIXME: Track the location at which the requirement was specified, and
 // use it here.
-Diags.Report(M->DefinitionLoc, diag::err_module_unavailable)
-<< M->getFullModuleName() << Requirement.second << Requirement.first;
+Diags.Report(M.DefinitionLoc, diag::err_module_unavailable)
+<< M.getFullModuleName() << Requirement.second << Requirement.first;
   }
   return true;
 }
@@ -2260,8 +2261,9 @@ Preprocessor::ImportAction 
Preprocessor::H