[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

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

https://github.com/zygoloid dismissed 
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] [clang][driver] Add avr-libc's default linker script to lld (PR #68507)

2023-10-10 Thread Jianjian Guan via cfe-commits

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

LGTM

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


[clang] [clang][C2x] Remove confusing diagnostic auto storage class specifier (PR #68710)

2023-10-10 Thread Guillot Tony via cfe-commits

to268 wrote:

Can you land this patch on my behalf?
"Guillot Tony "

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


[clang] [clang][RISCV] Fix the condition of checking signature in getIndex (PR #67403)

2023-10-10 Thread Jianjian Guan via cfe-commits

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


[clang] bccf2c8 - [clang][RISCV] Fix the condition of checking signature in getIndex (#67403)

2023-10-10 Thread via cfe-commits

Author: Jianjian Guan
Date: 2023-10-11T14:55:52+08:00
New Revision: bccf2c8468e2f364f8c364d613ffb78d61b67ceb

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

LOG: [clang][RISCV] Fix the condition of checking signature in getIndex (#67403)

The current condition causes assert failing if try to add a new vendor
vector file which only contains the same type signature.

Added: 


Modified: 
clang/utils/TableGen/RISCVVEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index 41025926058ed07..c08e48b3f44dfe3 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -290,7 +290,7 @@ unsigned 
SemaSignatureTable::getIndex(ArrayRef Signature) {
 return 0;
 
   // Checking Signature already in table or not.
-  if (Signature.size() < SignatureTable.size()) {
+  if (Signature.size() <= SignatureTable.size()) {
 size_t Bound = SignatureTable.size() - Signature.size() + 1;
 for (size_t Index = 0; Index < Bound; ++Index) {
   if (equal(Signature.begin(), Signature.end(),



___
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-10 Thread Richard Smith via cfe-commits


@@ -138,13 +138,14 @@ void g27(void) { // PR8073
 void g28(void) {
   typedef long long v1i64 __attribute((vector_size(8)));
   typedef short v12i16 __attribute((vector_size(24)));
+  typedef unsigned char v24u8 __attribute((vector_size(24)));
   typedef long double v2f80 __attribute((vector_size(24)));
   // CHECK: @g28.a = internal global <1 x i64> 
-  // CHECK: @g28.b = internal global <12 x i16> 
+  // CHECK: @g28.b = internal global <24 x i8> , align 32

zygoloid wrote:

I think the correct output here would be:
```suggestion
  // CHECK: @g28.b = internal global <24 x i8> , align 32
```

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] [clang] Implement constexpr bit_cast for vectors (PR #66894)

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

https://github.com/zygoloid commented:

Looks good, other than the handling of `x86_fp80`, which doesn't seem to match 
Clang's current runtime behavior.

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] [clang] Implement constexpr bit_cast for vectors (PR #66894)

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


@@ -138,13 +138,14 @@ void g27(void) { // PR8073
 void g28(void) {
   typedef long long v1i64 __attribute((vector_size(8)));
   typedef short v12i16 __attribute((vector_size(24)));
+  typedef unsigned char v24u8 __attribute((vector_size(24)));
   typedef long double v2f80 __attribute((vector_size(24)));
   // CHECK: @g28.a = internal global <1 x i64> 
-  // CHECK: @g28.b = internal global <12 x i16> 
+  // CHECK: @g28.b = internal global <24 x i8> , align 32
   // CHECK: @g28.c = internal global <2 x x86_fp80> , align 32
   static v1i64 a = (v1i64)10LL;
-  static v12i16 b = (v12i16)(v2f80){1,2};
-  static v2f80 c = (v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,0,-32768,16384,0};
+  static v24u8 b = (v24u8)(v2f80){1,2};
+  static v2f80 c = (v2f80)(v12i16){0,0,0,-32768,16383,0,0,0,-32768,16384,0,0};

zygoloid wrote:

I think `c` here was correct before.

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] [clang] Implement constexpr bit_cast for vectors (PR #66894)

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


@@ -7307,6 +7324,74 @@ class BufferToAPValueConverter {
 return ArrayValue;
   }
 
+  std::optional visit(const VectorType *VTy, CharUnits Offset) {
+QualType EltTy = VTy->getElementType();
+unsigned NElts = VTy->getNumElements();
+unsigned EltSize =
+VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy);
+
+if ((NElts * EltSize) % Info.Ctx.getCharWidth() != 0) {
+  // The vector's size in bits is not a multiple of the target's byte size,
+  // so its layout is unspecified. For now, we'll simply treat these cases
+  // as unsupported (this should only be possible with OpenCL bool vectors
+  // whose element count isn't a multiple of the byte size).
+  Info.FFDiag(BCE->getBeginLoc(),
+  diag::note_constexpr_bit_cast_invalid_vector)
+  << QualType(VTy, 0) << EltSize << NElts << Info.Ctx.getCharWidth();
+  return std::nullopt;
+}
+
+SmallVector Elts;
+Elts.reserve(NElts);
+if (VTy->isExtVectorBoolType()) {
+  // Special handling for OpenCL bool vectors:
+  // Since these vectors are stored as packed bits, but we can't read
+  // individual bits from the BitCastBuffer, we'll buffer all of the
+  // elements together into an appropriately sized APInt and write them all
+  // out at once. Because we don't accept vectors where NElts * EltSize
+  // isn't a multiple of the char size, there will be no padding space, so
+  // we don't have to worry about reading any padding data which didn't
+  // actually need to be accessed.
+  bool BigEndian = Info.Ctx.getTargetInfo().isBigEndian();
+
+  SmallVector Bytes;
+  Bytes.reserve(NElts / 8);
+  if (!Buffer.readObject(Offset, CharUnits::fromQuantity(NElts / 8), 
Bytes))
+return std::nullopt;
+
+  APSInt SValInt(NElts, true);
+  llvm::LoadIntFromMemory(SValInt, &*Bytes.begin(), Bytes.size());
+
+  for (unsigned I = 0; I < NElts; ++I) {
+llvm::APInt Elt =
+SValInt.extractBits(1, (BigEndian ? NElts - I - 1 : I) * EltSize);
+Elts.emplace_back(
+APSInt(std::move(Elt), !EltTy->isSignedIntegerType()));
+  }
+} else {
+  // Iterate over each of the elements and read them from the buffer at
+  // the appropriate offset.
+  CharUnits EltSizeChars = Info.Ctx.getTypeSizeInChars(EltTy);
+
+  // Special handling for vectors of x86_fp80: use a size of exactly 80 
bits
+  // because LLVM stores vector elements without padding
+  if (EltTy->isRealFloatingType() &&
+  &Info.Ctx.getFloatTypeSemantics(EltTy) ==
+  &APFloat::x87DoubleExtended())
+EltSizeChars = Info.Ctx.toCharUnitsFromBits(80);

zygoloid wrote:

(Same comment as above.)

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] [clang] Implement constexpr bit_cast for vectors (PR #66894)

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


@@ -7098,6 +7052,69 @@ class APValueToBufferConverter {
 return true;
   }
 
+  bool visitVector(const APValue &Val, QualType Ty, CharUnits Offset) {
+const VectorType *VTy = Ty->castAs();
+QualType EltTy = VTy->getElementType();
+unsigned NElts = VTy->getNumElements();
+unsigned EltSize =
+VTy->isExtVectorBoolType() ? 1 : Info.Ctx.getTypeSize(EltTy);
+
+if ((NElts * EltSize) % Info.Ctx.getCharWidth() != 0) {
+  // The vector's size in bits is not a multiple of the target's byte size,
+  // so its layout is unspecified. For now, we'll simply treat these cases
+  // as unsupported (this should only be possible with OpenCL bool vectors
+  // whose element count isn't a multiple of the byte size).
+  Info.FFDiag(BCE->getBeginLoc(),
+  diag::note_constexpr_bit_cast_invalid_vector)
+  << Ty.getCanonicalType() << EltSize << NElts
+  << Info.Ctx.getCharWidth();
+  return false;
+}
+
+if (VTy->isExtVectorBoolType()) {
+  // Special handling for OpenCL bool vectors:
+  // Since these vectors are stored as packed bits, but we can't write
+  // individual bits to the BitCastBuffer, we'll buffer all of the elements
+  // together into an appropriately sized APInt and write them all out at
+  // once. Because we don't accept vectors where NElts * EltSize isn't a
+  // multiple of the char size, there will be no padding space, so we don't
+  // have to worry about writing data which should have been left
+  // uninitialized.
+  bool BigEndian = Info.Ctx.getTargetInfo().isBigEndian();
+
+  llvm::APInt Res = llvm::APInt::getZero(NElts);
+  for (unsigned I = 0; I < NElts; ++I) {
+const llvm::APSInt &EltAsInt = Val.getVectorElt(I).getInt();
+assert(EltAsInt.isUnsigned() && EltAsInt.getBitWidth() == 1 &&
+   "bool vector element must be 1-bit unsigned integer!");
+
+Res.insertBits(EltAsInt, BigEndian ? (NElts - I - 1) : I);
+  }
+
+  SmallVector Bytes(NElts / 8);
+  llvm::StoreIntToMemory(Res, &*Bytes.begin(), NElts / 8);
+  Buffer.writeObject(Offset, Bytes);
+} else {
+  // Iterate over each of the elements and write them out to the buffer at
+  // the appropriate offset.
+  CharUnits EltSizeChars = Info.Ctx.getTypeSizeInChars(EltTy);
+
+  // Special handling for vectors of x86_fp80: use a size of exactly 80 
bits
+  // because LLVM stores vector elements without padding
+  if (EltTy->isRealFloatingType() &&
+  &Info.Ctx.getFloatTypeSemantics(EltTy) ==
+  &APFloat::x87DoubleExtended())
+EltSizeChars = Info.Ctx.toCharUnitsFromBits(80);

zygoloid wrote:

This doesn't seem correct: in [my 
investigation](https://godbolt.org/z/co8rxd5fe) it looks like LLVM stores 
vectors of `x86_fp80` with a stride of 12 (for x86) or 16 (for x86_64) bytes 
between elements -- the same layout as an array of `x86_fp80`, with 10 bytes of 
data followed by either 2 or 6 bytes of padding. Would it be correct to simply 
remove this special case and the matching one below?

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] [clang] Implement constexpr bit_cast for vectors (PR #66894)

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

https://github.com/zygoloid edited 
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] [clang][Interp] Add basic support for _BitInt (PR #68069)

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


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


[clang] 26d9f85 - [clang][Interp] Add basic support for _BitInt (#68069)

2023-10-10 Thread via cfe-commits

Author: Timm Baeder
Date: 2023-10-11T08:53:21+02:00
New Revision: 26d9f851cfddf2d6b57239a7ba054d027756bfb7

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

LOG: [clang][Interp] Add basic support for _BitInt (#68069)

Make sure we pass the expected bitwidth around when casting to
IntAP/IntAPS.

This makes it easier to test the `IntegralAP` code for different bit
widths than 128.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/Context.h
clang/lib/AST/Interp/IntegralAP.h
clang/lib/AST/Interp/Interp.h
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/lib/AST/Interp/Opcodes.td
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e7a431ddee6f002..2b745d6a1509868 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -138,6 +138,13 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
 if (!this->visit(SubExpr))
   return false;
 
+if (ToT == PT_IntAP)
+  return this->emitCastFloatingIntegralAP(Ctx.getBitWidth(CE->getType()),
+  CE);
+if (ToT == PT_IntAPS)
+  return this->emitCastFloatingIntegralAPS(Ctx.getBitWidth(CE->getType()),
+   CE);
+
 return this->emitCastFloatingIntegral(*ToT, CE);
   }
 
@@ -183,6 +190,11 @@ bool ByteCodeExprGen::VisitCastExpr(const 
CastExpr *CE) {
   return true;
 }
 
+if (ToT == PT_IntAP)
+  return this->emitCastAP(*FromT, Ctx.getBitWidth(CE->getType()), CE);
+if (ToT == PT_IntAPS)
+  return this->emitCastAPS(*FromT, Ctx.getBitWidth(CE->getType()), CE);
+
 return this->emitCast(*FromT, *ToT, CE);
   }
 

diff  --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index 958b50b1615ad18..6df61e93ad83abc 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -64,6 +64,8 @@ class Context final {
   unsigned getCharBit() const;
   /// Return the floating-point semantics for T.
   const llvm::fltSemantics &getFloatSemantics(QualType T) const;
+  /// Return the size of T in bits.
+  uint32_t getBitWidth(QualType T) const { return Ctx.getIntWidth(T); }
 
   /// Classifies an expression.
   std::optional classify(QualType T) const;

diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index a8df431bef11784..f9a33bbcd7bd7fa 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -37,8 +37,12 @@ template  class IntegralAP final {
   APSInt V;
 
   template  static T truncateCast(const APSInt &V) {
-return std::is_signed_v ? V.trunc(sizeof(T) * 8).getSExtValue()
-   : V.trunc(sizeof(T) * 8).getZExtValue();
+constexpr unsigned BitSize = sizeof(T) * 8;
+if (BitSize >= V.getBitWidth())
+  return std::is_signed_v ? V.getSExtValue() : V.getZExtValue();
+
+return std::is_signed_v ? V.trunc(BitSize).getSExtValue()
+   : V.trunc(BitSize).getZExtValue();
   }
 
 public:
@@ -89,10 +93,9 @@ template  class IntegralAP final {
   }
 
   template 
-  static IntegralAP from(Integral I) {
-// FIXME: Take bits parameter.
+  static IntegralAP from(Integral I, unsigned BitWidth) {
 APSInt Copy =
-APSInt(APInt(128, static_cast(I), InputSigned), !Signed);
+APSInt(APInt(BitWidth, static_cast(I), InputSigned), !Signed);
 Copy.setIsSigned(Signed);
 
 assert(Copy.isSigned() == Signed);
@@ -108,8 +111,7 @@ template  class IntegralAP final {
 return IntegralAP(0);
   }
 
-  // FIXME: This can't be static if the bitwidth depends on V.
-  static constexpr unsigned bitWidth() { return 128; }
+  constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
   APSInt toAPSInt(unsigned Bits = 0) const { return V; }
   APValue toAPValue() const { return APValue(V); }

diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 25ce93ac03d3733..1ad3b8bfc7711d3 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1568,6 +1568,22 @@ inline bool CastFP(InterpState &S, CodePtr OpPC, const 
llvm::fltSemantics *Sem,
   return true;
 }
 
+/// Like Cast(), but we cast to an arbitrary-bitwidth integral, so we need
+/// to know what bitwidth the result should be.
+template ::T>
+bool CastAP(InterpState &S, CodePtr OpPC, uint32_t BitWidth) {
+  S.Stk.push>(
+  IntegralAP::from(S.Stk.pop(), BitWidth));
+  return true;
+}
+
+template ::T>
+bool CastAPS(InterpState &S, CodePtr OpPC, uint32_t BitWidth) {
+  S.Stk.push>(
+  IntegralAP::from(S.Stk.pop(), BitWidth));
+  return true;
+}

[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-10 Thread via cfe-commits

https://github.com/sr-tream updated 
https://github.com/llvm/llvm-project/pull/67213

>From 13e43eb68b0172c4db5c0218ad4ba566da535f67 Mon Sep 17 00:00:00 2001
From: SR_team 
Date: Wed, 11 Oct 2023 09:49:11 +0300
Subject: [PATCH] [clangd] Show alignment for records and fields decls

---
 clang-tools-extra/clangd/Hover.cpp|  5 +
 clang-tools-extra/clangd/Hover.h  |  2 ++
 clang-tools-extra/clangd/unittests/HoverTests.cpp | 11 +++
 3 files changed, 18 insertions(+)

diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 0ec85fc24df151b..ddb188218cc274c 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1001,6 +1001,8 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
   if (auto *RD = llvm::dyn_cast(&ND)) {
 if (auto Size = Ctx.getTypeSizeInCharsIfKnown(RD->getTypeForDecl()))
   HI.Size = Size->getQuantity() * 8;
+if (!RD->isDependentType() && RD->isCompleteDefinition())
+  HI.Align = Ctx.getTypeAlign(RD->getTypeForDecl());
 return;
   }
 
@@ -1009,6 +1011,7 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
 if (Record)
   Record = Record->getDefinition();
 if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
+  HI.Align = Ctx.getTypeAlign(FD->getType());
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Record);
   HI.Offset = Layout.getFieldOffset(FD->getFieldIndex());
   if (FD->isBitField())
@@ -1488,6 +1491,8 @@ markup::Document HoverInfo::present() const {
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
   }
+  if (Align)
+Output.addParagraph().appendText("Align: " + formatSize(*Align));
 
   if (CalleeArgInfo) {
 assert(CallPassType);
diff --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h
index 6a61100912918ea..fe689de44732ebe 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -97,6 +97,8 @@ struct HoverInfo {
   std::optional Offset;
   /// Contains the padding following a field within the enclosing class.
   std::optional Padding;
+  /// Contains the alignment of fields and types where it's interesting.
+  std::optional Align;
   // Set when symbol is inside function call. Contains information extracted
   // from the callee definition about the argument this is passed as.
   std::optional CalleeArgInfo;
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 8c88cd52574536c..c5623759a7c2041 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -92,6 +92,7 @@ TEST(Hover, Structured) {
  HI.Offset = 0;
  HI.Size = 8;
  HI.Padding = 56;
+ HI.Align = 8;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -110,6 +111,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Size = 8;
  HI.Padding = 120;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -128,6 +130,7 @@ TEST(Hover, Structured) {
  HI.Type = "int";
  HI.Offset = 0;
  HI.Size = 1;
+ HI.Align = 32;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -192,6 +195,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Offset = 0;
  HI.Size = 8;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -204,6 +208,7 @@ TEST(Hover, Structured) {
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
  HI.Size = 8;
+ HI.Align = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1375,6 +1380,7 @@ class Foo final {})cpp";
  HI.Offset = 8;
  HI.Size = 1;
  HI.Padding = 23;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}}};
   for (const auto &Case : Cases) {
@@ -1411,6 +1417,7 @@ class Foo final {})cpp";
 EXPECT_EQ(H->Value, Expected.Value);
 EXPECT_EQ(H->Size, Expected.Size);
 EXPECT_EQ(H->Offset, Expected.Offset);
+EXPECT_EQ(H->Align, Expected.Align);
 EXPECT_EQ(H->AccessSpecifier, Expected.AccessSpecifier);
 EXPECT_EQ(H->CalleeArgInfo, Expected.CalleeArgInfo);
 EXPECT_EQ(H->CallPassType, Expected.CallPassType);
@@ -3448,6 +3455,7 @@ template  class Foo {})",
 HI.Size = 32;
 HI.Offset = 96;
 HI.Padding = 32;
+HI.Align = 32;
   },
   R"(field foo
 
@@ -3455,6 +3463,7 @@ Type: type (aka can_type)
 Value = value
 Offset: 12 bytes
 Size: 4 bytes (+4 bytes padding)
+Align: 4 bytes
 
 // In test::Bar
 def)",
@@ -3470,6 +3479,7 @@ def)",
 HI.Size = 25;
 HI.Offset = 35;
 HI.Padding = 4

[libunwind] [libunwind] Fix running tests with MSan (PR #67860)

2023-10-10 Thread Alexander Richardson via cfe-commits


@@ -115,6 +121,18 @@ extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, 
unw_word_t) LIBUNWIND_AVAIL
 extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t)  
LIBUNWIND_AVAIL;
 extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL;
 
+#ifdef LIBUNWIND_HAVE_MSAN
+// unw_getcontext is implemented in assembly so it is rather difficult to
+// mark the MSan shadow as initialized from within the function. Instead we
+// use a macro wrapper when compiling with MSan to avoid false-positives.
+#define unw_getcontext(context)
\

arichardson wrote:

We have to be careful to call unw_getcontext first to avoid registers being 
clobbered, but yes that would work if we don't need unw_getcontext to be an 
exported function. Maybe `extern inline __attribute__((always_inline))` could 
work.

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


[clang] [clang][C2x] Remove confusing diagnostic auto storage class specifier (PR #68710)

2023-10-10 Thread via cfe-commits

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

Thanks for the quick patch!

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


[clang] [clang][RISCV] Fix the condition of checking signature in getIndex (PR #67403)

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

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

LGTM

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


[clang] [clang][driver] Add avr-libc's default linker script to lld (PR #68507)

2023-10-10 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/68507

>From b2a442d6aca019a42baef45e1f245dc1ea5bd8a1 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Wed, 11 Oct 2023 14:05:14 +0800
Subject: [PATCH] [clang][driver] Add avr-libc's default linker script to lld

If lld is specified but no user linker script is offered,
we try to use avr-libc's default ones. This is unnecessary
for GNU ld.
---
 clang/lib/Driver/ToolChains/AVR.cpp   | 14 ++--
 .../usr/lib/avr/lib/ldscripts/avrtiny.x   |  0
 .../usr/lib/avr/lib/ldscripts/avrxmega6.x |  0
 clang/test/Driver/avr-ld.c| 22 +++
 4 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrtiny.x
 create mode 100644 
clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrxmega6.x

diff --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index e312fa155e11bf8..2e46b25aeba75ef 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -554,8 +554,18 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
 CmdArgs.push_back("--end-group");
 
-// Add user specified linker script.
-Args.AddAllArgs(CmdArgs, options::OPT_T);
+// Add avr-libc's linker script to lld by default, if it exists.
+if (!Args.hasArg(options::OPT_T) &&
+Linker.find("lld") != std::string::npos) {
+  std::string Path(*AVRLibcRoot + "/lib/ldscripts/");
+  Path += *FamilyName;
+  Path += ".x";
+  if (llvm::sys::fs::exists(Path))
+CmdArgs.push_back(Args.MakeArgString("-T" + Path));
+}
+// Otherwise add user specified linker script to either avr-ld or lld.
+else
+  Args.AddAllArgs(CmdArgs, options::OPT_T);
 
 if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
   CmdArgs.push_back("--relax");
diff --git 
a/clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrtiny.x 
b/clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrtiny.x
new file mode 100644
index 000..e69de29bb2d1d64
diff --git 
a/clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrxmega6.x 
b/clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrxmega6.x
new file mode 100644
index 000..e69de29bb2d1d64
diff --git a/clang/test/Driver/avr-ld.c b/clang/test/Driver/avr-ld.c
index 0f12607fe9d69eb..3e4114485332fcd 100644
--- a/clang/test/Driver/avr-ld.c
+++ b/clang/test/Driver/avr-ld.c
@@ -58,6 +58,28 @@
 // LINKS: {{".*ld.*"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x800100" 
"-plugin-opt=mcpu=atmega328"
 // LINKS-NOT: "-plugin-opt=thinlto"
 
+// RUN: %clang -### --target=avr -mmcu=attiny40 -fuse-ld=lld --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKT0 %s
+// LINKT0: {{".*lld.*"}} {{.*}} {{"-T.*avrtiny.x"}}
+// LINKT0-NOT: "-m
+
+// RUN: %clang -### --target=avr -mmcu=atxmega384c3 -fuse-ld=lld --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKT1 %s
+// LINKT1: {{".*lld.*"}} {{.*}} {{"-T.*avrxmega6.x"}}
+// LINKT1-NOT: "-m
+
+// RUN: %clang -### --target=avr -mmcu=atmega328 -fuse-ld=lld --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKT2 %s
+// LINKT2: {{".*lld.*"}} {{.*}} "--start-group" {{.*}} "--end-group"
+// LINKT2-NOT: "-T
+// LINKT2-NOT: "-m
+
+// RUN: %clang -### --target=avr -mmcu=attiny40 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKT3 %s
+// LINKT3: {{".*ld.*"}} {{.*}} "-mavrtiny"
+// LINKT3-NOT: "-T
+
+// RUN: %clang -### --target=avr -mmcu=attiny40 --sysroot 
%S/Inputs/basic_avr_tree -fuse-ld=lld -T 
%S/Inputs/basic_avr_tree/usr/lib/avr/lib/ldscripts/avrxmega6.x %s 2>&1 | 
FileCheck -check-prefix LINKT4 %s
+// LINKT4: {{".*lld.*"}} {{.*}} {{"-T.*avrxmega6.x"}}
+// LINKT4-NOT: {{"-T.*avrtiny.x"}}
+// LINKT4-NOT: "-m
+
 // RUN: %clang -### -r --target=avr -mmcu=atmega328 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKU %s
 // LINKU: {{".*ld.*"}} {{.*}} "-r" {{.*}} "-mavr5"
 // LINKU-NOT: "--gc-sections"

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


[clang] b888592 - Use llvm::endianness::{big,little,native} (NFC)

2023-10-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-10-10T22:54:51-07:00
New Revision: b8885926f8115d5fe2c06907e066cae061d5f230

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

LOG: Use llvm::endianness::{big,little,native} (NFC)

Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an enum.
This patch replaces llvm::support::{big,little,native} with
llvm::endianness::{big,little,native}.

Added: 


Modified: 
clang/lib/APINotes/APINotesWriter.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Driver/OffloadBundler.cpp
lld/ELF/DWARF.h
lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp
llvm/include/llvm/DebugInfo/CodeView/SymbolDeserializer.h
llvm/include/llvm/DebugInfo/CodeView/TypeDeserializer.h
llvm/include/llvm/Support/BinaryByteStream.h
llvm/lib/DebugInfo/CodeView/CVTypeVisitor.cpp
llvm/lib/DebugInfo/CodeView/RecordName.cpp
llvm/lib/DebugInfo/CodeView/RecordSerialization.cpp
llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewReader.cpp
llvm/lib/DebugInfo/LogicalView/Readers/LVCodeViewVisitor.cpp
llvm/lib/DebugInfo/MSF/MSFBuilder.cpp
llvm/lib/DebugInfo/PDB/Native/DbiStreamBuilder.cpp
llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
llvm/lib/DebugInfo/PDB/Native/TpiStreamBuilder.cpp
llvm/lib/ObjectYAML/CodeViewYAMLTypeHashing.cpp
llvm/lib/ProfileData/InstrProfReader.cpp
llvm/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
llvm/tools/llvm-objdump/MachODump.cpp
llvm/tools/llvm-objdump/llvm-objdump.cpp
llvm/tools/llvm-pdbutil/DumpOutputStyle.cpp
llvm/tools/llvm-pdbutil/ExplainOutputStyle.cpp
llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
llvm/tools/llvm-readobj/COFFDumper.cpp
llvm/tools/llvm-readobj/MachODumper.cpp
llvm/unittests/DebugInfo/CodeView/RandomAccessVisitorTest.cpp
llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp
llvm/unittests/DebugInfo/MSF/MappedBlockStreamTest.cpp
llvm/unittests/Support/BinaryStreamTest.cpp
llvm/unittests/Support/HashBuilderTest.cpp
llvm/unittests/Support/YAMLIOTest.cpp

Removed: 




diff  --git a/clang/lib/APINotes/APINotesWriter.cpp 
b/clang/lib/APINotes/APINotesWriter.cpp
index a92b379a8e56acb..770d78e22050c01 100644
--- a/clang/lib/APINotes/APINotesWriter.cpp
+++ b/clang/lib/APINotes/APINotesWriter.cpp
@@ -294,7 +294,7 @@ class IdentifierTableInfo {
 uint32_t KeyLength = Key.size();
 uint32_t DataLength = sizeof(uint32_t);
 
-llvm::support::endian::Writer writer(OS, llvm::support::little);
+llvm::support::endian::Writer writer(OS, llvm::endianness::little);
 writer.write(KeyLength);
 writer.write(DataLength);
 return {KeyLength, DataLength};
@@ -303,7 +303,7 @@ class IdentifierTableInfo {
   void EmitKey(raw_ostream &OS, key_type_ref Key, unsigned) { OS << Key; }
 
   void EmitData(raw_ostream &OS, key_type_ref, data_type_ref Data, unsigned) {
-llvm::support::endian::Writer writer(OS, llvm::support::little);
+llvm::support::endian::Writer writer(OS, llvm::endianness::little);
 writer.write(Data);
   }
 };
@@ -326,7 +326,7 @@ void APINotesWriter::Implementation::writeIdentifierBlock(
 llvm::raw_svector_ostream BlobStream(HashTableBlob);
 // Make sure that no bucket is at offset 0
 llvm::support::endian::write(BlobStream, 0,
-   llvm::support::little);
+   llvm::endianness::little);
 Offset = Generator.Emit(BlobStream);
   }
 
@@ -354,21 +354,21 @@ class ObjCContextIDTableInfo {
 uint32_t KeyLength = sizeof(uint32_t) + sizeof(uint8_t) + sizeof(uint32_t);
 uint32_t DataLength = sizeof(uint32_t);
 
-llvm::support::endian::Writer writer(OS, llvm::support::little);
+llvm::support::endian::Writer writer(OS, llvm::endianness::little);
 writer.write(KeyLength);
 writer.write(DataLength);
 return {KeyLength, DataLength};
   }
 
   void EmitKey(raw_ostream &OS, key_type_ref Key, unsigned) {
-llvm::support::endian::Writer writer(OS, llvm::support::little);
+llvm::support::endian::Writer writer(OS, llvm::endianness::little);
 writer.write(Key.parentContextID);
 writer.write(Key.contextKind);
 writer.write(Key.contextID);
   }
 
   void EmitData(raw_ostream &OS, key_type_ref, data_type_ref Data, unsigned) {
-llvm::support::endian::Writer writer(OS, llvm::support::little);
+llvm::support::endian::Writer writer(OS, llvm::endianness::little);
 writer.write(Data);
   }
 };
@@ -406,7 +406,7 @@ unsigned getVersionedInfoSize(
 
 /// Emit a serialized representation of a version tuple.
 void emitVersionTuple(raw_ostream &OS, const VersionTuple &VT) {
-  llvm::support::endian::Writer writer(OS, llvm::support::little);
+  

[clang] 0439a01 - [llvm] Drop unaligned from calls to llvm::support::endian::{read,write} (NFC)

2023-10-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-10-10T22:41:47-07:00
New Revision: 0439a017ef72effa9681cdb794860cf954de808a

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

LOG: [llvm] Drop unaligned from calls to llvm::support::endian::{read,write} 
(NFC)

The last template parameter of llvm::support::endian::{read,write}
defaults to unaligned, so we can drop that at call sites.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/Source.h
llvm/include/llvm/Object/FaultMapParser.h
llvm/include/llvm/Object/StackMapParser.h
llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index 4989b4ba797f2cf..c8abb7c17a38ba2 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -149,7 +149,7 @@ void ByteCodeEmitter::emitLabel(LabelTy Label) {
   void *Location = Code.data() + Reloc - align(sizeof(int32_t));
   assert(aligned(Location));
   const int32_t Offset = Target - static_cast(Reloc);
-  endian::write(Location, Offset);
+  endian::write(Location, Offset);
 }
 LabelRelocs.erase(It);
   }

diff  --git a/clang/lib/AST/Interp/Source.h b/clang/lib/AST/Interp/Source.h
index 70a6b87d031bb85..c28b488ff554d1f 100644
--- a/clang/lib/AST/Interp/Source.h
+++ b/clang/lib/AST/Interp/Source.h
@@ -55,7 +55,7 @@ class CodePtr final {
   template  std::enable_if_t::value, T> read() 
{
 assert(aligned(Ptr));
 using namespace llvm::support;
-T Value = endian::read(Ptr);
+T Value = endian::read(Ptr);
 Ptr += align(sizeof(T));
 return Value;
   }

diff  --git a/llvm/include/llvm/Object/FaultMapParser.h 
b/llvm/include/llvm/Object/FaultMapParser.h
index 4d1f0397a0dd222..bed2dba154f3c06 100644
--- a/llvm/include/llvm/Object/FaultMapParser.h
+++ b/llvm/include/llvm/Object/FaultMapParser.h
@@ -42,7 +42,7 @@ class FaultMapParser {
 
   template  static T read(const uint8_t *P, const uint8_t *E) {
 assert(P + sizeof(T) <= E && "out of bounds read!");
-return support::endian::read(P);
+return support::endian::read(P);
   }
 
 public:

diff  --git a/llvm/include/llvm/Object/StackMapParser.h 
b/llvm/include/llvm/Object/StackMapParser.h
index 37d0377cf93bca5..8853e3656fca071 100644
--- a/llvm/include/llvm/Object/StackMapParser.h
+++ b/llvm/include/llvm/Object/StackMapParser.h
@@ -436,7 +436,7 @@ template  class StackMapParser 
{
 private:
   template 
   static T read(const uint8_t *P) {
-return support::endian::read(P);
+return support::endian::read(P);
   }
 
   static const unsigned HeaderOffset = 0;

diff  --git 
a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp 
b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
index e56cb15406aeaa1..ed7757be6615827 100644
--- a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
+++ b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
@@ -109,8 +109,8 @@ template 
 bool parseImmediate(MCInst &MI, uint64_t &Size, ArrayRef Bytes) {
   if (Size + sizeof(T) > Bytes.size())
 return false;
-  T Val = support::endian::read(Bytes.data() +
-Size);
+  T Val =
+  support::endian::read(Bytes.data() + Size);
   Size += sizeof(T);
   if (std::is_floating_point::value) {
 MI.addOperand(



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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-10-10 Thread Felix via cfe-commits


@@ -660,14 +671,16 @@ void PPCAsmPrinter::EmitTlsCall(const MachineInstr *MI,
  "GETtls[ld]ADDR[32] must read GPR3");
 
   if (Subtarget->isAIXABI()) {
-// On AIX, the variable offset should already be in R4 and the region 
handle
-// should already be in R3.
-// For TLSGD, which currently is the only supported access model, we only
-// need to generate an absolute branch to .__tls_get_addr.
+// For TLSGD, the variable offset should already be in R4 and the region
+// handle should already be in R3. We generate an absolute branch to
+// .__tls_get_addr. For TLSLD, the module handle should already be in R3.
+// We generate an absolute branch to .__tls_get_mod.
 Register VarOffsetReg = Subtarget->isPPC64() ? PPC::X4 : PPC::R4;
 (void)VarOffsetReg;
-assert(MI->getOperand(2).isReg() &&
-   MI->getOperand(2).getReg() == VarOffsetReg &&
+assert((MI->getOpcode() == PPC::GETtlsMOD32AIX ||
+MI->getOpcode() == PPC::GETtlsMOD64AIX ||
+(MI->getOperand(2).isReg() &&
+ MI->getOperand(2).getReg() == VarOffsetReg)) &&
"GETtls[ld]ADDR[32] must read GPR4");
 EmitAIXTlsCallHelper(MI);

orcguru wrote:

Thank you for looking into this!

I tried the example, and it seems turn on optimization can help remove the FP 
load. We declared "Defs = [X0,X4,X5,X11,LR8,CR0]" for GETtlsMOD64AIX, and "Defs 
= [R0,R4,R5,R11,LR,CR0]" for GETtlsMOD32AIX. I think those FP registers should 
be treated as not touched by the call to __tls_get_mod.

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


[clang] c8e1774 - [Interp] Use llvm::endianness::native (NFC)

2023-10-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-10-10T22:26:08-07:00
New Revision: c8e17749757a62cdd5c1dea2cb25f3eaf933cd5d

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

LOG: [Interp] Use llvm::endianness::native (NFC)

This patch replaces endianness::native with llvm::endianness::native.
Note that endianness::native would rely on:

  using endianness = llvm::endianness;

in llvm/include/llvm/Support/Endian.h.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/Source.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp 
b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index a634ee288f57c99..4989b4ba797f2cf 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -149,7 +149,7 @@ void ByteCodeEmitter::emitLabel(LabelTy Label) {
   void *Location = Code.data() + Reloc - align(sizeof(int32_t));
   assert(aligned(Location));
   const int32_t Offset = Target - static_cast(Reloc);
-  endian::write(Location, Offset);
+  endian::write(Location, Offset);
 }
 LabelRelocs.erase(It);
   }

diff  --git a/clang/lib/AST/Interp/Source.h b/clang/lib/AST/Interp/Source.h
index fec950dd544f8a1..70a6b87d031bb85 100644
--- a/clang/lib/AST/Interp/Source.h
+++ b/clang/lib/AST/Interp/Source.h
@@ -55,7 +55,7 @@ class CodePtr final {
   template  std::enable_if_t::value, T> read() 
{
 assert(aligned(Ptr));
 using namespace llvm::support;
-T Value = endian::read(Ptr);
+T Value = endian::read(Ptr);
 Ptr += align(sizeof(T));
 return Value;
   }



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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-10 Thread Chen Zheng via cfe-commits


@@ -807,7 +807,7 @@ ArrayRef 
PPCTargetInfo::getGCCRegAliases() const {
 // PPC ELFABIv2 DWARF Definitoin "Table 2.26. Mappings of Common Registers".
 // vs0 ~ vs31 is mapping to 32 - 63,
 // vs32 ~ vs63 is mapping to 77 - 108.

chenzheng1030 wrote:

Done.

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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-10 Thread Chen Zheng via cfe-commits

https://github.com/chenzheng1030 updated 
https://github.com/llvm/llvm-project/pull/68476

>From eada8d170cefcf2c1d152eaadc68dc4c3077c9ce Mon Sep 17 00:00:00 2001
From: Chen Zheng 
Date: Sat, 7 Oct 2023 06:09:44 -0400
Subject: [PATCH 1/3] [AIX] recognize vsr in inline asm for AIX

---
 clang/lib/Basic/Targets/PPC.cpp  | 3 ++-
 clang/lib/Basic/Targets/PPC.h| 3 ++-
 clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c | 4 
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index e0abc069032e1ce..fa56d39fd2fdada 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -807,6 +807,7 @@ ArrayRef 
PPCTargetInfo::getGCCRegAliases() const {
 // PPC ELFABIv2 DWARF Definitoin "Table 2.26. Mappings of Common Registers".
 // vs0 ~ vs31 is mapping to 32 - 63,
 // vs32 ~ vs63 is mapping to 77 - 108.
+// And this mapping applies to all OSes which runs on powerpc.
 const TargetInfo::AddlRegName GCCAddlRegNames[] = {
 // Table of additional register names to use in user input.
 {{"vs0"}, 32},   {{"vs1"}, 33},   {{"vs2"}, 34},   {{"vs3"}, 35},
@@ -828,7 +829,7 @@ const TargetInfo::AddlRegName GCCAddlRegNames[] = {
 };
 
 ArrayRef PPCTargetInfo::getGCCAddlRegNames() const {
-  if (ABI == "elfv2")
+  if (ABI == "elfv2" || ABI == "aix")
 return llvm::ArrayRef(GCCAddlRegNames);
   else
 return TargetInfo::getGCCAddlRegNames();
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index ef667b3d511f0e6..c2a18d77a60a510 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -385,6 +385,7 @@ class LLVM_LIBRARY_VISIBILITY PPC32TargetInfo : public 
PPCTargetInfo {
   LongDoubleWidth = 64;
   LongDoubleAlign = DoubleAlign = 32;
   LongDoubleFormat = &llvm::APFloat::IEEEdouble();
+  ABI = "aix";
   break;
 default:
   break;
@@ -418,11 +419,11 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public 
PPCTargetInfo {
 std::string DataLayout;
 
 if (Triple.isOSAIX()) {
-  // TODO: Set appropriate ABI for AIX platform.
   DataLayout = "E-m:a-Fi64-i64:64-n32:64";
   LongDoubleWidth = 64;
   LongDoubleAlign = DoubleAlign = 32;
   LongDoubleFormat = &llvm::APFloat::IEEEdouble();
+  ABI = "aix";
 } else if ((Triple.getArch() == llvm::Triple::ppc64le)) {
   DataLayout = "e-m:e-Fn32-i64:64-n32:64";
   ABI = "elfv2";
diff --git a/clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c 
b/clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c
index a4fabd688175e14..a8033f22073cc9f 100644
--- a/clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c
+++ b/clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c
@@ -2,6 +2,10 @@
 
 // RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu -target-feature +vsx \
 // RUN:   -target-cpu pwr9 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -target-feature +vsx \
+// RUN:   -target-cpu pwr9 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-ibm-aix -target-feature +vsx \
+// RUN:   -target-cpu pwr9 -emit-llvm %s -o - | FileCheck %s
 
 // This case is to test VSX register support in the clobbers list for inline 
asm.
 void testVSX (void) {

>From 0d44bd306dc330f3f6c920789f986ae30b970505 Mon Sep 17 00:00:00 2001
From: Chen Zheng 
Date: Sat, 7 Oct 2023 23:03:06 -0400
Subject: [PATCH 2/3] address comments

---
 clang/lib/Basic/Targets/PPC.cpp  | 7 ++-
 clang/lib/Basic/Targets/PPC.h| 3 +--
 clang/test/CodeGen/PowerPC/inline-asm-matching-ppc-vsx.c | 8 +---
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index fa56d39fd2fdada..47cc8ee5db1b896 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -807,7 +807,7 @@ ArrayRef 
PPCTargetInfo::getGCCRegAliases() const {
 // PPC ELFABIv2 DWARF Definitoin "Table 2.26. Mappings of Common Registers".
 // vs0 ~ vs31 is mapping to 32 - 63,
 // vs32 ~ vs63 is mapping to 77 - 108.
-// And this mapping applies to all OSes which runs on powerpc.
+// And this mapping applies to all OSes which run on powerpc.
 const TargetInfo::AddlRegName GCCAddlRegNames[] = {
 // Table of additional register names to use in user input.
 {{"vs0"}, 32},   {{"vs1"}, 33},   {{"vs2"}, 34},   {{"vs3"}, 35},
@@ -829,10 +829,7 @@ const TargetInfo::AddlRegName GCCAddlRegNames[] = {
 };
 
 ArrayRef PPCTargetInfo::getGCCAddlRegNames() const {
-  if (ABI == "elfv2" || ABI == "aix")
-return llvm::ArrayRef(GCCAddlRegNames);
-  else
-return TargetInfo::getGCCAddlRegNames();
+  return llvm::ArrayRef(GCCAddlRegNames);
 }
 
 static constexpr llvm::StringLiteral ValidCPUNames[] = {
diff --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index c2a18d77a

[clang] [TSAN] add support for riscv64 (PR #68735)

2023-10-10 Thread via cfe-commits

hiraditya wrote:

> The review context is on https://reviews.llvm.org/D145214 . Moving it here 
> just causes more confusion.
> 
> @alexfanqi is the author of the patch and they can drive a reland.

Can you elaborate what is confusing? The patch was already reviewed and 
accepted. I'm waiting on the author to reply back but I posted here for it to 
be tested. @alexfanqi asked me to land the patch last time 
(https://reviews.llvm.org/D145214#4650928)

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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-10 Thread Hubert Tong via cfe-commits


@@ -807,7 +807,7 @@ ArrayRef 
PPCTargetInfo::getGCCRegAliases() const {
 // PPC ELFABIv2 DWARF Definitoin "Table 2.26. Mappings of Common Registers".
 // vs0 ~ vs31 is mapping to 32 - 63,
 // vs32 ~ vs63 is mapping to 77 - 108.

hubert-reinterpretcast wrote:

> I prefer to solve this in another patch with solution: for targets that have 
> no canonical name for physically overlapping registers, `ReturnCanonical` 
> should always be false.
> 
> What do you think?

I think the usage of `ReturnCanonical` is at least partially intended (and 
applies to the situation with vs0 -> f0). In particular, it is intended to 
diagnose (as GCC does):
```
void f(void) {
  register float f __asm__("fr1");
  __asm__ __volatile__ (
"fmul %0,%0,%0"
:
: "f"(f)
: "vs1"
  );
}
```

That diagnostic does not seem to operate for Clang (at least for PPC) even with 
a simpler case where the clobber is `fr1` though.

I think we can leave that for later. For now, with the current patch, I think a 
comment to say that these numbers are used for indexing into the `GCCRegNames` 
array would be correct. If you believe that is a problem, then an additional 
FIXME comment can be added.

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


[clang] 4eecfda - [Driver] Rename AddAllArgs (initialization list overload) to addAllArgs

2023-10-10 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-10-10T21:31:18-07:00
New Revision: 4eecfda50a4e7a05f448a59885d2572d0ea2f4a1

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

LOG: [Driver] Rename AddAllArgs (initialization list overload) to addAllArgs

Most ArgList member functions use the modern functionName style while some like
AddAllArgs use the legacy FunctionName style. These uses are mostly linker
options which have been modified recently to fix duplicate -e issues, so just
update these call sites.

Added: 


Modified: 
clang/lib/Driver/ToolChains/BareMetal.cpp
clang/lib/Driver/ToolChains/CSKYToolChain.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/Darwin.cpp
clang/lib/Driver/ToolChains/DragonFly.cpp
clang/lib/Driver/ToolChains/Flang.cpp
clang/lib/Driver/ToolChains/Haiku.cpp
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/lib/Driver/ToolChains/MSP430.cpp
clang/lib/Driver/ToolChains/OpenBSD.cpp
clang/lib/Driver/ToolChains/RISCVToolchain.cpp
clang/lib/Driver/ToolChains/Solaris.cpp
llvm/include/llvm/Option/ArgList.h
llvm/lib/Option/ArgList.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 26a6276ae50aa1a..f363d277a7b71d3 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -452,7 +452,7 @@ void baremetal::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
-  Args.AddAllArgs(CmdArgs,
+  Args.addAllArgs(CmdArgs,
   {options::OPT_L, options::OPT_T_Group, options::OPT_s,
options::OPT_t, options::OPT_Z_Flag, options::OPT_r});
 

diff  --git a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp 
b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
index 432d61ae2fdf094..2bd91e63fdd5a42 100644
--- a/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
+++ b/clang/lib/Driver/ToolChains/CSKYToolChain.cpp
@@ -169,7 +169,7 @@ void CSKY::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
   ToolChain.AddFilePathLibArgs(Args, CmdArgs);
-  Args.AddAllArgs(CmdArgs,
+  Args.addAllArgs(CmdArgs,
   {options::OPT_T_Group, options::OPT_s, options::OPT_t,
options::OPT_Z_Flag, options::OPT_r});
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index bfd6c5c2864abf7..b91126ebed0186c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -1322,7 +1322,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const 
JobAction &JA,
 A->render(Args, CmdArgs);
   }
 
-  Args.AddAllArgs(CmdArgs,
+  Args.addAllArgs(CmdArgs,
   {options::OPT_D, options::OPT_U, options::OPT_I_Group,
options::OPT_F, options::OPT_index_header_map});
 

diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index c8700a7d159aa47..15b9889157b903c 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -638,7 +638,7 @@ void darwin::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   // It seems that the 'e' option is completely ignored for dynamic executables
   // (the default), and with static executables, the last one wins, as 
expected.
-  Args.AddAllArgs(CmdArgs,
+  Args.addAllArgs(CmdArgs,
   {options::OPT_d_Flag, options::OPT_s, options::OPT_t,
options::OPT_Z_Flag, options::OPT_u_Group, options::OPT_r});
 

diff  --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index a1e4937231572b7..a58983aba5a12f2 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -115,8 +115,7 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   Args.MakeArgString(getToolChain().GetFilePath("crtbegin.o")));
   }
 
-  Args.AddAllArgs(CmdArgs,
-  {options::OPT_L, options::OPT_T_Group});
+  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group});
 
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
 

diff  --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index fe44939741d8ddb..c5bc572bef03458 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -31,7 +31,7 @@ static void addDashXForInput(const ArgList &Args, const 
InputInfo &Input,
 
 void Flang::addFortranDialectOptions(const ArgList &Args,
  ArgStringList &CmdArgs) const {
-  Args.

[clang] 1d8d326 - [clang][driver] Support option '-r' for target AVR (#68484)

2023-10-10 Thread via cfe-commits

Author: Ben Shi
Date: 2023-10-11T12:19:33+08:00
New Revision: 1d8d326a86d59d631655adcb623d08db4a3bf457

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

LOG: [clang][driver] Support option '-r' for target AVR (#68484)

If '-r' is specified with target AVR:

1. Do not link to the avr-libc.
2. Do not emit some conflict options.
3. Do not emit any sub-target related address information/warning.

Added: 


Modified: 
clang/lib/Driver/ToolChains/AVR.cpp
clang/test/Driver/avr-ld.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 81f501d417345d1..e312fa155e11bf8 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -457,7 +457,8 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back(Output.getFilename());
 
   // Enable garbage collection of unused sections.
-  CmdArgs.push_back("--gc-sections");
+  if (!Args.hasArg(options::OPT_r))
+CmdArgs.push_back("--gc-sections");
 
   // Add library search paths before we specify libraries.
   Args.AddAllArgs(CmdArgs, options::OPT_L);
@@ -471,7 +472,7 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   // Only add default libraries if the user hasn't explicitly opted out.
   bool LinkStdlib = false;
-  if (!Args.hasArg(options::OPT_nostdlib) &&
+  if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_r) &&
   !Args.hasArg(options::OPT_nodefaultlibs)) {
 if (!CPU.empty()) {
   if (!FamilyName) {
@@ -497,13 +498,17 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   D.Diag(diag::warn_drv_avr_stdlib_not_linked);
   }
 
-  if (SectionAddressData) {
-CmdArgs.push_back(
-Args.MakeArgString("--defsym=__DATA_REGION_ORIGIN__=0x" +
-   Twine::utohexstr(*SectionAddressData)));
-  } else {
-// We do not have an entry for this CPU in the address mapping table yet.
-D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented) << CPU;
+  if (!Args.hasArg(options::OPT_r)) {
+if (SectionAddressData) {
+  CmdArgs.push_back(
+  Args.MakeArgString("--defsym=__DATA_REGION_ORIGIN__=0x" +
+ Twine::utohexstr(*SectionAddressData)));
+} else {
+  // We do not have an entry for this CPU in the address mapping table
+  // yet.
+  D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented)
+  << CPU;
+}
   }
 
   if (D.isUsingLTO()) {
@@ -554,17 +559,17 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
 if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
   CmdArgs.push_back("--relax");
-
-// Specify the family name as the emulation mode to use.
-// This is almost always required because otherwise avr-ld
-// will assume 'avr2' and warn about the program being larger
-// than the bare minimum supports.
-if (Linker.find("avr-ld") != std::string::npos)
-  CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
   } else {
 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
   }
 
+  // Specify the family name as the emulation mode to use.
+  // This is almost always required because otherwise avr-ld
+  // will assume 'avr2' and warn about the program being larger
+  // than the bare minimum supports.
+  if (Linker.find("avr-ld") != std::string::npos && FamilyName)
+CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+
   C.addCommand(std::make_unique(
   JA, *this, ResponseFileSupport::AtFileCurCP(), 
Args.MakeArgString(Linker),
   CmdArgs, Inputs, Output));

diff  --git a/clang/test/Driver/avr-ld.c b/clang/test/Driver/avr-ld.c
index 4042ecb89adf5f1..0f12607fe9d69eb 100644
--- a/clang/test/Driver/avr-ld.c
+++ b/clang/test/Driver/avr-ld.c
@@ -57,3 +57,31 @@
 // RUN: %clang -### --target=avr -mmcu=atmega328 -fuse-ld=lld -flto --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKS %s
 // LINKS: {{".*ld.*"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x800100" 
"-plugin-opt=mcpu=atmega328"
 // LINKS-NOT: "-plugin-opt=thinlto"
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKU %s
+// LINKU: {{".*ld.*"}} {{.*}} "-r" {{.*}} "-mavr5"
+// LINKU-NOT: "--gc-sections"
+// LINKU-NOT: "--defsym
+// LINKU-NOT: "-l
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 -fuse-ld=lld --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKV %s
+// LINKV: {{".*ld.*"}} {{.*}} "-r"
+// LINKV-NOT: "--gc-sections"
+// LINKV-NOT: "--defsym
+// LINKV-NOT: "-l
+// LINKV-NOT: "-m
+
+// RUN: %clang -### -r 

[clang] [clang][driver] Support option '-r' for target AVR (PR #68484)

2023-10-10 Thread Ben Shi via cfe-commits

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


[clang] [Driver] Group together usage of AddAllArgs (PR #68349)

2023-10-10 Thread Fangrui Song via cfe-commits

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


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


[clang] [Driver] Group together usage of AddAllArgs (PR #68349)

2023-10-10 Thread Fangrui Song via cfe-commits

MaskRay wrote:

Replace with `AddAllArgs` with `addAllArgs` while you are changing these lines. 
Most `*Arg` options actually use the proper lower-case but some `Add*` ones are 
weird...

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


[clang] [clang][driver] Support option '-r' for target AVR (PR #68484)

2023-10-10 Thread Fangrui Song via cfe-commits

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


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


[clang] [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

2023-10-10 Thread via cfe-commits

h-vetinari wrote:

> > Because I don't know of any better way to commandeer a patch in GitHub
> 
> As a maintainer, you can push into this branch

I had reached out to @ThePhD with an offer to help on this before they opened 
this PR, and I now have push access to their fork, which means I could change 
the state of this PR.

To be clear, I cannot offer to defend the content (semantically) in the face of 
review, but - if desired - I'd be happy to help with some more routine 
operations like rebasing, formatting, or chopping off pieces into separate PRs 
(all while keeping @ThePhD's authorship, of course).

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-10 Thread Brandon Wu via cfe-commits


@@ -178,6 +178,19 @@ multiclass CustomSiFiveVCIX;
 }
 
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
+class CustomSiFiveVMACC funct6, RISCVVFormat opv, string opcodestr>
+: RVInstVCCustom2 {
+  let vm = 1;
+  let funct6_lo2 = funct6{1-0};
+}
+}
+
+multiclass CustomSiFiveVMACC funct6, RISCVVFormat opv, string 
opcodestr> {
+  def _VV : CustomSiFiveVMACC;

4vtomat wrote:

That's a good idea, I'll have a try, thanks!

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-10 Thread Shao-Ce SUN via cfe-commits


@@ -178,6 +178,19 @@ multiclass CustomSiFiveVCIX;
 }
 
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
+class CustomSiFiveVMACC funct6, RISCVVFormat opv, string opcodestr>
+: RVInstVCCustom2 {
+  let vm = 1;
+  let funct6_lo2 = funct6{1-0};
+}
+}
+
+multiclass CustomSiFiveVMACC funct6, RISCVVFormat opv, string 
opcodestr> {
+  def _VV : CustomSiFiveVMACC;

sunshaoce wrote:

I still think `4x8x4` or similar can be used instead of `VV`, but using `VV` 
can indeed avoid adding new multiclass.

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


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

2023-10-10 Thread Oskar Wirga via cfe-commits

https://github.com/oskarwirga commented:

I've reviewed the admittedly limited sections I'm familiar with and LGTM! This 
is great work :)

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


[clang-tools-extra] [Clang] Support target attr specifying CPU (PR #68678)

2023-10-10 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises updated 
https://github.com/llvm/llvm-project/pull/68678

>From 78f22a8a57f5b67660763b8c7731b9d3cddede72 Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Tue, 10 Oct 2023 17:20:00 +0800
Subject: [PATCH 1/2] [Clang] Support target attr specifying CPU

Currently targets except AArch64 cannot recognize function attribute
specifying target CPU. Make it equivalent to arch directive.
---
 clang/lib/Basic/TargetInfo.cpp | 7 ---
 clang/test/Sema/attr-target.c  | 4 
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 6cd5d618a4acaa5..474f4173eb5257d 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -560,11 +560,12 @@ ParsedTargetAttr TargetInfo::parseTargetAttr(StringRef 
Features) const {
 }
 
 // While we're here iterating check for a different target cpu.
-if (Feature.startswith("arch=")) {
+if (Feature.startswith("arch=") || Feature.startswith("cpu=")) {
+  auto [Key, CPU] = Feature.split("=");
   if (!Ret.CPU.empty())
-Ret.Duplicate = "arch=";
+Ret.Duplicate = StringRef(Key.data(), Key.size() + 1);
   else
-Ret.CPU = Feature.split("=").second.trim();
+Ret.CPU = CPU.trim();
 } else if (Feature.startswith("tune=")) {
   if (!Ret.Tune.empty())
 Ret.Duplicate = "tune=";
diff --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c
index 3416a3d0a6ba134..631e40b947ed69b 100644
--- a/clang/test/Sema/attr-target.c
+++ b/clang/test/Sema/attr-target.c
@@ -17,10 +17,14 @@ int __attribute__((target("avx,sse4.2,arch=hiss"))) 
meow(void) {  return 4; }
 int __attribute__((target("woof"))) bark(void) {  return 4; }
 // no warning, same as saying 'nothing'.
 int __attribute__((target("arch="))) turtle(void) { return 4; }
+// no warning, same as saying 'nothing'.
+int __attribute__((target("cpu="))) equus(void) { return 4; }
 //expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 
'target' attribute ignored}}
 int __attribute__((target("arch=hiss,arch=woof"))) pine_tree(void) { return 4; 
}
 //expected-warning@+1 {{duplicate 'arch=' in the 'target' attribute string; 
'target' attribute ignored}}
 int __attribute__((target("arch=ivybridge,arch=haswell"))) oak_tree(void) { 
return 4; }
+//expected-warning@+1 {{duplicate 'cpu=' in the 'target' attribute string; 
'target' attribute ignored}}
+int __attribute__((target("arch=ivybridge,cpu=haswell"))) cypress_tree(void) { 
return 4; }
 //expected-warning@+1 {{unsupported 'branch-protection' in the 'target' 
attribute string; 'target' attribute ignored}}
 int __attribute__((target("branch-protection=none"))) birch_tree(void) { 
return 5; }
 //expected-warning@+1 {{unknown tune CPU 'hiss' in the 'target' attribute 
string; 'target' attribute ignored}}

>From 69db1b10f119026c857781ee559b4e3e1b0de8af Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Wed, 11 Oct 2023 11:17:36 +0800
Subject: [PATCH 2/2] Rebase for PowerPC tests

---
 clang/test/Sema/attr-target.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c
index 72ca9887b21b016..3939f4d02744e4a 100644
--- a/clang/test/Sema/attr-target.c
+++ b/clang/test/Sema/attr-target.c
@@ -80,10 +80,14 @@ int __attribute__((target("fpmath=387"))) walrus(void) { 
return 4; }
 int __attribute__((target("float128,arch=hiss"))) meow(void) {  return 4; }
 // no warning, same as saying 'nothing'.
 int __attribute__((target("arch="))) turtle(void) { return 4; }
+// no warning, same as saying 'nothing'.
+int __attribute__((target("cpu="))) equus(void) { return 4; }
 //expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 
'target' attribute ignored}}
 int __attribute__((target("arch=hiss,arch=woof"))) pine_tree(void) { return 4; 
}
 //expected-warning@+1 {{duplicate 'arch=' in the 'target' attribute string; 
'target' attribute ignored}}
 int __attribute__((target("arch=pwr9,arch=pwr10"))) oak_tree(void) { return 4; 
}
+//expected-warning@+1 {{duplicate 'cpu=' in the 'target' attribute string; 
'target' attribute ignored}}
+int __attribute__((target("arch=pwr8,cpu=pwr9"))) cypress_tree(void) { return 
4; }
 //expected-warning@+1 {{unsupported 'branch-protection' in the 'target' 
attribute string; 'target' attribute ignored}}
 int __attribute__((target("branch-protection=none"))) birch_tree(void) { 
return 5; }
 //expected-warning@+1 {{unknown tune CPU 'hiss' in the 'target' attribute 
string; 'target' attribute ignored}}

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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-10 Thread Chen Zheng via cfe-commits


@@ -807,7 +807,7 @@ ArrayRef 
PPCTargetInfo::getGCCRegAliases() const {
 // PPC ELFABIv2 DWARF Definitoin "Table 2.26. Mappings of Common Registers".
 // vs0 ~ vs31 is mapping to 32 - 63,
 // vs32 ~ vs63 is mapping to 77 - 108.

chenzheng1030 wrote:

@hubert-reinterpretcast I think you are right. There is a legacy issue in the 
function `getNormalizedGCCRegisterName()`. Once `ReturnCanonical` is true for 
that function, current clang(without this patch) will use name f0 ~ f31 and v0 
~ v31 for vs0 ~ vs63 on ELFABIV2. And this patch extends this "issue" to AIX.

The `ReturnCanonical` was introduced in https://reviews.llvm.org/D15075 which 
was targeted for X86. Seems for X86, physically overlapping registers have 
canonical names, for example X86 ([eax|rax|al|ah] -> ax). But targets like PPC 
and SystemZ do not have such canonical register names, for example, PPC (vs0 -> 
f0), SystemZ(v0 -> f0) which are not right.

I prefer to solve this in another patch with solution: for targets that have no 
canonical name for physically overlapping registers, `ReturnCanonical` should 
always be false.

What do you think?

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


[clang] [RISCV] Support Xsfvfwmaccqqq extensions (PR #68296)

2023-10-10 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/68296

>From e5a746541509727210e5e561ecb85607939ec0f4 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Wed, 4 Oct 2023 10:23:52 -0700
Subject: [PATCH 1/4] [RISCV] Support Xsfvfwmaccqqq extensions

Bfloat16 Matrix Multiply Accumulate Instruction
https://sifive.cdn.prismic.io/sifive/c391d53e-ffcf-4091-82f6-c37bf3e883ed_xsfvfwmaccqqq-spec.pdf
---
 .../clang/Basic/riscv_sifive_vector.td|  12 ++
 .../clang/Support/RISCVVIntrinsicUtils.h  |  17 +-
 clang/lib/Sema/SemaRISCVVectorLookup.cpp  |   1 +
 .../non-overloaded/sf_vfwmacc_4x4x4.c |  57 +
 .../non-policy/overloaded/sf_vfwmacc_4x4x4.c  |  57 +
 .../policy/non-overloaded/sf_vfwmacc_4x4x4.c  |  57 +
 .../policy/overloaded/sf_vfwmacc_4x4x4.c  |  57 +
 .../test/Sema/rvv-required-features-invalid.c |   4 +
 clang/test/Sema/rvv-required-features.c   |   7 +-
 clang/utils/TableGen/RISCVVEmitter.cpp|   1 +
 llvm/include/llvm/IR/IntrinsicsRISCVXsf.td|  11 +
 llvm/lib/Support/RISCVISAInfo.cpp |   3 +
 .../RISCV/Disassembler/RISCVDisassembler.cpp  |   2 +
 llvm/lib/Target/RISCV/RISCVFeatures.td|   8 +
 llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td|  53 +
 .../CodeGen/RISCV/rvv/sf_vfwmacc_4x4x4.ll | 195 ++
 llvm/test/MC/RISCV/rvv/xsfvfwmacc.s   |  15 ++
 llvm/unittests/Support/RISCVISAInfoTest.cpp   |   1 +
 18 files changed, 549 insertions(+), 9 deletions(-)
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/non-overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/policy/overloaded/sf_vfwmacc_4x4x4.c
 create mode 100644 llvm/test/CodeGen/RISCV/rvv/sf_vfwmacc_4x4x4.ll
 create mode 100644 llvm/test/MC/RISCV/rvv/xsfvfwmacc.s

diff --git a/clang/include/clang/Basic/riscv_sifive_vector.td 
b/clang/include/clang/Basic/riscv_sifive_vector.td
index 6583a7eb7b2e59b..d9be21a2a602944 100644
--- a/clang/include/clang/Basic/riscv_sifive_vector.td
+++ b/clang/include/clang/Basic/riscv_sifive_vector.td
@@ -103,3 +103,15 @@ let SupportOverloading = false in {
 defm sf_vc_v_fvw : RVVVCIXBuiltinSet<["si"],  "UwKzUwUvFe", [-1, 0, 2, 3], 
UseGPR=0>;
   }
 }
+
+multiclass RVVVFWMACCBuiltinSet> suffixes_prototypes> {
+  let OverloadedName = NAME,
+  Name = NAME,
+  HasMasked = false,
+  Log2LMUL = [-2, -1, 0, 1, 2] in
+defm NAME : RVVOutOp1Op2BuiltinSet;
+}
+
+let UnMaskedPolicyScheme = HasPolicyOperand in
+  let RequiredFeatures = ["Xsfvfwmaccqqq"] in
+defm sf_vfwmacc_4x4x4 : RVVVFWMACCBuiltinSet<[["", "w", "wwSvv"]]>;
diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 8ba57d77221dc52..c6ce4884cdbb005 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -485,14 +485,15 @@ enum RVVRequire : uint16_t {
   RVV_REQ_RV64 = 1 << 0,
   RVV_REQ_ZvfhminOrZvfh = 1 << 1,
   RVV_REQ_Xsfvcp = 1 << 2,
-  RVV_REQ_Zvbb = 1 << 3,
-  RVV_REQ_Zvbc = 1 << 4,
-  RVV_REQ_Zvkb = 1 << 5,
-  RVV_REQ_Zvkg = 1 << 6,
-  RVV_REQ_Zvkned = 1 << 7,
-  RVV_REQ_Zvknha = 1 << 8,
-  RVV_REQ_Zvksed = 1 << 9,
-  RVV_REQ_Zvksh = 1 << 10,
+  RVV_REQ_Xsfvfwmaccqqq = 1 << 3,
+  RVV_REQ_Zvbb = 1 << 4,
+  RVV_REQ_Zvbc = 1 << 5,
+  RVV_REQ_Zvkb = 1 << 6,
+  RVV_REQ_Zvkg = 1 << 7,
+  RVV_REQ_Zvkned = 1 << 8,
+  RVV_REQ_Zvknha = 1 << 9,
+  RVV_REQ_Zvksed = 1 << 10,
+  RVV_REQ_Zvksh = 1 << 11,
 
   LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Zvksh)
 };
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index ae584dc68719901..97ebeed8ca4375d 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -205,6 +205,7 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
   static const std::pair FeatureCheckList[] = {
   {"64bit", RVV_REQ_RV64},
   {"xsfvcp", RVV_REQ_Xsfvcp},
+  {"xsfvfwmaccqqq", RVV_REQ_Xsfvfwmaccqqq},
   {"experimental-zvbb", RVV_REQ_Zvbb},
   {"experimental-zvbc", RVV_REQ_Zvbc},
   {"experimental-zvkb", RVV_REQ_Zvkb},
diff --git 
a/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
new file mode 100644
index 000..185b8f236b62a8d
--- /dev/null
+++ 
b/clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/sf_vfwmacc_4x4x4.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// REQUIRES: riscv-regi

[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-10 Thread Brandon Wu via cfe-commits

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-10 Thread Brandon Wu via cfe-commits


@@ -0,0 +1,57 @@
+# RUN: llvm-mc -triple=riscv64 -show-encoding 
--mattr=+v,+xsfvqmaccqoq,+xsfvqmaccdod %s \
+# RUN:| FileCheck %s --check-prefixes=CHECK-ENCODING,CHECK-INST
+# RUN: not llvm-mc -triple=riscv64 -show-encoding %s 2>&1 \
+# RUN:| FileCheck %s --check-prefix=CHECK-ERROR
+# RUN: llvm-mc -triple=riscv64 -filetype=obj 
--mattr=+v,+xsfvqmaccqoq,+xsfvqmaccdod %s \
+# RUN:| llvm-objdump -d --mattr=+v,+xsfvqmaccqoq,+xsfvqmaccdod - \
+# RUN:| FileCheck %s --check-prefix=CHECK-INST
+# RUN: llvm-mc -triple=riscv64 -filetype=obj 
--mattr=+v,+xsfvqmaccqoq,+xsfvqmaccdod %s \
+# RUN:| llvm-objdump -d - | FileCheck %s --check-prefix=CHECK-UNKNOWN
+
+sf.vqmaccu.2x8x2 v8, v4, v20

4vtomat wrote:

I'm not sure why we didn't define masked version of these extensions, do you 
know the reason @topperc @kito-cheng ?

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


[clang] [clang][dataflow]Use cast_or_null instead cast to prevent crash (PR #68510)

2023-10-10 Thread Qizhi Hu via cfe-commits

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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-10 Thread Brandon Wu via cfe-commits


@@ -178,6 +178,19 @@ multiclass CustomSiFiveVCIX;
 }
 
+let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
+class CustomSiFiveVMACC funct6, RISCVVFormat opv, string opcodestr>
+: RVInstVCCustom2 {
+  let vm = 1;
+  let funct6_lo2 = funct6{1-0};
+}
+}
+
+multiclass CustomSiFiveVMACC funct6, RISCVVFormat opv, string 
opcodestr> {
+  def _VV : CustomSiFiveVMACC;

4vtomat wrote:

Since `VPatVQMACC` use `VPatTernaryNoMaskWithPolicy` which defines the pseudo 
instruction matching pattern as 
`(!cast(inst#"_"#kind#"_"#vlmul.MX)` which takes `kind`, so if we 
don't define them as `_VV` we can't reuse and need to define one on our own.

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


[clang] [Clang][PowerPC] Support tune directive in target attribute (PR #68681)

2023-10-10 Thread Qiu Chaofan via cfe-commits

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


[clang] 15d78ce - [Clang][PowerPC] Support tune CPU in target attribute (#68681)

2023-10-10 Thread via cfe-commits

Author: Qiu Chaofan
Date: 2023-10-11T10:38:56+08:00
New Revision: 15d78cef3ddc9c2e00beaf7e6b1d4ba5dd232a89

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

LOG: [Clang][PowerPC] Support tune CPU in target attribute (#68681)

Added: 


Modified: 
clang/lib/Basic/Targets/PPC.h
clang/test/Sema/attr-target.c

Removed: 




diff  --git a/clang/lib/Basic/Targets/PPC.h b/clang/lib/Basic/Targets/PPC.h
index ef667b3d511f0e6..4d62673ba7fb8c5 100644
--- a/clang/lib/Basic/Targets/PPC.h
+++ b/clang/lib/Basic/Targets/PPC.h
@@ -198,6 +198,8 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
   void setFeatureEnabled(llvm::StringMap &Features, StringRef Name,
  bool Enabled) const override;
 
+  bool supportsTargetAttributeTune() const override { return true; }
+
   ArrayRef getGCCRegNames() const override;
 
   ArrayRef getGCCRegAliases() const override;

diff  --git a/clang/test/Sema/attr-target.c b/clang/test/Sema/attr-target.c
index 3416a3d0a6ba134..5328f056507a714 100644
--- a/clang/test/Sema/attr-target.c
+++ b/clang/test/Sema/attr-target.c
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -std=c2x %s
 // RUN: %clang_cc1 -triple aarch64-linux-gnu  -fsyntax-only -verify -std=c2x %s
 // RUN: %clang_cc1 -triple arm-linux-gnu  -fsyntax-only -verify -std=c2x %s
+// RUN: %clang_cc1 -triple powerpc-linux-gnu  -fsyntax-only -verify -std=c2x %s
+// RUN: %clang_cc1 -triple ppc64le-linux-gnu  -fsyntax-only -verify -std=c2x %s
 
 #ifdef __x86_64__
 
@@ -61,6 +63,28 @@ int 
__attribute__((target("tune=cortex-a710,tune=neoverse-n2"))) pear_tree(void)
 // no warning - branch-protection should work on aarch64
 int __attribute__((target("branch-protection=none"))) birch_tree(void) { 
return 5; }
 
+#elifdef __powerpc__
+
+int __attribute__((target("float128,arch=pwr9"))) foo(void) { return 4; }
+//expected-error@+1 {{'target' attribute takes one argument}}
+int __attribute__((target())) bar(void) { return 4; }
+// no warning, tune is supported for PPC
+int __attribute__((target("tune=pwr8"))) baz(void) { return 4; }
+//expected-warning@+1 {{unsupported 'fpmath=' in the 'target' attribute 
string; 'target' attribute ignored}}
+int __attribute__((target("fpmath=387"))) walrus(void) { return 4; }
+//expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 
'target' attribute ignored}}
+int __attribute__((target("float128,arch=hiss"))) meow(void) {  return 4; }
+// no warning, same as saying 'nothing'.
+int __attribute__((target("arch="))) turtle(void) { return 4; }
+//expected-warning@+1 {{unknown CPU 'hiss' in the 'target' attribute string; 
'target' attribute ignored}}
+int __attribute__((target("arch=hiss,arch=woof"))) pine_tree(void) { return 4; 
}
+//expected-warning@+1 {{duplicate 'arch=' in the 'target' attribute string; 
'target' attribute ignored}}
+int __attribute__((target("arch=pwr9,arch=pwr10"))) oak_tree(void) { return 4; 
}
+//expected-warning@+1 {{unsupported 'branch-protection' in the 'target' 
attribute string; 'target' attribute ignored}}
+int __attribute__((target("branch-protection=none"))) birch_tree(void) { 
return 5; }
+//expected-warning@+1 {{unknown tune CPU 'hiss' in the 'target' attribute 
string; 'target' attribute ignored}}
+int __attribute__((target("tune=hiss,tune=woof"))) apple_tree(void) { return 
4; }
+
 #else
 
 // tune is not supported by other targets.



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


[clang] [RISCV] Support Xsfvqmaccdod and Xsfvqmaccqoq extensions (PR #68295)

2023-10-10 Thread Brandon Wu via cfe-commits


@@ -103,3 +103,27 @@ let SupportOverloading = false in {
 defm sf_vc_v_fvw : RVVVCIXBuiltinSet<["si"],  "UwKzUwUvFe", [-1, 0, 2, 3], 
UseGPR=0>;
   }
 }
+
+multiclass RVVVQMACCBuiltinSet> suffixes_prototypes> {
+  let OverloadedName = NAME,
+  Name = NAME,
+  HasMasked = false,
+  Log2LMUL = [0, 1, 2, 3] in
+defm NAME : RVVOutOp1Op2BuiltinSet;
+}
+
+let UnMaskedPolicyScheme = HasPolicyOperand in
+  let RequiredFeatures = ["Xsfvqmaccdod"] in {
+defm sf_vqmaccu_2x8x2 : RVVVQMACCBuiltinSet<[["", "4", "44SUvUv"]]>;
+defm sf_vqmacc_2x8x2 : RVVVQMACCBuiltinSet<[["", "4", "44Svv"]]>;

4vtomat wrote:

Oh I didn't notice that modifier, thanks!

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


[clang] [clang][dataflow]Use cast_or_null instead cast to prevent crash (PR #68510)

2023-10-10 Thread Qizhi Hu via cfe-commits

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

>From 55ca8fa197e469a7c8f57d7a174c07a063eb022e Mon Sep 17 00:00:00 2001
From: huqizhi 
Date: Sun, 8 Oct 2023 16:00:29 +0800
Subject: [PATCH] [clang][analysis]Use dyn_cast_or_null instead cast to prevent
 crash

---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../absl/types/optional.h |  2 ++
 .../bugprone/unchecked-optional-access.cpp| 20 +++
 .../Models/UncheckedOptionalAccessModel.cpp   |  2 +-
 4 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c1b926b296b055a..837fd6ca1b61173 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -202,6 +202,10 @@ Changes in existing checks
   ` check, so that it does not
   warn on macros starting with underscore and lowercase letter.
 
+- Improved :doc:`bugprone-unchecked-optional-access
+  ` check, so that it 
does
+  not crash during handling of optional values.
+
 - Improved :doc:`bugprone-undefined-memory-manipulation
   ` check to support
   fixed-size arrays of non-trivial types.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/absl/types/optional.h
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/absl/types/optional.h
index 154cc262ab7cd79..3e692f347aa1ea5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/absl/types/optional.h
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/absl/types/optional.h
@@ -66,6 +66,8 @@ class optional {
   void reset() noexcept;
 
   void swap(optional &rhs) noexcept;
+
+  template  optional &operator=(const U &u);
 };
 
 } // namespace absl
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
index 1921291f2187d92..13a3ff52f3ebc59 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unchecked-optional-access.cpp
@@ -180,3 +180,23 @@ void std_forward_rvalue_ref_safe(absl::optional&& 
opt) {
 
   std::forward>(opt).value();
 }
+
+namespace std {
+
+template  class vector {
+public:
+  T &operator[](unsigned long index);
+  bool empty();
+};
+
+} // namespace std
+
+struct S {
+  absl::optional x;
+};
+std::vector vec;
+
+void foo() {
+  if (!vec.empty())
+vec[0].x = 0;
+}
diff --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index f61f26ff27804ec..8bd9a030f50cda0 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -599,7 +599,7 @@ void transferAssignment(const CXXOperatorCallExpr *E, 
BoolValue &HasValueVal,
 LatticeTransferState &State) {
   assert(E->getNumArgs() > 0);
 
-  if (auto *Loc = cast(
+  if (auto *Loc = cast_or_null(
   State.Env.getStorageLocation(*E->getArg(0 {
 createOptionalValue(*Loc, HasValueVal, State.Env);
 

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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-10 Thread Chen Zheng via cfe-commits

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


[clang] [clang][driver] Support option '-r' for target AVR (PR #68484)

2023-10-10 Thread Ben Shi via cfe-commits

https://github.com/benshi001 updated 
https://github.com/llvm/llvm-project/pull/68484

>From 329c4e231a2d039bec48699058e615da3fa3a6e8 Mon Sep 17 00:00:00 2001
From: Ben Shi 
Date: Sat, 7 Oct 2023 20:49:36 +0800
Subject: [PATCH] [clang][driver] Support option '-r' for target AVR

If '-r' is specified with target AVR:

1. Do not link to the avr-libc.
2. Do not emit some conflict options.
3. Do not emit any sub-target related address information/warning.
---
 clang/lib/Driver/ToolChains/AVR.cpp | 37 -
 clang/test/Driver/avr-ld.c  | 28 ++
 2 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/AVR.cpp 
b/clang/lib/Driver/ToolChains/AVR.cpp
index 81f501d417345d1..e312fa155e11bf8 100644
--- a/clang/lib/Driver/ToolChains/AVR.cpp
+++ b/clang/lib/Driver/ToolChains/AVR.cpp
@@ -457,7 +457,8 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   CmdArgs.push_back(Output.getFilename());
 
   // Enable garbage collection of unused sections.
-  CmdArgs.push_back("--gc-sections");
+  if (!Args.hasArg(options::OPT_r))
+CmdArgs.push_back("--gc-sections");
 
   // Add library search paths before we specify libraries.
   Args.AddAllArgs(CmdArgs, options::OPT_L);
@@ -471,7 +472,7 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
   // Only add default libraries if the user hasn't explicitly opted out.
   bool LinkStdlib = false;
-  if (!Args.hasArg(options::OPT_nostdlib) &&
+  if (!Args.hasArg(options::OPT_nostdlib) && !Args.hasArg(options::OPT_r) &&
   !Args.hasArg(options::OPT_nodefaultlibs)) {
 if (!CPU.empty()) {
   if (!FamilyName) {
@@ -497,13 +498,17 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
   D.Diag(diag::warn_drv_avr_stdlib_not_linked);
   }
 
-  if (SectionAddressData) {
-CmdArgs.push_back(
-Args.MakeArgString("--defsym=__DATA_REGION_ORIGIN__=0x" +
-   Twine::utohexstr(*SectionAddressData)));
-  } else {
-// We do not have an entry for this CPU in the address mapping table yet.
-D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented) << CPU;
+  if (!Args.hasArg(options::OPT_r)) {
+if (SectionAddressData) {
+  CmdArgs.push_back(
+  Args.MakeArgString("--defsym=__DATA_REGION_ORIGIN__=0x" +
+ Twine::utohexstr(*SectionAddressData)));
+} else {
+  // We do not have an entry for this CPU in the address mapping table
+  // yet.
+  D.Diag(diag::warn_drv_avr_linker_section_addresses_not_implemented)
+  << CPU;
+}
   }
 
   if (D.isUsingLTO()) {
@@ -554,17 +559,17 @@ void AVR::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 
 if (Args.hasFlag(options::OPT_mrelax, options::OPT_mno_relax, true))
   CmdArgs.push_back("--relax");
-
-// Specify the family name as the emulation mode to use.
-// This is almost always required because otherwise avr-ld
-// will assume 'avr2' and warn about the program being larger
-// than the bare minimum supports.
-if (Linker.find("avr-ld") != std::string::npos)
-  CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
   } else {
 AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
   }
 
+  // Specify the family name as the emulation mode to use.
+  // This is almost always required because otherwise avr-ld
+  // will assume 'avr2' and warn about the program being larger
+  // than the bare minimum supports.
+  if (Linker.find("avr-ld") != std::string::npos && FamilyName)
+CmdArgs.push_back(Args.MakeArgString(std::string("-m") + *FamilyName));
+
   C.addCommand(std::make_unique(
   JA, *this, ResponseFileSupport::AtFileCurCP(), 
Args.MakeArgString(Linker),
   CmdArgs, Inputs, Output));
diff --git a/clang/test/Driver/avr-ld.c b/clang/test/Driver/avr-ld.c
index 4042ecb89adf5f1..0f12607fe9d69eb 100644
--- a/clang/test/Driver/avr-ld.c
+++ b/clang/test/Driver/avr-ld.c
@@ -57,3 +57,31 @@
 // RUN: %clang -### --target=avr -mmcu=atmega328 -fuse-ld=lld -flto --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKS %s
 // LINKS: {{".*ld.*"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x800100" 
"-plugin-opt=mcpu=atmega328"
 // LINKS-NOT: "-plugin-opt=thinlto"
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKU %s
+// LINKU: {{".*ld.*"}} {{.*}} "-r" {{.*}} "-mavr5"
+// LINKU-NOT: "--gc-sections"
+// LINKU-NOT: "--defsym
+// LINKU-NOT: "-l
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 -fuse-ld=lld --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKV %s
+// LINKV: {{".*ld.*"}} {{.*}} "-r"
+// LINKV-NOT: "--gc-sections"
+// LINKV-NOT: "--defsym
+// LINKV-NOT: "-l
+// LINKV-NOT: "-m
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 -lm --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileC

[clang] [clang][dataflow]Use cast_or_null instead cast to prevent crash (PR #68510)

2023-10-10 Thread Qizhi Hu via cfe-commits

jcsxky wrote:

> Thanks for this fix! Unfortunately, I wasn't able to repro the crash in 
> godbolt: https://godbolt.org/z/s741z5djY. Can you double check that the check 
> crashes on that example without your fix?

The test case is different from that in this patch. Use `float` in `optional`.

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


[clang] [RISCV] Fix wrong implication for zvknhb. (PR #66860)

2023-10-10 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/66860

>From 3c28f7bace91dc4edd5e87b9f1a36d100cf38318 Mon Sep 17 00:00:00 2001
From: 4vtomat 
Date: Tue, 19 Sep 2023 23:06:01 -0700
Subject: [PATCH 1/3] [RISCV] Fix wrong implication for zvknhb.

---
 clang/include/clang/Basic/riscv_vector.td|  9 -
 .../include/clang/Support/RISCVVIntrinsicUtils.h |  5 +++--
 clang/lib/Sema/SemaRISCVVectorLookup.cpp |  1 +
 clang/test/Sema/zvk-invalid-zvknha.c | 11 +++
 clang/utils/TableGen/RISCVVEmitter.cpp   |  1 +
 llvm/lib/Support/RISCVISAInfo.cpp|  2 --
 llvm/lib/Target/RISCV/RISCVFeatures.td   | 16 +++-
 llvm/lib/Target/RISCV/RISCVInstrInfoZvk.td   | 16 +++-
 llvm/test/CodeGen/RISCV/attributes.ll| 16 
 llvm/test/CodeGen/RISCV/rvv/vsha2ch.ll   |  6 ++
 llvm/test/CodeGen/RISCV/rvv/vsha2cl.ll   |  6 ++
 llvm/test/CodeGen/RISCV/rvv/vsha2ms.ll   |  6 ++
 llvm/test/MC/RISCV/attribute-arch.s  |  8 
 llvm/test/MC/RISCV/rvv/zvknh.s   |  6 +++---
 14 files changed, 79 insertions(+), 30 deletions(-)
 create mode 100644 clang/test/Sema/zvk-invalid-zvknha.c

diff --git a/clang/include/clang/Basic/riscv_vector.td 
b/clang/include/clang/Basic/riscv_vector.td
index 60a1a2b2be6fb40..8d9c4237e59bf9f 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -2997,8 +2997,15 @@ let UnMaskedPolicyScheme = HasPolicyOperand, HasMasked = 
false in {
 defm vaesz   : RVVOutBuiltinSetZvk;
   }
 
-  // zvknha or zvknhb
+  // zvknha
   let RequiredFeatures = ["Zvknha"] in {
+defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"i">;
+defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"i">;
+defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"i">;
+  }
+
+  // zvknhb
+  let RequiredFeatures = ["Zvknhb"] in {
 defm vsha2ch : RVVOutOp2BuiltinSetVVZvk<"il">;
 defm vsha2cl : RVVOutOp2BuiltinSetVVZvk<"il">;
 defm vsha2ms : RVVOutOp2BuiltinSetVVZvk<"il">;
diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h 
b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 8ba57d77221dc52..b703259a777ec85 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -491,8 +491,9 @@ enum RVVRequire : uint16_t {
   RVV_REQ_Zvkg = 1 << 6,
   RVV_REQ_Zvkned = 1 << 7,
   RVV_REQ_Zvknha = 1 << 8,
-  RVV_REQ_Zvksed = 1 << 9,
-  RVV_REQ_Zvksh = 1 << 10,
+  RVV_REQ_Zvknhb = 1 << 9,
+  RVV_REQ_Zvksed = 1 << 10,
+  RVV_REQ_Zvksh = 1 << 11,
 
   LLVM_MARK_AS_BITMASK_ENUM(RVV_REQ_Zvksh)
 };
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp 
b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index ae584dc68719901..cf5c074761e017e 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -211,6 +211,7 @@ void RISCVIntrinsicManagerImpl::ConstructRVVIntrinsics(
   {"experimental-zvkg", RVV_REQ_Zvkg},
   {"experimental-zvkned", RVV_REQ_Zvkned},
   {"experimental-zvknha", RVV_REQ_Zvknha},
+  {"experimental-zvknhb", RVV_REQ_Zvknhb},
   {"experimental-zvksed", RVV_REQ_Zvksed},
   {"experimental-zvksh", RVV_REQ_Zvksh}};
 
diff --git a/clang/test/Sema/zvk-invalid-zvknha.c 
b/clang/test/Sema/zvk-invalid-zvknha.c
new file mode 100644
index 000..0ce2e321a175f5f
--- /dev/null
+++ b/clang/test/Sema/zvk-invalid-zvknha.c
@@ -0,0 +1,11 @@
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature 
+experimental-zvknha %s -fsyntax-only -verify
+
+#include 
+
+void test_zvk_features() {
+  // zvknhb
+  __riscv_vsha2ch_vv_u64m1(); // expected-error {{call to undeclared function 
'__riscv_vsha2ch_vv_u64m1'; ISO C99 and later do not support implicit function 
declarations}}
+  __riscv_vsha2cl_vv_u64m1(); // expected-error {{call to undeclared function 
'__riscv_vsha2cl_vv_u64m1'; ISO C99 and later do not support implicit function 
declarations}}
+  __riscv_vsha2ms_vv_u64m1(); // expected-error {{call to undeclared function 
'__riscv_vsha2ms_vv_u64m1'; ISO C99 and later do not support implicit function 
declarations}}
+}
diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp 
b/clang/utils/TableGen/RISCVVEmitter.cpp
index 41025926058ed07..368136208d9a751 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -662,6 +662,7 @@ void RVVEmitter::createRVVIntrinsics(
   .Case("Zvkg", RVV_REQ_Zvkg)
   .Case("Zvkned", RVV_REQ_Zvkned)
   .Case("Zvknha", RVV_REQ_Zvknha)
+  .Case("Zvknhb", RVV_REQ_Zvknhb)
   .Case("Zvksed", RVV_REQ_Zvksed)
   .Case("Zvksh", RVV_REQ_Zvksh)
   .De

[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-10 Thread Chen Zheng via cfe-commits


@@ -807,7 +807,7 @@ ArrayRef 
PPCTargetInfo::getGCCRegAliases() const {
 // PPC ELFABIv2 DWARF Definitoin "Table 2.26. Mappings of Common Registers".
 // vs0 ~ vs31 is mapping to 32 - 63,
 // vs32 ~ vs63 is mapping to 77 - 108.

chenzheng1030 wrote:

FP and VMX registers should have different DWARF number with VSX registers 
although on PPC they are physically overlapped.

Let me check the usage for the DWARF numbers...

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


[clang] [clang][dataflow]Use cast_or_null instead cast to prevent crash (PR #68510)

2023-10-10 Thread Qizhi Hu via cfe-commits


@@ -180,3 +180,44 @@ void std_forward_rvalue_ref_safe(absl::optional&& 
opt) {
 
   std::forward>(opt).value();
 }
+
+namespace std {
+
+template
+class optional {
+public:
+   template 
+  optional& operator=(const U &u){

jcsxky wrote:

Using `absl::optional` would produce a compilation error.

```cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/unchecked-optional-access/absl/types/optional.h:32:7:
 note: candidate function (the implicit copy assignment operator) not viable: 
no known conversion from 'int' to 'const optional' for 1st argument
   32 | class optional {
  |   ^~~~
```

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


[clang] [RISCV] Fix wrong implication for zvknhb. (PR #66860)

2023-10-10 Thread Brandon Wu via cfe-commits


@@ -1013,7 +1013,6 @@ static const char *ImpliedExtsZvfhmin[] = {"zve32f"};
 static const char *ImpliedExtsZvkn[] = {"zvkb", "zvkned", "zvknhb", "zvkt"};
 static const char *ImpliedExtsZvknc[] = {"zvbc", "zvkn"};
 static const char *ImpliedExtsZvkng[] = {"zvkg", "zvkn"};
-static const char *ImpliedExtsZvknhb[] = {"zvknha"};

4vtomat wrote:

Oh I missed it, thanks!

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


[clang] a157e79 - [FlowSensitive] Stop including llvm/ADT/Any.h (NFC)

2023-10-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-10-10T18:57:18-07:00
New Revision: a157e79dd207d72aea1d42953c61f14790d847c1

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

LOG: [FlowSensitive] Stop including llvm/ADT/Any.h (NFC)

DataflowAnalysis.h doesn't use Any.

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index dd1a685cb48ba2d..c5f14cfcd4f7bee 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -28,7 +28,6 @@
 #include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/WatchedLiteralsSolver.h"
-#include "llvm/ADT/Any.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include "llvm/ADT/SmallVector.h"



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


[clang] d12ece2 - [CodeGen] Use a range-based for loop (NFC)

2023-10-10 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-10-10T18:57:16-07:00
New Revision: d12ece2ecbb6065797c826c2e70d8f8a642b8eb0

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

LOG: [CodeGen] Use a range-based for loop (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 30683ad474cd2c0..e10617162733bba 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -675,7 +675,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
 AllImports.insert(M);
   // Ones that we import in the global module fragment or the private module
   // fragment.
-  llvm::for_each(Primary->submodules(), [&AllImports](Module *SubM) {
+  for (Module *SubM : Primary->submodules()) {
 assert((SubM->isGlobalModule() || SubM->isPrivateModule()) &&
"The sub modules of C++20 module unit should only be global module "
"fragments or private module framents.");
@@ -684,7 +684,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
"not allowed to export import modules.");
 for (Module *M : SubM->Imports)
   AllImports.insert(M);
-  });
+  }
 
   SmallVector ModuleInits;
   for (Module *M : AllImports) {



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


[clang] [AIX] recognize vsr in inline asm for AIX (PR #68476)

2023-10-10 Thread Chen Zheng via cfe-commits


@@ -828,10 +829,7 @@ const TargetInfo::AddlRegName GCCAddlRegNames[] = {
 };
 
 ArrayRef PPCTargetInfo::getGCCAddlRegNames() const {
-  if (ABI == "elfv2")
-return llvm::ArrayRef(GCCAddlRegNames);
-  else
-return TargetInfo::getGCCAddlRegNames();
+  return llvm::ArrayRef(GCCAddlRegNames);

chenzheng1030 wrote:

Accepting an non-exist(future defined) register in the asm clobber list should 
not cause any issue in the compiler side, I think. The register allocator can 
not allocate these future defined registers anyhow.

The more serious issue is that clang accepts vsx instructions in asm block even 
for targets that does not have VSX, see https://godbolt.org/z/rYnMbPPTE (gcc 
has same behavior.)

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


[clang] [Clang][PowerPC] Support tune directive in target attribute (PR #68681)

2023-10-10 Thread Chen Zheng via cfe-commits

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

Make sense to me. Thanks.

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


[PATCH] D159351: [Sema] Change order of displayed overloads in diagnostics

2023-10-10 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

You say "attempts to be a strict weak order" does that mean there are still 
cases which will cause an assert or are we not sure?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D159351

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


[PATCH] D86310: [X86] Align i128 to 16 bytes in x86 datalayouts

2023-10-10 Thread Harald van Dijk via Phabricator via cfe-commits
hvdijk added a comment.

In D86310#4653550 , @tmgross wrote:

> Probably would be good to add https://bugs.llvm.org/show_bug.cgi?id=50198 to 
> the test suite if it isn't there already.

That test would not work as an LLVM test directly, but we do already have lit 
tests that cover that, the test changes in here show the fixed alignment of 
f128 too.

This was ready to push pending @efriedma's approval, who rightly pointed out a 
release note was missing but it was otherwise okay. With the release note now 
added, I think that there is nothing stopping this from being pushed, so I 
intend to do so once I am able to rebase one hopefully last time and re-run 
tests to verify no new tests have been added that also require an update. 
Thanks for the feedback, everyone.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D86310

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


[PATCH] D140925: [CMake] Use Clang to infer the target triple

2023-10-10 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added inline comments.



Comment at: runtimes/CMakeLists.txt:167
 
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  set(CXX_TARGET_TRIPLE ${CMAKE_CXX_COMPILER} --target=${LLVM_RUNTIME_TRIPLE} 
-print-target-triple)

ldionne wrote:
> Is there any reason why you're carving out Apple here? Is it because 
> `-print-target-triple` doesn't work properly on that platform (I think this 
> rings a bell).
> 
> Anyway, this is non-blocking.
I think it's cos `LLVM_PER_TARGET_RUNTIME_DIR` is not supported for Apple 
platforms in general. I see a bunch of similar conditionals in other parts of 
compiler-rt.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140925

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


[PATCH] D140925: [CMake] Use Clang to infer the target triple

2023-10-10 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision.
ldionne added inline comments.
This revision is now accepted and ready to land.



Comment at: runtimes/CMakeLists.txt:167
 
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  set(CXX_TARGET_TRIPLE ${CMAKE_CXX_COMPILER} --target=${LLVM_RUNTIME_TRIPLE} 
-print-target-triple)

Is there any reason why you're carving out Apple here? Is it because 
`-print-target-triple` doesn't work properly on that platform (I think this 
rings a bell).

Anyway, this is non-blocking.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140925

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


[PATCH] D155688: [PATCH] [llvm] [InstCombine] Canonicalise ADD+GEP

2023-10-10 Thread Fei Peng via Phabricator via cfe-commits
fiigii added a comment.

That would be fine. Thanks for explaining.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155688

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


[clang] [clang] static operators should evaluate object argument (PR #68485)

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


@@ -5536,10 +5538,24 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, 
const CGCallee &OrigCallee
 break;
   }
 }
+
+if (const auto *MD =
+dyn_cast_if_present(OCE->getCalleeDecl());
+MD && MD->isStatic())
+  StaticOperator = true;
   }
 
-  EmitCallArgs(Args, dyn_cast(FnType), E->arguments(),
-   E->getDirectCallee(), /*ParamsToSkip*/ 0, Order);
+  if (StaticOperator) {
+// If we're calling a static operator, we need to emit the object argument
+// and ignore it.
+EmitIgnoredExpr(E->getArg(0));
+
+EmitCallArgs(Args, dyn_cast(FnType),
+ drop_begin(E->arguments(), 1), E->getDirectCallee(),
+ /*ParamsToSkip*/ 0, Order);
+  } else
+EmitCallArgs(Args, dyn_cast(FnType), E->arguments(),
+ E->getDirectCallee(), /*ParamsToSkip*/ 0, Order);

shafik wrote:

nit
```suggestion
 E->getDirectCallee(), /*ParamsToSkip=*/0, Order);
```

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


[clang] [clang] static operators should evaluate object argument (PR #68485)

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


@@ -7806,7 +7806,8 @@ class ExprEvaluatorBase
   // Overloaded operator calls to member functions are represented as 
normal
   // calls with '*this' as the first argument.
   const CXXMethodDecl *MD = dyn_cast(FD);
-  if (MD && MD->isImplicitObjectMemberFunction()) {
+  if (MD &&
+  (MD->isImplicitObjectMemberFunction() || (OCE && MD->isStatic( {

shafik wrote:

So in the static case, what value do we expect `ThisVal` to have and does that 
have consequences that the code after this is prepared for?

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


[clang] [clang] static operators should evaluate object argument (PR #68485)

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


@@ -5536,10 +5538,24 @@ RValue CodeGenFunction::EmitCall(QualType CalleeType, 
const CGCallee &OrigCallee
 break;
   }
 }
+
+if (const auto *MD =
+dyn_cast_if_present(OCE->getCalleeDecl());
+MD && MD->isStatic())
+  StaticOperator = true;
   }
 
-  EmitCallArgs(Args, dyn_cast(FnType), E->arguments(),
-   E->getDirectCallee(), /*ParamsToSkip*/ 0, Order);
+  if (StaticOperator) {
+// If we're calling a static operator, we need to emit the object argument
+// and ignore it.
+EmitIgnoredExpr(E->getArg(0));
+
+EmitCallArgs(Args, dyn_cast(FnType),
+ drop_begin(E->arguments(), 1), E->getDirectCallee(),
+ /*ParamsToSkip*/ 0, Order);

shafik wrote:

nit
```suggestion
 /*ParamsToSkip=*/0, Order);
```

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


[clang] [analyzer] Compute length of string literal initializers (#66990) (PR #68368)

2023-10-10 Thread Gábor Horváth via cfe-commits

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


[clang] 4df7496 - [analyzer] Compute length of string literal initializers (#66990) (#68368)

2023-10-10 Thread via cfe-commits

Author: luamfb
Date: 2023-10-10T16:08:18-07:00
New Revision: 4df74963ea0f6c8650d5837ab52e3cdcf1dcf016

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

LOG: [analyzer] Compute length of string literal initializers (#66990) (#68368)

Fix issue https://github.com/llvm/llvm-project/issues/66990

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/test/Analysis/string.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index f1539f2733298d9..b1bc98e93a27995 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -930,9 +930,23 @@ SVal CStringChecker::getCStringLength(CheckerContext &C, 
ProgramStateRef &state,
 const StringLiteral *strLit = cast(MR)->getStringLiteral();
 return svalBuilder.makeIntVal(strLit->getLength(), sizeTy);
   }
+  case MemRegion::NonParamVarRegionKind: {
+// If we have a global constant with a string literal initializer,
+// compute the initializer's length.
+const VarDecl *Decl = cast(MR)->getDecl();
+if (Decl->getType().isConstQualified() && Decl->hasGlobalStorage()) {
+  if (const Expr *Init = Decl->getInit()) {
+if (auto *StrLit = dyn_cast(Init)) {
+  SValBuilder &SvalBuilder = C.getSValBuilder();
+  QualType SizeTy = SvalBuilder.getContext().getSizeType();
+  return SvalBuilder.makeIntVal(StrLit->getLength(), SizeTy);
+}
+  }
+}
+[[fallthrough]];
+  }
   case MemRegion::SymbolicRegionKind:
   case MemRegion::AllocaRegionKind:
-  case MemRegion::NonParamVarRegionKind:
   case MemRegion::ParamVarRegionKind:
   case MemRegion::FieldRegionKind:
   case MemRegion::ObjCIvarRegionKind:

diff  --git a/clang/test/Analysis/string.c b/clang/test/Analysis/string.c
index d369ee9f7d854a1..d47de9db8228e57 100644
--- a/clang/test/Analysis/string.c
+++ b/clang/test/Analysis/string.c
@@ -97,6 +97,29 @@ void strlen_constant2(char x) {
   clang_analyzer_eval(strlen(a) == 3); // expected-warning{{UNKNOWN}}
 }
 
+const char *const global_str_ptr = "abcd";
+const char global_str_arr[] = "efgh";
+const char *global_non_const_ptr1 = "ijk";
+char *global_non_const_ptr2 = "lmn";
+char global_non_const_arr[] = "op";
+
+void strlen_global_constant_ptr(void) {
+  clang_analyzer_eval(strlen(global_str_ptr) == 4); // expected-warning{{TRUE}}
+}
+
+void strlen_global_constant_arr(void) {
+  clang_analyzer_eval(strlen(global_str_arr) == 4); // expected-warning{{TRUE}}
+}
+
+void strlen_global_non_const_ptr(void) {
+  clang_analyzer_eval(strlen(global_non_const_ptr1) == 3); // 
expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(strlen(global_non_const_ptr2) == 3); // 
expected-warning{{UNKNOWN}}
+}
+
+void strlen_global_non_const_arr(void) {
+  clang_analyzer_eval(strlen(global_non_const_arr) == 2); // 
expected-warning{{UNKNOWN}}
+}
+
 size_t strlen_null(void) {
   return strlen(0); // expected-warning{{Null pointer passed as 1st argument 
to string length function}}
 }



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


[clang] [clang][driver] Support option '-r' for target AVR (PR #68484)

2023-10-10 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang][driver] Support option '-r' for target AVR (PR #68484)

2023-10-10 Thread Fangrui Song via cfe-commits


@@ -57,3 +57,30 @@
 // RUN: %clang -### --target=avr -mmcu=atmega328 -fuse-ld=lld -flto --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKS %s
 // LINKS: {{".*ld.*"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x800100" 
"-plugin-opt=mcpu=atmega328"
 // LINKS-NOT: "-plugin-opt=thinlto"
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKU %s
+// LINKU: {{".*ld.*"}} {{.*}} "-r" {{.*}} "-mavr5"
+// LINKU-NOT: "--gc-sections"
+// LINKU-NOT: {{"--defsym.*"}}
+// LINKU-NOT: {{"-l.*"}}
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 -fuse-ld=lld --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKV %s
+// LINKV: {{".*ld.*"}} {{.*}} "-r"
+// LINKV-NOT: "--gc-sections"
+// LINKV-NOT: {{"--defsym.*"}}
+// LINKV-NOT: {{"-l.*"}}
+// LINKV-NOT: {{"-m.*"}}
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 -lm --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKW %s
+// LINKW: {{".*ld.*"}} {{.*}} "-r" "-lm" {{.*}} "-mavr5"
+// LINKW-NOT: "--gc-sections"
+// LINKW-NOT: {{"--defsym.*"}}

MaskRay wrote:

`// LINKW-NOT: "--defsym`

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


[clang] [clang][driver] Support option '-r' for target AVR (PR #68484)

2023-10-10 Thread Fangrui Song via cfe-commits


@@ -57,3 +57,30 @@
 // RUN: %clang -### --target=avr -mmcu=atmega328 -fuse-ld=lld -flto --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck -check-prefix LINKS %s
 // LINKS: {{".*ld.*"}} {{.*}} "--defsym=__DATA_REGION_ORIGIN__=0x800100" 
"-plugin-opt=mcpu=atmega328"
 // LINKS-NOT: "-plugin-opt=thinlto"
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKU %s
+// LINKU: {{".*ld.*"}} {{.*}} "-r" {{.*}} "-mavr5"
+// LINKU-NOT: "--gc-sections"
+// LINKU-NOT: {{"--defsym.*"}}
+// LINKU-NOT: {{"-l.*"}}
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 -fuse-ld=lld --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKV %s
+// LINKV: {{".*ld.*"}} {{.*}} "-r"
+// LINKV-NOT: "--gc-sections"
+// LINKV-NOT: {{"--defsym.*"}}
+// LINKV-NOT: {{"-l.*"}}
+// LINKV-NOT: {{"-m.*"}}
+
+// RUN: %clang -### -r --target=avr -mmcu=atmega328 -lm --sysroot 
%S/Inputs/basic_avr_tree %s 2>&1 | FileCheck --check-prefix=LINKW %s
+// LINKW: {{".*ld.*"}} {{.*}} "-r" "-lm" {{.*}} "-mavr5"
+// LINKW-NOT: "--gc-sections"
+// LINKW-NOT: {{"--defsym.*"}}
+
+// RUN: %clang -### -r --target=avr --sysroot %S/Inputs/basic_avr_tree %s 2>&1 
| FileCheck --check-prefix=LINKX %s
+// LINKX: {{".*ld.*"}} {{.*}} "-r" {{.*}}
+// LINKX-NOT: warning: {{.*}} standard library

MaskRay wrote:

Use `-Werror` to test there are no warnings. `-###` exits with 1 when there is 
an error. Delete `-NOT: warning` patterns.

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


[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

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


@@ -3605,8 +3605,11 @@ static QualType 
GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
 Info = &SemaRef.InventedParameterInfos.back();
   } else {
 // In C++14, generic lambdas allow 'auto' in their parameters.
-if (!SemaRef.getLangOpts().CPlusPlus14 || !Auto ||
-Auto->getKeyword() != AutoTypeKeyword::Auto) {
+if (!SemaRef.getLangOpts().CPlusPlus14 && Auto &&
+Auto->getKeyword() == AutoTypeKeyword::Auto) {
+  Error = 24;

shafik wrote:

A lot of the other cases have comments explaining what diagnostic the code 
pertains to. See 20 or 7 below for example. 

This is not really great but at least we have a guide to which diagnostic we 
intend to emit.

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-10 Thread via cfe-commits

sr-tream wrote:

In force-push fixed clangd crash when hovered forward-declared types

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


[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-10-10 Thread via cfe-commits

https://github.com/sr-tream updated 
https://github.com/llvm/llvm-project/pull/67213

>From 678bca64870bdc58882e242696ff548f96a5ec09 Mon Sep 17 00:00:00 2001
From: SR_team 
Date: Sat, 23 Sep 2023 03:49:23 +0300
Subject: [PATCH] [clangd] Show alignment for records and fields decls

---
 clang-tools-extra/clangd/Hover.cpp|  5 +
 clang-tools-extra/clangd/Hover.h  |  2 ++
 clang-tools-extra/clangd/unittests/HoverTests.cpp | 11 +++
 3 files changed, 18 insertions(+)

diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 0ec85fc24df151b..ddb188218cc274c 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1001,6 +1001,8 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
   if (auto *RD = llvm::dyn_cast(&ND)) {
 if (auto Size = Ctx.getTypeSizeInCharsIfKnown(RD->getTypeForDecl()))
   HI.Size = Size->getQuantity() * 8;
+if (!RD->isDependentType() && RD->isCompleteDefinition())
+  HI.Align = Ctx.getTypeAlign(RD->getTypeForDecl());
 return;
   }
 
@@ -1009,6 +1011,7 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
 if (Record)
   Record = Record->getDefinition();
 if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
+  HI.Align = Ctx.getTypeAlign(FD->getType());
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Record);
   HI.Offset = Layout.getFieldOffset(FD->getFieldIndex());
   if (FD->isBitField())
@@ -1488,6 +1491,8 @@ markup::Document HoverInfo::present() const {
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
   }
+  if (Align)
+Output.addParagraph().appendText("Align: " + formatSize(*Align));
 
   if (CalleeArgInfo) {
 assert(CallPassType);
diff --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h
index 6a61100912918ea..fe689de44732ebe 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -97,6 +97,8 @@ struct HoverInfo {
   std::optional Offset;
   /// Contains the padding following a field within the enclosing class.
   std::optional Padding;
+  /// Contains the alignment of fields and types where it's interesting.
+  std::optional Align;
   // Set when symbol is inside function call. Contains information extracted
   // from the callee definition about the argument this is passed as.
   std::optional CalleeArgInfo;
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 8c88cd52574536c..c5623759a7c2041 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -92,6 +92,7 @@ TEST(Hover, Structured) {
  HI.Offset = 0;
  HI.Size = 8;
  HI.Padding = 56;
+ HI.Align = 8;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -110,6 +111,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Size = 8;
  HI.Padding = 120;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -128,6 +130,7 @@ TEST(Hover, Structured) {
  HI.Type = "int";
  HI.Offset = 0;
  HI.Size = 1;
+ HI.Align = 32;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -192,6 +195,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Offset = 0;
  HI.Size = 8;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -204,6 +208,7 @@ TEST(Hover, Structured) {
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
  HI.Size = 8;
+ HI.Align = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1375,6 +1380,7 @@ class Foo final {})cpp";
  HI.Offset = 8;
  HI.Size = 1;
  HI.Padding = 23;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}}};
   for (const auto &Case : Cases) {
@@ -1411,6 +1417,7 @@ class Foo final {})cpp";
 EXPECT_EQ(H->Value, Expected.Value);
 EXPECT_EQ(H->Size, Expected.Size);
 EXPECT_EQ(H->Offset, Expected.Offset);
+EXPECT_EQ(H->Align, Expected.Align);
 EXPECT_EQ(H->AccessSpecifier, Expected.AccessSpecifier);
 EXPECT_EQ(H->CalleeArgInfo, Expected.CalleeArgInfo);
 EXPECT_EQ(H->CallPassType, Expected.CallPassType);
@@ -3448,6 +3455,7 @@ template  class Foo {})",
 HI.Size = 32;
 HI.Offset = 96;
 HI.Padding = 32;
+HI.Align = 32;
   },
   R"(field foo
 
@@ -3455,6 +3463,7 @@ Type: type (aka can_type)
 Value = value
 Offset: 12 bytes
 Size: 4 bytes (+4 bytes padding)
+Align: 4 bytes
 
 // In test::Bar
 def)",
@@ -3470,6 +3479,7 @@ def)",
 HI.Size = 25;
 HI.Offset = 35;
 HI.Padding = 4

[libunwind] [libunwind] Fix running tests with MSan (PR #67860)

2023-10-10 Thread Louis Dionne via cfe-commits


@@ -115,6 +121,18 @@ extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, 
unw_word_t) LIBUNWIND_AVAIL
 extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t)  
LIBUNWIND_AVAIL;
 extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL;
 
+#ifdef LIBUNWIND_HAVE_MSAN
+// unw_getcontext is implemented in assembly so it is rather difficult to
+// mark the MSan shadow as initialized from within the function. Instead we
+// use a macro wrapper when compiling with MSan to avoid false-positives.
+#define unw_getcontext(context)
\

ldionne wrote:

I think what I had in mind was something like:

```
extern "C" int __unw_getcontext(unw_context_t *);

inline int unw_getcontext(unw_context_t *ctx) {
  // do stuff
  return __unw_getcontext(ctx);
}
```

I am having a bit of trouble tracking down how `unw_getcontext` is implemented 
right now, but IIUC it's only an alias to `__unw_getcontext`, is that right? If 
so, I think the `inline` approach here would work, I think?

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


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

2023-10-10 Thread Bill Wendling via cfe-commits

https://github.com/bwendling updated 
https://github.com/llvm/llvm-project/pull/68750

>From b7b0c40542589e9c54c21140dbb5b163dd8ffc7b Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Wed, 4 Oct 2023 17:55:49 -0700
Subject: [PATCH 1/2] [Clang] Implement the 'counted_by' attribute

The 'counted_by' attribute is used on flexible array members. The
argument for the attribute is the name of the field member in the same
structure holding the count of elements in the flexible array. This
information can be used to improve the results of the array bound sanitizer
and the '__builtin_dynamic_object_size' builtin.

This example specifies the that the flexible array member 'array' has the
number of elements allocated for it in 'count':

  struct bar;
  struct foo {
size_t count;
 /* ... */
struct bar *array[] __attribute__((counted_by(count)));
  };

This establishes a relationship between 'array' and 'count', specifically
that 'p->array' must have *at least* 'p->count' number of elements available.
It's the user's responsibility to ensure that this relationship is maintained
through changes to the structure.

In the following, the allocated array erroneously has fewer elements than
what's specified by 'p->count'. This would result in an out-of-bounds access not
not being detected:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

The next example updates 'p->count', breaking the relationship requirement that
'p->array' must have at least 'p->count' number of elements available:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

  void use_foo(int index) {
p->count += 42;
p->array[index] = 0; /* The sanitizer cannot properly check this access */
  }

Reviewed By: nickdesaulniers, aaron.ballman

Differential Revision: https://reviews.llvm.org/D148381
---
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/AST/Decl.h|  24 ++
 clang/include/clang/AST/DeclBase.h|  10 +
 clang/include/clang/Basic/Attr.td |  18 ++
 clang/include/clang/Basic/AttrDocs.td |  66 +
 .../clang/Basic/DiagnosticSemaKinds.td|  15 ++
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/AST/ASTImporter.cpp |  13 +
 clang/lib/AST/DeclBase.cpp|  77 +-
 clang/lib/AST/Expr.cpp|  83 +--
 clang/lib/CodeGen/CGBuiltin.cpp   |  51 
 clang/lib/CodeGen/CGExpr.cpp  |  64 -
 clang/lib/CodeGen/CodeGenFunction.h   |   6 +
 clang/lib/Sema/SemaDecl.cpp   |  12 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 132 ++
 clang/test/CodeGen/attr-counted-by.c  | 227 ++
 clang/test/CodeGen/bounds-checking.c  |  10 +-
 ...a-attribute-supported-attributes-list.test |   1 +
 clang/test/Sema/attr-counted-by.c |  42 
 19 files changed, 780 insertions(+), 78 deletions(-)
 create mode 100644 clang/test/CodeGen/attr-counted-by.c
 create mode 100644 clang/test/Sema/attr-counted-by.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..1eebf5ea6b3e382 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ C Language Changes
 - ``structs``, ``unions``, and ``arrays`` that are const may now be used as
   constant expressions.  This change is more consistent with the behavior of
   GCC.
+- Clang now supports the C-only attribute ``counted_by``. When applied to a
+  struct's flexible array member, it points to the struct field that holds the
+  number of elements in the flexible array member. This information can improve
+  the results of the array bound sanitizer and the
+  ``__builtin_dynamic_object_size`` builtin.
 
 C23 Feature Support
 ^^^
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 02e30e24c8be470..7f076cc77ea82cb 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4302,6 +4302,30 @@ class RecordDecl : public TagDecl {
 return field_begin() == field_end();
   }
 
+  FieldDecl *getLastField() {
+FieldDecl *FD = nullptr;
+for (FieldDecl *Field : fields())
+  FD = Field;
+return FD;
+  }
+  const FieldDecl *getLastField() const {
+return const_cast(this)->getLastField();
+  }
+
+  template 
+  const FieldDecl *findFieldIf(Functor &Pred) const {
+for (const Decl *D : decls()) {
+  if (const auto *FD = dyn_cast(D); FD && Pred(FD))
+return FD;
+
+  if (const auto *RD = dyn_cast(D))
+if (const FieldDecl *FD = RD->findF

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

2023-10-10 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 3a6cc52fe3501b2b7b3aabdff305a18122c9e0db 
b7b0c40542589e9c54c21140dbb5b163dd8ffc7b -- 
clang/test/CodeGen/attr-counted-by.c clang/test/Sema/attr-counted-by.c 
clang/include/clang/AST/Decl.h clang/include/clang/AST/DeclBase.h 
clang/include/clang/Sema/Sema.h clang/lib/AST/ASTImporter.cpp 
clang/lib/AST/DeclBase.cpp clang/lib/AST/Expr.cpp 
clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGExpr.cpp 
clang/lib/CodeGen/CodeGenFunction.h clang/lib/Sema/SemaDecl.cpp 
clang/lib/Sema/SemaDeclAttr.cpp clang/test/CodeGen/bounds-checking.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 47e072ace072..934f7271b03e 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -8457,8 +8457,7 @@ bool Sema::CheckCountedByAttr(Scope *S, const FieldDecl 
*FD) {
StrictFlexArraysLevel, true)) {
 // The "counted_by" attribute must be on a flexible array member.
 SourceRange SR = FD->getLocation();
-Diag(SR.getBegin(),
- diag::err_counted_by_attr_not_on_flexible_array_member)
+Diag(SR.getBegin(), diag::err_counted_by_attr_not_on_flexible_array_member)
 << SR;
 return true;
   }
@@ -8466,14 +8465,12 @@ bool Sema::CheckCountedByAttr(Scope *S, const FieldDecl 
*FD) {
   if (Field->hasAttr()) {
 // The "counted_by" field can't point to the flexible array member.
 SourceRange SR = CBA->getCountedByFieldLoc();
-Diag(SR.getBegin(),
- diag::err_flexible_array_counted_by_attr_refers_to_self)
+Diag(SR.getBegin(), 
diag::err_flexible_array_counted_by_attr_refers_to_self)
 << CBA->getCountedByField() << SR;
 return true;
   }
 
-  if (!Field->getType()->isIntegerType() ||
-  Field->getType()->isBooleanType()) {
+  if (!Field->getType()->isIntegerType() || Field->getType()->isBooleanType()) 
{
 // The "counted_by" field must have an integer type.
 SourceRange SR = Field->getLocation();
 Diag(SR.getBegin(),

``




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


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

2023-10-10 Thread Bill Wendling via cfe-commits

bwendling wrote:

And @AaronBallman, I haven't forgotten my promise to change the diagnostics. 
I've been on vacation, and it's become trickier to get them to work the other 
way than I had first thought. The change is coming soon though.

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


[libunwind] [libunwind] Fix running tests with MSan (PR #67860)

2023-10-10 Thread Alexander Richardson via cfe-commits


@@ -115,6 +121,18 @@ extern int unw_set_reg(unw_cursor_t *, unw_regnum_t, 
unw_word_t) LIBUNWIND_AVAIL
 extern int unw_set_fpreg(unw_cursor_t *, unw_regnum_t, unw_fpreg_t)  
LIBUNWIND_AVAIL;
 extern int unw_resume(unw_cursor_t *) LIBUNWIND_AVAIL;
 
+#ifdef LIBUNWIND_HAVE_MSAN
+// unw_getcontext is implemented in assembly so it is rather difficult to
+// mark the MSan shadow as initialized from within the function. Instead we
+// use a macro wrapper when compiling with MSan to avoid false-positives.
+#define unw_getcontext(context)
\

arichardson wrote:

I don't think we can since I _believe_ that having an exported symbol called 
unw_getcontext is required. But I'm not familiar with what level of 
compatibility with GNU libunwind is required.

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


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

2023-10-10 Thread Bill Wendling via cfe-commits

bwendling wrote:

This is identical to the original change 
(9a954c693573281407f6ee3f4eb1b16cc545033d), but with a fix for the issue 
@alexfh discovered 
(https://github.com/llvm/llvm-project/commit/9a954c693573281407f6ee3f4eb1b16cc545033d#commitcomment-129529574).
 The change is on lines 473-475 of clang/lib/AST/DeclBase.cpp: using 
`dyn_cast_if_present` instead of just `dyn_cast`. Also added the testcase to 
`clang/test/CodeGen/bounds-checking.c`.

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


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

2023-10-10 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Bill Wendling (bwendling)


Changes

The 'counted_by' attribute is used on flexible array members. The argument for 
the attribute is the name of the field member in the same structure holding the 
count of elements in the flexible array. This information can be used to 
improve the results of the array bound sanitizer and the 
'__builtin_dynamic_object_size' builtin.

This example specifies the that the flexible array member 'array' has the 
number of elements allocated for it in 'count':

  struct bar;
  struct foo {
size_t count;
 /* ... */
struct bar *array[] __attribute__((counted_by(count)));
  };

This establishes a relationship between 'array' and 'count', specifically that 
'p->array' must have *at least* 'p->count' number of elements available. 
It's the user's responsibility to ensure that this relationship is maintained 
through changes to the structure.

In the following, the allocated array erroneously has fewer elements than 
what's specified by 'p->count'. This would result in an out-of-bounds access 
not not being detected:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

The next example updates 'p->count', breaking the relationship requirement 
that 'p->array' must have at least 'p->count' number of elements 
available:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

  void use_foo(int index) {
p->count += 42;
p->array[index] = 0; /* The sanitizer cannot properly check this access 
*/
  }

Reviewed By: nickdesaulniers, aaron.ballman

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

---

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


19 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+5) 
- (modified) clang/include/clang/AST/Decl.h (+24) 
- (modified) clang/include/clang/AST/DeclBase.h (+10) 
- (modified) clang/include/clang/Basic/Attr.td (+18) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+66) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+15) 
- (modified) clang/include/clang/Sema/Sema.h (+2) 
- (modified) clang/lib/AST/ASTImporter.cpp (+13) 
- (modified) clang/lib/AST/DeclBase.cpp (+76-1) 
- (modified) clang/lib/AST/Expr.cpp (+10-73) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+51) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+61-3) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+6) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+12) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+132) 
- (added) clang/test/CodeGen/attr-counted-by.c (+227) 
- (modified) clang/test/CodeGen/bounds-checking.c (+9-1) 
- (modified) clang/test/Misc/pragma-attribute-supported-attributes-list.test 
(+1) 
- (added) clang/test/Sema/attr-counted-by.c (+42) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..1eebf5ea6b3e382 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -157,6 +157,11 @@ C Language Changes
 - ``structs``, ``unions``, and ``arrays`` that are const may now be used as
   constant expressions.  This change is more consistent with the behavior of
   GCC.
+- Clang now supports the C-only attribute ``counted_by``. When applied to a
+  struct's flexible array member, it points to the struct field that holds the
+  number of elements in the flexible array member. This information can improve
+  the results of the array bound sanitizer and the
+  ``__builtin_dynamic_object_size`` builtin.
 
 C23 Feature Support
 ^^^
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 02e30e24c8be470..7f076cc77ea82cb 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -4302,6 +4302,30 @@ class RecordDecl : public TagDecl {
 return field_begin() == field_end();
   }
 
+  FieldDecl *getLastField() {
+FieldDecl *FD = nullptr;
+for (FieldDecl *Field : fields())
+  FD = Field;
+return FD;
+  }
+  const FieldDecl *getLastField() const {
+return const_cast(this)->getLastField();
+  }
+
+  template 
+  const FieldDecl *findFieldIf(Functor &Pred) const {
+for (const Decl *D : decls()) {
+  if (const auto *FD = dyn_cast(D); FD && Pred(FD))
+return FD;
+
+  if (const auto *RD = dyn_cast(D))
+if (const FieldDecl *FD = RD->findFieldIf(Pred))
+  return FD;
+}
+
+return nullptr;
+  }
+
   /// Note that the definition of this type is now complete.
   virtual void completeDefinition();
 
diff --git a/clang/include/clang/AST/DeclBase.h 
b/clang/include/c

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

2023-10-10 Thread Bill Wendling via cfe-commits

https://github.com/bwendling created 
https://github.com/llvm/llvm-project/pull/68750

The 'counted_by' attribute is used on flexible array members. The argument for 
the attribute is the name of the field member in the same structure holding the 
count of elements in the flexible array. This information can be used to 
improve the results of the array bound sanitizer and the 
'__builtin_dynamic_object_size' builtin.

This example specifies the that the flexible array member 'array' has the 
number of elements allocated for it in 'count':

  struct bar;
  struct foo {
size_t count;
 /* ... */
struct bar *array[] __attribute__((counted_by(count)));
  };

This establishes a relationship between 'array' and 'count', specifically that 
'p->array' must have *at least* 'p->count' number of elements available. It's 
the user's responsibility to ensure that this relationship is maintained 
through changes to the structure.

In the following, the allocated array erroneously has fewer elements than 
what's specified by 'p->count'. This would result in an out-of-bounds access 
not not being detected:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

The next example updates 'p->count', breaking the relationship requirement that 
'p->array' must have at least 'p->count' number of elements available:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

  void use_foo(int index) {
p->count += 42;
p->array[index] = 0; /* The sanitizer cannot properly check this access */
  }

Reviewed By: nickdesaulniers, aaron.ballman

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

>From b7b0c40542589e9c54c21140dbb5b163dd8ffc7b Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Wed, 4 Oct 2023 17:55:49 -0700
Subject: [PATCH] [Clang] Implement the 'counted_by' attribute

The 'counted_by' attribute is used on flexible array members. The
argument for the attribute is the name of the field member in the same
structure holding the count of elements in the flexible array. This
information can be used to improve the results of the array bound sanitizer
and the '__builtin_dynamic_object_size' builtin.

This example specifies the that the flexible array member 'array' has the
number of elements allocated for it in 'count':

  struct bar;
  struct foo {
size_t count;
 /* ... */
struct bar *array[] __attribute__((counted_by(count)));
  };

This establishes a relationship between 'array' and 'count', specifically
that 'p->array' must have *at least* 'p->count' number of elements available.
It's the user's responsibility to ensure that this relationship is maintained
through changes to the structure.

In the following, the allocated array erroneously has fewer elements than
what's specified by 'p->count'. This would result in an out-of-bounds access not
not being detected:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

The next example updates 'p->count', breaking the relationship requirement that
'p->array' must have at least 'p->count' number of elements available:

  struct foo *p;

  void foo_alloc(size_t count) {
p = malloc(MAX(sizeof(struct foo),
   offsetof(struct foo, array[0]) + count *
   sizeof(struct bar *)));
p->count = count + 42;
  }

  void use_foo(int index) {
p->count += 42;
p->array[index] = 0; /* The sanitizer cannot properly check this access */
  }

Reviewed By: nickdesaulniers, aaron.ballman

Differential Revision: https://reviews.llvm.org/D148381
---
 clang/docs/ReleaseNotes.rst   |   5 +
 clang/include/clang/AST/Decl.h|  24 ++
 clang/include/clang/AST/DeclBase.h|  10 +
 clang/include/clang/Basic/Attr.td |  18 ++
 clang/include/clang/Basic/AttrDocs.td |  66 +
 .../clang/Basic/DiagnosticSemaKinds.td|  15 ++
 clang/include/clang/Sema/Sema.h   |   2 +
 clang/lib/AST/ASTImporter.cpp |  13 +
 clang/lib/AST/DeclBase.cpp|  77 +-
 clang/lib/AST/Expr.cpp|  83 +--
 clang/lib/CodeGen/CGBuiltin.cpp   |  51 
 clang/lib/CodeGen/CGExpr.cpp  |  64 -
 clang/lib/CodeGen/CodeGenFunction.h   |   6 +
 clang/lib/Sema/SemaDecl.cpp   |  12 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 132 ++
 clang/test/CodeGen/attr-counted-by.c  | 227 ++
 clang/test/CodeGen/bounds-checking.c  

[libunwind] [libunwind][test] Avoid calling back into libunwind on sanitizer errors (PR #67861)

2023-10-10 Thread Alexander Richardson via cfe-commits

arichardson wrote:

> What is the nested MSAN fault? Wouldn't fixing that be a better way to handle 
> the situation?

Currently there are missing annotations for __unw_getcontext so MSan thinks 
there are unintialized reads inside libunwind. The underlying issues is fixed 
in #67860 but if we ever introduce an new MSan error inside libunwind we will 
see the same infinite recursion. 

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


[clang] [clang][Interp] Only evaluate the source array initialization of an `ArrayInitLoopExpr` once (PR #68039)

2023-10-10 Thread via cfe-commits

isuckatcs wrote:

ping @tbaederr 

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


[clang] [TSAN] add support for riscv64 (PR #68735)

2023-10-10 Thread Fangrui Song via cfe-commits

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

https://reviews.llvm.org/D145214#4653647

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


[clang] [TSAN] add support for riscv64 (PR #68735)

2023-10-10 Thread Fangrui Song via cfe-commits

MaskRay wrote:

The review context is on https://reviews.llvm.org/D145214 . Moving it here just 
causes more confusion. 

@alexfanqi is the author of the patch and they can drive a reland.


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


[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

2023-10-10 Thread via cfe-commits

weltschildkroete wrote:

LMK if the release note sounds good. If so, could you land this patch for me? 
Please use "Leonardo Duarte weltschildkro...@gmail.com" to commit the change. 
Thanks!

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


[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

2023-10-10 Thread via cfe-commits


@@ -2393,7 +2393,7 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration}1">;
+  "|in array declaration|in lambda parameter until C++14}1">;

weltschildkroete wrote:

Thanks, done.

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


[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

2023-10-10 Thread via cfe-commits

https://github.com/weltschildkroete updated 
https://github.com/llvm/llvm-project/pull/68540

>From 613ea6809b478ff7391614b24ec177fc19339cdd Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Sun, 8 Oct 2023 12:59:15 +0200
Subject: [PATCH 1/4] [clang][Sema] Emit more specific diagnostic for auto in
 lambda before C++14 (#46059)

Namely, we specify that `auto` in a lambda parameter is a C++14
extension in the error message, which now reads:

`'auto' not allowed in lambda parameter until C++14`

This does not change the behavior for `decltype(auto)` and `__auto_type`
though.

The relevant change to `SemaType.cpp` is the addition of a branch that
sets `Error = 24`, whilst the bulk of the change comes from formatting.
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 clang/lib/Sema/SemaType.cpp  | 7 +--
 clang/test/SemaCXX/auto-cxx0x.cpp| 4 ++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c1a6e3831127e56..815f78675c72ec2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2393,7 +2393,7 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration}1">;
+  "|in array declaration|in lambda parameter until C++14}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 068971f8130a4aa..52a8161797e15e1 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3605,8 +3605,11 @@ static QualType 
GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
 Info = &SemaRef.InventedParameterInfos.back();
   } else {
 // In C++14, generic lambdas allow 'auto' in their parameters.
-if (!SemaRef.getLangOpts().CPlusPlus14 || !Auto ||
-Auto->getKeyword() != AutoTypeKeyword::Auto) {
+if (!SemaRef.getLangOpts().CPlusPlus14 && Auto &&
+Auto->getKeyword() == AutoTypeKeyword::Auto) {
+  Error = 24;
+  break;
+} else if (!Auto || Auto->getKeyword() != AutoTypeKeyword::Auto) {
   Error = 16;
   break;
 }
diff --git a/clang/test/SemaCXX/auto-cxx0x.cpp 
b/clang/test/SemaCXX/auto-cxx0x.cpp
index b4da3f9330c1045..65398de28e10cfb 100644
--- a/clang/test/SemaCXX/auto-cxx0x.cpp
+++ b/clang/test/SemaCXX/auto-cxx0x.cpp
@@ -12,7 +12,7 @@ thread_local auto x; // expected-error {{requires an 
initializer}}
 void g() {
   [](auto){}(0);
 #if __cplusplus == 201103L
-  // expected-error@-2 {{'auto' not allowed in lambda parameter}}
+  // expected-error@-2 {{'auto' not allowed in lambda parameter until C++14}}
 #endif
 }
 
@@ -20,6 +20,6 @@ void rdar47689465() {
   int x = 0;
   [](auto __attribute__((noderef)) *){}(&x);
 #if __cplusplus == 201103L
-  // expected-error@-2 {{'auto' not allowed in lambda parameter}}
+  // expected-error@-2 {{'auto' not allowed in lambda parameter until C++14}}
 #endif
 }

>From b884f2b79d57343dea6e7f9b16dfc96984ec1f5b Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Tue, 10 Oct 2023 22:52:54 +0200
Subject: [PATCH 2/4] Slightly change wording in diagnostic

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 815f78675c72ec2..02644a84b4f4ea4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2393,7 +2393,7 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration|in lambda parameter until C++14}1">;
+  "|in array declaration|in lambda parameter before C++14}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"

>From 99bc3b6cb8d1a812b6dcd573261a77a2d50a79e2 Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Tue, 10 Oct 2023 23:09:07 +0200
Subject: [PATCH 3/4] Add release note

---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..41d83791cb5f287 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -301,6 +301,9 @@ Improvements to Clang's diagnostics
 - Clang 

[clang] [clang][Sema] Emit more specific diagnostic for auto in lambda before C++14 (#46059) (PR #68540)

2023-10-10 Thread via cfe-commits

https://github.com/weltschildkroete updated 
https://github.com/llvm/llvm-project/pull/68540

>From 613ea6809b478ff7391614b24ec177fc19339cdd Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Sun, 8 Oct 2023 12:59:15 +0200
Subject: [PATCH 1/3] [clang][Sema] Emit more specific diagnostic for auto in
 lambda before C++14 (#46059)

Namely, we specify that `auto` in a lambda parameter is a C++14
extension in the error message, which now reads:

`'auto' not allowed in lambda parameter until C++14`

This does not change the behavior for `decltype(auto)` and `__auto_type`
though.

The relevant change to `SemaType.cpp` is the addition of a branch that
sets `Error = 24`, whilst the bulk of the change comes from formatting.
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 clang/lib/Sema/SemaType.cpp  | 7 +--
 clang/test/SemaCXX/auto-cxx0x.cpp| 4 ++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c1a6e3831127e56..815f78675c72ec2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2393,7 +2393,7 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration}1">;
+  "|in array declaration|in lambda parameter until C++14}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 068971f8130a4aa..52a8161797e15e1 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3605,8 +3605,11 @@ static QualType 
GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
 Info = &SemaRef.InventedParameterInfos.back();
   } else {
 // In C++14, generic lambdas allow 'auto' in their parameters.
-if (!SemaRef.getLangOpts().CPlusPlus14 || !Auto ||
-Auto->getKeyword() != AutoTypeKeyword::Auto) {
+if (!SemaRef.getLangOpts().CPlusPlus14 && Auto &&
+Auto->getKeyword() == AutoTypeKeyword::Auto) {
+  Error = 24;
+  break;
+} else if (!Auto || Auto->getKeyword() != AutoTypeKeyword::Auto) {
   Error = 16;
   break;
 }
diff --git a/clang/test/SemaCXX/auto-cxx0x.cpp 
b/clang/test/SemaCXX/auto-cxx0x.cpp
index b4da3f9330c1045..65398de28e10cfb 100644
--- a/clang/test/SemaCXX/auto-cxx0x.cpp
+++ b/clang/test/SemaCXX/auto-cxx0x.cpp
@@ -12,7 +12,7 @@ thread_local auto x; // expected-error {{requires an 
initializer}}
 void g() {
   [](auto){}(0);
 #if __cplusplus == 201103L
-  // expected-error@-2 {{'auto' not allowed in lambda parameter}}
+  // expected-error@-2 {{'auto' not allowed in lambda parameter until C++14}}
 #endif
 }
 
@@ -20,6 +20,6 @@ void rdar47689465() {
   int x = 0;
   [](auto __attribute__((noderef)) *){}(&x);
 #if __cplusplus == 201103L
-  // expected-error@-2 {{'auto' not allowed in lambda parameter}}
+  // expected-error@-2 {{'auto' not allowed in lambda parameter until C++14}}
 #endif
 }

>From b884f2b79d57343dea6e7f9b16dfc96984ec1f5b Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Tue, 10 Oct 2023 22:52:54 +0200
Subject: [PATCH 2/3] Slightly change wording in diagnostic

---
 clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 815f78675c72ec2..02644a84b4f4ea4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2393,7 +2393,7 @@ def err_auto_not_allowed : Error<
   "|in type allocated by 'new'|in K&R-style function parameter"
   "|in template parameter|in friend declaration|in function prototype that is "
   "not a function declaration|in requires expression parameter"
-  "|in array declaration|in lambda parameter until C++14}1">;
+  "|in array declaration|in lambda parameter before C++14}1">;
 def err_dependent_deduced_tst : Error<
   "typename specifier refers to "
   "%select{class template|function template|variable template|alias template|"

>From 99bc3b6cb8d1a812b6dcd573261a77a2d50a79e2 Mon Sep 17 00:00:00 2001
From: Leonardo Duarte 
Date: Tue, 10 Oct 2023 23:09:07 +0200
Subject: [PATCH 3/3] Add release note

---
 clang/docs/ReleaseNotes.rst | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2d918967e7f0b02..41d83791cb5f287 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -301,6 +301,9 @@ Improvements to Clang's diagnostics
 - Clang 

[PATCH] D145262: [clang-format] Treat AttributeMacros more like __attribute__

2023-10-10 Thread Owen Pan via Phabricator via cfe-commits
owenpan added a comment.

@jaredgrubb please provide your authorship for `git commit --author` so that we 
can land the patch on your behalf.


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

https://reviews.llvm.org/D145262

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


[clang] [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and Obj-C++ by-proxy) (PR #68620)

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

shafik wrote:

> FWIW, I spoke offline with the original author of the PR and he said that 
> he's fine with me picking up the changes and carrying the review forward.
> 
> Because I don't know of any better way to commandeer a patch in GitHub, I'll 
> probably grab the changes, get them into my own fork, and then recreate the 
> PR to get the review started. Whenever we get ready to land the PR, @ThePhD 
> will be credited as a co-author.

So just to clarify, we should wait till you post a follow-up review before 
commenting, to avoid fragmenting the discussion.

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


[PATCH] D152914: [Draft] Make __builtin_cpu builtins target-independent

2023-10-10 Thread Lei Huang via Phabricator via cfe-commits
lei added a comment.

HI @nemanjai, Did you get a chance to post this as a github PR?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152914

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


[PATCH] D145262: [clang-format] Treat AttributeMacros more like __attribute__

2023-10-10 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added a comment.

LGTM


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

https://reviews.llvm.org/D145262

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


[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-10 Thread Björn Schäpers via cfe-commits


@@ -182,7 +182,7 @@ TEST_F(FormatTestComments, UnderstandsSingleLineComments) {
"int   a; // This is unrelated"));
   EXPECT_EQ("class C {\n"
 "  void f() { // This does something ..\n"
-"  }  // awesome..\n"
+"  } // awesome..\n"

HazardyKnusperkeks wrote:

But this would work against a conscious decision. Should we change that? Or 
should we add `TT_FunctionRBrace` (shouldn't be hard) and exempt them from not 
aligning?

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


[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-10 Thread Björn Schäpers via cfe-commits


@@ -3191,20 +3191,120 @@ TEST_F(FormatTestComments, DontAlignNamespaceComments) 
{
   "}\n"
   "// Comment";
 
-#if 0
-  // FIXME: The following comment is aligned with the namespace comment.
   verifyFormat("namespace A {\n"
"  int Foo;\n"
"  int Bar;\n"
"} // namespace A\n"
-   " // Comment",
+   "// Comment",
Input, Style);
-#endif
 
   Style.FixNamespaceComments = false;
   verifyFormat(Input, Style);
 }
 
+TEST_F(FormatTestComments, DontAlignOverScope) {
+  verifyFormat("if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("if (foo) {\n"
+   "  // something\n"
+   "} else if (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("while (foo) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("for (;;) {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("do {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} while (foo); // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "case 7: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("switch (foo) {\n"
+   "default: {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "} // case not aligned\n"
+   "} // switch also not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("class C {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("struct S {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("union U {\n"
+   "  int aLongVariable; // with comment\n"
+   "  int f; // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("enum E {\n"
+   "  aLongVariable, // with comment\n"
+   "  f  // aligned\n"
+   "}; // not aligned\n"
+   "int bar;// new align\n"
+   "int foobar; // group");
+
+  verifyFormat("void foo() {\n"
+   "  {\n"
+   "int aLongVariable; // with comment\n"
+   "int f; // aligned\n"
+   "  } // not aligned\n"
+   "  int bar;// new align\n"
+   "  int foobar; // group\n"
+   "}");
+}
+

HazardyKnusperkeks wrote:

Not added here is a lambda, currently trailing comments on lambdas would be 
aligned. And I tend to let it that way.

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


[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-10 Thread Björn Schäpers via cfe-commits


@@ -20794,7 +20794,7 @@ TEST_F(FormatTest, 
CatchAlignArrayOfStructuresRightAlignment) {
   verifyFormat("int a[][] = {\n"
"{\n"
" {0, 2}, //\n"
-   " {1, 2}  //\n"
+   " {1, 2} //\n"

HazardyKnusperkeks wrote:

This one is was not aligned on purpose, just the way clang-format did handled 
such cases.

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


[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-10 Thread via cfe-commits
=?utf-8?q?Björn_Schäpers?= 
Message-ID:
In-Reply-To: 


llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Björn Schäpers (HazardyKnusperkeks)


Changes

We now stop aligning trailing comments on all closing braces, for
classes etc. we even check for the semicolon between the comment and the
brace.

Fixes #67906.

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


6 Files Affected:

- (modified) clang/lib/Format/FormatToken.h (+2) 
- (modified) clang/lib/Format/UnwrappedLineParser.cpp (+18-2) 
- (modified) clang/lib/Format/WhitespaceManager.cpp (+36-9) 
- (modified) clang/unittests/Format/FormatTest.cpp (+1-1) 
- (modified) clang/unittests/Format/FormatTestComments.cpp (+105-5) 
- (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+31) 


``diff
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 527f1d744a58089..606e9e790ad833b 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -52,6 +52,7 @@ namespace format {
   TYPE(ConflictStart)  
\
   /* l_brace of if/for/while */
\
   TYPE(ControlStatementLBrace) 
\
+  TYPE(ControlStatementRBrace) 
\
   TYPE(CppCastLParen)  
\
   TYPE(CSharpGenericTypeConstraint)
\
   TYPE(CSharpGenericTypeConstraintColon)   
\
@@ -67,6 +68,7 @@ namespace format {
   TYPE(DesignatedInitializerPeriod)
\
   TYPE(DictLiteral)
\
   TYPE(ElseLBrace) 
\
+  TYPE(ElseRBrace) 
\
   TYPE(EnumLBrace) 
\
   TYPE(EnumRBrace) 
\
   TYPE(FatArrow)   
\
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 3275d7b6a71aaa0..9769d536bee32aa 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2756,6 +2756,10 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
 parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
/*MunchSemi=*/true, KeepIfBraces, &IfBlockKind);
+if (auto Prev = FormatTok->getPreviousNonComment();
+Prev && Prev->is(tok::r_brace)) {
+  Prev->setFinalizedType(TT_ControlStatementRBrace);
+}
 if (Style.BraceWrapping.BeforeElse)
   addUnwrappedLine();
 else
@@ -2794,6 +2798,10 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
   FormatToken *IfLBrace =
   parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
  /*MunchSemi=*/true, KeepElseBraces, &ElseBlockKind);
+  if (auto Prev = FormatTok->getPreviousNonComment();
+  Prev && Prev->is(tok::r_brace)) {
+Prev->setFinalizedType(TT_ElseRBrace);
+  }
   if (FormatTok->is(tok::kw_else)) {
 KeepElseBraces = KeepElseBraces ||
  ElseBlockKind == IfStmtKind::IfOnly ||
@@ -3057,12 +3065,15 @@ void UnwrappedLineParser::parseLoopBody(bool 
KeepBraces, bool WrapRightBrace) {
   keepAncestorBraces();
 
   if (isBlockBegin(*FormatTok)) {
-if (!KeepBraces)
-  FormatTok->setFinalizedType(TT_ControlStatementLBrace);
+FormatTok->setFinalizedType(TT_ControlStatementLBrace);
 FormatToken *LeftBrace = FormatTok;
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
 parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
/*MunchSemi=*/true, KeepBraces);
+if (auto Prev = FormatTok->getPreviousNonComment();
+Prev && Prev->is(tok::r_brace)) {
+  Prev->setFinalizedType(TT_ControlStatementRBrace);
+}
 if (!KeepBraces) {
   assert(!NestedTooDeep.empty());
   if (!NestedTooDeep.back())
@@ -3196,7 +3207,12 @@ void UnwrappedLineParser::parseSwitch() {
 
   if (FormatTok->is(tok::l_brace)) {
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
+FormatTok->setFinalizedType(TT_ControlStatementLBrace);
 parseBlock();
+if (auto Prev = FormatTok->getPreviousNonComment();
+Prev && Prev->is(tok::r_brace)) {
+  Prev->setFinalizedType(TT_ControlStatementRBrace);
+}
 addUnwrappedLine();
   } else {
 addUnwrappedLine();
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index dc81060671c1712..74f62ddc4cc3bb2 100

[clang] [clang-format] Don't align comments over scopes (PR #68743)

2023-10-10 Thread Björn Schäpers via cfe-commits

https://github.com/HazardyKnusperkeks created 
https://github.com/llvm/llvm-project/pull/68743

We now stop aligning trailing comments on all closing braces, for
classes etc. we even check for the semicolon between the comment and the
brace.

Fixes #67906.

From 358cbf4fd25d2d323e21774a3d4f5a605c4f1479 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Mon, 9 Oct 2023 21:28:01 +0200
Subject: [PATCH 1/2] [clang-format][NFC] Annotate control statement r_braces

Annotating switch braces for the first time.

Also in preparation of #67906.
---
 clang/lib/Format/FormatToken.h|  2 ++
 clang/lib/Format/UnwrappedLineParser.cpp  | 20 ++--
 clang/unittests/Format/TokenAnnotatorTest.cpp | 31 +++
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 527f1d744a58089..606e9e790ad833b 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -52,6 +52,7 @@ namespace format {
   TYPE(ConflictStart)  
\
   /* l_brace of if/for/while */
\
   TYPE(ControlStatementLBrace) 
\
+  TYPE(ControlStatementRBrace) 
\
   TYPE(CppCastLParen)  
\
   TYPE(CSharpGenericTypeConstraint)
\
   TYPE(CSharpGenericTypeConstraintColon)   
\
@@ -67,6 +68,7 @@ namespace format {
   TYPE(DesignatedInitializerPeriod)
\
   TYPE(DictLiteral)
\
   TYPE(ElseLBrace) 
\
+  TYPE(ElseRBrace) 
\
   TYPE(EnumLBrace) 
\
   TYPE(EnumRBrace) 
\
   TYPE(FatArrow)   
\
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 3275d7b6a71aaa0..9769d536bee32aa 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2756,6 +2756,10 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
 parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
/*MunchSemi=*/true, KeepIfBraces, &IfBlockKind);
+if (auto Prev = FormatTok->getPreviousNonComment();
+Prev && Prev->is(tok::r_brace)) {
+  Prev->setFinalizedType(TT_ControlStatementRBrace);
+}
 if (Style.BraceWrapping.BeforeElse)
   addUnwrappedLine();
 else
@@ -2794,6 +2798,10 @@ FormatToken 
*UnwrappedLineParser::parseIfThenElse(IfStmtKind *IfKind,
   FormatToken *IfLBrace =
   parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
  /*MunchSemi=*/true, KeepElseBraces, &ElseBlockKind);
+  if (auto Prev = FormatTok->getPreviousNonComment();
+  Prev && Prev->is(tok::r_brace)) {
+Prev->setFinalizedType(TT_ElseRBrace);
+  }
   if (FormatTok->is(tok::kw_else)) {
 KeepElseBraces = KeepElseBraces ||
  ElseBlockKind == IfStmtKind::IfOnly ||
@@ -3057,12 +3065,15 @@ void UnwrappedLineParser::parseLoopBody(bool 
KeepBraces, bool WrapRightBrace) {
   keepAncestorBraces();
 
   if (isBlockBegin(*FormatTok)) {
-if (!KeepBraces)
-  FormatTok->setFinalizedType(TT_ControlStatementLBrace);
+FormatTok->setFinalizedType(TT_ControlStatementLBrace);
 FormatToken *LeftBrace = FormatTok;
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
 parseBlock(/*MustBeDeclaration=*/false, /*AddLevels=*/1u,
/*MunchSemi=*/true, KeepBraces);
+if (auto Prev = FormatTok->getPreviousNonComment();
+Prev && Prev->is(tok::r_brace)) {
+  Prev->setFinalizedType(TT_ControlStatementRBrace);
+}
 if (!KeepBraces) {
   assert(!NestedTooDeep.empty());
   if (!NestedTooDeep.back())
@@ -3196,7 +3207,12 @@ void UnwrappedLineParser::parseSwitch() {
 
   if (FormatTok->is(tok::l_brace)) {
 CompoundStatementIndenter Indenter(this, Style, Line->Level);
+FormatTok->setFinalizedType(TT_ControlStatementLBrace);
 parseBlock();
+if (auto Prev = FormatTok->getPreviousNonComment();
+Prev && Prev->is(tok::r_brace)) {
+  Prev->setFinalizedType(TT_ControlStatementRBrace);
+}
 addUnwrappedLine();
   } else {
 addUnwrappedLine();
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 2d590f2

[PATCH] D153131: [clang analysis][thread-safety] Handle return-by-reference...

2023-10-10 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added a comment.

In D153131#4653564 , @courbet wrote:

> We have a large number of users of `-Werror -Wthread-safety-analysis` 
> internally. When we make the new warnings part of that flag we cannot 
> integrate because we're breaking all these users.

The proposal was to include it in `-Wthread-safety-reference`, not 
`-Wthread-safety-analysis`. See 
https://clang.llvm.org/docs/DiagnosticsReference.html#wthread-safety for the 
existing flags and their relations.

> If we don't integrate we can't run the new analysis to see what we would need 
> to fix.

Can you not add `-Wno-error=thread-safety-reference-return` together with the 
integration? Or are there too many places adding it independently?

> Introducing a new flag allows us to:
>
> - keep the current analysis running for users of `-Wthread-safety-analysis`.
> - progressively add `-Wthread-safety-analysis-reference-return` to these 
> users across the codebase, fixing them or disabling analysis as needed.

That is true, but these advantages seem to apply to a small number of users 
only (those aware of the new flag). If you integrate Clang trunk, it would be 
Ok if you leave it off by default for a couple of weeks, but turn it on before 
the next release.

I'm not generally against new flags, but this is more of a "gap closing" than a 
new feature, so an on-by-default (under `-Wthread-safety-reference`, not 
`-Wthread-safety-analysis`) warning should be the right choice. Changes that 
result in new warnings are not uncommon, and often we don't create a new flag 
for them at all. Here it's Ok due to the large number of warnings, but it fits 
too well into `-Wthread-safety-reference` to not be triggered by that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153131

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


  1   2   3   >