[PATCH] D152785: [COFF] Support -gsplit-dwarf for COFF on Windows

2023-06-24 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen closed this revision.
HaohaiWen added a comment.

Thanks.
This patch has been landed. 
https://github.com/llvm/llvm-project/commit/3eee5aa528abd67bb6d057e25ce1980d0d38c445


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152785

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


[clang] 3eee5aa - [COFF] Support -gsplit-dwarf for COFF on Windows

2023-06-24 Thread via cfe-commits

Author: Haohai Wen
Date: 2023-06-25T11:54:39+08:00
New Revision: 3eee5aa528abd67bb6d057e25ce1980d0d38c445

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

LOG: [COFF] Support -gsplit-dwarf for COFF on Windows

D152340 has split WinCOFFObjectWriter to WinCOFFWriter. This patch adds
another WinCOFFWriter as DwoWriter to write Dwo sections to dwo file.
Driver options are also updated accordingly to support -gsplit-dwarf in
CL mode.

e.g. $ clang-cl  -c -gdwarf -gsplit-dwarf foo.c

Like what -gsplit-dwarf did in ELF, using this option will create DWARF object
(.dwo) file. DWARF debug info is split between COFF object and DWARF object
file. It can reduce the executable file size especially for large project.

Reviewed By: skan, MaskRay

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

Added: 
llvm/test/DebugInfo/COFF/dwarf-headers.ll
llvm/test/DebugInfo/COFF/fission-cu.ll
llvm/test/DebugInfo/COFF/fission-sections.ll

Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/split-debug.c
llvm/include/llvm/MC/MCWinCOFFObjectWriter.h
llvm/lib/MC/MCAsmBackend.cpp
llvm/lib/MC/WinCOFFObjectWriter.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index bb3d487886eb7..77dcef9c73b9e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3434,11 +3434,13 @@ defm column_info : BoolOption<"g", "column-info",
   CodeGenOpts<"DebugColumnInfo">, DefaultTrue,
   NegFlag, PosFlag, BothFlags<[CoreOption]>>,
   Group;
-def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group;
+def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group,
+  Flags<[CoreOption]>;
 def gsplit_dwarf_EQ : Joined<["-"], "gsplit-dwarf=">, Group,
-  HelpText<"Set DWARF fission mode">,
+  Flags<[CoreOption]>, HelpText<"Set DWARF fission mode">,
   Values<"split,single">;
-def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group;
+def gno_split_dwarf : Flag<["-"], "gno-split-dwarf">, Group,
+  Flags<[CoreOption]>;
 def gsimple_template_names : Flag<["-"], "gsimple-template-names">, 
Group;
 def gsimple_template_names_EQ
 : Joined<["-"], "gsimple-template-names=">,

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 696db21d97c51..1580f092bcde0 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3925,12 +3925,13 @@ void Driver::handleArguments(Compilation , 
DerivedArgList ,
 // `-dumpdir x-` to cc1. If -o is unspecified, use
 // stem(getDefaultImageName()) (usually stem("a.out") = "a").
 if (!Args.hasArg(options::OPT_dumpdir)) {
+  Arg *FinalOutput = Args.getLastArg(options::OPT_o, 
options::OPT__SLASH_o);
   Arg *Arg = Args.MakeSeparateArg(
   nullptr, getOpts().getOption(options::OPT_dumpdir),
-  Args.MakeArgString(Args.getLastArgValue(
- options::OPT_o,
- llvm::sys::path::stem(getDefaultImageName())) 
+
- "-"));
+  Args.MakeArgString(
+  (FinalOutput ? FinalOutput->getValue()
+   : llvm::sys::path::stem(getDefaultImageName())) +
+  "-"));
   Arg->claim();
   Args.append(Arg);
 }

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index de22ea4455fa7..82e135012d6c9 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5647,7 +5647,8 @@ void Clang::ConstructJob(Compilation , const JobAction 
,
   // can propagate it to the backend.
   bool SplitDWARF = (DwarfFission != DwarfFissionKind::None) &&
 (TC.getTriple().isOSBinFormatELF() ||
- TC.getTriple().isOSBinFormatWasm()) &&
+ TC.getTriple().isOSBinFormatWasm() ||
+ TC.getTriple().isOSBinFormatCOFF()) &&
 (isa(JA) || isa(JA) ||
  isa(JA));
   if (SplitDWARF) {

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 4afe3cc1f7a6e..61b26cf1d3d19 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1278,7 +1278,7 @@ const char *tools::SplitDebugName(const JobAction , 
const ArgList ,
   if (const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
 T = A->getValue();
   } else {
-Arg *FinalOutput = Args.getLastArg(options::OPT_o);
+Arg *FinalOutput = Args.getLastArg(options::OPT_o, options::OPT__SLASH_o);
 if (FinalOutput && 

[PATCH] D153714: [NFC] Add missing cpu tests in predefined-arch-macros.c

2023-06-24 Thread Freddy, Ye via Phabricator via cfe-commits
FreddyYe created this revision.
Herald added a project: All.
FreddyYe requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Added tests for penryn, nehalem, westmere, sandybridge, ivybridge,
haswell, bonnell, silvermont.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153714

Files:
  clang/test/Preprocessor/predefined-arch-macros.c

Index: clang/test/Preprocessor/predefined-arch-macros.c
===
--- clang/test/Preprocessor/predefined-arch-macros.c
+++ clang/test/Preprocessor/predefined-arch-macros.c
@@ -365,9 +365,13 @@
 // RUN: %clang -march=core2 -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_CORE2_M32
+// RUN: %clang -march=penryn -m32 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_CORE2_M32,CHECK_PENRYN_M32
 // CHECK_CORE2_M32: #define __MMX__ 1
 // CHECK_CORE2_M32: #define __SSE2__ 1
 // CHECK_CORE2_M32: #define __SSE3__ 1
+// CHECK_PENRYN_M32: #define __SSE4_1__ 1
 // CHECK_CORE2_M32: #define __SSE__ 1
 // CHECK_CORE2_M32: #define __SSSE3__ 1
 // CHECK_CORE2_M32: #define __core2 1
@@ -380,10 +384,14 @@
 // RUN: %clang -march=core2 -m64 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_CORE2_M64
+// RUN: %clang -march=penryn -m64 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_CORE2_M64,CHECK_PENRYN_M64
 // CHECK_CORE2_M64: #define __MMX__ 1
 // CHECK_CORE2_M64: #define __SSE2_MATH__ 1
 // CHECK_CORE2_M64: #define __SSE2__ 1
 // CHECK_CORE2_M64: #define __SSE3__ 1
+// CHECK_PENRYN_M64: #define __SSE4_1__ 1
 // CHECK_CORE2_M64: #define __SSE_MATH__ 1
 // CHECK_CORE2_M64: #define __SSE__ 1
 // CHECK_CORE2_M64: #define __SSSE3__ 1
@@ -398,7 +406,15 @@
 // RUN: %clang -march=corei7 -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_COREI7_M32
+// RUN: %clang -march=nehalem -m32 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_COREI7_M32
+// RUN: %clang -march=westmere -m32 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_COREI7_M32,CHECK_WESTMERE_M32
+// CHECK_COREI7_M32: #define __CRC32__ 1
 // CHECK_COREI7_M32: #define __MMX__ 1
+// CHECK_WESTMERE_M32: #define __PCLMUL__ 1
 // CHECK_COREI7_M32: #define __POPCNT__ 1
 // CHECK_COREI7_M32: #define __SSE2__ 1
 // CHECK_COREI7_M32: #define __SSE3__ 1
@@ -416,7 +432,15 @@
 // RUN: %clang -march=corei7 -m64 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_COREI7_M64
+// RUN: %clang -march=nehalem -m64 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_COREI7_M64
+// RUN: %clang -march=westmere -m64 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefixes=CHECK_COREI7_M64,CHECK_WESTMERE_M64
+// CHECK_COREI7_M64: #define __CRC32__ 1
 // CHECK_COREI7_M64: #define __MMX__ 1
+// CHECK_WESTMERE_M64: #define __PCLMUL__ 1
 // CHECK_COREI7_M64: #define __POPCNT__ 1
 // CHECK_COREI7_M64: #define __SSE2_MATH__ 1
 // CHECK_COREI7_M64: #define __SSE2__ 1
@@ -437,6 +461,9 @@
 // RUN: %clang -march=corei7-avx -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_COREI7_AVX_M32
+// RUN: %clang -march=sandybridge -m32 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_COREI7_AVX_M32
 // CHECK_COREI7_AVX_M32: #define __AVX__ 1
 // CHECK_COREI7_AVX_M32: #define __MMX__ 1
 // CHECK_COREI7_AVX_M32: #define __PCLMUL__ 1
@@ -460,6 +487,9 @@
 // RUN: %clang -march=corei7-avx -m64 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_COREI7_AVX_M64
+// RUN: %clang -march=sandybridge -m64 -E -dM %s -o - 2>&1 \
+// RUN: -target i386-unknown-linux \
+// RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_COREI7_AVX_M64
 // CHECK_COREI7_AVX_M64: #define __AVX__ 1
 // CHECK_COREI7_AVX_M64: #define __MMX__ 1
 // CHECK_COREI7_AVX_M64: #define __PCLMUL__ 1
@@ -486,6 +516,9 @@
 // RUN: %clang -march=core-avx-i -m32 -E -dM %s -o - 2>&1 \
 // RUN: -target i386-unknown-linux \
 // RUN:   | FileCheck -match-full-lines %s -check-prefix=CHECK_CORE_AVX_I_M32
+// RUN: %clang -march=ivybridge -m32 -E -dM %s -o - 2>&1 \
+// RUN: -target 

[clang] df8d6d9 - [clang] Fix pretty-printing for variables declared in a for-loop condition

2023-06-24 Thread Fangrui Song via cfe-commits

Author: Vaibhav Thakkar
Date: 2023-06-24T19:27:10-07:00
New Revision: df8d6d95ca64c70b3acc5a4266326966f3e6f93e

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

LOG: [clang] Fix pretty-printing for variables declared in a for-loop condition

Reviewed By: MaskRay

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

Added: 


Modified: 
clang/lib/AST/StmtPrinter.cpp
clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
clang/test/SemaCXX/ast-print.cpp

Removed: 




diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index d62b7e52e8e6d..c3db500d8a8de 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ b/clang/lib/AST/StmtPrinter.cpp
@@ -400,7 +400,9 @@ void StmtPrinter::VisitForStmt(ForStmt *Node) {
 PrintInitStmt(Node->getInit(), 5);
   else
 OS << (Node->getCond() ? "; " : ";");
-  if (Node->getCond())
+  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
+PrintRawDeclStmt(DS);
+  else if (Node->getCond())
 PrintExpr(Node->getCond());
   OS << ";";
   if (Node->getInc()) {

diff  --git a/clang/test/PCH/for-loop-init-ternary-operator-statement.cpp 
b/clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
index 50819e79e6f6f..8bce3e8eeb3c4 100644
--- a/clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
+++ b/clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s
 
 int f() {
-  // CHECK: for (int i = 0; x; i++) {
+  // CHECK: for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
   for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
 return x;
   }

diff  --git a/clang/test/SemaCXX/ast-print.cpp 
b/clang/test/SemaCXX/ast-print.cpp
index fd1d3fe84fac3..2cb1ec440b6bb 100644
--- a/clang/test/SemaCXX/ast-print.cpp
+++ b/clang/test/SemaCXX/ast-print.cpp
@@ -21,12 +21,14 @@ void test1() {
 // CHECK: if (int a = 1)
 // CHECK:  while (int a = 1)
 // CHECK:  switch (int a = 1)
+// CHECK:  for (; int a = 1;)
 
 void test2()
 {
 if (int a = 1) { }
 while (int a = 1) { }
 switch (int a = 1) { }
+for(; int a = 1; ) { }
 }
 
 // CHECK: new (1) int;



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


[PATCH] D152785: [COFF] Support -gsplit-dwarf for COFF on Windows

2023-06-24 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen added a comment.

@MaskRay, any other comments? I'd like to land this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152785

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


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

2023-06-24 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert added inline comments.



Comment at: clang/lib/Analysis/ThreadSafety.cpp:2436
+CF.getVarDecl()->getLocation());
+  break;
+}

tbaeder wrote:
> This handles the function call, but without the instance parameter. I was 
> wondering how to best do that.
Should you not simply pass `SxBuilder.createVariable(CF.getVarDecl())` as third 
parameter in analogy with the `AutomaticObjectDtor` case? It might also make 
sense to copy the attribute check.



Comment at: clang/test/Sema/warn-thread-safety-analysis.c:76-77
 
+void cleanup_int(int *unused) __attribute__((release_capability(mu1))) {
+  (void)unused;
+  mutex_exclusive_unlock();





Comment at: clang/test/Sema/warn-thread-safety-analysis.c:136
 
+
+  {

Nitpick: one blank line is enough.


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

https://reviews.llvm.org/D152504

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


[PATCH] D153001: [clang][ThreadSafety] Add __builtin_instance_member (WIP)

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

I'm wondering why you chose this over a direct equivalent to `this`, say 
`__builtin_instance()`, such that instead of `__builtin_instance_member(M)` one 
would write `__builtin_instance().M` or `__builtin_instance()->M`? While 
allowing to reference the same fields, it would additionally allow referencing 
the object itself. That's not so interesting for Thread Safety Analysis, 
because many attributes refer to `this` if no argument is given, but it might 
be helpful for other analyses.

It also seems cleaner C/C++ to me, as you can read the expression in the usual 
way, whereas in `__builtin_instance_member(M)`, `M` is not a `DeclRefExpr`. And 
you could do `#define THIS __builtin_instance()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153001

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


[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-06-24 Thread Josh Haberman via Phabricator via cfe-commits
haberman added a comment.

I think I misunderstood @yamt's comment in 
https://reviews.llvm.org/D147714#4446780. I take back what I wrote above.

I agree that `[[clang::nonportable_musttail]]` is a nicer semantic, and the 
restrictions around the existing `[[clang:musttail]]` don't seem to buy us very 
much, since they are not universal enough to give a true assurance.

If someone could land a change to both LLVM and Clang to change the existing 
attribute, I would have no objection. But I have no idea what is involved in 
landing a backend (LLVM) change of that magnitude, especially since it would 
touch all the arch-specific backends.


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

https://reviews.llvm.org/D147714

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


[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-06-24 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> If all you want is (1), that doesn't require any attribute (the optimizer 
>> will do it automatically).

Not entirely true, as compiler can do anything. In some cases you really need 
*musttail* (in llvm IR) to get or preserve tail call.


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

https://reviews.llvm.org/D147714

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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-24 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked 2 inline comments as done.
mikecrowe added a comment.

Thanks for the further reviews.




Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:37
+
+  if (PrintfLikeFunctions.empty() && FprintfLikeFunctions.empty()) {
+PrintfLikeFunctions.push_back("::printf");

PiotrZSL wrote:
> those 2 looks in-depended. Cannot they be put as default value into Option 
> config ?
My expectation was that if you didn't want to replace `printf` (and instead 
wanted to replace some other `printf`-like function) then you'd also not want 
to replace `fprintf` and vice-versa. In my head the two options do go together. 
If setting one didn't also remove the default for the other you'd end up having 
to specify `PrintfLikeFunctions=my_printf, FPrintfLikeFunctions=` just to 
replace a single function.



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:79
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(
+  matchers::matchesAnyListedName(FprintfLikeFunctions))

PiotrZSL wrote:
> this could match also methods, maybe something `unless(cxxMethodDecl())` ?
I would like to be able to match methods. The code I wrote this check to run on 
has classes that have methods that used to call `std::fprintf`, and currently 
call `fmt::fprintf`. I wish to convert those methods to use `fmt::print` and 
use this check to fix all their callers. Eventually I hope to be able to move 
to `std::print`.

However, the check doesn't currently seem to work for methods since the 
arguments are off-by-one and the replacement is incorrect too. I'll add the 
`unless(cxxMethodDecl)` checks for now and support can be added later.



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:82
+  .bind("func_decl")),
+   hasArgument(1, stringLiteral()))
+  .bind("fprintf"),

PiotrZSL wrote:
> consider moving this stringLiteral to be first, consider adding something 
> like `unless(argumentCountIs(0)), unless(argumentCountIs(1))`` at begining or 
> create matcher that verify first that argument count is >= 2, so we could 
> exlude most of callExpr at begining, even before we match functions
I would have hoped that `hasArgument` would fail quite fast if the argument 
index passed is greater than the number of arguments. I will add 
`argumentCountAtLeast` and use it regardless though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-06-24 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:4967
 
+void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  const TargetInfo  = Context.getTargetInfo();

craig.topper wrote:
> What about the bool types? Is it sufficient to check Zve32x is enabled after 
> all the other checks? The caller already checked for it being an RVV type so 
> if we are in the function the type is RVV.
I don't think this comment was addressed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

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


[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-06-24 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D147714#4446809 , @haberman wrote:

>> Such a definition doesn't make much sense because for some targets tail call 
>> optimization isn't available at all.
>> Eg. Wasm w/o tail call proposal, xtensa windowed abi.
>
> That is true. But what is the correct behavior if you try to use 
> `[[clang::musttail]]` on such a target? In my case, I want to get a compiler 
> error, because if a tail call cannot be performed, the algorithm is incorrect 
> (it will cause stack overflow at runtime).
>
> There are three possible semantics that I can see:
>
> 1. Perform a tail call if possible.
> 2. Perform a tail call, fail to compile if this is not possible 
> (`[[clang::nonportable_musttail]]`)
> 3. Perform a tail call, fail to compile if this is not possible //or// if the 
> function signatures between caller and callee differ in ways that make tail 
> calls difficult on some platforms (`[[clang::musttail]]`)
>
> Both (2) and (3) would fail to compile on Wasm without tail calls. If all you 
> want is (1), that doesn't require any attribute (the optimizer will do it 
> automatically).

So clearly definition “musttail provide assurances that the tail call can be 
optimized on all targets.” is broken in reality.

Code with musttail will compile fine on x86, and musttail ensures that should 
compile to tail calls on other targets - not a case, on eg. wasm you get just 
an error.


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

https://reviews.llvm.org/D147714

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


[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-06-24 Thread Josh Haberman via Phabricator via cfe-commits
haberman added a comment.

> Such a definition doesn't make much sense because for some targets tail call 
> optimization isn't available at all.
> Eg. Wasm w/o tail call proposal, xtensa windowed abi.

That is true. But what is the correct behavior if you try to use 
`[[clang::musttail]]` on such a target? In my case, I want to get a compiler 
error, because if a tail call cannot be performed, the algorithm is incorrect 
(it will cause stack overflow at runtime).

There are three possible semantics that I can see:

1. Perform a tail call if possible.
2. Perform a tail call, fail to compile if this is not possible 
(`[[clang::nonportable_musttail]]`)
3. Perform a tail call, fail to compile if this is not possible //or// if the 
function signatures between caller and callee differ in ways that make tail 
calls difficult on some platforms (`[[clang::musttail]]`)

Both (2) and (3) would fail to compile on Wasm without tail calls. If all you 
want is (1), that doesn't require any attribute (the optimizer will do it 
automatically).


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

https://reviews.llvm.org/D147714

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


[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-06-24 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

In D147714#4446780 , @yamt wrote:

>> musttail provide assurances that the tail call can be optimized on all 
>> targets.
>
> Such a definition doesn't make much sense because for some targets tail call 
> optimization isn't available at all.
> Eg. Wasm w/o tail call proposal, xtensa windowed abi.
>
> So I'm not sure what's the point of the new attribute. It seems simpler to 
> fix the existing musttail attribute.

I agree, I consider the original design of this feature as a mistake, which 
made this attribute kinda unreliable and useless.. I dont think people are 
willing to just change existing impl of musttail attribute...


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

https://reviews.llvm.org/D147714

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


[PATCH] D147714: [Attr] Introduce [[clang::nonportable_musttail]] as less strict version of [[clang::musttail]]

2023-06-24 Thread YAMAMOTO Takashi via Phabricator via cfe-commits
yamt added a comment.

> musttail provide assurances that the tail call can be optimized on all 
> targets.

Such a definition doesn't make much sense because for some targets tail call 
optimization isn't available at all.
Eg. Wasm w/o tail call proposal, xtensa windowed abi.

So I'm not sure what's the point of the new attribute. It seems simpler to fix 
the existing musttail attribute.


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

https://reviews.llvm.org/D147714

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


[PATCH] D153699: [clang] Fix pretty-printing for variables declared in a for-loop condition

2023-06-24 Thread Vaibhav Thakkar via Phabricator via cfe-commits
vaithak added a comment.

Please commit this change for me as I don't have commit access. Thanks 
My details: "Vaibhav Thakkar" 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153699

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


[PATCH] D148958: Size and element numbers are often swapped when calling calloc

2023-06-24 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 534244.

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

https://reviews.llvm.org/D148958

Files:
  clang/test/Analysis/malloc.mm
  clang/test/Analysis/uninit-vals.m
  clang/test/CodeGen/alloc-size.c
  compiler-rt/lib/profile/InstrProfilingFile.c
  compiler-rt/test/tsan/java_finalizer2.cpp
  flang/runtime/ragged.cpp

Index: flang/runtime/ragged.cpp
===
--- flang/runtime/ragged.cpp
+++ flang/runtime/ragged.cpp
@@ -32,10 +32,9 @@
 header->flags = (rank << 1) | isHeader;
 header->extentPointer = extentVector;
 if (isHeader) {
-  header->bufferPointer = std::calloc(sizeof(RaggedArrayHeader), size);
+  header->bufferPointer = std::calloc(size, sizeof(RaggedArrayHeader));
 } else {
-  header->bufferPointer =
-  static_cast(std::calloc(elementSize, size));
+  header->bufferPointer = std::calloc(size, elementSize);
 }
 return header;
   } else {
Index: compiler-rt/test/tsan/java_finalizer2.cpp
===
--- compiler-rt/test/tsan/java_finalizer2.cpp
+++ compiler-rt/test/tsan/java_finalizer2.cpp
@@ -51,7 +51,7 @@
 }
 
 int main() {
-  Heap* heap = (Heap*)calloc(sizeof(Heap), 2) + 1;
+  Heap* heap = (Heap*)calloc(2, sizeof(Heap)) + 1;
   __tsan_java_init((jptr)heap, sizeof(*heap));
   __tsan_java_alloc((jptr)heap, sizeof(*heap));
   // Ballast threads merely make the bug a bit easier to trigger.
Index: compiler-rt/lib/profile/InstrProfilingFile.c
===
--- compiler-rt/lib/profile/InstrProfilingFile.c
+++ compiler-rt/lib/profile/InstrProfilingFile.c
@@ -293,10 +293,10 @@
 COMPILER_RT_VISIBILITY ProfBufferIO *
 lprofCreateBufferIOInternal(void *File, uint32_t BufferSz) {
   FreeHook = 
-  DynamicBufferIOBuffer = (uint8_t *)calloc(BufferSz, 1);
+  DynamicBufferIOBuffer = (uint8_t *)calloc(1, BufferSz);
   VPBufferSize = BufferSz;
   ProfDataWriter *fileWriter =
-  (ProfDataWriter *)calloc(sizeof(ProfDataWriter), 1);
+  (ProfDataWriter *)calloc(1, sizeof(ProfDataWriter));
   initFileWriter(fileWriter, File);
   ProfBufferIO *IO = lprofCreateBufferIO(fileWriter);
   IO->OwnFileWriter = 1;
Index: clang/test/CodeGen/alloc-size.c
===
--- clang/test/CodeGen/alloc-size.c
+++ clang/test/CodeGen/alloc-size.c
@@ -137,7 +137,7 @@
   // CHECK: store i32 36
   gi = OBJECT_SIZE_BUILTIN(>t[1], 3);
 
-  struct Data *const arr = my_calloc(sizeof(*data), 2);
+  struct Data *const arr = my_calloc(2, sizeof(*data));
   // CHECK: store i32 96
   gi = OBJECT_SIZE_BUILTIN(arr, 0);
   // CHECK: store i32 96
@@ -171,7 +171,7 @@
   // CHECK: store i32 11
   gi = OBJECT_SIZE_BUILTIN(data->end, 3);
 
-  struct Data *const arr = my_calloc(sizeof(*arr) + 5, 3);
+  struct Data *const arr = my_calloc(3, sizeof(*arr) + 5);
   // AFAICT, GCC treats malloc and calloc identically. So, we should do the
   // same.
   //
Index: clang/test/Analysis/uninit-vals.m
===
--- clang/test/Analysis/uninit-vals.m
+++ clang/test/Analysis/uninit-vals.m
@@ -158,7 +158,7 @@
 }
 
 void PR14765_test(void) {
-  Circle *testObj = calloc(sizeof(Circle), 1);
+  Circle *testObj = calloc(1, sizeof(Circle));
 
   clang_analyzer_eval(testObj->size == 0); // expected-warning{{TRUE}}
// expected-note@-1{{TRUE}}
@@ -207,7 +207,7 @@
 }
 
 void PR14765_test_int(void) {
-  IntCircle *testObj = calloc(sizeof(IntCircle), 1);
+  IntCircle *testObj = calloc(1, sizeof(IntCircle));
 
   clang_analyzer_eval(testObj->size == 0); // expected-warning{{TRUE}}
// expected-note@-1{{TRUE}}
@@ -311,7 +311,7 @@
 }
 
 void testSmallStructInLargerStruct(void) {
-  IntCircle2D *testObj = calloc(sizeof(IntCircle2D), 1);
+  IntCircle2D *testObj = calloc(1, sizeof(IntCircle2D));
 
   clang_analyzer_eval(testObj->size == 0); // expected-warning{{TRUE}}
// expected-note@-1{{TRUE}}
Index: clang/test/Analysis/malloc.mm
===
--- clang/test/Analysis/malloc.mm
+++ clang/test/Analysis/malloc.mm
@@ -116,17 +116,17 @@
 }
 
 void testNoCopy() {
-  char *p = (char *)calloc(sizeof(int), 1);
+  char *p = (char *)calloc(1, sizeof(int));
   CustomData *w = [CustomData somethingNoCopy:p]; // no-warning
 }
 
 void testFreeWhenDone() {
-  char *p = (char *)calloc(sizeof(int), 1);
+  char *p = (char *)calloc(1, sizeof(int));
   CustomData *w = [CustomData something:p freeWhenDone:1]; // no-warning
 }
 
 void testFreeWhenDonePositive() {
-  char *p = (char *)calloc(sizeof(int), 1);
+  char *p = (char *)calloc(1, sizeof(int));
   CustomData *w = [CustomData something:p freeWhenDone:0]; // expected-warning{{leak}}
 }
 

[PATCH] D148958: Size and element numbers are often swapped when calling calloc

2023-06-24 Thread Alf via Phabricator via cfe-commits
gAlfonso-bit updated this revision to Diff 534242.

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

https://reviews.llvm.org/D148958

Files:
  clang/test/Analysis/malloc.mm
  clang/test/Analysis/uninit-vals.m
  clang/test/CodeGen/alloc-size.c
  compiler-rt/lib/profile/InstrProfilingFile.c
  compiler-rt/test/tsan/java_finalizer2.cpp
  flang/runtime/ragged.cpp

Index: flang/runtime/ragged.cpp
===
--- flang/runtime/ragged.cpp
+++ flang/runtime/ragged.cpp
@@ -32,10 +32,9 @@
 header->flags = (rank << 1) | isHeader;
 header->extentPointer = extentVector;
 if (isHeader) {
-  header->bufferPointer = std::calloc(sizeof(RaggedArrayHeader), size);
+  header->bufferPointer = std::calloc(size, sizeof(RaggedArrayHeader));
 } else {
-  header->bufferPointer =
-  static_cast(std::calloc(elementSize, size));
+  header->bufferPointer = std::calloc(size, elementSize);
 }
 return header;
   } else {
Index: compiler-rt/test/tsan/java_finalizer2.cpp
===
--- compiler-rt/test/tsan/java_finalizer2.cpp
+++ compiler-rt/test/tsan/java_finalizer2.cpp
@@ -51,7 +51,7 @@
 }
 
 int main() {
-  Heap* heap = (Heap*)calloc(sizeof(Heap), 2) + 1;
+  Heap* heap = (Heap*)calloc(2, sizeof(Heap)) + 1;
   __tsan_java_init((jptr)heap, sizeof(*heap));
   __tsan_java_alloc((jptr)heap, sizeof(*heap));
   // Ballast threads merely make the bug a bit easier to trigger.
Index: compiler-rt/lib/profile/InstrProfilingFile.c
===
--- compiler-rt/lib/profile/InstrProfilingFile.c
+++ compiler-rt/lib/profile/InstrProfilingFile.c
@@ -293,10 +293,10 @@
 COMPILER_RT_VISIBILITY ProfBufferIO *
 lprofCreateBufferIOInternal(void *File, uint32_t BufferSz) {
   FreeHook = 
-  DynamicBufferIOBuffer = (uint8_t *)calloc(BufferSz, 1);
+  DynamicBufferIOBuffer = (uint8_t *)calloc(1, BufferSz);
   VPBufferSize = BufferSz;
   ProfDataWriter *fileWriter =
-  (ProfDataWriter *)calloc(sizeof(ProfDataWriter), 1);
+  (ProfDataWriter *)calloc(1, sizeof(ProfDataWriter));
   initFileWriter(fileWriter, File);
   ProfBufferIO *IO = lprofCreateBufferIO(fileWriter);
   IO->OwnFileWriter = 1;
Index: clang/test/CodeGen/alloc-size.c
===
--- clang/test/CodeGen/alloc-size.c
+++ clang/test/CodeGen/alloc-size.c
@@ -137,7 +137,7 @@
   // CHECK: store i32 36
   gi = OBJECT_SIZE_BUILTIN(>t[1], 3);
 
-  struct Data *const arr = my_calloc(sizeof(*data), 2);
+  struct Data *const arr = my_calloc(2, sizeof(*data));
   // CHECK: store i32 96
   gi = OBJECT_SIZE_BUILTIN(arr, 0);
   // CHECK: store i32 96
@@ -171,7 +171,7 @@
   // CHECK: store i32 11
   gi = OBJECT_SIZE_BUILTIN(data->end, 3);
 
-  struct Data *const arr = my_calloc(sizeof(*arr) + 5, 3);
+  struct Data *const arr = my_calloc(3, sizeof(*arr) + 5);
   // AFAICT, GCC treats malloc and calloc identically. So, we should do the
   // same.
   //
Index: clang/test/Analysis/uninit-vals.m
===
--- clang/test/Analysis/uninit-vals.m
+++ clang/test/Analysis/uninit-vals.m
@@ -158,7 +158,7 @@
 }
 
 void PR14765_test(void) {
-  Circle *testObj = calloc(sizeof(Circle), 1);
+  Circle *testObj = calloc(1, sizeof(Circle));
 
   clang_analyzer_eval(testObj->size == 0); // expected-warning{{TRUE}}
// expected-note@-1{{TRUE}}
@@ -207,7 +207,7 @@
 }
 
 void PR14765_test_int(void) {
-  IntCircle *testObj = calloc(sizeof(IntCircle), 1);
+  IntCircle *testObj = calloc(1, sizeof(IntCircle));
 
   clang_analyzer_eval(testObj->size == 0); // expected-warning{{TRUE}}
// expected-note@-1{{TRUE}}
@@ -311,7 +311,7 @@
 }
 
 void testSmallStructInLargerStruct(void) {
-  IntCircle2D *testObj = calloc(sizeof(IntCircle2D), 1);
+  IntCircle2D *testObj = calloc(1, sizeof(IntCircle2D));
 
   clang_analyzer_eval(testObj->size == 0); // expected-warning{{TRUE}}
// expected-note@-1{{TRUE}}
Index: clang/test/Analysis/malloc.mm
===
--- clang/test/Analysis/malloc.mm
+++ clang/test/Analysis/malloc.mm
@@ -116,17 +116,17 @@
 }
 
 void testNoCopy() {
-  char *p = (char *)calloc(sizeof(int), 1);
+  char *p = (char *)calloc(1, sizeof(int));
   CustomData *w = [CustomData somethingNoCopy:p]; // no-warning
 }
 
 void testFreeWhenDone() {
-  char *p = (char *)calloc(sizeof(int), 1);
+  char *p = (char *)calloc(1, sizeof(int));
   CustomData *w = [CustomData something:p freeWhenDone:1]; // no-warning
 }
 
 void testFreeWhenDonePositive() {
-  char *p = (char *)calloc(sizeof(int), 1);
+  char *p = (char *)calloc(1, sizeof(int));
   CustomData *w = [CustomData something:p freeWhenDone:0]; // expected-warning{{leak}}
 }
 

[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-24 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n updated this revision to Diff 534241.
xen0n added a comment.

Fix faulty refactor (unintended always-error case).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153707

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/test/Driver/loongarch-mdouble-float.c
  clang/test/Driver/loongarch-msingle-float.c
  clang/test/Driver/loongarch-msoft-float.c

Index: clang/test/Driver/loongarch-msoft-float.c
===
--- clang/test/Driver/loongarch-msoft-float.c
+++ clang/test/Driver/loongarch-msoft-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=64'
-// WARN: warning: argument unused during compilation: '-mabi=lp64d'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=0'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64s'
+// WARN: warning: the -mabi setting 'lp64d' conflicts with that implied by -m*-float (lp64s); using lp64s
+// WARN: warning: the -mfpu setting '64' conflicts with that implied by -m*-float (0); using 0
 
 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64s"
Index: clang/test/Driver/loongarch-msingle-float.c
===
--- clang/test/Driver/loongarch-msingle-float.c
+++ clang/test/Driver/loongarch-msingle-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=32'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64f'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64f); using lp64f
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (32); using 32
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64f"
Index: clang/test/Driver/loongarch-mdouble-float.c
===
--- clang/test/Driver/loongarch-mdouble-float.c
+++ clang/test/Driver/loongarch-mdouble-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -mdouble-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=64'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64d'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64d); using lp64d
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (64); using 64
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "+d"
 // CC1: "-target-abi" "lp64d"
Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
===
--- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -26,16 +26,55 @@
  "Unexpected triple");
   bool IsLA32 = Triple.getArch() == llvm::Triple::loongarch32;
 
+  // Parse -mfpu value for later use.
+  int FPU = -1;

[PATCH] D153707: [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present

2023-06-24 Thread WÁNG Xuěruì via Phabricator via cfe-commits
xen0n created this revision.
xen0n added reviewers: SixWeining, wangleiat, hev, xry111, MaskRay.
Herald added a subscriber: tpr.
Herald added a project: All.
xen0n requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This kind of CLI flags duplication can sometimes be convenient for build
systems that may have to tinker with these.

For example, in the Linux kernel we almost always want to ensure no FP
instruction is emitted, so `-msoft-float` is present by default; but
sometimes we do want to allow FPU usage (e.g. certain parts of amdgpu DC
code), in which case we want the `-msoft-float` stripped and `-mfpu=64`
added. Here we face a dilemma without this change:

- Either `-mabi` is not supplied by `arch/loongarch` Makefile, in which case 
the correct ABI has to be supplied by the driver Makefile, potentially 
duplicating logic;
- Or `-mabi` is still supplied by `arch/loongarch` Makefile, and the build 
immediately errors out because `-Werror,-Wunused-command-line-argument` is 
unconditionally set for Clang builds.

To solve this, simply make sure to check `-mabi` and `-mfpu` (and gain
some useful diagnostics in case of conflicting settings) when
`-m*-float` is successfully parsed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153707

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
  clang/test/Driver/loongarch-mdouble-float.c
  clang/test/Driver/loongarch-msingle-float.c
  clang/test/Driver/loongarch-msoft-float.c

Index: clang/test/Driver/loongarch-msoft-float.c
===
--- clang/test/Driver/loongarch-msoft-float.c
+++ clang/test/Driver/loongarch-msoft-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=64'
-// WARN: warning: argument unused during compilation: '-mabi=lp64d'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=0'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64s'
+// WARN: warning: the -mabi setting 'lp64d' conflicts with that implied by -m*-float (lp64s); using lp64s
+// WARN: warning: the -mfpu setting '64' conflicts with that implied by -m*-float (0); using 0
 
 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64s"
Index: clang/test/Driver/loongarch-msingle-float.c
===
--- clang/test/Driver/loongarch-msingle-float.c
+++ clang/test/Driver/loongarch-msingle-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \
 // RUN:   FileCheck %s --check-prefix=IR
 
-// WARN: warning: argument unused during compilation: '-mfpu=0'
-// WARN: warning: argument unused during compilation: '-mabi=lp64s'
+// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=32'
+// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64f'
+// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64f); using lp64f
+// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (32); using 32
 
 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d"
 // CC1: "-target-abi" "lp64f"
Index: clang/test/Driver/loongarch-mdouble-float.c
===
--- clang/test/Driver/loongarch-mdouble-float.c
+++ clang/test/Driver/loongarch-mdouble-float.c
@@ -1,12 +1,16 @@
 // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefix=CC1
+// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \
+// RUN:   FileCheck %s --check-prefixes=CC1,NOWARN
 // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \
 // RUN:   FileCheck %s --check-prefixes=CC1,WARN
 // RUN: %clang 

[PATCH] D153699: [clang] Fix pretty-printing for variables declared in a for-loop condition

2023-06-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks! `Node->getConditionVariableDeclStmt()` is how 
`StmtPrinter::VisitWhileStmt` prints the declaration in the condition.

https://reviews.llvm.org/D102502 added 
`PCH/for-loop-init-ternary-operator-statement.cpp`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153699

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


[PATCH] D153296: [AST] Stop evaluate constant expression if the condition expression which in switch statement contains errors

2023-06-24 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

In D153296#612 , @erichkeane 
wrote:

> So I think I'm pretty confident that the only time we would call 
> `EvaluateDependentExpr` is when we are in an error condition, so I'm 
> convinced the fix 'as is' is incorrect.  The check for noteSideEffect records 
> that we HAVE a side effect, then returns if we are OK ignoring them right now.
>
> So since we are in a state where ignoring this error-case is acceptable, I 
> think returning early there is incorrect as well, at least from a 'code 
> correctness' (even if there isn't a reproducer that would matter?).  I think 
> we're in a case where we want to continue in order to ensure we go through 
> the entire flow, so I THINK we should treat this as 'we have a value we don't 
> know, so its just not found', and should fall into the check on 5019 (unless 
> of course, there is a 'default' option!).
>
> So I think that we should be checking if `Value` is valid right after the 
> default check, which lets us fall into the 'default' branch and get 
> additional diagnostics/continued evaluation.  WDYT @shafik / @yronglin ?

Erich, do you mean we do a modification like this?If I'm not misunderstand, I 
think this looks good to me, we can get more diagnostics.

  diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
  index f1f89122d4cc..967695c61df5 100644
  --- a/clang/lib/AST/ExprConstant.cpp
  +++ b/clang/lib/AST/ExprConstant.cpp
  @@ -4984,8 +4984,7 @@ static EvalStmtResult EvaluateSwitch(StmtResult 
, EvalInfo ,
 return ESR_Failed;
   if (SS->getCond()->isValueDependent()) {
 // Stop evaluate if condition expression contains errors.
  -  if (SS->getCond()->containsErrors() ||
  -  !EvaluateDependentExpr(SS->getCond(), Info))
  +  if (!EvaluateDependentExpr(SS->getCond(), Info))
   return ESR_Failed;
   } else {
 if (!EvaluateInteger(SS->getCond(), Value, Info))
  @@ -4995,6 +4994,8 @@ static EvalStmtResult EvaluateSwitch(StmtResult 
, EvalInfo ,
 return ESR_Failed;
 }
   
  +  bool CondHasSideEffects = SS->getCond()->HasSideEffects(Info.getCtx());
  +
 // Find the switch case corresponding to the value of the condition.
 // FIXME: Cache this lookup.
 const SwitchCase *Found = nullptr;
  @@ -5009,7 +5010,7 @@ static EvalStmtResult EvaluateSwitch(StmtResult 
, EvalInfo ,
   APSInt LHS = CS->getLHS()->EvaluateKnownConstInt(Info.Ctx);
   APSInt RHS = CS->getRHS() ? CS->getRHS()->EvaluateKnownConstInt(Info.Ctx)
 : LHS;
  -if (LHS <= Value && Value <= RHS) {
  +if (!CondHasSideEffects && LHS <= Value && Value <= RHS) {
 Found = SC;
 break;
   }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153296

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


[PATCH] D153582: [SystemZ][z/OS] Add required options/macro/etc for z/os compilation step

2023-06-24 Thread Sean via Phabricator via cfe-commits
SeanP updated this revision to Diff 534232.
SeanP added a comment.

Removed __ptr32 address space from data layout.


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

https://reviews.llvm.org/D153582

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/ZOS.cpp
  clang/lib/Driver/ToolChains/ZOS.h
  clang/test/Driver/zos-comp-cxx.cpp
  clang/test/Driver/zos-comp.c
  clang/test/Driver/zos-driver-defaults.c
  clang/test/Preprocessor/init-s390x.c

Index: clang/test/Preprocessor/init-s390x.c
===
--- clang/test/Preprocessor/init-s390x.c
+++ clang/test/Preprocessor/init-s390x.c
@@ -183,17 +183,12 @@
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS %s
 // RUN: %clang_cc1 -x c++ -std=gnu++14 -E -dM -ffreestanding -triple=s390x-none-zos -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix S390X-ZOS -check-prefix S390X-ZOS-GNUXX %s
 
-// S390X-ZOS-GNUXX: #define _EXT 1
 // S390X-ZOS:   #define _LONG_LONG 1
-// S390X-ZOS-GNUXX: #define _MI_BUILTIN 1
-// S390X-ZOS:   #define _OPEN_DEFAULT 1
-// S390X-ZOS:   #define _UNIX03_WITHDRAWN 1
-// S390X-ZOS-GNUXX: #define _XOPEN_SOURCE 600
 // S390X-ZOS:   #define __370__ 1
 // S390X-ZOS:   #define __64BIT__ 1
 // S390X-ZOS:   #define __BFP__ 1
 // S390X-ZOS:   #define __BOOL__ 1
-// S390X-ZOS-GNUXX: #define __DLL__ 1
+// S390X-ZOS:   #define __COMPILER_VER__ 0x5000
 // S390X-ZOS:   #define __LONGNAME__ 1
 // S390X-ZOS:   #define __MVS__ 1
 // S390X-ZOS:   #define __THW_370__ 1
Index: clang/test/Driver/zos-driver-defaults.c
===
--- clang/test/Driver/zos-driver-defaults.c
+++ clang/test/Driver/zos-driver-defaults.c
@@ -1,8 +1,21 @@
-// RUN: %clang -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-SHORT-ENUMS %s
+// RUN: %clang -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefixes=CHECK-C-MACRO,CHECK-SHORT-ENUMS %s
+// RUN: %clang -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefix=CHECK-ZOS-INCLUDES %s
 // RUN: %clang -### --target=s390x-none-zos -fno-short-enums -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clangxx -### --target=s390x-none-zos -fsyntax-only %s 2>&1 | FileCheck --check-prefixes=CHECK-C-MACRO,CHECK-CXX-MACRO %s
+// RUN: %clang -### --target=s390x-none-zos -x c++ -fsyntax-only %s 2>&1 | FileCheck --check-prefixes=CHECK-C-MACRO,CHECK-CXX-MACRO %s
+
+//CHECK-C-MACRO: -D_UNIX03_WITHDRAWN
+//CHECK-C-MACRO: -D_OPEN_DEFAULT
+
+//CHECK-CXX-MACRO: -D_XOPEN_SOURCE=600
+//CHECK-USER-CXX-MACRO-NOT: -D_XOPEN_SOURCE=600
+//CHECK-USER-CXX-MACRO: "-D" "_XOPEN_SOURCE=700"
 
 //CHECK-SHORT-ENUMS: -fshort-enums
 //CHECK-SHORT-ENUMS: -fno-signed-char
 
+//CHECK-ZOS-INCLUDES: clang{{.*}} "-cc1" "-triple" "s390x-none-zos"
+//CHECK-ZOS-INCLUDES-SAME: "-internal-isystem" {{".+/lib/clang/.+/include/zos_wrappers"}} "-internal-isystem" {{".+/lib/clang/.+/include"}}
+
 //CHECK-NOT: -fshort-enums
 //CHECK: -fno-signed-char
Index: clang/test/Driver/zos-comp.c
===
--- /dev/null
+++ clang/test/Driver/zos-comp.c
@@ -0,0 +1,76 @@
+// Tests that the z/OS toolchain adds system includes to its search path.
+
+// RUN: %clang -c -### %s 2>&1 \
+// RUN:		--target=s390x-ibm-zos \
+// RUN:   | FileCheck %s
+
+// CHECK: "-D_UNIX03_WITHDRAWN"
+// CHECK: "-D_OPEN_DEFAULT"
+// CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include{{(/|)}}zos_wrappers"
+// CHECK: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK: "-internal-isystem" "/usr/include"
+// CHECK: "-fshort-enums" 
+// CHECK: "-fno-signed-char" 
+// CHECK: "-fno-signed-wchar" 
+
+// RUN: %clang -c -### -mzos-sys-include=/ABC/DEF %s 2>&1 \
+// RUN:		--target=s390x-ibm-zos \
+// RUN:   | FileCheck --check-prefixes=CHECK2 %s
+
+// CHECK2: "-D_UNIX03_WITHDRAWN"
+// CHECK2: "-D_OPEN_DEFAULT"
+// CHECK2: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK2: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include{{(/|)}}zos_wrappers"
+// CHECK2: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK2: "-internal-isystem" "/ABC/DEF"
+// CHECK2-NOT: "-internal-isystem" "/usr/include"
+// CHECK2: "-fshort-enums" 
+// CHECK2: "-fno-signed-char" 
+// CHECK2: "-fno-signed-wchar" 
+
+// RUN: %clang -c -### -mzos-sys-include=/ABC/DEF:/ghi/jkl %s 2>&1 \
+// RUN:		--target=s390x-ibm-zos \
+// RUN:   | FileCheck --check-prefixes=CHECK3 %s
+
+// CHECK3: "-D_UNIX03_WITHDRAWN"
+// CHECK3: "-D_OPEN_DEFAULT"
+// CHECK3: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]"
+// CHECK3: 

[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-24 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL accepted this revision.
PiotrZSL added inline comments.



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:37
+
+  if (PrintfLikeFunctions.empty() && FprintfLikeFunctions.empty()) {
+PrintfLikeFunctions.push_back("::printf");

those 2 looks in-depended. Cannot they be put as default value into Option 
config ?



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:70
+void UseStdPrintCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(

call this function only if PrintfLikeFunctions is not empty.



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:78
+
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(

call this function only if FprintfLikeFunctions is not empty



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:79
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(
+  matchers::matchesAnyListedName(FprintfLikeFunctions))

this could match also methods, maybe something `unless(cxxMethodDecl())` ?



Comment at: clang-tools-extra/clang-tidy/modernize/UseStdPrintCheck.cpp:82
+  .bind("func_decl")),
+   hasArgument(1, stringLiteral()))
+  .bind("fprintf"),

consider moving this stringLiteral to be first, consider adding something like 
`unless(argumentCountIs(0)), unless(argumentCountIs(1))`` at begining or create 
matcher that verify first that argument count is >= 2, so we could exlude most 
of callExpr at begining, even before we match functions



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:58
+- ``printf``, ``fprintf``, ``absl::PrintF``, ``absl::FPrintF`` and any
+  functions specified by the ``PrintfLikeFunctions`` option or
+  ``FprintfLikeFunctions`` are replaced with the function specified by the





Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:59
+  functions specified by the ``PrintfLikeFunctions`` option or
+  ``FprintfLikeFunctions`` are replaced with the function specified by the
+  ``ReplacementPrintlnFunction`` option if the format string ends with





Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:60
+  ``FprintfLikeFunctions`` are replaced with the function specified by the
+  ``ReplacementPrintlnFunction`` option if the format string ends with
+  ``\n`` or ``ReplacementPrintFunction`` otherwise.





Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:61
+  ``ReplacementPrintlnFunction`` option if the format string ends with
+  ``\n`` or ``ReplacementPrintFunction`` otherwise.
+- the format string is rewritten to use the ``std::formatter`` language and




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In D149280#4446591 , @mikecrowe wrote:

> @Eugene.Zelenko,
> I will make the documentation changes you've suggested, but I can't say I 
> really understand which document elements require single backticks and which 
> require dual backticks. https://llvm.org/docs/SphinxQuickstartTemplate.html 
> seems to imply that single backticks are only used for links and double 
> backticks are used for monospace, but it's not completely clear. Most of the 
> existing documentation seems to be consistent with what you've suggested 
> though.

In short: double back-ticks are for language constructs. Single - for 
command-line options, options and their values.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-24 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe added a comment.

@Eugene.Zelenko,
I will make the documentation changes you've suggested, but I can't say I 
really understand which document elements require single backticks and which 
require dual backticks. https://llvm.org/docs/SphinxQuickstartTemplate.html 
seems to imply that single backticks are only used for links and double 
backticks are used for monospace, but it's not completely clear. Most of the 
existing documentation seems to be consistent with what you've suggested though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:29
+- It assumes that the format string is correct for the arguments. If you
+  get any warnings when compiling with ``-Wformat`` then misbehaviour is
+  possible.

Please use single back-ticks for `-Wformat` (command-line option).



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:81
+
+   When true, the check will add casts when converting from variadic
+   functions like ``printf`` and printing signed or unsigned integer types

Please highlight `true` with back-ticks.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:87
+   converting from non-variadic functions such as ``absl::PrintF`` and
+   ``fmt::printf``. For example, with ``StrictMode`` enabled:
+

Please use single back-ticks for `StrictMode` (option).



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:103
+  of -42 and the signed representation of 0x (often 4294967254
+  and -1 respectively.) When false (which is the default), these casts
+  will not be added which may cause a change in the output.

Please highlight `false` and numbers with back-ticks.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:112
+   immediately afterwards. If neither this option nor
+   ``FprintfLikeFunctions`` are set then the default value for this option
+   is ``printf; absl::PrintF``, otherwise it is empty.

Please use single back-ticks for `FprintfLikeFunctions` (option). Same for 
`printf; absl::PrintF` below.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:122
+   arguments to be formatted follow immediately afterwards. If neither this
+   option nor ``PrintfLikeFunctions`` are set then the default value for
+   this option is ``fprintf; absl::FPrintF``, otherwise it is empty.

Ditto.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:144
+   The header that must be included for the declaration of
+   ``ReplacementPrintFunction`` so that a ``#include`` directive can be
+   added if required. If ``ReplacementPrintFunction`` is ``std::print``

Please use single back-ticks for `ReplacementPrintFunction` (option).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D153699: [clang] Fix pretty-printing for variables declared in a for-loop condition

2023-06-24 Thread Vaibhav Thakkar via Phabricator via cfe-commits
vaithak updated this revision to Diff 534223.
vaithak added a comment.

rebased on the latest changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153699

Files:
  clang/lib/AST/StmtPrinter.cpp
  clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
  clang/test/SemaCXX/ast-print.cpp


Index: clang/test/SemaCXX/ast-print.cpp
===
--- clang/test/SemaCXX/ast-print.cpp
+++ clang/test/SemaCXX/ast-print.cpp
@@ -21,12 +21,14 @@
 // CHECK: if (int a = 1)
 // CHECK:  while (int a = 1)
 // CHECK:  switch (int a = 1)
+// CHECK:  for (; int a = 1;)
 
 void test2()
 {
 if (int a = 1) { }
 while (int a = 1) { }
 switch (int a = 1) { }
+for(; int a = 1; ) { }
 }
 
 // CHECK: new (1) int;
Index: clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
===
--- clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
+++ clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s
 
 int f() {
-  // CHECK: for (int i = 0; x; i++) {
+  // CHECK: for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
   for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
 return x;
   }
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -400,7 +400,9 @@
 PrintInitStmt(Node->getInit(), 5);
   else
 OS << (Node->getCond() ? "; " : ";");
-  if (Node->getCond())
+  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
+PrintRawDeclStmt(DS);
+  else if (Node->getCond())
 PrintExpr(Node->getCond());
   OS << ";";
   if (Node->getInc()) {


Index: clang/test/SemaCXX/ast-print.cpp
===
--- clang/test/SemaCXX/ast-print.cpp
+++ clang/test/SemaCXX/ast-print.cpp
@@ -21,12 +21,14 @@
 // CHECK: if (int a = 1)
 // CHECK:  while (int a = 1)
 // CHECK:  switch (int a = 1)
+// CHECK:  for (; int a = 1;)
 
 void test2()
 {
 if (int a = 1) { }
 while (int a = 1) { }
 switch (int a = 1) { }
+for(; int a = 1; ) { }
 }
 
 // CHECK: new (1) int;
Index: clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
===
--- clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
+++ clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s
 
 int f() {
-  // CHECK: for (int i = 0; x; i++) {
+  // CHECK: for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
   for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
 return x;
   }
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -400,7 +400,9 @@
 PrintInitStmt(Node->getInit(), 5);
   else
 OS << (Node->getCond() ? "; " : ";");
-  if (Node->getCond())
+  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
+PrintRawDeclStmt(DS);
+  else if (Node->getCond())
 PrintExpr(Node->getCond());
   OS << ";";
   if (Node->getInc()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153228: [clang-format] Fixed bad performance with enabled qualifier fixer.

2023-06-24 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

For us to land this for you we'll need your name and email


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153228

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


[PATCH] D153641: [clang-format] Preserve AmpAmpTokenType in nested parentheses

2023-06-24 Thread Emilia Kond via Phabricator via cfe-commits
rymiel updated this revision to Diff 534220.
rymiel added a comment.

Add annotator test cases involving a lambda


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153641

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -906,6 +906,26 @@
   annotate("auto bar() -> Template requires(is_integral_v) {}");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("void foo() requires((A) && C) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void foo() requires(((A) && C)) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void foo() requires([](T&&){}(t)) {}");
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("void foo() requires([](T&& u){}(t)) {}");
+  ASSERT_EQ(Tokens.size(), 22u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2431,14 +2431,14 @@
 
 /// \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 only counts for the current parens scope.
+/// double ampersands. This applies for all nested scopes as well.
 void UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
   assert(FormatTok->is(tok::l_paren) && "'(' expected.");
   nextToken();
   do {
 switch (FormatTok->Tok.getKind()) {
 case tok::l_paren:
-  parseParens();
+  parseParens(AmpAmpTokenType);
   if (Style.Language == FormatStyle::LK_Java && 
FormatTok->is(tok::l_brace))
 parseChildBlock();
   break;


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -906,6 +906,26 @@
   annotate("auto bar() -> Template requires(is_integral_v) {}");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("void foo() requires((A) && C) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[12], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void foo() requires(((A) && C)) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void foo() requires([](T&&){}(t)) {}");
+  ASSERT_EQ(Tokens.size(), 21u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference);
+
+  Tokens = annotate("void foo() requires([](T&& u){}(t)) {}");
+  ASSERT_EQ(Tokens.size(), 22u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::kw_requires, TT_RequiresClause);
+  EXPECT_TOKEN(Tokens[10], tok::ampamp, TT_PointerOrReference);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2431,14 +2431,14 @@
 
 /// \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 only counts for the current parens scope.
+/// double ampersands. This applies for all nested scopes as well.
 void UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
   assert(FormatTok->is(tok::l_paren) && "'(' expected.");
   nextToken();
   do {
 switch (FormatTok->Tok.getKind()) {
 case tok::l_paren:
-  parseParens();
+  parseParens(AmpAmpTokenType);
   if (Style.Language == FormatStyle::LK_Java && 

[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-24 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked 4 inline comments as done.
mikecrowe added inline comments.



Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:384-397
+const auto StringDecl = type(hasUnqualifiedDesugaredType(recordType(
+hasDeclaration(cxxRecordDecl(hasName("::std::basic_string"));
+const auto StringExpr = expr(anyOf(
+hasType(StringDecl), hasType(qualType(pointsTo(StringDecl);
+
+const auto StringCStrCallExpr =
+cxxMemberCallExpr(on(StringExpr.bind("arg")),

PiotrZSL wrote:
> mikecrowe wrote:
> > PiotrZSL wrote:
> > > constant construction of those marchers may be costly.. can be cache them 
> > > somehow in this object ?
> > Good idea. Do you have any pointers to code that does this? I couldn't find 
> > any.
> > 
> > The types involved all seem to be in the `internal::` namespace and 
> > presumably subject to change. Ideally, I'd put:
> > ```
> > std::optional StringCStrCallExprMatcher;
> > ```
> > in the class and then populate it here the first time lazily. Unfortunately 
> > I have no idea what type to use for `SomeSortOfMatcherType`.
> `clang::ast_matchers::StatementMatcher`, this is defined 
> as `using clang::ast_matchers::StatementMatcher = typedef 
> internal::Matcher`.
> I would create it in class constructor as private member.
Thanks for the pointer. It turns out that I need just 
`clang::ast_matchers::StatementMatcher`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D153694: [clang][CodeGen] Remove no-op EmitCastToVoidPtr (NFC)

2023-06-24 Thread Youngsuk Kim via Phabricator via cfe-commits
JOE1994 added inline comments.



Comment at: clang/lib/CodeGen/CGAtomic.cpp:90
+StoragePtr = CGF.Builder.CreateAddrSpaceCast(
+StoragePtr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
 "atomic_bitfield_base");

barannikov88 wrote:
> I suppose address space shouldn't be dropped here, but this is what the 
> original code does.
> 
I agree. I think this can be addressed in a separate revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153694

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


[PATCH] D153702: [Clang] Implement P2738R1 - constexpr cast from void*

2023-06-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153702

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/CXX/expr/expr.const/p5-26.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -125,7 +125,7 @@
  
   constexpr cast from void*
   https://wg21.link/P2738R1;>P2738R1
-  No
+  Clang 17
  
  
   On the ignorability of standard attributes
Index: clang/test/CXX/expr/expr.const/p5-26.cpp
===
--- /dev/null
+++ clang/test/CXX/expr/expr.const/p5-26.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++2c -verify %s
+
+struct S {};
+struct T : S {} t;
+
+consteval void test() {
+void* a = 
+const void* b = 
+volatile void* c = 
+(void)static_cast(a);
+(void)static_cast(a);
+(void)static_cast(a);
+
+(void)(T*)(a);
+(void)(const T*)(a);
+(void)(volatile T*)(a);
+
+(void)static_cast(b); // expected-error {{static_cast from 'const void *' to 'T *' casts away qualifiers}}
+(void)static_cast(b); // expected-error {{static_cast from 'const void *' to 'volatile T *' casts away qualifiers}}
+(void)static_cast(b);
+(void)static_cast(b);
+
+(void)static_cast(c); // expected-error{{static_cast from 'volatile void *' to 'T *' casts away qualifiers}}
+(void)static_cast(c);
+(void)static_cast(b);
+(void)static_cast(b);
+}
+
+void err() {
+constexpr void* a = 
+constexpr auto err1 = static_cast(a); // expected-error{{constexpr variable 'err1' must be initialized by a constant expression}} \
+// expected-note {{cast from 'void *' is not allowed in a constant expression because the pointed object type 'T' is not similar to the target type 'int'}}
+constexpr auto err2 = static_cast(a);   // expected-error{{constexpr variable 'err2' must be initialized by a constant expression}} \
+// expected-note {{cast from 'void *' is not allowed in a constant expression because the pointed object type 'T' is not similar to the target type 'S'}}
+}
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -611,7 +611,8 @@
 Builder.defineMacro("__cpp_unicode_literals", "200710L");
 Builder.defineMacro("__cpp_user_defined_literals", "200809L");
 Builder.defineMacro("__cpp_lambdas", "200907L");
-Builder.defineMacro("__cpp_constexpr", LangOpts.CPlusPlus23   ? "202211L"
+Builder.defineMacro("__cpp_constexpr", LangOpts.CPlusPlus26   ? "202306L"
+   : LangOpts.CPlusPlus23 ? "202211L"
: LangOpts.CPlusPlus20 ? "201907L"
: LangOpts.CPlusPlus17 ? "201603L"
: LangOpts.CPlusPlus14 ? "201304L"
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -8896,9 +8896,10 @@
 if (!E->getType()->isVoidPointerType()) {
   // In some circumstances, we permit casting from void* to cv1 T*, when the
   // actual pointee object is actually a cv2 T.
+  bool HasValidResult = !Result.InvalidBase && !Result.Designator.Invalid &&
+!Result.IsNullPtr;
   bool VoidPtrCastMaybeOK =
-  !Result.InvalidBase && !Result.Designator.Invalid &&
-  !Result.IsNullPtr &&
+  HasValidResult &&
   Info.Ctx.hasSameUnqualifiedType(Result.Designator.getType(Info.Ctx),
   E->getType()->getPointeeType());
   // 1. We'll allow it in std::allocator::allocate, and anything which that
@@ -8910,16 +8911,23 @@
   //that back to `const __impl*` in its body.
   if (VoidPtrCastMaybeOK &&
   (Info.getStdAllocatorCaller("allocate") ||
-   IsDeclSourceLocationCurrent(Info.CurrentCall->Callee))) {
+   IsDeclSourceLocationCurrent(Info.CurrentCall->Callee) ||
+   Info.getLangOpts().CPlusPlus26)) {
 // Permitted.
   } else {
-Result.Designator.setInvalid();
-if (SubExpr->getType()->isVoidPointerType())
-  CCEDiag(E, diag::note_constexpr_invalid_cast)
-  << 3 << SubExpr->getType();
-else
+if (SubExpr->getType()->isVoidPointerType()) {

[PATCH] D153701: [clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-06-24 Thread Yurong via Phabricator via cfe-commits
yronglin updated this revision to Diff 534212.
yronglin added a comment.

Update c++ status


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153701

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CodeGenCXX/for-range-temporaries.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -413,7 +413,7 @@
 
   Lifetime extension in range-based for loops
   https://wg21.link/P2718R0;>P2718R0
-  No
+  Clang 17
 
 
 
Index: clang/test/CodeGenCXX/for-range-temporaries.cpp
===
--- clang/test/CodeGenCXX/for-range-temporaries.cpp
+++ clang/test/CodeGenCXX/for-range-temporaries.cpp
@@ -1,9 +1,10 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE -DDEPENDENT %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE -DDEPENDENT %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE -DDEPENDENT %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE -DDEPENDENT %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++20 -emit-llvm -o - -UDESUGAR %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-EXT-LIFETIME
 
 struct A {
   A();
@@ -103,8 +104,8 @@
 // CHECK: call void @_ZN1BC1Ev(
 // CHECK: call void @_ZN1CC1ERK1B(
 // CHECK: call void @_ZN1DC1ERK1C(
-// CHECK: call void @_ZN1CD1Ev(
-// CHECK: call void @_ZN1BD1Ev(
+// CHECK-NO-EXT-LIFETIME: call void @_ZN1CD1Ev(
+// CHECK-NO-EXT-LIFETIME: call void @_ZN1BD1Ev(
 // CHECK: call void @_ZN1DC1ERKS_(
 // CHECK: call void @_Z5begin1D(
 // CHECK: call void @_ZN1DD1Ev(
@@ -122,6 +123,8 @@
 // CHECK: [[CLEANUP]]:
 // CHECK: call void @_ZN1ED1Ev(
 // CHECK: call void @_ZN1ED1Ev(
+// CHECK-EXT-LIFETIME: call void @_ZN1CD1Ev(
+// CHECK-EXT-LIFETIME: call void @_ZN1BD1Ev(
 // In for-range:
 // call void @_ZN1DD1Ev(
 // CHECK: br label %[[END:.*]]
@@ -142,5 +145,6 @@
 // CHECK: [[END]]:
 // In desugared version:
 // call void @_ZN1DD1Ev(
+// CHECK-EXT-LIFETIME: call void @_ZN1DD1Ev(
 // CHECK: call void @_ZN1AD1Ev(
 // CHECK: ret void
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -2528,6 +2528,7 @@
   VarDecl *RangeVar = BuildForRangeVarDecl(*this, RangeLoc,
Context.getAutoRRefDeductType(),
std::string("__range") + DepthStr);
+  RangeVar->setCXXForRangeInitializer(true);
   if (FinishForRangeVarDecl(*this, RangeVar, Range, RangeLoc,
 diag::err_for_range_deduction_failure)) {
 ActOnInitializerError(LoopVar);
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -8806,7 +8806,7 @@
 
 ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
  bool DiscardedValue, bool IsConstexpr,
- bool IsTemplateArgument) {
+ bool IsTemplateArgument, bool IsForRangeInit) {
   ExprResult 

[PATCH] D130665: [clang-tidy] Fix false negative in readability-convert-member-functions-to-static

2023-06-24 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG67e05d380c22: [clang-tidy] Fix false negative in 
readability-convert-member-functions-to… (authored by njames93, committed by 
PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D130665?vs=448166=534211#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130665

Files:
  clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
@@ -45,6 +45,24 @@
 static_field = 1;
   }
 
+  void static_nested() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'static_nested' can be 
made static
+// CHECK-FIXES: {{^}}  static void static_nested() {
+struct Nested {
+  int Foo;
+  int getFoo() { return Foo; }
+};
+  }
+
+  void write_nested() {
+struct Nested {
+  int Foo;
+  int getFoo() { return Foo; }
+};
+// Ensure we still detect usages of `this` once we leave the nested class 
definition.
+field = 1;
+  }
+
   static int already_static() { return static_field; }
 
   int already_const() const { return field; }
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -412,6 +412,10 @@
   ``std::array`` objects to default constructed ones. The behavior for this and
   other relevant classes can now be configured with a new option.
 
+- Fixed a false negative in 
:doc:`readability-convert-member-functions-to-static
+  ` when a
+  nested class in a member function uses a ``this`` pointer.
+
 - Fixed reading `HungarianNotation.CString.*` options in
   :doc:`readability-identifier-naming
   ` check.
Index: 
clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
===
--- clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
@@ -61,6 +61,11 @@
   Used = true;
   return false; // Stop traversal.
 }
+
+// If we enter a class declaration, don't traverse into it as any usages of
+// `this` will correspond to the nested class.
+bool TraverseCXXRecordDecl(CXXRecordDecl *RD) { return true; }
+
   } UsageOfThis;
 
   // TraverseStmt does not modify its argument.


Index: clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
@@ -45,6 +45,24 @@
 static_field = 1;
   }
 
+  void static_nested() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'static_nested' can be made static
+// CHECK-FIXES: {{^}}  static void static_nested() {
+struct Nested {
+  int Foo;
+  int getFoo() { return Foo; }
+};
+  }
+
+  void write_nested() {
+struct Nested {
+  int Foo;
+  int getFoo() { return Foo; }
+};
+// Ensure we still detect usages of `this` once we leave the nested class definition.
+field = 1;
+  }
+
   static int already_static() { return static_field; }
 
   int already_const() const { return field; }
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -412,6 +412,10 @@
   ``std::array`` objects to default constructed ones. The behavior for this and
   other relevant classes can now be configured with a new option.
 
+- Fixed a false negative in :doc:`readability-convert-member-functions-to-static
+  ` when a
+  nested class in a member function uses a ``this`` pointer.
+
 - Fixed reading `HungarianNotation.CString.*` options in
   :doc:`readability-identifier-naming
   ` check.
Index: clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
===
--- clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
@@ -61,6 +61,11 @@
   Used = true;
  

[clang-tools-extra] 67e05d3 - [clang-tidy] Fix false negative in readability-convert-member-functions-to-static

2023-06-24 Thread Piotr Zegar via cfe-commits

Author: Nathan James
Date: 2023-06-24T14:35:11Z
New Revision: 67e05d380c2253319c22451d340e2e3c2043b6d8

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

LOG: [clang-tidy] Fix false negative in 
readability-convert-member-functions-to-static

A nested class in a member function can erroneously confuse the check into
thinking that any CXXThisExpr found relate to the outer class, preventing any 
warnings.
Fix this by not traversing any nested classes.

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

Reviewed By: PiotrZSL

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp 
b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
index 0ef7d2955ff76..1284df6bd99cf 100644
--- 
a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ 
b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
@@ -61,6 +61,11 @@ AST_MATCHER(CXXMethodDecl, usesThis) {
   Used = true;
   return false; // Stop traversal.
 }
+
+// If we enter a class declaration, don't traverse into it as any usages of
+// `this` will correspond to the nested class.
+bool TraverseCXXRecordDecl(CXXRecordDecl *RD) { return true; }
+
   } UsageOfThis;
 
   // TraverseStmt does not modify its argument.

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index e049ff87939a6..03426772f6037 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -412,6 +412,10 @@ Changes in existing checks
   ``std::array`` objects to default constructed ones. The behavior for this and
   other relevant classes can now be configured with a new option.
 
+- Fixed a false negative in 
:doc:`readability-convert-member-functions-to-static
+  ` when a
+  nested class in a member function uses a ``this`` pointer.
+
 - Fixed reading `HungarianNotation.CString.*` options in
   :doc:`readability-identifier-naming
   ` check.

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
index 9612fa9de8c20..5ec1f221b2207 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/convert-member-functions-to-static.cpp
@@ -45,6 +45,24 @@ class A {
 static_field = 1;
   }
 
+  void static_nested() {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: method 'static_nested' can be 
made static
+// CHECK-FIXES: {{^}}  static void static_nested() {
+struct Nested {
+  int Foo;
+  int getFoo() { return Foo; }
+};
+  }
+
+  void write_nested() {
+struct Nested {
+  int Foo;
+  int getFoo() { return Foo; }
+};
+// Ensure we still detect usages of `this` once we leave the nested class 
definition.
+field = 1;
+  }
+
   static int already_static() { return static_field; }
 
   int already_const() const { return field; }



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


[PATCH] D153701: [clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-06-24 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: yronglin 


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153701

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CodeGenCXX/for-range-temporaries.cpp

Index: clang/test/CodeGenCXX/for-range-temporaries.cpp
===
--- clang/test/CodeGenCXX/for-range-temporaries.cpp
+++ clang/test/CodeGenCXX/for-range-temporaries.cpp
@@ -1,9 +1,10 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE -DDEPENDENT %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE -DDEPENDENT %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -UDESUGAR -DTEMPLATE -DDEPENDENT %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++11 -emit-llvm -o - -DDESUGAR -DTEMPLATE -DDEPENDENT %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NO-EXT-LIFETIME
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -std=c++23 -emit-llvm -o - -UDESUGAR %s | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-EXT-LIFETIME
 
 struct A {
   A();
@@ -103,8 +104,8 @@
 // CHECK: call void @_ZN1BC1Ev(
 // CHECK: call void @_ZN1CC1ERK1B(
 // CHECK: call void @_ZN1DC1ERK1C(
-// CHECK: call void @_ZN1CD1Ev(
-// CHECK: call void @_ZN1BD1Ev(
+// CHECK-NO-EXT-LIFETIME: call void @_ZN1CD1Ev(
+// CHECK-NO-EXT-LIFETIME: call void @_ZN1BD1Ev(
 // CHECK: call void @_ZN1DC1ERKS_(
 // CHECK: call void @_Z5begin1D(
 // CHECK: call void @_ZN1DD1Ev(
@@ -122,6 +123,8 @@
 // CHECK: [[CLEANUP]]:
 // CHECK: call void @_ZN1ED1Ev(
 // CHECK: call void @_ZN1ED1Ev(
+// CHECK-EXT-LIFETIME: call void @_ZN1CD1Ev(
+// CHECK-EXT-LIFETIME: call void @_ZN1BD1Ev(
 // In for-range:
 // call void @_ZN1DD1Ev(
 // CHECK: br label %[[END:.*]]
@@ -142,5 +145,6 @@
 // CHECK: [[END]]:
 // In desugared version:
 // call void @_ZN1DD1Ev(
+// CHECK-EXT-LIFETIME: call void @_ZN1DD1Ev(
 // CHECK: call void @_ZN1AD1Ev(
 // CHECK: ret void
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -2528,6 +2528,7 @@
   VarDecl *RangeVar = BuildForRangeVarDecl(*this, RangeLoc,
Context.getAutoRRefDeductType(),
std::string("__range") + DepthStr);
+  RangeVar->setCXXForRangeInitializer(true);
   if (FinishForRangeVarDecl(*this, RangeVar, Range, RangeLoc,
 diag::err_for_range_deduction_failure)) {
 ActOnInitializerError(LoopVar);
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -8806,7 +8806,7 @@
 
 ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC,
  bool DiscardedValue, bool IsConstexpr,
- bool IsTemplateArgument) {
+ bool IsTemplateArgument, bool IsForRangeInit) {
   ExprResult FullExpr = FE;
 
   if (!FullExpr.get())
@@ -8889,13 +8889,28 @@
   //  - Teach the handful of places that iterate over FunctionScopes to
   //stop at the outermost enclosing lexical scope."
   DeclContext *DC = CurContext;
-  while (DC && isa(DC))
+  while (isa_and_nonnull(DC))
 DC = 

[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-24 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:117
+
+.. option:: PrintFunction
+

mikecrowe wrote:
> PiotrZSL wrote:
> > mikecrowe wrote:
> > > Is `PrintFunction` (and the soon-to-arrive `PrintlnFunction`) distinct 
> > > enough from `PrintfLikeFunctions` and `FprintfLikeFunctions`? Should I 
> > > use `ReplacementPrintFunction` instead?
> > Use `Replacement`. It will be way better.
> I assume that you mean `ReplacementPrintFunction`. (I see `ReplacementString` 
> used in other checks, so I think that just `Replacement` might be a bit 
> vague.)
Yes, ... `ReplacementPrintFunction`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D153694: [clang][CodeGen] Remove no-op EmitCastToVoidPtr (NFC)

2023-06-24 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 updated this revision to Diff 534205.
barannikov88 added a comment.

- Remove unused argument of EmitDynamicCastToVoid
- While here, adjust the name to start with lowercase letter


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153694

Files:
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp

Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -152,14 +152,13 @@
   bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
   QualType SrcRecordTy) override;
 
-  llvm::Value *EmitDynamicCastCall(CodeGenFunction , Address Value,
+  llvm::Value *emitDynamicCastCall(CodeGenFunction , Address Value,
QualType SrcRecordTy, QualType DestTy,
QualType DestRecordTy,
llvm::BasicBlock *CastEnd) override;
 
-  llvm::Value *EmitDynamicCastToVoid(CodeGenFunction , Address Value,
- QualType SrcRecordTy,
- QualType DestTy) override;
+  llvm::Value *emitDynamicCastToVoid(CodeGenFunction , Address Value,
+ QualType SrcRecordTy) override;
 
   bool EmitBadCastCall(CodeGenFunction ) override;
   bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const override {
@@ -1010,11 +1009,9 @@
  !getContext().getASTRecordLayout(SrcDecl).hasExtendableVFPtr();
 }
 
-llvm::Value *MicrosoftCXXABI::EmitDynamicCastCall(
-CodeGenFunction , Address This, QualType SrcRecordTy,
-QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd) {
-  llvm::Type *DestLTy = CGF.ConvertType(DestTy);
-
+llvm::Value *MicrosoftCXXABI::emitDynamicCastCall(
+CodeGenFunction , Address This, QualType SrcRecordTy, QualType DestTy,
+QualType DestRecordTy, llvm::BasicBlock *CastEnd) {
   llvm::Value *SrcRTTI =
   CGF.CGM.GetAddrOfRTTIDescriptor(SrcRecordTy.getUnqualifiedType());
   llvm::Value *DestRTTI =
@@ -1040,14 +1037,12 @@
   llvm::Value *Args[] = {
   ThisPtr, Offset, SrcRTTI, DestRTTI,
   llvm::ConstantInt::get(CGF.Int32Ty, DestTy->isReferenceType())};
-  ThisPtr = CGF.EmitRuntimeCallOrInvoke(Function, Args);
-  return CGF.Builder.CreateBitCast(ThisPtr, DestLTy);
+  return CGF.EmitRuntimeCallOrInvoke(Function, Args);
 }
 
-llvm::Value *
-MicrosoftCXXABI::EmitDynamicCastToVoid(CodeGenFunction , Address Value,
-   QualType SrcRecordTy,
-   QualType DestTy) {
+llvm::Value *MicrosoftCXXABI::emitDynamicCastToVoid(CodeGenFunction ,
+Address Value,
+QualType SrcRecordTy) {
   std::tie(Value, std::ignore, std::ignore) =
   performBaseAdjustment(CGF, Value, SrcRecordTy);
 
@@ -1568,11 +1563,8 @@
   // 1) getThisValue is currently protected
   // 2) in theory, an ABI could implement 'this' returns some other way;
   //HasThisReturn only specifies a contract, not the implementation
-  if (HasThisReturn(CGF.CurGD))
+  if (HasThisReturn(CGF.CurGD) || hasMostDerivedReturn(CGF.CurGD))
 CGF.Builder.CreateStore(getThisValue(CGF), CGF.ReturnValue);
-  else if (hasMostDerivedReturn(CGF.CurGD))
-CGF.Builder.CreateStore(CGF.EmitCastToVoidPtr(getThisValue(CGF)),
-CGF.ReturnValue);
 
   if (isa(MD) && MD->getParent()->getNumVBases()) {
 assert(getStructorImplicitParamDecl(CGF) &&
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -185,14 +185,13 @@
   bool shouldDynamicCastCallBeNullChecked(bool SrcIsPtr,
   QualType SrcRecordTy) override;
 
-  llvm::Value *EmitDynamicCastCall(CodeGenFunction , Address Value,
+  llvm::Value *emitDynamicCastCall(CodeGenFunction , Address Value,
QualType SrcRecordTy, QualType DestTy,
QualType DestRecordTy,
llvm::BasicBlock *CastEnd) override;
 
-  llvm::Value *EmitDynamicCastToVoid(CodeGenFunction , Address Value,
- QualType SrcRecordTy,
- QualType DestTy) override;
+  llvm::Value 

[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-06-24 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked 7 inline comments as done.
mikecrowe added a comment.

I'm still working on the remaining items.




Comment at: clang-tools-extra/clang-tidy/utils/FormatStringConverter.cpp:230
+return conversionNotPossible("'%m' is not supported in format string");
+  } else {
+StandardFormatString.push_back('{');

mikecrowe wrote:
> PiotrZSL wrote:
> > general: no need for else after return
> In general, you're correct that I've used else after return in other places 
> and I will fix them. However, in this case the else is required since the 
> very first `if` block above doesn't have a return. (Hopefully this complexity 
> will go away if I succeed in splitting this function up.)
I've now reworked this function extensively, so there's no longer an else here.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-print.rst:117
+
+.. option:: PrintFunction
+

PiotrZSL wrote:
> mikecrowe wrote:
> > Is `PrintFunction` (and the soon-to-arrive `PrintlnFunction`) distinct 
> > enough from `PrintfLikeFunctions` and `FprintfLikeFunctions`? Should I use 
> > `ReplacementPrintFunction` instead?
> Use `Replacement`. It will be way better.
I assume that you mean `ReplacementPrintFunction`. (I see `ReplacementString` 
used in other checks, so I think that just `Replacement` might be a bit vague.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D153694: [clang][CodeGen] Remove no-op EmitCastToVoidPtr (NFC)

2023-06-24 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:1473
   QualType SrcRecordTy,
   QualType DestTy) {
   auto *ClassDecl =

barannikov88 wrote:
> `DestTy` has become unused in both implementations. I'm not sure if I should 
> remove it. It is always a [cv-qualified] `void *`.
> 
Removing it sounds reasonable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153694

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


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

2023-06-24 Thread Patryk Wychowaniec via Phabricator via cfe-commits
Patryk27 added a comment.

Now that I think about it, there //might// be a simpler way!

So, the underlying issue is that sometimes LLVM spawns new shifts during the 
instruction selection pass - for instance given this IR¹:

  define i64 @test(i64 %x, i32 %y) {
  start:
%0 = or i32 %y, 38
%1 = zext i32 %0 to i64
%2 = lshr i64 %x, %1
ret i64 %2
  }

... this 64-bit shift will not get considered by our shift-expansion pass due 
to a condition here:

https://github.com/llvm/llvm-project/blob/eaaacc3c651e5b2c23bfa9648b6b0d69aab64d00/llvm/lib/Target/AVR/AVRShiftExpand.cpp#L54

... but later, during isel, LLVM **will** reduce this 64-bit shift into a 
32-bit shift² and then ask us to expand this brand new 32-bit shift - that 
causes a panic since we expect those to have been already expanded.

In order to solve this issue, I think we could simply expand //all// 
variable-shifts greater than i8 (instead of expanding only 32-bit shifts):

  diff --git a/llvm/lib/Target/AVR/AVRShiftExpand.cpp 
b/llvm/lib/Target/AVR/AVRShiftExpand.cpp
  index b7dcd860467d..4ea6d9fdb57c 100644
  --- a/llvm/lib/Target/AVR/AVRShiftExpand.cpp
  +++ b/llvm/lib/Target/AVR/AVRShiftExpand.cpp
  @@ -51,8 +51,7 @@ bool AVRShiftExpand::runOnFunction(Function ) {
   if (!I.isShift())
 // Only expand shift instructions (shl, lshr, ashr).
 continue;
  -if (I.getType() != Type::getInt32Ty(Ctx))
  -  // Only expand plain i32 types.
  +if (I.getType() == Type::getInt8Ty(Ctx))
 continue;
   if (isa(I.getOperand(1)))
 // Only expand when the shift amount is not known.
  @@ -75,7 +74,7 @@ bool AVRShiftExpand::runOnFunction(Function ) {
   void AVRShiftExpand::expand(BinaryOperator *BI) {
 auto  = BI->getContext();
 IRBuilder<> Builder(BI);
  -  Type *Int32Ty = Type::getInt32Ty(Ctx);
  +  Type *InputTy = cast(BI)->getType();
 Type *Int8Ty = Type::getInt8Ty(Ctx);
 Value *Int8Zero = ConstantInt::get(Int8Ty, 0);
   
  @@ -101,7 +100,7 @@ void AVRShiftExpand::expand(BinaryOperator *BI) {
 Builder.SetInsertPoint(LoopBB);
 PHINode *ShiftAmountPHI = Builder.CreatePHI(Int8Ty, 2);
 ShiftAmountPHI->addIncoming(ShiftAmount, BB);
  -  PHINode *ValuePHI = Builder.CreatePHI(Int32Ty, 2);
  +  PHINode *ValuePHI = Builder.CreatePHI(InputTy, 2);
 ValuePHI->addIncoming(BI->getOperand(0), BB);
   
 // Subtract the shift amount by one, as we're shifting one this loop
  @@ -116,13 +115,13 @@ void AVRShiftExpand::expand(BinaryOperator *BI) {
 Value *ValueShifted;
 switch (BI->getOpcode()) {
 case Instruction::Shl:
  -ValueShifted = Builder.CreateShl(ValuePHI, ConstantInt::get(Int32Ty, 1));
  +ValueShifted = Builder.CreateShl(ValuePHI, ConstantInt::get(InputTy, 1));
   break;
 case Instruction::LShr:
  -ValueShifted = Builder.CreateLShr(ValuePHI, ConstantInt::get(Int32Ty, 
1));
  +ValueShifted = Builder.CreateLShr(ValuePHI, ConstantInt::get(InputTy, 
1));
   break;
 case Instruction::AShr:
  -ValueShifted = Builder.CreateAShr(ValuePHI, ConstantInt::get(Int32Ty, 
1));
  +ValueShifted = Builder.CreateAShr(ValuePHI, ConstantInt::get(InputTy, 
1));
   break;
 default:
   llvm_unreachable("asked to expand an instruction that is not a shift");
  @@ -137,7 +136,7 @@ void AVRShiftExpand::expand(BinaryOperator *BI) {
 // Collect the resulting value. This is necessary in the IR but won't 
produce
 // any actual instructions.
 Builder.SetInsertPoint(BI);
  -  PHINode *Result = Builder.CreatePHI(Int32Ty, 2);
  +  PHINode *Result = Builder.CreatePHI(InputTy, 2);
 Result->addIncoming(BI->getOperand(0), BB);
 Result->addIncoming(ValueShifted, LoopBB);

Overall, this solution seems to work - I've checked it on a couple of Rust 
applications and the binaries behave correctly, both some simple and more 
complex ones.

I think the only disadvantage of this approach, as compared to expanding shifts 
during isel, are optimizations: expanding shifts eagerly means that we'll lose 
some of the optimizations we could have applied otherwise.

For instance, following that first example from Rust's standard library, we 
will expand that instruction into a 64-bit shift even though in principle a 
32-bit shift would suffice (but we don't know that yet during shift-expansion 
pass).

For safety, we could implement this simpler approach first, as presented in the 
diff here, and maybe come back to merging shift-expansion with isel in the 
future - what do you think about it?

¹ minimized case from Rust's standard library - originally: 
`_ZN4core3num7dec2flt6lemire13compute_float17hc1d4de6247502c96E`
² I'm not 100% sure why, though - seems to be somehow related to this `or + 
zext` combination


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153197

___
cfe-commits mailing list

[PATCH] D105759: Implement P2361 Unevaluated string literals

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

Address Shafik's comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105759

Files:
  clang-tools-extra/test/clang-tidy/checkers/modernize/unary-static-assert.cpp
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Lex/LiteralSupport.h
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Lex/Pragma.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/CXX/dcl.dcl/dcl.link/p2.cpp
  clang/test/CXX/dcl.dcl/p4-0x.cpp
  clang/test/FixIt/fixit-static-assert.cpp
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/SemaCXX/static-assert.cpp
  clang/test/SemaCXX/warn-thread-safety-parsing.cpp

Index: clang/test/SemaCXX/warn-thread-safety-parsing.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-parsing.cpp
+++ clang/test/SemaCXX/warn-thread-safety-parsing.cpp
@@ -309,7 +309,7 @@
 
 int gb_var_arg GUARDED_BY(mu1);
 
-int gb_non_ascii GUARDED_BY(L"wide"); // expected-warning {{ignoring 'guarded_by' attribute because its argument is invalid}}
+int gb_non_ascii GUARDED_BY(L"wide"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
 
 int gb_var_args __attribute__((guarded_by(mu1, mu2))); // \
   // expected-error {{'guarded_by' attribute takes one argument}}
Index: clang/test/SemaCXX/static-assert.cpp
===
--- clang/test/SemaCXX/static-assert.cpp
+++ clang/test/SemaCXX/static-assert.cpp
@@ -29,12 +29,18 @@
 S s1; // expected-note {{in instantiation of template class 'S' requested here}}
 S s2;
 
-static_assert(false, L"\x"); // expected-error {{static assertion failed: L"\x"}}
-static_assert(false, u"\U000317FF"); // expected-error {{static assertion failed: u"\U000317FF"}}
-
-static_assert(false, u8"Ω"); // expected-error {{static assertion failed: u8"\316\251"}}
-static_assert(false, L"\u1234"); // expected-error {{static assertion failed: L"\x1234"}}
-static_assert(false, L"\x1ff" "0\x123" "fx\xf" "goop"); // expected-error {{static assertion failed: L"\x1FF""0\x123""fx\xFgoop"}}
+static_assert(false, L"\x"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
+static_assert(false, u"\U000317FF"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
+// FIXME: render this as u8"\u03A9"
+static_assert(false, u8"Ω"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
+static_assert(false, L"\u1234"); // expected-error {{an unevaluated string literal cannot have an encoding prefix}}
+static_assert(false, L"\x1ff"// expected-error {{an unevaluated string literal cannot have an encoding prefix}}
+ "0\x123"
+ "fx\xf"
+ "goop");
+
+static_assert(true, "\xFF"); // expected-error {{invalid escape sequence '\xFF' in an unevaluated string literal}}
+static_assert(true, "\123"); // expected-error {{invalid escape sequence '\123' in an unevaluated string literal}}
 
 static_assert(false, R"(a
 \tb
Index: clang/test/Parser/cxx0x-attributes.cpp
===
--- clang/test/Parser/cxx0x-attributes.cpp
+++ clang/test/Parser/cxx0x-attributes.cpp
@@ -445,3 +445,8 @@
   ) {
   }
 };
+
+namespace P2361 {
+[[deprecated(L"\123")]] void a(); // expected-error{{an unevaluated string literal cannot have an encoding prefix}}
+[[nodiscard("\123")]] int b(); // expected-error{{invalid escape sequence '\123' in an unevaluated string literal}}
+}
Index: clang/test/FixIt/fixit-static-assert.cpp
===
--- clang/test/FixIt/fixit-static-assert.cpp
+++ clang/test/FixIt/fixit-static-assert.cpp
@@ -11,8 +11,6 @@
 // String literal prefixes are good.
 static_assert(true && R"(RawString)");
 // CHECK-DAG: {[[@LINE-1]]:20-[[@LINE-1]]:22}:","
-static_assert(true && L"RawString");
-// CHECK-DAG: {[[@LINE-1]]:20-[[@LINE-1]]:22}:","
 
 static_assert(true);
 // CHECK-DAG: {[[@LINE-1]]:19-[[@LINE-1]]:19}:", \"\""
Index: clang/test/CXX/dcl.dcl/p4-0x.cpp
===
--- clang/test/CXX/dcl.dcl/p4-0x.cpp
+++ clang/test/CXX/dcl.dcl/p4-0x.cpp
@@ -18,4 +18,6 @@
 static_assert(T(), "");
 static_assert(U(), 

[PATCH] D153590: Don't use float_t and double_t with #pragma clang fp eval_method.

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

This change causes test regressions on 32-bit x86:

  FAIL: Clang :: Sema/fp-eval-pragma-with-float-double_t-3.c (14665 of 17845)
   TEST 'Clang :: 
Sema/fp-eval-pragma-with-float-double_t-3.c' FAILED 
  Script:
  --
  : 'RUN: at line 1';   
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/17/include
 -nostdsysteminc -verify -fsyntax-only -verify -DNOERROR 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
  : 'RUN: at line 2';   
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/17/include
 -nostdsysteminc -verify -fsyntax-only -x c++ -DCPP -DNOERROR 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
  : 'RUN: at line 4';   
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/17/include
 -nostdsysteminc -verify -fsyntax-only -ffp-eval-method=extended -DNOERROR 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
  : 'RUN: at line 5';   
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/17/include
 -nostdsysteminc -verify -fsyntax-only -x c++ -DCPP  -ffp-eval-method=extended 
-DNOERROR 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
  : 'RUN: at line 8';   
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/17/include
 -nostdsysteminc -verify -fsyntax-only -ffp-eval-method=source 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
  : 'RUN: at line 9';   
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/17/include
 -nostdsysteminc -verify -fsyntax-only -x c++ -DCPP -ffp-eval-method=source 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
  : 'RUN: at line 11';   
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/17/include
 -nostdsysteminc -verify -fsyntax-only -ffp-eval-method=double 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
  : 'RUN: at line 12';   
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/17/include
 -nostdsysteminc -verify -fsyntax-only -x c++ -DCPP -ffp-eval-method=double 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
  --
  Exit Code: 1
  
  Command Output (stderr):
  --
  + : 'RUN: at line 1'
  + 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/clang
 -cc1 -internal-isystem 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/x/y/clang-abi_x86_32.x86/bin/../../../../lib/clang/17/include
 -nostdsysteminc -verify -fsyntax-only -verify -DNOERROR 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
  error: 'warning' diagnostics seen but not expected: 
File 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
 Line 36: Setting the floating point evaluation method to `source` on a target 
without SSE is not supported.
File 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
 Line 43: Setting the floating point evaluation method to `source` on a target 
without SSE is not supported.
File 
/var/tmp/portage/sys-devel/clang-17.0.0_pre20230624/work/clang/test/Sema/fp-eval-pragma-with-float-double_t-3.c
 Line 50: Setting the floating 

[PATCH] D153699: [clang] Fix pretty-printing for variables declared in a for-loop condition

2023-06-24 Thread Vaibhav Thakkar via Phabricator via cfe-commits
vaithak created this revision.
Herald added a project: All.
vaithak requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153699

Files:
  clang/lib/AST/StmtPrinter.cpp
  clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
  clang/test/SemaCXX/ast-print.cpp


Index: clang/test/SemaCXX/ast-print.cpp
===
--- clang/test/SemaCXX/ast-print.cpp
+++ clang/test/SemaCXX/ast-print.cpp
@@ -21,12 +21,14 @@
 // CHECK: if (int a = 1)
 // CHECK:  while (int a = 1)
 // CHECK:  switch (int a = 1)
+// CHECK:  for (; int a = 1;)
 
 void test2()
 {
 if (int a = 1) { }
 while (int a = 1) { }
 switch (int a = 1) { }
+for(; int a = 1; ) { }
 }
 
 // CHECK: new (1) int;
Index: clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
===
--- clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
+++ clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s
 
 int f() {
-  // CHECK: for (int i = 0; x; i++) {
+  // CHECK: for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
   for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
 return x;
   }
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -400,7 +400,9 @@
 PrintInitStmt(Node->getInit(), 5);
   else
 OS << (Node->getCond() ? "; " : ";");
-  if (Node->getCond())
+  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
+PrintRawDeclStmt(DS);
+  else if (Node->getCond())
 PrintExpr(Node->getCond());
   OS << ";";
   if (Node->getInc()) {


Index: clang/test/SemaCXX/ast-print.cpp
===
--- clang/test/SemaCXX/ast-print.cpp
+++ clang/test/SemaCXX/ast-print.cpp
@@ -21,12 +21,14 @@
 // CHECK: if (int a = 1)
 // CHECK:  while (int a = 1)
 // CHECK:  switch (int a = 1)
+// CHECK:  for (; int a = 1;)
 
 void test2()
 {
 if (int a = 1) { }
 while (int a = 1) { }
 switch (int a = 1) { }
+for(; int a = 1; ) { }
 }
 
 // CHECK: new (1) int;
Index: clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
===
--- clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
+++ clang/test/PCH/for-loop-init-ternary-operator-statement.cpp
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -x ast -ast-print %t | FileCheck %s
 
 int f() {
-  // CHECK: for (int i = 0; x; i++) {
+  // CHECK: for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
   for (int i = 0; int x = i < 2 ? 1 : 0; i++) {
 return x;
   }
Index: clang/lib/AST/StmtPrinter.cpp
===
--- clang/lib/AST/StmtPrinter.cpp
+++ clang/lib/AST/StmtPrinter.cpp
@@ -400,7 +400,9 @@
 PrintInitStmt(Node->getInit(), 5);
   else
 OS << (Node->getCond() ? "; " : ";");
-  if (Node->getCond())
+  if (const DeclStmt *DS = Node->getConditionVariableDeclStmt())
+PrintRawDeclStmt(DS);
+  else if (Node->getCond())
 PrintExpr(Node->getCond());
   OS << ";";
   if (Node->getInc()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153694: [clang][CodeGen] Remove no-op EmitCastToVoidPtr (NFC)

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



Comment at: clang/lib/CodeGen/CGAtomic.cpp:90
+StoragePtr = CGF.Builder.CreateAddrSpaceCast(
+StoragePtr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
 "atomic_bitfield_base");

I suppose address space shouldn't be dropped here, but this is what the 
original code does.




Comment at: clang/lib/CodeGen/ItaniumCXXABI.cpp:1473
   QualType SrcRecordTy,
   QualType DestTy) {
   auto *ClassDecl =

`DestTy` has become unused in both implementations. I'm not sure if I should 
remove it. It is always a [cv-qualified] `void *`.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153694

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


[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-06-24 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7f6e0052a97f: [clang-tidy] Add misc-header-include-cycle 
check (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144828

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
  clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
@@ -0,0 +1,59 @@
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+// RUN: mkdir %T/misc-header-include-cycle-headers
+// RUN: cp -r %S/Inputs/header-include-cycle* %T/misc-header-include-cycle-headers/
+// RUN: mkdir %T/misc-header-include-cycle-headers/system
+// RUN: cp -r %S/Inputs/system/header-include-cycle* %T/misc-header-include-cycle-headers/system
+// RUN: cp %s %T/header-include-cycle.cpp
+// RUN: clang-tidy %T/header-include-cycle.cpp -checks='-*,misc-header-include-cycle' -header-filter=.* \
+// RUN: -config="{CheckOptions: [{key: misc-header-include-cycle.IgnoredFilesList, value: 'header-include-cycle.self-e.hpp'}]}" \
+// RUN: -- -I%T/misc-header-include-cycle-headers -isystem %T/misc-header-include-cycle-headers/system \
+// RUN: --include %T/misc-header-include-cycle-headers/header-include-cycle.self-i.hpp | FileCheck %s \
+// RUN: -check-prefix=CHECK-MESSAGES "-implicit-check-not={{note|warning|error}}:" --dump-input=fail
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+
+#ifndef MAIN_GUARD
+#define MAIN_GUARD
+
+#include "header-include-cycle.cpp"
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: direct self-inclusion of header file 'header-include-cycle.cpp' [misc-header-include-cycle]
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth-d.hpp:3:10: warning: circular header file dependency detected while including 'header-include-cycle.first-d.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third-d.hpp:3:10: note: 'header-include-cycle.fourth-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second-d.hpp:3:10: note: 'header-include-cycle.third-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first-d.hpp:3:10: note: 'header-include-cycle.second-d.hpp' included from here
+// CHECK-MESSAGES: :[[@LINE-5]]:10: note: 'header-include-cycle.first-d.hpp' included from here
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth.hpp:2:10: warning: circular header file dependency detected while including 'header-include-cycle.first.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: 

[clang-tools-extra] 7f6e005 - [clang-tidy] Add misc-header-include-cycle check

2023-06-24 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-06-24T11:00:13Z
New Revision: 7f6e0052a97f13a5f595f3fd0c135c2c4db119d4

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

LOG: [clang-tidy] Add misc-header-include-cycle check

Check detects cyclic #include dependencies between user-defined headers.

Reviewed By: njames93

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

Added: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index a37f7b29ec999..348f3fa6402ec 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
+  HeaderIncludeCycleCheck.cpp
   IncludeCleanerCheck.cpp
   MiscTidyModule.cpp
   MisleadingBidirectional.cpp

diff  --git a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
new file mode 100644
index 0..bebd6e390ed53
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
@@ -0,0 +1,180 @@
+//===--- HeaderIncludeCycleCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "HeaderIncludeCycleCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Regex.h"
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+
+namespace {
+
+struct Include {
+  FileID Id;
+  llvm::StringRef Name;
+  SourceLocation Loc;
+};
+
+class CyclicDependencyCallbacks : public PPCallbacks {
+public:
+  CyclicDependencyCallbacks(HeaderIncludeCycleCheck ,
+const SourceManager ,
+const std::vector )
+  : Check(Check), SM(SM) {
+IgnoredFilesRegexes.reserve(IgnoredFilesList.size());
+for (const StringRef  : IgnoredFilesList) {
+  if 

[PATCH] D153641: [clang-format] Preserve AmpAmpTokenType in nested parentheses

2023-06-24 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

In D153641#465 , @rymiel wrote:

> @HazardyKnusperkeks I'm not sure why it didn't recurse already, given that 
> you even documented that it doesn't, but I chose to trust in the Beyoncé rule.

Most likely I didn't thought about what you now fixed and wanted to limit the 
scope of my change. I'm trying to think of something you may broke, but I can't.
Declaring functions should not be possible, if one already set the binary 
operator, right? Lambdas would be possible, but they should be handled 
correctly, but I think you could add something with `[](T&&){}(t)` in a clause, 
to show that it is correctly parsed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153641

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


[PATCH] D153694: [clang][CodeGen] Remove no-op EmitCastToVoidPtr

2023-06-24 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
Herald added a project: All.
barannikov88 updated this revision to Diff 534190.
barannikov88 added a comment.
barannikov88 added reviewers: nikic, JOE1994.
barannikov88 published this revision for review.
Herald added subscribers: cfe-commits, StephenFan.
Herald added a project: clang.

Cleanup


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153694

Files:
  clang/lib/CodeGen/CGAtomic.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/MicrosoftCXXABI.cpp

Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1011,10 +1011,8 @@
 }
 
 llvm::Value *MicrosoftCXXABI::EmitDynamicCastCall(
-CodeGenFunction , Address This, QualType SrcRecordTy,
-QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd) {
-  llvm::Type *DestLTy = CGF.ConvertType(DestTy);
-
+CodeGenFunction , Address This, QualType SrcRecordTy, QualType DestTy,
+QualType DestRecordTy, llvm::BasicBlock *CastEnd) {
   llvm::Value *SrcRTTI =
   CGF.CGM.GetAddrOfRTTIDescriptor(SrcRecordTy.getUnqualifiedType());
   llvm::Value *DestRTTI =
@@ -1040,8 +1038,7 @@
   llvm::Value *Args[] = {
   ThisPtr, Offset, SrcRTTI, DestRTTI,
   llvm::ConstantInt::get(CGF.Int32Ty, DestTy->isReferenceType())};
-  ThisPtr = CGF.EmitRuntimeCallOrInvoke(Function, Args);
-  return CGF.Builder.CreateBitCast(ThisPtr, DestLTy);
+  return CGF.EmitRuntimeCallOrInvoke(Function, Args);
 }
 
 llvm::Value *
@@ -1568,11 +1565,8 @@
   // 1) getThisValue is currently protected
   // 2) in theory, an ABI could implement 'this' returns some other way;
   //HasThisReturn only specifies a contract, not the implementation
-  if (HasThisReturn(CGF.CurGD))
+  if (HasThisReturn(CGF.CurGD) || hasMostDerivedReturn(CGF.CurGD))
 CGF.Builder.CreateStore(getThisValue(CGF), CGF.ReturnValue);
-  else if (hasMostDerivedReturn(CGF.CurGD))
-CGF.Builder.CreateStore(CGF.EmitCastToVoidPtr(getThisValue(CGF)),
-CGF.ReturnValue);
 
   if (isa(MD) && MD->getParent()->getNumVBases()) {
 assert(getStructorImplicitParamDecl(CGF) &&
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -1433,7 +1433,6 @@
 QualType DestTy, QualType DestRecordTy, llvm::BasicBlock *CastEnd) {
   llvm::Type *PtrDiffLTy =
   CGF.ConvertType(CGF.getContext().getPointerDiffType());
-  llvm::Type *DestLTy = CGF.ConvertType(DestTy);
 
   llvm::Value *SrcRTTI =
   CGF.CGM.GetAddrOfRTTIDescriptor(SrcRecordTy.getUnqualifiedType());
@@ -1448,12 +1447,9 @@
   computeOffsetHint(CGF.getContext(), SrcDecl, DestDecl).getQuantity());
 
   // Emit the call to __dynamic_cast.
-  llvm::Value *Value = ThisAddr.getPointer();
-  Value = CGF.EmitCastToVoidPtr(Value);
-
-  llvm::Value *args[] = {Value, SrcRTTI, DestRTTI, OffsetHint};
-  Value = CGF.EmitNounwindRuntimeCall(getItaniumDynamicCastFn(CGF), args);
-  Value = CGF.Builder.CreateBitCast(Value, DestLTy);
+  llvm::Value *Args[] = {ThisAddr.getPointer(), SrcRTTI, DestRTTI, OffsetHint};
+  llvm::Value *Value =
+  CGF.EmitNounwindRuntimeCall(getItaniumDynamicCastFn(CGF), Args);
 
   /// C++ [expr.dynamic.cast]p9:
   ///   A failed cast to reference type throws std::bad_cast
@@ -1475,7 +1471,6 @@
   Address ThisAddr,
   QualType SrcRecordTy,
   QualType DestTy) {
-  llvm::Type *DestLTy = CGF.ConvertType(DestTy);
   auto *ClassDecl =
   cast(SrcRecordTy->castAs()->getDecl());
   llvm::Value *OffsetToTop;
@@ -1506,10 +1501,8 @@
 PtrDiffLTy, OffsetToTop, CGF.getPointerAlign(), "offset.to.top");
   }
   // Finally, add the offset to the pointer.
-  llvm::Value *Value = ThisAddr.getPointer();
-  Value = CGF.EmitCastToVoidPtr(Value);
-  Value = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, Value, OffsetToTop);
-  return CGF.Builder.CreateBitCast(Value, DestLTy);
+  return CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, ThisAddr.getPointer(),
+   OffsetToTop);
 }
 
 bool ItaniumCXXABI::EmitBadCastCall(CodeGenFunction ) {
Index: clang/lib/CodeGen/CodeGenFunction.h
===
--- clang/lib/CodeGen/CodeGenFunction.h
+++ clang/lib/CodeGen/CodeGenFunction.h
@@ -2625,9 +2625,6 @@
  AggValueSlot::DoesNotOverlap);
   }
 
-  /// Emit a cast to void* in the 

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

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



Comment at: clang/lib/AST/Decl.cpp:1831
+  // Objective-C as an extension.
+  if (isa(this) && getLangOpts().ObjC)
 return true;

shafik wrote:
> It is not obvious to me if this is a drive by fix or this has a larger effect 
> in the context of this change. Is there a test that demonstrates the effect 
> of this change?
That's a left over from when the patched allowed placeholder in parameter names 
(EWG voted against that). thanks!



Comment at: clang/lib/Sema/SemaDecl.cpp:2024
   if (const VarDecl *VD = dyn_cast(D)) {
+if (D->isPlaceholderVar())
+  return !VD->hasInit();

erichkeane wrote:
> Why would we get here?  Doesn't line 1995 pick this up?  Or am I missing 
> where D is modified?
> 
> ALSO, I'd suggest making this VD->isPlaceholderVar, as to not annoy the SA 
> tools.
Yep, this was dead code, thanks!



Comment at: clang/lib/Sema/SemaDecl.cpp:18217
 
+  NewFD->setIsPlaceholderVar(LangOpts.CPlusPlus && II && II->isPlaceholder());
   if (PrevDecl && !isa(PrevDecl)) {

shafik wrote:
> Why can't we fold this into `FieldDecl::Create`? This comment applies in some 
> other places as well.
By adding a parameter to FieldDecl::Create? We could, I'm not sure it would 
necessarily be cleaner. Let me know what you prefer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D153695: [clang][Interp] Fix passing parameters of composite type

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

  We pass these as pointers, so we need to be careful not to emit pointers
  to pointers when we emit visit DeclRefExprs pointing to parameters.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153695

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeEmitter.h
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/Context.cpp
  clang/lib/AST/Interp/Context.h
  clang/lib/AST/Interp/EvalEmitter.h
  clang/test/AST/Interp/lambda.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
@@ -896,9 +896,7 @@
 
 }
 
-#if 0
 constexpr bool BPand(BoolPair bp) {
   return bp.first && bp.second;
 }
 static_assert(BPand(BoolPair{true, false}) == false, "");
-#endif
Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -103,10 +103,7 @@
 
 return a;
   }
-  /// FIXME: This should work in the new interpreter.
-#if 0
-  static_assert(foo() == 1); // expected-error {{not an integral constant expression}}
-#endif
+  static_assert(foo() == 1);
 }
 
 namespace LambdasAsParams {
Index: clang/lib/AST/Interp/EvalEmitter.h
===
--- clang/lib/AST/Interp/EvalEmitter.h
+++ clang/lib/AST/Interp/EvalEmitter.h
@@ -75,10 +75,9 @@
   }
 
   /// Parameter indices.
-  llvm::DenseMap Params;
+  llvm::DenseMap Params;
   /// Lambda captures.
-  /// Map from Decl* to [Offset, IsReference] pair.
-  llvm::DenseMap> LambdaCaptures;
+  llvm::DenseMap LambdaCaptures;
   unsigned LambdaThisCapture;
   /// Local descriptors.
   llvm::SmallVector, 2> Descriptors;
Index: clang/lib/AST/Interp/Context.h
===
--- clang/lib/AST/Interp/Context.h
+++ clang/lib/AST/Interp/Context.h
@@ -31,6 +31,11 @@
 class State;
 enum PrimType : unsigned;
 
+struct ParamOffset {
+  unsigned Offset;
+  bool IsPtr;
+};
+
 /// Holds all information required to evaluate constexpr code in a module.
 class Context final {
 public:
Index: clang/lib/AST/Interp/Context.cpp
===
--- clang/lib/AST/Interp/Context.cpp
+++ clang/lib/AST/Interp/Context.cpp
@@ -27,6 +27,8 @@
 Context::~Context() {}
 
 bool Context::isPotentialConstantExpr(State , const FunctionDecl *FD) {
+  llvm::errs() << __PRETTY_FUNCTION__ << "\n";
+  FD->dump();
   assert(Stk.empty());
   Function *Func = P->getFunction(FD);
   if (!Func || !Func->hasBody()) {
@@ -51,6 +53,9 @@
 }
 
 bool Context::evaluateAsRValue(State , const Expr *E, APValue ) {
+  llvm::errs() << __PRETTY_FUNCTION__ << "\n";
+  E->dump();
+
   assert(Stk.empty());
   ByteCodeExprGen C(*this, *P, Parent, Stk, Result);
   if (Check(Parent, C.interpretExpr(E))) {
Index: clang/lib/AST/Interp/ByteCodeStmtGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -125,7 +125,7 @@
 // We do the lvalue-to-rvalue conversion manually here, so no need
 // to care about references.
 PrimType ParamType = this->classify(PVD->getType()).value_or(PT_Ptr);
-if (!this->emitGetParam(ParamType, It->second, MD))
+if (!this->emitGetParam(ParamType, It->second.Offset, MD))
   return false;
   }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1273,7 +1273,7 @@
 llvm::function_ref Indirect) {
   auto It = this->Params.find(PD);
   if (It != this->Params.end()) {
-unsigned Idx = It->second;
+unsigned Idx = It->second.Offset;
 switch (AK) {
 case DerefKind::Read:
   return DiscardResult ? true : this->emitGetParam(T, Idx, LV);
@@ -2253,18 +2253,19 @@
 return this->emitGetPtrGlobal(*GlobalIndex, E);
   } else if (const auto *PVD = dyn_cast(D)) {
 if (auto It = this->Params.find(PVD); It != this->Params.end()) {
-  if (IsReference)
-return this->emitGetParamPtr(It->second, E);
-  return this->emitGetPtrParam(It->second, E);
+  if (IsReference || !It->second.IsPtr)
+return this->emitGetParamPtr(It->second.Offset, E);
+
+  return this->emitGetPtrParam(It->second.Offset, E);
 }
   }
 
   // Handle lambda captures.
   if (auto It = this->LambdaCaptures.find(D);
   It != 

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

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

- Address Shafik's an Erich's comments
- Add missing serialization code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Sema/Lookup.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/Lexer/unicode.c
  clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -145,7 +145,7 @@
  
   Placeholder variables with no name
   https://wg21.link/P2169R4;>P2169R4
-  No
+  Clang 17
  
 
 
Index: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2c-placeholder-vars.cpp
@@ -0,0 +1,98 @@
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter -Wunused %s
+
+void static_var() {
+static int _; // expected-note {{previous definition is here}} \
+  // expected-note {{candidate}}
+static int _; // expected-error {{redefinition of '_'}}
+int _;// expected-warning {{placeholder variables are a C++2c extension}} \
+  // expected-note {{candidate}}
+_++; // expected-error{{reference to '_' is ambiguous}}
+}
+
+void static_var_2() {
+int _; // expected-note {{previous definition is here}}
+static int _; // expected-error {{redefinition of '_'}}
+}
+
+void bindings() {
+int arr[4] = {0, 1, 2, 3};
+auto [_, _, _, _] = arr; // expected-warning 3{{placeholder variables are a C++2c extension}} \
+ // expected-note 4{{placeholder declared here}}
+_ == 42; // expected-error {{referring to placeholder '_' is not allowed}}
+{
+auto [_, a, b, c] = arr;
+auto [_, _, _, _] = arr; // expected-warning 4{{placeholder variables are a C++2c extension}}
+}
+}
+
+void lambda() {
+(void)[_ = 0, _ = 1] { // expected-warning {{placeholder variables are a C++2c extension}} \
+   // expected-note 4{{placeholder declared here}} \\
+   // expected-warning 2{{placeholder variable has no side effect}}
+(void)_++; // expected-error {{referring to placeholder '_' is not allowed}}
+};
+}
+
+namespace global_var {
+int _; // expected-note {{previous definition is here}}
+int _; // expected-error {{redefinition of '_'}}
+}
+
+namespace global_fun {
+void _();
+void _();
+
+void _() {} // expected-note {{previous definition is here}}
+void _() {} // expected-error {{redefinition of '_'}}
+void _(int){};
+}
+
+void extern_test() {
+extern int _;
+extern int _; // expected-note {{candidate}}
+int _; //expected-note {{candidate}}
+_++; // expected-error {{reference to '_' is ambiguous}}
+}
+
+
+struct Members {
+int _; // expected-note {{placeholder declared here}}
+int _; // expected-warning{{placeholder variables are a C++2c extension}} \
+   // expected-note {{placeholder declared here}}
+void f() {
+_++; // expected-error {{referring to placeholder '_' is not allowed}}
+}
+};
+
+namespace using_ {
+int _; // expected-note {{target of using declaration}}
+void f() {
+int _; // expected-note {{conflicting declaration}}
+_ = 0;
+using using_::_; // expected-error {{target of using declaration conflicts with declaration already in scope}}
+}
+}
+
+
+void call(int);
+void test_param(int _) {}
+void test_params(int _, int _); // expected-error {{redefinition of parameter '_'}} \
+// expected-note {{previous declaration is here}}
+
+template  // expected-error {{declaration of '_' shadows template parameter}} \
+  // expected-note  {{template parameter is declared here}}
+auto i = 0;
+
+template 
+concept C = requires(T _, T _) {  // expected-error {{redefinition of parameter '_'}} \
+// expected-note {{previous declaration is here}}
+T{};
+};
+
+struct S {
+int a;
+};
+
+void f(S a, S _) { // expected-warning {{unused parameter 'a'}}
+
+}
Index: clang/test/Lexer/unicode.c
===
--- clang/test/Lexer/unicode.c
+++ clang/test/Lexer/unicode.c
@@ 

[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-06-24 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 534183.
PiotrZSL added a comment.

Reorder warnigns & copy .cpp file to Output


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144828

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
  clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
@@ -0,0 +1,59 @@
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+// RUN: mkdir %T/misc-header-include-cycle-headers
+// RUN: cp -r %S/Inputs/header-include-cycle* %T/misc-header-include-cycle-headers/
+// RUN: mkdir %T/misc-header-include-cycle-headers/system
+// RUN: cp -r %S/Inputs/system/header-include-cycle* %T/misc-header-include-cycle-headers/system
+// RUN: cp %s %T/header-include-cycle.cpp
+// RUN: clang-tidy %T/header-include-cycle.cpp -checks='-*,misc-header-include-cycle' -header-filter=.* \
+// RUN: -config="{CheckOptions: [{key: misc-header-include-cycle.IgnoredFilesList, value: 'header-include-cycle.self-e.hpp'}]}" \
+// RUN: -- -I%T/misc-header-include-cycle-headers -isystem %T/misc-header-include-cycle-headers/system \
+// RUN: --include %T/misc-header-include-cycle-headers/header-include-cycle.self-i.hpp | FileCheck %s \
+// RUN: -check-prefix=CHECK-MESSAGES "-implicit-check-not={{note|warning|error}}:" --dump-input=fail
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+
+#ifndef MAIN_GUARD
+#define MAIN_GUARD
+
+#include "header-include-cycle.cpp"
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: direct self-inclusion of header file 'header-include-cycle.cpp' [misc-header-include-cycle]
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth-d.hpp:3:10: warning: circular header file dependency detected while including 'header-include-cycle.first-d.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third-d.hpp:3:10: note: 'header-include-cycle.fourth-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second-d.hpp:3:10: note: 'header-include-cycle.third-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first-d.hpp:3:10: note: 'header-include-cycle.second-d.hpp' included from here
+// CHECK-MESSAGES: :[[@LINE-5]]:10: note: 'header-include-cycle.first-d.hpp' included from here
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth.hpp:2:10: warning: circular header file dependency detected while including 'header-include-cycle.first.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third.hpp:2:10: note: 'header-include-cycle.fourth.hpp' included from here

[clang-tools-extra] 071b129 - Revert "[clang-tidy] Add misc-header-include-cycle check"

2023-06-24 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-06-24T08:41:52Z
New Revision: 071b129b64537eedf94b8fdf92e09a8fcb7a827f

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

LOG: Revert "[clang-tidy] Add misc-header-include-cycle check"

This reverts commit f3aa6cc0f5d56752242203c2a9231c1bc230c15e.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp



diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 348f3fa6402ec..a37f7b29ec999 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -20,7 +20,6 @@ add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
-  HeaderIncludeCycleCheck.cpp
   IncludeCleanerCheck.cpp
   MiscTidyModule.cpp
   MisleadingBidirectional.cpp

diff  --git a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
deleted file mode 100644
index bebd6e390ed53..0
--- a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
+++ /dev/null
@@ -1,180 +0,0 @@
-//===--- HeaderIncludeCycleCheck.cpp - clang-tidy 
-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-
-#include "HeaderIncludeCycleCheck.h"
-#include "../utils/OptionsUtils.h"
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/Lex/PPCallbacks.h"
-#include "clang/Lex/Preprocessor.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Support/Regex.h"
-#include 
-#include 
-#include 
-#include 
-
-using namespace clang::ast_matchers;
-
-namespace clang::tidy::misc {
-
-namespace {
-
-struct Include {
-  FileID Id;
-  llvm::StringRef Name;
-  SourceLocation Loc;
-};
-
-class CyclicDependencyCallbacks : public PPCallbacks {
-public:
-  CyclicDependencyCallbacks(HeaderIncludeCycleCheck ,
-const SourceManager ,
-const std::vector )
-  : Check(Check), SM(SM) {
-IgnoredFilesRegexes.reserve(IgnoredFilesList.size());
-for (const StringRef  : IgnoredFilesList) {
-  if (!It.empty())
-IgnoredFilesRegexes.emplace_back(It);
-}
-  }
-
-  

[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-06-24 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 534179.
eopXD added a comment.

Add test coverage for tuple types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/riscv-types.c
  clang/test/Sema/riscv-vector-float16-check.c
  clang/test/Sema/riscv-vector-float32-check.c
  clang/test/Sema/riscv-vector-float64-check.c
  clang/test/Sema/riscv-vector-int64-check.c
  clang/test/Sema/riscv-vector-zve32x-check.c

Index: clang/test/Sema/riscv-vector-zve32x-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-zve32x-check.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -triple riscv64 \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+
+__rvv_int8m1_t foo8() { /* expected-error {{RISC-V type '__rvv_int8m1_t' requires the 'zve32x' extension}} */
+  __rvv_int8m1_t i8m1; /* expected-error {{RISC-V type '__rvv_int8m1_t' requires the 'zve32x' extension}} */
+
+  (void)i8m1; /* expected-error {{RISC-V type '__rvv_int8m1_t' requires the 'zve32x' extension}} */
+
+  return i8m1; /* expected-error {{RISC-V type '__rvv_int8m1_t' requires the 'zve32x' extension}} */
+}
+
+__rvv_int16m1_t foo16() { /* expected-error {{RISC-V type '__rvv_int16m1_t' requires the 'zve32x' extension}} */
+  __rvv_int16m1_t i16m1; /* expected-error {{RISC-V type '__rvv_int16m1_t' requires the 'zve32x' extension}} */
+
+  (void)i16m1; /* expected-error {{RISC-V type '__rvv_int16m1_t' requires the 'zve32x' extension}} */
+
+  return i16m1; /* expected-error {{RISC-V type '__rvv_int16m1_t' requires the 'zve32x' extension}} */
+}
+
+__rvv_int32m1_t foo32() { /* expected-error {{RISC-V type '__rvv_int32m1_t' requires the 'zve32x' extension}} */
+  __rvv_int32m1_t i32m1; /* expected-error {{RISC-V type '__rvv_int32m1_t' requires the 'zve32x' extension}} */
+
+  (void)i32m1; /* expected-error {{RISC-V type '__rvv_int32m1_t' requires the 'zve32x' extension}} */
+
+  return i32m1; /* expected-error {{RISC-V type '__rvv_int32m1_t' requires the 'zve32x' extension}} */
+}
+
+__rvv_int8m1x2_t bar8() { /* expected-error {{RISC-V type '__rvv_int8m1x2_t' requires the 'zve32x' extension}} */
+  __rvv_int8m1x2_t i8m1x2; /* expected-error {{RISC-V type '__rvv_int8m1x2_t' requires the 'zve32x' extension}} */
+
+  (void)i8m1x2; /* expected-error {{RISC-V type '__rvv_int8m1x2_t' requires the 'zve32x' extension}} */
+
+  return i8m1x2; /* expected-error {{RISC-V type '__rvv_int8m1x2_t' requires the 'zve32x' extension}} */
+}
+
+__rvv_int16m1x2_t bar16() { /* expected-error {{RISC-V type '__rvv_int16m1x2_t' requires the 'zve32x' extension}} */
+  __rvv_int16m1x2_t i16m1x2; /* expected-error {{RISC-V type '__rvv_int16m1x2_t' requires the 'zve32x' extension}} */
+
+  (void)i16m1x2; /* expected-error {{RISC-V type '__rvv_int16m1x2_t' requires the 'zve32x' extension}} */
+
+  return i16m1x2; /* expected-error {{RISC-V type '__rvv_int16m1x2_t' requires the 'zve32x' extension}} */
+}
+
+__rvv_int32m1x2_t bar32() { /* expected-error {{RISC-V type '__rvv_int32m1x2_t' requires the 'zve32x' extension}} */
+  __rvv_int32m1x2_t i32m1x2; /* expected-error {{RISC-V type '__rvv_int32m1x2_t' requires the 'zve32x' extension}} */
+
+  (void)i32m1x2; /* expected-error {{RISC-V type '__rvv_int32m1x2_t' requires the 'zve32x' extension}} */
+
+  return i32m1x2; /* expected-error {{RISC-V type '__rvv_int32m1x2_t' requires the 'zve32x' extension}} */
+}
Index: clang/test/Sema/riscv-vector-int64-check.c
===
--- clang/test/Sema/riscv-vector-int64-check.c
+++ clang/test/Sema/riscv-vector-int64-check.c
@@ -5,4 +5,17 @@
 #include 
 
 vint64m1_t foo() { /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
-} /* expected-warning {{non-void function does not return a value}}*/
+  vint64m1_t i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+
+  (void)i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+
+  return i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+}
+
+vint64m1x2_t bar() { /* expected-error {{RISC-V type 'vint64m1x2_t' (aka '__rvv_int64m1x2_t') requires the 'zve64x' extension}} */
+  vint64m1x2_t i64m1x2; /* expected-error {{RISC-V type 'vint64m1x2_t' (aka '__rvv_int64m1x2_t') requires the 'zve64x' extension}} */
+
+  (void)i64m1x2; /* expected-error {{RISC-V type 'vint64m1x2_t' (aka '__rvv_int64m1x2_t') requires the 'zve64x' extension}} */
+
+  return i64m1x2; /* expected-error {{RISC-V type 'vint64m1x2_t' (aka '__rvv_int64m1x2_t') requires the 

[PATCH] D144828: [clang-tidy] Add misc-header-include-cycle check

2023-06-24 Thread Piotr Zegar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf3aa6cc0f5d5: [clang-tidy] Add misc-header-include-cycle 
check (authored by PiotrZSL).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144828

Files:
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
  clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp
  
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
  clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp
@@ -0,0 +1,58 @@
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+// RUN: mkdir %T/misc-header-include-cycle-headers
+// RUN: cp -r %S/Inputs/header-include-cycle* %T/misc-header-include-cycle-headers/
+// RUN: mkdir %T/misc-header-include-cycle-headers/system
+// RUN: cp -r %S/Inputs/system/header-include-cycle* %T/misc-header-include-cycle-headers/system
+// RUN: clang-tidy %s -checks='-*,misc-header-include-cycle' -header-filter=.* \
+// RUN: -config="{CheckOptions: [{key: misc-header-include-cycle.IgnoredFilesList, value: 'header-include-cycle.self-e.hpp'}]}" \
+// RUN: -- -I%T/misc-header-include-cycle-headers -isystem %T/misc-header-include-cycle-headers/system \
+// RUN: --include %T/misc-header-include-cycle-headers/header-include-cycle.self-i.hpp | FileCheck %s \
+// RUN: -check-prefix=CHECK-MESSAGES "-implicit-check-not={{note|warning|error}}:"
+// RUN: rm -rf %T/misc-header-include-cycle-headers
+
+#ifndef MAIN_GUARD
+#define MAIN_GUARD
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth-d.hpp:3:10: warning: circular header file dependency detected while including 'header-include-cycle.first-d.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third-d.hpp:3:10: note: 'header-include-cycle.fourth-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second-d.hpp:3:10: note: 'header-include-cycle.third-d.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first-d.hpp:3:10: note: 'header-include-cycle.second-d.hpp' included from here
+// CHECK-MESSAGES: :[[@LINE-5]]:10: note: 'header-include-cycle.first-d.hpp' included from here
+
+#include 
+// CHECK-MESSAGES: header-include-cycle.fourth.hpp:2:10: warning: circular header file dependency detected while including 'header-include-cycle.first.hpp', please check the include path [misc-header-include-cycle]
+// CHECK-MESSAGES: header-include-cycle.third.hpp:2:10: note: 'header-include-cycle.fourth.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.second.hpp:2:10: note: 'header-include-cycle.third.hpp' included from here
+// CHECK-MESSAGES: header-include-cycle.first.hpp:2:10: note: 

[clang-tools-extra] f3aa6cc - [clang-tidy] Add misc-header-include-cycle check

2023-06-24 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-06-24T08:06:48Z
New Revision: f3aa6cc0f5d56752242203c2a9231c1bc230c15e

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

LOG: [clang-tidy] Add misc-header-include-cycle check

Check detects cyclic #include dependencies between user-defined headers.

Reviewed By: njames93

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

Added: 
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.h
clang-tools-extra/docs/clang-tidy/checks/misc/header-include-cycle.rst

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.first.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.fourth.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.second.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-e.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-i.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-n.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self-o.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.self.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third-d.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/header-include-cycle.third.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.first-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.fourth-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.second-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.self-s.hpp

clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/system/header-include-cycle.third-s.hpp
clang-tools-extra/test/clang-tidy/checkers/misc/header-include-cycle.cpp

Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index a37f7b29ec999..348f3fa6402ec 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -20,6 +20,7 @@ add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
+  HeaderIncludeCycleCheck.cpp
   IncludeCleanerCheck.cpp
   MiscTidyModule.cpp
   MisleadingBidirectional.cpp

diff  --git a/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
new file mode 100644
index 0..bebd6e390ed53
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/HeaderIncludeCycleCheck.cpp
@@ -0,0 +1,180 @@
+//===--- HeaderIncludeCycleCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "HeaderIncludeCycleCheck.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Regex.h"
+#include 
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+
+namespace {
+
+struct Include {
+  FileID Id;
+  llvm::StringRef Name;
+  SourceLocation Loc;
+};
+
+class CyclicDependencyCallbacks : public PPCallbacks {
+public:
+  CyclicDependencyCallbacks(HeaderIncludeCycleCheck ,
+const SourceManager ,
+const std::vector )
+  : Check(Check), SM(SM) {
+IgnoredFilesRegexes.reserve(IgnoredFilesList.size());
+for (const StringRef  : IgnoredFilesList) {
+  if 

[PATCH] D152946: [C++20][Modules] Implement P2615R1 revised export diagnostics.

2023-06-24 Thread Iain Sandoe via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
iains marked an inline comment as done.
Closed by commit rGe5c7904fa0bf: [C++20][Modules] Implement P2615R1 revised 
export diagnostics. (authored by iains).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152946

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaModule.cpp
  clang/test/CXX/module/module.interface/p3.cpp
  clang/test/Modules/cxx20-10-2-ex1.cpp
  clang/test/Modules/cxx20-10-2-ex7.cpp
  clang/test/SemaCXX/modules.cppm

Index: clang/test/SemaCXX/modules.cppm
===
--- clang/test/SemaCXX/modules.cppm
+++ clang/test/SemaCXX/modules.cppm
@@ -34,11 +34,11 @@
 import foo; // expected-error {{imports must immediately follow the module declaration}}
 
 export {}
-export {  // expected-note {{begins here}}
-  ;   // expected-warning {{ISO C++20 does not permit an empty declaration to appear in an export block}}
+export {
+  ;   // No diagnostic after P2615R1 DR
 }
-export {   // expected-note {{begins here}}
-  static_assert(true); // expected-warning {{ISO C++20 does not permit a static_assert declaration to appear in an export block}}
+export {
+  static_assert(true); // No diagnostic after P2615R1 DR
 }
 
 int use_b = b; // expected-error{{use of undeclared identifier 'b'}}
Index: clang/test/Modules/cxx20-10-2-ex7.cpp
===
--- clang/test/Modules/cxx20-10-2-ex7.cpp
+++ clang/test/Modules/cxx20-10-2-ex7.cpp
@@ -2,8 +2,10 @@
 
 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %s -verify -o %t
 
+// expected-no-diagnostics
+
 export module M;
 export namespace N {
 int x; // OK
-static_assert(1 == 1); // expected-error {{static_assert declaration cannot be exported}}
+static_assert(1 == 1); // No diagnostic after P2615R1 DR
 } // namespace N
Index: clang/test/Modules/cxx20-10-2-ex1.cpp
===
--- clang/test/Modules/cxx20-10-2-ex1.cpp
+++ clang/test/Modules/cxx20-10-2-ex1.cpp
@@ -17,9 +17,9 @@
 // expected-error@std-10-2-ex1.h:* {{export declaration can only be used within a module purview}}
 
 export module M1;
-export namespace {} // expected-error {{declaration does not introduce any names to be exported}}
-export namespace {
-int a1; // expected-error {{declaration of 'a1' with internal linkage cannot be exported}}
+export namespace {} // expected-error {{anonymous namespaces cannot be exported}}
+export namespace { // expected-error {{anonymous namespaces cannot be exported}}
+int a1;
 }
 namespace {// expected-note {{anonymous namespace begins here}}
 export int a2; // expected-error {{export declaration appears within anonymous namespace}}
@@ -28,4 +28,4 @@
 export int f();  // OK
 
 export namespace N {} // namespace N
-export using namespace N; // expected-error {{ISO C++20 does not permit using directive to be exported}}
+export using namespace N; // No diagnostic after P2615R1 DR
Index: clang/test/CXX/module/module.interface/p3.cpp
===
--- clang/test/CXX/module/module.interface/p3.cpp
+++ clang/test/CXX/module/module.interface/p3.cpp
@@ -1,18 +1,19 @@
-// RUN: %clang_cc1 -std=c++2a %s -verify -pedantic-errors
+// RUN: %clang_cc1 -std=c++20 %s -verify -pedantic-errors
 
+// As amended by P2615R1 applied as a DR against C++20.
 export module p3;
 
 namespace A { int ns_mem; } // expected-note 2{{target}}
 
 // An exported declaration shall declare at least one name.
-export; // expected-error {{empty declaration cannot be exported}}
-export static_assert(true); // expected-error {{static_assert declaration cannot be exported}}
-export using namespace A;   // expected-error {{ISO C++20 does not permit using directive to be exported}}
+export; // No diagnostic after P2615R1 DR
+export static_assert(true); // No diagnostic after P2615R1 DR
+export using namespace A;   // No diagnostic after P2615R1 DR
 
-export { // expected-note 3{{export block begins here}}
-  ; // expected-error {{ISO C++20 does not permit an empty declaration to appear in an export block}}
-  static_assert(true); // expected-error {{ISO C++20 does not permit a static_assert declaration to appear in an export block}}
-  using namespace A;   // expected-error {{ISO C++20 does not permit using directive to be exported}}
+export { // No diagnostic after P2615R1 DR
+  ; // No diagnostic after P2615R1 DR
+  static_assert(true); // No diagnostic after P2615R1 DR
+  using namespace A;   // No diagnostic after P2615R1 DR
 }
 
 export struct {}; // expected-error {{must be class member}} expected-error {{GNU extension}} expected-error {{does not declare anything}}
@@ -24,27 +25,28 @@
 export enum E : int;
 export typedef int; // expected-error {{typedef 

[clang] e5c7904 - [C++20][Modules] Implement P2615R1 revised export diagnostics.

2023-06-24 Thread Iain Sandoe via cfe-commits

Author: Iain Sandoe
Date: 2023-06-24T09:01:59+01:00
New Revision: e5c7904fa0bfa5a24f192cfa7b9116560e1f5d43

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

LOG: [C++20][Modules] Implement P2615R1 revised export diagnostics.

It has been reported to that the current clang  errors for, specifically,
static_assert in export contexts are a serious blocker to adoption of
modules in some cases.

There is also implementation divergence with GCC and MSVC allowing the
constructs mentioned below where clang currently rejects them with an
error.

The category of errors [for declarations in an exported context] is:
(unnamed, static_assert, empty and asm decls). These are now permitted
after P2615R1 which was approved by WG21 as a DR (and thus should be
applied to C++20 as well).

This patch removes these diagnostics and amends the testsuite accordingly.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaModule.cpp
clang/test/CXX/module/module.interface/p3.cpp
clang/test/Modules/cxx20-10-2-ex1.cpp
clang/test/Modules/cxx20-10-2-ex7.cpp
clang/test/SemaCXX/modules.cppm

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a215095d540ae..3f0b7a54d8890 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11262,22 +11262,11 @@ def note_global_module_introducer_missing : Note<
 def err_export_within_anonymous_namespace : Error<
   "export declaration appears within anonymous namespace">;
 def note_anonymous_namespace : Note<"anonymous namespace begins here">;
-def ext_export_no_name_block : ExtWarn<
-  "ISO C++20 does not permit %select{an empty|a static_assert}0 declaration "
-  "to appear in an export block">, InGroup;
-def ext_export_no_names : ExtWarn<
-  "ISO C++20 does not permit a declaration that does not introduce any names "
-  "to be exported">, InGroup;
-def introduces_no_names : Error<
-  "declaration does not introduce any names to be exported">;
 def note_export : Note<"export block begins here">;
-def err_export_no_name : Error<
-  "%select{empty|static_assert|asm}0 declaration cannot be exported">;
-def ext_export_using_directive : ExtWarn<
-  "ISO C++20 does not permit using directive to be exported">,
-  InGroup>;
 def err_export_within_export : Error<
   "export declaration appears within another export declaration">;
+def err_export_anon_ns_internal : Error<
+  "anonymous namespaces cannot be exported">;
 def err_export_internal : Error<
   "declaration of %0 with internal linkage cannot be exported">;
 def err_export_using_internal : Error<

diff  --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 5ce5330b09466..9b2982e7fa4df 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -814,76 +814,22 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation 
ExportLoc,
   return D;
 }
 
-static bool checkExportedDeclContext(Sema , DeclContext *DC,
- SourceLocation BlockStart);
-
-namespace {
-enum class UnnamedDeclKind {
-  Empty,
-  StaticAssert,
-  Asm,
-  UsingDirective,
-  Namespace,
-  Context
-};
-}
-
-static std::optional getUnnamedDeclKind(Decl *D) {
-  if (isa(D))
-return UnnamedDeclKind::Empty;
-  if (isa(D))
-return UnnamedDeclKind::StaticAssert;
-  if (isa(D))
-return UnnamedDeclKind::Asm;
-  if (isa(D))
-return UnnamedDeclKind::UsingDirective;
-  // Everything else either introduces one or more names or is ill-formed.
-  return std::nullopt;
-}
-
-unsigned getUnnamedDeclDiag(UnnamedDeclKind UDK, bool InBlock) {
-  switch (UDK) {
-  case UnnamedDeclKind::Empty:
-  case UnnamedDeclKind::StaticAssert:
-// Allow empty-declarations and static_asserts in an export block as an
-// extension.
-return InBlock ? diag::ext_export_no_name_block : diag::err_export_no_name;
-
-  case UnnamedDeclKind::UsingDirective:
-// Allow exporting using-directives as an extension.
-return diag::ext_export_using_directive;
-
-  case UnnamedDeclKind::Namespace:
-// Anonymous namespace with no content.
-return diag::introduces_no_names;
-
-  case UnnamedDeclKind::Context:
-// Allow exporting DeclContexts that transitively contain no declarations
-// as an extension.
-return diag::ext_export_no_names;
-
-  case UnnamedDeclKind::Asm:
-return diag::err_export_no_name;
-  }
-  llvm_unreachable("unknown kind");
-}
+static bool checkExportedDecl(Sema &, Decl *, SourceLocation);
 
-static void diagExportedUnnamedDecl(Sema , UnnamedDeclKind UDK, Decl *D,
-

[PATCH] D153693: [clang][Interp] Handle InitListExprs of composite type

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

  They might appear freestanding, not as part of an initializer. In that
  case, we need to create a temporary variable and return a pointer to it.

The test case added doesn't work yet since passing structs by value to 
functions is broken right now, I will fix that in a follow-up patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153693

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.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
@@ -895,3 +895,10 @@
 #endif
 
 }
+
+#if 0
+constexpr bool BPand(BoolPair bp) {
+  return bp.first && bp.second;
+}
+static_assert(BPand(BoolPair{true, false}) == false, "");
+#endif
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -525,16 +525,27 @@
 
 template 
 bool ByteCodeExprGen::VisitInitListExpr(const InitListExpr *E) {
-  for (const Expr *Init : E->inits()) {
-if (DiscardResult) {
-  if (!this->discard(Init))
-return false;
-} else {
-  if (!this->visit(Init))
-return false;
-}
+  if (std::optional T = classify(E->getType())) {
+assert(E->getNumInits() == 1);
+return DiscardResult ? this->discard(E->inits()[0])
+ : this->visit(E->inits()[0]);
   }
-  return true;
+
+  if (std::optional LocalIndex = allocateLocal(E, false)) {
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+
+if (!this->visitInitializer(E))
+  return false;
+
+if (DiscardResult)
+  return this->emitPopPtr(E);
+return true;
+  }
+
+  // TODO: Array, complex, etc. types might appear here as well.
+
+  return false;
 }
 
 template 


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -895,3 +895,10 @@
 #endif
 
 }
+
+#if 0
+constexpr bool BPand(BoolPair bp) {
+  return bp.first && bp.second;
+}
+static_assert(BPand(BoolPair{true, false}) == false, "");
+#endif
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -525,16 +525,27 @@
 
 template 
 bool ByteCodeExprGen::VisitInitListExpr(const InitListExpr *E) {
-  for (const Expr *Init : E->inits()) {
-if (DiscardResult) {
-  if (!this->discard(Init))
-return false;
-} else {
-  if (!this->visit(Init))
-return false;
-}
+  if (std::optional T = classify(E->getType())) {
+assert(E->getNumInits() == 1);
+return DiscardResult ? this->discard(E->inits()[0])
+ : this->visit(E->inits()[0]);
   }
-  return true;
+
+  if (std::optional LocalIndex = allocateLocal(E, false)) {
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+
+if (!this->visitInitializer(E))
+  return false;
+
+if (DiscardResult)
+  return this->emitPopPtr(E);
+return true;
+  }
+
+  // TODO: Array, complex, etc. types might appear here as well.
+
+  return false;
 }
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-06-24 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

Does the code do the right FP checks for tuples?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

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


[PATCH] D153653: [clang][Interp] Make CXXTemporaryObjectExprs leave a value behind

2023-06-24 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 534174.

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

https://reviews.llvm.org/D153653

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.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
@@ -880,3 +880,18 @@
   }
 }
 
+namespace TemporaryObjectExpr {
+  struct F {
+int a;
+constexpr F() : a(12) {}
+  };
+  constexpr int foo(F f) {
+return 0;
+  }
+  /// FIXME: This should also work in C++14, but it needs suport for
+  ///   CXXConstructExpr. I think.
+#if __cplusplus > 201402L
+  static_assert(foo(F()) == 0, "");
+#endif
+
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1011,10 +1011,17 @@
 template 
 bool ByteCodeExprGen::VisitCXXTemporaryObjectExpr(
 const CXXTemporaryObjectExpr *E) {
-
   if (std::optional LocalIndex =
   allocateLocal(E, /*IsExtended=*/false)) {
-return this->visitLocalInitializer(E, *LocalIndex);
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+
+if (!this->visitInitializer(E))
+  return false;
+
+if (DiscardResult)
+  return this->emitPopPtr(E);
+return true;
   }
   return false;
 }


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -880,3 +880,18 @@
   }
 }
 
+namespace TemporaryObjectExpr {
+  struct F {
+int a;
+constexpr F() : a(12) {}
+  };
+  constexpr int foo(F f) {
+return 0;
+  }
+  /// FIXME: This should also work in C++14, but it needs suport for
+  ///   CXXConstructExpr. I think.
+#if __cplusplus > 201402L
+  static_assert(foo(F()) == 0, "");
+#endif
+
+}
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1011,10 +1011,17 @@
 template 
 bool ByteCodeExprGen::VisitCXXTemporaryObjectExpr(
 const CXXTemporaryObjectExpr *E) {
-
   if (std::optional LocalIndex =
   allocateLocal(E, /*IsExtended=*/false)) {
-return this->visitLocalInitializer(E, *LocalIndex);
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+
+if (!this->visitInitializer(E))
+  return false;
+
+if (DiscardResult)
+  return this->emitPopPtr(E);
+return true;
   }
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-06-24 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:4967
 
+void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  const TargetInfo  = Context.getTargetInfo();

What about the bool types? Is it sufficient to check Zve32x is enabled after 
all the other checks? The caller already checked for it being an RVV type so if 
we are in the function the type is RVV.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

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


[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-06-24 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 534172.
eopXD added a comment.

Add check for RVV types that require at least zve32x


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/riscv-types.c
  clang/test/Sema/riscv-vector-float16-check.c
  clang/test/Sema/riscv-vector-float32-check.c
  clang/test/Sema/riscv-vector-float64-check.c
  clang/test/Sema/riscv-vector-int64-check.c
  clang/test/Sema/riscv-vector-zve32x-check.c

Index: clang/test/Sema/riscv-vector-zve32x-check.c
===
--- /dev/null
+++ clang/test/Sema/riscv-vector-zve32x-check.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple riscv64 \
+// RUN:   -disable-O0-optnone -o - -fsyntax-only %s -verify 
+// REQUIRES: riscv-registered-target
+
+__rvv_int8m1_t foo8() { /* expected-error {{RISC-V type '__rvv_int8m1_t' requires the 'zve32x' extension}} */
+} /* expected-warning {{non-void function does not return a value}}*/
+
+void bar8(void) {
+  __rvv_int8m1_t i8m1; /* expected-error {{RISC-V type '__rvv_int8m1_t' requires the 'zve32x' extension}} */
+
+  (void)i8m1; /* expected-error {{RISC-V type '__rvv_int8m1_t' requires the 'zve32x' extension}} */
+}
+
+__rvv_int16m1_t foo16() { /* expected-error {{RISC-V type '__rvv_int16m1_t' requires the 'zve32x' extension}} */
+}
+
+void bar16(void) {
+  __rvv_int16m1_t i16m1; /* expected-error {{RISC-V type '__rvv_int16m1_t' requires the 'zve32x' extension}} */
+
+  (void)i16m1; /* expected-error {{RISC-V type '__rvv_int16m1_t' requires the 'zve32x' extension}} */
+}
+
+__rvv_int32m1_t foo32() { /* expected-error {{RISC-V type '__rvv_int32m1_t' requires the 'zve32x' extension}} */
+}
+
+void bar32(void) {
+  __rvv_int32m1_t i32m1; /* expected-error {{RISC-V type '__rvv_int32m1_t' requires the 'zve32x' extension}} */
+
+  (void)i32m1; /* expected-error {{RISC-V type '__rvv_int32m1_t' requires the 'zve32x' extension}} */
+}
Index: clang/test/Sema/riscv-vector-int64-check.c
===
--- clang/test/Sema/riscv-vector-int64-check.c
+++ clang/test/Sema/riscv-vector-int64-check.c
@@ -6,3 +6,9 @@
 
 vint64m1_t foo() { /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vint64m1_t i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+
+  (void)i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float64-check.c
===
--- clang/test/Sema/riscv-vector-float64-check.c
+++ clang/test/Sema/riscv-vector-float64-check.c
@@ -6,3 +6,9 @@
 
 vfloat64m1_t foo() { /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat64m1_t f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+
+  (void)f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float32-check.c
===
--- clang/test/Sema/riscv-vector-float32-check.c
+++ clang/test/Sema/riscv-vector-float32-check.c
@@ -6,3 +6,9 @@
 
 vfloat32m1_t foo() { /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat32m1_t f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+
+  (void)f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float16-check.c
===
--- clang/test/Sema/riscv-vector-float16-check.c
+++ clang/test/Sema/riscv-vector-float16-check.c
@@ -6,3 +6,9 @@
 
 vfloat16m1_t foo() { /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat16m1_t f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+
+  (void)f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} 

[PATCH] D153691: [Driver][ARM] Warn about -mabi= for assembler input

2023-06-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: michaelplatings, peter.smith, simon_tatham, 
nathanchance.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang Driver used to report a warning for assembler input when -mabi= is
specified and switched to an error after D152856 
.

GCC translates -mabi={apcs-gnu,atpcs} to gas -meabi=gnu and other -mabi= values
to -meabi=5. We don't support setting e_flags to any value other than
EF_ARM_EABI_VER5. For simplicity, just report a warning for -mabi= like before.

Close https://github.com/ClangBuiltLinux/linux/issues/1878


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153691

Files:
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/test/Driver/arm-abi.c


Index: clang/test/Driver/arm-abi.c
===
--- clang/test/Driver/arm-abi.c
+++ clang/test/Driver/arm-abi.c
@@ -61,3 +61,8 @@
 // CHECK-APCS-GNU: "-target-abi" "apcs-gnu"
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-AAPCS-LINUX: "-target-abi" "aapcs-linux"
+
+// RUN: %clang --target=arm---gnueabi -mabi=aapcs -x assembler %s -### -o 
/dev/null 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ASM %s
+
+// CHECK-ASM: warning: argument unused during compilation: '-mabi={{.*}}'
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -524,6 +524,10 @@
 }
   }
 }
+
+// Accept but warn.
+if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
+  A->ignoreTargetSpecific();
   }
 
   if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRURW)


Index: clang/test/Driver/arm-abi.c
===
--- clang/test/Driver/arm-abi.c
+++ clang/test/Driver/arm-abi.c
@@ -61,3 +61,8 @@
 // CHECK-APCS-GNU: "-target-abi" "apcs-gnu"
 // CHECK-AAPCS: "-target-abi" "aapcs"
 // CHECK-AAPCS-LINUX: "-target-abi" "aapcs-linux"
+
+// RUN: %clang --target=arm---gnueabi -mabi=aapcs -x assembler %s -### -o /dev/null 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-ASM %s
+
+// CHECK-ASM: warning: argument unused during compilation: '-mabi={{.*}}'
Index: clang/lib/Driver/ToolChains/Arch/ARM.cpp
===
--- clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -524,6 +524,10 @@
 }
   }
 }
+
+// Accept but warn.
+if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
+  A->ignoreTargetSpecific();
   }
 
   if (getReadTPMode(D, Args, Triple, ForAS) == ReadTPMode::TPIDRURW)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153359: [clang][Diagnostics] Fix distant source ranges in bad-conversion notes

2023-06-24 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet marked an inline comment as done.
hazohelet added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:10821
 
+// FIXME: No test case for this. Can we remove this block?
 if (FromQs.hasUnaligned() != ToQs.hasUnaligned()) {

cjdb wrote:
> Please don't commit until this is resolved (either tests added or it's 
> removed).
I opened another diff to remove this block: D153690


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

https://reviews.llvm.org/D153359

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


[PATCH] D153267: [clang][Diagnostics] Provide parameter source range to arity-mismatch notes

2023-06-24 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

In D153267#4445417 , @cjdb wrote:

> Thanks! This LGTM now. Do you need assistance with merging?

Thanks for the review! I have commit access now, so I'll be landing this myself.


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

https://reviews.llvm.org/D153267

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


[PATCH] D153690: [clang][Sema] Remove dead diagnostic for loss of __unaligned qualifier

2023-06-24 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet created this revision.
hazohelet added reviewers: aaron.ballman, cjdb, tbaeder, efriedma, rnk.
Herald added a project: All.
hazohelet requested review of this revision.
Herald added a project: clang.

D120936  has made the loss of `__unaligned` 
qualifier NOT a bad-conversion.
Because of this, the bad-conversion note about the loss of this qualifier does 
not take effect.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153690

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaOverload.cpp


Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10821,15 +10821,6 @@
   return;
 }
 
-if (FromQs.hasUnaligned() != ToQs.hasUnaligned()) {
-  S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_unaligned)
-  << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << 
FnDesc
-  << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy
-  << FromQs.hasUnaligned() << I + 1;
-  MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
-  return;
-}
-
 unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers();
 assert(CVR && "expected qualifiers mismatch");
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4696,9 +4696,6 @@
 "%select{const|restrict|const and restrict|volatile|const and volatile|"
 "volatile and restrict|const, volatile, and restrict}4 qualifier"
 "%select{||s||s|s|s}4">;
-def note_ovl_candidate_bad_unaligned : Note<
-"candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
-"%ordinal5 argument (%3) would lose __unaligned qualifier">;
 def note_ovl_candidate_bad_base_to_derived_conv : Note<
 "candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
 "cannot %select{convert from|convert from|bind}3 "


Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -10821,15 +10821,6 @@
   return;
 }
 
-if (FromQs.hasUnaligned() != ToQs.hasUnaligned()) {
-  S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_unaligned)
-  << (unsigned)FnKindPair.first << (unsigned)FnKindPair.second << FnDesc
-  << (FromExpr ? FromExpr->getSourceRange() : SourceRange()) << FromTy
-  << FromQs.hasUnaligned() << I + 1;
-  MaybeEmitInheritedConstructorNote(S, Cand->FoundDecl);
-  return;
-}
-
 unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers();
 assert(CVR && "expected qualifiers mismatch");
 
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4696,9 +4696,6 @@
 "%select{const|restrict|const and restrict|volatile|const and volatile|"
 "volatile and restrict|const, volatile, and restrict}4 qualifier"
 "%select{||s||s|s|s}4">;
-def note_ovl_candidate_bad_unaligned : Note<
-"candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
-"%ordinal5 argument (%3) would lose __unaligned qualifier">;
 def note_ovl_candidate_bad_base_to_derived_conv : Note<
 "candidate %sub{select_ovl_candidate_kind}0,1,2 not viable: "
 "cannot %select{convert from|convert from|bind}3 "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-06-24 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:4968
+void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  const TargetInfo  = Context.getTargetInfo();
+  if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) &&

eopXD wrote:
> craig.topper wrote:
> > Do we need to diagnose the use of any RVV type without at least zve32x?
> If users will be using RVV intrinsic types, they will need to include 
> , and the header is guarded by zve32x. So I think we don't 
> need the check for at least zve32x.
> 
> ```
> $ bin/clang -march=rv64g -emit-llvm -S -o - test.c
> In file included from test.c:1:
> /scratch/eopc/upstream-llvm-project2/build/lib/clang/17/include/riscv_vector.h:18:2:
>  error: "Vector intrinsics require the vector extension."
>18 | #error "Vector intrinsics require the vector extension."
>   |  ^
> 1 error generated.
> ```
The `__rvv` prefixed names are still available and do crash the backend if you 
use them without zve32x.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

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


[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-06-24 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:4968
+void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  const TargetInfo  = Context.getTargetInfo();
+  if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) &&

craig.topper wrote:
> Do we need to diagnose the use of any RVV type without at least zve32x?
If users will be using RVV intrinsic types, they will need to include 
, and the header is guarded by zve32x. So I think we don't need 
the check for at least zve32x.

```
$ bin/clang -march=rv64g -emit-llvm -S -o - test.c
In file included from test.c:1:
/scratch/eopc/upstream-llvm-project2/build/lib/clang/17/include/riscv_vector.h:18:2:
 error: "Vector intrinsics require the vector extension."
   18 | #error "Vector intrinsics require the vector extension."
  |  ^
1 error generated.
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

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


[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-06-24 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:4968
+void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  const TargetInfo  = Context.getTargetInfo();
+  if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) &&

Do we need to diagnose the use of any RVV type without at least zve32x?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

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


[PATCH] D153298: [clang-tidy] Extend bugprone-exception-escape diagnostics

2023-06-24 Thread Piotr Zegar via Phabricator via cfe-commits
PiotrZSL updated this revision to Diff 534169.
PiotrZSL added a comment.

Use std::map


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153298

Files:
  clang-tools-extra/clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.cpp
  clang-tools-extra/clang-tidy/utils/ExceptionAnalyzer.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-rethrow.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape-throw.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/exception-escape.cpp
@@ -9,6 +9,7 @@
 struct throwing_destructor {
   ~throwing_destructor() {
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function '~throwing_destructor' which should not throw exceptions
+// CHECK-MESSAGES: :[[@LINE+1]]:5: note: may throw 'int' here
 throw 1;
   }
 };
@@ -16,6 +17,7 @@
 struct throwing_move_constructor {
   throwing_move_constructor(throwing_move_constructor&&) {
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: an exception may be thrown in function 'throwing_move_constructor' which should not throw exceptions
+// CHECK-MESSAGES: :[[@LINE+1]]:5: note: may throw 'int' here
 throw 1;
   }
 };
@@ -23,12 +25,14 @@
 struct throwing_move_assignment {
   throwing_move_assignment& operator=(throwing_move_assignment&&) {
 // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: an exception may be thrown in function 'operator=' which should not throw exceptions
+// CHECK-MESSAGES: :[[@LINE+1]]:5: note: may throw 'int' here
 throw 1;
   }
 };
 
 void throwing_noexcept() noexcept {
-// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_noexcept' which should not throw exceptions
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throwing_noexcept' which should not throw exceptions
+  // CHECK-MESSAGES: :[[@LINE+1]]:3: note: may throw 'int' here
   throw 1;
 }
 
@@ -42,6 +46,7 @@
 
 void throw_and_catch_some(int n) noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_catch_some' which should not throw exceptions
+  // CHECK-MESSAGES: :[[@LINE+3]]:5: note: may throw 'double' here
   try {
 if (n) throw 1;
 throw 1.1;
@@ -70,6 +75,7 @@
 
 void throw_and_rethrow() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_and_rethrow' which should not throw exceptions
+  // CHECK-MESSAGES: :[[@LINE+2]]:5: note: may throw 'int' here
   try {
 throw 1;
   } catch(int &) {
@@ -79,6 +85,7 @@
 
 void throw_catch_throw() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_throw' which should not throw exceptions
+  // CHECK-MESSAGES: :[[@LINE+4]]:5: note: may throw 'int' here
   try {
 throw 1;
   } catch(int &) {
@@ -88,6 +95,7 @@
 
 void throw_catch_rethrow_the_rest(int n) noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_rethrow_the_rest' which should not throw exceptions
+  // CHECK-MESSAGES: :[[@LINE+3]]:5: note: may throw 'double' here
   try {
 if (n) throw 1;
 throw 1.1;
@@ -120,6 +128,7 @@
 
 void throw_catch_multi_ptr_1() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_catch_multi_ptr_1' which should not throw exceptions
+  // CHECK-MESSAGES: :[[@LINE+3]]:5: note: may throw 'char **' here
   try {
 char **p = 0;
 throw p;
@@ -152,7 +161,7 @@
 }
 
 // FIXME: In this case 'a' is convertible to the handler and should be caught
-// but in reality it's thrown. Note that clang doesn't report a warning for 
+// but in reality it's thrown. Note that clang doesn't report a warning for
 // this either.
 void throw_catch_multi_ptr_5() noexcept {
   try {
@@ -165,6 +174,7 @@
 
 void throw_c_catch_pointer() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_c_catch_pointer' which should not throw exceptions
+  // CHECK-MESSAGES: :[[@LINE+4]]:5: note: may throw 'const int *' here
   try {
 int a = 1;
 const int *p = 
@@ -174,6 +184,7 @@
 
 void throw_c_catch_pointer_v() noexcept {
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: an exception may be thrown in function 'throw_c_catch_pointer_v' which should not throw exceptions
+  // CHECK-MESSAGES: :[[@LINE+4]]:5: note: may throw 'const int *' here
   try {
 int a = 1;
 const int *p = 
@@ 

[PATCH] D153510: [Clang][RISCV] Check type support for local variable declaration of RVV type

2023-06-24 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD updated this revision to Diff 534167.
eopXD marked an inline comment as done.
eopXD added a comment.

Add a blank line to separate from SVE.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153510

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/riscv-types.c
  clang/test/Sema/riscv-vector-float16-check.c
  clang/test/Sema/riscv-vector-float32-check.c
  clang/test/Sema/riscv-vector-float64-check.c
  clang/test/Sema/riscv-vector-int64-check.c

Index: clang/test/Sema/riscv-vector-int64-check.c
===
--- clang/test/Sema/riscv-vector-int64-check.c
+++ clang/test/Sema/riscv-vector-int64-check.c
@@ -6,3 +6,9 @@
 
 vint64m1_t foo() { /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vint64m1_t i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+
+  (void)i64m1; /* expected-error {{RISC-V type 'vint64m1_t' (aka '__rvv_int64m1_t') requires the 'zve64x' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float64-check.c
===
--- clang/test/Sema/riscv-vector-float64-check.c
+++ clang/test/Sema/riscv-vector-float64-check.c
@@ -6,3 +6,9 @@
 
 vfloat64m1_t foo() { /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat64m1_t f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+
+  (void)f64m1; /* expected-error {{RISC-V type 'vfloat64m1_t' (aka '__rvv_float64m1_t') requires the 'zve64d' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float32-check.c
===
--- clang/test/Sema/riscv-vector-float32-check.c
+++ clang/test/Sema/riscv-vector-float32-check.c
@@ -6,3 +6,9 @@
 
 vfloat32m1_t foo() { /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat32m1_t f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+
+  (void)f32m1; /* expected-error {{RISC-V type 'vfloat32m1_t' (aka '__rvv_float32m1_t') requires the 'zve32f' extension}} */
+}
Index: clang/test/Sema/riscv-vector-float16-check.c
===
--- clang/test/Sema/riscv-vector-float16-check.c
+++ clang/test/Sema/riscv-vector-float16-check.c
@@ -6,3 +6,9 @@
 
 vfloat16m1_t foo() { /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
 } /* expected-warning {{non-void function does not return a value}}*/
+
+void bar(void) {
+  vfloat16m1_t f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+
+  (void)f16m1; /* expected-error {{RISC-V type 'vfloat16m1_t' (aka '__rvv_float16m1_t') requires the 'zvfh' extension}} */
+}
Index: clang/test/Sema/riscv-types.c
===
--- clang/test/Sema/riscv-types.c
+++ clang/test/Sema/riscv-types.c
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple riscv64 -target-feature +v -ast-print %s \
-// RUN:| FileCheck %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v \
+// RUN: -target-feature +experimental-zvfh -ast-print %s | FileCheck %s
 
 void bar(void) {
   // CHECK: __rvv_int64m1_t x0;
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -8777,6 +8777,9 @@
   return;
 }
   }
+
+  if (T->isRVVType())
+checkRVVTypeSupport(T, NewVD->getLocation(), cast(CurContext));
 }
 
 /// Perform semantic checking on a newly-created variable
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4964,6 +4964,22 @@
   return false;
 }
 
+void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
+  const TargetInfo  = Context.getTargetInfo();
+  if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) &&
+  !TI.hasFeature("zve64x"))
+Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
+  if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ true) &&
+  !TI.hasFeature("experimental-zvfh"))
+Diag(Loc, 

[PATCH] D153689: [clang][Interp] Handle CXXConstructExprs

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

Fixes a so far broken Lambda test case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153689

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/lambda.cpp


Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -159,10 +159,6 @@
   }
   static_assert(sv4(12) == 12);
 
-
-
-  /// FIXME: This is broken for lambda-unrelated reasons.
-#if 0
   constexpr int sv5(int i) {
 struct F { int a; float f; };
 auto l = [](int m, F f) { return m; };
@@ -170,7 +166,6 @@
 return fp(i, F{12, 14.0});
   }
   static_assert(sv5(12) == 12);
-#endif
 
   constexpr int sv6(int i) {
 struct F { int a;
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -99,6 +99,7 @@
   bool VisitPredefinedExpr(const PredefinedExpr *E);
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
+  bool VisitCXXConstructExpr(const CXXConstructExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1105,6 +1105,24 @@
   return this->emitInvalidCast(CastKind::Reinterpret, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXConstructExpr(
+const CXXConstructExpr *E) {
+  if (std::optional GI = allocateLocal(E, /*IsExtended=*/false)) {
+if (!this->emitGetPtrLocal(*GI, E))
+  return false;
+
+if (!this->visitRecordInitializer(E))
+  return false;
+
+if (DiscardResult)
+  return this->emitPopPtr(E);
+return true;
+  }
+
+  return false;
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;


Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -159,10 +159,6 @@
   }
   static_assert(sv4(12) == 12);
 
-
-
-  /// FIXME: This is broken for lambda-unrelated reasons.
-#if 0
   constexpr int sv5(int i) {
 struct F { int a; float f; };
 auto l = [](int m, F f) { return m; };
@@ -170,7 +166,6 @@
 return fp(i, F{12, 14.0});
   }
   static_assert(sv5(12) == 12);
-#endif
 
   constexpr int sv6(int i) {
 struct F { int a;
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -99,6 +99,7 @@
   bool VisitPredefinedExpr(const PredefinedExpr *E);
   bool VisitCXXThrowExpr(const CXXThrowExpr *E);
   bool VisitCXXReinterpretCastExpr(const CXXReinterpretCastExpr *E);
+  bool VisitCXXConstructExpr(const CXXConstructExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1105,6 +1105,24 @@
   return this->emitInvalidCast(CastKind::Reinterpret, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXConstructExpr(
+const CXXConstructExpr *E) {
+  if (std::optional GI = allocateLocal(E, /*IsExtended=*/false)) {
+if (!this->emitGetPtrLocal(*GI, E))
+  return false;
+
+if (!this->visitRecordInitializer(E))
+  return false;
+
+if (DiscardResult)
+  return this->emitPopPtr(E);
+return true;
+  }
+
+  return false;
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) {
   if (E->containsErrors())
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits