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

2023-10-01 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@hazohelet Please keep this patch on Phab. It's not going to be shutdown. The 
current consensus is that we will reconsider shutting down phab on November 15
https://discourse.llvm.org/t/update-on-github-pull-requests/71540/125


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-tools-extra] [Support] Add KnownBits::computeForSubBorrow (PR #67788)

2023-10-01 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] [clang-format] Fix a bug in RemoveParentheses: ReturnStatement (PR #67911)

2023-10-01 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/67911

Don't remove the outermost parentheses surrounding a return statement 
expression when inside a function/lambda that has the decltype(auto) return 
type.

Fixed #67892.

>From 561af2122a9155b44e340d89549b13b0ea9b2ce6 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 1 Oct 2023 03:11:23 -0700
Subject: [PATCH] [clang-format] Fix a bug in RemoveParentheses:
 ReturnStatement

Don't remove the outermost parentheses surrounding a return statement
expression when inside a function/lambda that has the decltype(auto)
return type.

Fixed #67892.
---
 clang/lib/Format/UnwrappedLineParser.cpp | 24 
 clang/lib/Format/UnwrappedLineParser.h   | 11 ++
 clang/unittests/Format/FormatTest.cpp| 50 
 3 files changed, 85 insertions(+)

diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index bf38ed73c4a0b4e..dda5fd077e590e5 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -173,10 +173,12 @@ void UnwrappedLineParser::reset() {
   CommentsBeforeNextToken.clear();
   FormatTok = nullptr;
   MustBreakBeforeNextToken = false;
+  IsDecltypeAutoFunction = false;
   PreprocessorDirectives.clear();
   CurrentLines = &Lines;
   DeclarationScopeStack.clear();
   NestedTooDeep.clear();
+  NestedLambdas.clear();
   PPStack.clear();
   Line->FirstStartColumn = FirstStartColumn;
 
@@ -1766,6 +1768,17 @@ void UnwrappedLineParser::parseStructuralElement(
   if (parseStructLike())
 return;
   break;
+case tok::kw_decltype:
+  nextToken();
+  if (FormatTok->is(tok::l_paren)) {
+parseParens();
+assert(FormatTok->Previous);
+if (FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
+  tok::l_paren)) {
+  Line->SeenDecltypeAuto = true;
+}
+  }
+  break;
 case tok::period:
   nextToken();
   // In Java, classes have an implicit static member "class".
@@ -1827,6 +1840,7 @@ void UnwrappedLineParser::parseStructuralElement(
   if (InRequiresExpression)
 FormatTok->setFinalizedType(TT_BracedListLBrace);
   if (!tryToParsePropertyAccessor() && !tryToParseBracedList()) {
+IsDecltypeAutoFunction = Line->SeenDecltypeAuto;
 // A block outside of parentheses must be the last part of a
 // structural element.
 // FIXME: Figure out cases where this is not true, and add projections
@@ -1844,6 +1858,7 @@ void UnwrappedLineParser::parseStructuralElement(
 }
 FormatTok->setFinalizedType(TT_FunctionLBrace);
 parseBlock();
+IsDecltypeAutoFunction = false;
 addUnwrappedLine();
 return;
   }
@@ -2249,9 +2264,15 @@ bool UnwrappedLineParser::tryToParseLambda() {
   return true;
 }
   }
+
   FormatTok->setFinalizedType(TT_LambdaLBrace);
   LSquare.setFinalizedType(TT_LambdaLSquare);
+
+  NestedLambdas.push_back(Line->SeenDecltypeAuto);
   parseChildBlock();
+  assert(!NestedLambdas.empty());
+  NestedLambdas.pop_back();
+
   return true;
 }
 
@@ -2469,6 +2490,8 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
PrevPrev->endsSequence(tok::kw_constexpr, tok::kw_if;
 const bool ReturnParens =
 Style.RemoveParentheses == FormatStyle::RPS_ReturnStatement &&
+((NestedLambdas.empty() && !IsDecltypeAutoFunction) ||
+ (!NestedLambdas.empty() && !NestedLambdas.back())) &&
 Prev && Prev->isOneOf(tok::kw_return, tok::kw_co_return) && Next &&
 Next->is(tok::semi);
 if ((DoubleParens && !Blacklisted) || ReturnParens) {
@@ -4379,6 +4402,7 @@ void UnwrappedLineParser::addUnwrappedLine(LineLevel 
AdjustLevel) {
   Line->MatchingOpeningBlockLineIndex = UnwrappedLine::kInvalidIndex;
   Line->FirstStartColumn = 0;
   Line->IsContinuation = false;
+  Line->SeenDecltypeAuto = false;
 
   if (ClosesWhitesmithsBlock && AdjustLevel == LineLevel::Remove)
 --Line->Level;
diff --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index 4138baaabe2693d..a4f150d19571266 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -61,6 +61,9 @@ struct UnwrappedLine {
 
   bool MustBeDeclaration = false;
 
+  /// Whether the parser has seen \c decltype(auto) in this line.
+  bool SeenDecltypeAuto = false;
+
   /// \c True if this line should be indented by ContinuationIndent in
   /// addition to the normal indention level.
   bool IsContinuation = false;
@@ -335,6 +338,14 @@ class UnwrappedLineParser {
   // statement contains more than some predefined number of nested statements).
   SmallVector NestedTooDeep;
 
+  // Keeps a stack of the states of nested lambdas (true if the return type of
+  // the lambda is `decltype(auto)`).
+  SmallV

[clang] [clang-format] Fix a bug in RemoveParentheses: ReturnStatement (PR #67911)

2023-10-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format


Changes

Don't remove the outermost parentheses surrounding a return statement 
expression when inside a function/lambda that has the decltype(auto) return 
type.

Fixed #67892.

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


3 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+24) 
- (modified) clang/lib/Format/UnwrappedLineParser.h (+11) 
- (modified) clang/unittests/Format/FormatTest.cpp (+50) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index bf38ed73c4a0b4e..dda5fd077e590e5 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -173,10 +173,12 @@ void UnwrappedLineParser::reset() {
   CommentsBeforeNextToken.clear();
   FormatTok = nullptr;
   MustBreakBeforeNextToken = false;
+  IsDecltypeAutoFunction = false;
   PreprocessorDirectives.clear();
   CurrentLines = &Lines;
   DeclarationScopeStack.clear();
   NestedTooDeep.clear();
+  NestedLambdas.clear();
   PPStack.clear();
   Line->FirstStartColumn = FirstStartColumn;
 
@@ -1766,6 +1768,17 @@ void UnwrappedLineParser::parseStructuralElement(
   if (parseStructLike())
 return;
   break;
+case tok::kw_decltype:
+  nextToken();
+  if (FormatTok->is(tok::l_paren)) {
+parseParens();
+assert(FormatTok->Previous);
+if (FormatTok->Previous->endsSequence(tok::r_paren, tok::kw_auto,
+  tok::l_paren)) {
+  Line->SeenDecltypeAuto = true;
+}
+  }
+  break;
 case tok::period:
   nextToken();
   // In Java, classes have an implicit static member "class".
@@ -1827,6 +1840,7 @@ void UnwrappedLineParser::parseStructuralElement(
   if (InRequiresExpression)
 FormatTok->setFinalizedType(TT_BracedListLBrace);
   if (!tryToParsePropertyAccessor() && !tryToParseBracedList()) {
+IsDecltypeAutoFunction = Line->SeenDecltypeAuto;
 // A block outside of parentheses must be the last part of a
 // structural element.
 // FIXME: Figure out cases where this is not true, and add projections
@@ -1844,6 +1858,7 @@ void UnwrappedLineParser::parseStructuralElement(
 }
 FormatTok->setFinalizedType(TT_FunctionLBrace);
 parseBlock();
+IsDecltypeAutoFunction = false;
 addUnwrappedLine();
 return;
   }
@@ -2249,9 +2264,15 @@ bool UnwrappedLineParser::tryToParseLambda() {
   return true;
 }
   }
+
   FormatTok->setFinalizedType(TT_LambdaLBrace);
   LSquare.setFinalizedType(TT_LambdaLSquare);
+
+  NestedLambdas.push_back(Line->SeenDecltypeAuto);
   parseChildBlock();
+  assert(!NestedLambdas.empty());
+  NestedLambdas.pop_back();
+
   return true;
 }
 
@@ -2469,6 +2490,8 @@ bool UnwrappedLineParser::parseParens(TokenType 
AmpAmpTokenType) {
PrevPrev->endsSequence(tok::kw_constexpr, tok::kw_if;
 const bool ReturnParens =
 Style.RemoveParentheses == FormatStyle::RPS_ReturnStatement &&
+((NestedLambdas.empty() && !IsDecltypeAutoFunction) ||
+ (!NestedLambdas.empty() && !NestedLambdas.back())) &&
 Prev && Prev->isOneOf(tok::kw_return, tok::kw_co_return) && Next &&
 Next->is(tok::semi);
 if ((DoubleParens && !Blacklisted) || ReturnParens) {
@@ -4379,6 +4402,7 @@ void UnwrappedLineParser::addUnwrappedLine(LineLevel 
AdjustLevel) {
   Line->MatchingOpeningBlockLineIndex = UnwrappedLine::kInvalidIndex;
   Line->FirstStartColumn = 0;
   Line->IsContinuation = false;
+  Line->SeenDecltypeAuto = false;
 
   if (ClosesWhitesmithsBlock && AdjustLevel == LineLevel::Remove)
 --Line->Level;
diff --git a/clang/lib/Format/UnwrappedLineParser.h 
b/clang/lib/Format/UnwrappedLineParser.h
index 4138baaabe2693d..a4f150d19571266 100644
--- a/clang/lib/Format/UnwrappedLineParser.h
+++ b/clang/lib/Format/UnwrappedLineParser.h
@@ -61,6 +61,9 @@ struct UnwrappedLine {
 
   bool MustBeDeclaration = false;
 
+  /// Whether the parser has seen \c decltype(auto) in this line.
+  bool SeenDecltypeAuto = false;
+
   /// \c True if this line should be indented by ContinuationIndent in
   /// addition to the normal indention level.
   bool IsContinuation = false;
@@ -335,6 +338,14 @@ class UnwrappedLineParser {
   // statement contains more than some predefined number of nested statements).
   SmallVector NestedTooDeep;
 
+  // Keeps a stack of the states of nested lambdas (true if the return type of
+  // the lambda is `decltype(auto)`).
+  SmallVector NestedLambdas;
+
+  // Whether the parser is parsing the body of a function whose return type is
+  // `decltype(auto)`.
+  bool IsDecltypeAutoFunction = false;
+
   // Represents preprocessor branch type, so we can find matching
   // #if/#else/#endif directives.
   enum PPBranchKind {
diff --git a/clang/unittests/Format/Format

[clang] Make -frewrite-includes put an endif at the end of the included text (PR #67613)

2023-10-01 Thread Dana Jansens via cfe-commits

danakj wrote:

I was just lamenting the lack of this feature this week. Thank you, I can’t 
wait to use it. 

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


[clang] [RISCV] Eliminate dead li after emitting VSETVLIs (PR #65934)

2023-10-01 Thread Yingwei Zheng via cfe-commits

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

>From 2fe5756dd4d49580d3a23b0ff1b72535f725915e Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Mon, 11 Sep 2023 15:51:46 +0800
Subject: [PATCH 1/4] [RISCV] Eliminate dead li after emitting VSETVLIs

---
 llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp  | 22 ++---
 .../RISCV/rvv/fixed-vectors-masked-gather.ll  | 24 ---
 2 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp 
b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index b42ad269c18de6f..918c96beb29afca 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -757,7 +757,8 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
   bool computeVLVTYPEChanges(const MachineBasicBlock &MBB,
  VSETVLIInfo &Info) const;
   void computeIncomingVLVTYPE(const MachineBasicBlock &MBB);
-  void emitVSETVLIs(MachineBasicBlock &MBB);
+  void emitVSETVLIs(MachineBasicBlock &MBB,
+SmallVectorImpl &DeadVLInstrs);
   void doLocalPostpass(MachineBasicBlock &MBB);
   void doPRE(MachineBasicBlock &MBB);
   void insertReadVL(MachineBasicBlock &MBB);
@@ -1216,7 +1217,8 @@ bool RISCVInsertVSETVLI::needVSETVLIPHI(const VSETVLIInfo 
&Require,
   return false;
 }
 
-void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock &MBB) {
+void RISCVInsertVSETVLI::emitVSETVLIs(
+MachineBasicBlock &MBB, SmallVectorImpl &DeadVLInstrs) {
   VSETVLIInfo CurInfo = BlockInfo[MBB.getNumber()].Pred;
   // Track whether the prefix of the block we've scanned is transparent
   // (meaning has not yet changed the abstract state).
@@ -1255,6 +1257,13 @@ void RISCVInsertVSETVLI::emitVSETVLIs(MachineBasicBlock 
&MBB) {
 MachineOperand &VLOp = MI.getOperand(getVLOpNum(MI));
 if (VLOp.isReg()) {
   // Erase the AVL operand from the instruction.
+  if (MachineInstr *MI = MRI->getVRegDef(VLOp.getReg());
+  MI && MI->getOpcode() == RISCV::ADDI &&
+  MI->getOperand(1).isReg() && MI->getOperand(2).isImm() &&
+  MI->getOperand(1).getReg() == RISCV::X0 &&
+  MI->getOperand(2).getImm() != 0)
+DeadVLInstrs.push_back(MI);
+
   VLOp.setReg(RISCV::NoRegister);
   VLOp.setIsKill(false);
 }
@@ -1580,8 +1589,9 @@ bool 
RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
   // Phase 2 information to avoid adding vsetvlis before the first vector
   // instruction in the block if the VL/VTYPE is satisfied by its
   // predecessors.
+  SmallVector DeadVLInstrs;
   for (MachineBasicBlock &MBB : MF)
-emitVSETVLIs(MBB);
+emitVSETVLIs(MBB, DeadVLInstrs);
 
   // Now that all vsetvlis are explicit, go through and do block local
   // DSE and peephole based demanded fields based transforms.  Note that
@@ -1592,6 +1602,12 @@ bool 
RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
   for (MachineBasicBlock &MBB : MF)
 doLocalPostpass(MBB);
 
+  // Remove dead LI instructions that set VL.
+  for (MachineInstr *MI : DeadVLInstrs) {
+if (MRI->use_nodbg_empty(MI->getOperand(0).getReg()))
+  MI->eraseFromParent();
+  }
+
   // Once we're fully done rewriting all the instructions, do a final pass
   // through to check for VSETVLIs which write to an unused destination.
   // For the non X0, X0 variant, we can replace the destination register
diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll 
b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
index f7352b4659e5a9b..0d306775528ed86 100644
--- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-masked-gather.ll
@@ -12393,7 +12393,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> %idxs, <32 x i1> %m
 ; RV64ZVE32F-NEXT:vmv.x.s a2, v12
 ; RV64ZVE32F-NEXT:add a2, a0, a2
 ; RV64ZVE32F-NEXT:lbu a2, 0(a2)
-; RV64ZVE32F-NEXT:li a3, 32
 ; RV64ZVE32F-NEXT:vmv.s.x v12, a2
 ; RV64ZVE32F-NEXT:vsetivli zero, 2, e8, m2, tu, ma
 ; RV64ZVE32F-NEXT:vslideup.vi v10, v12, 1
@@ -12431,7 +12430,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> %idxs, <32 x i1> %m
 ; RV64ZVE32F-NEXT:vmv.x.s a2, v14
 ; RV64ZVE32F-NEXT:add a2, a0, a2
 ; RV64ZVE32F-NEXT:lbu a2, 0(a2)
-; RV64ZVE32F-NEXT:li a3, 32
 ; RV64ZVE32F-NEXT:vmv.s.x v14, a2
 ; RV64ZVE32F-NEXT:vsetivli zero, 6, e8, m2, tu, ma
 ; RV64ZVE32F-NEXT:vslideup.vi v10, v14, 5
@@ -12455,7 +12453,6 @@ define <32 x i8> @mgather_baseidx_v32i8(ptr %base, <32 
x i8> %idxs, <32 x i1> %m
 ; RV64ZVE32F-NEXT:vmv.x.s a2, v13
 ; RV64ZVE32F-NEXT:add a2, a0, a2
 ; RV64ZVE32F-NEXT:lbu a2, 0(a2)
-; RV64ZVE32F-NEXT:li a3, 32
 ; RV64ZVE32F-NEXT:vmv.s.x v14, a2
 ; RV64ZVE32F-NEXT:vsetivli zero, 10, e8, m2, tu, ma
 ; RV64ZVE32F-NEXT:vslideup.vi v10, v

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

2023-10-01 Thread Yingwei Zheng 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))) {

dtcxzyw wrote:

Sorry, I accidentally dropped the checks in 
70a70fb44d0e628a1cf485e1767ada3eaaa26b0f.

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] [Support] Add KnownBits::computeForSubBorrow (PR #67788)

2023-10-01 Thread Nikita Popov via cfe-commits


@@ -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.
-if (Opcode == ISD::USUBO_CARRY || Opcode == ISD::SSUBO_CARRY)
-  break;
+// With UADDO_CARRY and SSUBO_CARRY a borrow bit may be added in.
+KnownBits Borrow(1);
+if (Opcode == ISD::USUBO_CARRY || Opcode == ISD::SSUBO_CARRY) {
+  Borrow = computeKnownBits(Op.getOperand(2), DemandedElts, Depth + 1);
+  // Borrow has bit width 1
+  Borrow = Borrow.zextOrTrunc(1);

nikic wrote:

There are no zero-bit integers in SDAG (or IR). The use of zextOrTrunc in the 
comment probably dates back to the time when APInt did not allow 
zext/sext/trunc to the original bit width.

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


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

2023-10-01 Thread Nikita Popov via cfe-commits


@@ -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.
-if (Opcode == ISD::USUBO_CARRY || Opcode == ISD::SSUBO_CARRY)
-  break;
+// With UADDO_CARRY and SSUBO_CARRY a borrow bit may be added in.
+KnownBits Borrow(1);
+if (Opcode == ISD::USUBO_CARRY || Opcode == ISD::SSUBO_CARRY) {
+  Borrow = computeKnownBits(Op.getOperand(2), DemandedElts, Depth + 1);
+  // Borrow has bit width 1
+  Borrow = Borrow.zextOrTrunc(1);

nikic wrote:

There are no zero-bit integers in SDAG (or IR). The use of zextOrTrunc in the 
comment probably dates back to the time when APInt did not allow 
zext/sext/trunc to the original bit width.

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


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

2023-10-01 Thread Nikita Popov via cfe-commits


@@ -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.
-if (Opcode == ISD::USUBO_CARRY || Opcode == ISD::SSUBO_CARRY)
-  break;
+// With UADDO_CARRY and SSUBO_CARRY a borrow bit may be added in.
+KnownBits Borrow(1);
+if (Opcode == ISD::USUBO_CARRY || Opcode == ISD::SSUBO_CARRY) {
+  Borrow = computeKnownBits(Op.getOperand(2), DemandedElts, Depth + 1);
+  // Borrow has bit width 1
+  Borrow = Borrow.zextOrTrunc(1);

nikic wrote:

There are no zero-bit integers in SDAG (or IR). The use of zextOrTrunc in the 
comment probably dates back to the time when APInt did not allow 
zext/sext/trunc to the original bit width.

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


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

2023-10-01 Thread Yingwei Zheng via cfe-commits

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

>From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 9 Sep 2023 23:07:29 +0800
Subject: [PATCH 1/9] [InstCombine] Simplify the pattern `a ne/eq (zext (a
 ne/eq c))`

---
 .../InstCombine/InstCombineCompares.cpp   |  62 ++
 .../test/Transforms/InstCombine/icmp-range.ll | 181 ++
 2 files changed, 243 insertions(+)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 9fdc46fec631679..837b8e6d2619989 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -6309,7 +6309,69 @@ Instruction 
*InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) {
   Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE)
 return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y);
 
+  ICmpInst::Predicate Pred1, Pred2;
   const APInt *C;
+  // icmp eq/ne X, (zext (icmp eq/ne X, C))
+  if (match(&I, m_c_ICmp(Pred1, m_Value(X),
+ m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) &&
+  ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) {
+if (C->isZero()) {
+  if (Pred2 == ICmpInst::ICMP_EQ) {
+// icmp eq X, (zext (icmp eq X, 0)) --> false
+// icmp ne X, (zext (icmp eq X, 0)) --> true
+return replaceInstUsesWith(
+I,
+Constant::getIntegerValue(
+I.getType(),
+APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE;
+  } else {
+// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2
+// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1
+return ICmpInst::Create(
+Instruction::ICmp,
+Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT
+   : ICmpInst::ICMP_ULT,
+X,
+Constant::getIntegerValue(
+X->getType(), APInt(X->getType()->getScalarSizeInBits(),
+Pred1 == ICmpInst::ICMP_NE ? 1 : 2)));
+  }
+} else if (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
+return replaceInstUsesWith(
+I,
+Constant::getIntegerValue(
+I.getType(),
+APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE;
+  } else {
+// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2
+// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1
+return ICmpInst::Create(
+Instruction::ICmp,
+Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT
+   : ICmpInst::ICMP_ULT,
+X,
+Constant::getIntegerValue(
+X->getType(), APInt(X->getType()->getScalarSizeInBits(),
+Pred1 == ICmpInst::ICMP_NE ? 1 : 2)));
+  }
+} else {
+  // 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
+  return ICmpInst::Create(
+  Instruction::ICmp, Pred1, X,
+  Constant::getIntegerValue(
+  X->getType(),
+  APInt(X->getType()->getScalarSizeInBits(),
+static_cast(Pred2 == ICmpInst::ICMP_NE;
+}
+  }
+
   if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y 
&&
   match(I.getOperand(1), m_APInt(C)) &&
   X->getType()->isIntOrIntVectorTy(1) &&
diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll 
b/llvm/test/Transforms/InstCombine/icmp-range.ll
index 4281e09cb0309c8..15424fce33fdeea 100644
--- a/llvm/test/Transforms/InstCombine/icmp-range.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-range.ll
@@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) {
   ret i1 %cmp
 }
 
+define i1 @icmp_ne_zext_eq_zero(i32 %a) {
+; CHECK-LABEL: @icmp_ne_zext_eq_zero(
+; CHECK-NEXT:ret i1 true
+;
+  %cmp = icmp eq i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp ne i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_ne_zext_ne_zero(i32 %a) {
+; CHECK-LABEL: @icmp_ne_zext_ne_zero(
+; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1
+; CHECK-NEXT:ret i1 [[CMP1]]
+;
+  %cmp = icmp ne i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp ne i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_eq_zext_eq_zero(i32 %a) {
+; CHECK-LABEL: @icmp_eq_zext_eq_zero(
+; CHECK-NEXT:ret i1 false
+;
+  %cmp = icmp eq i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp eq i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_eq_zext_ne_zero(i32 %

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

2023-10-01 Thread Yingwei Zheng via cfe-commits

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

>From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 9 Sep 2023 23:07:29 +0800
Subject: [PATCH 1/9] [InstCombine] Simplify the pattern `a ne/eq (zext (a
 ne/eq c))`

---
 .../InstCombine/InstCombineCompares.cpp   |  62 ++
 .../test/Transforms/InstCombine/icmp-range.ll | 181 ++
 2 files changed, 243 insertions(+)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 9fdc46fec631679..837b8e6d2619989 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -6309,7 +6309,69 @@ Instruction 
*InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) {
   Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE)
 return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y);
 
+  ICmpInst::Predicate Pred1, Pred2;
   const APInt *C;
+  // icmp eq/ne X, (zext (icmp eq/ne X, C))
+  if (match(&I, m_c_ICmp(Pred1, m_Value(X),
+ m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) &&
+  ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) {
+if (C->isZero()) {
+  if (Pred2 == ICmpInst::ICMP_EQ) {
+// icmp eq X, (zext (icmp eq X, 0)) --> false
+// icmp ne X, (zext (icmp eq X, 0)) --> true
+return replaceInstUsesWith(
+I,
+Constant::getIntegerValue(
+I.getType(),
+APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE;
+  } else {
+// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2
+// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1
+return ICmpInst::Create(
+Instruction::ICmp,
+Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT
+   : ICmpInst::ICMP_ULT,
+X,
+Constant::getIntegerValue(
+X->getType(), APInt(X->getType()->getScalarSizeInBits(),
+Pred1 == ICmpInst::ICMP_NE ? 1 : 2)));
+  }
+} else if (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
+return replaceInstUsesWith(
+I,
+Constant::getIntegerValue(
+I.getType(),
+APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE;
+  } else {
+// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2
+// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1
+return ICmpInst::Create(
+Instruction::ICmp,
+Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT
+   : ICmpInst::ICMP_ULT,
+X,
+Constant::getIntegerValue(
+X->getType(), APInt(X->getType()->getScalarSizeInBits(),
+Pred1 == ICmpInst::ICMP_NE ? 1 : 2)));
+  }
+} else {
+  // 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
+  return ICmpInst::Create(
+  Instruction::ICmp, Pred1, X,
+  Constant::getIntegerValue(
+  X->getType(),
+  APInt(X->getType()->getScalarSizeInBits(),
+static_cast(Pred2 == ICmpInst::ICMP_NE;
+}
+  }
+
   if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y 
&&
   match(I.getOperand(1), m_APInt(C)) &&
   X->getType()->isIntOrIntVectorTy(1) &&
diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll 
b/llvm/test/Transforms/InstCombine/icmp-range.ll
index 4281e09cb0309c8..15424fce33fdeea 100644
--- a/llvm/test/Transforms/InstCombine/icmp-range.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-range.ll
@@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) {
   ret i1 %cmp
 }
 
+define i1 @icmp_ne_zext_eq_zero(i32 %a) {
+; CHECK-LABEL: @icmp_ne_zext_eq_zero(
+; CHECK-NEXT:ret i1 true
+;
+  %cmp = icmp eq i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp ne i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_ne_zext_ne_zero(i32 %a) {
+; CHECK-LABEL: @icmp_ne_zext_ne_zero(
+; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1
+; CHECK-NEXT:ret i1 [[CMP1]]
+;
+  %cmp = icmp ne i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp ne i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_eq_zext_eq_zero(i32 %a) {
+; CHECK-LABEL: @icmp_eq_zext_eq_zero(
+; CHECK-NEXT:ret i1 false
+;
+  %cmp = icmp eq i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp eq i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_eq_zext_ne_zero(i32 %

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

2023-10-01 Thread Yingwei Zheng via cfe-commits

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

>From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 9 Sep 2023 23:07:29 +0800
Subject: [PATCH 1/9] [InstCombine] Simplify the pattern `a ne/eq (zext (a
 ne/eq c))`

---
 .../InstCombine/InstCombineCompares.cpp   |  62 ++
 .../test/Transforms/InstCombine/icmp-range.ll | 181 ++
 2 files changed, 243 insertions(+)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 9fdc46fec631679..837b8e6d2619989 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -6309,7 +6309,69 @@ Instruction 
*InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) {
   Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE)
 return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y);
 
+  ICmpInst::Predicate Pred1, Pred2;
   const APInt *C;
+  // icmp eq/ne X, (zext (icmp eq/ne X, C))
+  if (match(&I, m_c_ICmp(Pred1, m_Value(X),
+ m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) &&
+  ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) {
+if (C->isZero()) {
+  if (Pred2 == ICmpInst::ICMP_EQ) {
+// icmp eq X, (zext (icmp eq X, 0)) --> false
+// icmp ne X, (zext (icmp eq X, 0)) --> true
+return replaceInstUsesWith(
+I,
+Constant::getIntegerValue(
+I.getType(),
+APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE;
+  } else {
+// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2
+// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1
+return ICmpInst::Create(
+Instruction::ICmp,
+Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT
+   : ICmpInst::ICMP_ULT,
+X,
+Constant::getIntegerValue(
+X->getType(), APInt(X->getType()->getScalarSizeInBits(),
+Pred1 == ICmpInst::ICMP_NE ? 1 : 2)));
+  }
+} else if (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
+return replaceInstUsesWith(
+I,
+Constant::getIntegerValue(
+I.getType(),
+APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE;
+  } else {
+// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2
+// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1
+return ICmpInst::Create(
+Instruction::ICmp,
+Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT
+   : ICmpInst::ICMP_ULT,
+X,
+Constant::getIntegerValue(
+X->getType(), APInt(X->getType()->getScalarSizeInBits(),
+Pred1 == ICmpInst::ICMP_NE ? 1 : 2)));
+  }
+} else {
+  // 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
+  return ICmpInst::Create(
+  Instruction::ICmp, Pred1, X,
+  Constant::getIntegerValue(
+  X->getType(),
+  APInt(X->getType()->getScalarSizeInBits(),
+static_cast(Pred2 == ICmpInst::ICMP_NE;
+}
+  }
+
   if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y 
&&
   match(I.getOperand(1), m_APInt(C)) &&
   X->getType()->isIntOrIntVectorTy(1) &&
diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll 
b/llvm/test/Transforms/InstCombine/icmp-range.ll
index 4281e09cb0309c8..15424fce33fdeea 100644
--- a/llvm/test/Transforms/InstCombine/icmp-range.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-range.ll
@@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) {
   ret i1 %cmp
 }
 
+define i1 @icmp_ne_zext_eq_zero(i32 %a) {
+; CHECK-LABEL: @icmp_ne_zext_eq_zero(
+; CHECK-NEXT:ret i1 true
+;
+  %cmp = icmp eq i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp ne i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_ne_zext_ne_zero(i32 %a) {
+; CHECK-LABEL: @icmp_ne_zext_ne_zero(
+; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1
+; CHECK-NEXT:ret i1 [[CMP1]]
+;
+  %cmp = icmp ne i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp ne i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_eq_zext_eq_zero(i32 %a) {
+; CHECK-LABEL: @icmp_eq_zext_eq_zero(
+; CHECK-NEXT:ret i1 false
+;
+  %cmp = icmp eq i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp eq i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_eq_zext_ne_zero(i32 %

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

2023-10-01 Thread Yingwei Zheng via cfe-commits

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

>From d9d8bcbb98e8f5aecb9733329389d61a489bd731 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng 
Date: Sat, 9 Sep 2023 23:07:29 +0800
Subject: [PATCH 1/9] [InstCombine] Simplify the pattern `a ne/eq (zext (a
 ne/eq c))`

---
 .../InstCombine/InstCombineCompares.cpp   |  62 ++
 .../test/Transforms/InstCombine/icmp-range.ll | 181 ++
 2 files changed, 243 insertions(+)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 9fdc46fec631679..837b8e6d2619989 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -6309,7 +6309,69 @@ Instruction 
*InstCombinerImpl::foldICmpUsingBoolRange(ICmpInst &I) {
   Y->getType()->isIntOrIntVectorTy(1) && Pred == ICmpInst::ICMP_ULE)
 return BinaryOperator::CreateOr(Builder.CreateIsNull(X), Y);
 
+  ICmpInst::Predicate Pred1, Pred2;
   const APInt *C;
+  // icmp eq/ne X, (zext (icmp eq/ne X, C))
+  if (match(&I, m_c_ICmp(Pred1, m_Value(X),
+ m_ZExt(m_ICmp(Pred2, m_Deferred(X), m_APInt(C) &&
+  ICmpInst::isEquality(Pred1) && ICmpInst::isEquality(Pred2)) {
+if (C->isZero()) {
+  if (Pred2 == ICmpInst::ICMP_EQ) {
+// icmp eq X, (zext (icmp eq X, 0)) --> false
+// icmp ne X, (zext (icmp eq X, 0)) --> true
+return replaceInstUsesWith(
+I,
+Constant::getIntegerValue(
+I.getType(),
+APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE;
+  } else {
+// icmp eq X, (zext (icmp ne X, 0)) --> icmp ult X, 2
+// icmp ne X, (zext (icmp ne X, 0)) --> icmp ugt X, 1
+return ICmpInst::Create(
+Instruction::ICmp,
+Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT
+   : ICmpInst::ICMP_ULT,
+X,
+Constant::getIntegerValue(
+X->getType(), APInt(X->getType()->getScalarSizeInBits(),
+Pred1 == ICmpInst::ICMP_NE ? 1 : 2)));
+  }
+} else if (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
+return replaceInstUsesWith(
+I,
+Constant::getIntegerValue(
+I.getType(),
+APInt(1U, static_cast(Pred1 == ICmpInst::ICMP_NE;
+  } else {
+// icmp eq X, (zext (icmp eq X, 1)) --> icmp ult X, 2
+// icmp ne X, (zext (icmp eq X, 1)) --> icmp ugt X, 1
+return ICmpInst::Create(
+Instruction::ICmp,
+Pred1 == ICmpInst::ICMP_NE ? ICmpInst::ICMP_UGT
+   : ICmpInst::ICMP_ULT,
+X,
+Constant::getIntegerValue(
+X->getType(), APInt(X->getType()->getScalarSizeInBits(),
+Pred1 == ICmpInst::ICMP_NE ? 1 : 2)));
+  }
+} else {
+  // 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
+  return ICmpInst::Create(
+  Instruction::ICmp, Pred1, X,
+  Constant::getIntegerValue(
+  X->getType(),
+  APInt(X->getType()->getScalarSizeInBits(),
+static_cast(Pred2 == ICmpInst::ICMP_NE;
+}
+  }
+
   if (match(I.getOperand(0), m_c_Add(m_ZExt(m_Value(X)), m_SExt(m_Value(Y 
&&
   match(I.getOperand(1), m_APInt(C)) &&
   X->getType()->isIntOrIntVectorTy(1) &&
diff --git a/llvm/test/Transforms/InstCombine/icmp-range.ll 
b/llvm/test/Transforms/InstCombine/icmp-range.ll
index 4281e09cb0309c8..15424fce33fdeea 100644
--- a/llvm/test/Transforms/InstCombine/icmp-range.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-range.ll
@@ -1034,6 +1034,187 @@ define i1 @icmp_ne_bool_1(ptr %ptr) {
   ret i1 %cmp
 }
 
+define i1 @icmp_ne_zext_eq_zero(i32 %a) {
+; CHECK-LABEL: @icmp_ne_zext_eq_zero(
+; CHECK-NEXT:ret i1 true
+;
+  %cmp = icmp eq i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp ne i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_ne_zext_ne_zero(i32 %a) {
+; CHECK-LABEL: @icmp_ne_zext_ne_zero(
+; CHECK-NEXT:[[CMP1:%.*]] = icmp ugt i32 [[A:%.*]], 1
+; CHECK-NEXT:ret i1 [[CMP1]]
+;
+  %cmp = icmp ne i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp ne i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_eq_zext_eq_zero(i32 %a) {
+; CHECK-LABEL: @icmp_eq_zext_eq_zero(
+; CHECK-NEXT:ret i1 false
+;
+  %cmp = icmp eq i32 %a, 0
+  %conv = zext i1 %cmp to i32
+  %cmp1 = icmp eq i32 %conv, %a
+  ret i1 %cmp1
+}
+
+define i1 @icmp_eq_zext_ne_zero(i32 %

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

2023-10-01 Thread kleines Filmröllchen via cfe-commits

https://github.com/kleinesfilmroellchen updated 
https://github.com/llvm/llvm-project/pull/67749

From 167048c7025a516a5e57009947333c3980017107 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= 
Date: Sun, 1 Oct 2023 14:48:57 +0200
Subject: [PATCH] [clangd] Allow specifying what headers are always included
 via "" or <>

Projects can now add config fragments like this to their .clangd:

```yaml
Style:
  QuotedHeaders: "src/.*"
  AngledHeaders: ["path/sdk/.*", "third-party/.*"]
```

to force headers inserted via the --header-insertion=iwyu mode matching
at least one of the regexes to have <> (AngledHeaders) or ""
(QuotedHeaders) around them, respectively. For other headers (and in
conflicting cases where both styles have a matching regex), the current
system header detection remains.

Ref https://github.com/clangd/clangd/issues/1247

Based on https://reviews.llvm.org/D145843

This solution does not affect other clang tools like clang-format.
---
 clang-tools-extra/clangd/CodeComplete.cpp | 15 --
 clang-tools-extra/clangd/Config.h |  4 ++
 clang-tools-extra/clangd/ConfigCompile.cpp| 48 +++
 clang-tools-extra/clangd/ConfigFragment.h | 13 +
 clang-tools-extra/clangd/ConfigYAML.cpp   |  8 
 clang-tools-extra/clangd/Headers.cpp  | 34 +++--
 clang-tools-extra/clangd/Headers.h| 11 -
 clang-tools-extra/clangd/IncludeCleaner.h |  1 -
 clang-tools-extra/clangd/ParsedAST.cpp|  3 +-
 .../clangd/unittests/ConfigCompileTests.cpp   | 36 ++
 .../clangd/unittests/ConfigYAMLTests.cpp  |  8 +++-
 .../clangd/unittests/HeadersTests.cpp | 29 +--
 12 files changed, 192 insertions(+), 18 deletions(-)

diff --git a/clang-tools-extra/clangd/CodeComplete.cpp 
b/clang-tools-extra/clangd/CodeComplete.cpp
index 70c4d7e65b76db3..388e032e160474a 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -21,6 +21,7 @@
 #include "AST.h"
 #include "CodeCompletionStrings.h"
 #include "Compiler.h"
+#include "Config.h"
 #include "ExpectedTypes.h"
 #include "Feature.h"
 #include "FileDistance.h"
@@ -786,8 +787,8 @@ SpecifiedScope getQueryScopes(CodeCompletionContext 
&CCContext,
   llvm::StringRef SpelledSpecifier = Lexer::getSourceText(
   CharSourceRange::getCharRange(SemaSpecifier->getRange()),
   CCSema.SourceMgr, clang::LangOptions());
-  if (SpelledSpecifier.consume_front("::")) 
-  Scopes.QueryScopes = {""};
+  if (SpelledSpecifier.consume_front("::"))
+Scopes.QueryScopes = {""};
   Scopes.UnresolvedQualifier = std::string(SpelledSpecifier);
   // Sema excludes the trailing "::".
   if (!Scopes.UnresolvedQualifier->empty())
@@ -1540,7 +1541,7 @@ class CodeCompleteFlow {
   CompletionPrefix HeuristicPrefix;
   std::optional Filter; // Initialized once Sema runs.
   Range ReplacedRange;
-  std::vector QueryScopes; // Initialized once Sema runs.
+  std::vector QueryScopes;  // Initialized once Sema runs.
   std::vector AccessibleScopes; // Initialized once Sema runs.
   // Initialized once QueryScopes is initialized, if there are scopes.
   std::optional ScopeProximity;
@@ -1599,7 +1600,9 @@ class CodeCompleteFlow {
   Inserter.emplace(
   SemaCCInput.FileName, SemaCCInput.ParseInput.Contents, Style,
   SemaCCInput.ParseInput.CompileCommand.Directory,
-  &Recorder->CCSema->getPreprocessor().getHeaderSearchInfo());
+  &Recorder->CCSema->getPreprocessor().getHeaderSearchInfo(),
+  Config::current().Style.QuotedHeaders,
+  Config::current().Style.AngledHeaders);
   for (const auto &Inc : Includes.MainFileIncludes)
 Inserter->addExisting(Inc);
 
@@ -1682,7 +1685,9 @@ class CodeCompleteFlow {
 auto Style = getFormatStyleForFile(FileName, Content, TFS);
 // This will only insert verbatim headers.
 Inserter.emplace(FileName, Content, Style,
- /*BuildDir=*/"", /*HeaderSearchInfo=*/nullptr);
+ /*BuildDir=*/"", /*HeaderSearchInfo=*/nullptr,
+ Config::current().Style.QuotedHeaders,
+ Config::current().Style.AngledHeaders);
 
 auto Identifiers = collectIdentifiers(Content, Style);
 std::vector IdentifierResults;
diff --git a/clang-tools-extra/clangd/Config.h 
b/clang-tools-extra/clangd/Config.h
index daae8d1c0c833eb..5d70ed3376715e5 100644
--- a/clang-tools-extra/clangd/Config.h
+++ b/clang-tools-extra/clangd/Config.h
@@ -121,6 +121,10 @@ struct Config {
 // declarations, always spell out the whole name (with or without leading
 // ::). All nested namespaces are affected as well.
 std::vector FullyQualifiedNamespaces;
+
+// List of regexes for inserting certain headers with <> or "".
+std::vector> QuotedHeaders;
+std::vector> AngledHeaders;
   } Style;
 
   /// Configures code completion feature.
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp

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

2023-10-01 Thread kleines Filmröllchen via cfe-commits

kleinesfilmroellchen wrote:

Thanks for the finding @zyn0217, refactored the config compiler code a little. 
Tests should pass now and I have re-tested this on SerenityOS and other small 
project where it works as expected in practice.

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] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


https://github.com/carlosgalvezp updated 
https://github.com/llvm/llvm-project/pull/67528

>From 7a70366e08f2c2f1181bb74f7716d8b1e3f1b62e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 08:07:01 +
Subject: [PATCH 1/3] [clang] Enable Wenum-constexpr-conversion also in system
 headers and macros

As per review comments on https://reviews.llvm.org/D150226, we should
allow for one more release before turning this warning into a hard
error, by making it visible in system headers and macros, so that
people are aware of it and can work on it.
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/include/clang/Basic/DiagnosticASTKinds.td | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8f5a67e14c9aba3..6a1afa656a470b4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -71,6 +71,9 @@ C++ Specific Potentially Breaking Changes
   (`#49884 `_), and
   (`#61273 `_)
 
+- The warning `-Wenum-constexpr-conversion` is now also enabled by default on 
system headers and
+  macros. It will be turned into a hard (non-downgradable) error in the next 
Clang release.
+
 ABI Changes in This Version
 ---
 - Following the SystemV ABI for x86-64, ``__int128`` arguments will no longer
diff --git a/clang/include/clang/Basic/DiagnosticASTKinds.td 
b/clang/include/clang/Basic/DiagnosticASTKinds.td
index d2656310e79c9b8..0019553233fdef6 100644
--- a/clang/include/clang/Basic/DiagnosticASTKinds.td
+++ b/clang/include/clang/Basic/DiagnosticASTKinds.td
@@ -405,7 +405,8 @@ def warn_fixedpoint_constant_overflow : Warning<
   InGroup>;
 def warn_constexpr_unscoped_enum_out_of_range : Warning<
   "integer value %0 is outside the valid range of values [%1, %2] for the "
-  "enumeration type %3">, DefaultError, 
InGroup>;
+  "enumeration type %3">, DefaultError, ShowInSystemHeader, ShowInSystemMacro,
+  InGroup>;
 
 // This is a temporary diagnostic, and shall be removed once our
 // implementation is complete, and like the preceding constexpr notes belongs

>From 45fe235f06c4c1693e555baab2bedf233bef57e3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlos=20G=C3=A1lvez?= 
Date: Wed, 27 Sep 2023 09:15:33 +
Subject: [PATCH 2/3] Add test

---
 .../enum-constexpr-conversion-system-header.h | 19 +++
 .../SemaCXX/constant-expression-cxx11.cpp | 11 ---
 2 files changed, 27 insertions(+), 3 deletions(-)
 create mode 100644 
clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h

diff --git 
a/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h 
b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
new file mode 100644
index 000..0850f3405eed3a4
--- /dev/null
+++ b/clang/test/SemaCXX/Inputs/enum-constexpr-conversion-system-header.h
@@ -0,0 +1,19 @@
+// System header for testing that -Wenum-constexpr-conversion leads to an error
+// when included in user code, or when the system macro is used.
+
+enum SystemEnum
+{
+a = 0,
+b = 1,
+};
+
+void testValueInRangeOfEnumerationValuesInSystemHeader()
+{
+constexpr SystemEnum x1 = static_cast(123);
+// expected-error@-1 {{integer value 123 is outside the valid range of 
values [0, 1] for the enumeration type 'SystemEnum'}}
+
+const SystemEnum x2 = static_cast(123);  // ok, not a constant 
expression context
+}
+
+#define CONSTEXPR_CAST_TO_SYSTEM_ENUM_OUTSIDE_OF_RANGE \
+constexpr SystemEnum system_enum = static_cast(123)
diff --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 89d1b3ea6de05ea..8fb994224853bf1 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=expected,cxx20_23,cxx23
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=expected,cxx11_20,cxx20_23 
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify=expected,cxx11_20,cxx11
-triple x86_64-linux -Wno-string-plus-int -Wno-pointer-arith 
-Wno-zero-length-array -Wno-c99-designator -fcxx-exceptions -pedantic %s 
-Wno-comment -Wno-tautological-pointer-compare -Wno-bool-conversion
+// RUN: %clang_cc1 -std=c++23 -isystem %S/Inputs -fsyntax-only 
-verify=expected,cxx20_23,cxx23 

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

2023-10-01 Thread via cfe-commits

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

Thanks, looks good to me codewise. I haven't tested it myself but I trust that 
you have.
This seems worth backporting to 17.x since it technically fixes a new 
regression.

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][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)

2023-10-01 Thread Sergei Barannikov 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: 



@@ -26,6 +28,66 @@ static_assert(number != 10, ""); // expected-error{{failed}} 
\
  // expected-note{{evaluates to}} \
  // ref-note{{evaluates to}}
 
+
+namespace i128 {

s-barannikov wrote:

@tbaederr 
These tests fail on targets that do not have __int128 support.
You can reporoduce the issue by adding -triple=avr to the RUN lines.


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][Modules] `checkModuleIsAvailable` should use a const & parameter instead of pointer (PR #67902)

2023-10-01 Thread David Stone via cfe-commits

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

>From 63c7f357cedd2633feac36ec07892243661764d9 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,
  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.Definiti

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

2023-10-01 Thread David Stone via cfe-commits

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

>From 858a76e16a772078b29452645c5beb223c06dc8e 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 6ca9fe84266c9d4257ba0102c571f4f4771f8bb2 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] remove duplicate ModuleId alias (PR #67899)

2023-10-01 Thread David Stone via cfe-commits

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

>From 3583e0420b5de21a88f3e7d1289f3b272e680a98 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] Qualify non-dependent types of a class template with its declaration (PR #67566)

2023-10-01 Thread Luca Di sera via cfe-commits

diseraluca wrote:

>  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.

I cannot for certain say if there is an issue or not with how the Qt codebase 
is setup; but I think it is out of the scope of the task we are trying to solve 
to change that based on the behavior of QDoc interoperations with Clang.

For what it is worth, I've been playing with a very small example to check a 
few possibilities, and even excluding explicit specializations we still have 
certain cases that are not stable.

Say in

```
#pragma once

template
class QList {
public:
using Foo = const T&;

void begin(Foo);
};
```

Adding something as `using Bar = QList;`, and this being the only code in 
the translation unit, we still have the addition of such a line modifying our 
output, qualifying the type of the first parameter of `begin` as 
`QList::Foo`, even with your proposal.

Say we can stabilize that, so that it always qualify in the same way, say 
`QList`.

If we are documenting, maybe, some method `QList::Foo QList::bar()` and 
we show to the user the return type as `QList::Foo`, this is going to be 
misleading, 
albeit not as erroneous as the `QFuture` case, for our user.

Indeed, the return type of `bar` really depends on the instantiation of `QList` 
that we are looking at and it would be extremely confusing for a user skimming 
our documentation to think that it always returns a `QList::Foo`.
As a documentation generator we really want to look at the generic case for our 
output.

Now, say we have a very stable output, albeit not adequate for our case, it 
might simplify doing some postprocessing to qualify in the way we want, but at 
that point we still need to maintain something relatively similar to 
`getFullyQualified*`, thus why it isn't that much of a difference for our use 
case to only have a more stable output.

There are some other cases that might be iffy for our use-case too, with this 
behavior.

Thus why I think, albeit unfortunate, our use-cases just happen to be somewhat 
in conflict with regards to the output of `getFullyQualified*`.

@vgvassilev  Both me an my team are deeply thankful for your help. It was 
really kind to try and find a solution for our case.

I will close this PR as I don't think it can be merged, as it would break other 
people use cases.
I will leave it open 1 or 2 days more in case someone else wants to chime in 
with something.

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-10-01 Thread Vassil Vassilev via cfe-commits

vgvassilev wrote:

@diseraluca, since this code touches a case where we do some best effort 
recovery, would it be possible to change that interface to take a 
lambda/callback function and specialize it in your end to cover the docs case? 

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


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

2023-10-01 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

With this patch, it started to fail with:
It would be nice to have a better error message suggesting what to do

  -- Performing Test HAVE_DECL_STRERROR_S
  -- Performing Test HAVE_DECL_STRERROR_S - Failed
  CMake Error at /build/source/flang-rt/unittests/CMakeLists.txt:37 (message):
Target llvm_gtest not found.
  
  
  -- Configuring incomplete, errors occurred!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154869

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


[clang] [libclang] Visit function template instantiations (PR #67928)

2023-10-01 Thread Daan Vanoverloop via cfe-commits

https://github.com/Danacus created 
https://github.com/llvm/llvm-project/pull/67928

This PR changes `CursorVisitor::VisitFunctionTemplateDecl` such that 
instantiations of the function template (e.g. `template void foo();`) are 
visited as children of the `FunctionTemplateDecl`. This also applies to class 
methods. 

The use case for this I have in mind would be to add limited support for 
function templates in `rust-bindgen` (see 
https://github.com/rust-lang/rust-bindgen/pull/2650).

Additionally, I have taken the liberty to add `CXCursor_CXXMethod` to the list 
of cursors supported by `getTemplateArgument`, since I found it a bit odd that 
this was not the case before.

Please let me know if there is anything that needs to be changed, I'm happy to 
make changes if necessary.

>From a516d2c53451db78147a631b5c092dbfeba73e89 Mon Sep 17 00:00:00 2001
From: Daan Vanoverloop 
Date: Sun, 1 Oct 2023 18:48:26 +0200
Subject: [PATCH 1/2] [libclang] Add support for template arguments of
 CXXMethod cursors

---
 clang/include/clang-c/Index.h   | 13 +++--
 clang/tools/c-index-test/c-index-test.c |  1 +
 clang/tools/libclang/CXCursor.cpp   |  8 
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 1b91feabd584c50..eeb23ce41ef373c 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3126,9 +3126,9 @@ CINDEX_LINKAGE int 
clang_Cursor_getNumTemplateArguments(CXCursor C);
 /**
  * Retrieve the kind of the I'th template argument of the CXCursor C.
  *
- * If the argument CXCursor does not represent a FunctionDecl, StructDecl, or
- * ClassTemplatePartialSpecialization, an invalid template argument kind is
- * returned.
+ * If the argument CXCursor does not represent a FunctionDecl, CXXMethod,
+ * StructDecl, or ClassTemplatePartialSpecialization, an invalid template
+ * argument kind is returned.
  *
  * For example, for the following declaration and specialization:
  *   template 
@@ -3147,9 +3147,10 @@ clang_Cursor_getTemplateArgumentKind(CXCursor C, 
unsigned I);
  * Retrieve a CXType representing the type of a TemplateArgument of a
  *  function decl representing a template specialization.
  *
- * If the argument CXCursor does not represent a FunctionDecl, StructDecl,
- * ClassDecl or ClassTemplatePartialSpecialization whose I'th template argument
- * has a kind of CXTemplateArgKind_Integral, an invalid type is returned.
+ * If the argument CXCursor does not represent a FunctionDecl, CXXMethod,
+ * StructDecl, ClassDecl or ClassTemplatePartialSpecialization whose I'th
+ * template argument has a kind of CXTemplateArgKind_Integral, an invalid type
+ * is returned.
  *
  * For example, for the following declaration and specialization:
  *   template 
diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 9d66a22f3b43b55..238c9951269d159 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1040,6 +1040,7 @@ static void PrintCursor(CXCursor Cursor, const char 
*CommentSchemaFile) {
   clang_disposeString(Name);
 
   if (Cursor.kind == CXCursor_FunctionDecl
+  || Cursor.kind == CXCursor_CXXMethod
   || Cursor.kind == CXCursor_StructDecl
   || Cursor.kind == CXCursor_ClassDecl
   || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) {
diff --git a/clang/tools/libclang/CXCursor.cpp 
b/clang/tools/libclang/CXCursor.cpp
index fd03c48ba1a42aa..190e0063b78d740 100644
--- a/clang/tools/libclang/CXCursor.cpp
+++ b/clang/tools/libclang/CXCursor.cpp
@@ -1364,8 +1364,8 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) 
{
 
 int clang_Cursor_getNumTemplateArguments(CXCursor C) {
   CXCursorKind kind = clang_getCursorKind(C);
-  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
-  kind != CXCursor_ClassDecl &&
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod &&
+  kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl &&
   kind != CXCursor_ClassTemplatePartialSpecialization) {
 return -1;
   }
@@ -1411,8 +1411,8 @@ enum CXGetTemplateArgumentStatus {
 static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I,
 TemplateArgument *TA) {
   CXCursorKind kind = clang_getCursorKind(C);
-  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
-  kind != CXCursor_ClassDecl &&
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod &&
+  kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl &&
   kind != CXCursor_ClassTemplatePartialSpecialization) {
 return -1;
   }

>From fa471bdf99b7d4e44f92c6e88af4f3d9876f6b95 Mon Sep 17 00:00:00 2001
From: Daan Vanoverloop 
Date: Sun, 1 Oct 2023 18:48:32 +0200
Subject: [PATCH 2/2] [libclang] Visit function template instantiations

---
 clang/test/Index/index-templat

[clang] [libclang] Visit function template instantiations (PR #67928)

2023-10-01 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 632022e61c54428068576685b4743f105f2e 
fa471bdf99b7d4e44f92c6e88af4f3d9876f6b95 -- clang/include/clang-c/Index.h 
clang/test/Index/index-templates.cpp clang/test/Index/print-display-names.cpp 
clang/tools/c-index-test/c-index-test.c clang/tools/libclang/CIndex.cpp 
clang/tools/libclang/CXCursor.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 238c99512..b41aaf00c 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1039,11 +1039,11 @@ static void PrintCursor(CXCursor Cursor, const char 
*CommentSchemaFile) {
  clang_getCString(Name), line, column);
   clang_disposeString(Name);
 
-  if (Cursor.kind == CXCursor_FunctionDecl
-  || Cursor.kind == CXCursor_CXXMethod
-  || Cursor.kind == CXCursor_StructDecl
-  || Cursor.kind == CXCursor_ClassDecl
-  || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) {
+  if (Cursor.kind == CXCursor_FunctionDecl ||
+  Cursor.kind == CXCursor_CXXMethod ||
+  Cursor.kind == CXCursor_StructDecl ||
+  Cursor.kind == CXCursor_ClassDecl ||
+  Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) {
 /* Collect the template parameter kinds from the base template. */
 int NumTemplateArgs = clang_Cursor_getNumTemplateArguments(Cursor);
 int I;
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index aeb685694..7cb85ee61 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -967,8 +967,8 @@ bool 
CursorVisitor::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
 
   for (auto *Child : D->specializations())
 if (Visit(MakeCXCursor(Child, TU)))
-  return true; 
-  
+  return true;
+
   return false;
 }
 

``




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


[clang] [libclang] Visit function template instantiations (PR #67928)

2023-10-01 Thread Daan Vanoverloop via cfe-commits

https://github.com/Danacus updated 
https://github.com/llvm/llvm-project/pull/67928

>From a516d2c53451db78147a631b5c092dbfeba73e89 Mon Sep 17 00:00:00 2001
From: Daan Vanoverloop 
Date: Sun, 1 Oct 2023 18:48:26 +0200
Subject: [PATCH 1/3] [libclang] Add support for template arguments of
 CXXMethod cursors

---
 clang/include/clang-c/Index.h   | 13 +++--
 clang/tools/c-index-test/c-index-test.c |  1 +
 clang/tools/libclang/CXCursor.cpp   |  8 
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 1b91feabd584c50..eeb23ce41ef373c 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3126,9 +3126,9 @@ CINDEX_LINKAGE int 
clang_Cursor_getNumTemplateArguments(CXCursor C);
 /**
  * Retrieve the kind of the I'th template argument of the CXCursor C.
  *
- * If the argument CXCursor does not represent a FunctionDecl, StructDecl, or
- * ClassTemplatePartialSpecialization, an invalid template argument kind is
- * returned.
+ * If the argument CXCursor does not represent a FunctionDecl, CXXMethod,
+ * StructDecl, or ClassTemplatePartialSpecialization, an invalid template
+ * argument kind is returned.
  *
  * For example, for the following declaration and specialization:
  *   template 
@@ -3147,9 +3147,10 @@ clang_Cursor_getTemplateArgumentKind(CXCursor C, 
unsigned I);
  * Retrieve a CXType representing the type of a TemplateArgument of a
  *  function decl representing a template specialization.
  *
- * If the argument CXCursor does not represent a FunctionDecl, StructDecl,
- * ClassDecl or ClassTemplatePartialSpecialization whose I'th template argument
- * has a kind of CXTemplateArgKind_Integral, an invalid type is returned.
+ * If the argument CXCursor does not represent a FunctionDecl, CXXMethod,
+ * StructDecl, ClassDecl or ClassTemplatePartialSpecialization whose I'th
+ * template argument has a kind of CXTemplateArgKind_Integral, an invalid type
+ * is returned.
  *
  * For example, for the following declaration and specialization:
  *   template 
diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 9d66a22f3b43b55..238c9951269d159 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1040,6 +1040,7 @@ static void PrintCursor(CXCursor Cursor, const char 
*CommentSchemaFile) {
   clang_disposeString(Name);
 
   if (Cursor.kind == CXCursor_FunctionDecl
+  || Cursor.kind == CXCursor_CXXMethod
   || Cursor.kind == CXCursor_StructDecl
   || Cursor.kind == CXCursor_ClassDecl
   || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) {
diff --git a/clang/tools/libclang/CXCursor.cpp 
b/clang/tools/libclang/CXCursor.cpp
index fd03c48ba1a42aa..190e0063b78d740 100644
--- a/clang/tools/libclang/CXCursor.cpp
+++ b/clang/tools/libclang/CXCursor.cpp
@@ -1364,8 +1364,8 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) 
{
 
 int clang_Cursor_getNumTemplateArguments(CXCursor C) {
   CXCursorKind kind = clang_getCursorKind(C);
-  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
-  kind != CXCursor_ClassDecl &&
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod &&
+  kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl &&
   kind != CXCursor_ClassTemplatePartialSpecialization) {
 return -1;
   }
@@ -1411,8 +1411,8 @@ enum CXGetTemplateArgumentStatus {
 static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I,
 TemplateArgument *TA) {
   CXCursorKind kind = clang_getCursorKind(C);
-  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
-  kind != CXCursor_ClassDecl &&
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod &&
+  kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl &&
   kind != CXCursor_ClassTemplatePartialSpecialization) {
 return -1;
   }

>From fa471bdf99b7d4e44f92c6e88af4f3d9876f6b95 Mon Sep 17 00:00:00 2001
From: Daan Vanoverloop 
Date: Sun, 1 Oct 2023 18:48:32 +0200
Subject: [PATCH 2/3] [libclang] Visit function template instantiations

---
 clang/test/Index/index-templates.cpp | 17 +++--
 clang/test/Index/print-display-names.cpp |  3 +++
 clang/tools/libclang/CIndex.cpp  |  9 -
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/clang/test/Index/index-templates.cpp 
b/clang/test/Index/index-templates.cpp
index 430a156b189d9e3..4994ddcde8d9ebc 100644
--- a/clang/test/Index/index-templates.cpp
+++ b/clang/test/Index/index-templates.cpp
@@ -54,7 +54,7 @@ void template_exprs() {
   f(value());
   Z4().getAs();
 }
-
+extern template float Z4::getAs();
 template void swap(T&, T&);
 template void swap(Y&, Y&);
 void swap(Z4&, Z4&);
@@ -110,6 +110,8 @@ static const int FxnTmpl_Var = 7;
 template <>
 void foo(float Value);
 
+t

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

2023-10-01 Thread Paul Scoropan via Phabricator via cfe-commits
pscoro added a comment.

In D154869#4652224 , @sylvestre.ledru 
wrote:

> With this patch, it started to fail with:
> It would be nice to have a better error message suggesting what to do
>
>   -- Performing Test HAVE_DECL_STRERROR_S
>   -- Performing Test HAVE_DECL_STRERROR_S - Failed
>   CMake Error at /build/source/flang-rt/unittests/CMakeLists.txt:37 (message):
> Target llvm_gtest not found.
>   
>   
>   -- Configuring incomplete, errors occurred!

Hi, I originally authored this patch but **I am no longer actively involved in 
Flang's development at the moment**, however, I've been getting notifications 
that this patch has been landed yesterday and subsequently, the failing 
buildbots.
I believe all the gtest not found errors originate from a missing build flag, 
as per the documentation page for flang-rt in `flang-rt/docs/GettingStarted.md`:

  # We need to enable GTest if we want to run Flang-rt's testsuites
  -DLLVM_INSTALL_GTEST=On \

I believe I saw that clang buildbots also got inadvertently by this cmake 
change as well.
Wish I had time to investigate this further myself, hopefully @madanial can 
take a closer look. I believe what needs to be done is:

- flang buildbots need their build flags updated to include 
`-DLLVM_INSTALL_GTEST=On`
- The `Target llvm_gtest not found.` should be improved to offer better guidance
- The clang failures should be looked at closer; see if its possible to make a 
change to the cmake to limit the scope of builds needing the 
`-DLLVM_INSTALL_GTEST=On` flag update to just be flang builds. If there is no 
simple way to limit the scope, then updating the build flags for the clang 
builders is another solution
- I noticed at least one flang builder 
(https://lab.llvm.org/buildbot/#/builders/191/builds/24124) is failing build 
with:

  FAILED: bin/external-hello-world 
  : && /usr/local/bin/c++ -fPIC -fno-semantic-interposition 
-fvisibility-inlines-hidden -Werror=date-time 
-Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter 
-Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic 
-Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough 
-Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion 
-Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion 
-Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument 
-Wstring-conversion   -Wcovered-switch-default -Wno-nested-anon-types 
-O3 -DNDEBUG 
-Wl,-rpath-link,/home/tcwg-buildbot/worker/flang-aarch64-rel-assert/build/./lib 
 -Wl,--gc-sections 
tools/flang/examples/ExternalHelloWorld/CMakeFiles/external-hello-world.dir/external-hello.cpp.o
 -o bin/external-hello-world  -Wl,-rpath,"\$ORIGIN/../lib:"  -lpthread  
-lFortranRuntime && :
  /usr/bin/ld: cannot find -lFortranRuntime

This looks to be a usage of the old FortranRuntime configuration that I 
overlooked and so it wasnt updated. This should be linking flang-rt instead of 
FortranRuntime

Hopefully addressing these small issues will get the buildbots green again, 
sorry for the disruptions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154869

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


[clang] [libclang] Visit function template instantiations (PR #67928)

2023-10-01 Thread Daan Vanoverloop via cfe-commits

https://github.com/Danacus updated 
https://github.com/llvm/llvm-project/pull/67928

>From a516d2c53451db78147a631b5c092dbfeba73e89 Mon Sep 17 00:00:00 2001
From: Daan Vanoverloop 
Date: Sun, 1 Oct 2023 18:48:26 +0200
Subject: [PATCH 1/4] [libclang] Add support for template arguments of
 CXXMethod cursors

---
 clang/include/clang-c/Index.h   | 13 +++--
 clang/tools/c-index-test/c-index-test.c |  1 +
 clang/tools/libclang/CXCursor.cpp   |  8 
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 1b91feabd584c50..eeb23ce41ef373c 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3126,9 +3126,9 @@ CINDEX_LINKAGE int 
clang_Cursor_getNumTemplateArguments(CXCursor C);
 /**
  * Retrieve the kind of the I'th template argument of the CXCursor C.
  *
- * If the argument CXCursor does not represent a FunctionDecl, StructDecl, or
- * ClassTemplatePartialSpecialization, an invalid template argument kind is
- * returned.
+ * If the argument CXCursor does not represent a FunctionDecl, CXXMethod,
+ * StructDecl, or ClassTemplatePartialSpecialization, an invalid template
+ * argument kind is returned.
  *
  * For example, for the following declaration and specialization:
  *   template 
@@ -3147,9 +3147,10 @@ clang_Cursor_getTemplateArgumentKind(CXCursor C, 
unsigned I);
  * Retrieve a CXType representing the type of a TemplateArgument of a
  *  function decl representing a template specialization.
  *
- * If the argument CXCursor does not represent a FunctionDecl, StructDecl,
- * ClassDecl or ClassTemplatePartialSpecialization whose I'th template argument
- * has a kind of CXTemplateArgKind_Integral, an invalid type is returned.
+ * If the argument CXCursor does not represent a FunctionDecl, CXXMethod,
+ * StructDecl, ClassDecl or ClassTemplatePartialSpecialization whose I'th
+ * template argument has a kind of CXTemplateArgKind_Integral, an invalid type
+ * is returned.
  *
  * For example, for the following declaration and specialization:
  *   template 
diff --git a/clang/tools/c-index-test/c-index-test.c 
b/clang/tools/c-index-test/c-index-test.c
index 9d66a22f3b43b55..238c9951269d159 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1040,6 +1040,7 @@ static void PrintCursor(CXCursor Cursor, const char 
*CommentSchemaFile) {
   clang_disposeString(Name);
 
   if (Cursor.kind == CXCursor_FunctionDecl
+  || Cursor.kind == CXCursor_CXXMethod
   || Cursor.kind == CXCursor_StructDecl
   || Cursor.kind == CXCursor_ClassDecl
   || Cursor.kind == CXCursor_ClassTemplatePartialSpecialization) {
diff --git a/clang/tools/libclang/CXCursor.cpp 
b/clang/tools/libclang/CXCursor.cpp
index fd03c48ba1a42aa..190e0063b78d740 100644
--- a/clang/tools/libclang/CXCursor.cpp
+++ b/clang/tools/libclang/CXCursor.cpp
@@ -1364,8 +1364,8 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) 
{
 
 int clang_Cursor_getNumTemplateArguments(CXCursor C) {
   CXCursorKind kind = clang_getCursorKind(C);
-  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
-  kind != CXCursor_ClassDecl &&
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod &&
+  kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl &&
   kind != CXCursor_ClassTemplatePartialSpecialization) {
 return -1;
   }
@@ -1411,8 +1411,8 @@ enum CXGetTemplateArgumentStatus {
 static int clang_Cursor_getTemplateArgument(CXCursor C, unsigned I,
 TemplateArgument *TA) {
   CXCursorKind kind = clang_getCursorKind(C);
-  if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
-  kind != CXCursor_ClassDecl &&
+  if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod &&
+  kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl &&
   kind != CXCursor_ClassTemplatePartialSpecialization) {
 return -1;
   }

>From fa471bdf99b7d4e44f92c6e88af4f3d9876f6b95 Mon Sep 17 00:00:00 2001
From: Daan Vanoverloop 
Date: Sun, 1 Oct 2023 18:48:32 +0200
Subject: [PATCH 2/4] [libclang] Visit function template instantiations

---
 clang/test/Index/index-templates.cpp | 17 +++--
 clang/test/Index/print-display-names.cpp |  3 +++
 clang/tools/libclang/CIndex.cpp  |  9 -
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/clang/test/Index/index-templates.cpp 
b/clang/test/Index/index-templates.cpp
index 430a156b189d9e3..4994ddcde8d9ebc 100644
--- a/clang/test/Index/index-templates.cpp
+++ b/clang/test/Index/index-templates.cpp
@@ -54,7 +54,7 @@ void template_exprs() {
   f(value());
   Z4().getAs();
 }
-
+extern template float Z4::getAs();
 template void swap(T&, T&);
 template void swap(Y&, Y&);
 void swap(Z4&, Z4&);
@@ -110,6 +110,8 @@ static const int FxnTmpl_Var = 7;
 template <>
 void foo(float Value);
 
+t

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

2023-10-01 Thread Richard Smith via cfe-commits

zygoloid wrote:

> @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
> ```

I predict we'll get a bug report saying "I didn't do a store, I used `memcpy`, 
which is specified as doing a byte-by-byte copy". But given that improving this 
would require adding a new entry point into the runtime library, and we don't 
know how common or rare this situation will be, I think it's probably OK to 
wait until someone complains.

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][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)

2023-10-01 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: 



@@ -26,6 +28,66 @@ static_assert(number != 10, ""); // expected-error{{failed}} 
\
  // expected-note{{evaluates to}} \
  // ref-note{{evaluates to}}
 
+
+namespace i128 {

tbaederr wrote:

Oof, sorry. Everything was fine this morning and then I left the house... Will 
fix immediately.

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] c77b2ad - [clang][Interp] Disable int128 tests on targets that don't have int128

2023-10-01 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-01T19:18:48+02:00
New Revision: c77b2ad00ba465698783e3a4a9b7af07c337171c

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

LOG: [clang][Interp] Disable int128 tests on targets that don't have int128

This broke build bots.

Added: 


Modified: 
clang/test/AST/Interp/literals.cpp

Removed: 




diff  --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index 0dd036353fa7efd..b57a0e64c5fac32 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -7,8 +7,6 @@
 #define INT_MAX __INT_MAX__
 
 typedef __INTPTR_TYPE__ intptr_t;
-typedef __int128 int128_t;
-typedef unsigned __int128 uint128_t;
 
 
 static_assert(true, "");
@@ -29,7 +27,10 @@ static_assert(number != 10, ""); // expected-error{{failed}} 
\
  // ref-note{{evaluates to}}
 
 
+#ifdef __SIZEOF__INT128__
 namespace i128 {
+  typedef __int128 int128_t;
+  typedef unsigned __int128 uint128_t;
   constexpr int128_t I128_1 = 12;
   static_assert(I128_1 == 12, "");
   static_assert(I128_1 != 10, "");
@@ -87,6 +88,7 @@ constexpr int128_t Error = __LDBL_MAX__; // ref-warning 
{{implicit conversion of
  // expected-error {{must be 
initialized by a constant expression}} \
  // expected-note {{is outside the 
range of representable values of type}}
 }
+#endif
 
 constexpr bool b = number;
 static_assert(b, "");



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


[clang] [clang][Interp] Implement __builtin_popcount() (PR #67929)

2023-10-01 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/67929

None

>From ce44117306858aa1bff3766dc640201ffd99a89f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 1 Oct 2023 19:41:15 +0200
Subject: [PATCH] [clang][Interp] Implement __builtin_popcount()

---
 clang/lib/AST/Interp/InterpBuiltin.cpp  | 20 
 clang/test/AST/Interp/builtin-functions.cpp |  9 +
 2 files changed, 29 insertions(+)

diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index d816145598049b0..bba0255219bc0d7 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -398,6 +398,16 @@ static bool interp__builtin_fabs(InterpState &S, CodePtr 
OpPC,
   return true;
 }
 
+static bool interp__builtin_popcount(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *Func,
+ const CallExpr *Call) {
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  APSInt Val = peekToAPSInt(S.Stk, ArgT);
+  pushInt(S, Val.popcount());
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -513,6 +523,16 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return Ret(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_popcount:
+  case Builtin::BI__builtin_popcountl:
+  case Builtin::BI__builtin_popcountll:
+  case Builtin::BI__popcnt16: // Microsoft variants of popcount
+  case Builtin::BI__popcnt:
+  case Builtin::BI__popcnt64:
+if (interp__builtin_popcount(S, OpPC, Frame, F, Call))
+  return retInt(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index cd4ad010af12220..755f2b755412ef6 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -260,3 +260,12 @@ namespace SourceLocation {
 static_assert(c.a.n == __LINE__ - 1, "");
   }
 }
+
+namespace popcount {
+  static_assert(__builtin_popcount(~0u) == __CHAR_BIT__ * sizeof(unsigned 
int), "");
+  static_assert(__builtin_popcount(0) == 0, "");
+  static_assert(__builtin_popcountl(~0ul) == __CHAR_BIT__ * sizeof(unsigned 
long), "");
+  static_assert(__builtin_popcountl(0) == 0, "");
+  static_assert(__builtin_popcountll(~0ull) == __CHAR_BIT__ * sizeof(unsigned 
long long), "");
+  static_assert(__builtin_popcountll(0) == 0, "");
+}

___
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-10-01 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

This broke a buildbot, as a user reported on discord: 
https://buildkite.com/llvm-project/github-pull-requests/builds/5171#018aec0c-75ba-431a-a5c8-6a5cba51de28


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154869

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


[clang] [clang][Modules] Move `ASTSourceDescriptor` into its own file (PR #67930)

2023-10-01 Thread David Stone via cfe-commits

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

None

>From a52da2e5889f14bcc36ae4263518a49e1e85c244 Mon Sep 17 00:00:00 2001
From: David Stone 
Date: Sun, 1 Oct 2023 12:02:48 -0600
Subject: [PATCH] [clang][Modules] Move `ASTSourceDescriptor` into its own file

---
 .../include/clang/Basic/ASTSourceDescriptor.h | 52 +++
 clang/include/clang/Basic/Module.h| 26 --
 clang/lib/AST/ExternalASTSource.cpp   |  2 +-
 clang/lib/Basic/ASTSourceDescriptor.cpp   | 33 
 clang/lib/Basic/CMakeLists.txt|  1 +
 clang/lib/Basic/Module.cpp| 15 --
 clang/lib/CodeGen/CGDebugInfo.h   |  3 +-
 clang/lib/Serialization/ASTReader.cpp |  1 +
 .../Plugins/ExpressionParser/Clang/ASTUtils.h |  8 ++-
 .../Clang/ClangExternalASTSourceCallbacks.cpp |  1 +
 .../Clang/ClangExternalASTSourceCallbacks.h   |  8 ++-
 11 files changed, 105 insertions(+), 45 deletions(-)
 create mode 100644 clang/include/clang/Basic/ASTSourceDescriptor.h
 create mode 100644 clang/lib/Basic/ASTSourceDescriptor.cpp

diff --git a/clang/include/clang/Basic/ASTSourceDescriptor.h 
b/clang/include/clang/Basic/ASTSourceDescriptor.h
new file mode 100644
index 000..175e0551db76562
--- /dev/null
+++ b/clang/include/clang/Basic/ASTSourceDescriptor.h
@@ -0,0 +1,52 @@
+//===- ASTSourceDescriptor.h -*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+/// \file
+/// Defines the clang::ASTSourceDescriptor class, which abstracts clang modules
+/// and precompiled header files
+//
+//===--===//
+
+#ifndef LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H
+#define LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H
+
+#include "clang/Basic/Module.h"
+#include "llvm/ADT/StringRef.h"
+#include 
+#include 
+
+namespace clang {
+
+/// Abstracts clang modules and precompiled header files and holds
+/// everything needed to generate debug info for an imported module
+/// or PCH.
+class ASTSourceDescriptor {
+  StringRef PCHModuleName;
+  StringRef Path;
+  StringRef ASTFile;
+  ASTFileSignature Signature;
+  Module *ClangModule = nullptr;
+
+public:
+  ASTSourceDescriptor() = default;
+  ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
+  ASTFileSignature Signature)
+  : PCHModuleName(std::move(Name)), Path(std::move(Path)),
+ASTFile(std::move(ASTFile)), Signature(Signature) {}
+  ASTSourceDescriptor(Module &M);
+
+  std::string getModuleName() const;
+  StringRef getPath() const { return Path; }
+  StringRef getASTFile() const { return ASTFile; }
+  ASTFileSignature getSignature() const { return Signature; }
+  Module *getModuleOrNull() const { return ClangModule; }
+};
+
+} // namespace clang
+
+#endif // LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H
diff --git a/clang/include/clang/Basic/Module.h 
b/clang/include/clang/Basic/Module.h
index 676fd372493a3aa..60381472bbd4e59 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -850,32 +850,6 @@ class VisibleModuleSet {
   unsigned Generation = 0;
 };
 
-/// Abstracts clang modules and precompiled header files and holds
-/// everything needed to generate debug info for an imported module
-/// or PCH.
-class ASTSourceDescriptor {
-  StringRef PCHModuleName;
-  StringRef Path;
-  StringRef ASTFile;
-  ASTFileSignature Signature;
-  Module *ClangModule = nullptr;
-
-public:
-  ASTSourceDescriptor() = default;
-  ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
-  ASTFileSignature Signature)
-  : PCHModuleName(std::move(Name)), Path(std::move(Path)),
-ASTFile(std::move(ASTFile)), Signature(Signature) {}
-  ASTSourceDescriptor(Module &M);
-
-  std::string getModuleName() const;
-  StringRef getPath() const { return Path; }
-  StringRef getASTFile() const { return ASTFile; }
-  ASTFileSignature getSignature() const { return Signature; }
-  Module *getModuleOrNull() const { return ClangModule; }
-};
-
-
 } // namespace clang
 
 #endif // LLVM_CLANG_BASIC_MODULE_H
diff --git a/clang/lib/AST/ExternalASTSource.cpp 
b/clang/lib/AST/ExternalASTSource.cpp
index 090ef02aa4224d6..00bc6b4b919abf7 100644
--- a/clang/lib/AST/ExternalASTSource.cpp
+++ b/clang/lib/AST/ExternalASTSource.cpp
@@ -15,10 +15,10 @@
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/Basic/ASTSourceDescriptor.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/LLVM.h"
-#include "clang/Basic/Module.h"
 #include "c

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

2023-10-01 Thread Nico Weber 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: 


nico wrote:

Looks like this doesn't build on windows: 
http://45.33.8.238/win/84383/step_4.txt

Please take a look and revert for now if it takes a while to fix.

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][Modules] `checkModuleIsAvailable` should use a const & parameter instead of pointer (PR #67902)

2023-10-01 Thread David Stone via cfe-commits

davidstone wrote:

@ChuanqiXu9 

https://github.com/llvm/llvm-project/pull/67902
___
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-10-01 Thread David Stone via cfe-commits

davidstone wrote:

@ChuanqiXu9 

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] remove duplicate ModuleId alias (PR #67899)

2023-10-01 Thread David Stone via cfe-commits

davidstone wrote:

@ChuanqiXu9 

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] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-10-01 Thread via cfe-commits

goldsteinn wrote:

ping.

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


[clang] [clang] Add test for CWG2267 (PR #67931)

2023-10-01 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/67931

Related: #63416

>From 4720a0f6bce7b1531dec2005d642938db1370335 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Sun, 1 Oct 2023 21:28:21 +0300
Subject: [PATCH] [clang] Add test for CWG2267

---
 clang/test/CXX/drs/dr22xx.cpp | 22 ++
 clang/www/cxx_dr_status.html  |  2 +-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/dr22xx.cpp b/clang/test/CXX/drs/dr22xx.cpp
index 414925f0d74cc2e..cd849443b1119ba 100644
--- a/clang/test/CXX/drs/dr22xx.cpp
+++ b/clang/test/CXX/drs/dr22xx.cpp
@@ -123,6 +123,28 @@ namespace CheckAfterMerging2 {
 #endif
 } // namespace dr2233
 
+namespace dr2267 { // dr2267: no
+#if __cplusplus >= 201103L
+struct A {} a;
+struct B { explicit B(const A&); }; // #dr2267-struct-B
+
+struct D { D(); };
+struct C { explicit operator D(); } c;
+
+B b1(a);
+const B &b2{a}; // FIXME ill-formed
+const B &b3(a);
+// expected-error@-1 {{no viable conversion from 'struct A' to 'const B'}}
+// expected-note@#dr2267-struct-B {{candidate constructor (the implicit copy 
constructor) not viable: no known conversion from 'struct A' to 'const B &' for 
1st argument}}
+// expected-note@#dr2267-struct-B {{candidate constructor (the implicit move 
constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st 
argument}}
+// expected-note@#dr2267-struct-B {{explicit constructor is not a candidate}}
+
+D d1(c);
+const D &d2{c}; // FIXME ill-formed
+const D &d3(c); // FIXME ill-formed
+#endif
+}
+
 namespace dr2292 { // dr2292: 9
 #if __cplusplus >= 201103L
   template using id = T;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index ee9712e9bab9949..49386bbbc44c80f 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -13409,7 +13409,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2267.html";>2267
 CD5
 Copy-initialization of temporary in reference 
direct-initialization
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/2268.html";>2268

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


[clang] [clang] Add test for CWG2267 (PR #67931)

2023-10-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

Related: #63416

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


2 Files Affected:

- (modified) clang/test/CXX/drs/dr22xx.cpp (+22) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/test/CXX/drs/dr22xx.cpp b/clang/test/CXX/drs/dr22xx.cpp
index 414925f0d74cc2e..cd849443b1119ba 100644
--- a/clang/test/CXX/drs/dr22xx.cpp
+++ b/clang/test/CXX/drs/dr22xx.cpp
@@ -123,6 +123,28 @@ namespace CheckAfterMerging2 {
 #endif
 } // namespace dr2233
 
+namespace dr2267 { // dr2267: no
+#if __cplusplus >= 201103L
+struct A {} a;
+struct B { explicit B(const A&); }; // #dr2267-struct-B
+
+struct D { D(); };
+struct C { explicit operator D(); } c;
+
+B b1(a);
+const B &b2{a}; // FIXME ill-formed
+const B &b3(a);
+// expected-error@-1 {{no viable conversion from 'struct A' to 'const B'}}
+// expected-note@#dr2267-struct-B {{candidate constructor (the implicit copy 
constructor) not viable: no known conversion from 'struct A' to 'const B &' for 
1st argument}}
+// expected-note@#dr2267-struct-B {{candidate constructor (the implicit move 
constructor) not viable: no known conversion from 'struct A' to 'B &&' for 1st 
argument}}
+// expected-note@#dr2267-struct-B {{explicit constructor is not a candidate}}
+
+D d1(c);
+const D &d2{c}; // FIXME ill-formed
+const D &d3(c); // FIXME ill-formed
+#endif
+}
+
 namespace dr2292 { // dr2292: 9
 #if __cplusplus >= 201103L
   template using id = T;
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index ee9712e9bab9949..49386bbbc44c80f 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -13409,7 +13409,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/2267.html";>2267
 CD5
 Copy-initialization of temporary in reference 
direct-initialization
-Unknown
+No
   
   
 https://cplusplus.github.io/CWG/issues/2268.html";>2268

``




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


[clang] [clang] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread Carlos Galvez via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


carlosgalvezp wrote:

It seems checks are broken on trunk, I see commits merged with failing 
pre-merge tests. They seem to be unrelated to this patch though.

Is there anything else you'd like fixed before merging? @dwblaikie 
@AaronBallman @shafik 

https://github.com/llvm/llvm-project/pull/67528
___
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-10-01 Thread Luca Di sera via cfe-commits

diseraluca wrote:

@vgvassilev  If that is an acceptable interface for the LLVM interface then, 
yes, it would be perfect from our side, and I'm more than happy to update the 
PR in the next few days.

Just to be sure that I understood your proposal.

`getFullyQualified*` calls will accept a new parameter, a callable, that will 
be down the call chain up to `createNestedNameSpecifierForScopeOf(const 
ASTContext &, const Decl *, ...)` and will be called when the teplate case is 
encountered?
Or are you thinking more of a callable that replaces the call to 
`createNestedNameSpecifierForScopeOf(const ASTContext &, const Decl *, ...)`?

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] e39de2b - [clang] [MinGW] Tolerate mingw specific linker options during compilation (#67891)

2023-10-01 Thread via cfe-commits

Author: Martin Storsjö
Date: 2023-10-01T23:42:16+03:00
New Revision: e39de2b8862ae43459324da84279366997265078

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

LOG: [clang] [MinGW] Tolerate mingw specific linker options during compilation 
(#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.

Added: 
clang/test/Driver/mingw-linker-options.c

Modified: 
clang/lib/Driver/ToolChains/MinGW.cpp

Removed: 




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-10-01 Thread Martin Storsjö via cfe-commits

https://github.com/mstorsjo closed 
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] Implement constexpr bit_cast for vectors (PR #66894)

2023-10-01 Thread Richard Smith via cfe-commits


@@ -7304,6 +7382,21 @@ class BufferToAPValueConverter {
 return ArrayValue;
   }
 
+  std::optional visit(const VectorType *Ty, CharUnits Offset) {
+SmallVector Bytes;
+if (!Buffer.readObject(Offset, Info.Ctx.getTypeSizeInChars(Ty), Bytes))
+  return std::nullopt;

zygoloid wrote:

The object representation indeed does not seem to initialize the padding bits: 
https://godbolt.org/z/szWenbE8c

- In Clang, the padding bytes contain non-zero values for both vectors and 
structs.
- In Clang msan, only the branch on uninitialized padding in the struct is 
caught. (I think this is an msan bug; it presumably isn't taking into account 
that a vector type might contain padding.)
- In GCC, the padding bytes in the vector are zeroed but the padding bytes in 
the struct are not. (Though that could be an accident of implementation rather 
than intent.)

Casts between vector types don't seem to initialize padding bits either: 
https://godbolt.org/z/Gex93x3xx -- so the test in const-init.c seems to be 
wrong.

> Should I rewrite all the bit cast conversion code in 
> `APValueToBufferConverter`/`BufferToAPValueConverter` again while taking 
> uninitialized padding bytes into account, and redirect the existing 
> `CK_BitCast` code to point to that?

:( Yeah, I guess so. Sorry.

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


[clang-tools-extra] [clang-tidy] Fix bug in modernize-use-emplace (PR #66169)

2023-10-01 Thread Chris Cotter via cfe-commits

https://github.com/ccotter updated 
https://github.com/llvm/llvm-project/pull/66169

>From d8c40ccc6744d350b8bc530917accd1d8d87118e Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Mon, 11 Sep 2023 00:05:54 -0400
Subject: [PATCH 1/3] [clang-tidy] Fix bug in modernize-use-emplace

emplace_back cannot construct an aggregate with arguments used to
initialize the aggregate.
Closes #62387

Test plan: Added test case from #62387 which contains code that should
not be replaced by the check.
---
 .../clang-tidy/modernize/UseEmplaceCheck.cpp | 16 +++-
 clang-tools-extra/docs/ReleaseNotes.rst  |  4 
 .../checkers/modernize/use-emplace.cpp   | 16 
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
index 554abcd900e329c..e4455d6f9c1feec 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -13,6 +13,10 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::modernize {
 
 namespace {
+AST_MATCHER_P(InitListExpr, initCountIs, unsigned, N) {
+  return Node.getNumInits() == N;
+}
+
 // Identical to hasAnyName, except it does not take template specifiers into
 // account. This is used to match the functions names as in
 // DefaultEmplacyFunctions below without caring about the template types of the
@@ -207,11 +211,13 @@ void UseEmplaceCheck::registerMatchers(MatchFinder 
*Finder) {
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
   // allow for T{} to be replaced, even if no CTOR is declared
-  auto HasConstructInitListExpr = has(initListExpr(anyOf(
-  allOf(has(SoughtConstructExpr),
-has(cxxConstructExpr(argumentCountIs(0,
-  has(cxxBindTemporaryExpr(has(SoughtConstructExpr),
-   has(cxxConstructExpr(argumentCountIs(0;
+  auto HasConstructInitListExpr =
+  has(initListExpr(anyOf(initCountIs(0), initCountIs(1)),
+   anyOf(allOf(has(SoughtConstructExpr),
+   has(cxxConstructExpr(argumentCountIs(0,
+ has(cxxBindTemporaryExpr(
+ has(SoughtConstructExpr),
+ 
has(cxxConstructExpr(argumentCountIs(0;
   auto HasBracedInitListExpr =
   anyOf(has(cxxBindTemporaryExpr(HasConstructInitListExpr)),
 HasConstructInitListExpr);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 19c977977f9044c..694beeb98a54e36 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -247,6 +247,10 @@ Changes in existing checks
   ` to support for-loops with
   iterators initialized by free functions like ``begin``, ``end``, or ``size``.
 
+- Improved :doc:`modernize-use-emplace
+  ` to not replace aggregates that
+  ``emplace_back`` cannot construct with aggregate initialization.
+
 - Improved :doc:`modernize-use-equals-delete
   ` check to ignore
   false-positives when special member function is actually used or implicit.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
index fead2b6151d0218..74edf0760bb324d 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-emplace.cpp
@@ -1183,6 +1183,11 @@ struct NonTrivialWithVector {
   std::vector it;
 };
 
+struct NonTrivialWithIntAndVector {
+  int x;
+  std::vector it;
+};
+
 struct NonTrivialWithCtor {
   NonTrivialWithCtor();
   NonTrivialWithCtor(std::vector const&);
@@ -1332,6 +1337,17 @@ void testBracedInitTemporaries() {
   v3.push_back(NonTrivialWithCtor{{}});
   v3.push_back({{0}});
   v3.push_back({{}});
+
+  std::vector v4;
+
+  // These should not be noticed or fixed; after the correction, the code won't
+  // compile.
+  v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{1, {}});
+  v4.push_back(NonTrivialWithIntAndVector{});
+  // CHECK-FIXES: v4.push_back(NonTrivialWithIntAndVector{});
+  v4.push_back({});
+  // CHECK-FIXES: v4.push_back({});
 }
 
 void testWithPointerTypes() {

>From 9e96a3b60c132ac94e58f1e76e1ae7fe4d2238fb Mon Sep 17 00:00:00 2001
From: Chris Cotter 
Date: Wed, 13 Sep 2023 09:29:27 -0400
Subject: [PATCH 2/3] Use emplace in ReleaseNotes

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

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 694beeb98a54e36..fb6034caca06e30 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -249,7 +249,7 @@ Changes in e

[clang] [mlir][affine] Check the input vector sizes to be greater than 0 (PR #65293)

2023-10-01 Thread Sergei Grechanik via cfe-commits

https://github.com/sergei-grechanik approved this pull request.


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


[clang-tools-extra] [mlir][affine] Check the input vector sizes to be greater than 0 (PR #65293)

2023-10-01 Thread Sergei Grechanik via cfe-commits

https://github.com/sergei-grechanik approved this pull request.


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


[clang] [clang-format] Fix a bug in RemoveParentheses: ReturnStatement (PR #67911)

2023-10-01 Thread via cfe-commits

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


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


[clang] [NFC][clang] change remaining context-dependent type nodes to ContextualFoldingSet (PR #67751)

2023-10-01 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

Thank you for the PR. Could you provide some context in the PR description? 
From the title it sounds like there were prior changes that this is finishing. 
It would be helpful to have a link to those prior changes.

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


[clang] [NFC][clang] change remaining context-dependent type nodes to ContextualFoldingSet (PR #67751)

2023-10-01 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Thanks for the review.

I think the change stands on itself, as we are avoiding storing one pointer per 
Type Node instance, for the cost of one extra pointer per ASTContext, which is 
negligible.

These type nodes we are changing here are old, at least as far back as 2008.
In 2010 this `ContextualFoldingSet` folding set was added in this commit: 
b9639aaed4ef98becf413b9d52680686f8f22ca1
To solve exactly this problem as you can see in the commit description.

But we never went back and updated the existing users. This patch does that.

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


[clang] [NFC][clang] change remaining context-dependent type nodes to ContextualFoldingSet (PR #67751)

2023-10-01 Thread Matheus Izvekov via cfe-commits

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


[clang] [NFC][clang] change remaining context-dependent type nodes to ContextualFoldingSet (PR #67751)

2023-10-01 Thread Matheus Izvekov via cfe-commits

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


[clang] [clang] fix hasAnyBase not binding submatchers (PR #67939)

2023-10-01 Thread via cfe-commits

https://github.com/5chmidti created 
https://github.com/llvm/llvm-project/pull/67939

The BoundNodesTreeBuilder used in the BaseSpecMatcher was the original
and was reset to its original state if a match occurred.
The matcher now uses the local copy in the inner matcher.

Fixes #65421


>From 8a57465057bbbd8ef6fcf4376f5eba9ce972acc5 Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Mon, 2 Oct 2023 01:34:24 +0200
Subject: [PATCH] [clang] fix hasAnyBase not binding submatchers

The BoundNodesTreeBuilder used in the BaseSpecMatcher was the original
and was reset to its original state if a match occurred.
The matcher now uses the local copy in the inner matcher.

Fixes #65421
---
 clang/lib/ASTMatchers/ASTMatchersInternal.cpp   |  2 +-
 .../ASTMatchers/ASTMatchersTraversalTest.cpp| 13 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 40688107215f287..435bbdeda22066e 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -87,7 +87,7 @@ bool matchesAnyBase(const CXXRecordDecl &Node,
   [Finder, Builder, &BaseSpecMatcher](const CXXBaseSpecifier *BaseSpec,
   CXXBasePath &IgnoredParam) {
 BoundNodesTreeBuilder Result(*Builder);
-if (BaseSpecMatcher.matches(*BaseSpec, Finder, Builder)) {
+if (BaseSpecMatcher.matches(*BaseSpec, Finder, &Result)) {
   *Builder = std::move(Result);
   return true;
 }
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 89954711804aa57..d4a695b974bf0e5 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -8,6 +8,7 @@
 
 #include "ASTMatchersTest.h"
 #include "clang/AST/Attrs.inc"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
@@ -5457,6 +5458,18 @@ TEST(HasParent, NoDuplicateParents) {
 stmt().bind("node"), std::make_unique()));
 }
 
+TEST(HasAnyBase, BindsInnerBoundNodes) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "struct Inner {}; struct Proxy : Inner {}; struct Main : public "
+  "Proxy {};",
+  cxxRecordDecl(hasName("Main"),
+hasAnyBase(cxxBaseSpecifier(hasType(
+cxxRecordDecl(hasName("Inner")).bind("base-class")
+  .bind("class"),
+  std::make_unique>("base-class",
+ "Inner")));
+}
+
 TEST(TypeMatching, PointeeTypes) {
   EXPECT_TRUE(matches("int b; int &a = b;",
   referenceType(pointee(builtinType();

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


[clang] [clang] fix hasAnyBase not binding submatchers (PR #67939)

2023-10-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

The BoundNodesTreeBuilder used in the BaseSpecMatcher was the original
and was reset to its original state if a match occurred.
The matcher now uses the local copy in the inner matcher.

Fixes #65421


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


2 Files Affected:

- (modified) clang/lib/ASTMatchers/ASTMatchersInternal.cpp (+1-1) 
- (modified) clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp (+13) 


``diff
diff --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 40688107215f287..435bbdeda22066e 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -87,7 +87,7 @@ bool matchesAnyBase(const CXXRecordDecl &Node,
   [Finder, Builder, &BaseSpecMatcher](const CXXBaseSpecifier *BaseSpec,
   CXXBasePath &IgnoredParam) {
 BoundNodesTreeBuilder Result(*Builder);
-if (BaseSpecMatcher.matches(*BaseSpec, Finder, Builder)) {
+if (BaseSpecMatcher.matches(*BaseSpec, Finder, &Result)) {
   *Builder = std::move(Result);
   return true;
 }
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 89954711804aa57..d4a695b974bf0e5 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -8,6 +8,7 @@
 
 #include "ASTMatchersTest.h"
 #include "clang/AST/Attrs.inc"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
@@ -5457,6 +5458,18 @@ TEST(HasParent, NoDuplicateParents) {
 stmt().bind("node"), std::make_unique()));
 }
 
+TEST(HasAnyBase, BindsInnerBoundNodes) {
+  EXPECT_TRUE(matchAndVerifyResultTrue(
+  "struct Inner {}; struct Proxy : Inner {}; struct Main : public "
+  "Proxy {};",
+  cxxRecordDecl(hasName("Main"),
+hasAnyBase(cxxBaseSpecifier(hasType(
+cxxRecordDecl(hasName("Inner")).bind("base-class")
+  .bind("class"),
+  std::make_unique>("base-class",
+ "Inner")));
+}
+
 TEST(TypeMatching, PointeeTypes) {
   EXPECT_TRUE(matches("int b; int &a = b;",
   referenceType(pointee(builtinType();

``




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


[clang] Ensure NoTrapAfterNoreturn is false for the wasm backend (PR #65876)

2023-10-01 Thread Matt Harding via cfe-commits

https://github.com/majaha updated 
https://github.com/llvm/llvm-project/pull/65876

>From 7c43c803764bf9e0256d4e3e9f497d2622bb8f69 Mon Sep 17 00:00:00 2001
From: Matt Harding 
Date: Fri, 25 Aug 2023 06:19:14 +0100
Subject: [PATCH 01/10] Add no-trap-after-noreturn flag and wasm tests

Add the command line flag --no-trap-after-noreturn.
Add and improve tests related to WebAssembly's unreachable instruction.
Also fix various typos.
---
 llvm/include/llvm/CodeGen/MachineFunction.h   |   2 +-
 llvm/include/llvm/CodeGen/MachineInstr.h  |   2 +-
 llvm/lib/CodeGen/LLVMTargetMachine.cpp|   7 +
 .../WebAssembly/WebAssemblyCFGStackify.cpp|   2 +-
 llvm/test/CodeGen/WebAssembly/unreachable.ll  | 178 +++---
 5 files changed, 167 insertions(+), 24 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h 
b/llvm/include/llvm/CodeGen/MachineFunction.h
index 6c2da626ea54b4d..8f1651c2958e591 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -266,7 +266,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
   // RegInfo - Information about each register in use in the function.
   MachineRegisterInfo *RegInfo;
 
-  // Used to keep track of target-specific per-machine function information for
+  // Used to keep track of target-specific per-machine-function information for
   // the target implementation.
   MachineFunctionInfo *MFInfo;
 
diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h 
b/llvm/include/llvm/CodeGen/MachineInstr.h
index 03fb15f77c65cbb..8367f999fcc76d3 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -1276,7 +1276,7 @@ class MachineInstr
   /// eraseFromBundle() to erase individual bundled instructions.
   void eraseFromParent();
 
-  /// Unlink 'this' form its basic block and delete it.
+  /// Unlink 'this' from its basic block and delete it.
   ///
   /// If the instruction is part of a bundle, the other instructions in the
   /// bundle remain bundled.
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp 
b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index d02ec1db1165d41..aadc3709b85bfb7 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -37,6 +37,11 @@ static cl::opt
 EnableTrapUnreachable("trap-unreachable", cl::Hidden,
   cl::desc("Enable generating trap for unreachable"));
 
+static cl::opt
+EnableNoTrapAfterNoreturn("no-trap-after-noreturn", cl::Hidden,
+  cl::desc("Do not emit a trap instruction for 
'unreachable' IR instructions "
+  "after noreturn calls, even if 
--trap-unreachable is set."));
+
 void LLVMTargetMachine::initAsmInfo() {
   MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str()));
   assert(MRI && "Unable to create reg info");
@@ -95,6 +100,8 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
 
   if (EnableTrapUnreachable)
 this->Options.TrapUnreachable = true;
+  if (EnableNoTrapAfterNoreturn)
+this->Options.NoTrapAfterNoreturn = true;
 }
 
 TargetTransformInfo
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
index 131e99c66fa2e5a..d8cbddf74545da6 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
@@ -667,7 +667,7 @@ void 
WebAssemblyCFGStackify::removeUnnecessaryInstrs(MachineFunction &MF) {
 
   // When there is an unconditional branch right before a catch instruction and
   // it branches to the end of end_try marker, we don't need the branch, 
because
-  // it there is no exception, the control flow transfers to that point anyway.
+  // if there is no exception, the control flow transfers to that point anyway.
   // bb0:
   //   try
   // ...
diff --git a/llvm/test/CodeGen/WebAssembly/unreachable.ll 
b/llvm/test/CodeGen/WebAssembly/unreachable.ll
index ad1c90090ac58bf..1bac30b842e1e05 100644
--- a/llvm/test/CodeGen/WebAssembly/unreachable.ll
+++ b/llvm/test/CodeGen/WebAssembly/unreachable.ll
@@ -1,33 +1,169 @@
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck %s
-; RUN: llc < %s -asm-verbose=false -fast-isel -fast-isel-abort=1 
-verify-machineinstrs | FileCheck %s
-
-; Test that LLVM unreachable instruction and trap intrinsic are lowered to
-; wasm unreachable
+; RUN: llc < %s -verify-machineinstrs | FileCheck %s --check-prefixes 
CHECK,NORMAL
+; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs | 
FileCheck %s --check-prefixes CHECK,NORMAL
+; RUN: llc < %s -verify-machineinstrs --trap-unreachable | FileCheck %s 
--check-prefixes CHECK,NORMAL
+; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs 
--trap-unreachable | FileCheck %s --check-prefixes CHECK,NORMAL
+; RUN: llc < %s -verify-machineinstrs --trap-unreachable 
--no-trap-after-noreturn | FileCheck %s --check-p

[clang-tools-extra] Ensure NoTrapAfterNoreturn is false for the wasm backend (PR #65876)

2023-10-01 Thread Matt Harding via cfe-commits

https://github.com/majaha updated 
https://github.com/llvm/llvm-project/pull/65876

>From 7c43c803764bf9e0256d4e3e9f497d2622bb8f69 Mon Sep 17 00:00:00 2001
From: Matt Harding 
Date: Fri, 25 Aug 2023 06:19:14 +0100
Subject: [PATCH 01/10] Add no-trap-after-noreturn flag and wasm tests

Add the command line flag --no-trap-after-noreturn.
Add and improve tests related to WebAssembly's unreachable instruction.
Also fix various typos.
---
 llvm/include/llvm/CodeGen/MachineFunction.h   |   2 +-
 llvm/include/llvm/CodeGen/MachineInstr.h  |   2 +-
 llvm/lib/CodeGen/LLVMTargetMachine.cpp|   7 +
 .../WebAssembly/WebAssemblyCFGStackify.cpp|   2 +-
 llvm/test/CodeGen/WebAssembly/unreachable.ll  | 178 +++---
 5 files changed, 167 insertions(+), 24 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h 
b/llvm/include/llvm/CodeGen/MachineFunction.h
index 6c2da626ea54b4d..8f1651c2958e591 100644
--- a/llvm/include/llvm/CodeGen/MachineFunction.h
+++ b/llvm/include/llvm/CodeGen/MachineFunction.h
@@ -266,7 +266,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction {
   // RegInfo - Information about each register in use in the function.
   MachineRegisterInfo *RegInfo;
 
-  // Used to keep track of target-specific per-machine function information for
+  // Used to keep track of target-specific per-machine-function information for
   // the target implementation.
   MachineFunctionInfo *MFInfo;
 
diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h 
b/llvm/include/llvm/CodeGen/MachineInstr.h
index 03fb15f77c65cbb..8367f999fcc76d3 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -1276,7 +1276,7 @@ class MachineInstr
   /// eraseFromBundle() to erase individual bundled instructions.
   void eraseFromParent();
 
-  /// Unlink 'this' form its basic block and delete it.
+  /// Unlink 'this' from its basic block and delete it.
   ///
   /// If the instruction is part of a bundle, the other instructions in the
   /// bundle remain bundled.
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp 
b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index d02ec1db1165d41..aadc3709b85bfb7 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -37,6 +37,11 @@ static cl::opt
 EnableTrapUnreachable("trap-unreachable", cl::Hidden,
   cl::desc("Enable generating trap for unreachable"));
 
+static cl::opt
+EnableNoTrapAfterNoreturn("no-trap-after-noreturn", cl::Hidden,
+  cl::desc("Do not emit a trap instruction for 
'unreachable' IR instructions "
+  "after noreturn calls, even if 
--trap-unreachable is set."));
+
 void LLVMTargetMachine::initAsmInfo() {
   MRI.reset(TheTarget.createMCRegInfo(getTargetTriple().str()));
   assert(MRI && "Unable to create reg info");
@@ -95,6 +100,8 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
 
   if (EnableTrapUnreachable)
 this->Options.TrapUnreachable = true;
+  if (EnableNoTrapAfterNoreturn)
+this->Options.NoTrapAfterNoreturn = true;
 }
 
 TargetTransformInfo
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
index 131e99c66fa2e5a..d8cbddf74545da6 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
@@ -667,7 +667,7 @@ void 
WebAssemblyCFGStackify::removeUnnecessaryInstrs(MachineFunction &MF) {
 
   // When there is an unconditional branch right before a catch instruction and
   // it branches to the end of end_try marker, we don't need the branch, 
because
-  // it there is no exception, the control flow transfers to that point anyway.
+  // if there is no exception, the control flow transfers to that point anyway.
   // bb0:
   //   try
   // ...
diff --git a/llvm/test/CodeGen/WebAssembly/unreachable.ll 
b/llvm/test/CodeGen/WebAssembly/unreachable.ll
index ad1c90090ac58bf..1bac30b842e1e05 100644
--- a/llvm/test/CodeGen/WebAssembly/unreachable.ll
+++ b/llvm/test/CodeGen/WebAssembly/unreachable.ll
@@ -1,33 +1,169 @@
-; RUN: llc < %s -asm-verbose=false -verify-machineinstrs | FileCheck %s
-; RUN: llc < %s -asm-verbose=false -fast-isel -fast-isel-abort=1 
-verify-machineinstrs | FileCheck %s
-
-; Test that LLVM unreachable instruction and trap intrinsic are lowered to
-; wasm unreachable
+; RUN: llc < %s -verify-machineinstrs | FileCheck %s --check-prefixes 
CHECK,NORMAL
+; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs | 
FileCheck %s --check-prefixes CHECK,NORMAL
+; RUN: llc < %s -verify-machineinstrs --trap-unreachable | FileCheck %s 
--check-prefixes CHECK,NORMAL
+; RUN: llc < %s -fast-isel -fast-isel-abort=1 -verify-machineinstrs 
--trap-unreachable | FileCheck %s --check-prefixes CHECK,NORMAL
+; RUN: llc < %s -verify-machineinstrs --trap-unreachable 
--no-trap-after-noreturn | FileCheck %s --check-p

[clang-tools-extra] [mlir][affine] Check the input vector sizes to be greater than 0 (PR #65293)

2023-10-01 Thread Kai Sasaki via cfe-commits

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


[clang] [mlir][affine] Check the input vector sizes to be greater than 0 (PR #65293)

2023-10-01 Thread Kai Sasaki via cfe-commits

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


[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-01 Thread via cfe-commits

https://github.com/kasuga-fj updated 
https://github.com/llvm/llvm-project/pull/65246

>From cc6f7f7cb125f544de708830b3a9c0f39745ed1f Mon Sep 17 00:00:00 2001
From: "kasuga.ryotaro" 
Date: Wed, 30 Aug 2023 13:26:31 +0900
Subject: [PATCH 1/9] [Clang] Fix missing diagnostic for non-standard layout
 type in `offsetof`

Fixes #64619

Clang warns diagnostic for non-standard layout types in `offsetof` only
if they are in evaluated context. With this patch, you'll also get
  diagnostic if you use `offsetof` on non-standard layout types in any
  other contexts
---
 clang/lib/Sema/SemaExpr.cpp |  9 -
 clang/test/SemaCXX/class-layout.cpp | 30 ++---
 clang/test/SemaCXX/ms_struct.cpp|  5 ++---
 clang/test/SemaCXX/offsetof.cpp | 10 +-
 4 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 92496b03ecabe54..6537b085aa46c5b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16766,12 +16766,11 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation 
BuiltinLoc,
 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
 : diag::ext_offsetof_non_pod_type;
 
-  if (!IsSafe && !DidWarnAboutNonPOD &&
-  DiagRuntimeBehavior(BuiltinLoc, nullptr,
-  PDiag(DiagID)
-  << SourceRange(Components[0].LocStart, OC.LocEnd)
-  << CurrentType))
+  if (!IsSafe && !DidWarnAboutNonPOD) {
+Diag(BuiltinLoc, DiagID)
+<< SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType;
 DidWarnAboutNonPOD = true;
+  }
 }
 
 // Look for the field.
diff --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index 9782ff08100b2d6..23b3dbe24249378 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,18 +1,18 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-invalid-offsetof -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat=6

[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-01 Thread via cfe-commits

https://github.com/kasuga-fj updated 
https://github.com/llvm/llvm-project/pull/65246

>From 7d59f47b9b18ee5db90bb9fd69a1f73f68569ae4 Mon Sep 17 00:00:00 2001
From: "kasuga.ryotaro" 
Date: Wed, 30 Aug 2023 13:26:31 +0900
Subject: [PATCH 1/9] [Clang] Fix missing diagnostic for non-standard layout
 type in `offsetof`

Fixes #64619

Clang warns diagnostic for non-standard layout types in `offsetof` only
if they are in evaluated context. With this patch, you'll also get
  diagnostic if you use `offsetof` on non-standard layout types in any
  other contexts
---
 clang/lib/Sema/SemaExpr.cpp |  9 -
 clang/test/SemaCXX/class-layout.cpp | 30 ++---
 clang/test/SemaCXX/ms_struct.cpp|  5 ++---
 clang/test/SemaCXX/offsetof.cpp | 10 +-
 4 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 92496b03ecabe54..6537b085aa46c5b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16766,12 +16766,11 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation 
BuiltinLoc,
 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
 : diag::ext_offsetof_non_pod_type;
 
-  if (!IsSafe && !DidWarnAboutNonPOD &&
-  DiagRuntimeBehavior(BuiltinLoc, nullptr,
-  PDiag(DiagID)
-  << SourceRange(Components[0].LocStart, OC.LocEnd)
-  << CurrentType))
+  if (!IsSafe && !DidWarnAboutNonPOD) {
+Diag(BuiltinLoc, DiagID)
+<< SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType;
 DidWarnAboutNonPOD = true;
+  }
 }
 
 // Look for the field.
diff --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index 9782ff08100b2d6..23b3dbe24249378 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,18 +1,18 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-invalid-offsetof -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat=6

[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-01 Thread via cfe-commits

https://github.com/kasuga-fj updated 
https://github.com/llvm/llvm-project/pull/65246

>From 7d59f47b9b18ee5db90bb9fd69a1f73f68569ae4 Mon Sep 17 00:00:00 2001
From: "kasuga.ryotaro" 
Date: Wed, 30 Aug 2023 13:26:31 +0900
Subject: [PATCH 01/10] [Clang] Fix missing diagnostic for non-standard layout
 type in `offsetof`

Fixes #64619

Clang warns diagnostic for non-standard layout types in `offsetof` only
if they are in evaluated context. With this patch, you'll also get
  diagnostic if you use `offsetof` on non-standard layout types in any
  other contexts
---
 clang/lib/Sema/SemaExpr.cpp |  9 -
 clang/test/SemaCXX/class-layout.cpp | 30 ++---
 clang/test/SemaCXX/ms_struct.cpp|  5 ++---
 clang/test/SemaCXX/offsetof.cpp | 10 +-
 4 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 92496b03ecabe54..6537b085aa46c5b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16766,12 +16766,11 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation 
BuiltinLoc,
 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
 : diag::ext_offsetof_non_pod_type;
 
-  if (!IsSafe && !DidWarnAboutNonPOD &&
-  DiagRuntimeBehavior(BuiltinLoc, nullptr,
-  PDiag(DiagID)
-  << SourceRange(Components[0].LocStart, OC.LocEnd)
-  << CurrentType))
+  if (!IsSafe && !DidWarnAboutNonPOD) {
+Diag(BuiltinLoc, DiagID)
+<< SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType;
 DidWarnAboutNonPOD = true;
+  }
 }
 
 // Look for the field.
diff --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index 9782ff08100b2d6..23b3dbe24249378 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,18 +1,18 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-invalid-offsetof -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat

[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-01 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 97829935844e7f35216e12c13231f35fbea640c3 
b9e201a80ee7e79f8ddfe37fee097b8efddc0a8a -- clang/lib/Sema/SemaExpr.cpp 
clang/test/SemaCXX/class-layout.cpp clang/test/SemaCXX/ms_struct.cpp 
clang/test/SemaCXX/offsetof.cpp libcxx/include/__type_traits/datasizeof.h
``





View the diff from clang-format here.


``diff
diff --git a/libcxx/include/__type_traits/datasizeof.h 
b/libcxx/include/__type_traits/datasizeof.h
index cfdd8cbbc..389b006b6 100644
--- a/libcxx/include/__type_traits/datasizeof.h
+++ b/libcxx/include/__type_traits/datasizeof.h
@@ -47,7 +47,8 @@ struct __libcpp_datasizeof {
   };
 #endif
 
-  // _FirstPaddingByte<> is sometimes non-standard layout. Using `offsetof` is 
UB in that case, but GCC and Clang allow the use as an extension.
+  // _FirstPaddingByte<> is sometimes non-standard layout. Using `offsetof` is 
UB in that case, but GCC and Clang allow
+  // the use as an extension.
   // TODO : Find a way to replace `offsetof` ?
   _LIBCPP_DIAGNOSTIC_PUSH
   _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-offsetof")

``




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


[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-01 Thread via cfe-commits

https://github.com/kasuga-fj updated 
https://github.com/llvm/llvm-project/pull/65246

>From 7d59f47b9b18ee5db90bb9fd69a1f73f68569ae4 Mon Sep 17 00:00:00 2001
From: "kasuga.ryotaro" 
Date: Wed, 30 Aug 2023 13:26:31 +0900
Subject: [PATCH 01/11] [Clang] Fix missing diagnostic for non-standard layout
 type in `offsetof`

Fixes #64619

Clang warns diagnostic for non-standard layout types in `offsetof` only
if they are in evaluated context. With this patch, you'll also get
  diagnostic if you use `offsetof` on non-standard layout types in any
  other contexts
---
 clang/lib/Sema/SemaExpr.cpp |  9 -
 clang/test/SemaCXX/class-layout.cpp | 30 ++---
 clang/test/SemaCXX/ms_struct.cpp|  5 ++---
 clang/test/SemaCXX/offsetof.cpp | 10 +-
 4 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 92496b03ecabe54..6537b085aa46c5b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16766,12 +16766,11 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation 
BuiltinLoc,
 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
 : diag::ext_offsetof_non_pod_type;
 
-  if (!IsSafe && !DidWarnAboutNonPOD &&
-  DiagRuntimeBehavior(BuiltinLoc, nullptr,
-  PDiag(DiagID)
-  << SourceRange(Components[0].LocStart, OC.LocEnd)
-  << CurrentType))
+  if (!IsSafe && !DidWarnAboutNonPOD) {
+Diag(BuiltinLoc, DiagID)
+<< SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType;
 DidWarnAboutNonPOD = true;
+  }
 }
 
 // Look for the field.
diff --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index 9782ff08100b2d6..23b3dbe24249378 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,18 +1,18 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-invalid-offsetof -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat

[clang] [Clang] Add __datasizeof (PR #67805)

2023-10-01 Thread Shafik Yaghmour via cfe-commits

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


[clang] [Clang] Add __datasizeof (PR #67805)

2023-10-01 Thread Shafik Yaghmour via cfe-commits


@@ -5038,19 +5039,19 @@ void CXXNameMangler::mangleExpression(const Expr *E, 
unsigned Arity,
   Out << 'a';
   MangleAlignofSizeofArg();
   break;
+case UETT_DataSizeOf: {
+  Context.getDiags().Report(diag::err_cannot_mangle_expression)
+  << "__datasizeof";
+  return;
+}
 case UETT_VecStep: {
-  DiagnosticsEngine &Diags = Context.getDiags();
-  unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
- "cannot yet mangle vec_step expression");
-  Diags.Report(DiagID);
+  Context.getDiags().Report(diag::err_cannot_mangle_expression)
+  << "vec_step";
   return;
 }
 case UETT_OpenMPRequiredSimdAlign: {
-  DiagnosticsEngine &Diags = Context.getDiags();
-  unsigned DiagID = Diags.getCustomDiagID(
-  DiagnosticsEngine::Error,
-  "cannot yet mangle __builtin_omp_required_simd_align expression");
-  Diags.Report(DiagID);
+  Context.getDiags().Report(diag::err_cannot_mangle_expression)

shafik wrote:

It looks like we have one other case we can replace as well: 
https://github.com/llvm/llvm-project/blob/97829935844e7f35216e12c13231f35fbea640c3/clang/lib/AST/ItaniumMangle.cpp#L4728

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


[clang] [Clang] Add __datasizeof (PR #67805)

2023-10-01 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Looks good but Aaron should look at it as well.

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


[clang] [Clang] Add __datasizeof (PR #67805)

2023-10-01 Thread Shafik Yaghmour via cfe-commits


@@ -0,0 +1,34 @@
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-linux-gnu -verify %s

shafik wrote:

Maybe we should add tests to show parallels with `sizeof` e.g` *void* types and 
incomplete types. 

Also w/o parens etc 

https://github.com/llvm/llvm-project/pull/67805
___
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-10-01 Thread Shafik Yaghmour via cfe-commits


@@ -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());

shafik wrote:

To be consistent with 
[bugprone-argument-comment](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html)

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


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

2023-10-01 Thread Shafik Yaghmour via cfe-commits

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


[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-10-01 Thread via cfe-commits

https://github.com/kasuga-fj updated 
https://github.com/llvm/llvm-project/pull/65246

>From 7d59f47b9b18ee5db90bb9fd69a1f73f68569ae4 Mon Sep 17 00:00:00 2001
From: "kasuga.ryotaro" 
Date: Wed, 30 Aug 2023 13:26:31 +0900
Subject: [PATCH 01/12] [Clang] Fix missing diagnostic for non-standard layout
 type in `offsetof`

Fixes #64619

Clang warns diagnostic for non-standard layout types in `offsetof` only
if they are in evaluated context. With this patch, you'll also get
  diagnostic if you use `offsetof` on non-standard layout types in any
  other contexts
---
 clang/lib/Sema/SemaExpr.cpp |  9 -
 clang/test/SemaCXX/class-layout.cpp | 30 ++---
 clang/test/SemaCXX/ms_struct.cpp|  5 ++---
 clang/test/SemaCXX/offsetof.cpp | 10 +-
 4 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 92496b03ecabe54..6537b085aa46c5b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16766,12 +16766,11 @@ ExprResult Sema::BuildBuiltinOffsetOf(SourceLocation 
BuiltinLoc,
 LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type
 : diag::ext_offsetof_non_pod_type;
 
-  if (!IsSafe && !DidWarnAboutNonPOD &&
-  DiagRuntimeBehavior(BuiltinLoc, nullptr,
-  PDiag(DiagID)
-  << SourceRange(Components[0].LocStart, OC.LocEnd)
-  << CurrentType))
+  if (!IsSafe && !DidWarnAboutNonPOD) {
+Diag(BuiltinLoc, DiagID)
+<< SourceRange(Components[0].LocStart, OC.LocEnd) << CurrentType;
 DidWarnAboutNonPOD = true;
+  }
 }
 
 // Look for the field.
diff --git a/clang/test/SemaCXX/class-layout.cpp 
b/clang/test/SemaCXX/class-layout.cpp
index 9782ff08100b2d6..23b3dbe24249378 100644
--- a/clang/test/SemaCXX/class-layout.cpp
+++ b/clang/test/SemaCXX/class-layout.cpp
@@ -1,18 +1,18 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-c++11-extensions
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base
-// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=6 -DCLANG_ABI_COMPAT=6
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=16 -DCLANG_ABI_COMPAT=16
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple powerpc64-ibm-aix7.3.0.0 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base
-// RUN: %clang_cc1 -triple s390x-none-zos %s -fsyntax-only -verify -std=c++11 
-Wno-inaccessible-base -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++98 -Wno-inaccessible-base -Wno-invalid-offsetof -Wno-c++11-extensions
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof
+// RUN: %clang_cc1 -triple x86_64-apple-darwin%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=15
+// RUN: %clang_cc1 -triple x86_64-scei-ps4%s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-sie-ps5 %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -DCLANG_ABI_COMPAT=6
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -fsyntax-only -verify 
-std=c++11 -Wno-inaccessible-base -Wno-invalid-offsetof -fclang-abi-compat

[clang] [clang][ExprConst] Fix crash on uninitialized array subobject (PR #67817)

2023-10-01 Thread Shafik Yaghmour via cfe-commits


@@ -2411,10 +2411,15 @@ static bool 
CheckEvaluationResult(CheckEvaluationResultKind CERK,
   const FieldDecl *SubobjectDecl,
   CheckedTemporaries &CheckedTemps) {
   if (!Value.hasValue()) {
-assert(SubobjectDecl && "SubobjectDecl shall be non-null");
-Info.FFDiag(DiagLoc, diag::note_constexpr_uninitialized) << SubobjectDecl;
-Info.Note(SubobjectDecl->getLocation(),
-  diag::note_constexpr_subobject_declared_here);
+if (SubobjectDecl) {

shafik wrote:

So if we look back at https://reviews.llvm.org/D146358 you used to get the 
location which could be invalid and the diagnostic that was based on that is 
now lost b/c we lost that information b/c in many cases you just pass `nullptr` 
explicitly. So Perhaps you should have been encoding that information as well 
and then understand why that is important here.

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


[clang] [clang][ExprConst] Fix crash on uninitialized array subobject (PR #67817)

2023-10-01 Thread Shafik Yaghmour via cfe-commits

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


[clang] [clang][ExprConst] Fix crash on uninitialized array subobject (PR #67817)

2023-10-01 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

I am a bit concerned we don't fully understand how to recover the old 
diagnostic. I left a comment that I think may help but I think we need to 
understand this a bit better before committing to a fix.

https://github.com/llvm/llvm-project/pull/67817
___
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-10-01 Thread David Blaikie via cfe-commits

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

Awesome - love a good readability improvement. Thanks!

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] Enable Wenum-constexpr-conversion also in system headers and … (PR #67528)

2023-10-01 Thread David Blaikie via cfe-commits
Carlos =?utf-8?q?Gálvez?= ,
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


dwblaikie wrote:

> It seems checks are broken on trunk, I see commits merged with failing 
> pre-merge tests. They seem to be unrelated to this patch though.
> 
> Is there anything else you'd like fixed before merging? @dwblaikie 
> @AaronBallman @shafik

Nothing further from me, at least. But maybe wait for approval from one of the 
other two.

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


[clang] [clang] Add test for CWG472 (PR #67948)

2023-10-01 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll created 
https://github.com/llvm/llvm-project/pull/67948

https://cplusplus.github.io/CWG/issues/472.html
It has drafting status, but I think CWG has reached consesus on the behavior.

>From ad0df2131e12c59e57b603b955626e27e3067505 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Mon, 2 Oct 2023 08:12:56 +0300
Subject: [PATCH] [clang] Add test for CWG472

---
 clang/test/CXX/drs/dr4xx.cpp | 17 +
 clang/www/cxx_dr_status.html |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp
index d8bdf49d0b2dde7..cc12e9f158061f8 100644
--- a/clang/test/CXX/drs/dr4xx.cpp
+++ b/clang/test/CXX/drs/dr4xx.cpp
@@ -924,6 +924,23 @@ namespace dr471 { // dr471: yes
   struct H : B, G { int f() { return n; } }; // expected-error {{private}}
 }
 
+namespace dr472 { // dr472: no drafting
+struct B {
+  int i; // #dr472-i-decl
+};
+struct I : protected B {}; // #dr472-inheritance
+struct D : public I {
+  void f(I *ip) {
+ip->i = 0;
+// expected-error@-1{{'i' is a protected member of 
'dr472::B'}}
+// expected-note@#dr472-inheritance {{constrained by protected inheritance 
here}}
+// expected-note@#dr472-i-decl  {{member is declared here}}
+B *bp = ip;
+bp->i = 5;
+  }
+};
+}
+
 namespace dr474 { // dr474: yes
   namespace N {
 struct S {
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index ee9712e9bab9949..b02f7ccfd371411 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -2871,7 +2871,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/472.html";>472
 drafting
 Casting across protected inheritance
-Not resolved
+No
   
   
 https://cplusplus.github.io/CWG/issues/473.html";>473

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


[clang] [clang] Add test for CWG472 (PR #67948)

2023-10-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

https://cplusplus.github.io/CWG/issues/472.html
It has drafting status, but I think CWG has reached consesus on the behavior.

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


2 Files Affected:

- (modified) clang/test/CXX/drs/dr4xx.cpp (+17) 
- (modified) clang/www/cxx_dr_status.html (+1-1) 


``diff
diff --git a/clang/test/CXX/drs/dr4xx.cpp b/clang/test/CXX/drs/dr4xx.cpp
index d8bdf49d0b2dde7..cc12e9f158061f8 100644
--- a/clang/test/CXX/drs/dr4xx.cpp
+++ b/clang/test/CXX/drs/dr4xx.cpp
@@ -924,6 +924,23 @@ namespace dr471 { // dr471: yes
   struct H : B, G { int f() { return n; } }; // expected-error {{private}}
 }
 
+namespace dr472 { // dr472: no drafting
+struct B {
+  int i; // #dr472-i-decl
+};
+struct I : protected B {}; // #dr472-inheritance
+struct D : public I {
+  void f(I *ip) {
+ip->i = 0;
+// expected-error@-1{{'i' is a protected member of 
'dr472::B'}}
+// expected-note@#dr472-inheritance {{constrained by protected inheritance 
here}}
+// expected-note@#dr472-i-decl  {{member is declared here}}
+B *bp = ip;
+bp->i = 5;
+  }
+};
+}
+
 namespace dr474 { // dr474: yes
   namespace N {
 struct S {
diff --git a/clang/www/cxx_dr_status.html b/clang/www/cxx_dr_status.html
index ee9712e9bab9949..b02f7ccfd371411 100755
--- a/clang/www/cxx_dr_status.html
+++ b/clang/www/cxx_dr_status.html
@@ -2871,7 +2871,7 @@ C++ defect report implementation 
status
 https://cplusplus.github.io/CWG/issues/472.html";>472
 drafting
 Casting across protected inheritance
-Not resolved
+No
   
   
 https://cplusplus.github.io/CWG/issues/473.html";>473

``




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


[clang] [clang] Add test for CWG2267 (PR #67931)

2023-10-01 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [clang] Add test for CWG472 (PR #67948)

2023-10-01 Thread Vlad Serebrennikov via cfe-commits

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


[clang] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-10-01 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 5a2c930770cf548c5e3f3451e76b48cb067e6762 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/5] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   3 +
 6 files changed, 460 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..b096259f85f6ac8 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 000..16de6c29cb2a1a4
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if cons

[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-10-01 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/66963

>From 5a2c930770cf548c5e3f3451e76b48cb067e6762 Mon Sep 17 00:00:00 2001
From: Zijun Zhao 
Date: Wed, 13 Sep 2023 14:26:01 -0700
Subject: [PATCH 1/5] [libc++] Implement ranges::contains_subrange

---
 libcxx/include/CMakeLists.txt |   1 +
 .../__algorithm/ranges_contains_subrange.h| 145 +
 libcxx/include/algorithm  |  14 +
 ...obust_against_copying_projections.pass.cpp |   4 +
 .../ranges.contains_subrange.pass.cpp | 293 ++
 .../niebloid.compile.pass.cpp |   3 +
 6 files changed, 460 insertions(+)
 create mode 100644 libcxx/include/__algorithm/ranges_contains_subrange.h
 create mode 100644 
libcxx/test/std/algorithms/alg.nonmodifying/alg.contains/ranges.contains_subrange.pass.cpp

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index 2ec755236dbaee2..b096259f85f6ac8 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -104,6 +104,7 @@ set(files
   __algorithm/ranges_any_of.h
   __algorithm/ranges_binary_search.h
   __algorithm/ranges_clamp.h
+  __algorithm/ranges_contains_subrange.h
   __algorithm/ranges_copy.h
   __algorithm/ranges_copy_backward.h
   __algorithm/ranges_copy_if.h
diff --git a/libcxx/include/__algorithm/ranges_contains_subrange.h 
b/libcxx/include/__algorithm/ranges_contains_subrange.h
new file mode 100644
index 000..16de6c29cb2a1a4
--- /dev/null
+++ b/libcxx/include/__algorithm/ranges_contains_subrange.h
@@ -0,0 +1,145 @@
+//===--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_SUBRANGE_H
+
+#include <__algorithm/ranges_starts_with.h>
+#include <__config>
+#include <__functional/identity.h>
+#include <__functional/ranges_operations.h>
+#include <__functional/reference_wrapper.h>
+#include <__iterator/concepts.h>
+#include <__iterator/distance.h>
+#include <__iterator/indirectly_comparable.h>
+#include <__iterator/projected.h>
+#include <__ranges/access.h>
+#include <__ranges/concepts.h>
+#include <__utility/move.h>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+#if _LIBCPP_STD_VER >= 23
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace ranges {
+namespace __contains_subrange {
+struct __fn {
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred,
+class _Proj1,
+class _Proj2,
+class _Offset>
+  static _LIBCPP_HIDE_FROM_ABI constexpr bool __contains_subrange_fn_impl(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred& __pred,
+  _Proj1& __proj1,
+  _Proj2& __proj2,
+  _Offset __offset) {
+if (__offset < 0)
+  return false;
+else {
+  for (; __offset >= 0; __offset--, __first1++) {
+auto result = ranges::starts_with(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+std::ref(__pred),
+std::ref(__proj1),
+std::ref(__proj2));
+if (result)
+  return true;
+  }
+  return false;
+}
+  }
+
+  template  _Sent1,
+input_iterator _Iter2,
+sentinel_for<_Iter2> _Sent2,
+class _Pred  = ranges::equal_to,
+class _Proj1 = identity,
+class _Proj2 = identity>
+requires indirectly_comparable<_Iter1, _Iter2, _Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Iter1 __first1,
+  _Sent1 __last1,
+  _Iter2 __first2,
+  _Sent2 __last2,
+  _Pred __pred   = {},
+  _Proj1 __proj1 = {},
+  _Proj2 __proj2 = {}) const {
+auto __n1 = ranges::distance(__first1, __last1);
+auto __n2 = ranges::distance(__first2, __last2);
+auto __offset = __n1 - __n2;
+
+return __contains_subrange_fn_impl(
+std::move(__first1),
+std::move(__last1),
+std::move(__first2),
+std::move(__last2),
+__pred,
+__proj1,
+__proj2,
+std::move(__offset));
+  }
+
+  template 
+requires indirectly_comparable, iterator_t<_Range2>, 
_Pred, _Proj1, _Proj2>
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(
+  _Range1&& __range1, _Range2&& __range2, _Pred __pred = {}, _Proj1 
__proj1 = {}, _Proj2 __proj2 = {}) const {
+auto __n1 = 0;
+auto __n2 = 0;
+
+if cons

[clang] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-10-01 Thread via cfe-commits

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


[clang-tools-extra] [libc++] Implement ranges::contains_subrange (PR #66963)

2023-10-01 Thread via cfe-commits

https://github.com/ZijunZhaoCCK converted_to_draft 
https://github.com/llvm/llvm-project/pull/66963
___
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-10-01 Thread via cfe-commits

agozillon wrote:

Thank you all very much, I'll land this on Tuesday afternoon/evening provided 
no one has anything else to add in the time between. And I'll see what I can do 
about adding an OpenMPIRBuilderTest.cpp to the patch. 

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][RISCV] Remove duplicate functions isRVVSizelessBuiltinType. NFC (PR #67089)

2023-10-01 Thread Yueh-Ting Chen via cfe-commits

eopXD wrote:

Ping.

https://github.com/llvm/llvm-project/pull/67089
___
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-10-01 Thread Tobias Hieta via cfe-commits

tru wrote:

Did you plan to backport this as well @mstorsjo ?

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] dcb946a - [clang][Interp] Try to fix a build failure on Windows

2023-10-01 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2023-10-02T08:09:49+02:00
New Revision: dcb946a175ae98d432b0a6f8d92105afc992db3e

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

LOG: [clang][Interp] Try to fix a build failure on Windows

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 53ad76d8a1997eb..b2b367f30c238fe 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -39,7 +39,9 @@ template  class IntegralAP final {
   using AsUnsigned = IntegralAP;
 
   template 
-  IntegralAP(T Value) : V(APInt(sizeof(T) * 8, Value, std::is_signed_v)) {}
+  IntegralAP(T Value)
+  : V(APInt(sizeof(T) * 8, static_cast(Value),
+std::is_signed_v)) {}
 
   IntegralAP(APInt V) : V(V) {}
   IntegralAP(APSInt V) : V(V) {}



___
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-10-01 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

In D155610#4652198 , @cor3ntin wrote:

> @hazohelet Please keep this patch on Phab. It's not going to be shutdown. The 
> current consensus is that we will reconsider shutting down phab on November 15
> https://discourse.llvm.org/t/update-on-github-pull-requests/71540/125

Oh I failed to notice that post, thanks for letting me know.


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] [clang][Interp] Add IntegralAP for arbitrary-precision integers (PR #65844)

2023-10-01 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= ,
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

I pushed a fix that hopefully works, let me know if it doesn't.

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


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

2023-10-01 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet updated this revision to Diff 557524.
hazohelet added a comment.

Address comments from Corentin


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

https://reviews.llvm.org/D155610

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Diagnostic.h
  clang/lib/Basic/Diagnostic.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/test/Lexer/cxx1z-trigraphs.cpp
  clang/test/SemaCXX/static-assert-cxx26.cpp
  clang/test/SemaCXX/static-assert.cpp

Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -268,7 +268,31 @@
 return 'c';
   }
   static_assert(getChar() == 'a', ""); // expected-error {{failed}} \
-   // expected-note {{evaluates to ''c' == 'a''}}
+   // expected-note {{evaluates to ''c' (0x63, 99) == 'a' (0x61, 97)'}}
+  static_assert((char)9 == '\x61', ""); // expected-error {{failed}} \
+// expected-note {{evaluates to ''\t' (0x09, 9) == 'a' (0x61, 97)'}}
+  static_assert((char)10 == '\0', ""); // expected-error {{failed}} \
+   // expected-note {{n' (0x0A, 10) == '' (0x00, 0)'}}
+  // The note above is intended to match "evaluates to '\n' (0x0A, 10) == '' (0x00, 0)'", but if we write it as it is,
+  // the "\n" cannot be consumed by the diagnostic consumer.
+  static_assert((signed char)10 == (char)-123, ""); // expected-error {{failed}} \
+// expected-note {{evaluates to '10 == '<85>' (0x85, -123)'}}
+  static_assert((char)-4 == (unsigned char)-8, ""); // expected-error {{failed}} \
+// expected-note {{evaluates to ''' (0xFC, -4) == 248'}}
+  static_assert((char)-128 == (char)-123, ""); // expected-error {{failed}} \
+   // expected-note {{evaluates to ''<80>' (0x80, -128) == '<85>' (0x85, -123)'}}
+  static_assert('\xA0' == (char)'\x20', ""); // expected-error {{failed}} \
+ // expected-note {{evaluates to ''' (0xA0, -96) == ' ' (0x20, 32)'}}
+  static_assert((char16_t)L'ゆ' == L"C̵̭̯̠̎͌ͅť̺"[1], ""); // expected-error {{failed}} \
+  // expected-note {{evaluates to 'u'ゆ' (0x3086, 12422) == L'̵' (0x335, 821)'}}
+  static_assert(L"\/"[1] == u'\xFFFD', ""); // expected-error {{failed}} \
+  // expected-note {{evaluates to 'L'/' (0xFF0F, 65295) == u'�' (0xFFFD, 65533)'}}
+  static_assert(L"⚾"[0] == U'🌍', ""); // expected-error {{failed}} \
+ // expected-note {{evaluates to 'L'⚾' (0x26BE, 9918) == U'🌍' (0x1F30D, 127757)'}}
+  static_assert(U"\a"[0] == (wchar_t)9, ""); // expected-error {{failed}} \
+ // expected-note {{evaluates to 'U'\a' (0x07, 7) == L'\t' (0x09, 9)'}}
+  static_assert(L"§"[0] == U'Ö', ""); // expected-error {{failed}} \
+  // expected-note {{evaluates to 'L'§' (0xA7, 167) == U'Ö' (0xD6, 214)'}}
 
   /// Bools are printed as bools.
   constexpr bool invert(bool b) {
Index: clang/test/SemaCXX/static-assert-cxx26.cpp
===
--- clang/test/SemaCXX/static-assert-cxx26.cpp
+++ clang/test/SemaCXX/static-assert-cxx26.cpp
@@ -298,3 +298,12 @@
 Bad b; // expected-note {{in instantiation}}
 
 }
+
+namespace EscapeInDiagnostic {
+static_assert('\u{9}' == (char)1, ""); // expected-error {{failed}} \
+   // expected-note {{evaluates to ''\t' (0x09, 9) == '' (0x01, 1)'}}
+static_assert((char8_t)-128 == (char8_t)-123, ""); // expected-error {{failed}} \
+   // expected-note {{evaluates to 'u8'<80>' (0x80, 128) == u8'<85>' (0x85, 133)'}}
+static_assert((char16_t)0xFEFF == (char16_t)0xDB93, ""); // expected-error {{failed}} \
+ // expected-note {{evaluates to 'u'' (0xFEFF, 65279) == u'\xDB93' (0xDB93, 56211)'}}
+}
Index: clang/test/Lexer/cxx1z-trigraphs.cpp
===
--- clang/test/Lexer/cxx1z-trigraphs.cpp
+++ clang/test/Lexer/cxx1z-trigraphs.cpp
@@ -21,7 +21,7 @@
 
 #if !ENABLED_TRIGRAPHS
 // expected-error@11 {{}} expected-warning@11 {{trigraph ignored}}
-// expected-error@13 {{failed}} expected-warning@13 {{trigraph ignored}} expected-note@13 {{evaluates to ''?' == '#''}}
+// expected-error@13 {{failed}} expected-warning@13 {{trigraph ignored}} expected-note@13 {{evaluates to ''?' (0x3F, 63) == '#' (0x23, 35)'}}
 // expected-error@16 {{}}
 // expected-error@20 {{}}
 #else
Index: clang/lib/S

[clang] [clang][Interp] Implement IntegralAP::comp (PR #67954)

2023-10-01 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/67954

None

>From fe7f8cddb7f4590f481fce3b99c7b56f8163d889 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 1 Oct 2023 19:57:03 +0200
Subject: [PATCH] [clang][Interp] Implement IntegralAP::comp

---
 clang/lib/AST/Interp/IntegralAP.h  | 1 -
 clang/test/AST/Interp/literals.cpp | 3 +++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index b2b367f30c238fe..b29aac2a73e3243 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -210,7 +210,6 @@ template  class IntegralAP final {
   }
 
   static bool comp(IntegralAP A, IntegralAP *R) {
-assert(false);
 *R = IntegralAP(~A.V);
 return false;
   }
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index b57a0e64c5fac32..864c91dd0003b9e 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -87,6 +87,9 @@ constexpr int128_t Error = __LDBL_MAX__; // ref-warning 
{{implicit conversion of
  // expected-warning {{implicit 
conversion of out of range value}} \
  // expected-error {{must be 
initialized by a constant expression}} \
  // expected-note {{is outside the 
range of representable values of type}}
+
+  constexpr uint128_t UINT128_MAX = ~static_cast(0);
+  static_assert(UINT128_MAX == static_cast(-1), "");
 }
 #endif
 

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


[clang] [clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (PR #67955)

2023-10-01 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/67955

After annotating constructors/destructors as FunctionDeclarationName in commit 
08630512088, we have seen several issues because ctors/dtors had been treated 
differently than functions in aligning, wrapping, and indenting.

This patch annotates ctors/dtors as CtorDtorDeclName instead and would 
effectively revert commit 0468fa07f87f, which is obsolete now.

Fixed #67903.
Fixed #67907.

>From 62b4e7b5def02f09580d5308f4dc77c475e423bd Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Sun, 1 Oct 2023 23:01:30 -0700
Subject: [PATCH] [clang-format] Annotate ctors/dtors as CtorDtorDeclName
 instead

After annotating constructors/destructors as FunctionDeclarationName in
commit 08630512088, we have seen several issues because ctors/dtors had been
treated differently than functions in aligning, wrapping, and indenting.

This patch annotates ctors/dtors as CtorDtorDeclName instead and would
effectively revert commit 0468fa07f87f, which is obsolete now.

Fixed #67903.
Fixed #67907.
---
 clang/lib/Format/FormatToken.h|  1 +
 clang/lib/Format/TokenAnnotator.cpp   | 17 +++---
 clang/lib/Format/WhitespaceManager.cpp|  6 +--
 clang/unittests/Format/FormatTest.cpp | 10 +++-
 .../Format/FormatTestMacroExpansion.cpp   |  8 +--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 54 +++
 6 files changed, 55 insertions(+), 41 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index dbd3a6e70f037ef..5877b0a6124742a 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -61,6 +61,7 @@ namespace format {
   TYPE(CSharpStringLiteral)
\
   TYPE(CtorInitializerColon)   
\
   TYPE(CtorInitializerComma)   
\
+  TYPE(CtorDtorDeclName)   
\
   TYPE(DesignatedInitializerLSquare)   
\
   TYPE(DesignatedInitializerPeriod)
\
   TYPE(DictLiteral)
\
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index ae2cbbdce934618..dfb059ac8464ed2 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3211,9 +3211,6 @@ static bool isCtorOrDtorName(const FormatToken *Tok) {
 }
 
 void TokenAnnotator::annotate(AnnotatedLine &Line) {
-  for (auto &Child : Line.Children)
-annotate(*Child);
-
   AnnotatingParser Parser(Style, Line, Keywords, Scopes);
   Line.Type = Parser.parseLine();
 
@@ -3234,7 +3231,7 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
 auto *Tok = getFunctionName(Line);
 if (Tok && ((!Scopes.empty() && Scopes.back() == ST_Class) ||
 Line.endsWith(TT_FunctionLBrace) || isCtorOrDtorName(Tok))) {
-  Tok->setFinalizedType(TT_FunctionDeclarationName);
+  Tok->setFinalizedType(TT_CtorDtorDeclName);
 }
   }
 
@@ -3247,6 +3244,9 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
 
   Line.First->SpacesRequiredBefore = 1;
   Line.First->CanBreakBefore = Line.First->MustBreakBefore;
+
+  for (auto &Child : Line.Children)
+annotate(*Child);
 }
 
 // This function heuristically determines whether 'Current' starts the name of 
a
@@ -3446,9 +3446,12 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
Tok = Tok->Next) {
 if (Tok->Previous->EndsCppAttributeGroup)
   AfterLastAttribute = Tok;
-if (isFunctionDeclarationName(Style.isCpp(), *Tok, Line)) {
-  LineIsFunctionDeclaration = true;
-  Tok->setFinalizedType(TT_FunctionDeclarationName);
+if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
+IsCtorOrDtor || isFunctionDeclarationName(Style.isCpp(), *Tok, Line)) {
+  if (!IsCtorOrDtor) {
+LineIsFunctionDeclaration = true;
+Tok->setFinalizedType(TT_FunctionDeclarationName);
+  }
   if (AfterLastAttribute &&
   mustBreakAfterAttributes(*AfterLastAttribute, Style)) {
 AfterLastAttribute->MustBreakBefore = true;
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 762729d1c4166a5..1790a9df42b5d14 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -974,11 +974,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
   AlignTokens(
   Style,
   [](Change const &C) {
-if (C.Tok->is(TT_FunctionDeclarationName) && C.Tok->Previous &&
-C.Tok->Previous->isNot(tok::tilde)) {
-  return true;
-}
-if (C.Tok->is(TT_FunctionTypeLParen))
+if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
   

[clang] [clang-format] Annotate ctors/dtors as CtorDtorDeclName instead (PR #67955)

2023-10-01 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format


Changes

After annotating constructors/destructors as FunctionDeclarationName in commit 
08630512088, we have seen several issues because ctors/dtors had been treated 
differently than functions in aligning, wrapping, and indenting.

This patch annotates ctors/dtors as CtorDtorDeclName instead and would 
effectively revert commit 0468fa07f87f, which is obsolete now.

Fixed #67903.
Fixed #67907.

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


6 Files Affected:

- (modified) clang/lib/Format/FormatToken.h (+1) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+10-7) 
- (modified) clang/lib/Format/WhitespaceManager.cpp (+1-5) 
- (modified) clang/unittests/Format/FormatTest.cpp (+8-2) 
- (modified) clang/unittests/Format/FormatTestMacroExpansion.cpp (+2-6) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+33-21) 


``diff
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index dbd3a6e70f037ef..5877b0a6124742a 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -61,6 +61,7 @@ namespace format {
   TYPE(CSharpStringLiteral)
\
   TYPE(CtorInitializerColon)   
\
   TYPE(CtorInitializerComma)   
\
+  TYPE(CtorDtorDeclName)   
\
   TYPE(DesignatedInitializerLSquare)   
\
   TYPE(DesignatedInitializerPeriod)
\
   TYPE(DictLiteral)
\
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index ae2cbbdce934618..dfb059ac8464ed2 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3211,9 +3211,6 @@ static bool isCtorOrDtorName(const FormatToken *Tok) {
 }
 
 void TokenAnnotator::annotate(AnnotatedLine &Line) {
-  for (auto &Child : Line.Children)
-annotate(*Child);
-
   AnnotatingParser Parser(Style, Line, Keywords, Scopes);
   Line.Type = Parser.parseLine();
 
@@ -3234,7 +3231,7 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
 auto *Tok = getFunctionName(Line);
 if (Tok && ((!Scopes.empty() && Scopes.back() == ST_Class) ||
 Line.endsWith(TT_FunctionLBrace) || isCtorOrDtorName(Tok))) {
-  Tok->setFinalizedType(TT_FunctionDeclarationName);
+  Tok->setFinalizedType(TT_CtorDtorDeclName);
 }
   }
 
@@ -3247,6 +3244,9 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
 
   Line.First->SpacesRequiredBefore = 1;
   Line.First->CanBreakBefore = Line.First->MustBreakBefore;
+
+  for (auto &Child : Line.Children)
+annotate(*Child);
 }
 
 // This function heuristically determines whether 'Current' starts the name of 
a
@@ -3446,9 +3446,12 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
Tok = Tok->Next) {
 if (Tok->Previous->EndsCppAttributeGroup)
   AfterLastAttribute = Tok;
-if (isFunctionDeclarationName(Style.isCpp(), *Tok, Line)) {
-  LineIsFunctionDeclaration = true;
-  Tok->setFinalizedType(TT_FunctionDeclarationName);
+if (const bool IsCtorOrDtor = Tok->is(TT_CtorDtorDeclName);
+IsCtorOrDtor || isFunctionDeclarationName(Style.isCpp(), *Tok, Line)) {
+  if (!IsCtorOrDtor) {
+LineIsFunctionDeclaration = true;
+Tok->setFinalizedType(TT_FunctionDeclarationName);
+  }
   if (AfterLastAttribute &&
   mustBreakAfterAttributes(*AfterLastAttribute, Style)) {
 AfterLastAttribute->MustBreakBefore = true;
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index 762729d1c4166a5..1790a9df42b5d14 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -974,11 +974,7 @@ void WhitespaceManager::alignConsecutiveDeclarations() {
   AlignTokens(
   Style,
   [](Change const &C) {
-if (C.Tok->is(TT_FunctionDeclarationName) && C.Tok->Previous &&
-C.Tok->Previous->isNot(tok::tilde)) {
-  return true;
-}
-if (C.Tok->is(TT_FunctionTypeLParen))
+if (C.Tok->isOneOf(TT_FunctionDeclarationName, TT_FunctionTypeLParen))
   return true;
 if (C.Tok->isNot(TT_StartOfName))
   return false;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 0403de8a9a65594..0ab57398a6cc319 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10622,6 +10622,12 @@ TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {
   verifyFormat("a::\n"
"a\n"
".