[PATCH] D156063: [Clang] Reject programs declaring namespace std to be inline

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Can you add a test for `foo::std` ? I suspects it warns, which is incorrect ? 
Can you add additional tests for `inline std::foo` ? (which should warn) 
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156063

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


[PATCH] D156053: [Clang] Fix crash in CIndex, when visiting a static_assert without message

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

There is a failed unit test, can you look into it?


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

https://reviews.llvm.org/D156053

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


[PATCH] D155064: [clang][SemaCXX] Diagnose tautological uses of consteval if and is_constant_evaluated

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/vartemplate-lambda.cpp:17
+// 
expected-note{{cannot be used in a constant expression}} \
+// expected-error 2{{a 
lambda expression may not appear inside of a constant expression}}
 };

hazohelet wrote:
> cor3ntin wrote:
> > This also looks like a regression.
> > 
> > The current error is much clearer, can you investigate?
> > ```
> > :3:22: error: constexpr variable 't' must be initialized by a 
> > constant expression
> > 3 |   static constexpr T t = [](int f = T(7)){return f;}();
> >   |  ^   ~
> > :6:12: note: in instantiation of static data member 'S::t' 
> > requested here
> > 6 | int a = S::t;
> >   |^
> > :3:26: note: non-literal type 'S::(lambda at :3:26)' cannot 
> > be used in a constant expression
> > 3 |   static constexpr T t = [](int f = T(7)){return f;}();
> >   |  ^
> > ```
> > 
> > Why do we emt 2 errors instead of a single note? Here the error is that the 
> > initializer is not a constant expression, everything else should be notes.
> "lambda cannot be in constant expression" error is emitted from Sema against 
> lambda expressions in constant-evaluated contexts in C++14 mode, and the note 
> is emitted from constexpr evaluator.
> The Sema-side error is emitted twice because it is emitted both before/after 
> instantiation.
> We can suppress one of them by ignoring it when sema is instantiating 
> variable template initializer.
> Or we can completely suppress this Sema error against initializers to avoid 
> duplicate errors from Sema and constexpr evaluator.
> I think "lambda cannot be in constant expression" Sema error is more 
> understandable than the constexpr evaluator note "non-literal type cannot be 
> in constant expression", so I think it is ok to keep one Sema error here.
So maybe the issue is that we are not making the declaration invalid in sema 
when we get this error? Can you look into it?
any opinion @aaron.ballman 


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

https://reviews.llvm.org/D155064

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


[PATCH] D154716: [SemaCXX] Fix bug where unexpanded lambda captures where assumed to be expanded

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154716

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


[PATCH] D144829: [BPF] Add a few new insns under cpu=v4

2023-07-24 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

In D144829#4519036 , @eddyz87 wrote:

> I tried adding a test similar to `assemble-disassemble.ll`:
>
>   // RUN: llvm-mc -triple bpfel --mcpu=v4 --assemble --filetype=obj %s \
>   // RUN:   | llvm-objdump -d --mattr=+alu32 - \
>   // RUN:   | FileCheck %s
>   
>   // CHECK: d7 01 00 00 10 00 00 00   r1 = bswap16 r1
>   // CHECK: d7 02 00 00 20 00 00 00   r2 = bswap32 r2
>   // CHECK: d7 03 00 00 40 00 00 00   r3 = bswap64 r3
>   r1 = bswap16 r1
>   r2 = bswap32 r2
>   r3 = bswap64 r3
>   
>   // CHECK: 91 41 00 00 00 00 00 00   r1 = *(s8 *)(r4 + 0x0)
>   // CHECK: 89 52 04 00 00 00 00 00   r2 = *(s16 *)(r5 + 0x4)
>   // CHECK: 81 63 08 00 00 00 00 00   r3 = *(s32 *)(r6 + 0x8)
>   r1 = *(s8 *)(r4 + 0)
>   r2 = *(s16 *)(r5 + 4)
>   r3 = *(s32 *)(r6 + 8)
>   
>   // CHECK: 91 41 00 00 00 00 00 00   w1 = *(s8 *)(r4 + 0x0)
>   // CHECK: 89 52 04 00 00 00 00 00   w2 = *(s16 *)(r5 + 0x4)
>   w1 = *(s8 *)(r4 + 0)
>   w2 = *(s16 *)(r5 + 4)
>   
>   // CHECK: bf 41 08 00 00 00 00 00   r1 = (s8)r4
>   // CHECK: bf 52 10 00 00 00 00 00   r2 = (s16)r5
>   // CHECK: bf 63 20 00 00 00 00 00   r3 = (s32)w6
>   r1 = (s8)r4
>   r2 = (s16)r5
>   r3 = (s32)w6
>   // Should this work as well: r3 = (s32)r6 ?
>   
>   // CHECK: bc 31 08 00 00 00 00 00   w1 = (s8)w3
>   // CHECK: bc 42 10 00 00 00 00 00   w2 = (s16)w4
>   w1 = (s8)w3
>   w2 = (s16)w4
>   
>   // CHECK: 3f 31 01 00 00 00 00 00   r1 s/= r3
>   // CHECK: 9f 42 01 00 00 00 00 00   r2 s%= r4
>   r1 s/= r3
>   r2 s%= r4
>   
>   // CHECK: 3c 31 01 00 00 00 00 00   w1 s/= w3
>   // CHECK: 9c 42 01 00 00 00 00 00   w2 s%= w4
>   w1 s/= w3
>   w2 s%= w4
>
> And it looks like some instructions are not printed correctly:
>
>   $ llvm-mc -triple bpfel --mcpu=v4 --assemble --filetype=obj 
> /home/eddy/work/llvm-project/llvm/test/CodeGen/BPF/assembler-disassembler-v4.s
>  | llvm-objdump -d --mattr=+alu32 -
>   
>   :file format elf64-bpf
>   
>   Disassembly of section .text:
>   
>    <.text>:
>  0:   d7 01 00 00 10 00 00 00 r1 = bswap16 r1
>  1:   d7 02 00 00 20 00 00 00 r2 = bswap32 r2
>  2:   d7 03 00 00 40 00 00 00 r3 = bswap64 r3
>  3:   91 41 00 00 00 00 00 00 w1 = *(s8 *)(r4 + 0x0)
>  4:   89 52 04 00 00 00 00 00 w2 = *(s16 *)(r5 + 0x4)
>  5:   81 63 08 00 00 00 00 00 
>  6:   91 41 00 00 00 00 00 00 w1 = *(s8 *)(r4 + 0x0)
>  7:   89 52 04 00 00 00 00 00 w2 = *(s16 *)(r5 + 0x4)
>  8:   bf 41 08 00 00 00 00 00 r1 = (s8)r4
>  9:   bf 52 10 00 00 00 00 00 r2 = (s16)r5
> 10:   bf 63 20 00 00 00 00 00 r3 = (s32)w6
> 11:   bc 31 08 00 00 00 00 00 w1 = (s8)w3
> 12:   bc 42 10 00 00 00 00 00 w2 = (s16)w4
> 13:   3f 31 01 00 00 00 00 00 r1 s/= r3
> 14:   9f 42 01 00 00 00 00 00 r2 s%= r4
> 15:   3c 31 01 00 00 00 00 00 w1 s/= w3
> 16:   9c 42 01 00 00 00 00 00 w2 s%= w4
>
> I'm not sure if this is an issue with disassembler or some additional 
> `--mattr` options are needed.

There is a problem in the td file for 32-bit signed load. Current definition is 
not quite right since it is supposed to sign-extension all the way to 64bit. I 
will fix it in the next revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144829

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


[PATCH] D144829: [BPF] Add a few new insns under cpu=v4

2023-07-24 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added inline comments.



Comment at: llvm/lib/Target/BPF/BPFInstrInfo.td:379
+  "$dst = (s8)$src",
+  [(set GPR:$dst, (sra (shl GPR:$src, (i64 56)), (i64 
56)))]>;
+  def MOVSX_rr_16 : ALU_RR I think it is possible to avoid matching expansion pattern `(sra (shl 
> GPR:$src, (i64 56))` here, and instead turn off the expansion when `movsx` is 
> available.
> 
> I tried the change below and all BPF codegen tests are passing. Do I miss 
> something?
> 
> ---
> 
> ```
> diff --git a/llvm/lib/Target/BPF/BPFISelLowering.cpp 
> b/llvm/lib/Target/BPF/BPFISelLowering.cpp
> index 9a7357d6ad04..5e84af009591 100644
> --- a/llvm/lib/Target/BPF/BPFISelLowering.cpp
> +++ b/llvm/lib/Target/BPF/BPFISelLowering.cpp
> @@ -132,9 +132,11 @@ BPFTargetLowering::BPFTargetLowering(const TargetMachine 
> &TM,
>setOperationAction(ISD::CTLZ_ZERO_UNDEF, MVT::i64, Custom);
>  
>setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
> -  setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand);
> -  setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
> -  setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i32, Expand);
> +  if (!STI.hasMovsx()) {
> +setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand);
> +setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
> +setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i32, Expand);
> +  }
>  
>// Extended load operations for i1 types must be promoted
>for (MVT VT : MVT::integer_valuetypes()) {
> diff --git a/llvm/lib/Target/BPF/BPFInstrInfo.td 
> b/llvm/lib/Target/BPF/BPFInstrInfo.td
> index a1d532e60db2..29bec72aa92d 100644
> --- a/llvm/lib/Target/BPF/BPFInstrInfo.td
> +++ b/llvm/lib/Target/BPF/BPFInstrInfo.td
> @@ -376,11 +376,11 @@ let Predicates = [BPFHasMovsx] in {
>def MOVSX_rr_8 : ALU_RR(outs GPR:$dst), (ins GPR:$src),
>"$dst = (s8)$src",
> -  [(set GPR:$dst, (sra (shl GPR:$src, (i64 56)), (i64 
> 56)))]>;
> +  [(set GPR:$dst, (sext_inreg GPR:$src, i8))]>;
>def MOVSX_rr_16 : ALU_RR(outs GPR:$dst), (ins GPR:$src),
>"$dst = (s16)$src",
> -  [(set GPR:$dst, (sra (shl GPR:$src, (i64 48)), (i64 
> 48)))]>;
> +  [(set GPR:$dst, (sext_inreg GPR:$src, i16))]>;
>def MOVSX_rr_32 : ALU_RR(outs GPR:$dst), (ins GPR32:$src),
>"$dst = (s32)$src",
> @@ -388,11 +388,11 @@ let Predicates = [BPFHasMovsx] in {
>def MOVSX_rr_32_8 : ALU_RR(outs GPR32:$dst), (ins GPR32:$src),
>"$dst = (s8)$src",
> -  [(set GPR32:$dst, (sra (shl GPR32:$src, (i32 24)), 
> (i32 24)))]>;
> +  [(set GPR32:$dst, (sext_inreg GPR32:$src, i8))]>;
>def MOVSX_rr_32_16 : ALU_RR(outs GPR32:$dst), (ins GPR32:$src),
>"$dst = (s16)$src",
> -  [(set GPR32:$dst, (sra (shl GPR32:$src, (i32 16)), 
> (i32 16)))]>;
> +  [(set GPR32:$dst, (sext_inreg GPR32:$src, i16))]>;
>  }
>  }
>  ```
This indeed can simplify the code. I will incorporate your change into the 
patch. Thanks!



Comment at: llvm/lib/Target/BPF/BPFMIPeephole.cpp:321
+
+  std::map ReverseCondOpMap;
 

eddyz87 wrote:
> Is this map unused?
No. This is a leftover. Will remove.



Comment at: llvm/lib/Target/BPF/BPFMIPeephole.cpp:412
+  int CurrNumInsns = 0;
+  std::map SoFarNumInsns;
+  std::map FollowThroughBB;

eddyz87 wrote:
> Nitpick: Fangrui suggested in my llvm-objdump revisions to use `DenseMap` in 
> most cases (as `std::map` allocates for each pair).
Will try to use DenseMap.



Comment at: llvm/test/CodeGen/BPF/movsx.ll:30
+}
+; CHECK: w0 = w1 # encoding: 
[0xbc,0x10,0x00,0x00,0x00,0x00,0x00,0x00]
+

eddyz87 wrote:
> This does not seem right, as it does not sign extend 8-bit argument to 16-bit 
> value.
This is probably due to ABI. For example,
```
$ cat t1.c
__attribute__((noinline)) short f1(char a) {
  return a * a;
}

int f2(int a) {
  return f1(a);
}


$ clang --target=bpf -O2 -mcpu=v4 -S t1.c

f1: # @f1
# %bb.0:# %entry
w0 = w1
w0 *= w0
exit
.Lfunc_end0:
.size   f1, .Lfunc_end0-f1
# -- End function
.globl  f2  # -- Begin function f2
.p2align3
.type   f2,@function
f2: # @f2
# %bb.0:# %entry
w1 = (s8)w1
call f1
w0 = (s16)w0
exit
```
You can see in function f2(), the sign-extension has been done properly. and 
that is

[clang] 2dea969 - [clang][CodeGen] Introduce `-frecord-command-line` for MachO

2023-07-24 Thread Antonio Frighetto via cfe-commits

Author: Antonio Frighetto
Date: 2023-07-24T09:24:59+02:00
New Revision: 2dea969d8337251e4c9335fd601bd4e0e5dee10f

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

LOG: [clang][CodeGen] Introduce `-frecord-command-line` for MachO

Allow clang driver command-line recording when
targeting MachO object files as well.

Reviewed-by: sgraenitz

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

Added: 
llvm/test/CodeGen/AArch64/commandline-metadata.ll

Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang_f_opts.c
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index ef20dd5aefe7dc..adb550d9c5da50 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7183,7 +7183,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   Args.hasFlag(options::OPT_frecord_command_line,
options::OPT_fno_record_command_line, false);
   if (FRecordSwitches && !Triple.isOSBinFormatELF() &&
-  !Triple.isOSBinFormatXCOFF())
+  !Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
 D.Diag(diag::err_drv_unsupported_opt_for_target)
 << 
Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
 << TripleStr;

diff  --git a/clang/test/Driver/clang_f_opts.c 
b/clang/test/Driver/clang_f_opts.c
index e8bc46e23b78a3..8a27140cd16e5f 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -541,7 +541,7 @@
 // RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line 
-frecord-command-line %s 2>&1 | FileCheck 
-check-prefix=CHECK-RECORD-GCC-SWITCHES %s
 // RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line 
-fno-record-command-line %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
 // Test with a couple examples of non-ELF object file formats
-// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 
2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 
2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
 // RUN: %clang -### -S -target x86_64-unknown-windows -frecord-command-line %s 
2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
 // CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
 // CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"

diff  --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h 
b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
index 07ebf5e65431d3..9f92b919824d2d 100644
--- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -156,6 +156,8 @@ class TargetLoweringObjectFileMachO : public 
TargetLoweringObjectFile {
 
   void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV,
  const TargetMachine &TM) const override;
+
+  MCSection *getSectionForCommandLines() const override;
 };
 
 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {

diff  --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp 
b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 9e0914f667f02b..3994552884c4f6 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1420,6 +1420,11 @@ MCSection 
*TargetLoweringObjectFileMachO::getSectionForConstant(
   return ReadOnlySection;  // .const
 }
 
+MCSection *TargetLoweringObjectFileMachO::getSectionForCommandLines() const {
+  return getContext().getMachOSection("__TEXT", "__command_line", 0,
+  SectionKind::getReadOnly());
+}
+
 const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
 MachineModuleInfo *MMI, MCStreamer &Streamer) const {

diff  --git a/llvm/test/CodeGen/AArch64/commandline-metadata.ll 
b/llvm/test/CodeGen/AArch64/commandline-metadata.ll
new file mode 100644
index 00..7c6e01763220d1
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/commandline-metadata.ll
@@ -0,0 +1,24 @@
+; RUN: llc -mtriple=arm64-linux-gnu < %s | FileCheck %s
+; RUN: llc -mtriple=arm64-apple-darwin < %s | FileCheck %s 
--check-prefix=CHECK-MACHO
+
+; Verify that llvm.commandline metadata is emitted to the corresponding 
command line section.
+
+; CHECK:  .text
+; CHECK:  .section .GCC.command.line,"MS",@progbits,1
+; CHECK-NEXT: .zero 1
+; CHECK-NEXT: .ascii

[PATCH] D155716: [clang][CodeGen] Introduce `-frecord-command-line` for MachO

2023-07-24 Thread Antonio Frighetto via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2dea969d8337: [clang][CodeGen] Introduce 
`-frecord-command-line` for MachO (authored by antoniofrighetto).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155716

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/clang_f_opts.c
  llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
  llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
  llvm/test/CodeGen/AArch64/commandline-metadata.ll


Index: llvm/test/CodeGen/AArch64/commandline-metadata.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/commandline-metadata.ll
@@ -0,0 +1,24 @@
+; RUN: llc -mtriple=arm64-linux-gnu < %s | FileCheck %s
+; RUN: llc -mtriple=arm64-apple-darwin < %s | FileCheck %s 
--check-prefix=CHECK-MACHO
+
+; Verify that llvm.commandline metadata is emitted to the corresponding 
command line section.
+
+; CHECK:  .text
+; CHECK:  .section .GCC.command.line,"MS",@progbits,1
+; CHECK-NEXT: .zero 1
+; CHECK-NEXT: .ascii "clang -command1"
+; CHECK-NEXT: .zero 1
+; CHECK-NEXT: .ascii "clang -command2"
+; CHECK-NEXT: .zero 1
+
+; CHECK-MACHO:.section __TEXT,__text,regular,pure_instructions
+; CHECK-MACHO-NEXT:   .section __TEXT,__command_line
+; CHECK-MACHO-NEXT:   .space   1
+; CHECK-MACHO-NEXT:   .ascii   "clang -command1"
+; CHECK-MACHO-NEXT:   .space   1
+; CHECK-MACHO-NEXT:   .ascii   "clang -command2"
+; CHECK-MACHO-NEXT:   .space   1
+
+!llvm.commandline = !{!0, !1}
+!0 = !{!"clang -command1"}
+!1 = !{!"clang -command2"}
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1420,6 +1420,11 @@
   return ReadOnlySection;  // .const
 }
 
+MCSection *TargetLoweringObjectFileMachO::getSectionForCommandLines() const {
+  return getContext().getMachOSection("__TEXT", "__command_line", 0,
+  SectionKind::getReadOnly());
+}
+
 const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Index: llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
===
--- llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -156,6 +156,8 @@
 
   void getNameWithPrefix(SmallVectorImpl &OutName, const GlobalValue *GV,
  const TargetMachine &TM) const override;
+
+  MCSection *getSectionForCommandLines() const override;
 };
 
 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -541,7 +541,7 @@
 // RUN: %clang -### -S -target x86_64-unknown-linux -fno-record-command-line 
-frecord-command-line %s 2>&1 | FileCheck 
-check-prefix=CHECK-RECORD-GCC-SWITCHES %s
 // RUN: %clang -### -S -target x86_64-unknown-linux -frecord-command-line 
-fno-record-command-line %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-RECORD-GCC-SWITCHES %s
 // Test with a couple examples of non-ELF object file formats
-// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 
2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
+// RUN: %clang -### -S -target x86_64-unknown-macosx -frecord-command-line %s 
2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES %s
 // RUN: %clang -### -S -target x86_64-unknown-windows -frecord-command-line %s 
2>&1 | FileCheck -check-prefix=CHECK-RECORD-GCC-SWITCHES-ERROR %s
 // CHECK-RECORD-GCC-SWITCHES: "-record-command-line"
 // CHECK-NO-RECORD-GCC-SWITCHES-NOT: "-record-command-line"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -7183,7 +7183,7 @@
   Args.hasFlag(options::OPT_frecord_command_line,
options::OPT_fno_record_command_line, false);
   if (FRecordSwitches && !Triple.isOSBinFormatELF() &&
-  !Triple.isOSBinFormatXCOFF())
+  !Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
 D.Diag(diag::err_drv_unsupported_opt_for_target)
 << 
Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
 << TripleStr;


Index: llvm/test/CodeGen/AArch64/commandline-metadata.ll
=

[PATCH] D153914: [clang-cl] Enable concatenation of predefined identifiers

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/include/clang/Basic/TokenKinds.h:87-93
+/// Return true if this token is a predefined macro
+/// unexpandable by MSVC preprocessor.
+inline bool isUnexpandableMsMacro(TokenKind K) {
+  return K == tok::kw___FUNCTION__ || K == tok::kw___FUNCSIG__ ||
+ K == tok::kw_L__FUNCTION__ || K == tok::kw_L__FUNCSIG__ ||
+ K == tok::kw___FUNCDNAME__;
+}

RIscRIpt wrote:
> tahonermann wrote:
> > cor3ntin wrote:
> > > tahonermann wrote:
> > > > RIscRIpt wrote:
> > > > > tahonermann wrote:
> > > > > > 
> > > > > Thanks, I like the name. But shouldn't we reflect that we are 
> > > > > referring to only Microsoft (unexpandable) macros? How about 
> > > > > `isFunctionLocalPredefinedMsMacro`?
> > > > I don't think the Microsoft association is meaningful. Sure, some of 
> > > > the predefined macros are only treated differently when compiling in 
> > > > Microsoft mode, but some of those macros aren't Microsoft specific. 
> > > > Also, there might be macros provided by other implementations that 
> > > > we'll want to emulate some day.
> > > I think it is, there is currently no way to link 
> > > `isFunctionLocalPredefinedMacro` to the MS feature. "MSPredefinedMacro" 
> > > is pretty self explanatory, same reason we most often - but not always - 
> > > use GNU in the name of function related to GNU extensions.
> > > There are enough similar-sounding features and extensions that we should 
> > > try to make it clear which feature we are talking about.
> > Perhaps we still haven't found the right name then. With the name that I've 
> > been advocating, this function should also return true for 
> > `tok::kw___PRETTY_FUNCTION__` even though that macro should not expand to 
> > something that can be concatenated with other string literals (whether 
> > compiling in Microsoft mode or not).
> > 
> > The Microsoft extension is the localized expansion to a string literal that 
> > can be concatenated with other string literals. We probably should isolate 
> > the conditions for that behavior to one place and if we do that, then I 
> > guess naming this function as specific to Microsoft mode is ok; we can 
> > always rename it later if it gets used for non-Microsoft extensions.
> > 
> > Here is my suggestion then:
> >   // Return true if the token corresponds to a function local predefined
> >   // macro that, in Microsoft modes, expands to a string literal (that can
> >   // then be concatenated with other string literals).
> >   inline bool isMsFunctionLocalStringLiteralMacro(TokenKind K, const 
> > LangOptions &langOpts) {
> > return langOpts.MicrosoftExt && (
> > K == tok::kw___FUNCTION__ || K == tok::kw_L__FUNCTION__ ||
> > K == tok::kw___FUNCSIG__ || K == tok::kw_L__FUNCSIG__ ||
> > K == tok::kw___FUNCDNAME__);
> >   }  
> > 
> > This will avoid the need for callers to check for `MicrosoftExt`; that is 
> > what I really want to avoid since it is easy to forget to do that check.
> 1. By requiring user to pass `LangOptions` I think we can remove MS 
> association (implying that there could be other non-msft cases in the future)
> 2. We would have to include a `LangOptions.h` in `TokenKinds.h`, are we ok 
> with this? Alternatively while this function is for msft cases only, we could 
> pass `bool MicrosoftExt`
> 
> Personally, I like version with `LangOptions` and removal of `MS`.
> By requiring user to pass LangOptions I think we can remove MS association

I don't think there is any motivation to future proof against hypotheticals, we 
can always refactor later 

> We would have to include a LangOptions.h in TokenKinds.h

This makes me uneasy, but i think we can move the function to 
`LiteralSupport.h` and include that in `ParseExpr.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153914

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


[clang] 8ac137a - [NFC] Add checks for self-assignment.

2023-07-24 Thread Sindhu Chittireddy via cfe-commits

Author: Sindhu Chittireddy
Date: 2023-07-24T00:38:08-07:00
New Revision: 8ac137acefc01caf636db5f95eb0977c97def1ba

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

LOG: [NFC] Add checks for self-assignment.

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

Added: 


Modified: 
clang/lib/AST/APValue.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/Interpreter/Value.cpp

Removed: 




diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 5b0a5e256e411a..7bbde6d065316e 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -390,11 +390,13 @@ APValue &APValue::operator=(const APValue &RHS) {
 }
 
 APValue &APValue::operator=(APValue &&RHS) {
-  if (Kind != None && Kind != Indeterminate)
-DestroyDataAndMakeUninit();
-  Kind = RHS.Kind;
-  Data = RHS.Data;
-  RHS.Kind = None;
+  if (this != RHS) {
+if (Kind != None && Kind != Indeterminate)
+  DestroyDataAndMakeUninit();
+Kind = RHS.Kind;
+Data = RHS.Data;
+RHS.Kind = None;
+  }
   return *this;
 }
 

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 58ee6dd64c4fc3..5b089f3330c42b 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -832,8 +832,10 @@ class ApplyDebugLocation {
 
   // Define copy assignment operator.
   ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
-CGF = Other.CGF;
-Other.CGF = nullptr;
+if (this != Other) {
+  CGF = Other.CGF;
+  Other.CGF = nullptr;
+}
 return *this;
   }
 

diff  --git a/clang/lib/Interpreter/Value.cpp b/clang/lib/Interpreter/Value.cpp
index 6d0eaf1b82e108..68adfc268261af 100644
--- a/clang/lib/Interpreter/Value.cpp
+++ b/clang/lib/Interpreter/Value.cpp
@@ -201,16 +201,17 @@ Value &Value::operator=(const Value &RHS) {
 }
 
 Value &Value::operator=(Value &&RHS) noexcept {
-  if (IsManuallyAlloc)
-ValueStorage::getFromPayload(getPtr())->Release();
+  if (this != RHS) {
+if (IsManuallyAlloc)
+  ValueStorage::getFromPayload(getPtr())->Release();
 
-  Interp = std::exchange(RHS.Interp, nullptr);
-  OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
-  ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
-  IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
-
-  Data = RHS.Data;
+Interp = std::exchange(RHS.Interp, nullptr);
+OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
+ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
+IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
 
+Data = RHS.Data;
+  }
   return *this;
 }
 



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


[PATCH] D155776: [NFC] Add checks for self-assignment.

2023-07-24 Thread Sindhu Chittireddy via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8ac137acefc0: [NFC] Add checks for self-assignment. 
(authored by schittir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155776

Files:
  clang/lib/AST/APValue.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Interpreter/Value.cpp


Index: clang/lib/Interpreter/Value.cpp
===
--- clang/lib/Interpreter/Value.cpp
+++ clang/lib/Interpreter/Value.cpp
@@ -201,16 +201,17 @@
 }
 
 Value &Value::operator=(Value &&RHS) noexcept {
-  if (IsManuallyAlloc)
-ValueStorage::getFromPayload(getPtr())->Release();
+  if (this != RHS) {
+if (IsManuallyAlloc)
+  ValueStorage::getFromPayload(getPtr())->Release();
 
-  Interp = std::exchange(RHS.Interp, nullptr);
-  OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
-  ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
-  IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
-
-  Data = RHS.Data;
+Interp = std::exchange(RHS.Interp, nullptr);
+OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
+ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
+IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
 
+Data = RHS.Data;
+  }
   return *this;
 }
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -832,8 +832,10 @@
 
   // Define copy assignment operator.
   ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
-CGF = Other.CGF;
-Other.CGF = nullptr;
+if (this != Other) {
+  CGF = Other.CGF;
+  Other.CGF = nullptr;
+}
 return *this;
   }
 
Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -390,11 +390,13 @@
 }
 
 APValue &APValue::operator=(APValue &&RHS) {
-  if (Kind != None && Kind != Indeterminate)
-DestroyDataAndMakeUninit();
-  Kind = RHS.Kind;
-  Data = RHS.Data;
-  RHS.Kind = None;
+  if (this != RHS) {
+if (Kind != None && Kind != Indeterminate)
+  DestroyDataAndMakeUninit();
+Kind = RHS.Kind;
+Data = RHS.Data;
+RHS.Kind = None;
+  }
   return *this;
 }
 


Index: clang/lib/Interpreter/Value.cpp
===
--- clang/lib/Interpreter/Value.cpp
+++ clang/lib/Interpreter/Value.cpp
@@ -201,16 +201,17 @@
 }
 
 Value &Value::operator=(Value &&RHS) noexcept {
-  if (IsManuallyAlloc)
-ValueStorage::getFromPayload(getPtr())->Release();
+  if (this != RHS) {
+if (IsManuallyAlloc)
+  ValueStorage::getFromPayload(getPtr())->Release();
 
-  Interp = std::exchange(RHS.Interp, nullptr);
-  OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
-  ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
-  IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
-
-  Data = RHS.Data;
+Interp = std::exchange(RHS.Interp, nullptr);
+OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
+ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
+IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
 
+Data = RHS.Data;
+  }
   return *this;
 }
 
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -832,8 +832,10 @@
 
   // Define copy assignment operator.
   ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
-CGF = Other.CGF;
-Other.CGF = nullptr;
+if (this != Other) {
+  CGF = Other.CGF;
+  Other.CGF = nullptr;
+}
 return *this;
   }
 
Index: clang/lib/AST/APValue.cpp
===
--- clang/lib/AST/APValue.cpp
+++ clang/lib/AST/APValue.cpp
@@ -390,11 +390,13 @@
 }
 
 APValue &APValue::operator=(APValue &&RHS) {
-  if (Kind != None && Kind != Indeterminate)
-DestroyDataAndMakeUninit();
-  Kind = RHS.Kind;
-  Data = RHS.Data;
-  RHS.Kind = None;
+  if (this != RHS) {
+if (Kind != None && Kind != Indeterminate)
+  DestroyDataAndMakeUninit();
+Kind = RHS.Kind;
+Data = RHS.Data;
+RHS.Kind = None;
+  }
   return *this;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155776: [NFC] Add checks for self-assignment.

2023-07-24 Thread Sindhu Chittireddy via Phabricator via cfe-commits
schittir added a comment.

@tahonermann Thank you for considering this thoroughly. This patch is now 
landed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155776

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


[PATCH] D156076: [PowerPC][Clang] Remove constraint for initial-exec TLS mode on AIX

2023-07-24 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.

So we don't have code generation for this, but we are enabling it in the front 
end? What happens if we try to produce code for the IR this produces? It would 
make more sense to me to implement what is needed in the back end prior to 
allowing the front end to produce the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156076

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


[PATCH] D156044: [clangd] Exclude builtin headers from system include extraction

2023-07-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks a lot!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156044

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


[PATCH] D155776: [NFC] Add checks for self-assignment.

2023-07-24 Thread Jan-Patrick Lehr via Phabricator via cfe-commits
jplehr added a comment.

Hi,
it seems that this broke the AMDGPU OpenMP buildbot 
https://lab.llvm.org/buildbot/#/builders/193/builds/35271
Happy to help if you need more info etc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155776

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


[PATCH] D155694: [NFC][analyzer] Enable implicit destructor for cfg-lifetime tests

2023-07-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 543407.
tomasz-kaminski-sonarsource added a comment.

Updated text of FIXME


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155694

Files:
  clang/test/Analysis/lifetime-cfg-output.cpp

Index: clang/test/Analysis/lifetime-cfg-output.cpp
===
--- clang/test/Analysis/lifetime-cfg-output.cpp
+++ clang/test/Analysis/lifetime-cfg-output.cpp
@@ -1,6 +1,13 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-lifetime=true,cfg-temporary-dtors=false,cfg-rich-constructors=false -analyzer-config cfg-implicit-dtors=false %s > %t 2>&1
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-lifetime=true %s > %t 2>&1
 // RUN: FileCheck --input-file=%t %s
 
+// FIXME Most of the cases in this file test only with the objects of type `A`,
+// that has a non-trivial destructor. The types with a trivial destructor
+// ends their lifetime when the underlying memory is released, i.e. they
+// are destroyed last, after all objects with non-trivial destructors.
+// Consequently, they are handled differently in code, and we should make 
+// sure that test cover also trivially destructible types.
+
 extern bool UV;
 class A {
 public:
@@ -58,19 +65,21 @@
 // CHECK:   [B2 (ENTRY)]
 // CHECK-NEXT:Succs (1): B1
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A)
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A)
 // CHECK-NEXT:2: A a;
 // CHECK-NEXT:3: a
 // CHECK-NEXT:4: [B1.3] (ImplicitCastExpr, NoOp, const A)
 // CHECK-NEXT:5: const A &b = a;
-// CHECK-NEXT:6: A() (CXXConstructExpr, A)
+// CHECK-NEXT:6: A() (CXXConstructExpr, [B1.9], A)
 // CHECK-NEXT:7: [B1.6] (BindTemporary)
 // CHECK-NEXT:8: [B1.7] (ImplicitCastExpr, NoOp, const A)
 // CHECK-NEXT:9: [B1.8]
 // CHECK-NEXT:   10: const A &c = A();
-// CHECK-NEXT:   11: [B1.10] (Lifetime ends)
-// CHECK-NEXT:   12: [B1.2] (Lifetime ends)
-// CHECK-NEXT:   13: [B1.5] (Lifetime ends)
+// CHECK-NEXT:   11: [B1.10].~A() (Implicit destructor)
+// CHECK-NEXT:   12: [B1.10] (Lifetime ends)
+// CHECK-NEXT:   13: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   14: [B1.2] (Lifetime ends)
+// CHECK-NEXT:   15: [B1.5] (Lifetime ends)
 // CHECK-NEXT:Preds (1): B2
 // CHECK-NEXT:Succs (1): B0
 // CHECK:   [B0 (EXIT)]
@@ -84,14 +93,15 @@
 // CHECK:  [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A[2])
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A[2])
 // CHECK-NEXT:2: A a[2];
-// CHECK-NEXT:3:  (CXXConstructExpr, A[0])
+// CHECK-NEXT:3:  (CXXConstructExpr, [B1.4], A[0])
 // CHECK-NEXT:4: A b[0];
+// CHECK-NEXT:5: [B1.2].~A[2]() (Implicit destructor)
 // lifetime of a ends when its destructors are run
-// CHECK-NEXT:5: [B1.2] (Lifetime ends)
+// CHECK-NEXT:6: [B1.2] (Lifetime ends)
 // lifetime of b ends when its storage duration ends
-// CHECK-NEXT:6: [B1.4] (Lifetime ends)
+// CHECK-NEXT:7: [B1.4] (Lifetime ends)
 // CHECK-NEXT:Preds (1): B2
 // CHECK-NEXT:Succs (1): B0
 // CHECK:  [B0 (EXIT)]
@@ -104,18 +114,22 @@
 // CHECK:  [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A)
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A)
 // CHECK-NEXT:2: A a;
-// CHECK-NEXT:3:  (CXXConstructExpr, A)
+// CHECK-NEXT:3:  (CXXConstructExpr, [B1.4], A)
 // CHECK-NEXT:4: A c;
-// CHECK-NEXT:5:  (CXXConstructExpr, A)
+// CHECK-NEXT:5:  (CXXConstructExpr, [B1.6], A)
 // CHECK-NEXT:6: A d;
-// CHECK-NEXT:7: [B1.6] (Lifetime ends)
-// CHECK-NEXT:8: [B1.4] (Lifetime ends)
-// CHECK-NEXT:9:  (CXXConstructExpr, A)
-// CHECK-NEXT:   10: A b;
-// CHECK-NEXT:   11: [B1.10] (Lifetime ends)
-// CHECK-NEXT:   12: [B1.2] (Lifetime ends)
+// CHECK-NEXT:7: [B1.6].~A() (Implicit destructor)
+// CHECK-NEXT:8: [B1.6] (Lifetime ends)
+// CHECK-NEXT:9: [B1.4].~A() (Implicit destructor)
+// CHECK-NEXT:   10: [B1.4] (Lifetime ends)
+// CHECK-NEXT:   11:  (CXXConstructExpr, [B1.12], A)
+// CHECK-NEXT:   12: A b;
+// CHECK-NEXT:   13: [B1.12].~A() (Implicit destructor)
+// CHECK-NEXT:   14: [B1.12] (Lifetime ends)
+// CHECK-NEXT:   15: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   16: [B1.2] (Lifetime ends)
 // CHECK-NEXT:Preds (1): B2
 // CHECK-NEXT:Succs (1): B0
 // CHECK:  [B0 (EXIT)]
@@ -132,30 +146,34 @@
 // CHECK:  [B4 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B3
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A)
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A)
 // CHECK-NEXT:2: A c;
-// CHECK-NEXT:3: [B1.2] (Lifetime ends)
-// CHECK-NEXT:4: [B3.4] (L

[PATCH] D155776: [NFC] Add checks for self-assignment.

2023-07-24 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok added a comment.

This doesn't compile, could you fix this or revert 
8ac137acefc01caf636db5f95eb0977c97def1ba 
 ?




Comment at: clang/lib/AST/APValue.cpp:393
 APValue &APValue::operator=(APValue &&RHS) {
-  if (Kind != None && Kind != Indeterminate)
-DestroyDataAndMakeUninit();
-  Kind = RHS.Kind;
-  Data = RHS.Data;
-  RHS.Kind = None;
+  if (this != RHS) {
+if (Kind != None && Kind != Indeterminate)

Ditto for the other changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155776

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


[PATCH] D155694: [NFC][analyzer] Enable implicit destructor for cfg-lifetime tests

2023-07-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource marked an inline comment as done.
tomasz-kaminski-sonarsource added inline comments.



Comment at: clang/test/Analysis/lifetime-cfg-output.cpp:6
+// that has non-trivial destructor. As the behavior for such types is different
+// from ones with trivial destructor - later ends they lifetime last, we
+// should extended the test cases. 

xazax.hun wrote:
> I have a bit hard time understanding this part.
Rewrote it, to help with clarity.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155694

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


[PATCH] D156089: [Driver][XRay][test] Convert more tests to check 'target=...' after 016785d9316d8c5abc5fdf3cdb86479095bbb677

2023-07-24 Thread Lu Weining via Phabricator via cfe-commits
SixWeining created this revision.
SixWeining added reviewers: probinson, MaskRay.
Herald added a subscriber: dberris.
Herald added a project: All.
SixWeining requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix https://github.com/llvm/llvm-project/issues/64028


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156089

Files:
  clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
  clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
  clang/test/Driver/XRay/xray-mode-flags.cpp
  clang/test/Driver/XRay/xray-shared-noxray.cpp


Index: clang/test/Driver/XRay/xray-shared-noxray.cpp
===
--- clang/test/Driver/XRay/xray-shared-noxray.cpp
+++ clang/test/Driver/XRay/xray-shared-noxray.cpp
@@ -8,7 +8,8 @@
 // SHARED-NOT: {{clang_rt\.xray-}}
 // STATIC: {{clang_rt\.xray-}}
 //
-// REQUIRES: linux, enable_shared
+// REQUIRES: target={{.*-linux.*}}
+// REQUIRES: enable_shared
 int foo() { return 42; }
 
 #ifdef MAIN
Index: clang/test/Driver/XRay/xray-mode-flags.cpp
===
--- clang/test/Driver/XRay/xray-mode-flags.cpp
+++ clang/test/Driver/XRay/xray-mode-flags.cpp
@@ -45,5 +45,5 @@
 // FDR: libclang_rt.xray-fdr
 // NONE-NOT: libclang_rt.xray-basic
 // NONE-NOT: libclang_rt.xray-fdr
-// REQUIRES: linux || freebsd
-// REQUIRES: amd64 || x86_64 || x86_64h || arm || aarch64 || arm64
+// REQUIRES: target={{.*-(linux|freebsd).*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
Index: clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
===
--- clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
+++ clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
@@ -6,5 +6,5 @@
 // RUN:   -c -o - %s 2>&1 | FileCheck %s
 // CHECK:  -fxray-instrumentation-bundle=function
 //
-// REQUIRES: linux || freebsd
-// REQUIRES: amd64 || x86_64 || x86_64h || arm || aarch64 || arm64
+// REQUIRES: target={{.*-(linux|freebsd).*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
Index: clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
===
--- clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
+++ clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
@@ -6,4 +6,4 @@
 // RUN:   -x c++ -emit-llvm -c -o - %s 2>&1 | FileCheck %s
 // CHECK:  -fxray-ignore-loops
 //
-// REQUIRES: x86_64 || x86_64h
+// REQUIRES: target={{(x86_64|x86_64h)-.*}}


Index: clang/test/Driver/XRay/xray-shared-noxray.cpp
===
--- clang/test/Driver/XRay/xray-shared-noxray.cpp
+++ clang/test/Driver/XRay/xray-shared-noxray.cpp
@@ -8,7 +8,8 @@
 // SHARED-NOT: {{clang_rt\.xray-}}
 // STATIC: {{clang_rt\.xray-}}
 //
-// REQUIRES: linux, enable_shared
+// REQUIRES: target={{.*-linux.*}}
+// REQUIRES: enable_shared
 int foo() { return 42; }
 
 #ifdef MAIN
Index: clang/test/Driver/XRay/xray-mode-flags.cpp
===
--- clang/test/Driver/XRay/xray-mode-flags.cpp
+++ clang/test/Driver/XRay/xray-mode-flags.cpp
@@ -45,5 +45,5 @@
 // FDR: libclang_rt.xray-fdr
 // NONE-NOT: libclang_rt.xray-basic
 // NONE-NOT: libclang_rt.xray-fdr
-// REQUIRES: linux || freebsd
-// REQUIRES: amd64 || x86_64 || x86_64h || arm || aarch64 || arm64
+// REQUIRES: target={{.*-(linux|freebsd).*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
Index: clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
===
--- clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
+++ clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
@@ -6,5 +6,5 @@
 // RUN:   -c -o - %s 2>&1 | FileCheck %s
 // CHECK:  -fxray-instrumentation-bundle=function
 //
-// REQUIRES: linux || freebsd
-// REQUIRES: amd64 || x86_64 || x86_64h || arm || aarch64 || arm64
+// REQUIRES: target={{.*-(linux|freebsd).*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
Index: clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
===
--- clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
+++ clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
@@ -6,4 +6,4 @@
 // RUN:   -x c++ -emit-llvm -c -o - %s 2>&1 | FileCheck %s
 // CHECK:  -fxray-ignore-loops
 //
-// REQUIRES: x86_64 || x86_64h
+// REQUIRES: target={{(x86_64|x86_64h)-.*}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fa39c0a - Revert "[NFC] Add checks for self-assignment."

2023-07-24 Thread Michael Platings via cfe-commits

Author: Michael Platings
Date: 2023-07-24T09:36:11+01:00
New Revision: fa39c0a58e87d9fb0751d4e65a77259a3ec53448

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

LOG: Revert "[NFC] Add checks for self-assignment."

This reverts commit 8ac137acefc01caf636db5f95eb0977c97def1ba.

The code does not compile.

Added: 


Modified: 
clang/lib/AST/APValue.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/Interpreter/Value.cpp

Removed: 




diff  --git a/clang/lib/AST/APValue.cpp b/clang/lib/AST/APValue.cpp
index 7bbde6d065316e..5b0a5e256e411a 100644
--- a/clang/lib/AST/APValue.cpp
+++ b/clang/lib/AST/APValue.cpp
@@ -390,13 +390,11 @@ APValue &APValue::operator=(const APValue &RHS) {
 }
 
 APValue &APValue::operator=(APValue &&RHS) {
-  if (this != RHS) {
-if (Kind != None && Kind != Indeterminate)
-  DestroyDataAndMakeUninit();
-Kind = RHS.Kind;
-Data = RHS.Data;
-RHS.Kind = None;
-  }
+  if (Kind != None && Kind != Indeterminate)
+DestroyDataAndMakeUninit();
+  Kind = RHS.Kind;
+  Data = RHS.Data;
+  RHS.Kind = None;
   return *this;
 }
 

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 5b089f3330c42b..58ee6dd64c4fc3 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -832,10 +832,8 @@ class ApplyDebugLocation {
 
   // Define copy assignment operator.
   ApplyDebugLocation &operator=(ApplyDebugLocation &&Other) {
-if (this != Other) {
-  CGF = Other.CGF;
-  Other.CGF = nullptr;
-}
+CGF = Other.CGF;
+Other.CGF = nullptr;
 return *this;
   }
 

diff  --git a/clang/lib/Interpreter/Value.cpp b/clang/lib/Interpreter/Value.cpp
index 68adfc268261af..6d0eaf1b82e108 100644
--- a/clang/lib/Interpreter/Value.cpp
+++ b/clang/lib/Interpreter/Value.cpp
@@ -201,17 +201,16 @@ Value &Value::operator=(const Value &RHS) {
 }
 
 Value &Value::operator=(Value &&RHS) noexcept {
-  if (this != RHS) {
-if (IsManuallyAlloc)
-  ValueStorage::getFromPayload(getPtr())->Release();
+  if (IsManuallyAlloc)
+ValueStorage::getFromPayload(getPtr())->Release();
 
-Interp = std::exchange(RHS.Interp, nullptr);
-OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
-ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
-IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
+  Interp = std::exchange(RHS.Interp, nullptr);
+  OpaqueType = std::exchange(RHS.OpaqueType, nullptr);
+  ValueKind = std::exchange(RHS.ValueKind, K_Unspecified);
+  IsManuallyAlloc = std::exchange(RHS.IsManuallyAlloc, false);
+
+  Data = RHS.Data;
 
-Data = RHS.Data;
-  }
   return *this;
 }
 



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


[PATCH] D155776: [NFC] Add checks for self-assignment.

2023-07-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added a comment.

I reverted.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155776

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


[PATCH] D155846: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon abandoned this revision.
Fznamznon added a comment.

Oh shoot, I trusted the tool too much to not double check that the copy ctor is 
already deleted. Thank you for the catch and for the bug report.
I'll abandon this change then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155846

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


[PATCH] D153954: [WIP][clang][analyzer] Relax alpha.cplusplus.EnumCastOutOfRange checker

2023-07-24 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 543413.
gamesh411 edited the summary of this revision.
gamesh411 added a comment.

The checker now retains the original detection logic, but only whitelists empty
enums.

As a future step the checker is moved into the optin package.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153954

Files:
  clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
  clang/test/Analysis/enum-cast-out-of-range.cpp


Index: clang/test/Analysis/enum-cast-out-of-range.cpp
===
--- clang/test/Analysis/enum-cast-out-of-range.cpp
+++ clang/test/Analysis/enum-cast-out-of-range.cpp
@@ -198,3 +198,20 @@
   s.E = static_cast(4); // OK.
   s.E = static_cast(5); // expected-warning {{The 
value provided to the cast expression is not in the valid range of values for 
the enum}}
 }
+
+
+enum class empty_unfixed {};
+
+enum class empty_fixed: char {};
+
+enum class empty_fixed_unsigned: unsigned char {};
+
+void ignore_unused(...);
+
+void empty_enums_init_with_zero_should_not_warn() {
+  empty_unfixed eu = static_cast(0); //should always be OK to 
zero initialize any enum
+  empty_fixed ef = static_cast(0);
+  empty_fixed_unsigned efu = static_cast(0);
+
+  ignore_unused(eu, ef, efu);
+}
Index: clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
@@ -129,6 +129,14 @@
   const EnumDecl *ED = T->castAs()->getDecl();
 
   EnumValueVector DeclValues = getDeclValuesForEnum(ED);
+
+  // If the declarator list is empty, bail out.
+  // Every initialization an enum with a fixed underlying type but without any
+  // enumerators would produce a warning if we were to continue at this point.
+  // The most notable example is std::byte in the C++17 standard library.
+  if (DeclValues.size() == 0)
+return;
+
   // Check if any of the enum values possibly match.
   bool PossibleValueMatch = llvm::any_of(
   DeclValues, ConstraintBasedEQEvaluator(C, *ValueToCast));


Index: clang/test/Analysis/enum-cast-out-of-range.cpp
===
--- clang/test/Analysis/enum-cast-out-of-range.cpp
+++ clang/test/Analysis/enum-cast-out-of-range.cpp
@@ -198,3 +198,20 @@
   s.E = static_cast(4); // OK.
   s.E = static_cast(5); // expected-warning {{The value provided to the cast expression is not in the valid range of values for the enum}}
 }
+
+
+enum class empty_unfixed {};
+
+enum class empty_fixed: char {};
+
+enum class empty_fixed_unsigned: unsigned char {};
+
+void ignore_unused(...);
+
+void empty_enums_init_with_zero_should_not_warn() {
+  empty_unfixed eu = static_cast(0); //should always be OK to zero initialize any enum
+  empty_fixed ef = static_cast(0);
+  empty_fixed_unsigned efu = static_cast(0);
+
+  ignore_unused(eu, ef, efu);
+}
Index: clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp
@@ -129,6 +129,14 @@
   const EnumDecl *ED = T->castAs()->getDecl();
 
   EnumValueVector DeclValues = getDeclValuesForEnum(ED);
+
+  // If the declarator list is empty, bail out.
+  // Every initialization an enum with a fixed underlying type but without any
+  // enumerators would produce a warning if we were to continue at this point.
+  // The most notable example is std::byte in the C++17 standard library.
+  if (DeclValues.size() == 0)
+return;
+
   // Check if any of the enum values possibly match.
   bool PossibleValueMatch = llvm::any_of(
   DeclValues, ConstraintBasedEQEvaluator(C, *ValueToCast));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156042: [clang][Interp] Implement __builtin_strlen

2023-07-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 543414.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D156042

Files:
  clang/lib/AST/Interp/InterpBuiltin.cpp
  clang/test/AST/Interp/builtin-functions.cpp

Index: clang/test/AST/Interp/builtin-functions.cpp
===
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -1,7 +1,9 @@
-// RUN: %clang_cc1 -fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -verify=ref %s -Wno-constant-evaluated
-// RUN: %clang_cc1 -std=c++20 -fexperimental-new-constant-interpreter %s -verify
-// RUN: %clang_cc1 -std=c++20 -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify
+// RUN: %clang_cc1 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter %s -verify
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -fexperimental-new-constant-interpreter -triple i686 %s -verify
+// RUN: %clang_cc1 -std=c++20 -Wno-string-plus-int -verify=ref %s -Wno-constant-evaluated
 
 
 namespace strcmp {
@@ -38,6 +40,70 @@
 // ref-note {{dereferenced one-past-the-end}}
 }
 
+/// Copied from constant-expression-cxx11.cpp
+namespace strlen {
+constexpr const char *a = "foo\0quux";
+  constexpr char b[] = "foo\0quux";
+  constexpr int f() { return 'u'; }
+  constexpr char c[] = { 'f', 'o', 'o', 0, 'q', f(), 'u', 'x', 0 };
+
+  static_assert(__builtin_strlen("foo") == 3, "");
+  static_assert(__builtin_strlen("foo\0quux") == 3, "");
+  static_assert(__builtin_strlen("foo\0quux" + 4) == 4, "");
+
+  constexpr bool check(const char *p) {
+return __builtin_strlen(p) == 3 &&
+   __builtin_strlen(p + 1) == 2 &&
+   __builtin_strlen(p + 2) == 1 &&
+   __builtin_strlen(p + 3) == 0 &&
+   __builtin_strlen(p + 4) == 4 &&
+   __builtin_strlen(p + 5) == 3 &&
+   __builtin_strlen(p + 6) == 2 &&
+   __builtin_strlen(p + 7) == 1 &&
+   __builtin_strlen(p + 8) == 0;
+  }
+
+  static_assert(check(a), "");
+  static_assert(check(b), "");
+  static_assert(check(c), "");
+
+  constexpr int over1 = __builtin_strlen(a + 9); // expected-error {{constant expression}} \
+ // expected-note {{one-past-the-end}} \
+ // expected-note {{in call to}} \
+ // ref-error {{constant expression}} \
+ // ref-note {{one-past-the-end}}
+  constexpr int over2 = __builtin_strlen(b + 9); // expected-error {{constant expression}} \
+ // expected-note {{one-past-the-end}} \
+ // expected-note {{in call to}} \
+ // ref-error {{constant expression}} \
+ // ref-note {{one-past-the-end}}
+  constexpr int over3 = __builtin_strlen(c + 9); // expected-error {{constant expression}} \
+ // expected-note {{one-past-the-end}} \
+ // expected-note {{in call to}} \
+ // ref-error {{constant expression}} \
+ // ref-note {{one-past-the-end}}
+
+  constexpr int under1 = __builtin_strlen(a - 1); // expected-error {{constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+  constexpr int under2 = __builtin_strlen(b - 1); // expected-error {{constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+  constexpr int under3 = __builtin_strlen(c - 1); // expected-error {{constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+
+  constexpr char d[]

[PATCH] D156063: [Clang] Reject programs declaring namespace std to be inline

2023-07-24 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok requested changes to this revision.
MitalAshok added a comment.
This revision now requires changes to proceed.

This does currently break `namespace foo { inline namespace std {} }`, 
`namespace foo::inline std {}`, etc.




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11369
+// This has to be diagnosed before entering 
DiagnoseNamespaceInlineMismatch.
+if (IsInline && II->isStr("std"))
+  Diag(InlineLoc, diag::err_inline_namespace_std)

You need to check if this is a std namespace declaration at file scope, 
`namespace foo::inline std {}` in a namespace scope should be fine.

The check for this is a few lines below: 
`CurContext->getRedeclContext()->isTranslationUnit()`.



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11393-11394
   if (IsInline != PrevNS->isInline())
 DiagnoseNamespaceInlineMismatch(*this, NamespaceLoc, Loc, II,
 &IsInline, PrevNS);
 } else if (PrevDecl) {

This ends up giving two errors on the same line if this wasn't the first 
declaration (`error: namespace 'std' cannot be declared inline` followed by 
`error: non-inline namespace cannot be reopened as inline; note: previous 
definition is here`). The wording for the second error is also a little 
confusing (it cannot be opened at all as inline, let alone reopened), so 
consider refactoring so that both diagnostics can't be issued at once


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156063

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


[PATCH] D155849: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 543417.
Fznamznon added a comment.

Rebase, fix format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155849

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,11 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
+
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction &CGF, const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,11 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
+
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction &CGF, const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156065: [clang-format] Insert namespace comments with leading spaces

2023-07-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 543415.
owenpan added a comment.

Fixed unit tests in NamespaceEndCommentsFixerTest.cpp.


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

https://reviews.llvm.org/D156065

Files:
  clang/lib/Format/NamespaceEndCommentsFixer.cpp
  clang/unittests/Format/FormatTestComments.cpp
  clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp

Index: clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ clang/unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -46,7 +46,7 @@
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace",
+"} // namespace",
 fixNamespaceEndComments("namespace {\n"
 "int i;\n"
 "int j;\n"
@@ -55,7 +55,7 @@
   EXPECT_EQ("namespace {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace\n",
+"} // namespace\n",
 fixNamespaceEndComments("namespace {\n"
 "int i;\n"
 "int j;\n"
@@ -63,7 +63,7 @@
   EXPECT_EQ("namespace A {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace A",
+"} // namespace A",
 fixNamespaceEndComments("namespace A {\n"
 "int i;\n"
 "int j;\n"
@@ -72,7 +72,7 @@
 "namespace M(x) {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace M(x)",
+"} // namespace M(x)",
 fixNamespaceEndComments("#define M(x) x##x\n"
 "namespace M(x) {\n"
 "int i;\n"
@@ -82,7 +82,7 @@
 "namespace A::M(x) {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace A::M(x)",
+"} // namespace A::M(x)",
 fixNamespaceEndComments("#define M(x) x##x\n"
 "namespace A::M(x) {\n"
 "int i;\n"
@@ -92,7 +92,7 @@
 "namespace M(x)::A {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace M(x)::A",
+"} // namespace M(x)::A",
 fixNamespaceEndComments("#define M(x) x##x\n"
 "namespace M(x)::A {\n"
 "int i;\n"
@@ -102,7 +102,7 @@
 "namespace A::inline M(x)::B {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace A::inline M(x)::B",
+"} // namespace A::inline M(x)::B",
 fixNamespaceEndComments("#define M(x) x##x\n"
 "namespace A::inline M(x)::B {\n"
 "int i;\n"
@@ -112,7 +112,7 @@
 "namespace [[deprecated(\"foo\")]] A::inline M(x)::A {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace A::inline M(x)::A",
+"} // namespace A::inline M(x)::A",
 fixNamespaceEndComments(
 "#define M(x) x##x\n"
 "namespace [[deprecated(\"foo\")]] A::inline M(x)::A {\n"
@@ -123,7 +123,7 @@
   "namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ A {\n"
   "int i;\n"
   "int j;\n"
-  "}// namespace A",
+  "} // namespace A",
   fixNamespaceEndComments(
   "namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ A {\n"
   "int i;\n"
@@ -132,7 +132,7 @@
   EXPECT_EQ("namespace /* comment */ [[deprecated(\"foo\")]] A {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace A",
+"} // namespace A",
 fixNamespaceEndComments(
 "namespace /* comment */ [[deprecated(\"foo\")]] A {\n"
 "int i;\n"
@@ -143,7 +143,7 @@
   "namespace /* comment */ [[deprecated(\"foo\")]] /* comment */ M(x) {\n"
   "int i;\n"
   "int j;\n"
-  "}// namespace M(x)",
+  "} // namespace M(x)",
   fixNamespaceEndComments("#define M(x) x##x\n"
   "namespace /* comment */ "
   "[[deprecated(\"foo\")]] /* comment */ M(x) {\n"
@@ -155,7 +155,7 @@
 "A::M(x) {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace A::M(x)",
+"} // namespace A::M(x)",
 fixNamespaceEndComments(
 "#define M(x) x##x\n"
 "namespace /* comment */ "
@@ -168,7 +168,7 @@
 "M(x) /* comment */ {\n"
 "int i;\n"
 "int j;\n"
-"}// namespace M(x)",
+"} // namespace M(x)",
 fixNamespaceEndComments(
 "#define M(x) x##x\n"
 "n

[PATCH] D155992: [clangd] Use xxh3_64bits for background index file digests

2023-07-24 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks for doing this!

as Sam pointed out this will result in invalidation of all the index shards, 
but that's not something new. we already don't clean up non-relevant index 
shards when people delete sources over time and rely on people having new 
checkouts or clearing things up manually. this will be somewhat more severe, as 
we'll double the index size all of a sudden.

but i'd like to keep this patch from landing until llvm-17 is cut (which should 
be tomorrow). we didn't have any changes to our index shard serialization since 
llvm-16 release, so forcing everyone to face this invalidation purely for the 
sake of a clean up that might never happen in the codebase doesn't feel enough 
of a justification. whereas it's more likely that we'll have changes to 
serialization format throughout the next release cycle and can hit users only 
once with big cache invalidations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155992

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


[PATCH] D155992: [clangd] Use xxh3_64bits for background index file digests

2023-07-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Agree - LGTM but please land once the branch `release/17.x` exists. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155992

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


[PATCH] D156056: [clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders

2023-07-24 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL marked an inline comment as done.
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:75
+  Diags(new DiagnosticIDs,
+new DiagnosticOptions(Compiler.getDiagnosticOpts()),
 new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())),

carlosgalvezp wrote:
> PiotrZSL wrote:
> > carlosgalvezp wrote:
> > > When downloading your patch, this seems to not be needed to make the 
> > > tests pass, should it be removed?
> > No idea, it seem reasonable.
> Do you mean it seems reasonable to keep it, or reasonable to remove it?
reasonable to keep it, we want both DiagEngines to have same settings


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156056

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


[PATCH] D155842: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 543420.
Fznamznon added a comment.

Rebase to maybe fix precommit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155842

Files:
  clang/lib/Frontend/HeaderIncludeGen.cpp


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback &operator=(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback &operator=(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 438fc2c - [analyzer] Fix crash in GenericTaintChecker when propagatig taint to AllocaRegion

2023-07-24 Thread Tomasz Kamiński via cfe-commits

Author: Tomasz Kamiński
Date: 2023-07-24T10:52:35+02:00
New Revision: 438fc2c83b73e66f6dbae4f34e9a19f41302f825

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

LOG: [analyzer] Fix crash in GenericTaintChecker when propagatig taint to 
AllocaRegion

The `GenericTaintChecker` checker was crashing, when the taint
was propagated to `AllocaRegion` region in following code:
```
  int x;
  void* p = alloca(10);
  mempcy(p, &x, sizeof(x));
```
This crash was caused by the fact that determining type of
`AllocaRegion` returns a null `QualType`.

This patch makes `AllocaRegion` expose its type as `void`,
making them consistent with results of `malloc` or `new`
that produce `SymRegion` with `void*` symbol.

Reviewed By: steakhal, xazax.hun

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/SVals.cpp
clang/test/Analysis/taint-generic.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/SVals.cpp 
b/clang/lib/StaticAnalyzer/Core/SVals.cpp
index bc9c1e40d808a8..2a43a01ff88618 100644
--- a/clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -174,6 +174,9 @@ class TypeRetrievingVisitor
   QualType VisitSymbolicRegion(const SymbolicRegion *SR) {
 return Visit(SR->getSymbol());
   }
+  QualType VisitAllocaRegion(const AllocaRegion *) {
+return QualType{Context.VoidPtrTy};
+  }
   QualType VisitTypedRegion(const TypedRegion *TR) {
 return TR->getLocationType();
   }

diff  --git a/clang/test/Analysis/taint-generic.c 
b/clang/test/Analysis/taint-generic.c
index 84b7cc51dd6df8..9199b3510516e0 100644
--- a/clang/test/Analysis/taint-generic.c
+++ b/clang/test/Analysis/taint-generic.c
@@ -359,6 +359,25 @@ void testTaintedVLASize(void) {
   int vla[x]; // expected-warning{{Declared variable-length array (VLA) has 
tainted size}}
 }
 
+int testTaintedAllocaMem() {
+  char x;
+  void * p;
+  scanf("%c", &x);
+  p = __builtin_alloca(1);
+  __builtin_memcpy(p, &x, 1);
+  return 5 / *(char*)p; // expected-warning {{Division by a tainted value, 
possibly zero}}
+}
+
+int testTaintedMallocMem() {
+  char x;
+  void * p;
+  scanf("%c", &x);
+  p = malloc(1);
+  __builtin_memcpy(p, &x, 1);
+  return 5 / *(char*)p; // expected-warning {{Division by a tainted value, 
possibly zero}}
+}
+
+
 // This computation used to take a very long time.
 #define longcmp(a,b,c) { \
   a -= c;  a ^= c;  c += b; b -= a;  b ^= (a<<6) | (a >> (32-b));  a += c; c 
-= b;  c ^= b;  b += a; \



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


[PATCH] D155847: [analyzer] Fix crash in GenericTaintChecker when propagatig taint to AllocaRegion

2023-07-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG438fc2c83b73: [analyzer] Fix crash in GenericTaintChecker 
when propagatig taint to… (authored by tomasz-kaminski-sonarsource).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155847

Files:
  clang/lib/StaticAnalyzer/Core/SVals.cpp
  clang/test/Analysis/taint-generic.c


Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -359,6 +359,25 @@
   int vla[x]; // expected-warning{{Declared variable-length array (VLA) has 
tainted size}}
 }
 
+int testTaintedAllocaMem() {
+  char x;
+  void * p;
+  scanf("%c", &x);
+  p = __builtin_alloca(1);
+  __builtin_memcpy(p, &x, 1);
+  return 5 / *(char*)p; // expected-warning {{Division by a tainted value, 
possibly zero}}
+}
+
+int testTaintedMallocMem() {
+  char x;
+  void * p;
+  scanf("%c", &x);
+  p = malloc(1);
+  __builtin_memcpy(p, &x, 1);
+  return 5 / *(char*)p; // expected-warning {{Division by a tainted value, 
possibly zero}}
+}
+
+
 // This computation used to take a very long time.
 #define longcmp(a,b,c) { \
   a -= c;  a ^= c;  c += b; b -= a;  b ^= (a<<6) | (a >> (32-b));  a += c; c 
-= b;  c ^= b;  b += a; \
Index: clang/lib/StaticAnalyzer/Core/SVals.cpp
===
--- clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -174,6 +174,9 @@
   QualType VisitSymbolicRegion(const SymbolicRegion *SR) {
 return Visit(SR->getSymbol());
   }
+  QualType VisitAllocaRegion(const AllocaRegion *) {
+return QualType{Context.VoidPtrTy};
+  }
   QualType VisitTypedRegion(const TypedRegion *TR) {
 return TR->getLocationType();
   }


Index: clang/test/Analysis/taint-generic.c
===
--- clang/test/Analysis/taint-generic.c
+++ clang/test/Analysis/taint-generic.c
@@ -359,6 +359,25 @@
   int vla[x]; // expected-warning{{Declared variable-length array (VLA) has tainted size}}
 }
 
+int testTaintedAllocaMem() {
+  char x;
+  void * p;
+  scanf("%c", &x);
+  p = __builtin_alloca(1);
+  __builtin_memcpy(p, &x, 1);
+  return 5 / *(char*)p; // expected-warning {{Division by a tainted value, possibly zero}}
+}
+
+int testTaintedMallocMem() {
+  char x;
+  void * p;
+  scanf("%c", &x);
+  p = malloc(1);
+  __builtin_memcpy(p, &x, 1);
+  return 5 / *(char*)p; // expected-warning {{Division by a tainted value, possibly zero}}
+}
+
+
 // This computation used to take a very long time.
 #define longcmp(a,b,c) { \
   a -= c;  a ^= c;  c += b; b -= a;  b ^= (a<<6) | (a >> (32-b));  a += c; c -= b;  c ^= b;  b += a; \
Index: clang/lib/StaticAnalyzer/Core/SVals.cpp
===
--- clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -174,6 +174,9 @@
   QualType VisitSymbolicRegion(const SymbolicRegion *SR) {
 return Visit(SR->getSymbol());
   }
+  QualType VisitAllocaRegion(const AllocaRegion *) {
+return QualType{Context.VoidPtrTy};
+  }
   QualType VisitTypedRegion(const TypedRegion *TR) {
 return TR->getLocationType();
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153954: [WIP][clang][analyzer] Relax alpha.cplusplus.EnumCastOutOfRange checker

2023-07-24 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 marked 4 inline comments as done.
gamesh411 added a comment.

In D153954#4456713 , @shafik wrote:

> I did not look at this in detail but I don't think this approach is correct. 
> I fixed this for constant evaluation the other day and you can find the 
> details here: D130058 
>
> The test suite I wrote should be sufficient for you to validate your approach 
> against.

@shafik, @donat.nagy  Thanks for looking at this patch.
I have checked the linked improvements in Sema, and this initial modification 
would only lead to a ClangSA implementation of the same error-detection logic.
Due to symbolic execution, the set of potentially detectable errors is bigger, 
but this is maybe not the right place for this checker.

My goal is to improve the checker and eventually bring it out of alpha.

I see one main problem with this checker:

It does not support enums with fixed underlying type, namely `std::byte`, which 
is implemented like this:

  enum class byte: unsigned char {};

As `std::byte` has no enumerators, the checker would say any otherwise allowed 
non-default initialization of a std::byte instance is bad, i.e.:

  std::byte b {42}; // the checker gives a warning for this

Aside from this, in the `optin` package, there is a place for the current state 
of the checker (namely that only the value mentioned in the enumerator list are 
OK).
I will create a separate patch to move it out of alpha and into `optin` package.




Comment at: clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:42
+class RangeBasedValueMatchEvaluator : ValueMatchEvaluator {
+  llvm::APSInt Min, Max;
 

steakhal wrote:
> I can see `llvm::APSInt` used a few places. Consider `using namespace llvm;`
Again, good point, I just abandoned the direction where many APSInt mentions 
are introduced, and the original only has 2 mentions of APSInt.



Comment at: 
clang/lib/StaticAnalyzer/Checkers/EnumCastOutOfRangeChecker.cpp:65-69
+  if (TrueState && !FalseState) {
+Pred = C.addTransition(TrueState, Pred);
+  } else if (FalseState && !TrueState) {
+Pred = C.addTransition(FalseState, Pred);
+  }

steakhal wrote:
> Why do you fold the "Pred" ExplodedNode?
> I'd say, you probably didn't want to use `addTransition` here.
> Why don't you assume the subsequent assumptions and transition only once?
> 
> Anyway, I think it's better to have the `addTransition` closer to the outer 
> scope (where the error reporting is done), so that we can easily see how many 
> ways we branch off, etc.
Thanks! This is a very good point; I just changed the general direction of the 
checker, and this implementation is no longer touched by the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153954

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


[PATCH] D156090: [Driver][XRay][test] Add support for loongarch64

2023-07-24 Thread Limin Zhang via Phabricator via cfe-commits
Ami-zhang created this revision.
Ami-zhang added reviewers: SixWeining, probinson, MaskRay.
Herald added a subscriber: dberris.
Herald added a project: All.
Ami-zhang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends on D156089 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156090

Files:
  clang/test/Driver/XRay/lit.local.cfg
  clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
  clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
  clang/test/Driver/XRay/xray-mode-flags.cpp


Index: clang/test/Driver/XRay/xray-mode-flags.cpp
===
--- clang/test/Driver/XRay/xray-mode-flags.cpp
+++ clang/test/Driver/XRay/xray-mode-flags.cpp
@@ -46,4 +46,4 @@
 // NONE-NOT: libclang_rt.xray-basic
 // NONE-NOT: libclang_rt.xray-fdr
 // REQUIRES: target={{.*-(linux|freebsd).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64|loongarch64)-.*}}
Index: clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
===
--- clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
+++ clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
@@ -7,4 +7,4 @@
 // CHECK:  -fxray-instrumentation-bundle=function
 //
 // REQUIRES: target={{.*-(linux|freebsd).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64|loongarch64)-.*}}
Index: clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
===
--- clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
+++ clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
@@ -6,4 +6,4 @@
 // RUN:   -x c++ -emit-llvm -c -o - %s 2>&1 | FileCheck %s
 // CHECK:  -fxray-ignore-loops
 //
-// REQUIRES: target={{(x86_64|x86_64h)-.*}}
+// REQUIRES: target={{(x86_64|x86_64h|loongarch64)-.*}}
Index: clang/test/Driver/XRay/lit.local.cfg
===
--- clang/test/Driver/XRay/lit.local.cfg
+++ clang/test/Driver/XRay/lit.local.cfg
@@ -13,6 +13,7 @@
 "mipsel",
 "mips64",
 "mips64el",
+"loongarch64",
 ]
 
 # Only on platforms we support.


Index: clang/test/Driver/XRay/xray-mode-flags.cpp
===
--- clang/test/Driver/XRay/xray-mode-flags.cpp
+++ clang/test/Driver/XRay/xray-mode-flags.cpp
@@ -46,4 +46,4 @@
 // NONE-NOT: libclang_rt.xray-basic
 // NONE-NOT: libclang_rt.xray-fdr
 // REQUIRES: target={{.*-(linux|freebsd).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64|loongarch64)-.*}}
Index: clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
===
--- clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
+++ clang/test/Driver/XRay/xray-instrumentation-bundles-flags.cpp
@@ -7,4 +7,4 @@
 // CHECK:  -fxray-instrumentation-bundle=function
 //
 // REQUIRES: target={{.*-(linux|freebsd).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
+// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64|loongarch64)-.*}}
Index: clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
===
--- clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
+++ clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
@@ -6,4 +6,4 @@
 // RUN:   -x c++ -emit-llvm -c -o - %s 2>&1 | FileCheck %s
 // CHECK:  -fxray-ignore-loops
 //
-// REQUIRES: target={{(x86_64|x86_64h)-.*}}
+// REQUIRES: target={{(x86_64|x86_64h|loongarch64)-.*}}
Index: clang/test/Driver/XRay/lit.local.cfg
===
--- clang/test/Driver/XRay/lit.local.cfg
+++ clang/test/Driver/XRay/lit.local.cfg
@@ -13,6 +13,7 @@
 "mipsel",
 "mips64",
 "mips64el",
+"loongarch64",
 ]
 
 # Only on platforms we support.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155452: [Flang] Add support for fsave-optimization-record

2023-07-24 Thread victorkingi via Phabricator via cfe-commits
victorkingi updated this revision to Diff 543424.
victorkingi added a comment.

no changes rebasing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155452

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CodeGenOptions.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/test/Driver/fsave-optimization-record.f90

Index: flang/test/Driver/fsave-optimization-record.f90
===
--- /dev/null
+++ flang/test/Driver/fsave-optimization-record.f90
@@ -0,0 +1,42 @@
+! Tests for the '-f[no-]save-optimization-record[=]' flag.
+
+! Test -foptimization-record-file produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -foptimization-record-file=%t.opt.yaml -c %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! Test -fsave-optimization-record produces YAML file with given content
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -c -o %t.o %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -o %t.s %s
+! RUN: cat %t.opt.yaml | FileCheck %s
+
+! Produces an empty file
+! RUN: rm -f %t.opt.yaml
+! RUN: %flang -fsave-optimization-record -S -emit-llvm -o %t.ll %s
+! RUN: cat %t.opt.yaml
+
+!Test unknown format produces error
+! RUN: not %flang -fsave-optimization-record=hello %s 2>&1 \
+! RUN:   | FileCheck --check-prefix=CHECK-FORMAT-ERROR %s
+
+! CHECK: --- !Analysis
+! CHECK: Pass:prologepilog
+! CHECK: Name:StackSize
+! CHECK: Function:_QQmain
+! CHECK: Pass:asm-printer
+! CHECK: Name:InstructionMix
+! CHECK: Name:InstructionCount
+
+! CHECK-FORMAT-ERROR: error: unknown remark serializer format: 'hello'
+
+program forttest
+implicit none
+integer :: n
+
+n = 1 * 1
+
+end program forttest
Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -15,6 +15,7 @@
 ! RUN: -fassociative-math \
 ! RUN: -freciprocal-math \
 ! RUN: -fpass-plugin=Bye%pluginext \
+! RUN: -fsave-optimization-record \
 ! RUN: -fversion-loops-for-stride \
 ! RUN: -flang-experimental-polymorphism \
 ! RUN: -mllvm -print-before-all \
@@ -22,6 +23,10 @@
 ! RUN: -P \
 ! RUN:   | FileCheck %s
 
+! RUN: %flang -### %s 2>&1 \
+! RUN: -foptimization-record-file=%t.opt.yaml \
+! RUN:   | FileCheck --check-prefix=YAML %s
+
 ! CHECK: "-P"
 ! CHECK: "-finput-charset=utf-8"
 ! CHECK: "-fdefault-double-8"
@@ -38,5 +43,10 @@
 ! CHECK: "-fpass-plugin=Bye
 ! CHECK: "-flang-experimental-polymorphism"
 ! CHECK: "-fversion-loops-for-stride"
+! CHECK: "-opt-record-file" "{{.+}}.opt.yaml"
+! CHECK: "-opt-record-format" "yaml"
 ! CHECK: "-mllvm" "-print-before-all"
 ! CHECK: "-save-temps=obj"
+
+! YAML: "-opt-record-file" "{{.+}}.opt.yaml"
+! YAML: "-opt-record-format" "yaml"
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -54,8 +54,16 @@
 ! HELP-NEXT: -fopenmp-version=
 ! HELP-NEXT:Set OpenMP version (e.g. 45 for OpenMP 4.5, 50 for OpenMP 5.0). Default value is 50 for Clang and 11 for Flang
 ! HELP-NEXT: -fopenmp   Parse OpenMP pragmas and generate parallel code.
+! HELP-NEXT: -foptimization-record-file=
+! HELP-NEXT:Specify the output name of the file containing the optimization remarks. Implies -fsave-optimization-record. On Darwin platforms, this cannot be used with multiple -arch  options.
+! HELP-NEXT: -foptimization-record-passes=
+! HELP-NEXT:Only include passes which match a specified regular expression in the generated optimization record (by default, include all passes)
 ! HELP-NEXT: -fpass-plugin= Load pass plugin from a dynamic shared object file (only with new pass manager).
 ! HELP-NEXT: -freciprocal-math  Allow division operations to be reassociated
+! HELP-NEXT: -fsave-optimization-record=
+! HELP-NEXT:Generate an optimization record file in a specific format
+! HELP-NEXT: -fsave-optimization-record
+! HELP-NEXT:Generate a YAML optimization record file
 ! HELP-NEXT: -fstack-arrays Attempt to allocate array temporaries on the stack, no matter their size
 ! HELP-NEXT: -fsyntax-only  Run the preprocessor, parser and semantic analysis stages
 ! HELP-NEXT: -funderscoring Appends one trailing underscore to external names
@@ -186,6 

[PATCH] D155294: [Driver][RISCV] Find baremetal multilibs using YAML for GNU toolchain

2023-07-24 Thread Joseph Faulls via Phabricator via cfe-commits
Joe added a comment.

> Theoretically, I think this matching of multilibs could be done without the 
> need for multilib.yaml, but it is indeed much easier considering the logic is 
> already there.

Actually, I retract this statement. There would be no way of knowing what the 
default library is without something telling you, i.e. a yaml file.

@michaelplatings thank you for the speedy comment!

> Multilib flags must be valid command line options. So as `+a` is not a valid 
> command line option, it should not be used as a multilib flag.
>
> That said, I'm very aware that it would be desirable to specify attributes 
> independently of command line options, so I think there's room for the design 
> to grow.

Matching on extension is the most important thing for riscv. The only other way 
to do it under the current vision of multilib flags, as far as I'm aware, are 
some nasty and repetitive regexes. Do you think we could allow the design to 
grow to allow attributes prefixed by `+` in addition to flags?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155294

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


[clang] 17a58b3 - [clang][RISCV] Fix ABI handling of empty structs with hard FP calling conventions in C++

2023-07-24 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2023-07-24T10:24:34+01:00
New Revision: 17a58b3ca7ec18585e9ea8ed8b39d72fe36fb6cb

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

LOG: [clang][RISCV] Fix ABI handling of empty structs with hard FP calling 
conventions in C++

As reported in ,
Clang's handling of empty structs in the case of small structs that may
be eligible to be passed using the hard FP calling convention doesn't
match g++. In general, C++ record fields are never empty unless
[[no_unique_address]] is used, but the RISC-V FP ABI overrides this.

After this patch, fields of structs that contain empty records will be
ignored, even in C++, when considering eligibility for the FP calling
convention ('flattening'). See also the relevant psABI issue
 which
seeks to clarify the documentation.

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

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/ABIInfoImpl.cpp
clang/lib/CodeGen/ABIInfoImpl.h
clang/lib/CodeGen/Targets/RISCV.cpp
clang/test/CodeGen/RISCV/abi-empty-structs.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index db9149fae797c4..1df474d2672720 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -899,6 +899,9 @@ RISC-V Support
 - The rules for ordering of extensions in ``-march`` strings were relaxed. A
   canonical ordering is no longer enforced on ``z*``, ``s*``, and ``x*``
   prefixed extensions.
+* An ABI mismatch between GCC and Clang related to the handling of empty
+  structs in C++ parameter passing under the hard floating point calling
+  conventions was fixed.
 
 CUDA/HIP Language Changes
 ^

diff  --git a/clang/lib/CodeGen/ABIInfoImpl.cpp 
b/clang/lib/CodeGen/ABIInfoImpl.cpp
index 7c30cecfdb9b77..2b20d5a13346d3 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.cpp
+++ b/clang/lib/CodeGen/ABIInfoImpl.cpp
@@ -246,7 +246,7 @@ Address CodeGen::emitMergePHI(CodeGenFunction &CGF, Address 
Addr1,
 }
 
 bool CodeGen::isEmptyField(ASTContext &Context, const FieldDecl *FD,
-   bool AllowArrays) {
+   bool AllowArrays, bool AsIfNoUniqueAddr) {
   if (FD->isUnnamedBitfield())
 return true;
 
@@ -280,13 +280,14 @@ bool CodeGen::isEmptyField(ASTContext &Context, const 
FieldDecl *FD,
   // not arrays of records, so we must also check whether we stripped off an
   // array type above.
   if (isa(RT->getDecl()) &&
-  (WasArray || !FD->hasAttr()))
+  (WasArray || (!AsIfNoUniqueAddr && !FD->hasAttr(
 return false;
 
-  return isEmptyRecord(Context, FT, AllowArrays);
+  return isEmptyRecord(Context, FT, AllowArrays, AsIfNoUniqueAddr);
 }
 
-bool CodeGen::isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays) 
{
+bool CodeGen::isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,
+bool AsIfNoUniqueAddr) {
   const RecordType *RT = T->getAs();
   if (!RT)
 return false;
@@ -297,11 +298,11 @@ bool CodeGen::isEmptyRecord(ASTContext &Context, QualType 
T, bool AllowArrays) {
   // If this is a C++ record, check the bases first.
   if (const CXXRecordDecl *CXXRD = dyn_cast(RD))
 for (const auto &I : CXXRD->bases())
-  if (!isEmptyRecord(Context, I.getType(), true))
+  if (!isEmptyRecord(Context, I.getType(), true, AsIfNoUniqueAddr))
 return false;
 
   for (const auto *I : RD->fields())
-if (!isEmptyField(Context, I, AllowArrays))
+if (!isEmptyField(Context, I, AllowArrays, AsIfNoUniqueAddr))
   return false;
   return true;
 }

diff  --git a/clang/lib/CodeGen/ABIInfoImpl.h b/clang/lib/CodeGen/ABIInfoImpl.h
index 5f0cc289af68b3..afde08ba100cf0 100644
--- a/clang/lib/CodeGen/ABIInfoImpl.h
+++ b/clang/lib/CodeGen/ABIInfoImpl.h
@@ -122,13 +122,19 @@ Address emitMergePHI(CodeGenFunction &CGF, Address Addr1,
  llvm::BasicBlock *Block2, const llvm::Twine &Name = "");
 
 /// isEmptyField - Return true iff a the field is "empty", that is it
-/// is an unnamed bit-field or an (array of) empty record(s).
-bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays);
+/// is an unnamed bit-field or an (array of) empty record(s). If
+/// AsIfNoUniqueAddr is true, then C++ record fields are considered empty if
+/// the [[no_unique_address]] attribute would have made them empty.
+bool isEmptyField(ASTContext &Context, const FieldDecl *FD, bool AllowArrays,
+  bool AsIfNoUniqueAddr = false);
 
 /// isEmptyRecord - Return true iff a structure contains only empty
 /// fi

[PATCH] D142327: [clang][RISCV] Fix ABI handling of empty structs with hard FP calling conventions in C++

2023-07-24 Thread Alex Bradbury via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG17a58b3ca7ec: [clang][RISCV] Fix ABI handling of empty 
structs with hard FP calling… (authored by asb).
Herald added a subscriber: wangpc.

Changed prior to commit:
  https://reviews.llvm.org/D142327?vs=491781&id=543432#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D142327

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/ABIInfoImpl.cpp
  clang/lib/CodeGen/ABIInfoImpl.h
  clang/lib/CodeGen/Targets/RISCV.cpp
  clang/test/CodeGen/RISCV/abi-empty-structs.c

Index: clang/test/CodeGen/RISCV/abi-empty-structs.c
===
--- clang/test/CodeGen/RISCV/abi-empty-structs.c
+++ clang/test/CodeGen/RISCV/abi-empty-structs.c
@@ -19,8 +19,9 @@
 #include 
 
 // Fields containing empty structs or unions are ignored when flattening
-// structs for the hard FP ABIs, even in C++.
-// FIXME: This isn't currently respected.
+// structs for the hard FP ABIs, even in C++. The rules for arrays of empty
+// structs or unions are subtle and documented in
+// .
 
 struct empty { struct { struct { } e; }; };
 struct s1 { struct empty e; float f; };
@@ -29,13 +30,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local [2 x i32] @_Z7test_s12s1
-// CHECK32-CXX-SAME: ([2 x i32] [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local i64 @_Z7test_s12s1
-// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0:[0-9]+]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local float @_Z7test_s12s1
+// CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-CXX:  entry:
 //
 struct s1 test_s1(struct s1 a) {
   return a;
@@ -47,13 +44,9 @@
 // CHECK-C-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s22s2
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S2:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s22s2
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { i32, float } @_Z7test_s22s2
+// CHECK-CXX-SAME: (i32 [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s2 test_s2(struct s2 a) {
   return a;
@@ -65,13 +58,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s32s3
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S3:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s32s3
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s32s3
+// CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s3 test_s3(struct s3 a) {
   return a;
@@ -83,13 +72,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local void @_Z7test_s42s4
-// CHECK32-CXX-SAME: (ptr noalias sret([[STRUCT_S4:%.*]]) align 4 [[AGG_RESULT:%.*]], ptr noundef [[A:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local [2 x i64] @_Z7test_s42s4
-// CHECK64-CXX-SAME: ([2 x i64] [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local { float, float } @_Z7test_s42s4
+// CHECK-CXX-SAME: (float [[TMP0:%.*]], float [[TMP1:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s4 test_s4(struct s4 a) {
   return a;
@@ -142,7 +127,7 @@
 // CHECK-C:  entry:
 //
 // CHECK-CXX-LABEL: define dso_local float @_Z7test_s72s7
-// CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
 // CHECK-CXX:  entry:
 //
 struct s7 test_s7(struct s7 a) {
@@ -156,13 +141,9 @@
 // CHECK-C-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
 // CHECK-C:  entry:
 //
-// CHECK32-CXX-LABEL: define dso_local i32 @_Z7test_s82s8
-// CHECK32-CXX-SAME: (i32 [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK32-CXX:  entry:
-//
-// CHECK64-CXX-LABEL: define dso_local i64 @_Z7test_s82s8
-// CHECK64-CXX-SAME: (i64 [[A_COERCE:%.*]]) #[[ATTR0]] {
-// CHECK64-CXX:  entry:
+// CHECK-CXX-LABEL: define dso_local float @_Z7test_s82s8
+// CHECK-CXX-SAME: (float [[TMP0:%.*]]) #[[ATTR0]] {
+// CHECK-CXX:  entry:
 //
 struct s8 test_s8(str

[PATCH] D156056: [clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders

2023-07-24 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:75
+  Diags(new DiagnosticIDs,
+new DiagnosticOptions(Compiler.getDiagnosticOpts()),
 new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())),

PiotrZSL wrote:
> carlosgalvezp wrote:
> > PiotrZSL wrote:
> > > carlosgalvezp wrote:
> > > > When downloading your patch, this seems to not be needed to make the 
> > > > tests pass, should it be removed?
> > > No idea, it seem reasonable.
> > Do you mean it seems reasonable to keep it, or reasonable to remove it?
> reasonable to keep it, we want both DiagEngines to have same settings
Reason I ask is that it seems the majority of `DiagnosticOptions` are 
initialized with default ctor:

```
$ git grep -E " DiagnosticOptions\(\w" | wc -l
3
$ git grep -E " DiagnosticOptions\(\)" | wc -l
74
```

> we want both DiagEngines to have same settings

Do you know where "the other" `DiagEngine` is initialized? The one I can find 
is initialized without the compiler opts.

https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/ClangTidy.cpp#L544

Since the added code does not have any impact on the result of the test, I'd 
argue that either the test is insufficient or the added code is dead code that 
should be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156056

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


[PATCH] D156089: [Driver][XRay][test] Convert more tests to check 'target=...' after 016785d9316d8c5abc5fdf3cdb86479095bbb677

2023-07-24 Thread Lu Weining via Phabricator via cfe-commits
SixWeining added inline comments.



Comment at: clang/test/Driver/XRay/xray-ignore-loops-flags.cpp:5
 //
 // RUN: %clang -fxray-instrument -fxray-ignore-loops -target x86_64-linux- 
-### \
 // RUN:   -x c++ -emit-llvm -c -o - %s 2>&1 | FileCheck %s

`x86_64-linux` is used here, so maybe we can remove the `REQUIRES` line 
directly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156089

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


[PATCH] D156056: [clang-tidy] Initialize DiagnosticEngine in ExpandModularHeaders

2023-07-24 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL marked an inline comment as done.
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp:75
+  Diags(new DiagnosticIDs,
+new DiagnosticOptions(Compiler.getDiagnosticOpts()),
 new ForwardingDiagnosticConsumer(Compiler.getDiagnosticClient())),

carlosgalvezp wrote:
> PiotrZSL wrote:
> > carlosgalvezp wrote:
> > > PiotrZSL wrote:
> > > > carlosgalvezp wrote:
> > > > > When downloading your patch, this seems to not be needed to make the 
> > > > > tests pass, should it be removed?
> > > > No idea, it seem reasonable.
> > > Do you mean it seems reasonable to keep it, or reasonable to remove it?
> > reasonable to keep it, we want both DiagEngines to have same settings
> Reason I ask is that it seems the majority of `DiagnosticOptions` are 
> initialized with default ctor:
> 
> ```
> $ git grep -E " DiagnosticOptions\(\w" | wc -l
> 3
> $ git grep -E " DiagnosticOptions\(\)" | wc -l
> 74
> ```
> 
> > we want both DiagEngines to have same settings
> 
> Do you know where "the other" `DiagEngine` is initialized? The one I can find 
> is initialized without the compiler opts.
> 
> https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/clang-tidy/ClangTidy.cpp#L544
> 
> Since the added code does not have any impact on the result of the test, I'd 
> argue that either the test is insufficient or the added code is dead code 
> that should be removed.
sure, maybe ProcessWarningOptions will override it anyway, I didnt check more 
deeply.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156056

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


[PATCH] D155396: [Sema][ObjC] Invalidate BlockDecl with invalid return expr & its parent BlockExpr

2023-07-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, looks good to me.




Comment at: clang/test/AST/ast-dump-recovery.m:24
+// CHECK-NEXT: | `-BlockDecl {{.*}} invalid
+int (^a)() = ^() {
+  return c;

nit: it'd be nice to encode the github issue number to the testcase here, for 
example (renaming the `a` to `gh63863` etc).



Comment at: clang/test/AST/ast-dump-recovery.m:25
+int (^a)() = ^() {
+  return c;
+};

nit: use a more descriptive name `return undef;`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155396

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


[clang] 569e99a - [clang][docs] Attempt to fix warning when building ReleaseNotes

2023-07-24 Thread Alex Bradbury via cfe-commits

Author: Alex Bradbury
Date: 2023-07-24T10:36:42+01:00
New Revision: 569e99a471f618b7fdf045d5e96f21d3e3a7f898

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

LOG: [clang][docs] Attempt to fix warning when building ReleaseNotes

I believe my previous patch, 17a58b3ca7ec18585e9ea8ed8b39d72fe36fb6cb
introduced a warning here.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1df474d2672720..8e19b3695ef49e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -899,7 +899,7 @@ RISC-V Support
 - The rules for ordering of extensions in ``-march`` strings were relaxed. A
   canonical ordering is no longer enforced on ``z*``, ``s*``, and ``x*``
   prefixed extensions.
-* An ABI mismatch between GCC and Clang related to the handling of empty
+- An ABI mismatch between GCC and Clang related to the handling of empty
   structs in C++ parameter passing under the hard floating point calling
   conventions was fixed.
 



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


[clang-tools-extra] b0fd2fd - [include_cleaner] IncludeSpeller.cpp - fix MSVC "not all control paths return a value" warning. NFC.

2023-07-24 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2023-07-24T10:37:59+01:00
New Revision: b0fd2fd81606513444d867db13236750754b0d02

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

LOG: [include_cleaner] IncludeSpeller.cpp - fix MSVC "not all control paths 
return a value" warning. NFC.

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp 
b/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
index 8e6143820a2b73..bb49630fe3c80b 100644
--- a/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
+++ b/clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
@@ -34,6 +34,7 @@ class DefaultIncludeSpeller : public IncludeSpeller {
   Input.H.physical(), Input.Main->tryGetRealPathName(), &IsSystem);
   return IsSystem ? "<" + FinalSpelling + ">" : "\"" + FinalSpelling + 
"\"";
 }
+llvm_unreachable("Unknown clang::include_cleaner::Header::Kind enum");
   }
 };
 



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


[clang-tools-extra] 9fbabba - [clangd] InlayHints.cpp - fix MSVC "not all control paths return a value" warning. NFC.

2023-07-24 Thread Simon Pilgrim via cfe-commits

Author: Simon Pilgrim
Date: 2023-07-24T10:37:59+01:00
New Revision: 9fbabba9212e7f1a2488a3b05eed0fc61006a7ac

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

LOG: [clangd] InlayHints.cpp - fix MSVC "not all control paths return a value" 
warning. NFC.

Added: 


Modified: 
clang-tools-extra/clangd/InlayHints.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/InlayHints.cpp 
b/clang-tools-extra/clangd/InlayHints.cpp
index 0b5bab1aac9b1b..9247d212f73c45 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -222,6 +222,7 @@ const NamedDecl *getDeclForType(const Type *T) {
 return getDeclForTypeImpl(llvm::cast(T));
 #include "clang/AST/TypeNodes.inc"
   }
+  llvm_unreachable("Unknown TypeClass enum");
 }
 
 // getSimpleName() returns the plain identifier for an entity, if any.



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


[PATCH] D155809: [NFC] [Clang] Fix strict weak ordering in ItaniumVTableBuilder

2023-07-24 Thread Danila Kutenin via Phabricator via cfe-commits
danlark added a comment.

In D155809#4521494 , @rsmith wrote:

> This looks correct to me, but it's still a little subtle. Perhaps it'd be 
> clearer to map the method to an integer (0 for copy assignment, 1 for move 
> assignment, 2 for destructor, 3 for equality comparison), and then order them 
> by that integer? That'd be more obviously a strict weak order.



In D155809#4520765 , @shafik wrote:

> I am not sure about this change but I think we at least need a test and this 
> does not seem non-functional if it prevents a crash.

This is NFC as it only prevents further assert to fire when stable_sort 
compares the element with itself


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155809

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


cfe-commits@lists.llvm.org

2023-07-24 Thread Bing Yu via Phabricator via cfe-commits
yubing updated this revision to Diff 543433.
yubing added a comment.

make retcc respect regcall ABI v.4 as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155863

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/check-regcall4-moduleflag.c
  clang/test/CodeGen/regcall4.c
  clang/test/CodeGenCXX/regcall4.cpp
  clang/test/Driver/cl-cc-flags.c
  llvm/lib/Target/X86/X86CallingConv.td
  llvm/test/CodeGen/X86/sse-regcall4.ll

Index: llvm/test/CodeGen/X86/sse-regcall4.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/sse-regcall4.ll
@@ -0,0 +1,467 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=i386-pc-win32 -mattr=+sse | FileCheck --check-prefix=WIN32 %s
+; RUN: llc < %s -mtriple=x86_64-win32 -mattr=+sse | FileCheck --check-prefix=WIN64 %s
+; RUN: llc < %s -mtriple=x86_64-linux-gnu -mattr=+sse | FileCheck --check-prefix=LINUXOSX %s
+
+; Test regcall when receiving/returning i1
+define x86_regcallcc i1 @test_argReti1(i1 %a)  {
+; WIN32-LABEL: test_argReti1:
+; WIN32:   # %bb.0:
+; WIN32-NEXT:incb %cl
+; WIN32-NEXT:# kill: def $cl killed $cl killed $ecx
+; WIN32-NEXT:retl
+;
+; WIN64-LABEL: test_argReti1:
+; WIN64:   # %bb.0:
+; WIN64-NEXT:incb %al
+; WIN64-NEXT:# kill: def $al killed $al killed $eax
+; WIN64-NEXT:retq
+;
+; LINUXOSX-LABEL: test_argReti1:
+; LINUXOSX:   # %bb.0:
+; LINUXOSX-NEXT:incb %al
+; LINUXOSX-NEXT:# kill: def $al killed $al killed $eax
+; LINUXOSX-NEXT:retq
+  %add = add i1 %a, 1
+  ret i1 %add
+}
+
+; Test regcall when passing/retrieving i1
+define x86_regcallcc i1 @test_CallargReti1(i1 %a)  {
+; WIN32-LABEL: test_CallargReti1:
+; WIN32:   # %bb.0:
+; WIN32-NEXT:incb %cl
+; WIN32-NEXT:movzbl %cl, %ecx
+; WIN32-NEXT:calll _test_argReti1
+; WIN32-NEXT:incb %cl
+; WIN32-NEXT:retl
+;
+; WIN64-LABEL: test_CallargReti1:
+; WIN64:   # %bb.0:
+; WIN64-NEXT:pushq %rax
+; WIN64-NEXT:.seh_stackalloc 8
+; WIN64-NEXT:.seh_endprologue
+; WIN64-NEXT:incb %al
+; WIN64-NEXT:movzbl %al, %eax
+; WIN64-NEXT:callq test_argReti1
+; WIN64-NEXT:incb %al
+; WIN64-NEXT:popq %rcx
+; WIN64-NEXT:retq
+; WIN64-NEXT:.seh_endproc
+;
+; LINUXOSX-LABEL: test_CallargReti1:
+; LINUXOSX:   # %bb.0:
+; LINUXOSX-NEXT:pushq %rax
+; LINUXOSX-NEXT:.cfi_def_cfa_offset 16
+; LINUXOSX-NEXT:incb %al
+; LINUXOSX-NEXT:movzbl %al, %eax
+; LINUXOSX-NEXT:callq *test_argReti1@GOTPCREL(%rip)
+; LINUXOSX-NEXT:incb %al
+; LINUXOSX-NEXT:popq %rcx
+; LINUXOSX-NEXT:.cfi_def_cfa_offset 8
+; LINUXOSX-NEXT:retq
+  %b = add i1 %a, 1
+  %c = call x86_regcallcc i1 @test_argReti1(i1 %b)
+  %d = add i1 %c, 1
+  ret i1 %d
+}
+
+;test calling conventions - input parameters, callee saved xmms
+define x86_regcallcc <16 x float> @testf32_inp(<16 x float> %a, <16 x float> %b, <16 x float> %c) nounwind {
+; WIN32-LABEL: testf32_inp:
+; WIN32:   # %bb.0:
+; WIN32-NEXT:pushl %ebp
+; WIN32-NEXT:movl %esp, %ebp
+; WIN32-NEXT:andl $-16, %esp
+; WIN32-NEXT:subl $32, %esp
+; WIN32-NEXT:movaps %xmm7, (%esp) # 16-byte Spill
+; WIN32-NEXT:movaps %xmm6, %xmm7
+; WIN32-NEXT:movaps %xmm5, %xmm6
+; WIN32-NEXT:movaps %xmm3, %xmm5
+; WIN32-NEXT:movaps %xmm2, %xmm3
+; WIN32-NEXT:movaps %xmm1, %xmm2
+; WIN32-NEXT:movaps %xmm0, %xmm1
+; WIN32-NEXT:addps %xmm4, %xmm0
+; WIN32-NEXT:mulps %xmm4, %xmm1
+; WIN32-NEXT:subps %xmm1, %xmm0
+; WIN32-NEXT:movups 8(%ebp), %xmm1
+; WIN32-NEXT:addps %xmm1, %xmm0
+; WIN32-NEXT:movaps %xmm2, %xmm4
+; WIN32-NEXT:addps %xmm6, %xmm4
+; WIN32-NEXT:mulps %xmm6, %xmm2
+; WIN32-NEXT:subps %xmm2, %xmm4
+; WIN32-NEXT:movups 24(%ebp), %xmm1
+; WIN32-NEXT:addps %xmm1, %xmm4
+; WIN32-NEXT:movaps %xmm3, %xmm2
+; WIN32-NEXT:addps %xmm7, %xmm2
+; WIN32-NEXT:mulps %xmm7, %xmm3
+; WIN32-NEXT:subps %xmm3, %xmm2
+; WIN32-NEXT:movups 40(%ebp), %xmm1
+; WIN32-NEXT:addps %xmm1, %xmm2
+; WIN32-NEXT:movaps %xmm5, %xmm3
+; WIN32-NEXT:movaps (%esp), %xmm1 # 16-byte Reload
+; WIN32-NEXT:addps %xmm1, %xmm3
+; WIN32-NEXT:mulps %xmm1, %xmm5
+; WIN32-NEXT:subps %xmm5, %xmm3
+; WIN32-NEXT:movups 56(%ebp), %xmm1
+; WIN32-NEXT:addps %xmm1, %xmm3
+; WIN32-NEXT:movaps %xmm4, %xmm1
+; WIN32-NEXT:movl %ebp, %esp
+; WIN32-NEXT:popl %ebp
+; WIN32-NEXT:retl
+;
+; WIN64-LABEL: testf32_inp:
+; WIN64:   # %bb.0:
+; WIN64-NEXT:subq $72, %rsp
+; WIN64-NEXT:movaps %xmm15, {{[-0-9]+}}(%r{{[sb]}}p) # 16-byte Spill
+; WIN64-NEXT:movaps %xmm14, {{[-0-9]+}}(%r{{[s

cfe-commits@lists.llvm.org

2023-07-24 Thread Bing Yu via Phabricator via cfe-commits
yubing added inline comments.



Comment at: llvm/lib/Target/X86/X86CallingConv.td:468
+defm X86_32_RegCallv4_Win :
+X86_RegCall_base;
 defm X86_Win64_RegCall :

pengfei wrote:
> This will define RetCC_* as well but it is not used, hence will emit warning. 
> Any way to solve it?
yes, in fact retcc should respect regcall4 as well according to 
https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-8/c-c-calling-conventions.html#GUID-011A435D-F8D0-46D7-B973-9B704CA5B54E


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155863

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


cfe-commits@lists.llvm.org

2023-07-24 Thread Bing Yu via Phabricator via cfe-commits
yubing updated this revision to Diff 543437.
yubing added a comment.

small fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155863

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/Mangle.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/check-regcall4-moduleflag.c
  clang/test/CodeGen/regcall4.c
  clang/test/CodeGenCXX/regcall4.cpp
  clang/test/Driver/cl-cc-flags.c
  llvm/lib/Target/X86/X86CallingConv.td
  llvm/test/CodeGen/X86/sse-regcall4.ll

Index: llvm/test/CodeGen/X86/sse-regcall4.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/sse-regcall4.ll
@@ -0,0 +1,467 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=i386-pc-win32 -mattr=+sse | FileCheck --check-prefix=WIN32 %s
+; RUN: llc < %s -mtriple=x86_64-win32 -mattr=+sse | FileCheck --check-prefix=WIN64 %s
+; RUN: llc < %s -mtriple=x86_64-linux-gnu -mattr=+sse | FileCheck --check-prefix=LINUXOSX %s
+
+; Test regcall when receiving/returning i1
+define x86_regcallcc i1 @test_argReti1(i1 %a)  {
+; WIN32-LABEL: test_argReti1:
+; WIN32:   # %bb.0:
+; WIN32-NEXT:incb %cl
+; WIN32-NEXT:# kill: def $cl killed $cl killed $ecx
+; WIN32-NEXT:retl
+;
+; WIN64-LABEL: test_argReti1:
+; WIN64:   # %bb.0:
+; WIN64-NEXT:incb %al
+; WIN64-NEXT:# kill: def $al killed $al killed $eax
+; WIN64-NEXT:retq
+;
+; LINUXOSX-LABEL: test_argReti1:
+; LINUXOSX:   # %bb.0:
+; LINUXOSX-NEXT:incb %al
+; LINUXOSX-NEXT:# kill: def $al killed $al killed $eax
+; LINUXOSX-NEXT:retq
+  %add = add i1 %a, 1
+  ret i1 %add
+}
+
+; Test regcall when passing/retrieving i1
+define x86_regcallcc i1 @test_CallargReti1(i1 %a)  {
+; WIN32-LABEL: test_CallargReti1:
+; WIN32:   # %bb.0:
+; WIN32-NEXT:incb %cl
+; WIN32-NEXT:movzbl %cl, %ecx
+; WIN32-NEXT:calll _test_argReti1
+; WIN32-NEXT:incb %cl
+; WIN32-NEXT:retl
+;
+; WIN64-LABEL: test_CallargReti1:
+; WIN64:   # %bb.0:
+; WIN64-NEXT:pushq %rax
+; WIN64-NEXT:.seh_stackalloc 8
+; WIN64-NEXT:.seh_endprologue
+; WIN64-NEXT:incb %al
+; WIN64-NEXT:movzbl %al, %eax
+; WIN64-NEXT:callq test_argReti1
+; WIN64-NEXT:incb %al
+; WIN64-NEXT:popq %rcx
+; WIN64-NEXT:retq
+; WIN64-NEXT:.seh_endproc
+;
+; LINUXOSX-LABEL: test_CallargReti1:
+; LINUXOSX:   # %bb.0:
+; LINUXOSX-NEXT:pushq %rax
+; LINUXOSX-NEXT:.cfi_def_cfa_offset 16
+; LINUXOSX-NEXT:incb %al
+; LINUXOSX-NEXT:movzbl %al, %eax
+; LINUXOSX-NEXT:callq *test_argReti1@GOTPCREL(%rip)
+; LINUXOSX-NEXT:incb %al
+; LINUXOSX-NEXT:popq %rcx
+; LINUXOSX-NEXT:.cfi_def_cfa_offset 8
+; LINUXOSX-NEXT:retq
+  %b = add i1 %a, 1
+  %c = call x86_regcallcc i1 @test_argReti1(i1 %b)
+  %d = add i1 %c, 1
+  ret i1 %d
+}
+
+;test calling conventions - input parameters, callee saved xmms
+define x86_regcallcc <16 x float> @testf32_inp(<16 x float> %a, <16 x float> %b, <16 x float> %c) nounwind {
+; WIN32-LABEL: testf32_inp:
+; WIN32:   # %bb.0:
+; WIN32-NEXT:pushl %ebp
+; WIN32-NEXT:movl %esp, %ebp
+; WIN32-NEXT:andl $-16, %esp
+; WIN32-NEXT:subl $32, %esp
+; WIN32-NEXT:movaps %xmm7, (%esp) # 16-byte Spill
+; WIN32-NEXT:movaps %xmm6, %xmm7
+; WIN32-NEXT:movaps %xmm5, %xmm6
+; WIN32-NEXT:movaps %xmm3, %xmm5
+; WIN32-NEXT:movaps %xmm2, %xmm3
+; WIN32-NEXT:movaps %xmm1, %xmm2
+; WIN32-NEXT:movaps %xmm0, %xmm1
+; WIN32-NEXT:addps %xmm4, %xmm0
+; WIN32-NEXT:mulps %xmm4, %xmm1
+; WIN32-NEXT:subps %xmm1, %xmm0
+; WIN32-NEXT:movups 8(%ebp), %xmm1
+; WIN32-NEXT:addps %xmm1, %xmm0
+; WIN32-NEXT:movaps %xmm2, %xmm4
+; WIN32-NEXT:addps %xmm6, %xmm4
+; WIN32-NEXT:mulps %xmm6, %xmm2
+; WIN32-NEXT:subps %xmm2, %xmm4
+; WIN32-NEXT:movups 24(%ebp), %xmm1
+; WIN32-NEXT:addps %xmm1, %xmm4
+; WIN32-NEXT:movaps %xmm3, %xmm2
+; WIN32-NEXT:addps %xmm7, %xmm2
+; WIN32-NEXT:mulps %xmm7, %xmm3
+; WIN32-NEXT:subps %xmm3, %xmm2
+; WIN32-NEXT:movups 40(%ebp), %xmm1
+; WIN32-NEXT:addps %xmm1, %xmm2
+; WIN32-NEXT:movaps %xmm5, %xmm3
+; WIN32-NEXT:movaps (%esp), %xmm1 # 16-byte Reload
+; WIN32-NEXT:addps %xmm1, %xmm3
+; WIN32-NEXT:mulps %xmm1, %xmm5
+; WIN32-NEXT:subps %xmm5, %xmm3
+; WIN32-NEXT:movups 56(%ebp), %xmm1
+; WIN32-NEXT:addps %xmm1, %xmm3
+; WIN32-NEXT:movaps %xmm4, %xmm1
+; WIN32-NEXT:movl %ebp, %esp
+; WIN32-NEXT:popl %ebp
+; WIN32-NEXT:retl
+;
+; WIN64-LABEL: testf32_inp:
+; WIN64:   # %bb.0:
+; WIN64-NEXT:subq $72, %rsp
+; WIN64-NEXT:movaps %xmm15, {{[-0-9]+}}(%r{{[sb]}}p) # 16-byte Spill
+; WIN64-NEXT:movaps %xmm14, {{[-0-9]+}}(%r{{[sb]}}p) # 16-byte Spill
+; WIN64-N

[PATCH] D155396: [Sema][ObjC] Invalidate BlockDecl with invalid return expr & its parent BlockExpr

2023-07-24 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/test/AST/ast-dump-recovery.m:24
+// CHECK-NEXT: | `-BlockDecl {{.*}} invalid
+int (^a)() = ^() {
+  return c;

hokein wrote:
> nit: it'd be nice to encode the github issue number to the testcase here, for 
> example (renaming the `a` to `gh63863` etc).
Will be fixed in the final commit!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155396

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


[PATCH] D155985: [clang][ASTDumper] Remove redundant dump of BlockDecl's ParmVarDecl

2023-07-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks for the fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155985

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


[PATCH] D155294: [Driver][RISCV] Find baremetal multilibs using YAML for GNU toolchain

2023-07-24 Thread Joseph Faulls via Phabricator via cfe-commits
Joe updated this revision to Diff 543440.
Joe added a comment.

Add default ABI to multilib flags if none supplied


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

https://reviews.llvm.org/D155294

Files:
  clang/include/clang/Driver/ToolChain.h
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32i/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32i/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32iac/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32iac/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32im/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32im/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imac/ilp32/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imac/ilp32/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imafc/ilp32f/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imafc/ilp32f/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imac/lp64/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imac/lp64/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imafdc/lp64d/crtbegin.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv64imafdc/lp64d/crtend.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/riscv64-unknown-elf/bin/ld
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/riscv64-unknown-elf/lib/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/riscv64-unknown-elf/lib/multilib.yaml
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/riscv64-unknown-elf/lib/rv32i/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/riscv64-unknown-elf/lib/rv32iac/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/riscv64-unknown-elf/lib/rv32im/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/riscv64-unknown-elf/lib/rv32imac/ilp32/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/riscv64-unknown-elf/lib/rv32imafc/ilp32f/crt0.o
  
clang/test/Driver/Inputs/multilib_riscv_elf_sdk_yaml/riscv64-unknown-elf/lib/rv64imac/lp64/crt0.o
  clang/test/Driver/riscv-toolchain-multilib-yaml.c

Index: clang/test/Driver/riscv-toolchain-multilib-yaml.c
===
--- /dev/null
+++ clang/test/Driver/riscv-toolchain-multilib-yaml.c
@@ -0,0 +1,79 @@
+// UNSUPPORTED: system-windows
+// In this test, multilib resolution is resolved using a multilib.yaml
+// definition, in which multilibs are picked in accordance to matching abi /
+// marchs.
+
+// RUN: env "PATH=" %clang -### %s -fuse-ld=ld \
+// RUN:   --target=riscv32-unknown-elf --rtlib=platform --sysroot= \
+// RUN:   -march=rv32iac -mabi=ilp32\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk_yaml 2>&1 \
+// RUN:   | FileCheck -check-prefix=C-RV32IAC-BAREMETAL-MULTI-ILP32 %s
+
+// C-RV32IAC-BAREMETAL-MULTI-ILP32: "{{.*}}/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|}}..{{/|}}riscv64-unknown-elf/lib/rv32iac/ilp32{{/|}}crt0.o"
+// C-RV32IAC-BAREMETAL-MULTI-ILP32: "{{.*}}/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32iac/ilp32{{/|}}crtbegin.o"
+// C-RV32IAC-BAREMETAL-MULTI-ILP32: "{{.*}}/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32iac/ilp32{{/|}}crtend.o"
+
+// RUN: env "PATH=" %clang -### %s -fuse-ld=ld \
+// RUN:   --target=riscv32-unknown-elf --rtlib=platform --sysroot= \
+// RUN:   -march=rv32imafc -mabi=ilp32f\
+// RUN:   --gcc-toolchain=%S/Inputs/multilib_riscv_elf_sdk_yaml 2>&1 \
+// RUN:   | FileCheck -check-prefix=C-RV32IMAFC-BAREMETAL-MULTI-ILP32F %s
+
+// C-RV32IMAFC-BAREMETAL-MULTI-ILP32F: "{{.*}}/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/../../..{{/|}}..{{/|}}riscv64-unknown-elf/lib/rv32imafc/ilp32f{{/|}}crt0.o"
+// C-RV32IMAFC-BAREMETAL-MULTI-ILP32F: "{{.*}}/Inputs/multilib_riscv_elf_sdk_yaml/lib/gcc/riscv64-unknown-elf/8.2.0/rv32imafc/ilp

[PATCH] D155984: [Sema][ObjC] Invalidate BlockDecl with invalid ParmVarDecl

2023-07-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

thanks, the fix looks reasonable to me




Comment at: clang/test/AST/ast-dump-recovery.m:22
+// CHECK-NEXT:   `-BlockDecl {{.*}} invalid
+int (^a)(int, int) = ^(int, undefine b) {
+   return 1;

nit: a => `gh64005`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155984

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


[clang] 587b8f3 - [NFC][analyzer] Enable implicit destructor for cfg-lifetime tests

2023-07-24 Thread Tomasz Kamiński via cfe-commits

Author: Tomasz Kamiński
Date: 2023-07-24T11:50:20+02:00
New Revision: 587b8f323d2db30928a2d9f54412aeead69b6cb7

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

LOG: [NFC][analyzer] Enable implicit destructor for cfg-lifetime tests

This enables `cfg-temporary-dtors`, `cfg-rich-constructors`, and
`cfg-implicit-dtors` (defaults for CSA) for CFGLifetime test,
making int consistent with `cfg-scopes` test.
Before the fixes implemented in https://reviews.llvm.org/D153273,
this flags were incompatible.

Reviewed By: xazax.hun

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

Added: 


Modified: 
clang/test/Analysis/lifetime-cfg-output.cpp

Removed: 




diff  --git a/clang/test/Analysis/lifetime-cfg-output.cpp 
b/clang/test/Analysis/lifetime-cfg-output.cpp
index f9015e0c00cec3..d8b8dc4a71d4ae 100644
--- a/clang/test/Analysis/lifetime-cfg-output.cpp
+++ b/clang/test/Analysis/lifetime-cfg-output.cpp
@@ -1,6 +1,13 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze 
-analyzer-checker=debug.DumpCFG -analyzer-config 
cfg-lifetime=true,cfg-temporary-dtors=false,cfg-rich-constructors=false 
-analyzer-config cfg-implicit-dtors=false %s > %t 2>&1
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze 
-analyzer-checker=debug.DumpCFG -analyzer-config cfg-lifetime=true %s > %t 2>&1
 // RUN: FileCheck --input-file=%t %s
 
+// FIXME Most of the cases in this file test only with the objects of type `A`,
+// that has a non-trivial destructor. The types with a trivial destructor
+// ends their lifetime when the underlying memory is released, i.e. they
+// are destroyed last, after all objects with non-trivial destructors.
+// Consequently, they are handled 
diff erently in code, and we should make 
+// sure that test cover also trivially destructible types.
+
 extern bool UV;
 class A {
 public:
@@ -58,19 +65,21 @@ class A {
 // CHECK:   [B2 (ENTRY)]
 // CHECK-NEXT:Succs (1): B1
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A)
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A)
 // CHECK-NEXT:2: A a;
 // CHECK-NEXT:3: a
 // CHECK-NEXT:4: [B1.3] (ImplicitCastExpr, NoOp, const A)
 // CHECK-NEXT:5: const A &b = a;
-// CHECK-NEXT:6: A() (CXXConstructExpr, A)
+// CHECK-NEXT:6: A() (CXXConstructExpr, [B1.9], A)
 // CHECK-NEXT:7: [B1.6] (BindTemporary)
 // CHECK-NEXT:8: [B1.7] (ImplicitCastExpr, NoOp, const A)
 // CHECK-NEXT:9: [B1.8]
 // CHECK-NEXT:   10: const A &c = A();
-// CHECK-NEXT:   11: [B1.10] (Lifetime ends)
-// CHECK-NEXT:   12: [B1.2] (Lifetime ends)
-// CHECK-NEXT:   13: [B1.5] (Lifetime ends)
+// CHECK-NEXT:   11: [B1.10].~A() (Implicit destructor)
+// CHECK-NEXT:   12: [B1.10] (Lifetime ends)
+// CHECK-NEXT:   13: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   14: [B1.2] (Lifetime ends)
+// CHECK-NEXT:   15: [B1.5] (Lifetime ends)
 // CHECK-NEXT:Preds (1): B2
 // CHECK-NEXT:Succs (1): B0
 // CHECK:   [B0 (EXIT)]
@@ -84,14 +93,15 @@ void test_const_ref() {
 // CHECK:  [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A[2])
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A[2])
 // CHECK-NEXT:2: A a[2];
-// CHECK-NEXT:3:  (CXXConstructExpr, A[0])
+// CHECK-NEXT:3:  (CXXConstructExpr, [B1.4], A[0])
 // CHECK-NEXT:4: A b[0];
+// CHECK-NEXT:5: [B1.2].~A[2]() (Implicit destructor)
 // lifetime of a ends when its destructors are run
-// CHECK-NEXT:5: [B1.2] (Lifetime ends)
+// CHECK-NEXT:6: [B1.2] (Lifetime ends)
 // lifetime of b ends when its storage duration ends
-// CHECK-NEXT:6: [B1.4] (Lifetime ends)
+// CHECK-NEXT:7: [B1.4] (Lifetime ends)
 // CHECK-NEXT:Preds (1): B2
 // CHECK-NEXT:Succs (1): B0
 // CHECK:  [B0 (EXIT)]
@@ -104,18 +114,22 @@ void test_array() {
 // CHECK:  [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A)
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A)
 // CHECK-NEXT:2: A a;
-// CHECK-NEXT:3:  (CXXConstructExpr, A)
+// CHECK-NEXT:3:  (CXXConstructExpr, [B1.4], A)
 // CHECK-NEXT:4: A c;
-// CHECK-NEXT:5:  (CXXConstructExpr, A)
+// CHECK-NEXT:5:  (CXXConstructExpr, [B1.6], A)
 // CHECK-NEXT:6: A d;
-// CHECK-NEXT:7: [B1.6] (Lifetime ends)
-// CHECK-NEXT:8: [B1.4] (Lifetime ends)
-// CHECK-NEXT:9:  (CXXConstructExpr, A)
-// CHECK-NEXT:   10: A b;
-// CHECK-NEXT:   11: [B1.10] (Lifetime ends)
-// CHECK-NEXT:   12: [B1.2] (Lifetime ends)
+// CHECK-NEXT:7: [B1.6].~A() (Implicit destructor)
+// CHECK-NEXT:8: [B1.6] (Lifetime ends)
+// CHECK-NEXT:9: [B1.4].~A() (Implicit destructor)
+// CHECK-NEXT:   10: [B1.4] (Lifetime ends)
+// CHECK-NEXT:   11:  (

[PATCH] D155694: [NFC][analyzer] Enable implicit destructor for cfg-lifetime tests

2023-07-24 Thread Tomasz Kamiński via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
tomasz-kaminski-sonarsource marked an inline comment as done.
Closed by commit rG587b8f323d2d: [NFC][analyzer] Enable implicit destructor for 
cfg-lifetime tests (authored by tomasz-kaminski-sonarsource).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155694

Files:
  clang/test/Analysis/lifetime-cfg-output.cpp

Index: clang/test/Analysis/lifetime-cfg-output.cpp
===
--- clang/test/Analysis/lifetime-cfg-output.cpp
+++ clang/test/Analysis/lifetime-cfg-output.cpp
@@ -1,6 +1,13 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-lifetime=true,cfg-temporary-dtors=false,cfg-rich-constructors=false -analyzer-config cfg-implicit-dtors=false %s > %t 2>&1
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -analyze -analyzer-checker=debug.DumpCFG -analyzer-config cfg-lifetime=true %s > %t 2>&1
 // RUN: FileCheck --input-file=%t %s
 
+// FIXME Most of the cases in this file test only with the objects of type `A`,
+// that has a non-trivial destructor. The types with a trivial destructor
+// ends their lifetime when the underlying memory is released, i.e. they
+// are destroyed last, after all objects with non-trivial destructors.
+// Consequently, they are handled differently in code, and we should make 
+// sure that test cover also trivially destructible types.
+
 extern bool UV;
 class A {
 public:
@@ -58,19 +65,21 @@
 // CHECK:   [B2 (ENTRY)]
 // CHECK-NEXT:Succs (1): B1
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A)
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A)
 // CHECK-NEXT:2: A a;
 // CHECK-NEXT:3: a
 // CHECK-NEXT:4: [B1.3] (ImplicitCastExpr, NoOp, const A)
 // CHECK-NEXT:5: const A &b = a;
-// CHECK-NEXT:6: A() (CXXConstructExpr, A)
+// CHECK-NEXT:6: A() (CXXConstructExpr, [B1.9], A)
 // CHECK-NEXT:7: [B1.6] (BindTemporary)
 // CHECK-NEXT:8: [B1.7] (ImplicitCastExpr, NoOp, const A)
 // CHECK-NEXT:9: [B1.8]
 // CHECK-NEXT:   10: const A &c = A();
-// CHECK-NEXT:   11: [B1.10] (Lifetime ends)
-// CHECK-NEXT:   12: [B1.2] (Lifetime ends)
-// CHECK-NEXT:   13: [B1.5] (Lifetime ends)
+// CHECK-NEXT:   11: [B1.10].~A() (Implicit destructor)
+// CHECK-NEXT:   12: [B1.10] (Lifetime ends)
+// CHECK-NEXT:   13: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   14: [B1.2] (Lifetime ends)
+// CHECK-NEXT:   15: [B1.5] (Lifetime ends)
 // CHECK-NEXT:Preds (1): B2
 // CHECK-NEXT:Succs (1): B0
 // CHECK:   [B0 (EXIT)]
@@ -84,14 +93,15 @@
 // CHECK:  [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A[2])
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A[2])
 // CHECK-NEXT:2: A a[2];
-// CHECK-NEXT:3:  (CXXConstructExpr, A[0])
+// CHECK-NEXT:3:  (CXXConstructExpr, [B1.4], A[0])
 // CHECK-NEXT:4: A b[0];
+// CHECK-NEXT:5: [B1.2].~A[2]() (Implicit destructor)
 // lifetime of a ends when its destructors are run
-// CHECK-NEXT:5: [B1.2] (Lifetime ends)
+// CHECK-NEXT:6: [B1.2] (Lifetime ends)
 // lifetime of b ends when its storage duration ends
-// CHECK-NEXT:6: [B1.4] (Lifetime ends)
+// CHECK-NEXT:7: [B1.4] (Lifetime ends)
 // CHECK-NEXT:Preds (1): B2
 // CHECK-NEXT:Succs (1): B0
 // CHECK:  [B0 (EXIT)]
@@ -104,18 +114,22 @@
 // CHECK:  [B2 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B1
 // CHECK:   [B1]
-// CHECK-NEXT:1:  (CXXConstructExpr, A)
+// CHECK-NEXT:1:  (CXXConstructExpr, [B1.2], A)
 // CHECK-NEXT:2: A a;
-// CHECK-NEXT:3:  (CXXConstructExpr, A)
+// CHECK-NEXT:3:  (CXXConstructExpr, [B1.4], A)
 // CHECK-NEXT:4: A c;
-// CHECK-NEXT:5:  (CXXConstructExpr, A)
+// CHECK-NEXT:5:  (CXXConstructExpr, [B1.6], A)
 // CHECK-NEXT:6: A d;
-// CHECK-NEXT:7: [B1.6] (Lifetime ends)
-// CHECK-NEXT:8: [B1.4] (Lifetime ends)
-// CHECK-NEXT:9:  (CXXConstructExpr, A)
-// CHECK-NEXT:   10: A b;
-// CHECK-NEXT:   11: [B1.10] (Lifetime ends)
-// CHECK-NEXT:   12: [B1.2] (Lifetime ends)
+// CHECK-NEXT:7: [B1.6].~A() (Implicit destructor)
+// CHECK-NEXT:8: [B1.6] (Lifetime ends)
+// CHECK-NEXT:9: [B1.4].~A() (Implicit destructor)
+// CHECK-NEXT:   10: [B1.4] (Lifetime ends)
+// CHECK-NEXT:   11:  (CXXConstructExpr, [B1.12], A)
+// CHECK-NEXT:   12: A b;
+// CHECK-NEXT:   13: [B1.12].~A() (Implicit destructor)
+// CHECK-NEXT:   14: [B1.12] (Lifetime ends)
+// CHECK-NEXT:   15: [B1.2].~A() (Implicit destructor)
+// CHECK-NEXT:   16: [B1.2] (Lifetime ends)
 // CHECK-NEXT:Preds (1): B2
 // CHECK-NEXT:Succs (1): B0
 // CHECK:  [B0 (EXIT)]
@@ -132,30 +146,34 @@
 // CHECK:  [B4 (ENTRY)]
 // CHECK-NEXT:   Succs (1): B3
 // CHECK:   [B1]
-

[PATCH] D155984: [Sema][ObjC] Invalidate BlockDecl with invalid ParmVarDecl

2023-07-24 Thread Ding Fei via Phabricator via cfe-commits
danix800 marked an inline comment as done.
danix800 added inline comments.



Comment at: clang/test/AST/ast-dump-recovery.m:22
+// CHECK-NEXT:   `-BlockDecl {{.*}} invalid
+int (^a)(int, int) = ^(int, undefine b) {
+   return 1;

hokein wrote:
> nit: a => `gh64005`
Will be fixed in the final commit!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155984

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


[PATCH] D155294: [Driver][RISCV] Find baremetal multilibs using YAML for GNU toolchain

2023-07-24 Thread Michael Platings via Phabricator via cfe-commits
michaelplatings added a comment.

> some nasty and repetitive regexes

Yes, it's the same for Arm architecture extensions. Petr & I went back and 
forth on this for a long time. See discussion here to understand Petr's 
concerns: https://discourse.llvm.org/t/rfc-multilib/67494/23


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

https://reviews.llvm.org/D155294

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


[PATCH] D155452: [Flang] Add support for fsave-optimization-record

2023-07-24 Thread Tom Eccles via Phabricator via cfe-commits
tblah accepted this revision.
tblah added a comment.
This revision is now accepted and ready to land.

This looks good to me. Thanks for your efforts on this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155452

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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Just a couple of NITs otherwise LGTM




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:2506
+
+  for (auto A : E->arguments())
+if (!getDerived().TraverseStmt(A))





Comment at: clang/lib/Sema/SemaDeclCXX.cpp:2546
   } Visitor(*this, FD);
-  Visitor.TraverseStmt(FD->getBody());
+  Visitor.TraverseDecl(const_cast(FD));
 }

Maybe it makes sense to drop `const` from `FD` parameter instead of doing a 
`const_cast`?



Comment at: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp:48
 
-struct InitWithLambda {
-int b = [](int error = undefined()) { // expected-error {{cannot take 
address of consteval function 'undefined' outside of an immediate invocation}}
+struct InitWithLambda { // expected-note {{'InitWithLambda' is an immediate 
constructor because the default initializer of 'b' contains a call to a 
consteval function 'undefined' and that call is not a constant expression}}
+int b = [](int error = undefined()) {  // expected-note {{undefined 
function 'undefined' cannot be used in a constant expression}}

Maybe it makes sense to print `InitWithLambda::InitWithLambda` so it looks same 
as "call to immediate function ... is not a constant expression" message and 
makes it more obvious.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

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


[PATCH] D156093: [ASTImporter] Add extra sorting round for keeping lexical order of all imported decls within record

2023-07-24 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added a project: clang.
Herald added a subscriber: martong.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

Revision https://reviews.llvm.org/D154764 is still not complete. An extra 
sorting is needed
for keeping lexical order of all imported decls within a record. The final 
algorithm could be
summarized as the following:

1. Import all fields that'll be part of the layout;
2. Sort these fields to ensure correct layout;
3. Import everything else;
4. Final sort for correct lexical order.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156093

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1462,10 +1462,10 @@
   MatchVerifier{}.match(To->getTranslationUnitDecl(), Pattern));
 }
 
-AST_MATCHER_P(RecordDecl, hasFieldOrder, std::vector, Order) {
+AST_MATCHER_P(RecordDecl, hasLexicalOrder, std::vector, Order) {
   size_t Index = 0;
   for (Decl *D : Node.decls()) {
-if (isa(D) || isa(D)) {
+if (isa(D) || isa(D) || !D->isImplicit()) {
   auto *ND = cast(D);
   if (Index == Order.size())
 return false;
@@ -1513,8 +1513,8 @@
   Lang_CXX11, "", Lang_CXX11);
 
   MatchVerifier Verifier;
-  ASSERT_TRUE(Verifier.match(From, cxxRecordDecl(hasFieldOrder({"a", "b"};
-  EXPECT_TRUE(Verifier.match(To, cxxRecordDecl(hasFieldOrder({"a", "b"};
+  ASSERT_TRUE(Verifier.match(From, cxxRecordDecl(hasLexicalOrder({"a", "b"};
+  EXPECT_TRUE(Verifier.match(To, cxxRecordDecl(hasLexicalOrder({"a", "b"};
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
@@ -1532,11 +1532,30 @@
   )s",
   Lang_CXX11, "", Lang_CXX11);
 
+  auto Pattern = cxxRecordDecl(hasLexicalOrder({"a", "b", "c"}));
   MatchVerifier Verifier;
-  ASSERT_TRUE(
-  Verifier.match(From, cxxRecordDecl(hasFieldOrder({"a", "b", "c"};
-  EXPECT_TRUE(
-  Verifier.match(To, cxxRecordDecl(hasFieldOrder({"a", "b", "c"};
+  ASSERT_TRUE(Verifier.match(From, Pattern));
+  EXPECT_TRUE(Verifier.match(To, Pattern));
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, CXXRecordDeclCorrectLexicalOrder) {
+  Decl *From, *To;
+  std::tie(From, To) = getImportedDecl(
+  R"s(
+  struct declToImport {
+  int a = c;
+  void g() { h(); }
+  int b = 1;
+  void h();
+  int c = 2;
+  };
+  )s",
+  Lang_CXX11, "", Lang_CXX11);
+
+  auto Pattern = cxxRecordDecl(hasLexicalOrder({"a", "g", "b", "h", "c"}));
+  MatchVerifier Verifier;
+  ASSERT_TRUE(Verifier.match(From, Pattern));
+  EXPECT_TRUE(Verifier.match(To, Pattern));
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase,
@@ -1557,11 +1576,17 @@
   )s",
   Lang_CXX11, "", Lang_CXX11);
 
+  auto Pattern = cxxRecordDecl(hasLexicalOrder({
+"a",
+"" /*anony union*/,
+"" /* implicit field */,
+"b" /* indirect */,
+"c" /* indirect */,
+"d"
+  }));
   MatchVerifier Verifier;
-  ASSERT_TRUE(Verifier.match(
-  From, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"};
-  EXPECT_TRUE(Verifier.match(
-  To, cxxRecordDecl(hasFieldOrder({"a", "", "b", "c", "d"};
+  ASSERT_TRUE(Verifier.match(From, Pattern));
+  EXPECT_TRUE(Verifier.match(To, Pattern));
 }
 
 TEST_P(ASTImporterOptionSpecificTestBase, ShouldImportImplicitCXXRecordDecl) {
@@ -3007,7 +3032,7 @@
  "  int a = 5;"
  "};",
  Lang_CXX11, "", Lang_CXX11, Verifier,
- recordDecl(hasFieldOrder({"b", "a"})));
+ recordDecl(hasLexicalOrder({"b", "a"})));
 }
 
 const internal::VariadicDynCastAllOfMatcher
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -1942,6 +1942,16 @@
 ImportedOrErr.takeError());
   }
 
+  // Final round to re-order everything
+  for (auto *D : FromDC->decls()) {
+assert(D && "DC contains a null decl");
+if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D); ToD &&
+ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD)) {
+  ToDC->removeDecl(ToD);
+  ToDC->addDeclInternal(ToD);
+}
+  }
+
   return ChildErrors;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 106bde9 - [Sema][ObjC] Invalidate BlockDecl with invalid return expr & its parent BlockExpr

2023-07-24 Thread via cfe-commits

Author: dingfei
Date: 2023-07-24T18:24:32+08:00
New Revision: 106bde9ab2bdffb2409311ef2d4f2c3c9ca77d3f

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

LOG: [Sema][ObjC] Invalidate BlockDecl with invalid return expr & its parent 
BlockExpr

Invalidate BlockDecl with implicit return type, in case any of the return value 
exprs is invalid.
Propagating the error info up by replacing BlockExpr with a RecoveryExpr.

The idea of this fix is given by @hokein(Haojian Wu)

Fix https://github.com/llvm/llvm-project/issues/63863.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/AST/ast-dump-recovery.m

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8e19b3695ef49e..e686e83583919f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -670,6 +670,10 @@ Bug Fixes in This Version
 - Correcly diagnose jumps into statement expressions.
   This ensures the behavior of Clang is consistent with GCC.
   (`#63682 `_)
+- Invalidate BlockDecl with implicit return type, in case any of the return
+  value exprs is invalid. Propagating the error info up by replacing BlockExpr
+  with a RecoveryExpr. This fixes:
+  (`#63863 _`)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 240f1520efad2b..3c9d0efca8a1ee 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17159,6 +17159,9 @@ ExprResult Sema::ActOnBlockStmtExpr(SourceLocation 
CaretLoc,
   if (getCurFunction())
 getCurFunction()->addBlock(BD);
 
+  if (BD->isInvalidDecl())
+return CreateRecoveryExpr(Result->getBeginLoc(), Result->getEndLoc(),
+  {Result}, Result->getType());
   return Result;
 }
 

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 5657771a145189..70a549938d080d 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3730,6 +3730,11 @@ StmtResult Sema::ActOnCapScopeReturnStmt(SourceLocation 
ReturnLoc,
   if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
 
+  if (auto *CurBlock = dyn_cast(CurCap);
+  CurBlock && CurCap->HasImplicitReturnType && RetValExp &&
+  RetValExp->containsErrors())
+CurBlock->TheDecl->setInvalidDecl();
+
   return Result;
 }
 

diff  --git a/clang/test/AST/ast-dump-recovery.m 
b/clang/test/AST/ast-dump-recovery.m
index 5ca866a0282fdf..c2bd078959aba1 100644
--- a/clang/test/AST/ast-dump-recovery.m
+++ b/clang/test/AST/ast-dump-recovery.m
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -frecovery-ast 
-frecovery-ast-type -ast-dump %s | FileCheck -strict-whitespace %s
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -frecovery-ast 
-frecovery-ast-type -fblocks -ast-dump %s | FileCheck -strict-whitespace %s
 
 @interface Foo
 - (void)method:(int)n;
@@ -16,3 +16,11 @@ void k(Foo *foo) {
   // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'foo'
   foo.undef;
 }
+
+// CHECK:  |-VarDecl {{.*}} 'int (^)()' cinit
+// CHECK-NEXT: | `-RecoveryExpr {{.*}} ' (^)(void)' 
contains-errors lvalue
+// CHECK-NEXT: |   `-BlockExpr {{.*}} ' (^)(void)'
+// CHECK-NEXT: | `-BlockDecl {{.*}} invalid
+int (^gh63863)() = ^() {
+  return undef;
+};



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


[PATCH] D155396: [Sema][ObjC] Invalidate BlockDecl with invalid return expr & its parent BlockExpr

2023-07-24 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG106bde9ab2bd: [Sema][ObjC] Invalidate BlockDecl with invalid 
return expr & its parent… (authored by dingfei ).

Changed prior to commit:
  https://reviews.llvm.org/D155396?vs=543010&id=543447#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155396

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/AST/ast-dump-recovery.m


Index: clang/test/AST/ast-dump-recovery.m
===
--- clang/test/AST/ast-dump-recovery.m
+++ clang/test/AST/ast-dump-recovery.m
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -frecovery-ast 
-frecovery-ast-type -ast-dump %s | FileCheck -strict-whitespace %s
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -frecovery-ast 
-frecovery-ast-type -fblocks -ast-dump %s | FileCheck -strict-whitespace %s
 
 @interface Foo
 - (void)method:(int)n;
@@ -16,3 +16,11 @@
   // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'foo'
   foo.undef;
 }
+
+// CHECK:  |-VarDecl {{.*}} 'int (^)()' cinit
+// CHECK-NEXT: | `-RecoveryExpr {{.*}} ' (^)(void)' 
contains-errors lvalue
+// CHECK-NEXT: |   `-BlockExpr {{.*}} ' (^)(void)'
+// CHECK-NEXT: | `-BlockDecl {{.*}} invalid
+int (^gh63863)() = ^() {
+  return undef;
+};
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3730,6 +3730,11 @@
   if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
 
+  if (auto *CurBlock = dyn_cast(CurCap);
+  CurBlock && CurCap->HasImplicitReturnType && RetValExp &&
+  RetValExp->containsErrors())
+CurBlock->TheDecl->setInvalidDecl();
+
   return Result;
 }
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17159,6 +17159,9 @@
   if (getCurFunction())
 getCurFunction()->addBlock(BD);
 
+  if (BD->isInvalidDecl())
+return CreateRecoveryExpr(Result->getBeginLoc(), Result->getEndLoc(),
+  {Result}, Result->getType());
   return Result;
 }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -670,6 +670,10 @@
 - Correcly diagnose jumps into statement expressions.
   This ensures the behavior of Clang is consistent with GCC.
   (`#63682 `_)
+- Invalidate BlockDecl with implicit return type, in case any of the return
+  value exprs is invalid. Propagating the error info up by replacing BlockExpr
+  with a RecoveryExpr. This fixes:
+  (`#63863 _`)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/AST/ast-dump-recovery.m
===
--- clang/test/AST/ast-dump-recovery.m
+++ clang/test/AST/ast-dump-recovery.m
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -ast-dump %s | FileCheck -strict-whitespace %s
+// RUN: not %clang_cc1 -triple x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -fblocks -ast-dump %s | FileCheck -strict-whitespace %s
 
 @interface Foo
 - (void)method:(int)n;
@@ -16,3 +16,11 @@
   // CHECK-NEXT:   `-DeclRefExpr {{.*}} 'foo'
   foo.undef;
 }
+
+// CHECK:  |-VarDecl {{.*}} 'int (^)()' cinit
+// CHECK-NEXT: | `-RecoveryExpr {{.*}} ' (^)(void)' contains-errors lvalue
+// CHECK-NEXT: |   `-BlockExpr {{.*}} ' (^)(void)'
+// CHECK-NEXT: | `-BlockDecl {{.*}} invalid
+int (^gh63863)() = ^() {
+  return undef;
+};
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3730,6 +3730,11 @@
   if (FunctionScopes.back()->FirstReturnLoc.isInvalid())
 FunctionScopes.back()->FirstReturnLoc = ReturnLoc;
 
+  if (auto *CurBlock = dyn_cast(CurCap);
+  CurBlock && CurCap->HasImplicitReturnType && RetValExp &&
+  RetValExp->containsErrors())
+CurBlock->TheDecl->setInvalidDecl();
+
   return Result;
 }
 
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -17159,6 +17159,9 @@
   if (getCurFunction())
 getCurFunction()->addBlock(BD);
 
+  if (BD->isInvalidDecl())
+return CreateRecoveryExpr(Result->getBeginLoc(), Result->getEndLoc(),
+  {Result}, Resul

[PATCH] D152246: [clang][ThreadSafety] Analyze known function pointer values

2023-07-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D152246

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


[PATCH] D152504: [clang][ThreadSafety] Analyze cleanup functions

2023-07-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


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

https://reviews.llvm.org/D152504

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


[PATCH] D155393: [clang][Interp] Implement __builtin_isfpclass

2023-07-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155393

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


[PATCH] D155394: [clang][Interp] Implement __builtin_fpclassify

2023-07-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155394

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


[PATCH] D155430: [clang][Interp] Implement __arithmethic_fence for floating types

2023-07-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155430

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


[clang] 3cb16f6 - [Sema][ObjC] Invalidate BlockDecl with invalid ParmVarDecl

2023-07-24 Thread via cfe-commits

Author: dingfei
Date: 2023-07-24T18:32:46+08:00
New Revision: 3cb16f6d2ddd030c35df7ad3eb7985f1947173cb

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

LOG: [Sema][ObjC] Invalidate BlockDecl with invalid ParmVarDecl

BlockDecl should be invalidated because of its invalid ParmVarDecl.

Fixes #1 of https://github.com/llvm/llvm-project/issues/64005

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/AST/ast-dump-recovery.m

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e686e83583919f..5d09c454dea290 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -674,6 +674,8 @@ Bug Fixes in This Version
   value exprs is invalid. Propagating the error info up by replacing BlockExpr
   with a RecoveryExpr. This fixes:
   (`#63863 _`)
+- Invalidate BlockDecl with invalid ParmVarDecl
+  (`#64005 _`)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3c9d0efca8a1ee..716383412cc58c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -16959,6 +16959,9 @@ void Sema::ActOnBlockArguments(SourceLocation CaretLoc, 
Declarator &ParamInfo,
 
   PushOnScopeChains(AI, CurBlock->TheScope);
 }
+
+if (AI->isInvalidDecl())
+  CurBlock->TheDecl->setInvalidDecl();
   }
 }
 

diff  --git a/clang/test/AST/ast-dump-recovery.m 
b/clang/test/AST/ast-dump-recovery.m
index c2bd078959aba1..37fa8045c0b941 100644
--- a/clang/test/AST/ast-dump-recovery.m
+++ b/clang/test/AST/ast-dump-recovery.m
@@ -24,3 +24,9 @@ void k(Foo *foo) {
 int (^gh63863)() = ^() {
   return undef;
 };
+
+// CHECK:  `-BlockExpr {{.*}} 'int (^)(int, int)'
+// CHECK-NEXT:   `-BlockDecl {{.*}} invalid
+int (^gh64005)(int, int) = ^(int, undefined b) {
+   return 1;
+};



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


[PATCH] D155984: [Sema][ObjC] Invalidate BlockDecl with invalid ParmVarDecl

2023-07-24 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3cb16f6d2ddd: [Sema][ObjC] Invalidate BlockDecl with invalid 
ParmVarDecl (authored by dingfei ).

Changed prior to commit:
  https://reviews.llvm.org/D155984?vs=543005&id=543451#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155984

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/ast-dump-recovery.m


Index: clang/test/AST/ast-dump-recovery.m
===
--- clang/test/AST/ast-dump-recovery.m
+++ clang/test/AST/ast-dump-recovery.m
@@ -24,3 +24,9 @@
 int (^gh63863)() = ^() {
   return undef;
 };
+
+// CHECK:  `-BlockExpr {{.*}} 'int (^)(int, int)'
+// CHECK-NEXT:   `-BlockDecl {{.*}} invalid
+int (^gh64005)(int, int) = ^(int, undefined b) {
+   return 1;
+};
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16959,6 +16959,9 @@
 
   PushOnScopeChains(AI, CurBlock->TheScope);
 }
+
+if (AI->isInvalidDecl())
+  CurBlock->TheDecl->setInvalidDecl();
   }
 }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -674,6 +674,8 @@
   value exprs is invalid. Propagating the error info up by replacing BlockExpr
   with a RecoveryExpr. This fixes:
   (`#63863 _`)
+- Invalidate BlockDecl with invalid ParmVarDecl
+  (`#64005 _`)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/AST/ast-dump-recovery.m
===
--- clang/test/AST/ast-dump-recovery.m
+++ clang/test/AST/ast-dump-recovery.m
@@ -24,3 +24,9 @@
 int (^gh63863)() = ^() {
   return undef;
 };
+
+// CHECK:  `-BlockExpr {{.*}} 'int (^)(int, int)'
+// CHECK-NEXT:   `-BlockDecl {{.*}} invalid
+int (^gh64005)(int, int) = ^(int, undefined b) {
+   return 1;
+};
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -16959,6 +16959,9 @@
 
   PushOnScopeChains(AI, CurBlock->TheScope);
 }
+
+if (AI->isInvalidDecl())
+  CurBlock->TheDecl->setInvalidDecl();
   }
 }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -674,6 +674,8 @@
   value exprs is invalid. Propagating the error info up by replacing BlockExpr
   with a RecoveryExpr. This fixes:
   (`#63863 _`)
+- Invalidate BlockDecl with invalid ParmVarDecl
+  (`#64005 _`)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4b15bb9 - [clang][ASTDumper] Remove redundant dump of BlockDecl's ParmVarDecl

2023-07-24 Thread via cfe-commits

Author: dingfei
Date: 2023-07-24T18:42:26+08:00
New Revision: 4b15bb9a317edcf6a3ad95ddaa4a843afe700261

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

LOG: [clang][ASTDumper] Remove redundant dump of BlockDecl's ParmVarDecl

ParmVarDecl of BlockDecl is unnecessarily dumped twice.
Remove this duplication as other FunctionDecls.

Fixes https://github.com/llvm/llvm-project/issues/64005 (#2)

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/ASTNodeTraverser.h
clang/test/AST/ast-dump-decl-json.m
clang/test/AST/ast-dump-decl.m

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5d09c454dea290..4e60efa1c025ed 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -674,7 +674,8 @@ Bug Fixes in This Version
   value exprs is invalid. Propagating the error info up by replacing BlockExpr
   with a RecoveryExpr. This fixes:
   (`#63863 _`)
-- Invalidate BlockDecl with invalid ParmVarDecl
+- Invalidate BlockDecl with invalid ParmVarDecl. Remove redundant dump of
+  BlockDecl's ParmVarDecl
   (`#64005 _`)
 
 Bug Fixes to Compiler Builtins

diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index 35efb81bb522ed..d649ef6816ca42 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -104,7 +104,8 @@ class ASTNodeTraverser
 Visit(Comment, Comment);
 
   // Decls within functions are visited by the body.
-  if (!isa(*D) && !isa(*D)) {
+  if (!isa(*D) && !isa(*D) &&
+  !isa(*D)) {
 if (Traversal != TK_AsIs) {
   if (const auto *CTSD = dyn_cast(D)) 
{
 auto SK = CTSD->getSpecializationKind();

diff  --git a/clang/test/AST/ast-dump-decl-json.m 
b/clang/test/AST/ast-dump-decl-json.m
index 18450c9f82026f..9d82c6696cb524 100644
--- a/clang/test/AST/ast-dump-decl-json.m
+++ b/clang/test/AST/ast-dump-decl-json.m
@@ -1924,31 +1924,6 @@ void f(void) {
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
 // CHECK-NEXT:]
-// CHECK-NEXT:   },
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "ParmVarDecl",
-// CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
-// CHECK-NEXT: "col": 9,
-// CHECK-NEXT: "tokLen": 1
-// CHECK-NEXT:},
-// CHECK-NEXT:"range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 5,
-// CHECK-NEXT:  "tokLen": 3
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 9,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: }
-// CHECK-NEXT:},
-// CHECK-NEXT:"name": "y",
-// CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": "int"
-// CHECK-NEXT:}
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }

diff  --git a/clang/test/AST/ast-dump-decl.m b/clang/test/AST/ast-dump-decl.m
index 1157c99e459749..0b259d522645dc 100644
--- a/clang/test/AST/ast-dump-decl.m
+++ b/clang/test/AST/ast-dump-decl.m
@@ -142,12 +142,17 @@ @implementation TestObjCProperty {
 
 void TestBlockDecl(int x) {
   ^(int y, ...){ x; };
+  int z;
 }
 // CHECK:  FunctionDecl{{.*}}TestBlockDecl
 // CHECK:  BlockDecl {{.+}}  col:3 variadic
 // CHECK-NEXT:   ParmVarDecl{{.*}} y 'int'
 // CHECK-NEXT:   capture ParmVar{{.*}} 'x' 'int'
 // CHECK-NEXT:   CompoundStmt
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-NEXT:   DeclRefExpr{{.*}} 'x'
+// CHECK-NEXT: DeclStmt
+// CHECK-NEXT:   VarDecl{{.*}} z
 
 @interface B
 + (int) foo;



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


[PATCH] D155985: [clang][ASTDumper] Remove redundant dump of BlockDecl's ParmVarDecl

2023-07-24 Thread Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4b15bb9a317e: [clang][ASTDumper] Remove redundant dump of 
BlockDecl's ParmVarDecl (authored by dingfei ).

Changed prior to commit:
  https://reviews.llvm.org/D155985?vs=543003&id=543453#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155985

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/test/AST/ast-dump-decl-json.m
  clang/test/AST/ast-dump-decl.m


Index: clang/test/AST/ast-dump-decl.m
===
--- clang/test/AST/ast-dump-decl.m
+++ clang/test/AST/ast-dump-decl.m
@@ -142,12 +142,17 @@
 
 void TestBlockDecl(int x) {
   ^(int y, ...){ x; };
+  int z;
 }
 // CHECK:  FunctionDecl{{.*}}TestBlockDecl
 // CHECK:  BlockDecl {{.+}}  col:3 variadic
 // CHECK-NEXT:   ParmVarDecl{{.*}} y 'int'
 // CHECK-NEXT:   capture ParmVar{{.*}} 'x' 'int'
 // CHECK-NEXT:   CompoundStmt
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-NEXT:   DeclRefExpr{{.*}} 'x'
+// CHECK-NEXT: DeclStmt
+// CHECK-NEXT:   VarDecl{{.*}} z
 
 @interface B
 + (int) foo;
Index: clang/test/AST/ast-dump-decl-json.m
===
--- clang/test/AST/ast-dump-decl-json.m
+++ clang/test/AST/ast-dump-decl-json.m
@@ -1924,31 +1924,6 @@
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
 // CHECK-NEXT:]
-// CHECK-NEXT:   },
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "ParmVarDecl",
-// CHECK-NEXT:"loc": {
-// CHECK-NEXT: "offset": {{[0-9]+}},
-// CHECK-NEXT: "col": 9,
-// CHECK-NEXT: "tokLen": 1
-// CHECK-NEXT:},
-// CHECK-NEXT:"range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 5,
-// CHECK-NEXT:  "tokLen": 3
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT:  "offset": {{[0-9]+}},
-// CHECK-NEXT:  "col": 9,
-// CHECK-NEXT:  "tokLen": 1
-// CHECK-NEXT: }
-// CHECK-NEXT:},
-// CHECK-NEXT:"name": "y",
-// CHECK-NEXT:"type": {
-// CHECK-NEXT: "qualType": "int"
-// CHECK-NEXT:}
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
Index: clang/include/clang/AST/ASTNodeTraverser.h
===
--- clang/include/clang/AST/ASTNodeTraverser.h
+++ clang/include/clang/AST/ASTNodeTraverser.h
@@ -104,7 +104,8 @@
 Visit(Comment, Comment);
 
   // Decls within functions are visited by the body.
-  if (!isa(*D) && !isa(*D)) {
+  if (!isa(*D) && !isa(*D) &&
+  !isa(*D)) {
 if (Traversal != TK_AsIs) {
   if (const auto *CTSD = dyn_cast(D)) 
{
 auto SK = CTSD->getSpecializationKind();
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -674,7 +674,8 @@
   value exprs is invalid. Propagating the error info up by replacing BlockExpr
   with a RecoveryExpr. This fixes:
   (`#63863 _`)
-- Invalidate BlockDecl with invalid ParmVarDecl
+- Invalidate BlockDecl with invalid ParmVarDecl. Remove redundant dump of
+  BlockDecl's ParmVarDecl
   (`#64005 _`)
 
 Bug Fixes to Compiler Builtins


Index: clang/test/AST/ast-dump-decl.m
===
--- clang/test/AST/ast-dump-decl.m
+++ clang/test/AST/ast-dump-decl.m
@@ -142,12 +142,17 @@
 
 void TestBlockDecl(int x) {
   ^(int y, ...){ x; };
+  int z;
 }
 // CHECK:  FunctionDecl{{.*}}TestBlockDecl
 // CHECK:  BlockDecl {{.+}}  col:3 variadic
 // CHECK-NEXT:   ParmVarDecl{{.*}} y 'int'
 // CHECK-NEXT:   capture ParmVar{{.*}} 'x' 'int'
 // CHECK-NEXT:   CompoundStmt
+// CHECK-NEXT: ImplicitCastExpr
+// CHECK-NEXT:   DeclRefExpr{{.*}} 'x'
+// CHECK-NEXT: DeclStmt
+// CHECK-NEXT:   VarDecl{{.*}} z
 
 @interface B
 + (int) foo;
Index: clang/test/AST/ast-dump-decl-json.m
===
--- clang/test/AST/ast-dump-decl-json.m
+++ clang/test/AST/ast-dump-decl-json.m
@@ -1924,31 +1924,6 @@
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
 // CHECK-NEXT:]
-// CHECK-NEXT:   },
-// CHECK-NEXT:   {
-// CHECK-NEXT:"id": "0x{{.*}}",
-// CHECK-NEXT:"kind": "ParmVarDecl",
-// CHECK-NEXT:"loc": {
-//

[clang] 239ad4f - [OPENMP][NFC] Editing OpenMP support page

2023-07-24 Thread Sandeep Kosuri via cfe-commits

Author: Sandeep Kosuri
Date: 2023-07-24T05:43:07-05:00
New Revision: 239ad4fde8805ad8d48babff633230313e051e36

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

LOG: [OPENMP][NFC] Editing OpenMP support page

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 989c665db3bce2..6d31269d3abfa3 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -170,7 +170,7 @@ implementation.
 
+--+--+--+---+
 | device   | infer target functions from initializers  
   | :part:`worked on`| 
  |
 
+--+--+--+---+
-| device   | infer target variables from initializers  
   | :part:`worked on`| 
  |
+| device   | infer target variables from initializers  
   | :part:`done` | D146418 
|
 
+--+--+--+---+
 | device   | OMP_TARGET_OFFLOAD environment variable   
   | :good:`done` | D50522  
  |
 
+--+--+--+---+



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


[PATCH] D155452: [Flang] Add support for fsave-optimization-record

2023-07-24 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

Thanks for working on this, LG! I've left a few minor comments inline.




Comment at: clang/include/clang/Driver/Options.td:6449-6455
+def opt_record_file : Separate<["-"], "opt-record-file">, Flags<[FC1Option, 
CC1Option]>,
+  HelpText<"File name to use for YAML optimization record output">,
+  MarshallingInfoString>;
+def opt_record_passes : Separate<["-"], "opt-record-passes">, 
Flags<[FC1Option, CC1Option]>,
+  HelpText<"Only record remark information for passes whose names match the 
given regular expression">;
+def opt_record_format : Separate<["-"], "opt-record-format">, 
Flags<[FC1Option, CC1Option]>,
+  HelpText<"The format used for serializing remarks (default: YAML)">;

Currently, these options have the following flags set:
*  `CC1Option` and `NoDriverOption`.
See:
* 
https://github.com/llvm/llvm-project/blob/5da317a79e3e53f17c6d356361807df1d16a0b66/clang/include/clang/Driver/Options.td#L6156

IIUC, you'd like this to be CC1Option` and `NoDriverOption` _and_ `FC1Option`. 
You can do that by moving these definitions here:
* 
https://github.com/llvm/llvm-project/blob/5da317a79e3e53f17c6d356361807df1d16a0b66/clang/include/clang/Driver/Options.td#L6810-L6835



Comment at: flang/lib/Frontend/CompilerInvocation.cpp:195-197
+  args.getLastArg(clang::driver::options::OPT_opt_record_file)) {
+opts.OptRecordFile = a->getValue();
+  }

Drop braces: 
https://llvm.org/docs/CodingStandards.html#don-t-use-braces-on-simple-single-statement-bodies-of-if-else-loop-statements.
 Same for the other options below.

Btw, I'd be OK with moving this to a dedicated hook for parsing e.g. "opt 
remark options". 



Comment at: flang/lib/Frontend/FrontendActions.cpp:961-965
+  clang::DiagnosticsEngine &diags = ci.getDiagnostics();
+  const CodeGenOptions &codeGenOpts = ci.getInvocation().getCodeGenOpts();
+  Fortran::lower::LoweringOptions &loweringOpts =
+  ci.getInvocation().getLoweringOpts();
+

victorkingi wrote:
> Thought this refactoring might help making the function clearer. Let me know 
> if its unnecessary
It's a nice clean-up!

I'd move it to a separate patch, but the noise level is low, so I am not too 
concerned. 



Comment at: flang/test/Driver/frontend-forwarding.f90:26
 
+! RUN: %flang -### %s 2>&1 \
+! RUN: -foptimization-record-file=%t.opt.yaml \

Is a dedicated driver invocation needed for this test?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155452

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


[clang] 77ac634 - Fix the Clang sphinx build

2023-07-24 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-07-24T07:32:48-04:00
New Revision: 77ac634c64ec75b461139a730b23e6a9c26ae1dc

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

LOG: Fix the Clang sphinx build

This addresses issues found by:
https://lab.llvm.org/buildbot/#/builders/92/builds/47783

Added: 


Modified: 
clang/docs/OpenMPSupport.rst

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 6d31269d3abfa3..6e2c9c31c4bc7d 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -170,7 +170,7 @@ implementation.
 
+--+--+--+---+
 | device   | infer target functions from initializers  
   | :part:`worked on`| 
  |
 
+--+--+--+---+
-| device   | infer target variables from initializers  
   | :part:`done` | D146418 
|
+| device   | infer target variables from initializers  
   | :part:`done` | D146418 
  |
 
+--+--+--+---+
 | device   | OMP_TARGET_OFFLOAD environment variable   
   | :good:`done` | D50522  
  |
 
+--+--+--+---+



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


[PATCH] D144829: [BPF] Add a few new insns under cpu=v4

2023-07-24 Thread Eduard Zingerman via Phabricator via cfe-commits
eddyz87 added a comment.

Hi Yonghong,

Thank you for the comments.
Could you please also add a few tests for `gotol`?
Sorry, I should have asked for those last week.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144829

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


[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 543472.
cor3ntin added a comment.

- Use -fconstexpr-steps to limit the size of the array.
- Aply the logic to both constant evaluation and constant folding as is 
constant evaluation fail the limit can now be increased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp

Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
@@ -0,0 +1,82 @@
+// RUN: %clang_cc1 -std=c++2a -verify -fconstexpr-steps=1024 %s
+
+namespace std {
+  using size_t = decltype(sizeof(0));
+}
+
+void *operator new(std::size_t, void *p) { return p; }
+
+namespace std {
+  template struct allocator {
+constexpr T *allocate(size_t N) {
+  return (T*)operator new(sizeof(T) * N); // #alloc
+}
+constexpr void deallocate(void *p) {
+  operator delete(p);
+}
+  };
+  template
+  constexpr void construct_at(void *p, Args &&...args) { // #construct
+new (p) T((Args&&)args...);
+  }
+}
+
+namespace GH63562 {
+
+template 
+struct S {
+constexpr S(unsigned long long N)
+: data(nullptr){
+data = alloc.allocate(N);  // #call
+for(std::size_t i = 0; i < N; i ++)
+std::construct_at(data + i, i); // #construct_call
+
+}
+constexpr ~S() {
+alloc.deallocate(data);
+}
+std::allocator alloc;
+T* data;
+};
+
+constexpr S s(109951162); // expected-error {{constexpr variable 's' must be initialized by a constant expression}} \
+   // expected-note@#call {{in call to 'this->alloc.allocate(109951162)'}} \
+   // expected-note@#alloc {{cannot allocate array; evaluated array bound 109951162 is too large}} \
+   // expected-note {{in call to 'S(109951162)'}}
+// Check that we do not try to fold very large arrays
+S s2(109951162);
+S s3(~0ULL);
+
+// We can allocate this array but we hikt the number of steps
+constexpr S s4(1024); // expected-error {{constexpr variable 's4' must be initialized by a constant expression}} \
+   // expected-note@#construct {{constexpr evaluation hit maximum step limit; possible infinite loop?}} \
+   // expected-note@#construct_call {{in call}} \
+   // expected-note {{in call}}
+
+
+
+constexpr S s5(1025); // expected-error{{constexpr variable 's5' must be initialized by a constant expression}} \
+   // expected-note@#alloc {{cannot allocate array; evaluated array bound 1025 exceeds the limit (1024); use -fconstexpr-steps=1025 to increase this limit}} \
+   // expected-note@#call {{in call to 'this->alloc.allocate(1025)'}} \
+   // expected-note {{in call}}
+
+
+// Check we do not perform constant initialization in the presence
+// of very large arrays (this used to crash)
+
+template 
+constexpr int stack_array() {
+[[maybe_unused]] char BIG[N] = {0};  // expected-note  {{cannot allocate array; evaluated array bound 1025 exceeds the limit (1024); use -fconstexpr-steps=1025 to increase this limit}}
+return BIG[N-1];
+}
+
+int a = stack_array<~0U>();
+int c = stack_array<1024>();
+int d = stack_array<1025>();
+constexpr int e = stack_array<1024>();
+constexpr int f = stack_array<1025>(); // expected-error {{constexpr variable 'f' must be initialized by a constant expression}} \
+   //  expected-note {{in call}}
+
+
+
+}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -175,6 +175,11 @@
   return TotalSize.getActiveBits();
 }
 
+unsigned
+ConstantArrayType::getNumAddressingBits(const ASTContext &Context) const {
+  return getNumAddressingBits(Context, getElementType(), getSize());
+}
+
 unsigned ConstantArrayType::getMaxSizeBits(const ASTContext &Context) {
   unsigned Bits = Context.getTypeSize(Context.getSizeType());
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -1019,6 +1019,34 @@
   return false;
 }
 
+bool CheckArraySize(SourceLocation Loc, unsigned BitWidth,
+uint64_t ElemCount, bool Diag) {
+  // FIXME: GH63562
+  // APValue stores array extents as unsigned,
+  // so anything that 

[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:6754-6758
   bool IsNothrow = false;
   for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
 EvaluateIgnoredValue(Info, E->getArg(I));
 IsNothrow |= E->getType()->isNothrowT();
   }

Note that that the computation for nothrow is incorrect


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp:48
 
-struct InitWithLambda {
-int b = [](int error = undefined()) { // expected-error {{cannot take 
address of consteval function 'undefined' outside of an immediate invocation}}
+struct InitWithLambda { // expected-note {{'InitWithLambda' is an immediate 
constructor because the default initializer of 'b' contains a call to a 
consteval function 'undefined' and that call is not a constant expression}}
+int b = [](int error = undefined()) {  // expected-note {{undefined 
function 'undefined' cannot be used in a constant expression}}

Fznamznon wrote:
> Maybe it makes sense to print `InitWithLambda::InitWithLambda` so it looks 
> same as "call to immediate function ... is not a constant expression" message 
> and makes it more obvious.
I don't disagree but for some reason default constructors are printed that 
way... I'd have to make the diagnostics even more complicated and it did not 
feel worth it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp:48
 
-struct InitWithLambda {
-int b = [](int error = undefined()) { // expected-error {{cannot take 
address of consteval function 'undefined' outside of an immediate invocation}}
+struct InitWithLambda { // expected-note {{'InitWithLambda' is an immediate 
constructor because the default initializer of 'b' contains a call to a 
consteval function 'undefined' and that call is not a constant expression}}
+int b = [](int error = undefined()) {  // expected-note {{undefined 
function 'undefined' cannot be used in a constant expression}}

cor3ntin wrote:
> Fznamznon wrote:
> > Maybe it makes sense to print `InitWithLambda::InitWithLambda` so it looks 
> > same as "call to immediate function ... is not a constant expression" 
> > message and makes it more obvious.
> I don't disagree but for some reason default constructors are printed that 
> way... I'd have to make the diagnostics even more complicated and it did not 
> feel worth it.
Ok, I see! Yes, I don't feel that making it more complicated is worth it too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

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


[PATCH] D155175: [Clang] Fix consteval propagation for aggregates and defaulted constructors

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 543476.
cor3ntin added a comment.

- Fix FunctionDecl constness
- Replan an `auto`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155175

Files:
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CodeGenCXX/cxx2c-consteval-propagate.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Index: clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
===
--- clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
+++ clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -std=c++2a -emit-llvm-only -Wno-unused-value %s -verify
-// RUN: %clang_cc1 -std=c++2b -emit-llvm-only -Wno-unused-value %s -verify
+// RUN: %clang_cc1 -std=c++2a -Wno-unused-value %s -verify
+// RUN: %clang_cc1 -std=c++2b -Wno-unused-value %s -verify
 
 consteval int id(int i) { return i; }
 constexpr char id(char c) { return c; }
@@ -34,7 +34,7 @@
 
 template 
 constexpr T h(T t = id(x)) { // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}} \
- // expected-note 2{{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
+ // expected-note {{'hh' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
 return t;
 }
 
@@ -164,3 +164,169 @@
 int i = g(x); // expected-error {{call to immediate function 'ConstevalConstructor::g' is not a constant expression}} \
   // expected-note {{read of non-const variable 'x' is not allowed in a constant expression}}
 }
+
+
+
+namespace Aggregate {
+consteval int f(int); // expected-note {{declared here}}
+struct S {
+  int x = f(42); // expected-note {{undefined function 'f' cannot be used in a constant expression}} \
+ // expected-note {{'immediate' is an immediate function because its body contains a call to a consteval function 'f' and that call is not a constant expression}}
+};
+
+constexpr S immediate(auto) {
+return S{};
+}
+
+void test_runtime() {
+(void)immediate(0); // expected-error {{call to immediate function 'Aggregate::immediate' is not a constant expression}} \
+// expected-note {{in call to 'immediate(0)'}}
+}
+consteval int f(int i) {
+return i;
+}
+consteval void test() {
+constexpr S s = immediate(0);
+static_assert(s.x == 42);
+}
+}
+
+
+
+namespace GH63742 {
+void side_effect(); // expected-note  {{declared here}}
+consteval int f(int x) {
+if (!x) side_effect(); // expected-note {{non-constexpr function 'side_effect' cannot be used in a constant expression}}
+return x;
+}
+struct SS {
+  int y = f(1); // Ok
+  int x = f(0); // expected-error {{call to consteval function 'GH63742::f' is not a constant expression}} \
+// expected-note  {{declared here}} \
+// expected-note  {{in call to 'f(0)'}}
+  SS();
+};
+SS::SS(){} // expected-note {{in the default initializer of 'x'}}
+
+consteval int f2(int x) {
+if (!__builtin_is_constant_evaluated()) side_effect();
+return x;
+}
+struct S2 {
+int x = f2(0);
+constexpr S2();
+};
+
+constexpr S2::S2(){}
+S2 s = {};
+constinit S2 s2 = {};
+
+struct S3 {
+int x = f2(0);
+S3();
+};
+S3::S3(){}
+
+}
+
+namespace Defaulted {
+consteval int f(int x);
+struct SS {
+  int x = f(0);
+  SS() = default;
+};
+}
+
+namespace DefaultedUse{
+consteval int f(int x);  // expected-note {{declared here}}
+struct SS {
+  int a = sizeof(f(0)); // Ok
+  int x = f(0); // expected-note {{undefined function 'f' cannot be used in a constant expression}}
+
+  SS() = default; // expected-note {{'SS' is an immediate constructor because the default initializer of 'x' contains a call to a consteval function 'f' and that call is not a constant expression}}
+};
+
+void test() {
+[[maybe_unused]] SS s; // expected-error {{call to immediate function 'DefaultedUse::SS::SS' is not a constant expression}} \
+   //  expected-note {{in call to 'SS()'}}
+}
+}
+
+namespace UserDefinedConstructors {
+consteval int f(int x) {
+return x;
+}
+extern int NonConst; // expected-note 2{{declared here}}
+
+struct ConstevalCtr {
+int y;
+int x = f(y);
+consteval ConstevalCtr(int yy)
+: y(f(yy)) {}
+};
+
+ConstevalCtr c1(1);
+ConstevalCtr c2(NonConst);
+// expected-error@-1 {{call to consteval function 'UserDefinedConstructors::ConstevalCtr::ConstevalCtr' 

[PATCH] D156108: Rebase, extend the test a bit

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156108

Files:
  clang/test/SemaTemplate/gh61159.cpp


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- clang/test/SemaTemplate/gh61159.cpp
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -1,21 +1,39 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 // expected-no-diagnostics
 
-
 namespace GH61159 {
-template
-struct X {
-  struct impl;
+template  struct X {
+  struct I;
 };
 
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
 
-template <>
-struct X::impl {
-template
-int f() { return ct; };
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
 };
 
-void foo() {
-X::impl{}.f<17>();
-}
-}
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- clang/test/SemaTemplate/gh61159.cpp
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -1,21 +1,39 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
 // expected-no-diagnostics
 
-
 namespace GH61159 {
-template
-struct X {
-  struct impl;
+template  struct X {
+  struct I;
 };
 
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
 
-template <>
-struct X::impl {
-template
-int f() { return ct; };
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
 };
 
-void foo() {
-X::impl{}.f<17>();
-}
-}
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 543478.
Fznamznon added a comment.

Rebase, extend the test a bit


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155705

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/gh61159.cpp


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+namespace GH61159 {
+template  struct X {
+  struct I;
+};
+
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
+
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
+};
+
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -258,6 +258,11 @@
/*Final=*/false);
   }
 
+  if (const MemberSpecializationInfo *MSInfo =
+  Rec->getMemberSpecializationInfo())
+if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  return Response::Done();
+
   bool IsFriend = Rec->getFriendObjectKind() ||
   (Rec->getDescribedClassTemplate() &&
Rec->getDescribedClassTemplate()->getFriendObjectKind());
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -670,6 +670,8 @@
 - Correcly diagnose jumps into statement expressions.
   This ensures the behavior of Clang is consistent with GCC.
   (`#63682 `_)
+- Fix crash on nested templated class with template function call.
+  (`#61159 _`)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaTemplate/gh61159.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/gh61159.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+// expected-no-diagnostics
+
+namespace GH61159 {
+template  struct X {
+  struct I;
+};
+
+template <> struct X::I {
+  template  constexpr int f() { return ct; };
+
+  int data = 3;
+};
+
+template  struct X::I {
+  template  constexpr T f() { return ct + 1; };
+  T data = 7;
+};
+
+static_assert(X::I{}.f<17>() == 17);
+static_assert(X::I{}.data == 3);
+static_assert(X::I{}.data == 7);
+static_assert(X::I{}.f<18>() == 19);
+
+template  struct Y {
+  struct I;
+};
+
+template <> struct Y {
+  struct I {
+template  constexpr int f() { return ct; };
+int data = 3;
+  };
+};
+
+static_assert(Y::I{}.f<17>() == 17);
+static_assert(Y::I{}.data == 3);
+
+} // namespace GH61159
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -258,6 +258,11 @@
/*Final=*/false);
   }
 
+  if (const MemberSpecializationInfo *MSInfo =
+  Rec->getMemberSpecializationInfo())
+if (MSInfo->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
+  return Response::Done();
+
   bool IsFriend = Rec->getFriendObjectKind() ||
   (Rec->getDescribedClassTemplate() &&
Rec->getDescribedClassTemplate()->getFriendObjectKind());
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -670,6 +670,8 @@
 - Correcly diagnose jumps into statement expressions.
   This ensures the behavior of Clang is consistent with GCC.
   (`#63682 `_)
+- Fix crash on nested templated class with template function call.
+  (`#61159 _`)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156108: Rebase, extend the test a bit

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon abandoned this revision.
Fznamznon added a comment.

Miss click!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156108

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


[PATCH] D155798: [X86] Support -march=graniterapids-d and update -march=graniterapids

2023-07-24 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155798

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


[PATCH] D155705: [clang] Fix specialization of non-templated member classes of class templates

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

> Maybe we should think about tests that might exercise this code a bit more.

I tried adding more checks, but the patch fixes a specific case.
Do you have some examples in mind?
Please note that in order to test new change there should be an instantiation 
of nested non-template class inside of a templated class.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155705

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


[clang] dfca883 - [Sema] Fix handling of functions that hide classes

2023-07-24 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-07-24T13:11:30+01:00
New Revision: dfca88341794eec88c5009a93c569172fff62635

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

LOG: [Sema] Fix handling of functions that hide classes

When a function is declared in the same scope as a class with the same
name then the function hides that class. Currently this is done by a
single check after the main loop in LookupResult::resolveKind, but
this can give the wrong result when we have a using declaration in
multiple namespace scopes in two different ways:

 * When the using declaration is hidden in one namespace but not the
   other we can end up considering only the hidden one when deciding
   if the result is ambiguous, causing an incorrect "not ambiguous"
   result.

 * When two classes with the same name in different namespace scopes
   are both hidden by using declarations this can result in
   incorrectly deciding the result is ambiguous. There's currently a
   comment saying this is expected, but I don't think that's correct.

Solve this by checking each Decl to see if it's hidden by some other
Decl in the same scope. This means we have to delay removing anything
from Decls until after the main loop, in case a Decl is hidden by
another that is removed due to being non-unique.

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

Added: 
clang/test/SemaCXX/using-hiding.cpp

Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index d1ff688c2a21d0..03f917d95275b6 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -513,21 +513,42 @@ void LookupResult::resolveKind() {
   const NamedDecl *HasNonFunction = nullptr;
 
   llvm::SmallVector EquivalentNonFunctions;
+  llvm::BitVector RemovedDecls(N);
 
-  unsigned UniqueTagIndex = 0;
-
-  unsigned I = 0;
-  while (I < N) {
+  for (unsigned I = 0; I < N; I++) {
 const NamedDecl *D = Decls[I]->getUnderlyingDecl();
 D = cast(D->getCanonicalDecl());
 
 // Ignore an invalid declaration unless it's the only one left.
 // Also ignore HLSLBufferDecl which not have name conflict with other 
Decls.
-if ((D->isInvalidDecl() || isa(D)) && !(I == 0 && N == 1)) 
{
-  Decls[I] = Decls[--N];
+if ((D->isInvalidDecl() || isa(D)) &&
+N - RemovedDecls.count() > 1) {
+  RemovedDecls.set(I);
   continue;
 }
 
+// C++ [basic.scope.hiding]p2:
+//   A class name or enumeration name can be hidden by the name of
+//   an object, function, or enumerator declared in the same
+//   scope. If a class or enumeration name and an object, function,
+//   or enumerator are declared in the same scope (in any order)
+//   with the same name, the class or enumeration name is hidden
+//   wherever the object, function, or enumerator name is visible.
+if (HideTags && isa(D)) {
+  bool Hidden = false;
+  for (auto *OtherDecl : Decls) {
+if (canHideTag(OtherDecl) &&
+getContextForScopeMatching(OtherDecl)->Equals(
+getContextForScopeMatching(Decls[I]))) {
+  RemovedDecls.set(I);
+  Hidden = true;
+  break;
+}
+  }
+  if (Hidden)
+continue;
+}
+
 std::optional ExistingI;
 
 // Redeclarations of types via typedef can occur both within a scope
@@ -559,8 +580,9 @@ void LookupResult::resolveKind() {
   // discard the other.
   if (isPreferredLookupResult(getSema(), getLookupKind(), Decls[I],
   Decls[*ExistingI]))
-Decls[*ExistingI] = Decls[I];
-  Decls[I] = Decls[--N];
+RemovedDecls.set(*ExistingI);
+  else
+RemovedDecls.set(I);
   continue;
 }
 
@@ -571,7 +593,6 @@ void LookupResult::resolveKind() {
 } else if (isa(D)) {
   if (HasTag)
 Ambiguous = true;
-  UniqueTagIndex = I;
   HasTag = true;
 } else if (isa(D)) {
   HasFunction = true;
@@ -587,7 +608,7 @@ void LookupResult::resolveKind() {
 if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
  D)) {
   EquivalentNonFunctions.push_back(D);
-  Decls[I] = Decls[--N];
+  RemovedDecls.set(I);
   continue;
 }
 
@@ -595,28 +616,6 @@ void LookupResult::resolveKind() {
   }
   HasNonFunction = D;
 }
-I++;
-  }
-
-  // C++ [basic.scope.hiding]p2:
-  //   A class name or enumeration name can be hidden by the name of
-  //   an object, function, or enumerator declared in the same
-  //   scope. If a class or enumeration name and an object, function,
-  //   or enumerator are declared in the same scope (in any order)
-  /

[PATCH] D154503: [Sema] Fix handling of functions that hide classes

2023-07-24 Thread John Brawn via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdfca88341794: [Sema] Fix handling of functions that hide 
classes (authored by john.brawn).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154503

Files:
  clang/lib/Sema/SemaLookup.cpp
  clang/test/SemaCXX/using-hiding.cpp

Index: clang/test/SemaCXX/using-hiding.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/using-hiding.cpp
@@ -0,0 +1,373 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+namespace A {
+  class X { }; // expected-note{{candidate found by name lookup is 'A::X'}}
+   // expected-note@-1{{candidate found by name lookup is 'A::X'}}
+}
+namespace B {
+  void X(int); // expected-note{{candidate found by name lookup is 'B::X'}}
+   // expected-note@-1{{candidate found by name lookup is 'B::X'}}
+}
+
+// Using directive doesn't cause A::X to be hidden, so X is ambiguous.
+namespace Test1a {
+  using namespace A;
+  using namespace B;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test1b {
+  using namespace B;
+  using namespace A;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// The behaviour here should be the same as using namespaces A and B directly
+namespace Test2a {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test2a::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test2a::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test2b {
+  namespace C {
+using A::X; // expected-note{{candidate found by name lookup is 'Test2b::C::X'}}
+  }
+  namespace D {
+using B::X; // expected-note{{candidate found by name lookup is 'Test2b::D::X'}}
+  }
+  using namespace D;
+  using namespace C;
+
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// Defining a function X inside C should hide using A::X in C but not D, so the result is ambiguous.
+namespace Test3a {
+  namespace C {
+using A::X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test3a::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3a::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test3b {
+  namespace C {
+using A::X;
+void X(int); // expected-note{{candidate found by name lookup is 'Test3b::C::X'}}
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3b::D::X'}}
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test3c {
+  namespace C {
+void X(int); // expected-note{{candidate found by name lookup is 'Test3c::C::X'}}
+using A::X;
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3c::D::X'}}
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+namespace Test3d {
+  namespace C {
+void X(int); // expected-note{{candidate found by name lookup is 'Test3d::C::X'}}
+using A::X;
+  }
+  namespace D {
+using A::X; // expected-note{{candidate found by name lookup is 'Test3d::D::X'}}
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1); // expected-error{{reference to 'X' is ambiguous}}
+  }
+}
+
+// A::X hidden in both C and D by overloaded function, so the result is not ambiguous.
+namespace Test4a {
+  namespace C {
+using A::X;
+void X(int);
+  }
+  namespace D {
+using A::X;
+void X(int, int);
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+namespace Test4b {
+  namespace C {
+using A::X;
+void X(int);
+  }
+  namespace D {
+using A::X;
+void X(int, int);
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1);
+  }
+}
+
+namespace Test4c {
+  namespace C {
+void X(int);
+using A::X;
+  }
+  namespace D {
+void X(int, int);
+using A::X;
+  }
+  using namespace C;
+  using namespace D;
+  void f() {
+X(1);
+  }
+}
+
+namespace Test4d {
+  namespace C {
+void X(int);
+using A::X;
+  }
+  namespace D {
+void X(int, int);
+using A::X;
+  }
+  using namespace D;
+  using namespace C;
+  void f() {
+X(1);
+  }
+}
+
+// B::X hides class X in C, so the the result is not ambiguous
+namespace Test5a {
+  namespace C {
+using B::X;
+class X { };
+  }
+  namespace D {
+using

[PATCH] D156042: [clang][Interp] Implement __builtin_strlen

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM, modulo suggestion




Comment at: clang/lib/AST/Interp/InterpBuiltin.cpp:63-69
+  if (SizeTWidth == 64)
+S.Stk.push>(Integral<64, false>::from(Val));
+  else if (SizeTWidth == 32)
+S.Stk.push>(Integral<32, false>::from(Val));
+  else
+llvm_unreachable("size_t isn't 64 or 32 bit?");
+}

Maybe we could have
```
pushSignedInteger(InterpState &S, unsigned bit width, int64_t Val);
pushUnsignedInteger(InterpState &S, unsigned bit width, int64_t Val)
```
to simplify pushSizeT and pushInt


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

https://reviews.llvm.org/D156042

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


[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticASTKinds.td:356
+  "cannot allocate array; evaluated array bound %0 exceeds the limit (%1); "
+  "use -fconstexpr-steps=%0 to increase this limit">;
 def note_constexpr_new_too_small : Note<

I think use of %0 twice here is a bit of a surprise. The first time it's 
telling you the array bounds, but the second time it's telling you a step 
limit; these are different things (array bounds contribute to the step limit 
but there's no reason to assume that setting the step limit to the array bounds 
will fix anything (or even be larger than the current step limit).



Comment at: clang/lib/AST/ExprConstant.cpp:1039
+  // of arrays to avoid exhausting the system resources, as initialization
+  // of each element in likely to take some number of steps anyway.
+  uint64_t Limit = Ctx.getLangOpts().ConstexprStepLimit;





Comment at: clang/lib/AST/ExprConstant.cpp:6544-6546
+if (Size && Size > Value.getArrayInitializedElts()) {
   expandArray(Value, Value.getArraySize() - 1);
+}

Unnecessary changes.



Comment at: clang/lib/AST/ExprConstant.cpp:6754-6758
   bool IsNothrow = false;
   for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
 EvaluateIgnoredValue(Info, E->getArg(I));
 IsNothrow |= E->getType()->isNothrowT();
   }

cor3ntin wrote:
> Note that that the computation for nothrow is incorrect
Good catch -- are you planning to fix in a follow-up? If not, can you file an 
issue so we don't lose track of this? (Bonus points for a test case showing 
that we get this wrong.)



Comment at: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp:1
+// RUN: %clang_cc1 -std=c++2a -verify -fconstexpr-steps=1024 %s
+





Comment at: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp:52
+constexpr S s4(1024); // expected-error {{constexpr variable 's4' 
must be initialized by a constant expression}} \
+   // expected-note@#construct {{constexpr 
evaluation hit maximum step limit; possible infinite loop?}} \
+   // expected-note@#construct_call {{in 
call}} \

The wording of this note is a bit unfortunate given that there's no loop in 
sight. :-(



Comment at: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp:59
+constexpr S s5(1025); // expected-error{{constexpr variable 's5' 
must be initialized by a constant expression}} \
+   // expected-note@#alloc {{cannot allocate 
array; evaluated array bound 1025 exceeds the limit (1024); use 
-fconstexpr-steps=1025 to increase this limit}} \
+   // expected-note@#call {{in call to 
'this->alloc.allocate(1025)'}} \

If you set the limit to 1025 do you actually succeed?



Comment at: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp:79-82
+
+
+
+}




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

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


[PATCH] D155808: [clang][driver] Missing the condition in IsARMBigEndain function.

2023-07-24 Thread Simi Pallipurath via Phabricator via cfe-commits
simpal01 updated this revision to Diff 543484.
simpal01 added a comment.

Addressing review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155808

Files:
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -424,12 +424,13 @@
   if (Args.hasArg(options::OPT_s))
 CmdArgs.push_back("-s");
 
-  if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) {
+  if (Triple.isARM() || Triple.isThumb()) {
 bool IsBigEndian = arm::isARMBigEndian(Triple, Args);
 if (IsBigEndian)
   arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
-IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be;
 CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
+  } else if (Triple.isAArch64()) {
+CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
   // Most Android ARM64 targets should enable the linker fix for erratum
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -443,12 +443,13 @@
 
   CmdArgs.push_back("-Bstatic");
 
-  if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) {
+  if (Triple.isARM() || Triple.isThumb()) {
 bool IsBigEndian = arm::isARMBigEndian(Triple, Args);
 if (IsBigEndian)
   arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
-IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be;
 CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
+  } else if (Triple.isAArch64()) {
+CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
   Args.AddAllArgs(CmdArgs,


Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp
+++ clang/lib/Driver/ToolChains/Gnu.cpp
@@ -424,12 +424,13 @@
   if (Args.hasArg(options::OPT_s))
 CmdArgs.push_back("-s");
 
-  if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) {
+  if (Triple.isARM() || Triple.isThumb()) {
 bool IsBigEndian = arm::isARMBigEndian(Triple, Args);
 if (IsBigEndian)
   arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
-IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be;
 CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
+  } else if (Triple.isAArch64()) {
+CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
   // Most Android ARM64 targets should enable the linker fix for erratum
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -443,12 +443,13 @@
 
   CmdArgs.push_back("-Bstatic");
 
-  if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64()) {
+  if (Triple.isARM() || Triple.isThumb()) {
 bool IsBigEndian = arm::isARMBigEndian(Triple, Args);
 if (IsBigEndian)
   arm::appendBE8LinkFlag(Args, CmdArgs, Triple);
-IsBigEndian = IsBigEndian || Arch == llvm::Triple::aarch64_be;
 CmdArgs.push_back(IsBigEndian ? "-EB" : "-EL");
+  } else if (Triple.isAArch64()) {
+CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
   Args.AddAllArgs(CmdArgs,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin marked 2 inline comments as done.
cor3ntin added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticASTKinds.td:356
+  "cannot allocate array; evaluated array bound %0 exceeds the limit (%1); "
+  "use -fconstexpr-steps=%0 to increase this limit">;
 def note_constexpr_new_too_small : Note<

aaron.ballman wrote:
> I think use of %0 twice here is a bit of a surprise. The first time it's 
> telling you the array bounds, but the second time it's telling you a step 
> limit; these are different things (array bounds contribute to the step limit 
> but there's no reason to assume that setting the step limit to the array 
> bounds will fix anything (or even be larger than the current step limit).
"use '-fconstexpr-steps' to increase this limit" then?

(The idea was that fconstexpr-steps needs to be at least that value, i agree 
that the program could still fail a few instructions later)



Comment at: clang/lib/AST/ExprConstant.cpp:6754-6758
   bool IsNothrow = false;
   for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
 EvaluateIgnoredValue(Info, E->getArg(I));
 IsNothrow |= E->getType()->isNothrowT();
   }

aaron.ballman wrote:
> cor3ntin wrote:
> > Note that that the computation for nothrow is incorrect
> Good catch -- are you planning to fix in a follow-up? If not, can you file an 
> issue so we don't lose track of this? (Bonus points for a test case showing 
> that we get this wrong.)
I'll file an issue because it's unclear to me whether this is the only problem 
with nothrow allocation, or how they should work in general.
Assuming we fix that `(T*) new(TOO_BIG, nothrow)` still complain about casting 
a `void*` ptr.

Ie, i already looked into it and decided it was way out of scope.



Comment at: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp:52
+constexpr S s4(1024); // expected-error {{constexpr variable 's4' 
must be initialized by a constant expression}} \
+   // expected-note@#construct {{constexpr 
evaluation hit maximum step limit; possible infinite loop?}} \
+   // expected-note@#construct_call {{in 
call}} \

aaron.ballman wrote:
> The wording of this note is a bit unfortunate given that there's no loop in 
> sight. :-(
Line 32. ie, that the case where the allocation succeeds but we can't do much 
to the array.



Comment at: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp:59
+constexpr S s5(1025); // expected-error{{constexpr variable 's5' 
must be initialized by a constant expression}} \
+   // expected-note@#alloc {{cannot allocate 
array; evaluated array bound 1025 exceeds the limit (1024); use 
-fconstexpr-steps=1025 to increase this limit}} \
+   // expected-note@#call {{in call to 
'this->alloc.allocate(1025)'}} \

aaron.ballman wrote:
> If you set the limit to 1025 do you actually succeed?
Yes... but no, see previous comment :)
Maybe I can add `constexpr S s4(100);` that would have no error at 
all


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

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


[clang] cc928c6 - [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread via cfe-commits

Author: Podchishchaeva, Mariya
Date: 2023-07-24T05:15:50-07:00
New Revision: cc928c683058b2e43d250234066609008aa02f68

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

LOG: [NFC][clang] Fix static analyzer concerns

OMPTransformDirectiveScopeRAII doesn't have user-written copy
constructor/assignment operator but it frees memory in the destructor.
Delete these members since doesn't seem that OMPTransformDirectiveScopeRAII
objects are intended for copy.

Reviewed By: tahonermann, ABataev

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

Added: 


Modified: 
clang/lib/CodeGen/CGStmtOpenMP.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 7721feccb46ee2..4910ff6865e43d 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,11 @@ class OMPTransformDirectiveScopeRAII {
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
+
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction &CGF, const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {



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


[PATCH] D155849: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcc928c683058: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155849

Files:
  clang/lib/CodeGen/CGStmtOpenMP.cpp


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,11 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
+
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction &CGF, const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {


Index: clang/lib/CodeGen/CGStmtOpenMP.cpp
===
--- clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -1820,6 +1820,11 @@
   CodeGenFunction::CGCapturedStmtInfo *CGSI = nullptr;
   CodeGenFunction::CGCapturedStmtRAII *CapInfoRAII = nullptr;
 
+  OMPTransformDirectiveScopeRAII(const OMPTransformDirectiveScopeRAII &) =
+  delete;
+  OMPTransformDirectiveScopeRAII &
+  operator=(const OMPTransformDirectiveScopeRAII &) = delete;
+
 public:
   OMPTransformDirectiveScopeRAII(CodeGenFunction &CGF, const Stmt *S) {
 if (const auto *Dir = dyn_cast(S)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] dc3cd59 - Revert "[Sema] Fix handling of functions that hide classes"

2023-07-24 Thread John Brawn via cfe-commits

Author: John Brawn
Date: 2023-07-24T13:30:26+01:00
New Revision: dc3cd5926423c56d4673308617f035713aa024d6

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

LOG: Revert "[Sema] Fix handling of functions that hide classes"

This reverts commit dfca88341794eec88c5009a93c569172fff62635.

Causes clang/test/Modules/stress1.cpp to fail.

Added: 


Modified: 
clang/lib/Sema/SemaLookup.cpp

Removed: 
clang/test/SemaCXX/using-hiding.cpp



diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 03f917d95275b6..d1ff688c2a21d0 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -513,42 +513,21 @@ void LookupResult::resolveKind() {
   const NamedDecl *HasNonFunction = nullptr;
 
   llvm::SmallVector EquivalentNonFunctions;
-  llvm::BitVector RemovedDecls(N);
 
-  for (unsigned I = 0; I < N; I++) {
+  unsigned UniqueTagIndex = 0;
+
+  unsigned I = 0;
+  while (I < N) {
 const NamedDecl *D = Decls[I]->getUnderlyingDecl();
 D = cast(D->getCanonicalDecl());
 
 // Ignore an invalid declaration unless it's the only one left.
 // Also ignore HLSLBufferDecl which not have name conflict with other 
Decls.
-if ((D->isInvalidDecl() || isa(D)) &&
-N - RemovedDecls.count() > 1) {
-  RemovedDecls.set(I);
+if ((D->isInvalidDecl() || isa(D)) && !(I == 0 && N == 1)) 
{
+  Decls[I] = Decls[--N];
   continue;
 }
 
-// C++ [basic.scope.hiding]p2:
-//   A class name or enumeration name can be hidden by the name of
-//   an object, function, or enumerator declared in the same
-//   scope. If a class or enumeration name and an object, function,
-//   or enumerator are declared in the same scope (in any order)
-//   with the same name, the class or enumeration name is hidden
-//   wherever the object, function, or enumerator name is visible.
-if (HideTags && isa(D)) {
-  bool Hidden = false;
-  for (auto *OtherDecl : Decls) {
-if (canHideTag(OtherDecl) &&
-getContextForScopeMatching(OtherDecl)->Equals(
-getContextForScopeMatching(Decls[I]))) {
-  RemovedDecls.set(I);
-  Hidden = true;
-  break;
-}
-  }
-  if (Hidden)
-continue;
-}
-
 std::optional ExistingI;
 
 // Redeclarations of types via typedef can occur both within a scope
@@ -580,9 +559,8 @@ void LookupResult::resolveKind() {
   // discard the other.
   if (isPreferredLookupResult(getSema(), getLookupKind(), Decls[I],
   Decls[*ExistingI]))
-RemovedDecls.set(*ExistingI);
-  else
-RemovedDecls.set(I);
+Decls[*ExistingI] = Decls[I];
+  Decls[I] = Decls[--N];
   continue;
 }
 
@@ -593,6 +571,7 @@ void LookupResult::resolveKind() {
 } else if (isa(D)) {
   if (HasTag)
 Ambiguous = true;
+  UniqueTagIndex = I;
   HasTag = true;
 } else if (isa(D)) {
   HasFunction = true;
@@ -608,7 +587,7 @@ void LookupResult::resolveKind() {
 if (getSema().isEquivalentInternalLinkageDeclaration(HasNonFunction,
  D)) {
   EquivalentNonFunctions.push_back(D);
-  RemovedDecls.set(I);
+  Decls[I] = Decls[--N];
   continue;
 }
 
@@ -616,6 +595,28 @@ void LookupResult::resolveKind() {
   }
   HasNonFunction = D;
 }
+I++;
+  }
+
+  // C++ [basic.scope.hiding]p2:
+  //   A class name or enumeration name can be hidden by the name of
+  //   an object, function, or enumerator declared in the same
+  //   scope. If a class or enumeration name and an object, function,
+  //   or enumerator are declared in the same scope (in any order)
+  //   with the same name, the class or enumeration name is hidden
+  //   wherever the object, function, or enumerator name is visible.
+  // But it's still an error if there are distinct tag types found,
+  // even if they're not visible. (ref?)
+  if (N > 1 && HideTags && HasTag && !Ambiguous &&
+  (HasFunction || HasNonFunction || HasUnresolved)) {
+const NamedDecl *OtherDecl = Decls[UniqueTagIndex ? 0 : N - 1];
+if (isa(Decls[UniqueTagIndex]->getUnderlyingDecl()) &&
+getContextForScopeMatching(Decls[UniqueTagIndex])->Equals(
+getContextForScopeMatching(OtherDecl)) &&
+canHideTag(OtherDecl))
+  Decls[UniqueTagIndex] = Decls[--N];
+else
+  Ambiguous = true;
   }
 
   // FIXME: This diagnostic should really be delayed until we're done with
@@ -624,15 +625,9 @@ void LookupResult::resolveKind() {
 getSema().diagnoseEquivalentInternalLinkageDeclarations(
 getNameLoc(), HasNonFunction, EquivalentNonFunctions);
 
-  // Remove decls

[clang] 0cb2906 - [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread via cfe-commits

Author: Podchishchaeva, Mariya
Date: 2023-07-24T05:31:55-07:00
New Revision: 0cb2906cdfb3480382828890e9ac4c076c17f3fa

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

LOG: [NFC][clang] Fix static analyzer concerns

HeaderIncludesCallback and HeaderIncludesJSONCallback classes may own
resources and free them in the destructor. However they don't have copy
user-written constructors/assignment operators, so an attempt to copy a
HeaderIncludesCallback object will use compiler-generated copy
constructor which will only do dummy copy and afterwards there will be
use-after-free issues.

Reviewed By: aaron.ballman, tahonermann

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

Added: 


Modified: 
clang/lib/Frontend/HeaderIncludeGen.cpp

Removed: 




diff  --git a/clang/lib/Frontend/HeaderIncludeGen.cpp 
b/clang/lib/Frontend/HeaderIncludeGen.cpp
index 9ada227d42d622..9c1bf490fcd65e 100644
--- a/clang/lib/Frontend/HeaderIncludeGen.cpp
+++ b/clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@ class HeaderIncludesCallback : public PPCallbacks {
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback &operator=(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@ class HeaderIncludesJSONCallback : public PPCallbacks {
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,



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


[PATCH] D155842: [NFC][clang] Fix static analyzer concerns

2023-07-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0cb2906cdfb3: [NFC][clang] Fix static analyzer concerns 
(authored by Fznamznon).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155842

Files:
  clang/lib/Frontend/HeaderIncludeGen.cpp


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback &operator=(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,


Index: clang/lib/Frontend/HeaderIncludeGen.cpp
===
--- clang/lib/Frontend/HeaderIncludeGen.cpp
+++ clang/lib/Frontend/HeaderIncludeGen.cpp
@@ -43,6 +43,9 @@
   delete OutputFile;
   }
 
+  HeaderIncludesCallback(const HeaderIncludesCallback &) = delete;
+  HeaderIncludesCallback &operator=(const HeaderIncludesCallback &) = delete;
+
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
SrcMgr::CharacteristicKind FileType,
FileID PrevFID) override;
@@ -90,6 +93,10 @@
   delete OutputFile;
   }
 
+  HeaderIncludesJSONCallback(const HeaderIncludesJSONCallback &) = delete;
+  HeaderIncludesJSONCallback &
+  operator=(const HeaderIncludesJSONCallback &) = delete;
+
   void EndOfMainFile() override;
 
   void FileChanged(SourceLocation Loc, FileChangeReason Reason,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticASTKinds.td:356
+  "cannot allocate array; evaluated array bound %0 exceeds the limit (%1); "
+  "use -fconstexpr-steps=%0 to increase this limit">;
 def note_constexpr_new_too_small : Note<

cor3ntin wrote:
> aaron.ballman wrote:
> > I think use of %0 twice here is a bit of a surprise. The first time it's 
> > telling you the array bounds, but the second time it's telling you a step 
> > limit; these are different things (array bounds contribute to the step 
> > limit but there's no reason to assume that setting the step limit to the 
> > array bounds will fix anything (or even be larger than the current step 
> > limit).
> "use '-fconstexpr-steps' to increase this limit" then?
> 
> (The idea was that fconstexpr-steps needs to be at least that value, i agree 
> that the program could still fail a few instructions later)
Yeah, I think this is a case where it's better to just mention the option but 
not suggest a value.



Comment at: clang/lib/AST/ExprConstant.cpp:6754-6758
   bool IsNothrow = false;
   for (unsigned I = 1, N = E->getNumArgs(); I != N; ++I) {
 EvaluateIgnoredValue(Info, E->getArg(I));
 IsNothrow |= E->getType()->isNothrowT();
   }

cor3ntin wrote:
> aaron.ballman wrote:
> > cor3ntin wrote:
> > > Note that that the computation for nothrow is incorrect
> > Good catch -- are you planning to fix in a follow-up? If not, can you file 
> > an issue so we don't lose track of this? (Bonus points for a test case 
> > showing that we get this wrong.)
> I'll file an issue because it's unclear to me whether this is the only 
> problem with nothrow allocation, or how they should work in general.
> Assuming we fix that `(T*) new(TOO_BIG, nothrow)` still complain about 
> casting a `void*` ptr.
> 
> Ie, i already looked into it and decided it was way out of scope.
SGTM!



Comment at: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp:1
+// RUN: %clang_cc1 -std=c++2a -verify -fconstexpr-steps=1024 %s
+

aaron.ballman wrote:
> 
Should we add -Wvla to show when constant folding fails we're getting a VLA?



Comment at: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp:52
+constexpr S s4(1024); // expected-error {{constexpr variable 's4' 
must be initialized by a constant expression}} \
+   // expected-note@#construct {{constexpr 
evaluation hit maximum step limit; possible infinite loop?}} \
+   // expected-note@#construct_call {{in 
call}} \

cor3ntin wrote:
> aaron.ballman wrote:
> > The wording of this note is a bit unfortunate given that there's no loop in 
> > sight. :-(
> Line 32. ie, that the case where the allocation succeeds but we can't do much 
> to the array.
Ahhh, I see. Hmm, okay, not as bad as I had thought.



Comment at: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp:59
+constexpr S s5(1025); // expected-error{{constexpr variable 's5' 
must be initialized by a constant expression}} \
+   // expected-note@#alloc {{cannot allocate 
array; evaluated array bound 1025 exceeds the limit (1024); use 
-fconstexpr-steps=1025 to increase this limit}} \
+   // expected-note@#call {{in call to 
'this->alloc.allocate(1025)'}} \

cor3ntin wrote:
> aaron.ballman wrote:
> > If you set the limit to 1025 do you actually succeed?
> Yes... but no, see previous comment :)
> Maybe I can add `constexpr S s4(100);` that would have no error 
> at all
I think that'd be a good test to add as well, yes,


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

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


cfe-commits@lists.llvm.org

2023-07-24 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added inline comments.



Comment at: llvm/lib/Target/X86/X86CallingConv.td:98-103
+def RC_X86_64_RegCallv4_Win : RC_X86_64_RegCall {
+  let GPR_8 = [AL, CL, DL, DIL, SIL, R8B, R9B, R11B, R12B, R14B, R15B];
+  let GPR_16 = [AX, CX, DX, DI, SI, R8W, R9W, R11W, R12W, R14W, R15W];
+  let GPR_32 = [EAX, ECX, EDX, EDI, ESI, R8D, R9D, R11D, R12D, R14D, R15D];
+  let GPR_64 = [RAX, RCX, RDX, RDI, RSI, R8, R9, R11, R12, R14, R15];
+}

According to the spec, Win64 calling convention is identical to Linux64 on V4, 
i.e., both `R10` and `R11` are reserved. I think you can reuse 
`RC_X86_64_RegCall_SysV` instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155863

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


[PATCH] D155955: [Clang] Improve the handling of large arrays evaluation.

2023-07-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 543490.
cor3ntin added a comment.

Address Aaron's comments and add documentation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D155955

Files:
  clang/docs/ReleaseNotes.rst
  clang/docs/UsersManual.rst
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp

Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc-limits.cpp
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 -std=c++2a -verify -fconstexpr-steps=1024 %s
+
+namespace std {
+  using size_t = decltype(sizeof(0));
+}
+
+void *operator new(std::size_t, void *p) { return p; }
+
+namespace std {
+  template struct allocator {
+constexpr T *allocate(size_t N) {
+  return (T*)operator new(sizeof(T) * N); // #alloc
+}
+constexpr void deallocate(void *p) {
+  operator delete(p);
+}
+  };
+  template
+  constexpr void construct_at(void *p, Args &&...args) { // #construct
+new (p) T((Args&&)args...);
+  }
+}
+
+namespace GH63562 {
+
+template 
+struct S {
+constexpr S(unsigned long long N)
+: data(nullptr){
+data = alloc.allocate(N);  // #call
+for(std::size_t i = 0; i < N; i ++)
+std::construct_at(data + i, i); // #construct_call
+
+}
+constexpr ~S() {
+alloc.deallocate(data);
+}
+std::allocator alloc;
+T* data;
+};
+
+constexpr S s(109951162); // expected-error {{constexpr variable 's' must be initialized by a constant expression}} \
+   // expected-note@#call {{in call to 'this->alloc.allocate(109951162)'}} \
+   // expected-note@#alloc {{cannot allocate array; evaluated array bound 109951162 is too large}} \
+   // expected-note {{in call to 'S(109951162)'}}
+// Check that we do not try to fold very large arrays
+S s2(109951162);
+S s3(~0ULL);
+
+// We can allocate this array but we hikt the number of steps
+constexpr S s4(1024); // expected-error {{constexpr variable 's4' must be initialized by a constant expression}} \
+   // expected-note@#construct {{constexpr evaluation hit maximum step limit; possible infinite loop?}} \
+   // expected-note@#construct_call {{in call}} \
+   // expected-note {{in call}}
+
+
+
+constexpr S s5(1025); // expected-error{{constexpr variable 's5' must be initialized by a constant expression}} \
+   // expected-note@#alloc {{cannot allocate array; evaluated array bound 1025 exceeds the limit (1024); use '-fconstexpr-steps' to increase this limit}} \
+   // expected-note@#call {{in call to 'this->alloc.allocate(1025)'}} \
+   // expected-note {{in call}}
+
+
+// Check we do not perform constant initialization in the presence
+// of very large arrays (this used to crash)
+
+template 
+constexpr int stack_array() {
+[[maybe_unused]] char BIG[N] = {0};  // expected-note  {{cannot allocate array; evaluated array bound 1025 exceeds the limit (1024); use '-fconstexpr-steps' to increase this limit}}
+return BIG[N-1];
+}
+
+int a = stack_array<~0U>();
+int c = stack_array<1024>();
+int d = stack_array<1025>();
+constexpr int e = stack_array<1024>();
+constexpr int f = stack_array<1025>(); // expected-error {{constexpr variable 'f' must be initialized by a constant expression}} \
+   //  expected-note {{in call}}
+}
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -175,6 +175,11 @@
   return TotalSize.getActiveBits();
 }
 
+unsigned
+ConstantArrayType::getNumAddressingBits(const ASTContext &Context) const {
+  return getNumAddressingBits(Context, getElementType(), getSize());
+}
+
 unsigned ConstantArrayType::getMaxSizeBits(const ASTContext &Context) {
   unsigned Bits = Context.getTypeSize(Context.getSizeType());
 
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -1019,6 +1019,34 @@
   return false;
 }
 
+bool CheckArraySize(SourceLocation Loc, unsigned BitWidth,
+uint64_t ElemCount, bool Diag) {
+  // FIXME: GH63562
+  // APValue stores array extents as unsigned,
+  // so anything that is greater that unsigned would overflow when
+  // constructing the array, we catch this here.
+  if (BitWidth > C

  1   2   3   4   >