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

2023-07-09 Thread Patryk Wychowaniec via Phabricator via cfe-commits
Patryk27 added a comment.

ping ping, @benshi001 👀


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153197

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


[PATCH] D131533: [Flang][Driver] Enable PIC in the frontend

2023-07-09 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added inline comments.



Comment at: flang/test/Driver/pic-flags.f90:3
 
-! RUN: %flang -### %s --target=aarch64-linux-gnu 2>&1 | FileCheck %s 
--check-prefix=CHECK-NOPIE
-! RUN: %flang -### %s --target=aarch64-linux-gnu -fno-pie 2>&1 | FileCheck %s 
--check-prefix=CHECK-NOPIE
+! RUN: %flang -v -S -emit-llvm -o - %s --target=aarch64-linux-gnu 2>&1 | 
FileCheck %s --check-prefixes=CHECK,CHECK-PIE-LEVEL2,CHECK-PIE-LEVEL2-IR
+! RUN: %flang -v -S -emit-llvm -o - %s --target=aarch64-linux-gnu -fpie 2>&1 | 
FileCheck %s --check-prefixes=CHECK,CHECK-PIE-LEVEL1,CHECK-PIE-LEVEL1-IR

clementval wrote:
> This test has been failing on my side for very long time. Just curious why we 
> check for PIE-LEVEL-2 when no level is given. Where is the default given?
> 
> On my machine I have `-mrelocation-model static` for this run line. 
> This test has been failing on my side for very long time. 

If this is failing for you then it should also fail on one of the Flang 
buildbots, right? Do you know what's different/special in your configuration?

> Where is the default given?

You want to check:
* [[ 
https://github.com/llvm/llvm-project/blob/2712b2805b47f10b3864ab19a4016ea306126ad7/clang/lib/Driver/ToolChains/Flang.cpp#L149-L168
 | Flang::addPicOption ]] (Flang.cpp)
* [[ 
https://github.com/llvm/llvm-project/blob/2712b2805b47f10b3864ab19a4016ea306126ad7/clang/lib/Driver/ToolChains/CommonArgs.cpp#L1399
 | ParsePICArgs ]] (CommonArgs.cpp)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131533

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


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

2023-07-09 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added a comment.

In D153197#4483230 , @Patryk27 wrote:

> ping ping, @benshi001 👀

Could you please upload your final version of this patch ? I see you have made 
some changes, but only mentioned in your comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153197

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


[PATCH] D154773: [AST] Use correct APSInt width when evaluating string literals

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

I think this is fine, and it's a nice simplification.

However it doesn't seem to do much of anything in practice: if you look at 
`StringLiteral::mapCharByteWidth`, supporting different `CHAR_BIT` would be 
more involved. And that's just part of the front end. 
I really don't how much effort would be involved for complete support, and... 
well, as you say, we have no way to test anything.

So my feeling is that we can land that because it simplifies the code, but 
further work into non 8-bits platforms probably require the input of more folks
and a RFC may be warranted.

Looking around non 8 bits CHAR_BIT seems to have been discussed before 
https://discourse.llvm.org/t/rfc-on-non-8-bit-bytes-and-the-target-for-it/53455 
but i don't know if a conclusion was reached. Maybe worth poking that thread if 
you are interested?

WDYT @aaron.ballman ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154773

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


[PATCH] D154778: [clang] Fix __is_trivially_equality_comparable for classes which contain arrays of non-trivially equality comparable types

2023-07-09 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/D154778/new/

https://reviews.llvm.org/D154778

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


[PATCH] D154778: [clang] Fix __is_trivially_equality_comparable for classes which contain arrays of non-trivially equality comparable types

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



Comment at: clang/lib/AST/Type.cpp:2676
+   if (Type->isArrayType())
+Type = 
Type->getBaseElementTypeUnsafe()->getCanonicalTypeUnqualified();
+




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154778

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


[PATCH] D154784: [clang] Fix crash caused by PseudoObjectExprBitfields::NumSubExprs overflow

2023-07-09 Thread Yurong via Phabricator via cfe-commits
yronglin created this revision.
Herald added a project: All.
yronglin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Signed-off-by: yrong 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154784

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/lib/AST/Expr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/test/SemaCXX/builtin-dump-struct.cpp

Index: clang/test/SemaCXX/builtin-dump-struct.cpp
===
--- clang/test/SemaCXX/builtin-dump-struct.cpp
+++ clang/test/SemaCXX/builtin-dump-struct.cpp
@@ -159,3 +159,27 @@
 // expected-note@#Format {{no known conversion from 'int' to 'ConstexprString &' for 1st argument}}
 }
 #endif
+
+// Check that PseudoObjectExprBitfields:NumSubExprs doesn't overflow.
+struct t1 {
+  int v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16,
+  v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31,
+  v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46,
+  v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61,
+  v62, v63, v64, v65, v66, v67, v68, v69, v70, v71, v72, v73, v74, v75, v76,
+  v77, v78, v79, v80, v81, v82, v83, v84, v85, v86, v87, v88, v89, v90, v91,
+  v92, v93, v94, v95, v96, v97, v98, v99;
+};
+
+struct t2 {
+  t1 v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16,
+  v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31,
+  v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46,
+  v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61,
+  v62, v63, v64, v65, v66, v67, v68, v69, v70, v71, v72, v73, v74, v75, v76,
+  v77, v78, v79, v80, v81, v82, v83, v84, v85, v86, v87, v88, v89, v90, v91,
+  v92, v93, v94, v95, v96, v97, v98, v99;
+};
+
+int printf(const char *, ...);
+void f1(t2 w) { __builtin_dump_struct(&w, printf); }
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1378,8 +1378,15 @@
 void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
   VisitExpr(E);
   unsigned numSemanticExprs = Record.readInt();
-  assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs);
-  E->PseudoObjectExprBits.ResultIndex = Record.readInt();
+  assert(numSemanticExprs + 1 == E->getNumSubExprs());
+
+  unsigned ResultIndex = Record.readInt();
+  if (ResultIndex) {
+E->PseudoObjectExprBits.HasResult = true;
+E->PseudoObjectExprBits.ResultBits.ResultIndex = ResultIndex;
+  } else {
+E->PseudoObjectExprBits.HasResult = false;
+  }
 
   // Read the syntactic expression.
   E->getSubExprsBuffer()[0] = Record.readSubExpr();
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4848,7 +4848,8 @@
 
 PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs)
   : Expr(PseudoObjectExprClass, shell) {
-  PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1;
+  PseudoObjectExprBits.HasResult = false;
+  PseudoObjectExprBits.NumSubExprsIfNoResult = numSemanticExprs + 1;
 }
 
 PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &C, Expr *syntax,
@@ -4879,8 +4880,15 @@
Expr *syntax, ArrayRef semantics,
unsigned resultIndex)
 : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary) {
-  PseudoObjectExprBits.NumSubExprs = semantics.size() + 1;
-  PseudoObjectExprBits.ResultIndex = resultIndex + 1;
+  
+  if (resultIndex == NoResult) {
+PseudoObjectExprBits.HasResult = false;
+PseudoObjectExprBits.NumSubExprsIfNoResult = semantics.size() + 1;
+  } else {
+PseudoObjectExprBits.HasResult = true;
+PseudoObjectExprBits.ResultBits.NumSubExprs = semantics.size() + 1;
+PseudoObjectExprBits.ResultBits.ResultIndex = resultIndex + 1;
+  }
 
   for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) {
 Expr *E = (i == 0 ? syntax : semantics[i-1]);
Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -591,12 +591,26 @@
 friend class ASTStmtReader; // deserialization
 friend class PseudoObjectExpr;
 
+struct ResultBitfields {
+  // These don't need to be particularly wide, because they're
+  // strictly limited by the forms of expressions we permit.
+  unsigned NumSubExprs : 16;
+  unsigned ResultIndex : 16;
+};
+
 unsigned : NumExprBits;
 
-// These don't need to be particula

[PATCH] D154784: [clang] Fix crash caused by PseudoObjectExprBitfields::NumSubExprs overflow

2023-07-09 Thread Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 538418.
yronglin added a comment.

Format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154784

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/Stmt.h
  clang/lib/AST/Expr.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/test/SemaCXX/builtin-dump-struct.cpp

Index: clang/test/SemaCXX/builtin-dump-struct.cpp
===
--- clang/test/SemaCXX/builtin-dump-struct.cpp
+++ clang/test/SemaCXX/builtin-dump-struct.cpp
@@ -159,3 +159,27 @@
 // expected-note@#Format {{no known conversion from 'int' to 'ConstexprString &' for 1st argument}}
 }
 #endif
+
+// Check that PseudoObjectExprBitfields:NumSubExprs doesn't overflow.
+struct t1 {
+  int v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16,
+  v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31,
+  v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46,
+  v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61,
+  v62, v63, v64, v65, v66, v67, v68, v69, v70, v71, v72, v73, v74, v75, v76,
+  v77, v78, v79, v80, v81, v82, v83, v84, v85, v86, v87, v88, v89, v90, v91,
+  v92, v93, v94, v95, v96, v97, v98, v99;
+};
+
+struct t2 {
+  t1 v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16,
+  v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31,
+  v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46,
+  v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61,
+  v62, v63, v64, v65, v66, v67, v68, v69, v70, v71, v72, v73, v74, v75, v76,
+  v77, v78, v79, v80, v81, v82, v83, v84, v85, v86, v87, v88, v89, v90, v91,
+  v92, v93, v94, v95, v96, v97, v98, v99;
+};
+
+int printf(const char *, ...);
+void f1(t2 w) { __builtin_dump_struct(&w, printf); }
Index: clang/lib/Serialization/ASTReaderStmt.cpp
===
--- clang/lib/Serialization/ASTReaderStmt.cpp
+++ clang/lib/Serialization/ASTReaderStmt.cpp
@@ -1378,8 +1378,15 @@
 void ASTStmtReader::VisitPseudoObjectExpr(PseudoObjectExpr *E) {
   VisitExpr(E);
   unsigned numSemanticExprs = Record.readInt();
-  assert(numSemanticExprs + 1 == E->PseudoObjectExprBits.NumSubExprs);
-  E->PseudoObjectExprBits.ResultIndex = Record.readInt();
+  assert(numSemanticExprs + 1 == E->getNumSubExprs());
+
+  unsigned ResultIndex = Record.readInt();
+  if (ResultIndex) {
+E->PseudoObjectExprBits.HasResult = true;
+E->PseudoObjectExprBits.ResultBits.ResultIndex = ResultIndex;
+  } else {
+E->PseudoObjectExprBits.HasResult = false;
+  }
 
   // Read the syntactic expression.
   E->getSubExprsBuffer()[0] = Record.readSubExpr();
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4848,7 +4848,8 @@
 
 PseudoObjectExpr::PseudoObjectExpr(EmptyShell shell, unsigned numSemanticExprs)
   : Expr(PseudoObjectExprClass, shell) {
-  PseudoObjectExprBits.NumSubExprs = numSemanticExprs + 1;
+  PseudoObjectExprBits.HasResult = false;
+  PseudoObjectExprBits.NumSubExprsIfNoResult = numSemanticExprs + 1;
 }
 
 PseudoObjectExpr *PseudoObjectExpr::Create(const ASTContext &C, Expr *syntax,
@@ -4879,8 +4880,15 @@
Expr *syntax, ArrayRef semantics,
unsigned resultIndex)
 : Expr(PseudoObjectExprClass, type, VK, OK_Ordinary) {
-  PseudoObjectExprBits.NumSubExprs = semantics.size() + 1;
-  PseudoObjectExprBits.ResultIndex = resultIndex + 1;
+
+  if (resultIndex == NoResult) {
+PseudoObjectExprBits.HasResult = false;
+PseudoObjectExprBits.NumSubExprsIfNoResult = semantics.size() + 1;
+  } else {
+PseudoObjectExprBits.HasResult = true;
+PseudoObjectExprBits.ResultBits.NumSubExprs = semantics.size() + 1;
+PseudoObjectExprBits.ResultBits.ResultIndex = resultIndex + 1;
+  }
 
   for (unsigned i = 0, e = semantics.size() + 1; i != e; ++i) {
 Expr *E = (i == 0 ? syntax : semantics[i-1]);
Index: clang/include/clang/AST/Stmt.h
===
--- clang/include/clang/AST/Stmt.h
+++ clang/include/clang/AST/Stmt.h
@@ -591,12 +591,26 @@
 friend class ASTStmtReader; // deserialization
 friend class PseudoObjectExpr;
 
+struct ResultBitfields {
+  // These don't need to be particularly wide, because they're
+  // strictly limited by the forms of expressions we permit.
+  unsigned NumSubExprs : 16;
+  unsigned ResultIndex : 16;
+};
+
 unsigned : NumExprBits;
 
-// These don't need to be particularly wide, because they're
-// strictly limited by

[PATCH] D154784: [clang] Fix crash caused by PseudoObjectExprBitfields::NumSubExprs overflow

2023-07-09 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

I'm not sure if we should limit the value of `NumSubExprs` when build  
`PseudoObjectExpr` for `__builtin_dump_struct`, This cost too much memory when 
the nested members of the record are very deep and the num of member is very 
large.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154784

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


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

2023-07-09 Thread Patryk Wychowaniec via Phabricator via cfe-commits
Patryk27 abandoned this revision.
Patryk27 added a comment.

Superseded by:

- https://reviews.llvm.org/D154785


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153197

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


[PATCH] D154786: [Clang][Driver] Pass through the --be8 endian flag to linker in BareMetal driver For Arm.

2023-07-09 Thread Simi Pallipurath via Phabricator via cfe-commits
simpal01 created this revision.
Herald added subscribers: abidh, kristof.beyls.
Herald added a project: All.
simpal01 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

When linking a big-endian image for Arm, clang has
to select  between BE8 and BE32 formats. The default
is dependent on the selected target architecture.
For ARMv6 and later architectures the default is
BE8, for older architectures the default is BE32.
For BE8 and BE32, compiler outputs a big endian ELF
relocatable object file with the instructions and
data both big endian. The difference is that at
link time, for BE8 a linker must endian reverse
the instructions to little endian. For BE8, the
clang has to pass --be8 to the linker for Arm.

At the moment clang is not passing the --be8 flag
to linker for the baremetal target architectures
above ArmV6 for Arm. This patch passes through --be8
and -BE or EL to the linker, taking into account the
target and the -mbig-endian and -mlittle-endian flag.
Also there are few more changes in the baremetal
driver so that the code can cope with AArch64 being
big-endian as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154786

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/lib/Driver/ToolChains/Arch/ARM.h
  clang/lib/Driver/ToolChains/BareMetal.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/test/Driver/baremetal.cpp

Index: clang/test/Driver/baremetal.cpp
===
--- clang/test/Driver/baremetal.cpp
+++ clang/test/Driver/baremetal.cpp
@@ -15,7 +15,7 @@
 // CHECK-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECk-V6M-C-SAME: "-internal-isystem" "[[SYSROOT]]{{[/\\]+}}include"
 // CHECK-V6M-C-SAME: "-x" "c++" "{{.*}}baremetal.cpp"
-// CHECK-V6M-C-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-C-NEXT: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for"
 // CHECK-V6M-C-SAME: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
@@ -34,7 +34,7 @@
 // CHECK-ARMV7M-PER-TARGET: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-ARMV7M-PER-TARGET: "-isysroot" "[[SYSROOT:[^"]*]]"
 // CHECK-ARMV7M-PER-TARGET: "-x" "c++" "{{.*}}baremetal.cpp"
-// CHECK-ARMV7M-PER-TARGET: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-ARMV7M-PER-TARGET: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-ARMV7M-PER-TARGET: "-L[[SYSROOT:[^"]+]]{{[/\\]+}}lib"
 // CHECK-ARMV7M-PER-TARGET: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}armv7m-vendor-none-eabi
 // CHECK-ARMV7M-PER-TARGET: "-lc" "-lm" "-lclang_rt.builtins"
@@ -42,7 +42,7 @@
 // RUN: %clangxx %s -### --target=armv6m-none-eabi 2>&1 \
 // RUN: --sysroot=%S/Inputs/baremetal_arm | FileCheck --check-prefix=CHECK-V6M-DEFAULTCXX %s
 // CHECK-V6M-DEFAULTCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-// CHECK-V6M-DEFAULTCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-DEFAULTCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-DEFAULTCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-DEFAULTCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
@@ -53,7 +53,7 @@
 // CHECK-V6M-LIBCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-V6M-LIBCXX-NOT: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}{{[^v].*}}"
 // CHECK-V6M-LIBCXX-SAME: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
-// CHECK-V6M-LIBCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-LIBCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-LIBCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind"
@@ -66,7 +66,7 @@
 // CHECK-V6M-LIBSTDCXX: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
 // CHECK-V6M-LIBSTDCXX-NOT: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}v1"
 // CHECK-V6M-LIBSTDCXX-SAME: "-internal-isystem" "{{[^"]+}}{{[/\\]+}}include{{[/\\]+}}c++{{[/\\]+}}6.0.0"
-// CHECK-V6M-LIBSTDCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-LIBSTDCXX: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic" "-EL"
 // CHECK-V6M-LIBSTDCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}Inputs{{[/\\]+}}baremetal_arm{{[/\\]+}}lib"
 // CHECK-V6M-LIBSTDCXX-SAME: "-L[[RESOURCE_DIR]]{{[/\\]+}}lib{{[/\\]+}}baremetal"
 // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind"
@@ -77,7 +77,7 @@
 // RUN: -nodefaultlibs \
 // RUN:   | FileCheck --check-prefix=CHECK-V6M-NDL %s
 // CHECK-V6M-NDL: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
-// CHECK-V6M-NDL: ld{{(.exe)?}}" "{{.*}}.o" "-Bstatic"
+// CHECK-V6M-NDL: ld{{(.exe)?}}" "

[PATCH] D154681: [RISCV] Split __builtin_riscv_xperm4/8 into separate _32 and _64 builtins.

2023-07-09 Thread Alex Bradbury via Phabricator via cfe-commits
asb accepted this revision.
asb added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154681

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


[PATCH] D154683: [RISCV] Split __builtin_riscv_brev8 into _32 and _64 builtin.

2023-07-09 Thread Alex Bradbury via Phabricator via cfe-commits
asb accepted this revision.
asb added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154683

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


[clang] 1402c43 - [clang][Interp][NFC] Remove duplicate private specifier

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

Author: Timm Bäder
Date: 2023-07-09T15:49:32+02:00
New Revision: 1402c4313820da984805b70e1bb6661217706499

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

LOG: [clang][Interp][NFC] Remove duplicate private specifier

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/Source.h b/clang/lib/AST/Interp/Source.h
index 99ffce34c12fa6..a836eb09db7f86 100644
--- a/clang/lib/AST/Interp/Source.h
+++ b/clang/lib/AST/Interp/Source.h
@@ -56,12 +56,9 @@ class CodePtr final {
   }
 
 private:
+  friend class Function;
   /// Constructor used by Function to generate pointers.
   CodePtr(const char *Ptr) : Ptr(Ptr) {}
-
-private:
-  friend class Function;
-
   /// Pointer into the code owned by a function.
   const char *Ptr;
 };



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


[clang] 5191214 - [clang][Interp][NFC] Make some Frame pointers const

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

Author: Timm Bäder
Date: 2023-07-09T15:49:33+02:00
New Revision: 51912142381d190dfa56ef13df1a2f7384391c9d

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

LOG: [clang][Interp][NFC] Make some Frame pointers const

Added: 


Modified: 
clang/lib/AST/Interp/State.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/State.cpp b/clang/lib/AST/Interp/State.cpp
index f67bde1082fa03..9a327fb810de0e 100644
--- a/clang/lib/AST/Interp/State.cpp
+++ b/clang/lib/AST/Interp/State.cpp
@@ -126,9 +126,9 @@ void State::addCallStack(unsigned Limit) {
 
   // Walk the call stack and add the diagnostics.
   unsigned CallIdx = 0;
-  Frame *Top = getCurrentFrame();
+  const Frame *Top = getCurrentFrame();
   const Frame *Bottom = getBottomFrame();
-  for (Frame *F = Top; F != Bottom; F = F->getCaller(), ++CallIdx) {
+  for (const Frame *F = Top; F != Bottom; F = F->getCaller(), ++CallIdx) {
 SourceLocation CallLocation = F->getCallLocation();
 
 // Skip this call?



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


[clang] a83079f - [clang][ConstExpr][NFC] Make Frame::describe() const

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

Author: Timm Bäder
Date: 2023-07-09T15:49:32+02:00
New Revision: a83079f754a529b9a6d21480f834269b847220d3

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

LOG: [clang][ConstExpr][NFC] Make Frame::describe() const

Added: 


Modified: 
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/Interp/Frame.h
clang/lib/AST/Interp/InterpFrame.cpp
clang/lib/AST/Interp/InterpFrame.h

Removed: 




diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index c740aecf32f154..2da4eb772589f9 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -626,7 +626,7 @@ namespace {
 /// Allocate storage for a parameter of a function call made in this frame.
 APValue &createParam(CallRef Args, const ParmVarDecl *PVD, LValue &LV);
 
-void describe(llvm::raw_ostream &OS) override;
+void describe(llvm::raw_ostream &OS) const override;
 
 Frame *getCaller() const override { return Caller; }
 SourceLocation getCallLocation() const override { return CallLoc; }
@@ -1914,7 +1914,7 @@ APValue *EvalInfo::createHeapAlloc(const Expr *E, 
QualType T, LValue &LV) {
 }
 
 /// Produce a string describing the given constexpr call.
-void CallStackFrame::describe(raw_ostream &Out) {
+void CallStackFrame::describe(raw_ostream &Out) const {
   unsigned ArgIndex = 0;
   bool IsMemberCall = isa(Callee) &&
   !isa(Callee) &&

diff  --git a/clang/lib/AST/Interp/Frame.h b/clang/lib/AST/Interp/Frame.h
index b9a0ea9412f838..304f0d108cab7b 100644
--- a/clang/lib/AST/Interp/Frame.h
+++ b/clang/lib/AST/Interp/Frame.h
@@ -27,7 +27,7 @@ class Frame {
   virtual ~Frame();
 
   /// Generates a human-readable description of the call site.
-  virtual void describe(llvm::raw_ostream &OS) = 0;
+  virtual void describe(llvm::raw_ostream &OS) const = 0;
 
   /// Returns a pointer to the caller frame.
   virtual Frame *getCaller() const = 0;

diff  --git a/clang/lib/AST/Interp/InterpFrame.cpp 
b/clang/lib/AST/Interp/InterpFrame.cpp
index 14b55bea882068..d1b6c0d68041e5 100644
--- a/clang/lib/AST/Interp/InterpFrame.cpp
+++ b/clang/lib/AST/Interp/InterpFrame.cpp
@@ -144,7 +144,7 @@ void print(llvm::raw_ostream &OS, const Pointer &P, 
ASTContext &Ctx,
   }
 }
 
-void InterpFrame::describe(llvm::raw_ostream &OS) {
+void InterpFrame::describe(llvm::raw_ostream &OS) const {
   const FunctionDecl *F = getCallee();
   if (const auto *M = dyn_cast(F);
   M && M->isInstance() && !isa(F)) {

diff  --git a/clang/lib/AST/Interp/InterpFrame.h 
b/clang/lib/AST/Interp/InterpFrame.h
index 7988e74a61fe83..ce58fb8d3f84eb 100644
--- a/clang/lib/AST/Interp/InterpFrame.h
+++ b/clang/lib/AST/Interp/InterpFrame.h
@@ -50,7 +50,7 @@ class InterpFrame final : public Frame {
   void popArgs();
 
   /// Describes the frame with arguments for diagnostic purposes.
-  void describe(llvm::raw_ostream &OS) override;
+  void describe(llvm::raw_ostream &OS) const override;
 
   /// Returns the parent frame object.
   Frame *getCaller() const override;



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


[PATCH] D154287: [clang-tidy] Add modernize-use-std-format check

2023-07-09 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked 9 inline comments as done.
mikecrowe added a comment.

Thanks for the reviews!




Comment at: clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp:81
+ << ReplacementFormatFunction
+ << OldFunction->getIdentifier()
+ << Converter.conversionNotPossibleReason();

PiotrZSL wrote:
> using ``<< OldFunction`` should be sufficient and more safe, same in line 88
I don't think that's the same. If I use just `OldFunction` then I get the 
template arguments in strings like `StrFormat` and `sprintf` when I just want `StrFormat` 
and `sprintf` respectively.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:629-630
+  if (Config.AllowTrailingNewlineRemoval &&
+  StringRef(StandardFormatString).ends_with("\\n") &&
   !StringRef(StandardFormatString).ends_with("n")) {
 UsePrintNewlineFunction = true;

PiotrZSL wrote:
> what if it's ends with Windows new line style ? Will it work ?
Good point. Your question actually relates to the `modernize-use-std-print` 
check only since `config.AllowTrailingNewlineRemoval` is always `false` in this 
check.

`std::println` is [[ https://en.cppreference.com/w/cpp/io/println | described 
]] as just appending `\n` to the end of the formatted string when written to 
the desired output. The code here means that `printf("A\r\n")` would be 
converted to `std::println("A\r")` which would behave in the same way, though I 
would admit that it's rather confusing.

This situation isn't really Windows-specific. Most the of the time a POSIX tty 
would be in cooked mode, so the `\r` would be added automatically before the 
`\n`. However, when the tty is in raw mode using `\r\n` line endings would be 
necessary there too, just as they might be on Windows when writing to a binary 
stream.

I think that the least confusing outcome would be for this code to not consider 
format strings that end with `\r\n`  to be suitable for conversion to 
`std::println` and let them use `std::print` instead. I think that this better 
reflects the intent of the existing code.

I will prepare a separate change for this.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst:27
+The check uses the same format-string-conversion algorithm as
+`modernize-use-std-print ` and its
+shortcomings are described in the documentation for that check.

PiotrZSL wrote:
> is this link correct ? shouldn't this be put into `doc:`, verify if its 
> working
It was wrong, but I believe that I've fixed it.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst:33
+
+.. option:: StrictMode TODO
+

PiotrZSL wrote:
> If not implemented, do not add it
It is implemented, I just forgot to remove the TODO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154287

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


[PATCH] D154788: [clang-tidy] Don't split \r\n in modernize-use-std-print check

2023-07-09 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe created this revision.
mikecrowe added a reviewer: PiotrZSL.
Herald added subscribers: carlosgalvezp, xazax.hun.
Herald added a reviewer: njames93.
Herald added a project: All.
mikecrowe requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

When given:
 printf("Hello\r\n");

it's clearer to leave the CRLF intact and convert this to:
 std::print("Hello\r\n");

than to remove the trailing newline and convert it to:
 std::println("Hello\r");

Update the documentation to match, and clarify the situations for using
println vs print which weren't previously explained.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154788

Files:
  clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
@@ -44,6 +44,16 @@
   // CHECK-FIXES: std::println("Hello");
 }
 
+void printf_crlf_newline() {
+  printf("Hello\r\n");
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::print' instead of 
'printf' [modernize-use-std-print]
+  // CHECK-FIXES: std::print("Hello\r\n");
+
+  printf("Hello\r\\n");
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::print' instead of 
'printf' [modernize-use-std-print]
+  // CHECK-FIXES: std::print("Hello\r\\n");
+}
+
 // std::print returns nothing, so any callers that use the return
 // value cannot be automatically translated.
 int printf_uses_return_value(int choice) {
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
@@ -70,8 +70,10 @@
   `FprintfLikeFunctions` are replaced with the function specified by the
   `ReplacementPrintlnFunction` option if the format string ends with ``\n``
   or `ReplacementPrintFunction` otherwise.
-- the format string is rewritten to use the ``std::formatter`` language and
-  a ``\n`` is removed from the end.
+- the format string is rewritten to use the ``std::formatter`` language. If
+  a ``\n`` is found at the end of the format string not preceded by ``r``
+  then it is removed and `ReplacementPrintlnFunction` is used rather than
+  `ReplacementPrintFunction`.
 - any arguments that corresponded to ``%p`` specifiers that
   ``std::formatter`` wouldn't accept are wrapped in a ``static_cast``
   to ``const void *``.
Index: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
===
--- clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
+++ clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
@@ -623,8 +623,11 @@
 PrintfFormatString.size() - PrintfFormatStringPos));
   PrintfFormatStringPos = PrintfFormatString.size();
 
+  // It's clearer to convert printf("Hello\r\n"); to std::print("Hello\r\n")
+  // than to std::println("Hello\r");
   if (StringRef(StandardFormatString).ends_with("\\n") &&
-  !StringRef(StandardFormatString).ends_with("n")) {
+  !StringRef(StandardFormatString).ends_with("n") &&
+  !StringRef(StandardFormatString).ends_with("\\r\\n")) {
 UsePrintNewlineFunction = true;
 FormatStringNeededRewriting = true;
 StandardFormatString.erase(StandardFormatString.end() - 2,


Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp
@@ -44,6 +44,16 @@
   // CHECK-FIXES: std::println("Hello");
 }
 
+void printf_crlf_newline() {
+  printf("Hello\r\n");
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::print' instead of 'printf' [modernize-use-std-print]
+  // CHECK-FIXES: std::print("Hello\r\n");
+
+  printf("Hello\r\\n");
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::print' instead of 'printf' [modernize-use-std-print]
+  // CHECK-FIXES: std::print("Hello\r\\n");
+}
+
 // std::print returns nothing, so any callers that use the return
 // value cannot be automatically translated.
 int printf_uses_return_value(int choice) {
Index: clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.

[PATCH] D154287: [clang-tidy] Add modernize-use-std-format check

2023-07-09 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe updated this revision to Diff 538427.
mikecrowe marked 3 inline comments as done.
mikecrowe added a comment.

Address review comments and improve documentation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154287

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.h
  clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp
  clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp
  clang-tools-extra/clang-tidy/utils/FormatStringConverter.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-format.rst
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-custom.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp
  clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp
@@ -0,0 +1,75 @@
+// RUN: %check_clang_tidy \
+// RUN:   -std=c++20 %s modernize-use-std-format %t -- \
+// RUN:   -config="{CheckOptions: [{key: StrictMode, value: true}]}" \
+// RUN:   -- -isystem %clang_tidy_headers
+// RUN: %check_clang_tidy \
+// RUN:   -std=c++20 %s modernize-use-std-format %t -- \
+// RUN:   -config="{CheckOptions: [{key: StrictMode, value: false}]}" \
+// RUN:   -- -isystem %clang_tidy_headers
+#include 
+// CHECK-FIXES: #include 
+
+namespace absl
+{
+// Use const char * for the format since the real type is hard to mock up.
+template 
+std::string StrFormat(const char *format, const Args&... args);
+} // namespace absl
+
+std::string StrFormat_simple() {
+  return absl::StrFormat("Hello");
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("Hello");
+}
+
+std::string StrFormat_complex(const char *name, double value) {
+  return absl::StrFormat("'%s'='%f'", name, value);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("'{}'='{:f}'", name, value);
+}
+
+std::string StrFormat_integer_conversions() {
+  return absl::StrFormat("int:%d int:%d char:%c char:%c", 65, 'A', 66, 'B');
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("int:{} int:{:d} char:{:c} char:{}", 65, 'A', 66, 'B');
+}
+
+// FormatConverter is capable of removing newlines from the end of the format
+// string. Ensure that isn't incorrectly happening for std::format.
+std::string StrFormat_no_newline_removal() {
+  return absl::StrFormat("a line\n");
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("a line\n");
+}
+
+// FormatConverter is capable of removing newlines from the end of the format
+// string. Ensure that isn't incorrectly happening for std::format.
+std::string StrFormat_cstr_removal(const std::string &s1, const std::string *s2) {
+  return absl::StrFormat("%s %s %s %s", s1.c_str(), s1.data(), s2->c_str(), s2->data());
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("{} {} {} {}", s1, s1, *s2, *s2);
+}
+
+std::string StrFormat_strict_conversion() {
+  const unsigned char uc = 'A';
+  return absl::StrFormat("Integer %hhd from unsigned char\n", uc);
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: return std::format("Integer {} from unsigned char\n", uc);
+}
+
+std::string StrFormat_field_width_and_precision() {
+  auto s1 = absl::StrFormat("width only:%*d width and precision:%*.*f precision only:%.*f", 3, 42, 4, 2, 3.14159265358979323846, 5, 2.718);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("width only:{:{}} width and precision:{:{}.{}f} precision only:{:.{}f}", 42, 3, 3.14159265358979323846, 4, 2, 2.718, 5);
+
+  auto s2 = absl::StrFormat("width and precision positional:%1$*2$.*3$f after", 3.14159265358979323846, 4, 2);
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: use 'std::format' instead of 'StrFormat' [modernize-use-std-format]
+  // CHECK-FIXES: std::format("width and precision positional:{0:{1}.{2}f} after", 3.14159265358979323846, 4, 2);
+
+  c

[clang] 3262aea - [clang][Interp][NFC] Add missing return statement

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

Author: Timm Bäder
Date: 2023-07-09T16:13:18+02:00
New Revision: 3262aea06d36b1fbf3eb16d47afec742c18fd5e8

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

LOG: [clang][Interp][NFC] Add missing return statement

I removed the else here, but forgot to add a return before.
Interestingly, none of the existing test cases triggered a problem. A
future commit will add a test case.

Added: 


Modified: 
clang/lib/AST/Interp/Pointer.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index 9c55a55d42a74f..5b304019b511e0 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -185,6 +185,7 @@ void Pointer::initialize() const {
   free(Map);
   Map = (InitMap *)-1;
 }
+return;
   }
 
   // Field has its bit in an inline descriptor.



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


[clang] b9e1679 - [clang][Interp][NFC] Clear stack memory even on success

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

Author: Timm Bäder
Date: 2023-07-09T16:13:19+02:00
New Revision: b9e167994f01172c20716de28ea24f202b45b6a7

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

LOG: [clang][Interp][NFC] Clear stack memory even on success

This makes it easier to use asan to find memory problems. clear() will
actually free the memory.

Added: 


Modified: 
clang/lib/AST/Interp/Context.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index 9d093ba1ad65b0..eeb7fa9379f5cc 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -55,6 +55,11 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, 
APValue &Result) {
   ByteCodeExprGen C(*this, *P, Parent, Stk, Result);
   if (Check(Parent, C.interpretExpr(E))) {
 assert(Stk.empty());
+#ifndef NDEBUG
+// Make sure we don't rely on some value being still alive in
+// InterpStack memory.
+Stk.clear();
+#endif
 return true;
   }
 
@@ -68,6 +73,11 @@ bool Context::evaluateAsInitializer(State &Parent, const 
VarDecl *VD,
   ByteCodeExprGen C(*this, *P, Parent, Stk, Result);
   if (Check(Parent, C.interpretDecl(VD))) {
 assert(Stk.empty());
+#ifndef NDEBUG
+// Make sure we don't rely on some value being still alive in
+// InterpStack memory.
+Stk.clear();
+#endif
 return true;
   }
 



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


[clang] 88d65e1 - [clang][Interp][NFC] Fix a doc comment mixup

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

Author: Timm Bäder
Date: 2023-07-09T16:13:19+02:00
New Revision: 88d65e13464ab200f36082bf4f2613835e677144

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

LOG: [clang][Interp][NFC] Fix a doc comment mixup

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBlock.h 
b/clang/lib/AST/Interp/InterpBlock.h
index 8c95d8e122be48..059a32491cfebb 100644
--- a/clang/lib/AST/Interp/InterpBlock.h
+++ b/clang/lib/AST/Interp/InterpBlock.h
@@ -118,10 +118,10 @@ class Block final {
   Block(Descriptor *Desc, bool IsExtern, bool IsStatic, bool IsDead)
 : IsStatic(IsStatic), IsExtern(IsExtern), IsDead(true), Desc(Desc) {}
 
-  // Deletes a dead block at the end of its lifetime.
+  /// Deletes a dead block at the end of its lifetime.
   void cleanup();
 
-  // Pointer chain management.
+  /// Pointer chain management.
   void addPointer(Pointer *P);
   void removePointer(Pointer *P);
   void movePointer(Pointer *From, Pointer *To);



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


[clang] fa1e9c3 - [clang][Interp][NFC] Add std:: qualifiers to all malloc/free calls

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

Author: Timm Bäder
Date: 2023-07-09T16:13:19+02:00
New Revision: fa1e9c3a5aacb1183fa3da410cb9dfd24b1a6d15

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

LOG: [clang][Interp][NFC] Add std:: qualifiers to all malloc/free calls

Added: 


Modified: 
clang/lib/AST/Interp/InterpBlock.cpp
clang/lib/AST/Interp/InterpStack.cpp
clang/lib/AST/Interp/InterpState.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBlock.cpp 
b/clang/lib/AST/Interp/InterpBlock.cpp
index ed6e8910194d8d..c2a2ba70f4cd32 100644
--- a/clang/lib/AST/Interp/InterpBlock.cpp
+++ b/clang/lib/AST/Interp/InterpBlock.cpp
@@ -83,5 +83,5 @@ void DeadBlock::free() {
 Next->Prev = Prev;
   if (Root == this)
 Root = Next;
-  ::free(this);
+  std::free(this);
 }

diff  --git a/clang/lib/AST/Interp/InterpStack.cpp 
b/clang/lib/AST/Interp/InterpStack.cpp
index 63a088be670592..592e22ed77b9f7 100644
--- a/clang/lib/AST/Interp/InterpStack.cpp
+++ b/clang/lib/AST/Interp/InterpStack.cpp
@@ -19,9 +19,9 @@ InterpStack::~InterpStack() {
 
 void InterpStack::clear() {
   if (Chunk && Chunk->Next)
-free(Chunk->Next);
+std::free(Chunk->Next);
   if (Chunk)
-free(Chunk);
+std::free(Chunk);
   Chunk = nullptr;
   StackSize = 0;
 }
@@ -33,7 +33,7 @@ void *InterpStack::grow(size_t Size) {
 if (Chunk && Chunk->Next) {
   Chunk = Chunk->Next;
 } else {
-  StackChunk *Next = new (malloc(ChunkSize)) StackChunk(Chunk);
+  StackChunk *Next = new (std::malloc(ChunkSize)) StackChunk(Chunk);
   if (Chunk)
 Chunk->Next = Next;
   Chunk = Next;
@@ -65,7 +65,7 @@ void InterpStack::shrink(size_t Size) {
   while (Size > Chunk->size()) {
 Size -= Chunk->size();
 if (Chunk->Next) {
-  free(Chunk->Next);
+  std::free(Chunk->Next);
   Chunk->Next = nullptr;
 }
 Chunk->End = Chunk->start();

diff  --git a/clang/lib/AST/Interp/InterpState.cpp 
b/clang/lib/AST/Interp/InterpState.cpp
index abc29e059aa9f0..2596c56b4e095c 100644
--- a/clang/lib/AST/Interp/InterpState.cpp
+++ b/clang/lib/AST/Interp/InterpState.cpp
@@ -28,7 +28,7 @@ InterpState::~InterpState() {
 
   while (DeadBlocks) {
 DeadBlock *Next = DeadBlocks->Next;
-free(DeadBlocks);
+std::free(DeadBlocks);
 DeadBlocks = Next;
   }
 }
@@ -54,7 +54,8 @@ void InterpState::deallocate(Block *B) {
 size_t Size = B->getSize();
 
 // Allocate a new block, transferring over pointers.
-char *Memory = reinterpret_cast(malloc(sizeof(DeadBlock) + Size));
+char *Memory =
+reinterpret_cast(std::malloc(sizeof(DeadBlock) + Size));
 auto *D = new (Memory) DeadBlock(DeadBlocks, B);
 
 // Move data from one block to another.



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


[PATCH] D154788: [clang-tidy] Don't split \r\n in modernize-use-std-print check

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

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154788

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


[clang] 254ad7d - [clang][Interp][NFC] Move isGloballyIndexed() to Context

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

Author: Timm Bäder
Date: 2023-07-09T16:27:49+02:00
New Revision: 254ad7dd412308855ca29b97e9fd8079088cbef5

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

LOG: [clang][Interp][NFC] Move isGloballyIndexed() to Context

And use it in Program as well, to make a similar decision.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Context.h
clang/lib/AST/Interp/Program.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 86200f9ad08313..4f61f87b0fd241 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1617,7 +1617,7 @@ bool ByteCodeExprGen::visitDecl(const VarDecl 
*VD) {
 return false;
 
   // Get a pointer to the variable
-  if (shouldBeGloballyIndexed(VD)) {
+  if (Context::shouldBeGloballyIndexed(VD)) {
 auto GlobalIndex = P.getGlobal(VD);
 assert(GlobalIndex); // visitVarDecl() didn't return false.
 if (!this->emitGetPtrGlobal(*GlobalIndex, VD))
@@ -1649,7 +1649,7 @@ bool ByteCodeExprGen::visitVarDecl(const VarDecl 
*VD) {
   const Expr *Init = VD->getInit();
   std::optional VarT = classify(VD->getType());
 
-  if (shouldBeGloballyIndexed(VD)) {
+  if (Context::shouldBeGloballyIndexed(VD)) {
 // We've already seen and initialized this global.
 if (P.getGlobal(VD))
   return true;

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 83bafeb9aac616..57b0af9459e3ab 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -247,15 +247,6 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 return T->getAsCXXRecordDecl();
   }
 
-  /// Returns whether we should create a global variable for the
-  /// given ValueDecl.
-  bool shouldBeGloballyIndexed(const ValueDecl *VD) const {
-if (const auto *V = dyn_cast(VD))
-  return V->hasGlobalStorage() || V->isConstexpr();
-
-return false;
-  }
-
   llvm::RoundingMode getRoundingMode(const Expr *E) const {
 FPOptions FPO = E->getFPFeaturesInEffect(Ctx.getLangOpts());
 

diff  --git a/clang/lib/AST/Interp/Context.h b/clang/lib/AST/Interp/Context.h
index 8879186f7072ec..19d480d912116b 100644
--- a/clang/lib/AST/Interp/Context.h
+++ b/clang/lib/AST/Interp/Context.h
@@ -67,6 +67,14 @@ class Context final {
   getOverridingFunction(const CXXRecordDecl *DynamicDecl,
 const CXXRecordDecl *StaticDecl,
 const CXXMethodDecl *InitialFunction) const;
+  /// Returns whether we should create a global variable for the
+  /// given ValueDecl.
+  static bool shouldBeGloballyIndexed(const ValueDecl *VD) {
+if (const auto *V = dyn_cast(VD))
+  return V->hasGlobalStorage() || V->isConstexpr();
+
+return false;
+  }
 
 private:
   /// Runs a function.

diff  --git a/clang/lib/AST/Interp/Program.cpp 
b/clang/lib/AST/Interp/Program.cpp
index 5adc4cf3b54748..1ebf9e8cbb1655 100644
--- a/clang/lib/AST/Interp/Program.cpp
+++ b/clang/lib/AST/Interp/Program.cpp
@@ -162,7 +162,7 @@ std::optional Program::createGlobal(const 
ValueDecl *VD,
   assert(!getGlobal(VD));
   bool IsStatic, IsExtern;
   if (auto *Var = dyn_cast(VD)) {
-IsStatic = !Var->hasLocalStorage();
+IsStatic = Context::shouldBeGloballyIndexed(VD);
 IsExtern = !Var->getAnyInitializer();
   } else {
 IsStatic = false;



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


[clang] 193db1e - [clang][Interp][NFC] Make pointer chain management more robust

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

Author: Timm Bäder
Date: 2023-07-09T16:27:49+02:00
New Revision: 193db1ebf09ac8a7661b4273e2847de34430a9af

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

LOG: [clang][Interp][NFC] Make pointer chain management more robust

Add a bunch of assertions to ensure we're doing the right thing. Also,
rename movePointer to replacePointer, since the old name didn't make
much sense.

Added: 


Modified: 
clang/lib/AST/Interp/InterpBlock.cpp
clang/lib/AST/Interp/InterpBlock.h
clang/lib/AST/Interp/Pointer.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/InterpBlock.cpp 
b/clang/lib/AST/Interp/InterpBlock.cpp
index c2a2ba70f4cd32..a62128d9cfaedd 100644
--- a/clang/lib/AST/Interp/InterpBlock.cpp
+++ b/clang/lib/AST/Interp/InterpBlock.cpp
@@ -16,11 +16,16 @@
 using namespace clang;
 using namespace clang::interp;
 
-
-
 void Block::addPointer(Pointer *P) {
-  if (IsStatic)
+  assert(P);
+  if (IsStatic) {
+assert(!Pointers);
 return;
+  }
+
+#ifndef NDEBUG
+  assert(!hasPointer(P));
+#endif
   if (Pointers)
 Pointers->Prev = P;
   P->Next = Pointers;
@@ -29,10 +34,19 @@ void Block::addPointer(Pointer *P) {
 }
 
 void Block::removePointer(Pointer *P) {
-  if (IsStatic)
+  assert(P);
+  if (IsStatic) {
+assert(!Pointers);
 return;
+  }
+
+#ifndef NDEBUG
+  assert(hasPointer(P));
+#endif
+
   if (Pointers == P)
 Pointers = P->Next;
+
   if (P->Prev)
 P->Prev->Next = P->Next;
   if (P->Next)
@@ -44,21 +58,38 @@ void Block::cleanup() {
 (reinterpret_cast(this + 1) - 1)->free();
 }
 
-void Block::movePointer(Pointer *From, Pointer *To) {
-  if (IsStatic)
+void Block::replacePointer(Pointer *Old, Pointer *New) {
+  assert(Old);
+  assert(New);
+  if (IsStatic) {
+assert(!Pointers);
 return;
-  To->Prev = From->Prev;
-  if (To->Prev)
-To->Prev->Next = To;
-  To->Next = From->Next;
-  if (To->Next)
-To->Next->Prev = To;
-  if (Pointers == From)
-Pointers = To;
-
-  From->Prev = nullptr;
-  From->Next = nullptr;
+  }
+
+#ifndef NDEBUG
+  assert(hasPointer(Old));
+#endif
+
+  removePointer(Old);
+  addPointer(New);
+
+  Old->Pointee = nullptr;
+
+#ifndef NDEBUG
+  assert(!hasPointer(Old));
+  assert(hasPointer(New));
+#endif
+}
+
+#ifndef NDEBUG
+bool Block::hasPointer(const Pointer *P) const {
+  for (const Pointer *C = Pointers; C; C = C->Next) {
+if (C == P)
+  return true;
+  }
+  return false;
 }
+#endif
 
 DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
 : Root(Root), B(Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {

diff  --git a/clang/lib/AST/Interp/InterpBlock.h 
b/clang/lib/AST/Interp/InterpBlock.h
index 059a32491cfebb..0080dad718edd2 100644
--- a/clang/lib/AST/Interp/InterpBlock.h
+++ b/clang/lib/AST/Interp/InterpBlock.h
@@ -124,7 +124,10 @@ class Block final {
   /// Pointer chain management.
   void addPointer(Pointer *P);
   void removePointer(Pointer *P);
-  void movePointer(Pointer *From, Pointer *To);
+  void replacePointer(Pointer *Old, Pointer *New);
+#ifndef NDEBUG
+  bool hasPointer(const Pointer *P) const;
+#endif
 
   /// Start of the chain of pointers.
   Pointer *Pointers = nullptr;

diff  --git a/clang/lib/AST/Interp/Pointer.cpp 
b/clang/lib/AST/Interp/Pointer.cpp
index 5b304019b511e0..00943dc846d3b2 100644
--- a/clang/lib/AST/Interp/Pointer.cpp
+++ b/clang/lib/AST/Interp/Pointer.cpp
@@ -24,7 +24,7 @@ Pointer::Pointer(const Pointer &P) : Pointer(P.Pointee, 
P.Base, P.Offset) {}
 Pointer::Pointer(Pointer &&P)
 : Pointee(P.Pointee), Base(P.Base), Offset(P.Offset) {
   if (Pointee)
-Pointee->movePointer(&P, this);
+Pointee->replacePointer(&P, this);
 }
 
 Pointer::Pointer(Block *Pointee, unsigned Base, unsigned Offset)
@@ -69,7 +69,7 @@ void Pointer::operator=(Pointer &&P) {
 
   Pointee = P.Pointee;
   if (Pointee)
-Pointee->movePointer(&P, this);
+Pointee->replacePointer(&P, this);
 
   if (Old)
 Old->cleanup();



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


[clang] c54ff51 - [clang][Interp] Emit correct diagnostic for uninitialized reads

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

Author: Timm Bäder
Date: 2023-07-09T16:27:49+02:00
New Revision: c54ff51be9c1192214eb56fc5c8dea2b73557406

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

LOG: [clang][Interp] Emit correct diagnostic for uninitialized reads

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

Added: 


Modified: 
clang/lib/AST/Interp/Interp.cpp
clang/test/AST/Interp/constexpr-nqueens.cpp
clang/test/AST/Interp/cxx20.cpp
clang/test/AST/Interp/literals.cpp
clang/test/AST/Interp/records.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index cf9e5b8ea6bd29..4917f43f9512ec 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -239,7 +239,8 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
 
   if (!S.checkingPotentialConstantExpression()) {
 const SourceInfo &Loc = S.Current->getSource(OpPC);
-S.FFDiag(Loc, diag::note_constexpr_access_uninit) << AK << false;
+S.FFDiag(Loc, diag::note_constexpr_access_uninit)
+<< AK << /*uninitialized=*/true;
   }
   return false;
 }

diff  --git a/clang/test/AST/Interp/constexpr-nqueens.cpp 
b/clang/test/AST/Interp/constexpr-nqueens.cpp
index 8b8b608fc8c57c..971f99a032b665 100644
--- a/clang/test/AST/Interp/constexpr-nqueens.cpp
+++ b/clang/test/AST/Interp/constexpr-nqueens.cpp
@@ -18,7 +18,7 @@ struct Board {
 Failed(Failed) {}
   constexpr Board addQueen(int Row, int Col) const {
 return Board(State | ((uint64_t)Row << (Col * 4))); // ref-note {{read of 
uninitialized object}} \
-// expected-note 
{{read of object outside its lifetime}}
+// expected-note 
{{read of uninitialized object}}
   }
   constexpr int getQueenRow(int Col) const {
 return (State >> (Col * 4)) & 0xf;

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 87c32e42d053e5..a7d7705c1cefa6 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -59,8 +59,7 @@ static_assert(pointerAssign2() == 12, "");
 constexpr int unInitLocal() {
   int a;
   return a; // ref-note {{read of uninitialized object}} \
-// expected-note {{read of object outside its lifetime}}
-// FIXME: ^^^ Wrong diagnostic.
+// expected-note {{read of uninitialized object}}
 }
 static_assert(unInitLocal() == 0, ""); // ref-error {{not an integral constant 
expression}} \
// ref-note {{in call to 
'unInitLocal()'}} \
@@ -76,7 +75,7 @@ static_assert(initializedLocal() == 20);
 
 constexpr int initializedLocal2() {
   int a[2];
-  return *a; // expected-note {{read of object outside its lifetime}} \
+  return *a; // expected-note {{read of uninitialized object is not allowed in 
a constant expression}} \
  // ref-note {{read of uninitialized object is not allowed in a 
constant expression}}
 }
 static_assert(initializedLocal2() == 20); // expected-error {{not an integral 
constant expression}} \
@@ -89,7 +88,7 @@ struct Int { int a; };
 constexpr int initializedLocal3() {
   Int i;
   return i.a; // ref-note {{read of uninitialized object is not allowed in a 
constant expression}} \
-  // expected-note {{read of object outside its lifetime}}
+  // expected-note {{read of uninitialized object}}
 }
 static_assert(initializedLocal3() == 20); // expected-error {{not an integral 
constant expression}} \
   // expected-note {{in call to}} \
@@ -315,7 +314,7 @@ namespace BaseInit {
 
   static_assert(Final{1, 2, 3}.c == 3, ""); // OK
   static_assert(Final{1, 2, 3}.a == 0, ""); // expected-error {{not an 
integral constant expression}} \
-// expected-note {{read of object 
outside its lifetime}} \
+// expected-note {{read of 
uninitialized object}} \
 // ref-error {{not an integral 
constant expression}} \
 // ref-note {{read of 
uninitialized object}}
 
@@ -337,7 +336,7 @@ namespace BaseInit {
   static_assert(Final2{1, 2, 3}.c == 3, ""); // OK
   static_assert(Final2{1, 2, 3}.b == 2, ""); // OK
   static_assert(Final2{1, 2, 3}.a == 0, ""); // expected-error {{not an 
integral constant expression}} \
- // expected-note {{read of object 
outside its lifetime}} \
+ // expected-note {{read of 
uninitialized object}} \
  // ref-error {{not an integral 
constant ex

[PATCH] D154758: [clang][Interp] Emit correct diagnostic for uninitialized reads

2023-07-09 Thread Timm Bäder 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 rGc54ff51be9c1: [clang][Interp] Emit correct diagnostic for 
uninitialized reads (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D154758?vs=538325&id=538434#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154758

Files:
  clang/lib/AST/Interp/Interp.cpp
  clang/test/AST/Interp/constexpr-nqueens.cpp
  clang/test/AST/Interp/cxx20.cpp
  clang/test/AST/Interp/literals.cpp
  clang/test/AST/Interp/records.cpp

Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -404,7 +404,7 @@
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
  // ref-note {{initializer of 'D' is not a constant expression}} \
  // expected-error {{not an integral constant expression}} \
- // expected-note {{read of object outside its lifetime}}
+ // expected-note {{read of uninitialized object}}
 #endif
 
   struct AnotherBase {
@@ -467,7 +467,7 @@
   constexpr A a{10}; // expected-error {{must be initialized by a constant expression}}
   static_assert(a.m == 10, "");
   static_assert(a.f == 10, ""); // expected-error {{not an integral constant expression}} \
-// expected-note {{read of object outside its lifetime}}
+// expected-note {{read of uninitialized object}}
 
   class Foo {
   public:
Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -467,10 +467,10 @@
 T a;
 if constexpr (Inc)
   ++a; // ref-note 2{{increment of uninitialized}} \
-   // expected-note 2{{increment of object outside its lifetime}}
+   // expected-note 2{{increment of uninitialized}}
 else
   --a; // ref-note 2{{decrement of uninitialized}} \
-   // expected-note 2{{decrement of object outside its lifetime}}
+   // expected-note 2{{decrement of uninitialized}}
 return 1;
   }
   static_assert(uninit(), ""); // ref-error {{not an integral constant expression}} \
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -59,8 +59,7 @@
 constexpr int unInitLocal() {
   int a;
   return a; // ref-note {{read of uninitialized object}} \
-// expected-note {{read of object outside its lifetime}}
-// FIXME: ^^^ Wrong diagnostic.
+// expected-note {{read of uninitialized object}}
 }
 static_assert(unInitLocal() == 0, ""); // ref-error {{not an integral constant expression}} \
// ref-note {{in call to 'unInitLocal()'}} \
@@ -76,7 +75,7 @@
 
 constexpr int initializedLocal2() {
   int a[2];
-  return *a; // expected-note {{read of object outside its lifetime}} \
+  return *a; // expected-note {{read of uninitialized object is not allowed in a constant expression}} \
  // ref-note {{read of uninitialized object is not allowed in a constant expression}}
 }
 static_assert(initializedLocal2() == 20); // expected-error {{not an integral constant expression}} \
@@ -89,7 +88,7 @@
 constexpr int initializedLocal3() {
   Int i;
   return i.a; // ref-note {{read of uninitialized object is not allowed in a constant expression}} \
-  // expected-note {{read of object outside its lifetime}}
+  // expected-note {{read of uninitialized object}}
 }
 static_assert(initializedLocal3() == 20); // expected-error {{not an integral constant expression}} \
   // expected-note {{in call to}} \
@@ -315,7 +314,7 @@
 
   static_assert(Final{1, 2, 3}.c == 3, ""); // OK
   static_assert(Final{1, 2, 3}.a == 0, ""); // expected-error {{not an integral constant expression}} \
-// expected-note {{read of object outside its lifetime}} \
+// expected-note {{read of uninitialized object}} \
 // ref-error {{not an integral constant expression}} \
 // ref-note {{read of uninitialized object}}
 
@@ -337,7 +336,7 @@
   static_assert(Final2{1, 2, 3}.c == 3, ""); // OK
   static_assert(Final2{1, 2, 3}.b == 2, ""); // OK
   static_assert(Final2{1, 2, 3}.a == 0, ""); // expected-error {{not an integral constant expression}} \
-   

[PATCH] D153092: [Clang][CodeGen]`vtable`, `typeinfo` et al. are globals

2023-07-09 Thread Alex Voicu via Phabricator via cfe-commits
AlexVlx updated this revision to Diff 538437.
AlexVlx added a comment.
Herald added a subscriber: wangpc.

Rebase.


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

https://reviews.llvm.org/D153092

Files:
  clang/lib/CodeGen/CGVTT.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/vtable-align-address-space.cpp
  clang/test/CodeGenCXX/vtable-assume-load-address-space.cpp
  clang/test/CodeGenCXX/vtable-consteval-address-space.cpp
  clang/test/CodeGenCXX/vtable-constexpr-address-space.cpp
  clang/test/CodeGenCXX/vtable-key-function-address-space.cpp
  clang/test/CodeGenCXX/vtable-layout-extreme-address-space.cpp
  clang/test/CodeGenCXX/vtable-linkage-address-space.cpp
  clang/test/CodeGenCXX/vtable-pointer-initialization-address-space.cpp
  clang/test/CodeGenCXX/vtt-address-space.cpp
  clang/test/CodeGenCXX/vtt-layout-address-space.cpp
  clang/test/Headers/hip-header.hip

Index: clang/test/Headers/hip-header.hip
===
--- clang/test/Headers/hip-header.hip
+++ clang/test/Headers/hip-header.hip
@@ -43,6 +43,22 @@
 
 // expected-no-diagnostics
 
+// Check handling of overriden, implicitly __host__ dtor (should emit as a
+// nullptr to global)
+
+struct vbase {
+virtual ~vbase();
+};
+
+template
+struct vderived : public vbase {
+~vderived();
+};
+
+template struct vderived;
+
+// CHECK: @_ZTV8vderivedIvE = weak_odr unnamed_addr addrspace(1) constant { [4 x ptr addrspace(1)] } zeroinitializer, comdat, align 8
+
 // Check support for pure and deleted virtual functions
 struct base {
   __host__
@@ -60,9 +76,8 @@
 __device__ void test_vf() {
 derived d;
 }
-// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN7derived2pvEv, ptr @__cxa_deleted_virtual] }, comdat, align 8
-// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @__cxa_pure_virtual, ptr @__cxa_deleted_virtual] }, comdat, align 8
-
+// CHECK: @_ZTV7derived = linkonce_odr unnamed_addr addrspace(1) constant { [4 x ptr addrspace(1)] } { [4 x ptr addrspace(1)] [ptr addrspace(1) null, ptr addrspace(1) null, ptr addrspace(1) addrspacecast (ptr @_ZN7derived2pvEv to ptr addrspace(1)), ptr addrspace(1) addrspacecast (ptr @__cxa_deleted_virtual to ptr addrspace(1))] }, comdat, align 8
+// CHECK: @_ZTV4base = linkonce_odr unnamed_addr addrspace(1) constant { [4 x ptr addrspace(1)] } { [4 x ptr addrspace(1)] [ptr addrspace(1) null, ptr addrspace(1) null, ptr addrspace(1) addrspacecast (ptr @__cxa_pure_virtual to ptr addrspace(1)), ptr addrspace(1) addrspacecast (ptr @__cxa_deleted_virtual to ptr addrspace(1))] }, comdat, align 8
 // CHECK: define{{.*}}void @__cxa_pure_virtual()
 // CHECK: define{{.*}}void @__cxa_deleted_virtual()
 
Index: clang/test/CodeGenCXX/vtt-layout-address-space.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/vtt-layout-address-space.cpp
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 %s -triple=amdgcn-amd-amdhsa -std=c++11 -emit-llvm -o - | FileCheck %s
+
+// Test1::B should just have a single entry in its VTT, which points to the vtable.
+namespace Test1 {
+struct A { };
+
+struct B : virtual A {
+  virtual void f();
+};
+
+void B::f() { }
+}
+
+// Check that we don't add a secondary virtual pointer for Test2::A, since Test2::A doesn't have any virtual member functions or bases.
+namespace Test2 {
+  struct A { };
+
+  struct B : A { virtual void f(); };
+  struct C : virtual B { };
+
+  C c;
+}
+
+// This is the sample from the C++ Itanium ABI, p2.6.2.
+namespace Test3 {
+  class A1 { int i; };
+  class A2 { int i; virtual void f(); };
+  class V1 : public A1, public A2 { int i; };
+  class B1 { int i; };
+  class B2 { int i; };
+  class V2 : public B1, public B2, public virtual V1 { int i; };
+  class V3 {virtual void g(); };
+  class C1 : public virtual V1 { int i; };
+  class C2 : public virtual V3, virtual V2 { int i; };
+  class X1 { int i; };
+  class C3 : public X1 { int i; };
+  class D : public C1, public C2, public C3 { int i;  };
+
+  D d;
+}
+
+// This is the sample from the C++ Itanium ABI, p2.6.2, with the change suggested
+// (making A2 a virtual base of V1)
+namespace Test4 {
+  class A1 { int i; };
+  class A2 { int i; virtual void f(); };
+  class V1 : public A1, public virtual A2 { int i; };
+  class B1 { int i; };
+  class B2 { int i; };
+  class V2 : public B1, public B2, public virtual V1 { int i; };
+  class V3 {virtual void g(); };
+  class C1 : public virtual V1 { int i; };
+  class C2 : public virtual V3, virtual V2 { int i; };
+  class X1 { int i; };
+  class C3 : public X1 { int i; };
+  class D : public C1, public C2, public C3 { int i;  };
+
+  D d;
+}
+
+namespace Test5 {
+  struct A {
+virtual void f() = 0;
+virtual void anchor()

[clang] 5704630 - [RISCV] Remove redundant _ta suffix in RVV intrinsics builtins. NFC

2023-07-09 Thread via cfe-commits

Author: eopXD
Date: 2023-07-09T08:40:36-07:00
New Revision: 5704630ec40dbf1ebc7b16181b226e1545f8eb5c

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

LOG: [RISCV] Remove redundant _ta suffix in RVV intrinsics builtins. NFC

Reviewed By: craig.topper

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

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/lib/Support/RISCVVIntrinsicUtils.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 294d9bfac73a5c..3284cf1b4f91be 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4697,24 +4697,24 @@ bool Sema::CheckRISCVBuiltinFunctionCall(const 
TargetInfo &TI,
   case RISCV::BI__builtin_riscv_aes64ks1i_64:
 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 10);
   // Check if value range for vxrm is in [0, 3]
-  case RISCVVector::BI__builtin_rvv_vaaddu_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vaaddu_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vaadd_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vaadd_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vasubu_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vasubu_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vasub_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vasub_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vsmul_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vsmul_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vssra_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vssra_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vssrl_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vssrl_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vnclip_wv_ta:
-  case RISCVVector::BI__builtin_rvv_vnclip_wx_ta:
-  case RISCVVector::BI__builtin_rvv_vnclipu_wv_ta:
-  case RISCVVector::BI__builtin_rvv_vnclipu_wx_ta:
+  case RISCVVector::BI__builtin_rvv_vaaddu_vv:
+  case RISCVVector::BI__builtin_rvv_vaaddu_vx:
+  case RISCVVector::BI__builtin_rvv_vaadd_vv:
+  case RISCVVector::BI__builtin_rvv_vaadd_vx:
+  case RISCVVector::BI__builtin_rvv_vasubu_vv:
+  case RISCVVector::BI__builtin_rvv_vasubu_vx:
+  case RISCVVector::BI__builtin_rvv_vasub_vv:
+  case RISCVVector::BI__builtin_rvv_vasub_vx:
+  case RISCVVector::BI__builtin_rvv_vsmul_vv:
+  case RISCVVector::BI__builtin_rvv_vsmul_vx:
+  case RISCVVector::BI__builtin_rvv_vssra_vv:
+  case RISCVVector::BI__builtin_rvv_vssra_vx:
+  case RISCVVector::BI__builtin_rvv_vssrl_vv:
+  case RISCVVector::BI__builtin_rvv_vssrl_vx:
+  case RISCVVector::BI__builtin_rvv_vnclip_wv:
+  case RISCVVector::BI__builtin_rvv_vnclip_wx:
+  case RISCVVector::BI__builtin_rvv_vnclipu_wv:
+  case RISCVVector::BI__builtin_rvv_vnclipu_wx:
 return SemaBuiltinConstantArgRange(TheCall, 2, 0, 3);
   case RISCVVector::BI__builtin_rvv_vaaddu_vv_tu:
   case RISCVVector::BI__builtin_rvv_vaaddu_vx_tu:

diff  --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp 
b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
index b7406f7b672a62..cba4ab7c675886 100644
--- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -1080,10 +1080,9 @@ void RVVIntrinsic::updateNamesAndPolicy(bool IsMasked, 
bool HasPolicy,
   } else {
 if (PolicyAttrs.isTUPolicy())
   appendPolicySuffix("_tu");
-else if (PolicyAttrs.isTAPolicy()) {
-  if (HasPolicy)
-BuiltinName += "_ta";
-} else
+else if (PolicyAttrs.isTAPolicy()) // no suffix needed
+  return;
+else
   llvm_unreachable("Unhandled policy condition");
   }
 }



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


[PATCH] D154693: [RISCV] Remove redundant _ta suffix in RVV intrinsics builtins. NFC

2023-07-09 Thread Yueh-Ting (eop) Chen 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 rG5704630ec40d: [RISCV] Remove redundant _ta suffix in RVV 
intrinsics builtins. NFC (authored by eopXD).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154693

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Support/RISCVVIntrinsicUtils.cpp


Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -1080,10 +1080,9 @@
   } else {
 if (PolicyAttrs.isTUPolicy())
   appendPolicySuffix("_tu");
-else if (PolicyAttrs.isTAPolicy()) {
-  if (HasPolicy)
-BuiltinName += "_ta";
-} else
+else if (PolicyAttrs.isTAPolicy()) // no suffix needed
+  return;
+else
   llvm_unreachable("Unhandled policy condition");
   }
 }
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4697,24 +4697,24 @@
   case RISCV::BI__builtin_riscv_aes64ks1i_64:
 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 10);
   // Check if value range for vxrm is in [0, 3]
-  case RISCVVector::BI__builtin_rvv_vaaddu_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vaaddu_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vaadd_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vaadd_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vasubu_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vasubu_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vasub_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vasub_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vsmul_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vsmul_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vssra_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vssra_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vssrl_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vssrl_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vnclip_wv_ta:
-  case RISCVVector::BI__builtin_rvv_vnclip_wx_ta:
-  case RISCVVector::BI__builtin_rvv_vnclipu_wv_ta:
-  case RISCVVector::BI__builtin_rvv_vnclipu_wx_ta:
+  case RISCVVector::BI__builtin_rvv_vaaddu_vv:
+  case RISCVVector::BI__builtin_rvv_vaaddu_vx:
+  case RISCVVector::BI__builtin_rvv_vaadd_vv:
+  case RISCVVector::BI__builtin_rvv_vaadd_vx:
+  case RISCVVector::BI__builtin_rvv_vasubu_vv:
+  case RISCVVector::BI__builtin_rvv_vasubu_vx:
+  case RISCVVector::BI__builtin_rvv_vasub_vv:
+  case RISCVVector::BI__builtin_rvv_vasub_vx:
+  case RISCVVector::BI__builtin_rvv_vsmul_vv:
+  case RISCVVector::BI__builtin_rvv_vsmul_vx:
+  case RISCVVector::BI__builtin_rvv_vssra_vv:
+  case RISCVVector::BI__builtin_rvv_vssra_vx:
+  case RISCVVector::BI__builtin_rvv_vssrl_vv:
+  case RISCVVector::BI__builtin_rvv_vssrl_vx:
+  case RISCVVector::BI__builtin_rvv_vnclip_wv:
+  case RISCVVector::BI__builtin_rvv_vnclip_wx:
+  case RISCVVector::BI__builtin_rvv_vnclipu_wv:
+  case RISCVVector::BI__builtin_rvv_vnclipu_wx:
 return SemaBuiltinConstantArgRange(TheCall, 2, 0, 3);
   case RISCVVector::BI__builtin_rvv_vaaddu_vv_tu:
   case RISCVVector::BI__builtin_rvv_vaaddu_vx_tu:


Index: clang/lib/Support/RISCVVIntrinsicUtils.cpp
===
--- clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -1080,10 +1080,9 @@
   } else {
 if (PolicyAttrs.isTUPolicy())
   appendPolicySuffix("_tu");
-else if (PolicyAttrs.isTAPolicy()) {
-  if (HasPolicy)
-BuiltinName += "_ta";
-} else
+else if (PolicyAttrs.isTAPolicy()) // no suffix needed
+  return;
+else
   llvm_unreachable("Unhandled policy condition");
   }
 }
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4697,24 +4697,24 @@
   case RISCV::BI__builtin_riscv_aes64ks1i_64:
 return SemaBuiltinConstantArgRange(TheCall, 1, 0, 10);
   // Check if value range for vxrm is in [0, 3]
-  case RISCVVector::BI__builtin_rvv_vaaddu_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vaaddu_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vaadd_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vaadd_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vasubu_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vasubu_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vasub_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vasub_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vsmul_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vsmul_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vssra_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vssra_vx_ta:
-  case RISCVVector::BI__builtin_rvv_vssrl_vv_ta:
-  case RISCVVector::BI__builtin_rvv_vssrl_vx_ta:
-  case RISCVVector::BI_

[clang] b4e09c0 - [RISCV] Update test case riscv-attr-builtin-alias.c (NFC)

2023-07-09 Thread via cfe-commits

Author: eopXD
Date: 2023-07-09T08:41:59-07:00
New Revision: b4e09c0dea866e48be83eae8c2f269162f6f04e0

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

LOG: [RISCV] Update test case riscv-attr-builtin-alias.c (NFC)

Added: 


Modified: 
clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c

Removed: 




diff  --git a/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c 
b/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c
index 5719f77a376d88..51aab8a83c3652 100644
--- a/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c
+++ b/clang/test/CodeGen/RISCV/riscv-attr-builtin-alias.c
@@ -10,7 +10,7 @@
 static inline __attribute__((__always_inline__, __nodebug__))
 
 __rvv_generic
-__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv_ta)))
+__attribute__((clang_builtin_alias(__builtin_rvv_vadd_vv)))
 vint8m1_t vadd_generic (vint8m1_t op0, vint8m1_t op1, size_t op2);
 
 // CHECK-LABEL: @test(



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


[PATCH] D154790: [HIP] Use native math functions for `-fcuda-approx-transcendentals`

2023-07-09 Thread Brian Sumner via Phabricator via cfe-commits
b-sumner added inline comments.



Comment at: clang/lib/Headers/__clang_hip_math.h:304
+__DEVICE__
+float __tanf(float __x) { return __ocml_tan_f32(__x); }
+// END INTRINSICS

We could consider multiplying native_sin here with the native_recip of 
native_cos.


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

https://reviews.llvm.org/D154790

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


[PATCH] D154795: [clang][Interp] Check pointers for live-ness when returning them

2023-07-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  We might be trying to return a pointer or reference to a local variable,
  which doesn't work.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154795

Files:
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/functions.cpp


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -265,3 +265,29 @@
 g(0);
   }
 }
+
+namespace ReturnLocalPtr {
+  constexpr int *p() {
+int a = 12;
+return &a; // ref-warning {{address of stack memory}} \
+   // expected-warning {{address of stack memory}}
+  }
+
+  /// GCC rejects the expression below, just like the new interpreter. The 
current interpreter
+  /// however accepts it and only warns about the function above returning an 
address to stack
+  /// memory. If we change the condition to 'p() != nullptr', it even succeeds.
+  static_assert(p() == nullptr, ""); // ref-error {{static assertion failed}} \
+ // expected-error {{not an integral 
constant expression}}
+
+  /// FIXME: The current interpreter emits diagnostics in the reference case 
below, but the
+  /// new one does not.
+  constexpr const int &p2() {
+int a = 12; // ref-note {{declared here}}
+return a; // ref-warning {{reference to stack memory associated with local 
variable}} \
+  // expected-warning {{reference to stack memory associated with 
local variable}}
+  }
+
+  static_assert(p2() == 12, ""); // ref-error {{not an integral constant 
expression}} \
+ // ref-note {{read of variable whose lifetime 
has ended}} \
+ // expected-error {{not an integral constant 
expression}}
+}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -204,6 +204,17 @@
 bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   const T &Ret = S.Stk.pop();
 
+  // Make sure returned pointers are live. We might be trying to return a
+  // pointer or reference to a local variable.
+  // Just return false, since a diagnostic has already been emitted in Sema.
+  if constexpr (std::is_same_v) {
+// FIXME: We could be calling isLive() here, but the emitted diagnostics
+// seem a little weird, at least if the returned expresion is of
+// pointer type.
+if (!Ret.isLive())
+  return false;
+  }
+
   assert(S.Current->getFrameOffset() == S.Stk.size() && "Invalid frame");
   if (!S.checkingPotentialConstantExpression() || S.Current->Caller)
 S.Current->popArgs();


Index: clang/test/AST/Interp/functions.cpp
===
--- clang/test/AST/Interp/functions.cpp
+++ clang/test/AST/Interp/functions.cpp
@@ -265,3 +265,29 @@
 g(0);
   }
 }
+
+namespace ReturnLocalPtr {
+  constexpr int *p() {
+int a = 12;
+return &a; // ref-warning {{address of stack memory}} \
+   // expected-warning {{address of stack memory}}
+  }
+
+  /// GCC rejects the expression below, just like the new interpreter. The current interpreter
+  /// however accepts it and only warns about the function above returning an address to stack
+  /// memory. If we change the condition to 'p() != nullptr', it even succeeds.
+  static_assert(p() == nullptr, ""); // ref-error {{static assertion failed}} \
+ // expected-error {{not an integral constant expression}}
+
+  /// FIXME: The current interpreter emits diagnostics in the reference case below, but the
+  /// new one does not.
+  constexpr const int &p2() {
+int a = 12; // ref-note {{declared here}}
+return a; // ref-warning {{reference to stack memory associated with local variable}} \
+  // expected-warning {{reference to stack memory associated with local variable}}
+  }
+
+  static_assert(p2() == 12, ""); // ref-error {{not an integral constant expression}} \
+ // ref-note {{read of variable whose lifetime has ended}} \
+ // expected-error {{not an integral constant expression}}
+}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -204,6 +204,17 @@
 bool Ret(InterpState &S, CodePtr &PC, APValue &Result) {
   const T &Ret = S.Stk.pop();
 
+  // Make sure returned pointers are live. We might be trying to return a
+  // pointer or reference to a local variable.
+  // Just return false, since a diagnostic has already b

[PATCH] D154786: [Clang][Driver] Pass through the --be8 endian flag to linker in BareMetal driver For Arm.

2023-07-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/ARM.cpp:48
+  case llvm::Triple::thumb:
+if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
+ options::OPT_mbig_endian))

We can check the options first and do an early return, then check `getArch`. We 
can then avoid `[[fallthrough]]`.

`arm::setArchNameInTriple` has very similar code. We should factor it out.



Comment at: clang/lib/Driver/ToolChains/Arch/ARM.h:17
 #include "llvm/TargetParser/Triple.h"
+//#include "llvm/Option/ArgList.h"
 #include 

This should not be commented out. IWYU we need this header.



Comment at: clang/lib/Driver/ToolChains/BareMetal.cpp:433
   auto &TC = static_cast(getToolChain());
 
+  const llvm::Triple::ArchType Arch = TC.getArch();

no blank line



Comment at: clang/test/Driver/baremetal.cpp:121
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=armebv7-none-eabi \
+// RUN: --sysroot=%S/Inputs/baremetal_arm \

I think we can use a more dense style by packing more options on one line.

I often find the large number of lines impacts readability.



Comment at: clang/test/Driver/baremetal.cpp:126
+
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-none-eabi \

Delete `-no-canonical-prefixes`.

https://maskray.me/blog/2021-03-28-compiler-driver-and-cross-compilation#misc

> -no-canonical-prefixes uses the dereferenced absolute path for the -cc1 
> command. For most tests "-cc1" is sufficient to identify the command line, no 
> need to specifically test the "clang" command, and -no-canonical-prefixes can 
> be removed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154786

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


[PATCH] D154602: [clang][clangd] Don't crash/assert on -gsplit-dwarf=single without output

2023-07-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay requested changes to this revision.
MaskRay added a comment.
This revision now requires changes to proceed.

Thanks for the patch! But I share the concern that the test is added to a wrong 
layer 
(https://maskray.me/blog/2021-08-08-toolchain-testing#the-test-checks-at-the-wrong-layer).

We can add a `clang::createInvocation` test to 
`clang/unittests/Driver/ToolChainTest.cpp`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154602

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


[clang] 9ec5dc6 - [clang-format] Add note directive generation for docs

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

Author: Gedare Bloom
Date: 2023-07-09T12:24:55-07:00
New Revision: 9ec5dc6944781b0c233e874a4ed8d12106df14ac

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

LOG: [clang-format] Add note directive generation for docs

Generate a ..note:: directive when the \note is encountered in Format.h.

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

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/docs/tools/dump_format_style.py
clang/include/clang/Format/Format.h

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 3dbb955347da2d..866bf0910898b3 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -239,7 +239,7 @@ the configuration (without a prefix: ``Auto``).
   )
 
 
-.. warning::
+.. note::
 
  This currently only applies to braced initializer lists (when
  ``Cpp11BracedListStyle`` is ``true``) and parentheses.
@@ -252,8 +252,11 @@ the configuration (without a prefix: ``Auto``).
   if not ``None``, when using initialization for an array of structs
   aligns the fields into columns.
 
-  NOTE: As of clang-format 15 this option only applied to arrays with equal
-  number of columns per row.
+
+  .. note::
+
+   As of clang-format 15 this option only applied to arrays with equal
+   number of columns per row.
 
   Possible values:
 
@@ -879,8 +882,11 @@ the configuration (without a prefix: ``Auto``).
 **AlignTrailingComments** (``TrailingCommentsAlignmentStyle``) 
:versionbadge:`clang-format 3.7` :ref:`¶ `
   Control of trailing comments.
 
-  NOTE: As of clang-format 16 this option is not a bool but can be set
-  to the options. Conventional bool options still can be parsed as before.
+
+  .. note::
+
+   As of clang-format 16 this option is not a bool but can be set
+   to the options. Conventional bool options still can be parsed as before.
 
 
   .. code-block:: yaml
@@ -1677,8 +1683,11 @@ the configuration (without a prefix: ``Auto``).
   }
 
   * ``bool AfterObjCDeclaration`` Wrap ObjC definitions (interfaces, 
implementations...).
-@autoreleasepool and @synchronized blocks are wrapped
-according to `AfterControlStatement` flag.
+
+.. note::
+
+ @autoreleasepool and @synchronized blocks are wrapped
+ according to `AfterControlStatement` flag.
 
   * ``bool AfterStruct`` Wrap struct definitions.
 
@@ -1921,7 +1930,10 @@ the configuration (without a prefix: ``Auto``).
   otherwise it will scan until the closing `]` to determine if it should add
   newlines between elements (prettier compatible).
 
-  NOTE: This is currently only for formatting JSON.
+
+  .. note::
+
+   This is currently only for formatting JSON.
 
   .. code-block:: c++
 
@@ -2877,8 +2889,11 @@ the configuration (without a prefix: ``Auto``).
   made, clang-format analyzes whether there are other bin-packed cases in
   the input file and act accordingly.
 
-  NOTE: This is an experimental flag, that might go away or be renamed. Do
-  not use this in config files, etc. Use at your own risk.
+
+  .. note::
+
+   This is an experimental flag, that might go away or be renamed. Do
+   not use this in config files, etc. Use at your own risk.
 
 .. _FixNamespaceComments:
 
@@ -4177,10 +4192,14 @@ the configuration (without a prefix: ``Auto``).
 * restrict
 * type
 
-  Note: it MUST contain 'type'.
+
+  .. note::
+
+   it MUST contain 'type'.
+
   Items to the left of 'type' will be placed to the left of the type and
-  aligned in the order supplied. Items to the right of 'type' will be placed
-  to the right of the type and aligned in the order supplied.
+  aligned in the order supplied. Items to the right of 'type' will be
+  placed to the right of the type and aligned in the order supplied.
 
 
   .. code-block:: yaml

diff  --git a/clang/docs/tools/dump_format_style.py 
b/clang/docs/tools/dump_format_style.py
index 0b7399aee9fd5e..270ac34c03b39c 100755
--- a/clang/docs/tools/dump_format_style.py
+++ b/clang/docs/tools/dump_format_style.py
@@ -257,6 +257,14 @@ def __clean_comment_line(self, line: str):
 endwarning_match = re.match(r"^/// +\\endwarning$", line)
 if endwarning_match:
 return ""
+
+match = re.match(r"^/// \\note$", line)
+if match:
+return "\n.. note::\n\n"
+
+endnote_match = re.match(r"^/// +\\endnote$", line)
+if endnote_match:
+return ""
 return line[4:] + "\n"
 
 def read_options(self):

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ca4e89dcafc9d4..3992dd89fb950d 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -92,10 +92,10 

[PATCH] D154552: [clang-format] Add note directive generation for docs

2023-07-09 Thread Owen Pan 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 rG9ec5dc694478: [clang-format] Add note directive generation 
for docs (authored by gedare, committed by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154552

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/tools/dump_format_style.py
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -92,10 +92,10 @@
 ///   )
 /// \endcode
 ///
-/// \warning
+/// \note
 ///  This currently only applies to braced initializer lists (when
 ///  ``Cpp11BracedListStyle`` is ``true``) and parentheses.
-/// \endwarning
+/// \endnote
 BAS_BlockIndent,
   };
 
@@ -134,8 +134,10 @@
   /// if not ``None``, when using initialization for an array of structs
   /// aligns the fields into columns.
   ///
-  /// NOTE: As of clang-format 15 this option only applied to arrays with equal
-  /// number of columns per row.
+  /// \note
+  ///  As of clang-format 15 this option only applied to arrays with equal
+  ///  number of columns per row.
+  /// \endnote
   ///
   /// \version 13
   ArrayInitializerAlignmentStyle AlignArrayOfStructures;
@@ -440,8 +442,10 @@
 
   /// Control of trailing comments.
   ///
-  /// NOTE: As of clang-format 16 this option is not a bool but can be set
-  /// to the options. Conventional bool options still can be parsed as before.
+  /// \note
+  ///  As of clang-format 16 this option is not a bool but can be set
+  ///  to the options. Conventional bool options still can be parsed as before.
+  /// \endnote
   ///
   /// \code{.yaml}
   ///   # Example of usage:
@@ -1094,8 +1098,10 @@
 /// \endcode
 bool AfterNamespace;
 /// Wrap ObjC definitions (interfaces, implementations...).
-/// \note @autoreleasepool and @synchronized blocks are wrapped
-/// according to `AfterControlStatement` flag.
+/// \note
+///  @autoreleasepool and @synchronized blocks are wrapped
+///  according to `AfterControlStatement` flag.
+/// \endnote
 bool AfterObjCDeclaration;
 /// Wrap struct definitions.
 /// \code
@@ -1290,7 +1296,9 @@
   /// otherwise it will scan until the closing `]` to determine if it should add
   /// newlines between elements (prettier compatible).
   ///
-  /// NOTE: This is currently only for formatting JSON.
+  /// \note
+  ///  This is currently only for formatting JSON.
+  /// \endnote
   /// \code
   ///true:  false:
   ///[  vs.  [1, 2, 3, 4]
@@ -2180,8 +2188,10 @@
   /// made, clang-format analyzes whether there are other bin-packed cases in
   /// the input file and act accordingly.
   ///
-  /// NOTE: This is an experimental flag, that might go away or be renamed. Do
-  /// not use this in config files, etc. Use at your own risk.
+  /// \note
+  ///  This is an experimental flag, that might go away or be renamed. Do
+  ///  not use this in config files, etc. Use at your own risk.
+  /// \endnote
   /// \version 3.7
   bool ExperimentalAutoDetectBinPacking;
 
@@ -3200,10 +3210,13 @@
   ///   * restrict
   ///   * type
   ///
-  /// Note: it MUST contain 'type'.
+  /// \note
+  ///  it MUST contain 'type'.
+  /// \endnote
+  ///
   /// Items to the left of 'type' will be placed to the left of the type and
-  /// aligned in the order supplied. Items to the right of 'type' will be placed
-  /// to the right of the type and aligned in the order supplied.
+  /// aligned in the order supplied. Items to the right of 'type' will be
+  /// placed to the right of the type and aligned in the order supplied.
   ///
   /// \code{.yaml}
   ///   QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
Index: clang/docs/tools/dump_format_style.py
===
--- clang/docs/tools/dump_format_style.py
+++ clang/docs/tools/dump_format_style.py
@@ -257,6 +257,14 @@
 endwarning_match = re.match(r"^/// +\\endwarning$", line)
 if endwarning_match:
 return ""
+
+match = re.match(r"^/// \\note$", line)
+if match:
+return "\n.. note::\n\n"
+
+endnote_match = re.match(r"^/// +\\endnote$", line)
+if endnote_match:
+return ""
 return line[4:] + "\n"
 
 def read_options(self):
Index: clang/docs/ClangFormatStyleOptions.rst
===
--- clang/docs/ClangFormatStyleOptions.rst
+++ clang/docs/ClangFormatStyleOptions.rst
@@ -239,7 +239,7 @@
   )
 
 
-.. warning::
+.. note::
 
  This currently only applies to braced initiali

[PATCH] D138810: [RISCV] Support vector crypto extension C intrinsics

2023-07-09 Thread Michael Maitland via Phabricator via cfe-commits
michaelmaitland added a comment.

Can you please add a description for this patch?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138810

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


[PATCH] D154797: [CUDA][HIP] Rename and fix `-fcuda-approx-transcendentals`

2023-07-09 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: tra, MaskRay, b-sumner.
Herald added subscribers: mattd, carlosgalvezp.
Herald added a project: All.
yaxunl requested review of this revision.

Rename `-fcuda-approx-transcendentals` as
`-fgpu-approx-transcendentals` and pass it
to both device and host clang -cc1.

Fix its interaction with `-ffast-math` to allow
`-fno-gpu-approx-transcendentals` to override
the implicit `-fcuda-approx-transcendentals`
due to `-ffast-math`.

Rename the predefined macro to be
`__CLANG_[CUDA|HIP]_APPROX_TRANSCENDENTALS__`
depending on the language. Emit the macro for both
device and host compilation.


https://reviews.llvm.org/D154797

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/lib/Driver/ToolChains/HIPAMD.cpp
  clang/lib/Driver/ToolChains/HIPSPV.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Headers/__clang_cuda_math.h
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h
  clang/lib/Headers/__clang_hip_math.h
  clang/test/Driver/hip-macros.hip
  clang/test/Driver/hip-options.hip
  clang/test/Headers/__clang_hip_math.hip

Index: clang/test/Headers/__clang_hip_math.hip
===
--- clang/test/Headers/__clang_hip_math.hip
+++ clang/test/Headers/__clang_hip_math.hip
@@ -22,7 +22,7 @@
 // RUN:   -internal-isystem %S/../../lib/Headers/cuda_wrappers \
 // RUN:   -internal-isystem %S/Inputs/include \
 // RUN:   -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-unknown \
-// RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -O1 -fcuda-approx-transcendentals -o - \
+// RUN:   -target-cpu gfx906 -emit-llvm %s -fcuda-is-device -O1 -fgpu-approx-transcendentals -o - \
 // RUN:   -D__HIPCC_RTC__ | FileCheck -check-prefixes=CHECK,APPROX %s
 
 #define BOOL_TYPE int
Index: clang/test/Driver/hip-options.hip
===
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -169,3 +169,41 @@
 // RUN: %clang -### -nogpuinc -nogpulib -fhip-fp32-correctly-rounded-divide-sqrt \
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefixes=CRDS %s
 // CRDS-NOT: "-f{{(no-)?}}hip-fp32-correctly-rounded-divide-sqrt"
+
+// Check -fgpu-approx-transcendentals is passed to clang -cc1 but
+// (default) -fno-gpu-approx-transcendentals is not.
+// -ffast-math implies -fgpu-approx-transcendentals, which can be overridden
+// by -fno-gpu-approx-transcendentals.
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib -fgpu-approx-transcendentals \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefixes=APPROX %s
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib -ffast-math \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefixes=APPROX %s
+
+// APPROX: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-fgpu-approx-transcendentals"
+// APPROX: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-fgpu-approx-transcendentals"
+
+// RUN: %clang -### -nogpuinc -nogpulib -fno-gpu-approx-transcendentals \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefixes=NOAPPROX %s
+
+// RUN: %clang -### -nogpuinc -nogpulib \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefixes=NOAPPROX %s
+
+// RUN: %clang -### -nogpuinc -nogpulib -ffast-math -fno-fast-math \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefixes=NOAPPROX %s
+
+// RUN: %clang -### -nogpuinc -nogpulib -ffast-math -fno-gpu-approx-transcendentals \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefixes=NOAPPROX %s
+
+// NOAPPROX-NOT: "-f{{(no-)?}}gpu-approx-transcendentals"
+
+// Check no warnings for -fgpu-approx-transcendentals.
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib -fgpu-approx-transcendentals \
+// RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefixes=APPROXNEG %s
+
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nostdinc -nostdlib -fgpu-approx-transcendentals \
+// RUN:   -x c++ %s 2>&1 | FileCheck -check-prefixes=APPROXNEG %s
+
+// APPROXNEG-NOT: warning
Index: clang/test/Driver/hip-macros.hip
===
--- clang/test/Driver/hip-macros.hip
+++ clang/test/Driver/hip-macros.hip
@@ -63,3 +63,11 @@
 // WARN: warning: feature flag '{{[+|-]}}image-insts' is ignored since the feature is read only [-Winvalid-command-line-argument]
 // IMAGE-NOT: #define __HIP_NO_IMAGE_SUPPORT
 // NOIMAGE: #define __HIP_NO_IMAGE_SUPPORT 1
+
+// RUN: %clang -E -dM --offload-arch=gfx906 -nogpuinc -nogpulib \
+// RUN:   %s 2>&1 | FileCheck --check-prefix=NOAPPROX %s
+// RUN: %clang -E -dM --offload-arch=gfx906 -nogpuinc -nogpulib -fgpu-approx-transcendentals \
+// RUN:   %s 2>&1 | FileCheck --check-prefix=APPROX %s
+// NOAPPR

[PATCH] D154287: [clang-tidy] Add modernize-use-std-format check

2023-07-09 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp:46
+void UseStdFormatCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(argumentCountAtLeast(1), hasArgument(0, stringLiteral()),

This matcher also matches the `operator+` call in:
```
std::string A(const std::string &in)


{   


return "_" + in;


}   


```
which causes an assertion failure:
```
clang-tidy: /home/mac/git/llvm-project/clang/include/clang/AST/Decl.h:275: 
llvm::StringRef clang::NamedDecl::getName() const: Assertion 
`Name.isIdentifier() && "Name is not a simple identifier"' failed.
```
when the `StrFormatLikeFunctions` option is set to an unqualified name:
```
-config="{CheckOptions: [{key: modernize-use-std-format.StrictMode, value: 
false}, {key: modernize-use-std-format.StrFormatLikeFunctions, value: 
'strprintf'}]}"
```

`MatchesAnyListedNameMatcher::NameMatcher::match` calls `NamedDecl.getName()` 
which presumably raises the assertion due to the `operator+` not having a name 
(that's mentioned in the source anyway.)

I'm unsure whether I should be narrowing the matcher here so that it guaranteed 
to not try calling `matchesAnyListedName` on something that lacks a name, or 
whether `MatchesAnyListedNameMatcher` ought to be more tolerant of being called 
in such situations.

I note that `HasNameMatcher` has rather more elaborate code for generating the 
name than `MatchesAnyListedNameMatcher` does.

This problem also affects `modernize-use-std-print`, but due to the need for 
there to be no return value in that check it requires somewhat-unlikely code 
like:
```
void A(const std::string &in)
{
  "_" + in;
}
```

Do you have any advice? Given that this problem affects a check that has 
already landed should I open a bug?



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdFormatCheck.cpp:47
+  Finder->addMatcher(
+  callExpr(argumentCountAtLeast(1), hasArgument(0, stringLiteral()),
+   callee(functionDecl(matchers::matchesAnyListedName(

I need to add an `isOrdinary()` call here like `modernize-use-std-print` has.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154287

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


[PATCH] D154484: [clang-format] Add an option to remove redundant parentheses

2023-07-09 Thread sstwcw via Phabricator via cfe-commits
sstwcw added a comment.

Did you forget about GNU statement expressions?

  if (({
foo();
bar();
  })) {
  }




Comment at: clang/docs/ReleaseNotes.rst:804
 - Add ``KeepEmptyLinesAtEOF`` to keep empty lines at end of file.
+- Add ``RemoveParenthese`` to remove redundant parentheses.
 

The option is misspelled.


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

https://reviews.llvm.org/D154484

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


[PATCH] D138810: [RISCV] Support vector crypto extension C intrinsics

2023-07-09 Thread Michael Maitland via Phabricator via cfe-commits
michaelmaitland added inline comments.



Comment at: clang/include/clang/Basic/riscv_vector.td:2381
+  if HasVV then {
+defvar suffix = !if(!or(HasVS, !eq(NAME, "vsm4r")), "vv", "v");
+// We don't need suffix in Zvkb extension since it's consider as normal

Why do we check `HasVS` when assigning suffix `vv`? I would have expected we 
use `HasVV`. In addition, why do we need to check `!eq(NAME, "vsm4r")` instead 
of setting the `HasVV` for that instruction?



Comment at: clang/include/clang/Basic/riscv_vector.td:2400
+// mnemonics into its intrinsic function name.
+defvar suffix = !if(!eq(NAME, "vgmul"), "vv", "vs");
+defvar name = NAME # !if(!or(IsZvkb, !or(!eq(NAME, "vaesz"),

Why not set `HasVS=1` and `HasVV=0` for `vaesz` instead of checking 
`!if(!eq(NAME, "vgmul"),...`?

Also, do you mean to be discussing `vaesz` in the comment but use `vgmul` below?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D138810

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


[PATCH] D154801: C++20 Modules: update pr59999.cppm to reflect a reproducible state

2023-07-09 Thread Eduardo Costa via Phabricator via cfe-commits
m4c0 created this revision.
Herald added a project: All.
m4c0 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is a extension for #5 tests in order to make them reproduce the issue 
reported.

After local tests, I found out the definition in a "part unit" being 
instantiated in a deeper dependency tree is fundamental to the failure. So, in 
the case of this issue, splitting the code with its parts and the `World` 
module are important.

Also, I noticed more symbols are also important to reproduce the issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154801

Files:
  clang/test/Modules/pr5.cppm


Index: clang/test/Modules/pr5.cppm
===
--- clang/test/Modules/pr5.cppm
+++ clang/test/Modules/pr5.cppm
@@ -4,17 +4,31 @@
 // RUN: mkdir -p %t
 // RUN: split-file %s %t
 //
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple 
%t/Module-Reflector.cppm \
+// RUN: -emit-module-interface -o %t/Module-Reflector.pcm
 // RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Module.cppm \
 // RUN: -emit-module-interface -o %t/Module.pcm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple 
%t/Object-Reflector.cppm \
+// RUN: -fmodule-file=Module=%t/Module.pcm -emit-module-interface \
+// RUN: -o %t/Object-Reflector.pcm
 // RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Object.cppm \
 // RUN: -fmodule-file=Module=%t/Module.pcm -emit-module-interface -o 
%t/Object.pcm
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Object.pcm \
-// RUN: -fmodule-file=Module=%t/Module.pcm -S -emit-llvm -o - | FileCheck 
%t/Object.cppm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/World.cppm \
+// RUN: -fmodule-file=Module=%t/Module.pcm 
-fmodule-file=Object=%t/Object.pcm \
+// RUN: -o %t/World.pcm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/World.pcm \
+// RUN: -fmodule-file=Module=%t/Module.pcm 
-fmodule-file=Object=%t/Object.pcm \
+// RUN: -S -emit-llvm -o - | FileCheck %t/World.cppm
+
+//--- Module-Reflector.cppm
+export module Module:Reflector;
+
+export template  bool ModuleRegister() { return true; };
 
 //--- Module.cppm
 export module Module;
 
-export template  bool ModuleRegister() { return true; };
+export import :Reflector;
 
 export struct ModuleEntry {
   static const bool bRegistered;
@@ -22,12 +36,18 @@
 
 const bool ModuleEntry::bRegistered = ModuleRegister();
 
+//--- Object-Reflector.cppm
+export module Object:Reflector;
+
+export template  bool ObjectRegister() { return true; };
+
 //--- Object.cppm
 export module Object;
 
 import Module;
 
-export template  bool ObjectRegister() { return true; }
+export import :Reflector;
+
 export struct NObject {
   static const bool bRegistered;
 };
@@ -40,5 +60,13 @@
 // One another function, that helps clang crash
 const bool ObjectModuleEntry::bRegistered = 
ModuleRegister();
 
+//--- World.cppm
+
+export module World;
+
+import Object;
+
+export const bool NWorldRegistered = ModuleRegister();
+
 // Check that the LLVM IR is generated correctly instead of crashing.
-// CHECK: define{{.*}}@_ZGIW6Object
+// CHECK: define{{.*}}@_ZGIW5World


Index: clang/test/Modules/pr5.cppm
===
--- clang/test/Modules/pr5.cppm
+++ clang/test/Modules/pr5.cppm
@@ -4,17 +4,31 @@
 // RUN: mkdir -p %t
 // RUN: split-file %s %t
 //
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Module-Reflector.cppm \
+// RUN: -emit-module-interface -o %t/Module-Reflector.pcm
 // RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Module.cppm \
 // RUN: -emit-module-interface -o %t/Module.pcm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Object-Reflector.cppm \
+// RUN: -fmodule-file=Module=%t/Module.pcm -emit-module-interface \
+// RUN: -o %t/Object-Reflector.pcm
 // RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Object.cppm \
 // RUN: -fmodule-file=Module=%t/Module.pcm -emit-module-interface -o %t/Object.pcm
-// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Object.pcm \
-// RUN: -fmodule-file=Module=%t/Module.pcm -S -emit-llvm -o - | FileCheck %t/Object.cppm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/World.cppm \
+// RUN: -fmodule-file=Module=%t/Module.pcm -fmodule-file=Object=%t/Object.pcm \
+// RUN: -o %t/World.pcm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/World.pcm \
+// RUN: -fmodule-file=Module=%t/Module.pcm -fmodule-file=Object=%t/Object.pcm \
+// RUN: -S -emit-llvm -o - | FileCheck %t/World.cppm
+
+//--- Module-Reflector.cppm
+export module Module:Reflector;
+
+export template  bool ModuleRegister() { return true; };
 
 //--- Module.cppm
 export module Module;
 
-export template  bool ModuleRegister() { return true; };
+ex

[PATCH] D154675: [Clang] Fix crash when emitting diagnostic for out of order designated initializers in C++

2023-07-09 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 538456.
shafik added a comment.

- Stopped using `NumBases` when calculating `OldIndex`
- Added bases classes to the test and added more test cases


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

https://reviews.llvm.org/D154675

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp


Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -63,7 +63,7 @@
   .x = 1, // override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}} override-note 
{{previous}}
   .y = 1, // override-note {{previous}}
-  .y = 1, // override-error {{overrides prior initialization}}
+  .y = 1, // override-error {{overrides prior initialization}} // reorder-note 
{{previous initialization for field 'y' is here}}
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides 
prior initialization}} override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}}
 };
@@ -177,3 +177,43 @@
 h({.a = 1});
   }
 }
+
+namespace GH63605 {
+struct A  {
+  unsigned x;
+  unsigned y;
+  unsigned z;
+};
+
+struct B {
+  unsigned a;
+  unsigned b;
+};
+
+struct : public A, public B {
+  unsigned : 2;
+  unsigned a : 6;
+  unsigned : 1;
+  unsigned b : 6;
+  unsigned : 2;
+  unsigned c : 6;
+  unsigned d : 1;
+  unsigned e : 2;
+} data = {
+  {.z=0,
+ // pedantic-note@-1 {{first non-designated initializer is here}}
+ // reorder-note@-2 {{previous initialization for field 'z' is here}}
+   .y=1, // reorder-error {{field 'z' will be initialized after field 'y'}}
+ // reorder-note@-1 {{previous initialization for field 'y' is here}}
+   .x=2}, // reorder-error {{field 'y' will be initialized after field 'x'}}
+  {.b=3,  // reorder-note {{previous initialization for field 'b' is here}}
+   .a=4}, // reorder-error {{field 'b' will be initialized after field 'a'}}
+.e = 1, // reorder-note {{previous initialization for field 'e' is here}}
+// pedantic-error@-1 {{mixture of designated and non-designated 
initializers in the same initializer list is a C99 extension}}
+.d = 1, // reorder-error {{field 'e' will be initialized after field 'd'}}
+// reorder-note@-1 {{previous initialization for field 'd' is 
here}}
+.c = 1, // reorder-error {{field 'd' will be initialized after field 'c'}} 
// reorder-note {{previous initialization for field 'c' is here}}
+.b = 1, // reorder-error {{field 'c' will be initialized after field 'b'}} 
// reorder-note {{previous initialization for field 'b' is here}}
+.a = 1, // reorder-error {{field 'b' will be initialized after field 'a'}}
+};
+}
Index: clang/lib/Sema/SemaInit.cpp
===
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -2844,7 +2844,7 @@
 SemaRef.Diag(DIE->getBeginLoc(), diag::ext_designated_init_reordered)
 << KnownField << PrevField << DIE->getSourceRange();
 
-unsigned OldIndex = NumBases + PrevField->getFieldIndex();
+unsigned OldIndex = StructuredIndex - 1;
 if (StructuredList && OldIndex <= StructuredList->getNumInits()) {
   if (Expr *PrevInit = StructuredList->getInit(OldIndex)) {
 SemaRef.Diag(PrevInit->getBeginLoc(),
@@ -2948,8 +2948,12 @@
 // If this the first designator, our caller will continue checking
 // the rest of this struct/class/union subobject.
 if (IsFirstDesignator) {
+  if (Field != RD->field_end() && Field->isUnnamedBitfield())
+++Field;
+
   if (NextField)
 *NextField = Field;
+
   StructuredIndex = FieldIndex;
   return false;
 }


Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -63,7 +63,7 @@
   .x = 1, // override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}} override-note {{previous}}
   .y = 1, // override-note {{previous}}
-  .y = 1, // override-error {{overrides prior initialization}}
+  .y = 1, // override-error {{overrides prior initialization}} // reorder-note {{previous initialization for field 'y' is here}}
   .x = 1, // reorder-error {{declaration order}} override-error {{overrides prior initialization}} override-note {{previous}}
   .x = 1, // override-error {{overrides prior initialization}}
 };
@@ -177,3 +177,43 @@
 h({.a = 1});
   }
 }
+
+namespace GH63605 {
+struct A  {
+  unsigned x;
+  unsigned y;
+  unsigned z;
+};
+
+struct B {
+  unsigned a;
+  unsigned b;
+};
+
+struct : public A, public B {
+  unsigned : 2;
+  unsigned a : 6;
+  

[PATCH] D154675: [Clang] Fix crash when emitting diagnostic for out of order designated initializers in C++

2023-07-09 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik marked an inline comment as done.
shafik added a comment.

Found a new issue https://github.com/llvm/llvm-project/issues/63759 but this 
feels different enough that I will deal with it separately.




Comment at: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp:182
+namespace GH63605 {
+struct {
+  unsigned : 2;

shafik wrote:
> cor3ntin wrote:
> > Should we add bases?
> Good catch b/c of course bases would cause problems 🤣
Problems due to bases now fixed as well.



Comment at: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp:195
+.c = 1, // reorder-error {{field 'd' will be initialized after field 'c'}} 
// reorder-note {{previous initialization for field 'c' is here}}
+.b = 1, // reorder-error {{field 'c' will be initialized after field 'b'}} 
// reorder-note {{previous initialization for field 'e' is here}}
+.a = 1, // reorder-error {{field 'e' will be initialized after field 'a'}}

shafik wrote:
> Note the `e` in the diagnostic in this line and the next line should be `b`. 
> I have not managed to figure out how to fix this yet but this feels 
> relatively minor compared to the crash.
This is now fixed


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

https://reviews.llvm.org/D154675

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


[PATCH] D154790: [HIP] Use native math functions for `-fcuda-approx-transcendentals`

2023-07-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

This would be a lot easier if we clang fp was fully featured. As far as I can 
tell it lets you set #pragma clang fp reassociate(on), and contract(fast), but 
doesn't have a way to set arcp, afn, ninf or nnan




Comment at: clang/lib/Headers/__clang_hip_math.h:160
+__DEVICE__
+float __exp10f(float __x) { return __ocml_native_exp10_f32(__x); }
+

We should have llvm.exp10 but don't today. Just inline 
__builtin_exp2f(M_LOG2_10_F * x)



Comment at: clang/lib/Headers/__clang_hip_math.h:163
+__DEVICE__
+float __expf(float __x) { return __ocml_native_exp_f32(__x); }
+

__builtin_expf 



Comment at: clang/lib/Headers/__clang_hip_math.h:280
+__DEVICE__
+float __log10f(float __x) { return __ocml_native_log10_f32(__x); }
+

We want llvm.log10.f32 with afn set. You get closer by just using 
__builtin_log10f. Ideally we would have a pragma to set afn locally 



Comment at: clang/lib/Headers/__clang_hip_math.h:283
+__DEVICE__
+float __log2f(float __x) { return __ocml_native_log2_f32(__x); }
+

__builtin_log2f or __builtin_amdgcn_log. Ideally would be llvm.log2.f32 with 
afn set 



Comment at: clang/lib/Headers/__clang_hip_math.h:286
+__DEVICE__
+float __logf(float __x) { return __ocml_native_log_f32(__x); }
+

Same as log10 case, except with log 



Comment at: clang/lib/Headers/__clang_hip_math.h:301
+__DEVICE__
+float __sinf(float __x) { return __ocml_native_sin_f32(__x); }
+

Really we want these inlined with FMF set, the built libraries currently have 
no flags 


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

https://reviews.llvm.org/D154790

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


[PATCH] D154790: [HIP] Use native math functions for `-fcuda-approx-transcendentals`

2023-07-09 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/Headers/__clang_hip_math.h:163
+__DEVICE__
+float __expf(float __x) { return __ocml_native_exp_f32(__x); }
+

arsenm wrote:
> __builtin_expf 
Maybe this should just be __builtin_amdgcn_exp2f


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

https://reviews.llvm.org/D154790

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


[PATCH] D128059: [Clang] Add a warning on invalid UTF-8 in comments.

2023-07-09 Thread Fako via Phabricator via cfe-commits
Fako432 added a comment.
Herald added a subscriber: wangpc.

In D128059#3640564 , @cor3ntin wrote:

> In D128059#3640544 , 
> @hubert.reinterpretcast wrote:
>
>> In D128059#3640424 , @cor3ntin 
>> wrote:
>>
>>> @aaron.ballman Thanks for the review. I landed the changes and got a bunch 
>>> of bots screaming at me for changes that are completely unrelated
>>>
>>> https://lab.llvm.org/buildbot/#/builders/21/builds/45146
>>> https://lab.llvm.org/buildbot/#/builders/36/builds/22838
>>> https://lab.llvm.org/buildbot/#/builders/121/builds/21183/monkey mart 
>>> 
>>
>> What do you mean it is completely unrelated? You have `__ALTIVEC__`-specific 
>> changes and it knocks out the PPC bots.
>
> Good point. The error was a bit misleading but i guess what's happening is a 
> segfault when running `clang-ast-dump`. 
> I'm reverting for now and I don't really know how to go from there as I don't 
> have the hardware to test that code path.

You raise a valid argument. The confusion caused by the error could potentially 
be attributed to a segmentation fault occurring during the execution.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128059

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


[clang] 3450272 - [Driver][FreeBSD] Generalise lib32 handling to support arm

2023-07-09 Thread Jessica Clarke via cfe-commits

Author: Jessica Clarke
Date: 2023-07-10T01:40:58+01:00
New Revision: 3450272fc281979388bb845a9fffb59b42cc2e7e

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

LOG: [Driver][FreeBSD] Generalise lib32 handling to support arm

The current code maintains its own list of 32-bit architectures for
which there is a 64-bit FreeBSD architecture that supports it for lib32.
This is unnecessary (if it's not supported, the directory just won't
exist), and means that, when FreeBSD gains lib32 support for a new
architecture, you need an updated toolchain that knows about it.
Instead we can check for any 32-bit architecture and have forwards
compatibility.

This is motivated by FreeBSD adding support for building arm lib32
libraries on aarch64.

Co-authored-by: Mike Karels 

Added: 


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

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index ac336598a78c94..84e257741702ce 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -376,8 +376,7 @@ FreeBSD::FreeBSD(const Driver &D, const llvm::Triple 
&Triple,
 
   // When targeting 32-bit platforms, look for '/usr/lib32/crt1.o' and fall
   // back to '/usr/lib' if it doesn't exist.
-  if ((Triple.getArch() == llvm::Triple::x86 || Triple.isMIPS32() ||
-   Triple.isPPC32()) &&
+  if (Triple.isArch32Bit() &&
   D.getVFS().exists(concat(getDriver().SysRoot, "/usr/lib32/crt1.o")))
 getFilePaths().push_back(concat(getDriver().SysRoot, "/usr/lib32"));
   else



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


[PATCH] D154484: [clang-format] Add an option to remove redundant parentheses

2023-07-09 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 538470.
owenpan added a reviewer: sstwcw.
owenpan removed a subscriber: sstwcw.
owenpan added a comment.

Don't treat `(` as `l_paren` if it's followed by `{`.


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

https://reviews.llvm.org/D154484

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25805,6 +25805,56 @@
getGoogleStyle());
 }
 
+TEST_F(FormatTest, RemoveParentheses) {
+  FormatStyle Style = getLLVMStyle();
+  EXPECT_EQ(Style.RemoveParentheses, FormatStyle::RPS_Leave);
+
+  Style.RemoveParentheses = FormatStyle::RPS_MultipleParentheses;
+  verifyFormat("int x __attribute__((aligned(16))) = 0;", Style);
+  verifyFormat("class __declspec(dllimport) X {};",
+   "class __declspec((dllimport)) X {};", Style);
+  verifyFormat("int x = (({ 0; }));", "int x = ((({ 0; })));", Style);
+  verifyFormat("while (a)\n"
+   "  b;",
+   "while (((a)))\n"
+   "  b;",
+   Style);
+  verifyFormat("while ((a = b))\n"
+   "  c;",
+   "while (((a = b)))\n"
+   "  c;",
+   Style);
+  verifyFormat("if (a)\n"
+   "  b;",
+   "if (((a)))\n"
+   "  b;",
+   Style);
+  verifyFormat("if constexpr ((a = b))\n"
+   "  c;",
+   "if constexpr (((a = b)))\n"
+   "  c;",
+   Style);
+  verifyFormat("if (({ a; }))\n"
+   "  b;",
+   "if ((({ a; })))\n"
+   "  b;",
+   Style);
+  verifyFormat("return (0);", "return (((0)));", Style);
+  verifyFormat("return (({ 0; }));", "return ((({ 0; })));", Style);
+
+  Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
+  verifyFormat("return 0;", "return (0);", Style);
+  verifyFormat("co_return 0;", "co_return ((0));", Style);
+  verifyFormat("return 0;", "return (((0)));", Style);
+  verifyFormat("return ({ 0; });", "return ((({ 0; })));", Style);
+
+  Style.ColumnLimit = 25;
+  verifyFormat("return (a + b) - (c + d);",
+   "return (((a + b)) -\n"
+   "((c + d)));",
+   Style);
+}
+
 } // namespace
 } // namespace test
 } // namespace format
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -917,6 +917,13 @@
   LineEnding, FormatStyle::LE_CRLF);
   Style.LineEnding = DefaultLineEnding;
   CHECK_PARSE("UseCRLF: true", LineEnding, FormatStyle::LE_DeriveCRLF);
+
+  CHECK_PARSE("RemoveParentheses: MultipleParentheses", RemoveParentheses,
+  FormatStyle::RPS_MultipleParentheses);
+  CHECK_PARSE("RemoveParentheses: ReturnStatement", RemoveParentheses,
+  FormatStyle::RPS_ReturnStatement);
+  CHECK_PARSE("RemoveParentheses: Leave", RemoveParentheses,
+  FormatStyle::RPS_Leave);
 }
 
 TEST(ConfigParseTest, ParsesConfigurationWithLanguages) {
Index: clang/lib/Format/UnwrappedLineParser.h
===
--- clang/lib/Format/UnwrappedLineParser.h
+++ clang/lib/Format/UnwrappedLineParser.h
@@ -156,7 +156,7 @@
   bool tryToParseBracedList();
   bool parseBracedList(bool ContinueOnSemicolons = false, bool IsEnum = false,
tok::TokenKind ClosingBraceKind = tok::r_brace);
-  void parseParens(TokenType AmpAmpTokenType = TT_Unknown);
+  bool parseParens(TokenType AmpAmpTokenType = TT_Unknown);
   void parseSquare(bool LambdaIntroducer = false);
   void keepAncestorBraces();
   void parseUnbracedBody(bool CheckEOF = false);
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2432,22 +2432,50 @@
 /// \brief Parses a pair of parentheses (and everything between them).
 /// \param AmpAmpTokenType If different than TT_Unknown sets this type for all
 /// double ampersands. This applies for all nested scopes as well.
-void UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
+///
+/// Returns whether there is a `=` token between the parentheses.
+bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
   assert(FormatTok->is(tok::l_paren) && "'(' expected.");
+  auto *LeftParen = FormatTok;
+  bool SeenEqual = false;
+  const bool Mi

[PATCH] D154484: [clang-format] Add an option to remove redundant parentheses

2023-07-09 Thread Owen Pan via Phabricator via cfe-commits
owenpan marked an inline comment as done.
owenpan added a comment.

In D154484#4483659 , @sstwcw wrote:

> Did you forget about GNU statement expressions?
>
>   if (({
> foo();
> bar();
>   })) {
>   }

Thanks!


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

https://reviews.llvm.org/D154484

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


[PATCH] D154675: [Clang] Fix crash when emitting diagnostic for out of order designated initializers in C++

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

@aaron.ballman I can't figure out why the libcxx bot failed, can you understand 
why?


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

https://reviews.llvm.org/D154675

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


[PATCH] D154576: [RISCV] RISCV vector calling convention (1/2)

2023-07-09 Thread Lehua Ding via Phabricator via cfe-commits
lhtin added a comment.

In D154576#4476300 , @4vtomat wrote:

> In D154576#4476291 , @craig.topper 
> wrote:
>
>> Does this only change the calling convention when 
>> `__attribute__((riscv_vector_cc))` is used? The attribute should be 
>> mentioned in the patch description.
>
> Yes it only changes when `__attribute__((riscv_vector_cc))` is used, thanks 
> for reminding, I will mention in the description.

In addition to using attributes, functions that use vector registers to pass 
arguments or return values also need to comply with the new calling convention.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154576

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


[PATCH] D154801: C++20 Modules: update pr59999.cppm to reflect a reproducible state

2023-07-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Thanks for working on this.

The message from the CI bot shows there is something wrong with the updating.

> I'm trying to run this patch using LLVM sources on my machine, but 
> unfortunately, I'm facing disk space issues (it's an old Windows machine).

In this case, you can use apt.llvm.org to get the latest Clang builds. This is 
a workaround in your cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154801

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


[PATCH] D154130: [lit] Avoid os.path.realpath on Windows due to MAX_PATH limitations

2023-07-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

I don't write module map a lot neither. But I am curious where is the 
definition for the term `%>/t`? It is indeed a little bit odd at the first look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154130

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


[PATCH] D154706: [RISCV] Add XLEN width integer type: riscv_int.h

2023-07-09 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 538497.
kito-cheng added a comment.

Changes:

- Define __RISCV_INT_H


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154706

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/riscv_int.h


Index: clang/lib/Headers/riscv_int.h
===
--- /dev/null
+++ clang/lib/Headers/riscv_int.h
@@ -0,0 +1,62 @@
+/*===- riscv_int.h - RISC-V: XLEN-width integer type and format conversion 
--===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __RISCV_INT_H
+#define __RISCV_INT_H
+
+#include 
+#include 
+
+#if __riscv_xlen == 32
+typedef int32_t __riscv_int_xlen_t;
+typedef uint32_t __riscv_uint_xlen_t;
+
+#define __RISCV_INT_XLEN_MIN INT32_MIN
+#define __RISCV_INT_XLEN_MAX INT32_MAX
+#define __RISCV_UINT_XLEN_MAX UINT32_MAX
+
+#define __RISCV_PRIdXLEN PRId32
+#define __RISCV_PRIiXLEN PRIi32
+#define __RISCV_PRIoXLEN PRIo32
+#define __RISCV_PRIuXLEN PRIu32
+#define __RISCV_PRIxXLEN PRIx32
+#define __RISCV_PRIXXLEN PRIX32
+
+#define __RISCV_SCNdXLEN SCNd32
+#define __RISCV_SCNiXLEN SCNi32
+#define __RISCV_SCNoXLEN SCNo32
+#define __RISCV_SCNuXLEN SCNu32
+#define __RISCV_SCNxXLEN SCNx32
+
+#elif __riscv_xlen == 64
+typedef int64_t __riscv_int_xlen_t;
+typedef uint64_t __riscv_uint_xlen_t;
+
+#define __RISCV_INT_XLEN_MIN INT64_MIN
+#define __RISCV_INT_XLEN_MAX INT64_MAX
+#define __RISCV_UINT_XLEN_MAX UINT64_MAX
+
+#define __RISCV_PRIdXLEN PRId64
+#define __RISCV_PRIiXLEN PRIi64
+#define __RISCV_PRIoXLEN PRIo64
+#define __RISCV_PRIuXLEN PRIu64
+#define __RISCV_PRIxXLEN PRIx64
+#define __RISCV_PRIXXLEN PRIX64
+
+#define __RISCV_SCNdXLEN SCNd64
+#define __RISCV_SCNiXLEN SCNi64
+#define __RISCV_SCNoXLEN SCNo64
+#define __RISCV_SCNuXLEN SCNu64
+#define __RISCV_SCNxXLEN SCNx64
+
+#else
+#error "Unknown XLEN"
+#endif
+
+#endif
Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -99,6 +99,7 @@
   )
 
 set(riscv_files
+  riscv_int.h
   riscv_ntlh.h
   )
 


Index: clang/lib/Headers/riscv_int.h
===
--- /dev/null
+++ clang/lib/Headers/riscv_int.h
@@ -0,0 +1,62 @@
+/*===- riscv_int.h - RISC-V: XLEN-width integer type and format conversion --===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __RISCV_INT_H
+#define __RISCV_INT_H
+
+#include 
+#include 
+
+#if __riscv_xlen == 32
+typedef int32_t __riscv_int_xlen_t;
+typedef uint32_t __riscv_uint_xlen_t;
+
+#define __RISCV_INT_XLEN_MIN INT32_MIN
+#define __RISCV_INT_XLEN_MAX INT32_MAX
+#define __RISCV_UINT_XLEN_MAX UINT32_MAX
+
+#define __RISCV_PRIdXLEN PRId32
+#define __RISCV_PRIiXLEN PRIi32
+#define __RISCV_PRIoXLEN PRIo32
+#define __RISCV_PRIuXLEN PRIu32
+#define __RISCV_PRIxXLEN PRIx32
+#define __RISCV_PRIXXLEN PRIX32
+
+#define __RISCV_SCNdXLEN SCNd32
+#define __RISCV_SCNiXLEN SCNi32
+#define __RISCV_SCNoXLEN SCNo32
+#define __RISCV_SCNuXLEN SCNu32
+#define __RISCV_SCNxXLEN SCNx32
+
+#elif __riscv_xlen == 64
+typedef int64_t __riscv_int_xlen_t;
+typedef uint64_t __riscv_uint_xlen_t;
+
+#define __RISCV_INT_XLEN_MIN INT64_MIN
+#define __RISCV_INT_XLEN_MAX INT64_MAX
+#define __RISCV_UINT_XLEN_MAX UINT64_MAX
+
+#define __RISCV_PRIdXLEN PRId64
+#define __RISCV_PRIiXLEN PRIi64
+#define __RISCV_PRIoXLEN PRIo64
+#define __RISCV_PRIuXLEN PRIu64
+#define __RISCV_PRIxXLEN PRIx64
+#define __RISCV_PRIXXLEN PRIX64
+
+#define __RISCV_SCNdXLEN SCNd64
+#define __RISCV_SCNiXLEN SCNi64
+#define __RISCV_SCNoXLEN SCNo64
+#define __RISCV_SCNuXLEN SCNu64
+#define __RISCV_SCNxXLEN SCNx64
+
+#else
+#error "Unknown XLEN"
+#endif
+
+#endif
Index: clang/lib/Headers/CMakeLists.txt
===
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -99,6 +99,7 @@
   )
 
 set(riscv_files
+  riscv_int.h
   riscv_ntlh.h
   )
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154706: [RISCV] Add XLEN width integer type: riscv_int.h

2023-07-09 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng marked an inline comment as done.
kito-cheng added inline comments.



Comment at: clang/lib/Headers/riscv_int.h:10
+
+#ifndef __RISCV_INT_H
+

craig.topper wrote:
> Don't you have to `#define __RISCV_INT_H` after this to make this a complete 
> include guard?
Ooops, thanks for catching this!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154706

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


[PATCH] D148490: [AIX] use system assembler for assembly files

2023-07-09 Thread Brad Smith via Phabricator via cfe-commits
brad added a comment.

What is left for this to be reverted, in the quest to fully enable IAS for AIX?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148490

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


[PATCH] D154764: [clang] ASTImport: force recomputing ASTRecordLayout when importing

2023-07-09 Thread Ding Fei via Phabricator via cfe-commits
danix800 updated this revision to Diff 538500.
danix800 added a comment.

Apply git-clang-format.


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

https://reviews.llvm.org/D154764

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/Analysis/astimport-force-relayout/Inputs/api.cc
  clang/test/Analysis/astimport-force-relayout/Inputs/externalDefMap.txt
  clang/test/Analysis/astimport-force-relayout/Inputs/v8.h
  clang/test/Analysis/astimport-force-relayout/date.cpp

Index: clang/test/Analysis/astimport-force-relayout/date.cpp
===
--- /dev/null
+++ clang/test/Analysis/astimport-force-relayout/date.cpp
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+
+// RUN: %clang -c -mthumb --target=armv7a-linux-androideabi1 -x c++ \
+// RUN:   -std=gnu++17 %p/Inputs/api.cc -emit-ast -o %t/ctudir/api.cc.ast
+
+// RUN: cp %p/Inputs/externalDefMap.txt %t/ctudir/externalDefMap.txt
+
+// RUN: %clang_analyze_cc1 -triple thumbv7-unknown-linux-android1 \
+// RUN:   -std=gnu++17 \
+// RUN:   -analyzer-checker=core.DivideZero \
+// RUN:   -analyzer-opt-analyze-headers \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -analyzer-config display-ctu-progress=true \
+// RUN:   -fno-signed-char %s
+
+// expected-no-diagnostics
+
+#include "Inputs/v8.h"
Index: clang/test/Analysis/astimport-force-relayout/Inputs/v8.h
===
--- /dev/null
+++ clang/test/Analysis/astimport-force-relayout/Inputs/v8.h
@@ -0,0 +1,28 @@
+#ifndef INCLUDE_V8_H_
+#define INCLUDE_V8_H_
+
+namespace v8 {
+
+class Context;
+class Object;
+class Value;
+
+template 
+class Local {};
+
+class Function {
+ public:
+  Local NewInstance(Local context, int argc,
+Local argv[]) const;
+
+  Local NewInstance(Local context) const {
+return NewInstance(context, 0, nullptr);
+  }
+
+  Local NewInstanceWithSideEffectType(Local context, int argc,
+  Local argv[]) const;
+};
+
+}  // namespace v8
+
+#endif  // INCLUDE_V8_H_
Index: clang/test/Analysis/astimport-force-relayout/Inputs/externalDefMap.txt
===
--- /dev/null
+++ clang/test/Analysis/astimport-force-relayout/Inputs/externalDefMap.txt
@@ -0,0 +1,3 @@
+45:c:@N@v8@S@Deoptimizer@F@output_count_offset#S api.cc.ast
+38:c:@N@v8@S@Deoptimizer@F@input_offset#S api.cc.ast
+101:c:@N@v8@S@Function@F@NewInstance#$@N@v8@S@Local>#$@N@v8@S@Context#I#*$@N@v8@S@Local>#$@N@v8@S@Value#1 api.cc.ast
Index: clang/test/Analysis/astimport-force-relayout/Inputs/api.cc
===
--- /dev/null
+++ clang/test/Analysis/astimport-force-relayout/Inputs/api.cc
@@ -0,0 +1,31 @@
+#include "v8.h"
+
+typedef long int intptr_t;
+
+namespace v8 {
+
+class Deoptimizer {
+public:
+  static int input_offset() {
+return (reinterpret_cast(
+&(reinterpret_cast(16)->input_)) -
+16);
+  }
+
+  static int output_count_offset() {
+return (reinterpret_cast(
+&(reinterpret_cast(16)->output_count_)) -
+16);
+  }
+
+private:
+  int input_;
+  int output_count_;
+};
+
+Local Function::NewInstance(Local context, int argc,
+Local argv[]) const {
+  return NewInstanceWithSideEffectType(context, argc, argv);
+}
+
+} // namespace v8
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -3278,8 +3278,8 @@
 /// getASTRecordLayout - Get or compute information about the layout of the
 /// specified record (struct/union/class), which indicates its size and field
 /// position information.
-const ASTRecordLayout &
-ASTContext::getASTRecordLayout(const RecordDecl *D) const {
+const ASTRecordLayout &ASTContext::getASTRecordLayout(const RecordDecl *D,
+  bool NoCache) const {
   // These asserts test different things.  A record has a definition
   // as soon as we begin to parse the definition.  That definition is
   // not a complete definition (which is what isDefinition() tests)
@@ -3298,8 +3298,11 @@
   // Look up this layout, if already laid out, return what we have.
   // Note that we can't save a reference to the entry because this function
   // is recursive.
-  const ASTRecordLayout *Entry = ASTRecordLayouts[D];
-  if (Entry) return *Entry;
+  if (!NoCache) {
+const ASTRecordLayout *Entry = ASTRecordLayouts[D];
+if (Entry)
+  return *Entry;
+  }
 
   const ASTRecordLayout *NewEntry = nullptr;
 
Index: clang/lib/AST/ExprConstant.cpp

[PATCH] D148490: [AIX] use system assembler for assembly files

2023-07-09 Thread ChenZheng via Phabricator via cfe-commits
shchenz added a comment.

> What is left for this to be reverted, in the quest to fully enable IAS for 
> AIX?

See `XCOFFAsmParser::ParseDirectiveCSect()` and I think qual symbol names in 
AIX assembly(quite common for AIX assembly) can also not be parsed with llvm's 
asm parser.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148490

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


[PATCH] D154597: [clang][dataflow] Various refactorings to UncheckedOptionalAccessModel.

2023-07-09 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

libcxx and clangd failures look unrelated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154597

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


[PATCH] D154586: [clang][dataflow] Various changes to handling of modeled fields.

2023-07-09 Thread Martin Böhme via Phabricator via cfe-commits
mboehme added a comment.

libcxx failure looks unrelated


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154586

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


[PATCH] D152132: [clang][Inter] Fix lifetime diagnostics for dead records

2023-07-09 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/D152132/new/

https://reviews.llvm.org/D152132

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


[clang] e8a1560 - [clang][dataflow] Various changes to handling of modeled fields.

2023-07-09 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-10T06:45:53Z
New Revision: e8a1560d1de9514d3f1631388fe966476778e540

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

LOG: [clang][dataflow] Various changes to handling of modeled fields.

- Rename `getReferencedFields()` to `getModeledFields()`. Move the logic that
  returns all object fields when doing a context-sensitive analysis to here from
  `DataflowAnalysisContext::createStorageLocation()`. I think all callers of
  the previous `getReferencedFields()` should use this logic; the fact that they
  were not doing so looks like a bug.

- Make `getModeledFields()` public. I have an upcoming patch that will need to
  use this function from Transfer.cpp, and there doesn't seem to be any reason
  why this function should not be public.

- Use a `SmallSetVector` to get deterministic iteration order. I have a pending
  patch where I'm getting flaky tests because
  `Environment::createValueUnlessSelfReferential()` is non-deterministically
  populating different fields depending on the iteration order. This change
  fixes those flaky tests.

Reviewed By: gribozavr2

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index 2a31a3477e8ceb..e5c325b876bd7a 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -51,8 +51,12 @@ class Logger;
 const Expr &ignoreCFGOmittedNodes(const Expr &E);
 const Stmt &ignoreCFGOmittedNodes(const Stmt &S);
 
+/// A set of `FieldDecl *`. Use `SmallSetVector` to guarantee deterministic
+/// iteration order.
+using FieldSet = llvm::SmallSetVector;
+
 /// Returns the set of all fields in the type.
-llvm::DenseSet getObjectFields(QualType Type);
+FieldSet getObjectFields(QualType Type);
 
 struct ContextSensitiveOptions {
   /// The maximum depth to analyze. A value of zero is equivalent to disabling
@@ -181,6 +185,10 @@ class DataflowAnalysisContext {
   /// been stored in flow conditions.
   Solver::Result querySolver(llvm::SetVector Constraints);
 
+  /// Returns the fields of `Type`, limited to the set of fields modeled by 
this
+  /// context.
+  FieldSet getModeledFields(QualType Type);
+
 private:
   friend class Environment;
 
@@ -196,11 +204,7 @@ class DataflowAnalysisContext {
   };
 
   // Extends the set of modeled field declarations.
-  void addModeledFields(const llvm::DenseSet &Fields);
-
-  /// Returns the fields of `Type`, limited to the set of fields modeled by 
this
-  /// context.
-  llvm::DenseSet getReferencedFields(QualType Type);
+  void addModeledFields(const FieldSet &Fields);
 
   /// Adds all constraints of the flow condition identified by `Token` and all
   /// of its transitive dependencies to `Constraints`. `VisitedTokens` is used
@@ -257,7 +261,7 @@ class DataflowAnalysisContext {
   llvm::DenseMap FunctionContexts;
 
   // Fields modeled by environments covered by this context.
-  llvm::DenseSet ModeledFields;
+  FieldSet ModeledFields;
 
   std::unique_ptr LogOwner; // If created via flags.
 };

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index a807ef8209be85..b0c1014e3c975e 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -40,31 +40,28 @@ static llvm::cl::opt DataflowLog(
 namespace clang {
 namespace dataflow {
 
-void DataflowAnalysisContext::addModeledFields(
-const llvm::DenseSet &Fields) {
-  llvm::set_union(ModeledFields, Fields);
+FieldSet DataflowAnalysisContext::getModeledFields(QualType Type) {
+  // During context-sensitive analysis, a struct may be allocated in one
+  // function, but its field accessed in a function lower in the stack than
+  // the allocation. Since we only collect fields used in the function where
+  // the allocation occurs, we can't apply that filter when performing
+  // context-sensitive analysis. But, this only applies to storage locations,
+  // since field access it not allowed to fail. In contrast, field *values*
+  // don't need this allowance, since the API allows for uninitialized fields.
+  if (Opts.ContextSensitiveOpts)
+return getObjectFields(Type);
+
+  return llvm::set_intersection(getObjectFields(Type), ModeledFields);
 }
 
-llvm::DenseSet
-DataflowAnalysis

[clang] f653d14 - [clang][dataflow] Various refactorings to UncheckedOptionalAccessModel.

2023-07-09 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-07-10T06:45:55Z
New Revision: f653d14065a362c98114082c4e9a3b1ede7a90f5

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

LOG: [clang][dataflow] Various refactorings to UncheckedOptionalAccessModel.

These are intended to ease an upcoming change that will eliminate the 
duplication between `AggregateStorageLocation` and `StructValue` (see 
https://discourse.llvm.org/t/70086 for details), but many of the changes also 
have value in their own right.

Depends On D154586

Reviewed By: ymandel, gribozavr2

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp

Removed: 




diff  --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index a239d54674e96c..91aa9d11e751cd 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -255,12 +255,22 @@ void setHasValue(Value &OptionalVal, BoolValue 
&HasValueVal) {
 
 /// Creates a symbolic value for an `optional` value using `HasValueVal` as the
 /// symbolic value of its "has_value" property.
-StructValue &createOptionalValue(Environment &Env, BoolValue &HasValueVal) {
+StructValue &createOptionalValue(BoolValue &HasValueVal, Environment &Env) {
   auto &OptionalVal = Env.create();
   setHasValue(OptionalVal, HasValueVal);
   return OptionalVal;
 }
 
+/// Creates a symbolic value for an `optional` value at an existing storage
+/// location. Uses `HasValueVal` as the symbolic value of the "has_value"
+/// property.
+StructValue &createOptionalValue(AggregateStorageLocation &Loc,
+ BoolValue &HasValueVal, Environment &Env) {
+  StructValue &OptionalVal = createOptionalValue(HasValueVal, Env);
+  Env.setValue(Loc, OptionalVal);
+  return OptionalVal;
+}
+
 /// Returns the symbolic value that represents the "has_value" property of the
 /// optional value `OptionalVal`. Returns null if `OptionalVal` is null.
 BoolValue *getHasValue(Environment &Env, Value *OptionalVal) {
@@ -422,15 +432,6 @@ bool isNonEmptyOptional(const Value &OptionalVal, const 
Environment &Env) {
   return HasValueVal != nullptr && Env.flowConditionImplies(*HasValueVal);
 }
 
-StorageLocation *maybeSkipPointer(StorageLocation *Loc,
-  const Environment &Env) {
-  if (Loc == nullptr)
-return nullptr;
-  if (auto *Val = dyn_cast_or_null(Env.getValue(*Loc)))
-return &Val->getPointeeLoc();
-  return Loc;
-}
-
 Value *getValueBehindPossiblePointer(const Expr &E, const Environment &Env) {
   Value *Val = Env.getValue(E, SkipPast::Reference);
   if (auto *PointerVal = dyn_cast_or_null(Val))
@@ -467,7 +468,7 @@ void transferMakeOptionalCall(const CallExpr *E,
   auto &Loc = State.Env.createStorageLocation(*E);
   State.Env.setStorageLocation(*E, Loc);
   State.Env.setValue(
-  Loc, createOptionalValue(State.Env, 
State.Env.getBoolLiteralValue(true)));
+  Loc, createOptionalValue(State.Env.getBoolLiteralValue(true), 
State.Env));
 }
 
 void transferOptionalHasValueCall(const CXXMemberCallExpr *CallExpr,
@@ -544,15 +545,12 @@ void transferCallReturningOptional(const CallExpr *E,
   auto &Loc = State.Env.createStorageLocation(*E);
   State.Env.setStorageLocation(*E, Loc);
   State.Env.setValue(
-  Loc, createOptionalValue(State.Env, State.Env.makeAtomicBoolValue()));
+  Loc, createOptionalValue(State.Env.makeAtomicBoolValue(), State.Env));
 }
 
-void assignOptionalValue(const Expr &E, Environment &Env,
- BoolValue &HasValueVal) {
-  if (auto *OptionalLoc = maybeSkipPointer(
-  Env.getStorageLocation(E, SkipPast::Reference), Env)) {
-Env.setValue(*OptionalLoc, createOptionalValue(Env, HasValueVal));
-  }
+void constructOptionalValue(const Expr &E, Environment &Env,
+BoolValue &HasValueVal) {
+  Env.setValueStrict(E, createOptionalValue(HasValueVal, Env));
 }
 
 /// Returns a symbolic value for the "has_value" property of an `optional`
@@ -590,25 +588,23 @@ void transferValueOrConversionConstructor(
 LatticeTransferState &State) {
   assert(E->getNumArgs() > 0);
 
-  assignOptionalValue(*E, State.Env,
-  valueOrConversionHasValue(*E->getConstructor(),
-*E->getArg(0), MatchRes,
-State));
+  constructOptionalValue(*E, State.Env,
+ valueOrConversionHasValue(*E->getConstructor(),
+   *E->getArg(0), MatchRes,
+ 

[PATCH] D154586: [clang][dataflow] Various changes to handling of modeled fields.

2023-07-09 Thread Martin Böhme 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 rGe8a1560d1de9: [clang][dataflow] Various changes to handling 
of modeled fields. (authored by mboehme).

Changed prior to commit:
  https://reviews.llvm.org/D154586?vs=537636&id=538515#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154586

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -170,8 +170,7 @@
 }
 
 static void
-getFieldsGlobalsAndFuncs(const Decl &D,
- llvm::DenseSet &Fields,
+getFieldsGlobalsAndFuncs(const Decl &D, FieldSet &Fields,
  llvm::DenseSet &Vars,
  llvm::DenseSet &Funcs) {
   insertIfGlobal(D, Vars);
@@ -188,8 +187,7 @@
 /// global variables and functions that are declared in or referenced from
 /// sub-statements.
 static void
-getFieldsGlobalsAndFuncs(const Stmt &S,
- llvm::DenseSet &Fields,
+getFieldsGlobalsAndFuncs(const Stmt &S, FieldSet &Fields,
  llvm::DenseSet &Vars,
  llvm::DenseSet &Funcs) {
   for (auto *Child : S.children())
@@ -222,7 +220,7 @@
 void Environment::initFieldsGlobalsAndFuncs(const FunctionDecl *FuncDecl) {
   assert(FuncDecl->getBody() != nullptr);
 
-  llvm::DenseSet Fields;
+  FieldSet Fields;
   llvm::DenseSet Vars;
   llvm::DenseSet Funcs;
 
@@ -708,7 +706,7 @@
 const QualType Type = AggregateLoc.getType();
 assert(Type->isRecordType());
 
-for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
+for (const FieldDecl *Field : DACtx->getModeledFields(Type)) {
   assert(Field != nullptr);
   StorageLocation &FieldLoc = AggregateLoc.getChild(*Field);
   MemberLocToStruct[&FieldLoc] = std::make_pair(StructVal, Field);
@@ -846,7 +844,7 @@
   if (Type->isRecordType()) {
 CreatedValuesCount++;
 llvm::DenseMap FieldValues;
-for (const FieldDecl *Field : DACtx->getReferencedFields(Type)) {
+for (const FieldDecl *Field : DACtx->getModeledFields(Type)) {
   assert(Field != nullptr);
 
   QualType FieldType = Field->getType();
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -40,31 +40,28 @@
 namespace clang {
 namespace dataflow {
 
-void DataflowAnalysisContext::addModeledFields(
-const llvm::DenseSet &Fields) {
-  llvm::set_union(ModeledFields, Fields);
+FieldSet DataflowAnalysisContext::getModeledFields(QualType Type) {
+  // During context-sensitive analysis, a struct may be allocated in one
+  // function, but its field accessed in a function lower in the stack than
+  // the allocation. Since we only collect fields used in the function where
+  // the allocation occurs, we can't apply that filter when performing
+  // context-sensitive analysis. But, this only applies to storage locations,
+  // since field access it not allowed to fail. In contrast, field *values*
+  // don't need this allowance, since the API allows for uninitialized fields.
+  if (Opts.ContextSensitiveOpts)
+return getObjectFields(Type);
+
+  return llvm::set_intersection(getObjectFields(Type), ModeledFields);
 }
 
-llvm::DenseSet
-DataflowAnalysisContext::getReferencedFields(QualType Type) {
-  llvm::DenseSet Fields = getObjectFields(Type);
-  llvm::set_intersect(Fields, ModeledFields);
-  return Fields;
+void DataflowAnalysisContext::addModeledFields(const FieldSet &Fields) {
+  ModeledFields.set_union(Fields);
 }
 
 StorageLocation &DataflowAnalysisContext::createStorageLocation(QualType Type) {
   if (!Type.isNull() && Type->isRecordType()) {
 llvm::DenseMap FieldLocs;
-// During context-sensitive analysis, a struct may be allocated in one
-// function, but its field accessed in a function lower in the stack than
-// the allocation. Since we only collect fields used in the function where
-// the allocation occurs, we can't apply that filter when performing
-// context-sensitive analysis. But, this only applies to storage locations,
-// since field access it not allowed to fail. In contrast, field *values*
-// don't need this allowance, since the API allows for uninitialized fields.
-auto Fields = Opts.ContextSensitiveOpts ? getObjectFields(Type)
-

[PATCH] D154597: [clang][dataflow] Various refactorings to UncheckedOptionalAccessModel.

2023-07-09 Thread Martin Böhme 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 rGf653d14065a3: [clang][dataflow] Various refactorings to 
UncheckedOptionalAccessModel. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154597

Files:
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp

Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -255,12 +255,22 @@
 
 /// Creates a symbolic value for an `optional` value using `HasValueVal` as the
 /// symbolic value of its "has_value" property.
-StructValue &createOptionalValue(Environment &Env, BoolValue &HasValueVal) {
+StructValue &createOptionalValue(BoolValue &HasValueVal, Environment &Env) {
   auto &OptionalVal = Env.create();
   setHasValue(OptionalVal, HasValueVal);
   return OptionalVal;
 }
 
+/// Creates a symbolic value for an `optional` value at an existing storage
+/// location. Uses `HasValueVal` as the symbolic value of the "has_value"
+/// property.
+StructValue &createOptionalValue(AggregateStorageLocation &Loc,
+ BoolValue &HasValueVal, Environment &Env) {
+  StructValue &OptionalVal = createOptionalValue(HasValueVal, Env);
+  Env.setValue(Loc, OptionalVal);
+  return OptionalVal;
+}
+
 /// Returns the symbolic value that represents the "has_value" property of the
 /// optional value `OptionalVal`. Returns null if `OptionalVal` is null.
 BoolValue *getHasValue(Environment &Env, Value *OptionalVal) {
@@ -422,15 +432,6 @@
   return HasValueVal != nullptr && Env.flowConditionImplies(*HasValueVal);
 }
 
-StorageLocation *maybeSkipPointer(StorageLocation *Loc,
-  const Environment &Env) {
-  if (Loc == nullptr)
-return nullptr;
-  if (auto *Val = dyn_cast_or_null(Env.getValue(*Loc)))
-return &Val->getPointeeLoc();
-  return Loc;
-}
-
 Value *getValueBehindPossiblePointer(const Expr &E, const Environment &Env) {
   Value *Val = Env.getValue(E, SkipPast::Reference);
   if (auto *PointerVal = dyn_cast_or_null(Val))
@@ -467,7 +468,7 @@
   auto &Loc = State.Env.createStorageLocation(*E);
   State.Env.setStorageLocation(*E, Loc);
   State.Env.setValue(
-  Loc, createOptionalValue(State.Env, State.Env.getBoolLiteralValue(true)));
+  Loc, createOptionalValue(State.Env.getBoolLiteralValue(true), State.Env));
 }
 
 void transferOptionalHasValueCall(const CXXMemberCallExpr *CallExpr,
@@ -544,15 +545,12 @@
   auto &Loc = State.Env.createStorageLocation(*E);
   State.Env.setStorageLocation(*E, Loc);
   State.Env.setValue(
-  Loc, createOptionalValue(State.Env, State.Env.makeAtomicBoolValue()));
+  Loc, createOptionalValue(State.Env.makeAtomicBoolValue(), State.Env));
 }
 
-void assignOptionalValue(const Expr &E, Environment &Env,
- BoolValue &HasValueVal) {
-  if (auto *OptionalLoc = maybeSkipPointer(
-  Env.getStorageLocation(E, SkipPast::Reference), Env)) {
-Env.setValue(*OptionalLoc, createOptionalValue(Env, HasValueVal));
-  }
+void constructOptionalValue(const Expr &E, Environment &Env,
+BoolValue &HasValueVal) {
+  Env.setValueStrict(E, createOptionalValue(HasValueVal, Env));
 }
 
 /// Returns a symbolic value for the "has_value" property of an `optional`
@@ -590,25 +588,23 @@
 LatticeTransferState &State) {
   assert(E->getNumArgs() > 0);
 
-  assignOptionalValue(*E, State.Env,
-  valueOrConversionHasValue(*E->getConstructor(),
-*E->getArg(0), MatchRes,
-State));
+  constructOptionalValue(*E, State.Env,
+ valueOrConversionHasValue(*E->getConstructor(),
+   *E->getArg(0), MatchRes,
+   State));
 }
 
 void transferAssignment(const CXXOperatorCallExpr *E, BoolValue &HasValueVal,
 LatticeTransferState &State) {
   assert(E->getNumArgs() > 0);
 
-  auto *OptionalLoc =
-  State.Env.getStorageLocation(*E->getArg(0), SkipPast::Reference);
-  if (OptionalLoc == nullptr)
-return;
-
-  State.Env.setValue(*OptionalLoc, createOptionalValue(State.Env, HasValueVal));
+  if (auto *Loc = cast(
+  State.Env.getStorageLocationStrict(*E->getArg(0 {
+createOptionalValue(*Loc, HasValueVal, State.Env);
 
-  // Assign a storage location for the whole expression.
-  State.Env.setStorageLocation(*E, *OptionalLoc);
+// Assign a storage location for the whole expression.
+State.Env.setStorageLocationStrict

[PATCH] D154675: [Clang] Fix crash when emitting diagnostic for out of order designated initializers in C++

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

Thanks, this looks good! (the libc++ test seems completely unrelated, it 
happens before compilation starts).
Can you add re release note though? Thanks!


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

https://reviews.llvm.org/D154675

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