[PATCH] D145849: [Driver][xray] Allow XRay on Apple Silicon

2023-06-17 Thread Oleksii Lozovskyi via Phabricator via cfe-commits
ilammy added a comment.

In D145849#4412286 , @MaskRay wrote:

> However, `Triple.isMacOSX()` is allowed before the feature actually works and 
> `compiler-rt/test/xray/lit.cfg.py` tests it.

I have some patches for `compiler-rt` cooking, fixing the build for AArch64. 
Should those go in first, before `clang` is ultimately allowed to use 
`-fxray-instrument` when targeting AArch64, so that everything works out of the 
box?

For me, Clang is able to compile binaries with XRay sections (with this 
change), but I have `compiler-rt` disabled and not linked in, since it's not 
possible to build it for AArch64 yet.

I thought it could be done separately. I was not aware of those tests in 
compiler-rt, checking all archs.

I guess the build should be fixed first, then this change should simultaneously 
allow clang to target AArch64 and update compiler-rt's expectations of what 
works.

How does that sound to you?


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

https://reviews.llvm.org/D145849

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


[PATCH] D153205: [clang-format] Add new block type ListInit

2023-06-17 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added a comment.

In D153205#4430528 , @owenpan wrote:

> It seems to me that there has been a proliferation of new options being 
> proposed and/or accepted recently. I'd like to remind everyone of the 
> long-standing policy 
> 
>  of adding new options. That being said, I wonder if we should add a new 
> language `LK_C` along with its variants C78 (i.e. K C), C89 (i.e. ANSI C), 
> GNU extensions (e.g. #55745 
>  and #62755 
> ), etc.

Understood. In this case, the `BK_ListInit` is not visible at the API / Style 
level. It is an internal categorization to help distinguish different kinds of 
blocks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153205

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


[PATCH] D153198: [clang-tidy] Refactor common code from the Noexcept*Checks into `NoexceptFunctionCheck`

2023-06-17 Thread André Schackier via Phabricator via cfe-commits
AMS21 added a comment.

If there are no more problems, I would kindly ask for someone to push this no 
my behalf :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153198

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


[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Sergei Barannikov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG44e63ffe2bf7: [clang] Replace uses of 
CGBuilderTy::CreateElementBitCast (NFC) (authored by JOE1994, committed by 
barannikov88).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153196

Files:
  clang/lib/CodeGen/Address.h
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/SystemZ.cpp

Index: clang/lib/CodeGen/Targets/SystemZ.cpp
===
--- clang/lib/CodeGen/Targets/SystemZ.cpp
+++ clang/lib/CodeGen/Targets/SystemZ.cpp
@@ -302,8 +302,7 @@
 Address OverflowArgArea =
 Address(CGF.Builder.CreateLoad(OverflowArgAreaPtr, "overflow_arg_area"),
 CGF.Int8Ty, TyInfo.Align);
-Address MemAddr =
-CGF.Builder.CreateElementBitCast(OverflowArgArea, DirectTy, "mem_addr");
+Address MemAddr = OverflowArgArea.withElementType(DirectTy);
 
 // Update overflow_arg_area_ptr pointer
 llvm::Value *NewOverflowArgArea = CGF.Builder.CreateGEP(
@@ -360,8 +359,7 @@
   Address RawRegAddr(
   CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, RegOffset, "raw_reg_addr"),
   CGF.Int8Ty, PaddedSize);
-  Address RegAddr =
-  CGF.Builder.CreateElementBitCast(RawRegAddr, DirectTy, "reg_addr");
+  Address RegAddr = RawRegAddr.withElementType(DirectTy);
 
   // Update the register count
   llvm::Value *One = llvm::ConstantInt::get(IndexTy, 1);
@@ -381,8 +379,7 @@
   CGF.Int8Ty, PaddedSize);
   Address RawMemAddr =
   CGF.Builder.CreateConstByteGEP(OverflowArgArea, Padding, "raw_mem_addr");
-  Address MemAddr =
-CGF.Builder.CreateElementBitCast(RawMemAddr, DirectTy, "mem_addr");
+  Address MemAddr = RawMemAddr.withElementType(DirectTy);
 
   // Update overflow_arg_area_ptr pointer
   llvm::Value *NewOverflowArgArea =
Index: clang/lib/CodeGen/Targets/Sparc.cpp
===
--- clang/lib/CodeGen/Targets/Sparc.cpp
+++ clang/lib/CodeGen/Targets/Sparc.cpp
@@ -315,7 +315,7 @@
   case ABIArgInfo::Indirect:
   case ABIArgInfo::IndirectAliased:
 Stride = SlotSize;
-ArgAddr = Builder.CreateElementBitCast(Addr, ArgPtrTy, "indirect");
+ArgAddr = Addr.withElementType(ArgPtrTy);
 ArgAddr = Address(Builder.CreateLoad(ArgAddr, "indirect.arg"), ArgTy,
   TypeInfo.Align);
 break;
@@ -328,7 +328,7 @@
   Address NextPtr = Builder.CreateConstInBoundsByteGEP(Addr, Stride, "ap.next");
   Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
 
-  return Builder.CreateElementBitCast(ArgAddr, ArgTy, "arg.addr");
+  return ArgAddr.withElementType(ArgTy);
 }
 
 void SparcV9ABIInfo::computeInfo(CGFunctionInfo ) const {
Index: clang/lib/CodeGen/Targets/Hexagon.cpp
===
--- clang/lib/CodeGen/Targets/Hexagon.cpp
+++ clang/lib/CodeGen/Targets/Hexagon.cpp
@@ -236,7 +236,7 @@
   // FIXME: Need to handle alignment
   llvm::Type *BP = CGF.Int8PtrTy;
   CGBuilderTy  = CGF.Builder;
-  Address VAListAddrAsBPP = Builder.CreateElementBitCast(VAListAddr, BP, "ap");
+  Address VAListAddrAsBPP = VAListAddr.withElementType(BP);
   llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
   // Handle address alignment for type alignment > 32 bits
   uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8;
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1279,7 +1279,7 @@
 void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction ,
   const CXXRecordDecl *RD) {
   Address This = getThisAddress(CGF);
-  This = CGF.Builder.CreateElementBitCast(This, CGM.Int8Ty, "this.int8");
+  This = This.withElementType(CGM.Int8Ty);
   const ASTContext  = getContext();
   const ASTRecordLayout  = Context.getASTRecordLayout(RD);
 
@@ -1296,8 +1296,7 @@
 Address VBPtr = CGF.Builder.CreateConstInBoundsByteGEP(This, Offs);
 llvm::Value *GVPtr =
 CGF.Builder.CreateConstInBoundsGEP2_32(GV->getValueType(), GV, 0, 0);
-VBPtr = CGF.Builder.CreateElementBitCast(VBPtr, GVPtr->getType(),
-  "vbptr." + VBT->ObjectWithVPtr->getName());
+VBPtr = VBPtr.withElementType(GVPtr->getType());
 

[clang] 44e63ff - [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Sergei Barannikov via cfe-commits

Author: Youngsuk Kim
Date: 2023-06-18T04:13:15+03:00
New Revision: 44e63ffe2bf7e5c026b828054d67088239939e81

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

LOG: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

* Add `Address::withElementType()` as a replacement for
  `CGBuilderTy::CreateElementBitCast`.

* Partial progress towards replacing `CreateElementBitCast`, as it no
  longer does what its name suggests. Either replace its uses with
  `Address::withElementType()`, or remove them if no longer needed.

* Remove unused parameter 'Name' of `CreateElementBitCast`

Reviewed By: barannikov88, nikic

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

Added: 


Modified: 
clang/lib/CodeGen/Address.h
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGException.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/CodeGen/CodeGenFunction.cpp
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/CodeGen/Targets/Hexagon.cpp
clang/lib/CodeGen/Targets/Sparc.cpp
clang/lib/CodeGen/Targets/SystemZ.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/Address.h b/clang/lib/CodeGen/Address.h
index 899aceac88672..cf48df8f5e736 100644
--- a/clang/lib/CodeGen/Address.h
+++ b/clang/lib/CodeGen/Address.h
@@ -95,6 +95,12 @@ class Address {
isKnownNonNull());
   }
 
+  /// Return address with 
diff erent element type, but same pointer and
+  /// alignment.
+  Address withElementType(llvm::Type *ElemTy) const {
+return Address(getPointer(), ElemTy, getAlignment(), isKnownNonNull());
+  }
+
   /// Whether the pointer is known not to be null.
   KnownNonNull_t isKnownNonNull() const {
 assert(isValid());

diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 100144cabbf48..cfbe3272196e3 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1259,9 +1259,8 @@ Address CodeGenFunction::GetAddrOfBlockDecl(const VarDecl 
*variable) {
 // to byref*.
 
 auto  = getBlockByrefInfo(variable);
-addr = Address(Builder.CreateLoad(addr), Int8Ty, byrefInfo.ByrefAlignment);
-
-addr = Builder.CreateElementBitCast(addr, byrefInfo.Type, "byref.addr");
+addr = Address(Builder.CreateLoad(addr), byrefInfo.Type,
+   byrefInfo.ByrefAlignment);
 
 addr = emitBlockByrefAddress(addr, byrefInfo, /*follow*/ true,
  variable->getName());
@@ -1935,14 +1934,12 @@ CodeGenFunction::GenerateCopyHelperFunction(const 
CGBlockInfo ) {
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   Address src = GetAddrOfLocalVar();
-  src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign);
-  src = Builder.CreateElementBitCast(src, blockInfo.StructureType,
- "block.source");
+  src = Address(Builder.CreateLoad(src), blockInfo.StructureType,
+blockInfo.BlockAlign);
 
   Address dst = GetAddrOfLocalVar();
-  dst = Address(Builder.CreateLoad(dst), Int8Ty, blockInfo.BlockAlign);
-  dst =
-  Builder.CreateElementBitCast(dst, blockInfo.StructureType, "block.dest");
+  dst = Address(Builder.CreateLoad(dst), blockInfo.StructureType,
+blockInfo.BlockAlign);
 
   for (auto  : blockInfo.SortedCaptures) {
 if (capture.isConstantOrTrivial())
@@ -2125,8 +2122,8 @@ CodeGenFunction::GenerateDestroyHelperFunction(const 
CGBlockInfo ) {
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   Address src = GetAddrOfLocalVar();
-  src = Address(Builder.CreateLoad(src), Int8Ty, blockInfo.BlockAlign);
-  src = Builder.CreateElementBitCast(src, blockInfo.StructureType, "block");
+  src = Address(Builder.CreateLoad(src), blockInfo.StructureType,
+blockInfo.BlockAlign);
 
   CodeGenFunction::RunCleanupsScope cleanups(*this);
 
@@ -2163,9 +2160,9 @@ class ObjectByrefHelpers final : public BlockByrefHelpers 
{
 
   void emitCopy(CodeGenFunction , Address destField,
 Address srcField) override {
-destField = CGF.Builder.CreateElementBitCast(destField, CGF.Int8Ty);
+destField = destField.withElementType(CGF.Int8Ty);
 
-srcField = CGF.Builder.CreateElementBitCast(srcField, CGF.Int8PtrTy);
+srcField = srcField.withElementType(CGF.Int8PtrTy);
 llvm::Value *srcValue = CGF.Builder.CreateLoad(srcField);
 
 unsigned flags = (Flags | BLOCK_BYREF_CALLER).getBitMask();
@@ -2178,7 +2175,7 @@ class ObjectByrefHelpers final : public BlockByrefHelpers 
{
   }
 

[PATCH] D153208: [clang-format] Add InsertNewlineAtEOF to .clang-format files

2023-06-17 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 532434.
owenpan edited the summary of this revision.
owenpan added a comment.

Took out `Language: Cpp`.


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

https://reviews.llvm.org/D153208

Files:
  clang/include/clang/Format/.clang-format
  clang/lib/Format/.clang-format
  clang/tools/clang-format/.clang-format
  clang/unittests/Format/.clang-format
  clang/unittests/Format/FormatTestMacroExpansion.cpp


Index: clang/unittests/Format/FormatTestMacroExpansion.cpp
===
--- clang/unittests/Format/FormatTestMacroExpansion.cpp
+++ clang/unittests/Format/FormatTestMacroExpansion.cpp
@@ -259,4 +259,4 @@
 } // namespace
 } // namespace test
 } // namespace format
-} // namespace clang
\ No newline at end of file
+} // namespace clang
Index: clang/unittests/Format/.clang-format
===
--- clang/unittests/Format/.clang-format
+++ clang/unittests/Format/.clang-format
@@ -1,4 +1,5 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/tools/clang-format/.clang-format
===
--- clang/tools/clang-format/.clang-format
+++ clang/tools/clang-format/.clang-format
@@ -1,4 +1,5 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/lib/Format/.clang-format
===
--- clang/lib/Format/.clang-format
+++ clang/lib/Format/.clang-format
@@ -1,4 +1,5 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/include/clang/Format/.clang-format
===
--- clang/include/clang/Format/.clang-format
+++ clang/include/clang/Format/.clang-format
@@ -1,4 +1,5 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
 LineEnding: LF
 RemoveBracesLLVM: true


Index: clang/unittests/Format/FormatTestMacroExpansion.cpp
===
--- clang/unittests/Format/FormatTestMacroExpansion.cpp
+++ clang/unittests/Format/FormatTestMacroExpansion.cpp
@@ -259,4 +259,4 @@
 } // namespace
 } // namespace test
 } // namespace format
-} // namespace clang
\ No newline at end of file
+} // namespace clang
Index: clang/unittests/Format/.clang-format
===
--- clang/unittests/Format/.clang-format
+++ clang/unittests/Format/.clang-format
@@ -1,4 +1,5 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/tools/clang-format/.clang-format
===
--- clang/tools/clang-format/.clang-format
+++ clang/tools/clang-format/.clang-format
@@ -1,4 +1,5 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/lib/Format/.clang-format
===
--- clang/lib/Format/.clang-format
+++ clang/lib/Format/.clang-format
@@ -1,4 +1,5 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/include/clang/Format/.clang-format
===
--- clang/include/clang/Format/.clang-format
+++ clang/include/clang/Format/.clang-format
@@ -1,4 +1,5 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
 LineEnding: LF
 RemoveBracesLLVM: true
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146777: [clang] Preliminary fat-lto-object support

2023-06-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7298
+  if (IsUsingLTO && Args.getLastArg(options::OPT_ffat_lto_objects)) {
+assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin);
+CmdArgs.push_back(Args.MakeArgString(

We also need a `err_drv_unsupported_opt_for_target` error for non-ELF


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146777

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


[PATCH] D153008: [RISCV] Allow slash-star comments in instruction operands

2023-06-17 Thread Abel Bernabeu via Phabricator via cfe-commits
abel-bernabeu added a comment.

In D153008#4430491 , @MaskRay wrote:

> In D153008#4428694 , @abel-bernabeu 
> wrote:
>
>> In D153008#4428568 , @MaskRay 
>> wrote:
>>
>>> This new update still applies many unneeded `getParser().Lex();` and adds a 
>>> test at a wrong layer 
>>> 
>>>  (clang/test/CodeGen):
>>
>> Would you rather have:
>>
>> - LLVM IR as input
>> - assembly as output
>> - the test placed under llvm/test/CodeGen/RISCV/
>>
>> ?
>>
>> That would make the test more verbose, but it would reduce the testing 
>> scope. Please confirm your preference.
>
> I created D153204  as an alternative. 
> Thanks for reporting the issue!

Thanks for reviewing. Added my comments on your patch proposal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153008

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


[PATCH] D146777: [clang] Preliminary fat-lto-object support

2023-06-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:250
 
+- `-ffat-lto-objects` can now be used to emit object files with both object
+  code and bitcode. Previously this flag was ignored for GCC compatibility.

MaskRay wrote:
> 
`bitcode` => `LLVM bitcode`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146777

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


[PATCH] D146777: [clang] Preliminary fat-lto-object support

2023-06-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.

There is a `-fno-fat-lto-objects` issue, but otherwise looks good after some 
nits are addressed. Thanks!




Comment at: clang/docs/ReleaseNotes.rst:250
 
+- `-ffat-lto-objects` can now be used to emit object files with both object
+  code and bitcode. Previously this flag was ignored for GCC compatibility.





Comment at: clang/include/clang/Driver/Options.td:2311
   MarshallingInfoString>;
+defm fat_lto_objects : BoolFOption<"fat-lto-objects",
+  CodeGenOpts<"FatLTO">, DefaultFalse,

We just need the pos flag for CC1Option, so use `OptInCC1FFlag`



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:7297
 
+  if (IsUsingLTO && Args.getLastArg(options::OPT_ffat_lto_objects)) {
+assert(LTOMode == LTOK_Full || LTOMode == LTOK_Thin);

This does not consider the negative option.

```
if (IsUsingLTO) {
  if (Arg *A = Args.getLastArg(options::OPT_ffat_lto_objects, 
options::OPT_fno_fat_lto_objects)) {
if (A->getOption().matches(options::OPT_ffat_lto_objects)) {
  CmdArgs.push_back(...)
  A->render(Args, CmdArgs);
}
  }
}
```

or move `getLastArg` outside of `if (IsUsingLTO)` to avoid 
-Wunused-command-line-argument in the absence of `-flto=`.

This code block probably should be moved before `fglobal_isel` to be closer to 
other LTO code.



Comment at: clang/test/CodeGen/embed-lto-fatlto.c:1
+// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -S -flto=full 
-ffat-lto-objects -fsplit-lto-unit -emit-llvm < %s  | FileCheck %s 
--check-prefixes=FULL,SPLIT
+// RUN: %clang -cc1 -triple x86_64-unknown-linux-gnu -S -flto=full 
-ffat-lto-objects -emit-llvm < %s  | FileCheck %s --check-prefixes=FULL,SPLIT

Remove `-S`. In CC1, `-emit-llvm` wins.



Comment at: clang/test/CodeGen/embed-lto-fatlto.c:8
+/// Check that the ThinLTO metadata is only set false for full LTO
+// FULL: !{{[0-9]+}} = !{i32 1, !"ThinLTO", i32 0}
+// THIN-NOT: !{{[0-9]+}} = !{i32 1, !"ThinLTO", i32 0}





Comment at: clang/test/CodeGen/embed-lto-fatlto.c:11
+
+/// Be sure we enable split LTO unints correctly under -ffat-lto-objects
+// SPLIT: !{{[0-9]+}} = !{i32 1, !"EnableSplitLTOUnit", i32 1}





Comment at: clang/test/Driver/fatlto-objects.c:1
+// REQUIRES: x86_64-linux
+// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects 
-fintegrated-as -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC

Delete the `REQUIRES`. The driver code should be portable as long as we only 
use `-###`.



Comment at: clang/test/Driver/fatlto-objects.c:1
+// REQUIRES: x86_64-linux
+// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects 
-fintegrated-as -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC

MaskRay wrote:
> Delete the `REQUIRES`. The driver code should be portable as long as we only 
> use `-###`.
`fat-lto-objects.c` or `ffat-lto-objects.c`



Comment at: clang/test/Driver/fatlto-objects.c:2
+// REQUIRES: x86_64-linux
+// RUN: %clang --target=x86_64-unknown-linux-gnu -flto -ffat-lto-objects 
-fintegrated-as -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC
+// CHECK-CC: -cc1

Delete `-fintegrated-as`. It's the default.



Comment at: clang/test/Driver/fatlto-objects.c:4
+// CHECK-CC: -cc1
+// CHECK-CC: -emit-obj
+// CHECK-CC: -ffat-lto-objects

Use `-SAME:` whenever applicable.



Comment at: clang/test/Driver/fatlto-objects.c:7
+
+// RUN: %clang --target=x86_64-unknown-linux-gnu -ffat-lto-objects 
-fintegrated-as -### %s -c 2>&1 | FileCheck %s -check-prefix=CHECK-CC-NOLTO
+// CHECK-CC-NOLTO: -cc1

You may test that `-ffat-lto-objects` in the absence of `-flto=` gives a 
`warning: argument unused during compilation: '-ffat-lto-objects'` warning



Comment at: clang/test/Driver/fatlto-objects.c:18
+// RUN:   -fuse-ld=lld -fno-lto -ffat-lto-objects -### 2>&1 | FileCheck 
--check-prefix=NOLTO %s
+// LTO: -fat-lto-objects
+// NOLTO-NOT: -fat-lto-objects




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146777

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


[PATCH] D134677: [Clang][AArch64][SME] Add ZA zeroing intrinsics

2023-06-17 Thread Bryan Chan via Phabricator via cfe-commits
bryanpkc updated this revision to Diff 532431.
bryanpkc marked 3 inline comments as done.
bryanpkc added a comment.

Rebased. NFC.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134677

Files:
  clang/include/clang/Basic/arm_sme.td
  clang/include/clang/Basic/arm_sve_sme_incl.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c
  clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp

Index: clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
===
--- clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
+++ clang/test/Sema/aarch64-sme-intrinsics/acle_sme_imm.cpp
@@ -14,8 +14,10 @@
 
 #ifdef DISABLE_SME_ATTRIBUTES
 #define ARM_STREAMING_ATTR
+#define ARM_SHARED_ZA_ATTR
 #else
 #define ARM_STREAMING_ATTR __attribute__((arm_streaming))
+#define ARM_SHARED_ZA_ATTR __attribute__((arm_shared_za))
 #endif
 
 ARM_STREAMING_ATTR
@@ -203,6 +205,14 @@
   SVE_ACLE_FUNC(svwrite_ver_za8, _s8, _m,)(0, -1, 16, pg, svundef_s8());
 }
 
+ARM_SHARED_ZA_ATTR
+void test_range_0_255(svbool_t pg, void *ptr) {
+  // expected-error@+1 {{argument value 256 is outside the valid range [0, 255]}}
+  SVE_ACLE_FUNC(svzero_mask_za,,,)(256);
+  // expected-error@+1 {{argument value 18446744073709551615 is outside the valid range [0, 255]}}
+  SVE_ACLE_FUNC(svzero_mask_za,,,)(-1);
+}
+
 ARM_STREAMING_ATTR
 void test_constant(uint64_t u64, svbool_t pg, void *ptr) {
   SVE_ACLE_FUNC(svld1_hor_za8,,,)(u64, u64, 0, pg, ptr);  // expected-error {{argument to 'svld1_hor_za8' must be a constant integer}}
Index: clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c
===
--- /dev/null
+++ clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_zero.c
@@ -0,0 +1,52 @@
+// REQUIRES: aarch64-registered-target
+// RUN: %clang_cc1 -DDISABLE_SME_ATTRIBUTES -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - %s | FileCheck %s -check-prefixes=CHECK,CHECK-C
+// RUN: %clang_cc1 -DDISABLE_SME_ATTRIBUTES -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -emit-llvm -o - -x c++ %s | FileCheck %s -check-prefixes=CHECK,CHECK-CXX
+// RUN: %clang_cc1 -DDISABLE_SME_ATTRIBUTES -triple aarch64-none-linux-gnu -target-feature +sme -target-feature +sve -S -O1 -Werror -o /dev/null %s
+
+#include 
+
+#ifdef DISABLE_SME_ATTRIBUTES
+#define ARM_SHARED_ZA_ATTR
+#else
+#define ARM_SHARED_ZA_ATTR __attribute__((arm_shared_za))
+#endif
+
+// CHECK-C-LABEL: @test_svzero_mask_za(
+// CHECK-CXX-LABEL: @_Z19test_svzero_mask_zav(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 0)
+// CHECK-NEXT:ret void
+//
+ARM_SHARED_ZA_ATTR void test_svzero_mask_za() {
+  svzero_mask_za(0);
+}
+
+// CHECK-C-LABEL: @test_svzero_mask_za_1(
+// CHECK-CXX-LABEL: @_Z21test_svzero_mask_za_1v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 176)
+// CHECK-NEXT:ret void
+//
+ARM_SHARED_ZA_ATTR void test_svzero_mask_za_1() {
+  svzero_mask_za(176);
+}
+
+// CHECK-C-LABEL: @test_svzero_mask_za_2(
+// CHECK-CXX-LABEL: @_Z21test_svzero_mask_za_2v(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 255)
+// CHECK-NEXT:ret void
+//
+ARM_SHARED_ZA_ATTR void test_svzero_mask_za_2() {
+  svzero_mask_za(255);
+}
+
+// CHECK-C-LABEL: @test_svzero_za(
+// CHECK-CXX-LABEL: @_Z14test_svzero_zav(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.zero(i32 255)
+// CHECK-NEXT:ret void
+//
+ARM_SHARED_ZA_ATTR void test_svzero_za() {
+  svzero_za();
+}
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -2995,6 +2995,10 @@
   if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 0, 15))
 HasError = true;
   break;
+case SVETypeFlags::ImmCheck0_255:
+  if (SemaBuiltinConstantArgRange(TheCall, ArgNum, 0, 255))
+HasError = true;
+  break;
 }
   }
 
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -4266,6 +4266,9 @@
   llvm::Value *EmitSMEReadWrite(SVETypeFlags TypeFlags,
 llvm::SmallVectorImpl ,
 unsigned IntID);
+  llvm::Value *EmitSMEZero(SVETypeFlags TypeFlags,
+   llvm::SmallVectorImpl ,
+   unsigned IntID);
   llvm::Value *EmitAArch64SMEBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
 
   llvm::Value *EmitAArch64BuiltinExpr(unsigned 

[PATCH] D153208: [clang-format] Add InsertNewlineAtEOF to .clang-format files

2023-06-17 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, MyDeveloperDay.
owenpan requested review of this revision.

Also, add `Language: Cpp` to make it explicit. Then reformat all clang-format 
related files.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153208

Files:
  clang/include/clang/Format/.clang-format
  clang/lib/Format/.clang-format
  clang/tools/clang-format/.clang-format
  clang/unittests/Format/.clang-format
  clang/unittests/Format/FormatTestMacroExpansion.cpp


Index: clang/unittests/Format/FormatTestMacroExpansion.cpp
===
--- clang/unittests/Format/FormatTestMacroExpansion.cpp
+++ clang/unittests/Format/FormatTestMacroExpansion.cpp
@@ -259,4 +259,4 @@
 } // namespace
 } // namespace test
 } // namespace format
-} // namespace clang
\ No newline at end of file
+} // namespace clang
Index: clang/unittests/Format/.clang-format
===
--- clang/unittests/Format/.clang-format
+++ clang/unittests/Format/.clang-format
@@ -1,4 +1,6 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
+Language: Cpp
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/tools/clang-format/.clang-format
===
--- clang/tools/clang-format/.clang-format
+++ clang/tools/clang-format/.clang-format
@@ -1,4 +1,6 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
+Language: Cpp
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/lib/Format/.clang-format
===
--- clang/lib/Format/.clang-format
+++ clang/lib/Format/.clang-format
@@ -1,4 +1,6 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
+Language: Cpp
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/include/clang/Format/.clang-format
===
--- clang/include/clang/Format/.clang-format
+++ clang/include/clang/Format/.clang-format
@@ -1,4 +1,6 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
+Language: Cpp
 LineEnding: LF
 RemoveBracesLLVM: true


Index: clang/unittests/Format/FormatTestMacroExpansion.cpp
===
--- clang/unittests/Format/FormatTestMacroExpansion.cpp
+++ clang/unittests/Format/FormatTestMacroExpansion.cpp
@@ -259,4 +259,4 @@
 } // namespace
 } // namespace test
 } // namespace format
-} // namespace clang
\ No newline at end of file
+} // namespace clang
Index: clang/unittests/Format/.clang-format
===
--- clang/unittests/Format/.clang-format
+++ clang/unittests/Format/.clang-format
@@ -1,4 +1,6 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
+Language: Cpp
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/tools/clang-format/.clang-format
===
--- clang/tools/clang-format/.clang-format
+++ clang/tools/clang-format/.clang-format
@@ -1,4 +1,6 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
+Language: Cpp
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/lib/Format/.clang-format
===
--- clang/lib/Format/.clang-format
+++ clang/lib/Format/.clang-format
@@ -1,4 +1,6 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
+Language: Cpp
 LineEnding: LF
 RemoveBracesLLVM: true
Index: clang/include/clang/Format/.clang-format
===
--- clang/include/clang/Format/.clang-format
+++ clang/include/clang/Format/.clang-format
@@ -1,4 +1,6 @@
 BasedOnStyle: LLVM
 InsertBraces: true
+InsertNewlineAtEOF: true
+Language: Cpp
 LineEnding: LF
 RemoveBracesLLVM: true
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8411bdb - [clang-format][NFC] Remove redundant getLLVMStyle() in unit tests

2023-06-17 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-06-17T15:25:59-07:00
New Revision: 8411bdb0acde8569c9bfcd08401fa587f7dea834

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

LOG: [clang-format][NFC] Remove redundant getLLVMStyle() in unit tests

Added: 


Modified: 
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/FormatTestComments.cpp

Removed: 




diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index ebf5850da439a..4c58df893aa8f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -312,8 +312,7 @@ TEST_F(FormatTest, RemovesEmptyLines) {
"\n"
"  }\n"
"\n"
-   "}",
-   getLLVMStyle()));
+   "}"));
   EXPECT_EQ("void f() {\n"
 "  if (a) {\n"
 "f();\n"
@@ -2565,8 +2564,7 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
"g();\n"
"break;\n"
"  }\n"
-   "});",
-   getLLVMStyle()));
+   "});"));
   EXPECT_EQ("switch (n) {\n"
 "case 0: {\n"
 "  return false;\n"
@@ -2583,8 +2581,7 @@ TEST_F(FormatTest, FormatsSwitchStatement) {
"default: {\n"
"  return true;\n"
"}\n"
-   "}",
-   getLLVMStyle()));
+   "}"));
   verifyFormat("switch (a) {\n"
"case (b):\n"
"  return;\n"
@@ -5512,14 +5509,14 @@ TEST_F(FormatTest, MacroDefinitionInsideStatement) {
 }
 
 TEST_F(FormatTest, HashInMacroDefinition) {
-  verifyFormat("#define A(c) L#c", getLLVMStyle());
-  verifyFormat("#define A(c) u#c", getLLVMStyle());
-  verifyFormat("#define A(c) U#c", getLLVMStyle());
-  verifyFormat("#define A(c) u8#c", getLLVMStyle());
-  verifyFormat("#define A(c) LR#c", getLLVMStyle());
-  verifyFormat("#define A(c) uR#c", getLLVMStyle());
-  verifyFormat("#define A(c) UR#c", getLLVMStyle());
-  verifyFormat("#define A(c) u8R#c", getLLVMStyle());
+  verifyFormat("#define A(c) L#c");
+  verifyFormat("#define A(c) u#c");
+  verifyFormat("#define A(c) U#c");
+  verifyFormat("#define A(c) u8#c");
+  verifyFormat("#define A(c) LR#c");
+  verifyFormat("#define A(c) uR#c");
+  verifyFormat("#define A(c) UR#c");
+  verifyFormat("#define A(c) u8R#c");
   verifyFormat("#define A \\\n  b #c;", getLLVMStyleWithColumns(11));
   verifyFormat("#define A  \\\n"
"  {\\\n"
@@ -12192,8 +12189,7 @@ TEST_F(FormatTest, BreaksLongDeclarations) {
 
   verifyFormat("template  // Templates on own line.\n"
"static int// Some comment.\n"
-   "MyFunction(int a);",
-   getLLVMStyle());
+   "MyFunction(int a);");
 }
 
 TEST_F(FormatTest, FormatsAccessModifiers) {
@@ -16202,15 +16198,13 @@ TEST_F(FormatTest, CalculatesOriginalColumn) {
 "   comment */",
 format("  \"qq\\\n"
"q\"; /* some\n"
-   "   comment */",
-   getLLVMStyle()));
+   "   comment */"));
   EXPECT_EQ("// qq\n"
 "/* some\n"
 "   comment */",
 format("// qq\n"
" /* some\n"
-   "comment */",
-   getLLVMStyle()));
+   "comment */"));
   EXPECT_EQ("// qq\\\n"
 "qqq\n"
 "/* some\n"
@@ -16218,15 +16212,13 @@ TEST_F(FormatTest, CalculatesOriginalColumn) {
 format("// qq\\\n"
"qqq\n"
" /* some\n"
-   "comment */",
-   getLLVMStyle()));
+   "comment */"));
   EXPECT_EQ("inttt qqq\\\n"
 "; /* some\n"
 " comment */",
 format("  inttt qqq\\\n"
"; /* some\n"
-   " comment */",
-   getLLVMStyle()));
+   " comment */"));
 }
 
 TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
@@ -20416,8 +20408,7 @@ TEST_F(FormatTest, CatchExceptionReferenceBinding) {
"  try {\n"
"  } catch (const Exception ) {\n"
"  }\n"
-   "}\n",
-   getLLVMStyle());
+   "}\n");
 }
 
 TEST_F(FormatTest, CatchAlignArrayOfStructuresRightAlignment) {
@@ -22669,22 +22660,19 @@ TEST_F(FormatTest, 

[PATCH] D149867: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-06-17 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:559
+emitError |= DefaultCC == LangOptions::DCC_StdCall &&
+ Arch != llvm::Triple::m68k && Arch != llvm::Triple::x86;
 emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||

aaron.ballman wrote:
> Maybe it's too early in the morning for me to be thinking clearly, but this 
> is wrong for m68k, isn't it? If the default calling convention is stdcall and 
> the architecture is m68k, we want to emit the error, don't we?
> 
> I don't see test coverage for the change.
The idea was to use our new RTD CC whenever `-mrtd` is given to either the 
driver or the frontend. Due to some historical reasons `-mrtd` has been taken 
by i386 to specify stdcall. Specifically, DefaultCallingConvention will be set 
to `DCC_StdCall` when `-mrtd` is present. My original approach was to reuse 
this workflow and the `DCC_StdCall`, then translate to either `CC_X86StdCall` 
or `CC_M68kRTD` later in ASTContext.

Since there are many concerns on reusing DCC_StdCall, I will create another DCC 
enum value instead.



Comment at: clang/test/Sema/m68k-mrtd.c:4-9
+#ifdef MRTD
+// expected-error@+3 {{function with no prototype cannot use the m68k_rtd 
calling convention}}
+#endif
+void foo(int arg) {
+  bar(arg);
+}

aaron.ballman wrote:
> A better way to do this is to use `-verify=mrtd` on the line enabling rtd, 
> and using `// rtd-error {{whatever}}` on the line being diagnosed. (Same 
> comment applies throughout the file.)
> 
> Huh, I was unaware that implicit function declarations are using something 
> other than the default calling convention (which is C, not m68k_rtd). Is this 
> intentional?
> Huh, I was unaware that implicit function declarations are using something 
> other than the default calling convention (which is C, not m68k_rtd). Is this 
> intentional?

I'm not sure if I understand you correctly, but this diagnostic is emitted if 
the CC does not support variadic function call. 



Comment at: clang/test/Sema/m68k-mrtd.c:45
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);

aaron.ballman wrote:
> Missing tests for:
> 
> * Function without a prototype
> * Applying the attribute to a non-function
> * Providing arguments to the attribute
> * What should happen for C++ and things like member functions?
> Function without a prototype

I thought the first check was testing function without a prototype.

> What should happen for C++ and things like member functions?

I believe we don't have any special handling for C++.

I addressed rest of the bullet items you mentioned, please take a look.


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

https://reviews.llvm.org/D149867

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


[PATCH] D149867: [Clang][M68k] Add Clang support for the new M68k_RTD CC

2023-06-17 Thread Min-Yih Hsu via Phabricator via cfe-commits
myhsu updated this revision to Diff 532423.
myhsu marked 5 inline comments as done.
myhsu edited the summary of this revision.
myhsu added a comment.
Herald added a subscriber: MaskRay.

- Add a new default calling convention `-fdefault-calling-conv=rtdcall` to 
model using `m68k_rtdcc` globally
- Add documents for `rtdcall`
- Add more tests on `__attribute__((m68k_rtd))`


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

https://reviews.llvm.org/D149867

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang-c/Index.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Basic/Targets/M68k.cpp
  clang/lib/Basic/Targets/M68k.h
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGen/mrtd.c
  clang/test/Sema/m68k-mrtd.c
  clang/tools/libclang/CXType.cpp

Index: clang/tools/libclang/CXType.cpp
===
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -678,6 +678,7 @@
   TCALLINGCONV(SwiftAsync);
   TCALLINGCONV(PreserveMost);
   TCALLINGCONV(PreserveAll);
+  TCALLINGCONV(M68kRTD);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_AMDGPUKernelCall: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
Index: clang/test/Sema/m68k-mrtd.c
===
--- /dev/null
+++ clang/test/Sema/m68k-mrtd.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -mrtd -std=c89 -verify -verify=rtd %s
+// RUN: %clang_cc1 -triple m68k-unknown-unknown -std=c89 -verify -verify=nortd %s
+
+// rtd-error@+2 {{function with no prototype cannot use the m68k_rtd calling convention}}
+void foo(int arg) {
+  bar(arg);
+}
+
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+// nortd-note@+4 {{previous declaration is here}}
+// nortd-error@+4 {{function declared 'm68k_rtd' here was previously declared without calling convention}}
+void nonvariadic1(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic1(int a, int b, int c);
+void nonvariadic2(int a, int b, int c);
+void __attribute__((m68k_rtd)) nonvariadic2(int a, int b, int c) { }
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+void variadic(int a, ...);
+void __attribute__((m68k_rtd)) variadic(int a, ...);
+
+// rtd-note@+2 {{previous declaration is here}}
+// rtd-error@+2 {{redeclaration of 'a' with a different type: 'void ((*))(int, int) __attribute__((cdecl))' vs 'void (*)(int, int) __attribute__((m68k_rtd))'}}
+extern void (*a)(int, int);
+__attribute__((cdecl)) extern void (*a)(int, int);
+
+extern void (*b)(int, ...);
+__attribute__((cdecl)) extern void (*b)(int, ...);
+
+// nortd-note@+2 {{previous declaration is here}}
+// nortd-error@+2 {{redeclaration of 'c' with a different type: 'void ((*))(int, int) __attribute__((m68k_rtd))' vs 'void (*)(int, int)'}}
+extern void (*c)(int, int);
+__attribute__((m68k_rtd)) extern void (*c)(int, int);
+
+// expected-error@+2 {{variadic function cannot use m68k_rtd calling convention}}
+extern void (*d)(int, ...);
+__attribute__((m68k_rtd)) extern void (*d)(int, ...);
+
+// expected-warning@+1 {{'m68k_rtd' only applies to function types; type here is 'int'}}
+__attribute__((m68k_rtd)) static int g = 0;
+
+// expected-error@+1 {{'m68k_rtd' attribute takes no arguments}}
+void __attribute__((m68k_rtd("invalid"))) z(int a);
Index: clang/test/CodeGen/mrtd.c
===
--- clang/test/CodeGen/mrtd.c
+++ clang/test/CodeGen/mrtd.c
@@ -1,20 +1,24 @@
-// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck %s
-
-// CHECK: mrtd.c:10:3: warning: function with no prototype cannot use the stdcall calling convention
+// RUN: %clang_cc1 -mrtd -triple i386-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,X86 %s
+// RUN: %clang_cc1 -mrtd -triple m68k-unknown-unknown -std=c89 -emit-llvm -o - %s 2>&1 | FileCheck --check-prefixes=CHECK,M68k %s
 
 void baz(int arg);
 
-// CHECK: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// X86: define{{.*}} x86_stdcallcc void @foo(i32 noundef %arg) [[NUW:#[0-9]+]]
+// M68k: define{{.*}} m68k_rtdcc void @foo(i32 noundef %arg)
 void foo(int arg) {
-// CHECK: call x86_stdcallcc i32 @bar(
+// X86: call x86_stdcallcc i32 

[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 updated this revision to Diff 532424.
JOE1994 added a comment.

- git clang-format (update clang/lib/CodGen/CGBlocks.cpp)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153196

Files:
  clang/lib/CodeGen/Address.h
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/SystemZ.cpp

Index: clang/lib/CodeGen/Targets/SystemZ.cpp
===
--- clang/lib/CodeGen/Targets/SystemZ.cpp
+++ clang/lib/CodeGen/Targets/SystemZ.cpp
@@ -302,8 +302,7 @@
 Address OverflowArgArea =
 Address(CGF.Builder.CreateLoad(OverflowArgAreaPtr, "overflow_arg_area"),
 CGF.Int8Ty, TyInfo.Align);
-Address MemAddr =
-CGF.Builder.CreateElementBitCast(OverflowArgArea, DirectTy, "mem_addr");
+Address MemAddr = OverflowArgArea.withElementType(DirectTy);
 
 // Update overflow_arg_area_ptr pointer
 llvm::Value *NewOverflowArgArea = CGF.Builder.CreateGEP(
@@ -360,8 +359,7 @@
   Address RawRegAddr(
   CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, RegOffset, "raw_reg_addr"),
   CGF.Int8Ty, PaddedSize);
-  Address RegAddr =
-  CGF.Builder.CreateElementBitCast(RawRegAddr, DirectTy, "reg_addr");
+  Address RegAddr = RawRegAddr.withElementType(DirectTy);
 
   // Update the register count
   llvm::Value *One = llvm::ConstantInt::get(IndexTy, 1);
@@ -381,8 +379,7 @@
   CGF.Int8Ty, PaddedSize);
   Address RawMemAddr =
   CGF.Builder.CreateConstByteGEP(OverflowArgArea, Padding, "raw_mem_addr");
-  Address MemAddr =
-CGF.Builder.CreateElementBitCast(RawMemAddr, DirectTy, "mem_addr");
+  Address MemAddr = RawMemAddr.withElementType(DirectTy);
 
   // Update overflow_arg_area_ptr pointer
   llvm::Value *NewOverflowArgArea =
Index: clang/lib/CodeGen/Targets/Sparc.cpp
===
--- clang/lib/CodeGen/Targets/Sparc.cpp
+++ clang/lib/CodeGen/Targets/Sparc.cpp
@@ -315,7 +315,7 @@
   case ABIArgInfo::Indirect:
   case ABIArgInfo::IndirectAliased:
 Stride = SlotSize;
-ArgAddr = Builder.CreateElementBitCast(Addr, ArgPtrTy, "indirect");
+ArgAddr = Addr.withElementType(ArgPtrTy);
 ArgAddr = Address(Builder.CreateLoad(ArgAddr, "indirect.arg"), ArgTy,
   TypeInfo.Align);
 break;
@@ -328,7 +328,7 @@
   Address NextPtr = Builder.CreateConstInBoundsByteGEP(Addr, Stride, "ap.next");
   Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
 
-  return Builder.CreateElementBitCast(ArgAddr, ArgTy, "arg.addr");
+  return ArgAddr.withElementType(ArgTy);
 }
 
 void SparcV9ABIInfo::computeInfo(CGFunctionInfo ) const {
Index: clang/lib/CodeGen/Targets/Hexagon.cpp
===
--- clang/lib/CodeGen/Targets/Hexagon.cpp
+++ clang/lib/CodeGen/Targets/Hexagon.cpp
@@ -236,7 +236,7 @@
   // FIXME: Need to handle alignment
   llvm::Type *BP = CGF.Int8PtrTy;
   CGBuilderTy  = CGF.Builder;
-  Address VAListAddrAsBPP = Builder.CreateElementBitCast(VAListAddr, BP, "ap");
+  Address VAListAddrAsBPP = VAListAddr.withElementType(BP);
   llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
   // Handle address alignment for type alignment > 32 bits
   uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8;
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1279,7 +1279,7 @@
 void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction ,
   const CXXRecordDecl *RD) {
   Address This = getThisAddress(CGF);
-  This = CGF.Builder.CreateElementBitCast(This, CGM.Int8Ty, "this.int8");
+  This = This.withElementType(CGM.Int8Ty);
   const ASTContext  = getContext();
   const ASTRecordLayout  = Context.getASTRecordLayout(RD);
 
@@ -1296,8 +1296,7 @@
 Address VBPtr = CGF.Builder.CreateConstInBoundsByteGEP(This, Offs);
 llvm::Value *GVPtr =
 CGF.Builder.CreateConstInBoundsGEP2_32(GV->getValueType(), GV, 0, 0);
-VBPtr = CGF.Builder.CreateElementBitCast(VBPtr, GVPtr->getType(),
-  "vbptr." + VBT->ObjectWithVPtr->getName());
+VBPtr = VBPtr.withElementType(GVPtr->getType());
 CGF.Builder.CreateStore(GVPtr, VBPtr);
   }
 }
Index: clang/lib/CodeGen/CodeGenFunction.cpp

[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/lib/CodeGen/CGBlocks.cpp:1262-1263
 auto  = getBlockByrefInfo(variable);
 addr = Address(Builder.CreateLoad(addr), Int8Ty, byrefInfo.ByrefAlignment);
-
-addr = Builder.CreateElementBitCast(addr, byrefInfo.Type, "byref.addr");
+addr = addr.withElementType(byrefInfo.Type);
 

barannikov88 wrote:
> I meant something like this :)
(It it is equivalent, that is.)



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153196

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


[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 updated this revision to Diff 532422.
JOE1994 added a comment.

- Apply suggested change (combining 2 lines) from barannikov88


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153196

Files:
  clang/lib/CodeGen/Address.h
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/SystemZ.cpp

Index: clang/lib/CodeGen/Targets/SystemZ.cpp
===
--- clang/lib/CodeGen/Targets/SystemZ.cpp
+++ clang/lib/CodeGen/Targets/SystemZ.cpp
@@ -302,8 +302,7 @@
 Address OverflowArgArea =
 Address(CGF.Builder.CreateLoad(OverflowArgAreaPtr, "overflow_arg_area"),
 CGF.Int8Ty, TyInfo.Align);
-Address MemAddr =
-CGF.Builder.CreateElementBitCast(OverflowArgArea, DirectTy, "mem_addr");
+Address MemAddr = OverflowArgArea.withElementType(DirectTy);
 
 // Update overflow_arg_area_ptr pointer
 llvm::Value *NewOverflowArgArea = CGF.Builder.CreateGEP(
@@ -360,8 +359,7 @@
   Address RawRegAddr(
   CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, RegOffset, "raw_reg_addr"),
   CGF.Int8Ty, PaddedSize);
-  Address RegAddr =
-  CGF.Builder.CreateElementBitCast(RawRegAddr, DirectTy, "reg_addr");
+  Address RegAddr = RawRegAddr.withElementType(DirectTy);
 
   // Update the register count
   llvm::Value *One = llvm::ConstantInt::get(IndexTy, 1);
@@ -381,8 +379,7 @@
   CGF.Int8Ty, PaddedSize);
   Address RawMemAddr =
   CGF.Builder.CreateConstByteGEP(OverflowArgArea, Padding, "raw_mem_addr");
-  Address MemAddr =
-CGF.Builder.CreateElementBitCast(RawMemAddr, DirectTy, "mem_addr");
+  Address MemAddr = RawMemAddr.withElementType(DirectTy);
 
   // Update overflow_arg_area_ptr pointer
   llvm::Value *NewOverflowArgArea =
Index: clang/lib/CodeGen/Targets/Sparc.cpp
===
--- clang/lib/CodeGen/Targets/Sparc.cpp
+++ clang/lib/CodeGen/Targets/Sparc.cpp
@@ -315,7 +315,7 @@
   case ABIArgInfo::Indirect:
   case ABIArgInfo::IndirectAliased:
 Stride = SlotSize;
-ArgAddr = Builder.CreateElementBitCast(Addr, ArgPtrTy, "indirect");
+ArgAddr = Addr.withElementType(ArgPtrTy);
 ArgAddr = Address(Builder.CreateLoad(ArgAddr, "indirect.arg"), ArgTy,
   TypeInfo.Align);
 break;
@@ -328,7 +328,7 @@
   Address NextPtr = Builder.CreateConstInBoundsByteGEP(Addr, Stride, "ap.next");
   Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
 
-  return Builder.CreateElementBitCast(ArgAddr, ArgTy, "arg.addr");
+  return ArgAddr.withElementType(ArgTy);
 }
 
 void SparcV9ABIInfo::computeInfo(CGFunctionInfo ) const {
Index: clang/lib/CodeGen/Targets/Hexagon.cpp
===
--- clang/lib/CodeGen/Targets/Hexagon.cpp
+++ clang/lib/CodeGen/Targets/Hexagon.cpp
@@ -236,7 +236,7 @@
   // FIXME: Need to handle alignment
   llvm::Type *BP = CGF.Int8PtrTy;
   CGBuilderTy  = CGF.Builder;
-  Address VAListAddrAsBPP = Builder.CreateElementBitCast(VAListAddr, BP, "ap");
+  Address VAListAddrAsBPP = VAListAddr.withElementType(BP);
   llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
   // Handle address alignment for type alignment > 32 bits
   uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8;
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1279,7 +1279,7 @@
 void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction ,
   const CXXRecordDecl *RD) {
   Address This = getThisAddress(CGF);
-  This = CGF.Builder.CreateElementBitCast(This, CGM.Int8Ty, "this.int8");
+  This = This.withElementType(CGM.Int8Ty);
   const ASTContext  = getContext();
   const ASTRecordLayout  = Context.getASTRecordLayout(RD);
 
@@ -1296,8 +1296,7 @@
 Address VBPtr = CGF.Builder.CreateConstInBoundsByteGEP(This, Offs);
 llvm::Value *GVPtr =
 CGF.Builder.CreateConstInBoundsGEP2_32(GV->getValueType(), GV, 0, 0);
-VBPtr = CGF.Builder.CreateElementBitCast(VBPtr, GVPtr->getType(),
-  "vbptr." + VBT->ObjectWithVPtr->getName());
+VBPtr = VBPtr.withElementType(GVPtr->getType());
 CGF.Builder.CreateStore(GVPtr, VBPtr);
   }
 }
Index: clang/lib/CodeGen/CodeGenFunction.cpp

[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/lib/CodeGen/CGBlocks.cpp:1262-1263
 auto  = getBlockByrefInfo(variable);
 addr = Address(Builder.CreateLoad(addr), Int8Ty, byrefInfo.ByrefAlignment);
-
-addr = Builder.CreateElementBitCast(addr, byrefInfo.Type, "byref.addr");
+addr = addr.withElementType(byrefInfo.Type);
 

I meant something like this :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153196

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


[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 updated this revision to Diff 532421.
JOE1994 added a comment.
Herald added subscribers: jrtc27, fedor.sergeev, jyknight.

- Rebase onto latest llvm-project main

- Remove awkward empty line in `clang/lib/CodeGen/CGBlocks.cpp`, as suggested 
by barannikov88


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153196

Files:
  clang/lib/CodeGen/Address.h
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/Targets/Hexagon.cpp
  clang/lib/CodeGen/Targets/Sparc.cpp
  clang/lib/CodeGen/Targets/SystemZ.cpp

Index: clang/lib/CodeGen/Targets/SystemZ.cpp
===
--- clang/lib/CodeGen/Targets/SystemZ.cpp
+++ clang/lib/CodeGen/Targets/SystemZ.cpp
@@ -302,8 +302,7 @@
 Address OverflowArgArea =
 Address(CGF.Builder.CreateLoad(OverflowArgAreaPtr, "overflow_arg_area"),
 CGF.Int8Ty, TyInfo.Align);
-Address MemAddr =
-CGF.Builder.CreateElementBitCast(OverflowArgArea, DirectTy, "mem_addr");
+Address MemAddr = OverflowArgArea.withElementType(DirectTy);
 
 // Update overflow_arg_area_ptr pointer
 llvm::Value *NewOverflowArgArea = CGF.Builder.CreateGEP(
@@ -360,8 +359,7 @@
   Address RawRegAddr(
   CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, RegOffset, "raw_reg_addr"),
   CGF.Int8Ty, PaddedSize);
-  Address RegAddr =
-  CGF.Builder.CreateElementBitCast(RawRegAddr, DirectTy, "reg_addr");
+  Address RegAddr = RawRegAddr.withElementType(DirectTy);
 
   // Update the register count
   llvm::Value *One = llvm::ConstantInt::get(IndexTy, 1);
@@ -381,8 +379,7 @@
   CGF.Int8Ty, PaddedSize);
   Address RawMemAddr =
   CGF.Builder.CreateConstByteGEP(OverflowArgArea, Padding, "raw_mem_addr");
-  Address MemAddr =
-CGF.Builder.CreateElementBitCast(RawMemAddr, DirectTy, "mem_addr");
+  Address MemAddr = RawMemAddr.withElementType(DirectTy);
 
   // Update overflow_arg_area_ptr pointer
   llvm::Value *NewOverflowArgArea =
Index: clang/lib/CodeGen/Targets/Sparc.cpp
===
--- clang/lib/CodeGen/Targets/Sparc.cpp
+++ clang/lib/CodeGen/Targets/Sparc.cpp
@@ -315,7 +315,7 @@
   case ABIArgInfo::Indirect:
   case ABIArgInfo::IndirectAliased:
 Stride = SlotSize;
-ArgAddr = Builder.CreateElementBitCast(Addr, ArgPtrTy, "indirect");
+ArgAddr = Addr.withElementType(ArgPtrTy);
 ArgAddr = Address(Builder.CreateLoad(ArgAddr, "indirect.arg"), ArgTy,
   TypeInfo.Align);
 break;
@@ -328,7 +328,7 @@
   Address NextPtr = Builder.CreateConstInBoundsByteGEP(Addr, Stride, "ap.next");
   Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
 
-  return Builder.CreateElementBitCast(ArgAddr, ArgTy, "arg.addr");
+  return ArgAddr.withElementType(ArgTy);
 }
 
 void SparcV9ABIInfo::computeInfo(CGFunctionInfo ) const {
Index: clang/lib/CodeGen/Targets/Hexagon.cpp
===
--- clang/lib/CodeGen/Targets/Hexagon.cpp
+++ clang/lib/CodeGen/Targets/Hexagon.cpp
@@ -236,7 +236,7 @@
   // FIXME: Need to handle alignment
   llvm::Type *BP = CGF.Int8PtrTy;
   CGBuilderTy  = CGF.Builder;
-  Address VAListAddrAsBPP = Builder.CreateElementBitCast(VAListAddr, BP, "ap");
+  Address VAListAddrAsBPP = VAListAddr.withElementType(BP);
   llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
   // Handle address alignment for type alignment > 32 bits
   uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8;
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1279,7 +1279,7 @@
 void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction ,
   const CXXRecordDecl *RD) {
   Address This = getThisAddress(CGF);
-  This = CGF.Builder.CreateElementBitCast(This, CGM.Int8Ty, "this.int8");
+  This = This.withElementType(CGM.Int8Ty);
   const ASTContext  = getContext();
   const ASTRecordLayout  = Context.getASTRecordLayout(RD);
 
@@ -1296,8 +1296,7 @@
 Address VBPtr = CGF.Builder.CreateConstInBoundsByteGEP(This, Offs);
 llvm::Value *GVPtr =
 CGF.Builder.CreateConstInBoundsGEP2_32(GV->getValueType(), GV, 0, 0);
-VBPtr = CGF.Builder.CreateElementBitCast(VBPtr, GVPtr->getType(),
-  "vbptr." + VBT->ObjectWithVPtr->getName());
+VBPtr = 

[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 accepted this revision.
barannikov88 added a comment.

This needs to be rebased, there will be conflicts with 992cb984 
.




Comment at: clang/lib/CodeGen/CGBlocks.cpp:1264
 
-addr = Builder.CreateElementBitCast(addr, byrefInfo.Type, "byref.addr");
+addr = addr.withElementType(byrefInfo.Type);
 

Can this be merged with the previous line?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153196

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


[PATCH] D152975: [clang-format] Allow break after return keyword

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

See D153205#4430528 .


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152975

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


[PATCH] D153205: [clang-format] Add new block type ListInit

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

It seems to me that there has been a proliferation of new options being 
proposed and/or accepted recently. I'd like to remind everyone of the 
long-standing policy 

 of adding new options. That being said, I wonder if we should add a new 
language `LK_C` along with its variants C78 (i.e. K C), C89 (i.e. ANSI C), 
GNU extensions (e.g. #55745  
and #62755 ), etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153205

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


[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-17 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added inline comments.



Comment at: clang/test/OpenMP/target_data_codegen.cpp:355-356
 // Region 00
+// CK2-DAG: [[DEV:%[^,]+]] = sext i32 [[DEVi32:%[^,]+]] to i64
+// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
 // CK2: br i1 %{{[^,]+}}, label %[[IFTHEN:[^,]+]], label %[[IFELSE:[^,]+]]

jdoerfert wrote:
> TIFitis wrote:
> > jsjodin wrote:
> > > TIFitis wrote:
> > > > When both if clause and device clause are present, the device clause 
> > > > argument is inadvertently brought outside the `IfThen` region as we 
> > > > emit the `llvm:Value` from the `Clang::Expr` for it before making call 
> > > > to createTargetData.
> > > > 
> > > > I don't think this change would affect any use cases.
> > > > When both if clause and device clause are present, the device clause 
> > > > argument is inadvertently brought outside the `IfThen` region as we 
> > > > emit the `llvm:Value` from the `Clang::Expr` for it before making call 
> > > > to createTargetData.
> > > > 
> > > > I don't think this change would affect any use cases.
> > > 
> > > Is it at all possible that the load could cause an exception if moved 
> > > outside the if?
> > > 
> > Int pointer is not allowed inside device clause, so I don't think think the 
> > load can cause exceptions.
> > 
> > Also this would fix a scenario similar to the if clause, where in the 
> > following code `target_begin` would get device as //10// and `target_end` 
> > mapper call would get device as //100//.
> > 
> > ```
> > int arg = 10;
> > #pragma omp target data map(to: arg) if(arg < 20) device(arg)
> >   {arg = 100;}
> > ```
> > 
> Resting the value is good, computing it before the if is not. Take:
> 
> `... if(isValidPtr(p)) device(*p)`
> 
> We can generate the good code fairly easily, see above. Won't trigger much 
> and will almost always be folded to straight line code anyway, except in 
> cases like above, which is good. We end up with a phi and reuse the device 
> value, which is also good. Win Win Win 
-Resting +Reusing (apply auto-correction)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150860

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


[PATCH] D153205: [clang-format] Add new block type ListInit

2023-06-17 Thread Gedare Bloom via Phabricator via cfe-commits
gedare created this revision.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
gedare requested review of this revision.

C89 and C90 list initializers are treated differently than Cpp11 braced
initializers. This patch introduces a new block type (BK_ListInit) that
is used to identify the C array/struct initializer lists and to support
formatting rules for BracketAlignmentStyle.BlockIndent applied to them.

Addresses Issue #57878.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153205

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/FormatToken.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25494,6 +25494,155 @@
Style);
 }
 
+TEST_F(FormatTest, AlignAfterOpenBracketBlockIndentInitializers) {
+  auto Style = getLLVMStyleWithColumns(60);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+  // Aggregate initialization.
+  verifyFormat("int LongVariable[2] = {\n"
+   "1000, 2000\n"
+   "};",
+   Style);
+  verifyFormat("SomeStruct s{\n"
+   "\"\", \"\",\n"
+   "\"\"\n"
+   "};",
+   Style);
+  // Designated initializers.
+  verifyFormat("int LongVariable[1] = {\n"
+   "[0] = 1000, [1] = 2000\n"
+   "};",
+   Style);
+  verifyFormat("SomeStruct s{\n"
+   ".foo = \"x\",\n"
+   ".bar = \"y\",\n"
+   ".baz = \"z\"\n"
+   "};\n",
+   Style);
+  // List initialization.
+  verifyFormat("SomeStruct s{\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "};\n",
+   Style);
+  verifyFormat("SomeStruct{\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "};\n",
+   Style);
+  verifyFormat("new SomeStruct{\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "};\n",
+   Style);
+  // Member initializer.
+  verifyFormat("class SomeClass {\n"
+   "  SomeStruct s{\n"
+   "  \"x\",\n"
+   "  \"y\",\n"
+   "  \"z\",\n"
+   "  };\n"
+   "};\n",
+   Style);
+  // Constructor member initializer.
+  verifyFormat("SomeClass::SomeClass : strct{\n"
+   "   \"x\",\n"
+   "   \"y\",\n"
+   "   \"z\",\n"
+   "   } {}\n",
+   Style);
+  // Copy initialization.
+  verifyFormat("SomeStruct s = SomeStruct{\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "};\n",
+   Style);
+  // Copy list initialization.
+  verifyFormat("SomeStruct s = {\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "};\n",
+   Style);
+  // Assignment operand initialization.
+  verifyFormat("s = {\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "};\n",
+   Style);
+  // Returned object initialization.
+  verifyFormat("return {\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "};\n",
+   Style);
+  // Initializer list.
+  verifyFormat("auto initializerList = {\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "};\n",
+   Style);
+  // Function parameter initialization.
+  verifyFormat("func({\n"
+   "\"x\",\n"
+   "\"y\",\n"
+   "\"z\",\n"
+   "});\n",
+   Style);
+  // Nested init lists.
+  verifyFormat("SomeStruct s = {\n"
+   "

[PATCH] D152975: [clang-format] Allow break after return keyword

2023-06-17 Thread Gedare Bloom via Phabricator via cfe-commits
gedare added a comment.

In D152975#4425932 , 
@HazardyKnusperkeks wrote:

> I'd like more tests (and examples how it is before the change), some 
> operations (+, *, etc.), your stated string literal with and without many 
> spaces, call chains.

Ok. Since it applies by default, all the existing unittests use it. I will see 
about fabricating some more interesting tests for it.

> I have nothing against the introduction, I'm just not sure about the default 
> value and the position of the check in `splitPenalty`.

Yes the default was chosen arbitrarily.  Adding more tests to exercise return 
value lengths should help tune defaults.

> And please add a remark in the changelog.

Is there a separate changelog file?  I don't understand this request.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152975

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


[PATCH] D148827: -fsanitize=function: support C

2023-06-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D148827#4424237 , @uabelho wrote:

> Hi,
>
> A question: it seems like this messes with alignment on functions?
> So with input program al.c:
>
>   __attribute__((aligned(64)))
>   void alignedfn(void) {
> __asm("nop");
>   }
>   void alignedfn2(void) {
> __asm("nop");
>   }
>   int main(void){}
>
> if we compile with -fsanitize=function we get:
>
>   -> clang al.c -o al.o -c -fsanitize=function
>   -> nm al.o
>   0008 T alignedfn
>   0018 T alignedfn2
>   0028 T main
>
> So alignedfn and alignedfn2 doesn't seem to be aligned as we said.
> Without -fsanitize=function:
>
>   -> clang al.c -o al.o -c 
>   -> nm al.o
>    T alignedfn
>   0010 T alignedfn2
>   0020 T main
>
> I guess the data put before the functions get aligned but not the functions 
> themselves. Should I write a ticket about this?

When `__attribute__((aligned(...)))` is used with an instrumentation that 
places extra bytes before the function label, I think it is unclear what the 
desired behavior should be.
This applies to many instructions including `-fsanitize=kcfi`, 
`-fsanitize=function`, and `-fpatchable-function-entry=N,M` (M>0).
It's unclear whether this attribute applies to the first byte of the function 
or the first intended instruction.
For example, with `-fpatchable-function-entry=2,2`, we can make 
`st_value(foo)%64=2`.

  gcc -c -fpatchable-function-entry=2,2 -xc =(printf 
'__attribute__((aligned(64))) void foo() {}') -o a.o
  clang -c -fpatchable-function-entry=2,2 -xc =(printf 
'__attribute__((aligned(64))) void foo() {}') -o a.o

I acknowledge that 
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html says "The 
aligned attribute specifies a minimum alignment for the first instruction of 
the function, measured in bytes.", but I think the GCC documentation doesn't 
consider these instructions.
I consider Clang's behavior working as intended.

(Other angles: with PPC64 ELFv2, the local entry, the target destination of a 
function call, is not aligned by `__attribute__((aligned(...)))`. 
`__attribute__((aligned(...)))` is usually for performance reasons and has 
different tradeoff with `-fsanitize=function`.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148827

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


[PATCH] D153008: [RISCV] Allow slash-star comments in instruction operands

2023-06-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D153008#4428694 , @abel-bernabeu 
wrote:

> In D153008#4428568 , @MaskRay wrote:
>
>> This new update still applies many unneeded `getParser().Lex();` and adds a 
>> test at a wrong layer 
>> 
>>  (clang/test/CodeGen):
>
> Would you rather have:
>
> - LLVM IR as input
> - assembly as output
> - the test placed under llvm/test/CodeGen/RISCV/
>
> ?
>
> That would make the test more verbose, but it would reduce the testing scope. 
> Please confirm your preference.

I created D153204  as an alternative. Thanks 
for reporting the issue!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153008

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


[PATCH] D153198: [clang-tidy] Refactor common code from the Noexcept*Checks into `NoexceptFunctionCheck`

2023-06-17 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 532414.
AMS21 marked an inline comment as done.
AMS21 added a comment.

So somehow I didn't add the actual `BaseNoexceptFunctionCheck` files, thats why 
the build failed.

Also implemented the two new suggestions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153198

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptFunctionBaseCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h

Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
===
--- clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
+++ clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTSWAPCHECK_H
 
 #include "../ClangTidyCheck.h"
-#include "../utils/ExceptionSpecAnalyzer.h"
+#include "NoexceptFunctionBaseCheck.h"
 
 namespace clang::tidy::performance {
 
@@ -20,21 +20,17 @@
 ///
 /// For the user-facing documentation see:
 /// https://clang.llvm.org/extra/clang-tidy/checks/performance/noexcept-swap.html
-class NoexceptSwapCheck : public ClangTidyCheck {
+class NoexceptSwapCheck : public NoexceptFunctionBaseCheck {
 public:
-  NoexceptSwapCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  using NoexceptFunctionBaseCheck::NoexceptFunctionBaseCheck;
+
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  bool isLanguageVersionSupported(const LangOptions ) const override {
-return LangOpts.CPlusPlus11 && LangOpts.CXXExceptions;
-  }
-  void check(const ast_matchers::MatchFinder::MatchResult ) override;
-  std::optional getCheckTraversalKind() const override {
-return TK_IgnoreUnlessSpelledInSource;
-  }
 
 private:
-  utils::ExceptionSpecAnalyzer SpecAnalyzer;
+  DiagnosticBuilder
+  reportMissingNoexcept(const FunctionDecl *FuncDecl) final override;
+  void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl,
+  const Expr *NoexceptExpr) final override;
 };
 
 } // namespace clang::tidy::performance
Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
@@ -7,10 +7,7 @@
 //===--===//
 
 #include "NoexceptSwapCheck.h"
-#include "../utils/LexerUtils.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -18,40 +15,20 @@
 
 void NoexceptSwapCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(unless(isDeleted()), hasName("swap")).bind("decl"), this);
+  functionDecl(unless(isDeleted()), hasName("swap")).bind(BindFuncDeclName),
+  this);
 }
 
-void NoexceptSwapCheck::check(const MatchFinder::MatchResult ) {
-  const auto *FuncDecl = Result.Nodes.getNodeAs("decl");
-  assert(FuncDecl);
-
-  if (SpecAnalyzer.analyze(FuncDecl) !=
-  utils::ExceptionSpecAnalyzer::State::Throwing)
-return;
-
-  // Don't complain about nothrow(false), but complain on nothrow(expr)
-  // where expr evaluates to false.
-  const auto *ProtoType = FuncDecl->getType()->castAs();
-  const Expr *NoexceptExpr = ProtoType->getNoexceptExpr();
-  if (NoexceptExpr) {
-NoexceptExpr = NoexceptExpr->IgnoreImplicit();
-if (!isa(NoexceptExpr)) {
-  diag(NoexceptExpr->getExprLoc(),
-   "noexcept specifier on swap function evaluates to 'false'");
-}
-return;
-  }
-
-  auto Diag = diag(FuncDecl->getLocation(), "swap functions should "
-"be marked noexcept");
-
-  // Add FixIt hints.
-  const SourceManager  = *Result.SourceManager;
+DiagnosticBuilder
+NoexceptSwapCheck::reportMissingNoexcept(const FunctionDecl *FuncDecl) {
+  return diag(FuncDecl->getLocation(), "swap functions should "
+   "be marked noexcept");
+}
 
-  const SourceLocation NoexceptLoc =
-  utils::lexer::getLocationForNoexceptSpecifier(FuncDecl, SM);
-  if (NoexceptLoc.isValid())
-Diag << FixItHint::CreateInsertion(NoexceptLoc, " noexcept ");
+void 

[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 updated this revision to Diff 532404.
JOE1994 added a comment.

- Apply suggestions from @nikic


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153196

Files:
  clang/lib/CodeGen/Address.h
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7680,8 +7680,7 @@
 Address OverflowArgArea =
 Address(CGF.Builder.CreateLoad(OverflowArgAreaPtr, "overflow_arg_area"),
 CGF.Int8Ty, TyInfo.Align);
-Address MemAddr =
-CGF.Builder.CreateElementBitCast(OverflowArgArea, DirectTy, "mem_addr");
+Address MemAddr = OverflowArgArea.withElementType(DirectTy);
 
 // Update overflow_arg_area_ptr pointer
 llvm::Value *NewOverflowArgArea = CGF.Builder.CreateGEP(
@@ -7738,8 +7737,7 @@
   Address RawRegAddr(
   CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, RegOffset, "raw_reg_addr"),
   CGF.Int8Ty, PaddedSize);
-  Address RegAddr =
-  CGF.Builder.CreateElementBitCast(RawRegAddr, DirectTy, "reg_addr");
+  Address RegAddr = RawRegAddr.withElementType(DirectTy);
 
   // Update the register count
   llvm::Value *One = llvm::ConstantInt::get(IndexTy, 1);
@@ -7759,8 +7757,7 @@
   CGF.Int8Ty, PaddedSize);
   Address RawMemAddr =
   CGF.Builder.CreateConstByteGEP(OverflowArgArea, Padding, "raw_mem_addr");
-  Address MemAddr =
-CGF.Builder.CreateElementBitCast(RawMemAddr, DirectTy, "mem_addr");
+  Address MemAddr = RawMemAddr.withElementType(DirectTy);
 
   // Update overflow_arg_area_ptr pointer
   llvm::Value *NewOverflowArgArea =
@@ -8869,7 +8866,7 @@
   // FIXME: Need to handle alignment
   llvm::Type *BP = CGF.Int8PtrTy;
   CGBuilderTy  = CGF.Builder;
-  Address VAListAddrAsBPP = Builder.CreateElementBitCast(VAListAddr, BP, "ap");
+  Address VAListAddrAsBPP = VAListAddr.withElementType(BP);
   llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
   // Handle address alignment for type alignment > 32 bits
   uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8;
@@ -8880,9 +8877,8 @@
 AddrAsInt = Builder.CreateAnd(AddrAsInt, Builder.getInt32(~(TyAlign - 1)));
 Addr = Builder.CreateIntToPtr(AddrAsInt, BP);
   }
-  Address AddrTyped = Builder.CreateElementBitCast(
-  Address(Addr, CGF.Int8Ty, CharUnits::fromQuantity(TyAlign)),
-  CGF.ConvertType(Ty));
+  Address AddrTyped =
+  Address(Addr, CGF.ConvertType(Ty), CharUnits::fromQuantity(TyAlign));
 
   uint64_t Offset = llvm::alignTo(CGF.getContext().getTypeSize(Ty) / 8, 4);
   llvm::Value *NextAddr = Builder.CreateGEP(
@@ -9994,7 +9990,7 @@
   case ABIArgInfo::Indirect:
   case ABIArgInfo::IndirectAliased:
 Stride = SlotSize;
-ArgAddr = Builder.CreateElementBitCast(Addr, ArgPtrTy, "indirect");
+ArgAddr = Addr.withElementType(ArgPtrTy);
 ArgAddr = Address(Builder.CreateLoad(ArgAddr, "indirect.arg"), ArgTy,
   TypeInfo.Align);
 break;
@@ -10007,7 +10003,7 @@
   Address NextPtr = Builder.CreateConstInBoundsByteGEP(Addr, Stride, "ap.next");
   Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
 
-  return Builder.CreateElementBitCast(ArgAddr, ArgTy, "arg.addr");
+  return ArgAddr.withElementType(ArgTy);
 }
 
 void SparcV9ABIInfo::computeInfo(CGFunctionInfo ) const {
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1279,7 +1279,7 @@
 void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction ,
   const CXXRecordDecl *RD) {
   Address This = getThisAddress(CGF);
-  This = CGF.Builder.CreateElementBitCast(This, CGM.Int8Ty, "this.int8");
+  This = This.withElementType(CGM.Int8Ty);
   const ASTContext  = getContext();
   const ASTRecordLayout  = Context.getASTRecordLayout(RD);
 
@@ -1296,8 +1296,7 @@
 Address VBPtr = CGF.Builder.CreateConstInBoundsByteGEP(This, Offs);
 llvm::Value *GVPtr =
 CGF.Builder.CreateConstInBoundsGEP2_32(GV->getValueType(), GV, 0, 0);
-VBPtr = CGF.Builder.CreateElementBitCast(VBPtr, GVPtr->getType(),
-  "vbptr." + VBT->ObjectWithVPtr->getName());
+VBPtr = VBPtr.withElementType(GVPtr->getType());
 CGF.Builder.CreateStore(GVPtr, VBPtr);
   }
 }
Index: 

[PATCH] D153198: [clang-tidy] Refactor common code from the Noexcept*Checks into `NoexceptFunctionCheck`

2023-06-17 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added a comment.
This revision is now accepted and ready to land.

The is compiler error in CI "Cannot find source file: 
BaseNoexceptFunctionCheck.cpp".
Consider naming it NoexceptFunctionBase.cpp or  NoexceptFunctionBaseCheck.cpp 
unless there are already other .cpp files in some other modules that start with 
Base, in such case its fine.
Main reason for this is to somehow show others that this file is not an full 
check, but more a base for some checks.




Comment at: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h:29
+
+protected:
+  DiagnosticBuilder

you can put those all as private here in derived class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153198

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


[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/CodeGen/CGObjC.cpp:2207
   llvm::Type *origType = addr.getElementType();
-  addr = CGF.Builder.CreateElementBitCast(addr, CGF.Int8PtrTy);
+  addr = addr.withElementType(CGF.Int8PtrTy);
 

Can drop this call, we only use addr.getPointer() below.



Comment at: clang/lib/CodeGen/CGObjC.cpp:2214
   if (origType != CGF.Int8PtrTy)
 result = CGF.Builder.CreateBitCast(result, origType);
 

While here, might as well drop this as well.



Comment at: clang/lib/CodeGen/CGObjC.cpp:2662
   // Cast the argument to 'id*'.
-  addr = Builder.CreateElementBitCast(addr, Int8PtrTy);
+  addr = addr.withElementType(Int8PtrTy);
 

Can drop this, as we only use `addr.getPointer()` below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153196

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


[PATCH] D153198: [clang-tidy] Refactor common code from the Noexcept*Checks into `NoexceptFunctionCheck`

2023-06-17 Thread André Schackier via Phabricator via cfe-commits
AMS21 updated this revision to Diff 532394.
AMS21 marked 3 inline comments as done.
AMS21 added a comment.

Implement suggested changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153198

Files:
  clang-tools-extra/clang-tidy/performance/CMakeLists.txt
  clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h

Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
===
--- clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
+++ clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
@@ -10,7 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTSWAPCHECK_H
 
 #include "../ClangTidyCheck.h"
-#include "../utils/ExceptionSpecAnalyzer.h"
+#include "BaseNoexceptFunctionCheck.h"
 
 namespace clang::tidy::performance {
 
@@ -20,21 +20,17 @@
 ///
 /// For the user-facing documentation see:
 /// https://clang.llvm.org/extra/clang-tidy/checks/performance/noexcept-swap.html
-class NoexceptSwapCheck : public ClangTidyCheck {
+class NoexceptSwapCheck : public BaseNoexceptFunctionCheck {
 public:
-  NoexceptSwapCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  using BaseNoexceptFunctionCheck::BaseNoexceptFunctionCheck;
+
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  bool isLanguageVersionSupported(const LangOptions ) const override {
-return LangOpts.CPlusPlus11 && LangOpts.CXXExceptions;
-  }
-  void check(const ast_matchers::MatchFinder::MatchResult ) override;
-  std::optional getCheckTraversalKind() const override {
-return TK_IgnoreUnlessSpelledInSource;
-  }
-
-private:
-  utils::ExceptionSpecAnalyzer SpecAnalyzer;
+
+protected:
+  DiagnosticBuilder
+  reportMissingNoexcept(const FunctionDecl *FuncDecl) final override;
+  void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl,
+  const Expr *NoexceptExpr) final override;
 };
 
 } // namespace clang::tidy::performance
Index: clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
===
--- clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
+++ clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
@@ -7,10 +7,7 @@
 //===--===//
 
 #include "NoexceptSwapCheck.h"
-#include "../utils/LexerUtils.h"
-#include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;
 
@@ -18,40 +15,20 @@
 
 void NoexceptSwapCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
-  functionDecl(unless(isDeleted()), hasName("swap")).bind("decl"), this);
+  functionDecl(unless(isDeleted()), hasName("swap")).bind(BindFuncDeclName),
+  this);
 }
 
-void NoexceptSwapCheck::check(const MatchFinder::MatchResult ) {
-  const auto *FuncDecl = Result.Nodes.getNodeAs("decl");
-  assert(FuncDecl);
-
-  if (SpecAnalyzer.analyze(FuncDecl) !=
-  utils::ExceptionSpecAnalyzer::State::Throwing)
-return;
-
-  // Don't complain about nothrow(false), but complain on nothrow(expr)
-  // where expr evaluates to false.
-  const auto *ProtoType = FuncDecl->getType()->castAs();
-  const Expr *NoexceptExpr = ProtoType->getNoexceptExpr();
-  if (NoexceptExpr) {
-NoexceptExpr = NoexceptExpr->IgnoreImplicit();
-if (!isa(NoexceptExpr)) {
-  diag(NoexceptExpr->getExprLoc(),
-   "noexcept specifier on swap function evaluates to 'false'");
-}
-return;
-  }
-
-  auto Diag = diag(FuncDecl->getLocation(), "swap functions should "
-"be marked noexcept");
-
-  // Add FixIt hints.
-  const SourceManager  = *Result.SourceManager;
+DiagnosticBuilder
+NoexceptSwapCheck::reportMissingNoexcept(const FunctionDecl *FuncDecl) {
+  return diag(FuncDecl->getLocation(), "swap functions should "
+   "be marked noexcept");
+}
 
-  const SourceLocation NoexceptLoc =
-  utils::lexer::getLocationForNoexceptSpecifier(FuncDecl, SM);
-  if (NoexceptLoc.isValid())
-Diag << FixItHint::CreateInsertion(NoexceptLoc, " noexcept ");
+void NoexceptSwapCheck::reportNoexceptEvaluatedToFalse(
+const FunctionDecl *FuncDecl, const Expr *NoexceptExpr) {
+  diag(NoexceptExpr->getExprLoc(),
+   "noexcept specifier on swap function evaluates to 'false'");
 }
 
 } // namespace 

[PATCH] D152435: [analyzer][CStringChecker] Adjust the invalidation operation on the super region of the destination buffer during string copy

2023-06-17 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

Let me come back to this once again in the upcoming days to make sure 
everything is good.




Comment at: clang/test/Analysis/pr22954.c:581
   clang_analyzer_eval(m27.s3[i] == 1); // expected-warning{{UNKNOWN}}\
   expected-warning{{Potential leak of memory pointed to by 'm27.s4'}}
   return 0;

OikawaKirie wrote:
> Do I need to update all other leak expectation directions in this file as 
> well? Such as this one here.
Definitely no.
Its not advised to have different, but similar looking hunks out of which some 
are the consequence of the semantic change we made and also have others where 
they are just refactors.


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

https://reviews.llvm.org/D152435

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


[PATCH] D153198: [clang-tidy] Refactor common code from the Noexcept*Checks into `NoexceptFunctionCheck`

2023-06-17 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added a comment.

Overall good, my main concern is base class name & location.




Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h:23
 /// 
https://clang.llvm.org/extra/clang-tidy/checks/performance/noexcept-destructor.html
-class NoexceptDestructorCheck : public ClangTidyCheck {
+class NoexceptDestructorCheck : public utils::NoexceptFunctionCheck {
 public:

Consider putting "Base" into a name, so that it woudn't be considered a full 
check, and it can be in this module, no need to put it into utils



Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h:25-26
 public:
   NoexceptDestructorCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : NoexceptFunctionCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;

we got c++17, so delegate constructor.
using utils::NoexceptFunctionCheck::NoexceptFunctionCheck;



Comment at: 
clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h:28-30
   std::optional getCheckTraversalKind() const override {
 return TK_IgnoreUnlessSpelledInSource;
   }

consider moving this into base class



Comment at: clang-tools-extra/clang-tidy/utils/NoexceptFunctionCheck.h:34-38
+  virtual DiagnosticBuilder
+  reportMissingNoexcept(const FunctionDecl *FuncDecl) = 0;
+
+  virtual void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl,
+  const Expr *NoexceptExpr) = 0;

you can move those into protected.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153198

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


[PATCH] D153198: [clang-tidy] Refactor common code from the Noexcept*Checks into `NoexceptFunctionCheck`

2023-06-17 Thread André Schackier via Phabricator via cfe-commits
AMS21 created this revision.
AMS21 added a reviewer: PiotrZSL.
Herald added subscribers: ChuanqiXu, carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
AMS21 requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153198

Files:
  clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptDestructorCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptMoveConstructorCheck.h
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.cpp
  clang-tools-extra/clang-tidy/performance/NoexceptSwapCheck.h
  clang-tools-extra/clang-tidy/utils/CMakeLists.txt
  clang-tools-extra/clang-tidy/utils/NoexceptFunctionCheck.cpp
  clang-tools-extra/clang-tidy/utils/NoexceptFunctionCheck.h

Index: clang-tools-extra/clang-tidy/utils/NoexceptFunctionCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/utils/NoexceptFunctionCheck.h
@@ -0,0 +1,49 @@
+//===--- NoexceptFunctionCheck.h - clang-tidy ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
+
+#include "../ClangTidyCheck.h"
+#include "../utils/ExceptionSpecAnalyzer.h"
+#include "clang/AST/Decl.h"
+#include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang::tidy::utils {
+
+/// Generic check which checks if the bound function decl is
+/// marked with `noexcept` or `noexcept(expr)` where `expr` evaluates to
+/// `false`.
+class NoexceptFunctionCheck : public ClangTidyCheck {
+public:
+  NoexceptFunctionCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+
+  bool isLanguageVersionSupported(const LangOptions ) const override {
+return LangOpts.CPlusPlus11 && LangOpts.CXXExceptions;
+  }
+  void
+  check(const ast_matchers::MatchFinder::MatchResult ) final override;
+
+  virtual DiagnosticBuilder
+  reportMissingNoexcept(const FunctionDecl *FuncDecl) = 0;
+
+  virtual void reportNoexceptEvaluatedToFalse(const FunctionDecl *FuncDecl,
+  const Expr *NoexceptExpr) = 0;
+
+protected:
+  static constexpr StringRef BindFuncDeclName = "FuncDecl";
+
+private:
+  utils::ExceptionSpecAnalyzer SpecAnalyzer;
+};
+
+} // namespace clang::tidy::utils
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PERFORMANCE_NOEXCEPTFUNCTIONCHECK_H
Index: clang-tools-extra/clang-tidy/utils/NoexceptFunctionCheck.cpp
===
--- clang-tools-extra/clang-tidy/utils/NoexceptFunctionCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/NoexceptFunctionCheck.cpp
@@ -1,4 +1,4 @@
-//===--- NoexceptDestructorCheck.cpp - clang-tidy -===//
+//===--- NoexceptFunctionCheck.cpp - clang-tidy ---===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.
@@ -6,23 +6,18 @@
 //
 //===--===//
 
-#include "NoexceptDestructorCheck.h"
+#include "NoexceptFunctionCheck.h"
 #include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 
 using namespace clang::ast_matchers;
 
-namespace clang::tidy::performance {
+namespace clang::tidy::utils {
 
-void NoexceptDestructorCheck::registerMatchers(MatchFinder *Finder) {
-  Finder->addMatcher(
-  functionDecl(unless(isDeleted()), cxxDestructorDecl()).bind("decl"),
-  this);
-}
-
-void NoexceptDestructorCheck::check(const MatchFinder::MatchResult ) {
-  const auto *FuncDecl = Result.Nodes.getNodeAs("decl");
+void NoexceptFunctionCheck::check(const MatchFinder::MatchResult ) {
+  const auto *FuncDecl = Result.Nodes.getNodeAs(BindFuncDeclName);
   assert(FuncDecl);
 
   if (SpecAnalyzer.analyze(FuncDecl) !=
@@ -35,15 +30,12 @@
   const Expr *NoexceptExpr = ProtoType->getNoexceptExpr();
   if (NoexceptExpr) {
 NoexceptExpr = NoexceptExpr->IgnoreImplicit();
-if (!isa(NoexceptExpr)) {
-  diag(NoexceptExpr->getExprLoc(),
-   "noexcept specifier on the destructor evaluates to 'false'");
-}
+if (!isa(NoexceptExpr))
+  reportNoexceptEvaluatedToFalse(FuncDecl, NoexceptExpr);
 return;
   }
 
-  auto 

[PATCH] D153197: [AVR] Expand shifts during AVRISelLowering

2023-06-17 Thread Patryk Wychowaniec via Phabricator via cfe-commits
Patryk27 added inline comments.



Comment at: llvm/lib/Target/AVR/AVRISelLowering.cpp:2193
+// (the output registers are stored in this array on return).
+static MachineBasicBlock *insertMultibyteShiftLoop(
+MachineInstr , MachineBasicBlock *BB, Register ShiftNum,

Note that I've changed to code to re-arrange the generated blocks a bit, from:

```
body: |
  bb.0 (%ir-block.0):
successors: %bb.2(0x8000)
liveins: $r23r22, $r25r24, $r19r18
  
%2:dregs = COPY $r19r18
%1:dregs = COPY $r25r24
%0:dregs = COPY $r23r22
%4:gpr8 = COPY %2.sub_lo
RJMPk %bb.2
  
  bb.1 (%ir-block.0):
successors: %bb.2(0x8000)
  
%12:gpr8 = ADDRdRr %10, %10, implicit-def $sreg
%13:gpr8 = ADCRdRr %9, %9, implicit-def $sreg, implicit $sreg
%14:gpr8 = ADCRdRr %8, %8, implicit-def $sreg, implicit $sreg
%15:gpr8 = ADCRdRr %7, %7, implicit-def $sreg, implicit $sreg
  
  bb.2 (%ir-block.0):
successors: %bb.1(0x4000), %bb.3(0x4000)
  
%7:gpr8 = PHI %1.sub_hi, %bb.0, %15, %bb.1
%8:gpr8 = PHI %1.sub_lo, %bb.0, %14, %bb.1
%9:gpr8 = PHI %0.sub_hi, %bb.0, %13, %bb.1
%10:gpr8 = PHI %0.sub_lo, %bb.0, %12, %bb.1
%16:gpr8 = PHI %4, %bb.0, %17, %bb.1
%17:gpr8 = DECRd %16, implicit-def $sreg
BRPLk %bb.1, implicit $sreg
  
  bb.3 (%ir-block.0):
%6:dregs = REG_SEQUENCE %7, %subreg.sub_hi, %8, %subreg.sub_lo
%5:dregs = REG_SEQUENCE %9, %subreg.sub_hi, %10, %subreg.sub_lo
$r23r22 = COPY %5
$r25r24 = COPY %6
RET implicit $r23r22, implicit $r25r24, implicit $r1
```

... to:

```
body: |
  bb.0 (%ir-block.0):
successors: %bb.1(0x8000)
liveins: $r23r22, $r25r24, $r19r18
  
%2:dregs = COPY $r19r18
%1:dregs = COPY $r25r24
%0:dregs = COPY $r23r22
%4:gpr8 = COPY %2.sub_lo
# fall-through instead of jumping
  
  bb.1 (%ir-block.0):
successors: %bb.2(0x4000), %bb.3(0x4000)
  
%7:gpr8 = PHI %1.sub_hi, %bb.0, %15, %bb.2
%8:gpr8 = PHI %1.sub_lo, %bb.0, %14, %bb.2
%9:gpr8 = PHI %0.sub_hi, %bb.0, %13, %bb.2
%10:gpr8 = PHI %0.sub_lo, %bb.0, %12, %bb.2
%16:gpr8 = PHI %4, %bb.0, %17, %bb.2
%17:gpr8 = DECRd %16, implicit-def $sreg
BRMIk %bb.3, implicit $sreg # <- reversed comparison + fallthrough
  
  bb.2 (%ir-block.0):
successors: %bb.1(0x8000)
  
%12:gpr8 = ADDRdRr %10, %10, implicit-def $sreg
%13:gpr8 = ADCRdRr %9, %9, implicit-def $sreg, implicit $sreg
%14:gpr8 = ADCRdRr %8, %8, implicit-def $sreg, implicit $sreg
%15:gpr8 = ADCRdRr %7, %7, implicit-def $sreg, implicit $sreg
RJMPk %bb.1 # <- jump to the beginning
  
  bb.3 (%ir-block.0):
%6:dregs = REG_SEQUENCE %7, %subreg.sub_hi, %8, %subreg.sub_lo
%5:dregs = REG_SEQUENCE %9, %subreg.sub_hi, %10, %subreg.sub_lo
$r23r22 = COPY %5
$r25r24 = COPY %6
RET implicit $r23r22, implicit $r25r24, implicit $r1
```

It looks like the generated assembly remained the same, I've also checked the 
actual binary through rustc + simavr.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153197

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


[PATCH] D153197: [AVR] Expand shifts during AVRISelLowering

2023-06-17 Thread Patryk Wychowaniec via Phabricator via cfe-commits
Patryk27 created this revision.
Herald added subscribers: Jim, JDevlieghere, hiraditya, dylanmckay.
Herald added a project: All.
Patryk27 requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Some passes can introduce shifts after AVRShiftExpandPass has completed;
if this happens, we panic during isel because we assume such shifts must
have been already expanded before.

This commit integrates our shift-expansion pass with isel-selection pass
so that isel doesn't get surprised by shifts of non-constant amounts
anymore.

Spotted in the wild in rustc:

- https://github.com/rust-lang/compiler-builtins/issues/523
- https://github.com/rust-lang/rust/issues/112140


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153197

Files:
  clang/docs/tools/clang-formatted-files.txt
  llvm/lib/Target/AVR/AVR.h
  llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
  llvm/lib/Target/AVR/AVRISelLowering.cpp
  llvm/lib/Target/AVR/AVRShiftExpand.cpp
  llvm/lib/Target/AVR/AVRTargetMachine.cpp
  llvm/lib/Target/AVR/CMakeLists.txt
  llvm/test/CodeGen/AVR/shift-expand.ll
  llvm/test/CodeGen/AVR/shift-loop.ll
  llvm/test/CodeGen/AVR/shift32.ll
  llvm/utils/gn/secondary/llvm/lib/Target/AVR/BUILD.gn

Index: llvm/utils/gn/secondary/llvm/lib/Target/AVR/BUILD.gn
===
--- llvm/utils/gn/secondary/llvm/lib/Target/AVR/BUILD.gn
+++ llvm/utils/gn/secondary/llvm/lib/Target/AVR/BUILD.gn
@@ -37,7 +37,6 @@
 "AVRInstrInfo.cpp",
 "AVRMCInstLower.cpp",
 "AVRRegisterInfo.cpp",
-"AVRShiftExpand.cpp",
 "AVRSubtarget.cpp",
 "AVRTargetMachine.cpp",
 "AVRTargetObjectFile.cpp",
Index: llvm/test/CodeGen/AVR/shift32.ll
===
--- llvm/test/CodeGen/AVR/shift32.ll
+++ llvm/test/CodeGen/AVR/shift32.ll
@@ -1,6 +1,67 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc < %s -mtriple=avr -mattr=movw -verify-machineinstrs | FileCheck %s
 
+; Shift by a number unknown at compile time.
+; The 'optsize' attribute is set to avoid duplicating part of the loop.
+; TODO: it is more efficent to jump at the start and do the check where the
+; 'rjmp' is now. The branch relaxation pass puts them in this non-optimal order.
+
+define i32 @shl_i32_n(i32 %a, i32 %b) #0 {
+; CHECK-LABEL: shl_i32_n:
+; CHECK:   ; %bb.0:
+; CHECK-NEXT:  .LBB0_1: ; =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:dec r18
+; CHECK-NEXT:brmi .LBB0_3
+; CHECK-NEXT:  ; %bb.2: ; in Loop: Header=BB0_1 Depth=1
+; CHECK-NEXT:lsl r22
+; CHECK-NEXT:rol r23
+; CHECK-NEXT:rol r24
+; CHECK-NEXT:rol r25
+; CHECK-NEXT:rjmp .LBB0_1
+; CHECK-NEXT:  .LBB0_3:
+; CHECK-NEXT:ret
+  %res = shl i32 %a, %b
+  ret i32 %res
+}
+
+define i32 @lshr_i32_n(i32 %a, i32 %b) #0 {
+; CHECK-LABEL: lshr_i32_n:
+; CHECK:   ; %bb.0:
+; CHECK-NEXT:  .LBB1_1: ; =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:dec r18
+; CHECK-NEXT:brmi .LBB1_3
+; CHECK-NEXT:  ; %bb.2: ; in Loop: Header=BB1_1 Depth=1
+; CHECK-NEXT:lsr r25
+; CHECK-NEXT:ror r24
+; CHECK-NEXT:ror r23
+; CHECK-NEXT:ror r22
+; CHECK-NEXT:rjmp .LBB1_1
+; CHECK-NEXT:  .LBB1_3:
+; CHECK-NEXT:ret
+  %res = lshr i32 %a, %b
+  ret i32 %res
+}
+
+define i32 @ashr_i32_n(i32 %a, i32 %b) #0 {
+; CHECK-LABEL: ashr_i32_n:
+; CHECK:   ; %bb.0:
+; CHECK-NEXT:  .LBB2_1: ; =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:dec r18
+; CHECK-NEXT:brmi .LBB2_3
+; CHECK-NEXT:  ; %bb.2: ; in Loop: Header=BB2_1 Depth=1
+; CHECK-NEXT:asr r25
+; CHECK-NEXT:ror r24
+; CHECK-NEXT:ror r23
+; CHECK-NEXT:ror r22
+; CHECK-NEXT:rjmp .LBB2_1
+; CHECK-NEXT:  .LBB2_3:
+; CHECK-NEXT:ret
+  %res = ashr i32 %a, %b
+  ret i32 %res
+}
+
+; Shift by a constant known at compile time.
+
 define i32 @shl_i32_1(i32 %a) {
 ; CHECK-LABEL: shl_i32_1:
 ; CHECK:   ; %bb.0:
@@ -575,3 +636,5 @@
   %res = ashr i32 %a, 31
   ret i32 %res
 }
+
+attributes #0 = { optsize }
Index: llvm/test/CodeGen/AVR/shift-loop.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AVR/shift-loop.ll
@@ -0,0 +1,46 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+; RUN: llc < %s -mtriple=avr -verify-machineinstrs -stop-after=dead-mi-elimination | FileCheck %s
+
+; This test shows the machine IR that is generated when lowering a shift
+; operation to a loop.
+
+define i32 @shl_i32_n(i32 %a, i32 %b) #0 {
+  ; CHECK-LABEL: name: shl_i32_n
+  ; CHECK: bb.0 (%ir-block.0):
+  ; CHECK-NEXT:   successors: %bb.1(0x8000)
+  ; CHECK-NEXT:   liveins: $r23r22, $r25r24, $r19r18
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:dregs = COPY $r19r18
+  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:dregs = COPY $r25r24
+  ; CHECK-NEXT:   [[COPY2:%[0-9]+]]:dregs = COPY $r23r22
+  ; CHECK-NEXT:   

[PATCH] D152551: [clang] Remove dead parameter of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 abandoned this revision.
JOE1994 added a comment.

By mistake, I created a new revision D153196  
instead of updating this one.
Please refer to the new revision instead. I apologize for the inconvenience.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152551

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


[PATCH] D153196: [clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)

2023-06-17 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 created this revision.
Herald added a project: All.
JOE1994 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Add `Address::withElementType()` as a replacement for 
`CGBuilderTy::CreateElementBitCast`.

- Partial progress towards replacing `CreateElementBitCast`, as it no longer 
does what its name suggests. Either replace its uses with 
`Address::withElementType()`, or remove them if no longer needed.

- Remove unused parameter 'Name' of `CreateElementBitCast`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153196

Files:
  clang/lib/CodeGen/Address.h
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGException.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGObjC.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  clang/lib/CodeGen/CGStmt.cpp
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp

Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -7680,8 +7680,7 @@
 Address OverflowArgArea =
 Address(CGF.Builder.CreateLoad(OverflowArgAreaPtr, "overflow_arg_area"),
 CGF.Int8Ty, TyInfo.Align);
-Address MemAddr =
-CGF.Builder.CreateElementBitCast(OverflowArgArea, DirectTy, "mem_addr");
+Address MemAddr = OverflowArgArea.withElementType(DirectTy);
 
 // Update overflow_arg_area_ptr pointer
 llvm::Value *NewOverflowArgArea = CGF.Builder.CreateGEP(
@@ -7738,8 +7737,7 @@
   Address RawRegAddr(
   CGF.Builder.CreateGEP(CGF.Int8Ty, RegSaveArea, RegOffset, "raw_reg_addr"),
   CGF.Int8Ty, PaddedSize);
-  Address RegAddr =
-  CGF.Builder.CreateElementBitCast(RawRegAddr, DirectTy, "reg_addr");
+  Address RegAddr = RawRegAddr.withElementType(DirectTy);
 
   // Update the register count
   llvm::Value *One = llvm::ConstantInt::get(IndexTy, 1);
@@ -7759,8 +7757,7 @@
   CGF.Int8Ty, PaddedSize);
   Address RawMemAddr =
   CGF.Builder.CreateConstByteGEP(OverflowArgArea, Padding, "raw_mem_addr");
-  Address MemAddr =
-CGF.Builder.CreateElementBitCast(RawMemAddr, DirectTy, "mem_addr");
+  Address MemAddr = RawMemAddr.withElementType(DirectTy);
 
   // Update overflow_arg_area_ptr pointer
   llvm::Value *NewOverflowArgArea =
@@ -8869,7 +8866,7 @@
   // FIXME: Need to handle alignment
   llvm::Type *BP = CGF.Int8PtrTy;
   CGBuilderTy  = CGF.Builder;
-  Address VAListAddrAsBPP = Builder.CreateElementBitCast(VAListAddr, BP, "ap");
+  Address VAListAddrAsBPP = VAListAddr.withElementType(BP);
   llvm::Value *Addr = Builder.CreateLoad(VAListAddrAsBPP, "ap.cur");
   // Handle address alignment for type alignment > 32 bits
   uint64_t TyAlign = CGF.getContext().getTypeAlign(Ty) / 8;
@@ -8880,9 +8877,8 @@
 AddrAsInt = Builder.CreateAnd(AddrAsInt, Builder.getInt32(~(TyAlign - 1)));
 Addr = Builder.CreateIntToPtr(AddrAsInt, BP);
   }
-  Address AddrTyped = Builder.CreateElementBitCast(
-  Address(Addr, CGF.Int8Ty, CharUnits::fromQuantity(TyAlign)),
-  CGF.ConvertType(Ty));
+  Address AddrTyped =
+  Address(Addr, CGF.ConvertType(Ty), CharUnits::fromQuantity(TyAlign));
 
   uint64_t Offset = llvm::alignTo(CGF.getContext().getTypeSize(Ty) / 8, 4);
   llvm::Value *NextAddr = Builder.CreateGEP(
@@ -9994,7 +9990,7 @@
   case ABIArgInfo::Indirect:
   case ABIArgInfo::IndirectAliased:
 Stride = SlotSize;
-ArgAddr = Builder.CreateElementBitCast(Addr, ArgPtrTy, "indirect");
+ArgAddr = Addr.withElementType(ArgPtrTy);
 ArgAddr = Address(Builder.CreateLoad(ArgAddr, "indirect.arg"), ArgTy,
   TypeInfo.Align);
 break;
@@ -10007,7 +10003,7 @@
   Address NextPtr = Builder.CreateConstInBoundsByteGEP(Addr, Stride, "ap.next");
   Builder.CreateStore(NextPtr.getPointer(), VAListAddr);
 
-  return Builder.CreateElementBitCast(ArgAddr, ArgTy, "arg.addr");
+  return ArgAddr.withElementType(ArgTy);
 }
 
 void SparcV9ABIInfo::computeInfo(CGFunctionInfo ) const {
Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1279,7 +1279,7 @@
 void MicrosoftCXXABI::EmitVBPtrStores(CodeGenFunction ,
   const CXXRecordDecl *RD) {
   Address This = getThisAddress(CGF);
-  This = CGF.Builder.CreateElementBitCast(This, CGM.Int8Ty, "this.int8");
+  This = This.withElementType(CGM.Int8Ty);
   const ASTContext  = getContext();
   const ASTRecordLayout  = Context.getASTRecordLayout(RD);
 
@@ -1296,8 +1296,7 @@
 Address VBPtr = CGF.Builder.CreateConstInBoundsByteGEP(This, Offs);
 llvm::Value *GVPtr =
 

[PATCH] D152696: Prevent deadlocks in death tests.

2023-06-17 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

This change is causing a lot of unittests to fail on Gentoo. I've tested both 
on amd64 and arm64; on amd64 additionally the test suite seems to hang.

  Failed Tests (75):
LLVM-Unit :: ADT/./ADTTests/APFloatTest/SemanticsDeath
LLVM-Unit :: ADT/./ADTTests/APIntTest/StringDeath
LLVM-Unit :: ADT/./ADTTests/APSIntTest/StringDeath
LLVM-Unit :: ADT/./ADTTests/BitVectorTest/0/DenseSet
LLVM-Unit :: ADT/./ADTTests/BitVectorTest/1/DenseSet
LLVM-Unit :: ADT/./ADTTests/BitfieldsTest/ValueTooBigBool
LLVM-Unit :: ADT/./ADTTests/BitfieldsTest/ValueTooBigBounded
LLVM-Unit :: ADT/./ADTTests/BitfieldsTest/ValueTooBigInt
LLVM-Unit :: ADT/./ADTTests/BumpPtrListTest/resetAlloc
LLVM-Unit :: 
ADT/./ADTTests/FallibleIteratorTest/RegularLoopExitRequiresErrorCheck
LLVM-Unit :: ADT/./ADTTests/PackedVectorTest/SignedValues
LLVM-Unit :: ADT/./ADTTests/PackedVectorTest/UnsignedValues
LLVM-Unit :: ADT/./ADTTests/STLExtrasTest/EarlyIncrementTest
LLVM-Unit :: 
ADT/./ADTTests/STLExtrasTest/EarlyIncrementTestCustomPointerIterator
LLVM-Unit :: ADT/./ADTTests/STLExtrasTest/EnumerateDifferentLengths
LLVM-Unit :: 
ADT/./ADTTests/SmallVectorReferenceInvalidationTest/0/AppendRange
LLVM-Unit :: 
ADT/./ADTTests/SmallVectorReferenceInvalidationTest/0/AssignRange
LLVM-Unit :: 
ADT/./ADTTests/SmallVectorReferenceInvalidationTest/0/InsertRange
LLVM-Unit :: 
ADT/./ADTTests/SmallVectorReferenceInvalidationTest/1/AppendRange
LLVM-Unit :: 
ADT/./ADTTests/SmallVectorReferenceInvalidationTest/1/AssignRange
LLVM-Unit :: 
ADT/./ADTTests/SmallVectorReferenceInvalidationTest/1/InsertRange
LLVM-Unit :: ADT/./ADTTests/SmallVectorTest/0/TruncateTest
LLVM-Unit :: ADT/./ADTTests/SmallVectorTest/1/TruncateTest
LLVM-Unit :: ADT/./ADTTests/SmallVectorTest/2/TruncateTest
LLVM-Unit :: ADT/./ADTTests/SmallVectorTest/3/TruncateTest
LLVM-Unit :: ADT/./ADTTests/SmallVectorTest/4/TruncateTest
LLVM-Unit :: ADT/./ADTTests/StrongIntDeathTest/OutOfBounds
LLVM-Unit :: ADT/./ADTTests/ZipIteratorTest/ZipEqualNotEqual
LLVM-Unit :: ADT/./ADTTests/ZipIteratorTest/ZipFirstNotShortest
LLVM-Unit :: 
Analysis/./AnalysisTests/CGSCCPassManagerTest/TestUpdateCGAndAnalysisManagerForPasses1
LLVM-Unit :: 
Analysis/./AnalysisTests/CGSCCPassManagerTest/TestUpdateCGAndAnalysisManagerForPasses3
LLVM-Unit :: 
Analysis/./AnalysisTests/CGSCCPassManagerTest/TestUpdateCGAndAnalysisManagerForPasses5
LLVM-Unit :: Analysis/./AnalysisTests/VFShapeAPITest/Parameters_Invalid
LLVM-Unit :: AsmParser/./AsmParserTests/AsmParserTest/NonNullTerminatedInput
LLVM-Unit :: 
BinaryFormat/./BinaryFormatTests/MsgPackWriter/TestWriteCompatibleNoBin
LLVM-Unit :: 
ExecutionEngine/JITLink/./JITLinkTests/LinkGraphTest/ContentAccessAndUpdate
LLVM-Unit :: FileCheck/./FileCheckTests/FileCheckTest/FileCheckContext
LLVM-Unit :: IR/./IRTests/ConstantsTest/ReplaceWithConstantTest
LLVM-Unit :: IR/./IRTests/GlobalTest/AlignDeath
LLVM-Unit :: IR/./IRTests/ValueHandle/AssertingVH_Asserts
LLVM-Unit :: IR/./IRTests/ValueHandle/PoisoningVH_Asserts
LLVM-Unit :: IR/./IRTests/ValueHandle/TrackingVH_Asserts
LLVM-Unit :: IR/./IRTests/ValueTest/getLocalSlotDeath
LLVM-Unit :: IR/./IRTests/VectorBuilderTest/TestFail_ReportAndAbort
LLVM-Unit :: Support/./SupportTests/AlignmentDeathTest/AlignAddr
LLVM-Unit :: Support/./SupportTests/AlignmentDeathTest/ComparisonsWithZero
LLVM-Unit :: Support/./SupportTests/AlignmentDeathTest/InvalidCTors
LLVM-Unit :: Support/./SupportTests/CastingTest/assertion_check_const_ref
LLVM-Unit :: Support/./SupportTests/CastingTest/assertion_check_ptr
LLVM-Unit :: Support/./SupportTests/CastingTest/assertion_check_ref
LLVM-Unit :: Support/./SupportTests/CastingTest/assertion_check_unique_ptr
LLVM-Unit :: Support/./SupportTests/DataExtractorDeathTest/Cursor
LLVM-Unit :: Support/./SupportTests/Error/AccessExpectedInFailureMode
LLVM-Unit :: Support/./SupportTests/Error/CantFailDeath
LLVM-Unit :: Support/./SupportTests/Error/ErrorAsOutParameterUnchecked
LLVM-Unit :: Support/./SupportTests/Error/FailureFromHandler
LLVM-Unit :: Support/./SupportTests/Error/FailureToHandle
LLVM-Unit :: Support/./SupportTests/Error/UncheckedError
LLVM-Unit :: 
Support/./SupportTests/Error/UncheckedExpectedInSuccessModeAccess
LLVM-Unit :: 
Support/./SupportTests/Error/UncheckedExpectedInSuccessModeAssignment
LLVM-Unit :: 
Support/./SupportTests/Error/UncheckedExpectedInSuccessModeDestruction
LLVM-Unit :: Support/./SupportTests/Error/UncheckedSuccess
LLVM-Unit :: Support/./SupportTests/Error/UnhandledExpectedInFailureMode
LLVM-Unit :: Support/./SupportTests/ErrorDeathTest/ExitOnError
LLVM-Unit :: Support/./SupportTests/ErrorOr/SimpleValue
LLVM-Unit :: Support/./SupportTests/FileSystemTest/FileMapping
LLVM-Unit :: Support/./SupportTests/JSONTest/Types
LLVM-Unit 

[PATCH] D152435: [analyzer][CStringChecker] Adjust the invalidation operation on the super region of the destination buffer during string copy

2023-06-17 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie added inline comments.



Comment at: clang/test/Analysis/issue-55019.cpp:13-14
+
+void *malloc(size_t);
+void free(void *);
+

> Ah, I see that it's for c function declarations. If that's the case, have you 
> considered adding the malloc and free declarations to that header?

What about doing this in another patch and updating all test cases that use 
malloc and free? Maybe other libc APIs as well?
The test case malloc-three-arg.c declares malloc and in a different signature 
and also includes this header. Simply doing so in this patch will lead to other 
conflicts.



Comment at: clang/test/Analysis/pr22954.c:581
   clang_analyzer_eval(m27.s3[i] == 1); // expected-warning{{UNKNOWN}}\
   expected-warning{{Potential leak of memory pointed to by 'm27.s4'}}
   return 0;

Do I need to update all other leak expectation directions in this file as well? 
Such as this one here.


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

https://reviews.llvm.org/D152435

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


[PATCH] D152435: [analyzer][CStringChecker] Adjust the invalidation operation on the super region of the destination buffer during string copy

2023-06-17 Thread Ella Ma via Phabricator via cfe-commits
OikawaKirie updated this revision to Diff 532372.
OikawaKirie edited the summary of this revision.
OikawaKirie added a comment.

Update the implementation of InvalidateBuffer in a multi-entrance-with-callback 
manner.
Update test cases as suggested.


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

https://reviews.llvm.org/D152435

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/issue-55019.cpp
  clang/test/Analysis/pr22954.c

Index: clang/test/Analysis/pr22954.c
===
--- clang/test/Analysis/pr22954.c
+++ clang/test/Analysis/pr22954.c
@@ -557,11 +557,12 @@
   char input[] = {'a', 'b', 'c', 'd'};
   memcpy(x263.s1, input, *(len + n));
   clang_analyzer_eval(x263.s1[0] == 0); // expected-warning{{UNKNOWN}}
+  // expected-warning@-1{{Potential leak of memory pointed to by 'x263.s2'}}
   clang_analyzer_eval(x263.s1[1] == 0); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(x263.s1[2] == 0); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(x263.s1[3] == 0); // expected-warning{{UNKNOWN}}
   clang_analyzer_eval(x263.s2 == 0); // expected-warning{{UNKNOWN}}
-  return 0; // expected-warning{{Potential leak of memory pointed to by 'x263.s2'}}
+  return 0;
 }
 
 
Index: clang/test/Analysis/issue-55019.cpp
===
--- /dev/null
+++ clang/test/Analysis/issue-55019.cpp
@@ -0,0 +1,89 @@
+// Refer issue 55019 for more details.
+// A supplemental test case of pr22954.c for other functions modeled in
+// the CStringChecker.
+
+// RUN: %clang_analyze_cc1 %s -verify \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=unix \
+// RUN:   -analyzer-checker=debug.ExprInspection
+
+#include "Inputs/system-header-simulator.h"
+#include "Inputs/system-header-simulator-cxx.h"
+
+void *malloc(size_t);
+void free(void *);
+
+struct mystruct {
+  void *ptr;
+  char arr[4];
+};
+
+void clang_analyzer_dump(const void *);
+
+// CStringChecker::memsetAux
+void fmemset() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  memset(x.arr, 0, sizeof(x.arr));
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+// CStringChecker::evalCopyCommon
+void fmemcpy() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  memcpy(x.arr, "hi", 2);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+// CStringChecker::evalStrcpyCommon
+void fstrcpy() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  strcpy(x.arr, "hi");
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+void fstrncpy() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  strncpy(x.arr, "hi", sizeof(x.arr));
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+// CStringChecker::evalStrsep
+void fstrsep() {
+  mystruct x;
+  x.ptr = malloc(1);
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  char *p = x.arr;
+  (void)strsep(, "x");
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+  free(x.ptr);// no-leak-warning
+}
+
+// CStringChecker::evalStdCopyCommon
+void fstdcopy() {
+  mystruct x;
+  x.ptr = new char;
+  clang_analyzer_dump(x.ptr); // expected-warning {{HeapSymRegion}}
+
+  const char *p = "x";
+  std::copy(p, p + 1, x.arr);
+
+  // FIXME: As we currently cannot know whether the copy overflows, the checker
+  // invalidates the entire `x` object. When the copy size through iterators
+  // can be correctly modeled, we can then update the verify direction from
+  // SymRegion to HeapSymRegion as this std::copy call never overflows and
+  // hence the pointer `x.ptr` shall not be invalidated.
+  clang_analyzer_dump(x.ptr);   // expected-warning {{SymRegion}}
+  delete static_cast(x.ptr); // no-leak-warning
+}
Index: clang/test/Analysis/Inputs/system-header-simulator.h
===
--- clang/test/Analysis/Inputs/system-header-simulator.h
+++ clang/test/Analysis/Inputs/system-header-simulator.h
@@ -63,7 +63,9 @@
 
 char *strcpy(char *restrict, const char *restrict);
 char *strncpy(char *dst, const char *src, size_t n);
+char *strsep(char **stringp, const char *delim);
 void *memcpy(void *dst, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
 
 typedef unsigned long __darwin_pthread_key_t;
 typedef __darwin_pthread_key_t pthread_key_t;
Index: 

[PATCH] D148216: Add support for annotations in UpdateTestChecks (NFC)

2023-06-17 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

Could you please rebase the patch to current main? I wasn't able to apply it.

The behavior you describe sounds reasonable to me.




Comment at: llvm/utils/UpdateTestChecks/common.py:1286
+  if value == default_value:
+continue
 if action.dest == 'filters':

We should also not print the `all` argument for `--check-globals` argument for 
`version < 3`, otherwise that will introduce a spurious change in all such 
tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148216

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


[clang] f2a352e - [Clang] Add the list of core papers approved in Varna to the status page

2023-06-17 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-06-17T09:52:36+03:00
New Revision: f2a352e0584093c65f07cdd7cc62c5cc66beacbd

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

LOG: [Clang] Add the list of core papers approved in Varna to the status page

Added: 


Modified: 
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/www/cxx_status.html b/clang/www/cxx_status.html
index d2ef73f821ceb..4eea21cb9da47 100755
--- a/clang/www/cxx_status.html
+++ b/clang/www/cxx_status.html
@@ -101,10 +101,55 @@ C++2c implementation status
 C++26 Proposal
 Available in Clang?
  
+ 
+ 
+  Remove undefined behavior from lexing
+  https://wg21.link/P2621R2;>P2621R2 (DR)
+  Clang 3.3
+ 
+ 
+  Making non-encodable string literals ill-formed
+  https://wg21.link/P1854R4;>P1854R4 (DR)
+  Clang 14
+ 
+ 
+  Unevaluated strings
+  https://wg21.link/P2361R6;>P2361R6
+  No
+ 
+ 
+  Add @, $, and ` to the basic character set
+  https://wg21.link/P2558R2;>P2558R2
+  Yes
+ 
+ 
+  constexpr cast from void*
+  https://wg21.link/P2738R1;>P2738R1
+  No
+ 
+ 
+  On the ignorability of standard attributes
+  https://wg21.link/P2552R3;>P2552R3 (DR)
+  No
+ 
+ 
+  Static storage for braced initializers
+  https://wg21.link/P2752R3;>P2752R3 (DR)
+  No
+ 
+ 
+  User-generated static_assert messages
+  https://wg21.link/P2741R3;>P2741R3
+  No
+ 
+ 
+  Placeholder variables with no name
+  https://wg21.link/P2169R4;>P2169R4
+  No
+ 
 
 
 
-
 C++23 implementation status
 
 



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