[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/72213
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/72213
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/72213
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Utkarsh Saxena via cfe-commits
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/72213
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Handle Flang in same manner between Gnu and *BSD/Solaris ToolChain (PR #70429)

2023-11-14 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay approved this pull request.


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


[clang] [Driver] Default LoongArch to -fno-direct-access-external-data for non-PIC (PR #72221)

2023-11-14 Thread via cfe-commits
https://github.com/heiher approved this pull request.

LGTM. Thank you.

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


[clang] [clang][LoongArch] Don't imply -fdirect-access-external-data for non-PIC (PR #71887)

2023-11-14 Thread via cfe-commits
https://github.com/heiher closed https://github.com/llvm/llvm-project/pull/71887
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [llvm] [clang] [llvm-objcopy] Check for missing argument values (PR #70710)

2023-11-14 Thread James Henderson via cfe-commits
https://github.com/jh7370 approved this pull request.

Are there any options that expect 2+ values (i.e. something that would give a 
different response to "expected 1 value(s)"? If so, it might be worth switching 
one of the cases for that one, just for additional bonus coverage without 
additional test complexity.

Otherwise, LGTM.

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


[clang] [Driver] Make use of AddFilePathLibArgs() on NetBSD. (PR #71371)

2023-11-14 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/71371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Make use of AddFilePathLibArgs() on NetBSD. (PR #71371)

2023-11-14 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay approved this pull request.


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


[clang] [Driver] Make use of AddFilePathLibArgs() on NetBSD. (PR #71371)

2023-11-14 Thread Fangrui Song via cfe-commits

@@ -461,3 +461,8 @@
 // DRIVER-PASS-INCLUDES:  "-cc1" {{.*}}"-resource-dir" "[[RESOURCE:[^"]+]]"
 // DRIVER-PASS-INCLUDES-SAME: "-internal-isystem" 
"[[RESOURCE]]{{/|}}include"
 // DRIVER-PASS-INCLUDES-SAME: {{^}} "-internal-externc-isystem" 
"{{.*}}/usr/include"
+
+// Check that the driver passes the system library path.

MaskRay wrote:

This file is very long and can be better organized. I think you can reuse an 
existing RUN line.

If cmake `DEFAULT_SYSROOT` is set, there may not be a  `-L/usr/lib`. You need 
to set `--sysroot=` to test a usr/lib directory

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


[clang] [Driver] Make use of AddFilePathLibArgs() on NetBSD. (PR #71371)

2023-11-14 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/71371
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 47eeee2 - [Driver] Default LoongArch to -fno-direct-access-external-data for non-PIC (#72221)

2023-11-14 Thread via cfe-commits
Author: Fangrui Song
Date: 2023-11-14T00:43:40-08:00
New Revision: 47297775347cbdb7624d6a766c2a3eec4a59

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

LOG: [Driver] Default LoongArch to -fno-direct-access-external-data for non-PIC 
(#72221)

For -fno-pic, if an extern variable is defined in a DSO, a copy
relocation will be needed. However, loongarch*-linux does not and will
not support copy relocations.

Change Driver to default to -fno-direct-access-external-data for
LoongArch && non-PIC.
Keep Frontend conditions unchanged (-fdirect-access-external-data ||
-fno-direct-access-external-data && PIC>0 => direct access).

Fix #71645

Added: 


Modified: 
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/fdirect-access-external-data.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3b98c7ae6e6ec66..b462f5a44057d94 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5663,10 +5663,15 @@ void Clang::ConstructJob(Compilation &C, const 
JobAction &JA,
   // defaults to -fno-direct-access-external-data. Pass the option if 
diff erent
   // from the default.
   if (Arg *A = Args.getLastArg(options::OPT_fdirect_access_external_data,
-   options::OPT_fno_direct_access_external_data))
+   options::OPT_fno_direct_access_external_data)) {
 if (A->getOption().matches(options::OPT_fdirect_access_external_data) !=
 (PICLevel == 0))
   A->render(Args, CmdArgs);
+  } else if (PICLevel == 0 && Triple.isLoongArch()) {
+// Some targets default to -fno-direct-access-external-data even for
+// -fno-pic.
+CmdArgs.push_back("-fno-direct-access-external-data");
+  }
 
   if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) {
 CmdArgs.push_back("-fno-plt");

diff  --git a/clang/test/Driver/fdirect-access-external-data.c 
b/clang/test/Driver/fdirect-access-external-data.c
index f132b1b088af35d..a6da776e6977742 100644
--- a/clang/test/Driver/fdirect-access-external-data.c
+++ b/clang/test/Driver/fdirect-access-external-data.c
@@ -9,6 +9,12 @@
 // RUN: %clang -### -c -target aarch64 %s -fpic 2>&1 | FileCheck %s 
--check-prefix=DEFAULT
 // RUN: %clang -### -c -target aarch64 %s -fpic -fdirect-access-external-data 
2>&1 | FileCheck %s --check-prefix=DIRECT
 
+/// loongarch* targets default to -fno-direct-access-external-data even for 
-fno-pic.
+// RUN: %clang -### -c --target=loongarch64 -fno-pic %s 2>&1 | FileCheck %s 
--check-prefix=INDIRECT
+// RUN: %clang -### -c --target=loongarch64 -fpie %s 2>&1 | FileCheck %s 
--check-prefix=DEFAULT
+// RUN: %clang -### -c --target=loongarch32 -fno-pic 
-fdirect-access-external-data %s 2>&1 | FileCheck %s --check-prefix=DEFAULT
+// RUN: %clang -### -c --target=loongarch32 -fpie 
-fdirect-access-external-data %s 2>&1 | FileCheck %s --check-prefix=DIRECT
+
 // DEFAULT-NOT: direct-access-external-data"
 // DIRECT:  "-fdirect-access-external-data"
 // INDIRECT:"-fno-direct-access-external-data"



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


[clang] [Driver] Default LoongArch to -fno-direct-access-external-data for non-PIC (PR #72221)

2023-11-14 Thread Fangrui Song via cfe-commits
https://github.com/MaskRay closed 
https://github.com/llvm/llvm-project/pull/72221
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Sema] Check nullness of captured type before use (PR #72230)

2023-11-14 Thread Qiu Chaofan via cfe-commits
https://github.com/ecnelises created 
https://github.com/llvm/llvm-project/pull/72230

Fixes #72198 

>From 0b74141dec486989f75f4c361e8b950b869f7a1e Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Tue, 14 Nov 2023 16:20:42 +0800
Subject: [PATCH] [Sema] Check nullness of captured type before use

---
 clang/lib/Sema/SemaExpr.cpp   | 2 ++
 clang/test/SemaCXX/lambda-invalid-capture.cpp | 6 ++
 2 files changed, 8 insertions(+)

diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5b0c4439fd1710c..cb7383ea8790f67 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19773,6 +19773,8 @@ bool Sema::tryCaptureVariable(
   // declcontext can either capture the variable or have already captured
   // the variable.
   CaptureType = Var->getType();
+  if (CaptureType.isNull())
+return true;
   DeclRefType = CaptureType.getNonReferenceType();
   bool Nested = false;
   bool Explicit = (Kind != TryCapture_Implicit);
diff --git a/clang/test/SemaCXX/lambda-invalid-capture.cpp 
b/clang/test/SemaCXX/lambda-invalid-capture.cpp
index 236753871d7018b..b77a844cfbbda50 100644
--- a/clang/test/SemaCXX/lambda-invalid-capture.cpp
+++ b/clang/test/SemaCXX/lambda-invalid-capture.cpp
@@ -23,3 +23,9 @@ int pr43080(int i) { // expected-note {{declared here}}
   i; // expected-error {{variable 'i' cannot be implicitly captured in a 
lambda with no capture-default specified}}
   }();
 }
+
+void pr72198() {
+  int [_, b] = {0, 0}; // expected-error{{decomposition declaration cannot be 
declared with type 'int'; declared type must be 'auto' or reference to 'auto'}} 
\
+  expected-error{{excess elements in scalar 
initializer}}
+  [b]{}; // expected-warning{{expression result unused}}
+}

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


[clang] [Sema] Check nullness of captured type before use (PR #72230)

2023-11-14 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Qiu Chaofan (ecnelises)


Changes

Fixes #72198 

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


2 Files Affected:

- (modified) clang/lib/Sema/SemaExpr.cpp (+2) 
- (modified) clang/test/SemaCXX/lambda-invalid-capture.cpp (+6) 


``diff
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5b0c4439fd1710c..cb7383ea8790f67 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -19773,6 +19773,8 @@ bool Sema::tryCaptureVariable(
   // declcontext can either capture the variable or have already captured
   // the variable.
   CaptureType = Var->getType();
+  if (CaptureType.isNull())
+return true;
   DeclRefType = CaptureType.getNonReferenceType();
   bool Nested = false;
   bool Explicit = (Kind != TryCapture_Implicit);
diff --git a/clang/test/SemaCXX/lambda-invalid-capture.cpp 
b/clang/test/SemaCXX/lambda-invalid-capture.cpp
index 236753871d7018b..b77a844cfbbda50 100644
--- a/clang/test/SemaCXX/lambda-invalid-capture.cpp
+++ b/clang/test/SemaCXX/lambda-invalid-capture.cpp
@@ -23,3 +23,9 @@ int pr43080(int i) { // expected-note {{declared here}}
   i; // expected-error {{variable 'i' cannot be implicitly captured in a 
lambda with no capture-default specified}}
   }();
 }
+
+void pr72198() {
+  int [_, b] = {0, 0}; // expected-error{{decomposition declaration cannot be 
declared with type 'int'; declared type must be 'auto' or reference to 'auto'}} 
\
+  expected-error{{excess elements in scalar 
initializer}}
+  [b]{}; // expected-warning{{expression result unused}}
+}

``




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


[clang] [Sema] Check nullness of captured type before use (PR #72230)

2023-11-14 Thread Younan Zhang via cfe-commits
zyn0217 wrote:

Could you please explain why the `CaptureType` might be null at the time when 
exercising `tryCaptureVariable`? I'm worried that doing so would hide a more 
significant issue.

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


[compiler-rt] [libcxx] [clang-tools-extra] [llvm] [flang] [clang] [Clang][Sema] Fix qualifier restriction of overriden methods (PR #71696)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits
https://github.com/Fznamznon commented:

LGTM, but someone else must approve. I added more folks for visibility.

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


[clang] [Driver] Add ExclusiveGroup feature to multilib.yaml. (PR #69447)

2023-11-14 Thread Simon Tatham via cfe-commits
statham-arm wrote:

> my only concern is to make sure we don't unintentionally make it harder to 
> integrate potential future extensions such as the mutually dependent groups.

Hmmm. So if you had both ME and MD groups, you might also need a _group_ to be 
able to be a member of another group? That way you could specify hierarchies 
such as "must have all of: A, B, and exactly one of C,D" (a MD group one of 
whose members is a ME group), or "must have at most one of: (all of A,B,C) or 
(all of U,V,W)" (a ME group containing MD groups).

I suppose that makes sense, and the only change it needs to your structure is 
that maybe later a group record might also need to have a `Group:` or `Parent:` 
header. But there's no need to put that part in now, only to make sure there's 
room to add it in future if needed.

Would you accept `Type: Exclusive` instead of `Exclusive: True`? It seems more 
plausible to me that there might be three kinds of group that _can't_ go 
together than three group-type flags that you can have in any combination.

> although that may not necessarily be a bad thing since you could also warn if 
> someone accidentally tries to use a group that wasn't previously defined 
> (e.g. when making a typo).

That is true.

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


[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

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



@@ -1288,11 +1291,33 @@ void TextDiagnostic::emitSnippet(StringRef SourceLine,
 
   // Print the source line one character at a time.
   bool PrintReversed = false;
+  bool HighlightingEnabled = DiagOpts->ShowColors;
   size_t I = 0;
   while (I < SourceLine.size()) {
 auto [Str, WasPrintable] =
 printableTextForNextCharacter(SourceLine, &I, DiagOpts->TabStop);
 
+// Just stop highlighting anything for this line if we found a 
non-printable
+// character.

tbaederr wrote:

>From some local testing, seems like this just works.

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


[clang] 41fe5c9 - [clang][analyzer] Improve StdLibraryFunctionsChecker 'readlink' modeling. (#71373)

2023-11-14 Thread via cfe-commits
Author: Balázs Kéri
Date: 2023-11-14T10:58:05+01:00
New Revision: 41fe5c9a08f585a548ccf917804d67c79abcd3c3

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

LOG: [clang][analyzer] Improve StdLibraryFunctionsChecker 'readlink' modeling. 
(#71373)

The functions 'readlink' and 'readlinkat' do return 0 only if the
'bufsize' argument is 0.

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
clang/test/Analysis/std-c-library-functions-POSIX.c
clang/test/Analysis/std-c-library-functions-path-notes.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 13bb9cef5e490ed..54a41b8bd7843dd 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2865,9 +2865,14 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 Signature(ArgTypes{ConstCharPtrRestrictTy, CharPtrRestrictTy, SizeTy},
   RetType{Ssize_tTy}),
 Summary(NoEvalCall)
-.Case({ReturnValueCondition(LessThanOrEq, ArgNo(2)),
-   ReturnValueCondition(WithinRange, Range(0, Ssize_tMax))},
+.Case({ArgumentCondition(2, WithinRange, Range(1, IntMax)),
+   ReturnValueCondition(LessThanOrEq, ArgNo(2)),
+   ReturnValueCondition(WithinRange, Range(1, Ssize_tMax))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ArgumentCondition(2, WithinRange, SingleValue(0)),
+   ReturnValueCondition(WithinRange, SingleValue(0))},
+  ErrnoMustNotBeChecked,
+  "Assuming that argument 'bufsize' is 0")
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(NotNull(ArgNo(0)))
 .ArgConstraint(NotNull(ArgNo(1)))
@@ -2884,9 +2889,14 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 ArgTypes{IntTy, ConstCharPtrRestrictTy, CharPtrRestrictTy, SizeTy},
 RetType{Ssize_tTy}),
 Summary(NoEvalCall)
-.Case({ReturnValueCondition(LessThanOrEq, ArgNo(3)),
-   ReturnValueCondition(WithinRange, Range(0, Ssize_tMax))},
+.Case({ArgumentCondition(3, WithinRange, Range(1, IntMax)),
+   ReturnValueCondition(LessThanOrEq, ArgNo(3)),
+   ReturnValueCondition(WithinRange, Range(1, Ssize_tMax))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
+.Case({ArgumentCondition(3, WithinRange, SingleValue(0)),
+   ReturnValueCondition(WithinRange, SingleValue(0))},
+  ErrnoMustNotBeChecked,
+  "Assuming that argument 'bufsize' is 0")
 .Case(ReturnsMinusOne, ErrnoNEZeroIrrelevant, GenericFailureMsg)
 .ArgConstraint(ValidFileDescriptorOrAtFdcwd(ArgNo(0)))
 .ArgConstraint(NotNull(ArgNo(1)))

diff  --git a/clang/test/Analysis/std-c-library-functions-POSIX.c 
b/clang/test/Analysis/std-c-library-functions-POSIX.c
index 84ce0f21e569fb5..daa4d904c3ac5ed 100644
--- a/clang/test/Analysis/std-c-library-functions-POSIX.c
+++ b/clang/test/Analysis/std-c-library-functions-POSIX.c
@@ -205,3 +205,23 @@ void test_sendmsg(int sockfd, const struct msghdr *msg, 
int flags) {
   ssize_t Ret = sendmsg(sockfd, msg, flags);
   clang_analyzer_eval(Ret != 0); // expected-warning{{TRUE}}
 }
+
+void test_readlink_bufsize_zero(char *Buf, size_t Bufsize) {
+  ssize_t Ret = readlink("path", Buf, Bufsize);
+  if (Ret == 0)
+clang_analyzer_eval(Bufsize == 0); // expected-warning{{TRUE}}
+  else if (Ret > 0)
+clang_analyzer_eval(Bufsize == 0); // expected-warning{{FALSE}}
+  else
+clang_analyzer_eval(Bufsize == 0); // expected-warning{{UNKNOWN}}
+}
+
+void test_readlinkat_bufsize_zero(int fd, char *Buf, size_t Bufsize) {
+  ssize_t Ret = readlinkat(fd, "path", Buf, Bufsize);
+  if (Ret == 0)
+clang_analyzer_eval(Bufsize == 0); // expected-warning{{TRUE}}
+  else if (Ret > 0)
+clang_analyzer_eval(Bufsize == 0); // expected-warning{{FALSE}}
+  else
+clang_analyzer_eval(Bufsize == 0); // expected-warning{{UNKNOWN}}
+}

diff  --git a/clang/test/Analysis/std-c-library-functions-path-notes.c 
b/clang/test/Analysis/std-c-library-functions-path-notes.c
index d0957483c1391ad..4df00fe1e60646f 100644
--- a/clang/test/Analysis/std-c-library-functions-path-notes.c
+++ b/clang/test/Analysis/std-c-library-functions-path-notes.c
@@ -80,3 +80,12 @@ int test_fileno_arg_note(FILE *f1) {
   // expected-note{{The 1st argument to 'dup' is < 0 but should be >= 0}} \
   // expected-note{{Assuming that 'fileno' f

[clang] [clang][analyzer] Improve StdLibraryFunctionsChecker 'readlink' modeling. (PR #71373)

2023-11-14 Thread Balázs Kéri via cfe-commits
https://github.com/balazske closed 
https://github.com/llvm/llvm-project/pull/71373
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-14 Thread Michael Buch via cfe-commits
https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/72234

This patch adds the LLVM-side infrastructure to implement DWARFv5 issue 
161118.1: "DW_TAG for C++ static data members".

The clang-side of this patch will simply construct the DIDerivedType with a 
different DW_TAG.

>From af4a49c1f468705f2f7226e4244936363c41155e Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Mon, 6 Nov 2023 11:52:47 +
Subject: [PATCH] [llvm][DebugInfo] DWARFv5: static data members declarations
 are DW_TAG_variable

This patch adds the LLVM-side infrastructure to implement
DWARFv5 issue 161118.1: "DW_TAG for C++ static data members".

The clang-side of this patch will simply construct the DIDerivedType
with a different DW_TAG.
---
 clang/lib/CodeGen/CGDebugInfo.cpp |   3 +-
 llvm/include/llvm-c/DebugInfo.h   |   6 +-
 llvm/include/llvm/IR/DIBuilder.h  |   3 +-
 llvm/lib/IR/DIBuilder.cpp |   9 +-
 llvm/lib/IR/DebugInfo.cpp |  12 +-
 llvm/lib/IR/DebugInfoMetadata.cpp |   4 +-
 llvm/lib/IR/Verifier.cpp  |   1 +
 .../dwarf5-debug-info-static-member.ll| 109 ++
 8 files changed, 129 insertions(+), 18 deletions(-)
 create mode 100644 
llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 04ca02cfe858579..b8acef67dee4c7c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1681,7 +1681,8 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
+  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr,
+  DW_TAG_member, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 5924294708cc354..61659d514b520e5 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -785,14 +785,14 @@ LLVMMetadataRef LLVMDIBuilderCreateMemberType(
  * \param Type Type of the static member.
  * \param FlagsFlags to encode member attribute, e.g. private.
  * \param ConstantVal  Const initializer of the member.
+ * \param Tag  DWARF tag of the static member.
  * \param AlignInBits  Member alignment.
  */
-LLVMMetadataRef
-LLVMDIBuilderCreateStaticMemberType(
+LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(
 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
-uint32_t AlignInBits);
+unsigned Tag, uint32_t AlignInBits);
 
 /**
  * Create debugging information entry for a pointer to member.
diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h
index ecd6dd7b0a4f822..2be133e85e8c1e4 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -376,11 +376,12 @@ namespace llvm {
 /// \param Ty Type of the static member.
 /// \param Flags  Flags to encode member attribute, e.g. private.
 /// \param ValConst initializer of the member.
+/// \param TagDWARF tag of the static member.
 /// \param AlignInBits  Member alignment.
 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
   DIFile *File, unsigned LineNo,
   DIType *Ty, DINode::DIFlags Flags,
-  Constant *Val,
+  Constant *Val, unsigned Tag,
   uint32_t AlignInBits = 0);
 
 /// Create debugging information entry for Objective-C
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 1ce8c17f8a880f6..58a7e07d9b58d86 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -405,12 +405,11 @@ DIDerivedType *
 DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File,
   unsigned LineNumber, DIType *Ty,
   DINode::DIFlags Flags, llvm::Constant *Val,
-  uint32_t AlignInBits) {
+  unsigned Tag, uint32_t AlignInBits) {
   Flags |= DINode::FlagStaticMember;
-  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
-LineNumber, getNonCompileUnitScope(Scope), Ty

[clang] [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72235)

2023-11-14 Thread Michael Buch via cfe-commits
https://github.com/Michael137 created 
https://github.com/llvm/llvm-project/pull/72235

This patch implements the DWARFv5 issue
161118.1: "DW_TAG for C++ static data members".

This will simplify LLDB's handling of static data
members greatly in the long term since we no longer need to differentiate 
non-static from static data
member declarations using non-portable heuristics.

>From c0db61f318f50a1cf219c69af9c6b624b05c9da1 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Mon, 13 Nov 2023 09:48:39 +
Subject: [PATCH] [clang][DebugInfo] DWARFv5: static data members declarations
 are DW_TAG_variable

This patch implements the DWARFv5 issue
161118.1: "DW_TAG for C++ static data members".

This will simplify LLDB's handling of static data
members greatly in the long term since we no longer
need to differentiate non-static from static data
member declarations using non-portable heuristics.
---
 clang/lib/CodeGen/CGDebugInfo.cpp |  8 +++--
 .../debug-info-static-inline-member.cpp   |  4 +--
 .../CodeGenCXX/debug-info-static-member.cpp   | 36 ---
 3 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 04ca02cfe858579..f3de91d4a39ebee 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1679,9 +1679,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   StringRef VName = Var->getName();
 
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
+  auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
+ ? llvm::dwarf::DW_TAG_variable
+ : llvm::dwarf::DW_TAG_member;
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
-  llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
+  llvm::DIDerivedType *GV =
+  DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy,
+  Flags, /* Val */ nullptr, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index bfb7ad6b80fabf3..f2d4d9408a8297a 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -1,5 +1,5 @@
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -debug-info-kind=limited 
%s -emit-llvm -S -o - | FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=limited %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
 
 enum class Enum : int {
   VAL = -1
diff --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-member.cpp
index 578995801c6400b..a2d25e98ed1cb62 100644
--- a/clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,7 +1,8 @@
-// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-windows-msvc -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++98 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-5 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF5 %s
+// RUN: %clangxx -target x86_64-windows-msvc -g -gdwarf-4 %s -emit-llvm -S -o 
- | FileCheck --check-prefixes=CHECK,DWARF4 %s
 // PR14471
 
 // CHECK: @{{.*}}a{{.*}} = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
@@ -39,17 +40,20 @@ class C
 //
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}})
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"anon_static_decl_struct"
-// CHE

[llvm] [clang] [llvm][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72234)

2023-11-14 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Michael Buch (Michael137)


Changes

This patch adds the LLVM-side infrastructure to implement DWARFv5 issue 
161118.1: "DW_TAG for C++ static data members".

The clang-side of this patch will simply construct the DIDerivedType with a 
different DW_TAG.

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


8 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+2-1) 
- (modified) llvm/include/llvm-c/DebugInfo.h (+3-3) 
- (modified) llvm/include/llvm/IR/DIBuilder.h (+2-1) 
- (modified) llvm/lib/IR/DIBuilder.cpp (+4-5) 
- (modified) llvm/lib/IR/DebugInfo.cpp (+5-7) 
- (modified) llvm/lib/IR/DebugInfoMetadata.cpp (+3-1) 
- (modified) llvm/lib/IR/Verifier.cpp (+1) 
- (added) llvm/test/DebugInfo/Generic/dwarf5-debug-info-static-member.ll (+109) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 04ca02cfe858579..b8acef67dee4c7c 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1681,7 +1681,8 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
+  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr,
+  DW_TAG_member, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
diff --git a/llvm/include/llvm-c/DebugInfo.h b/llvm/include/llvm-c/DebugInfo.h
index 5924294708cc354..61659d514b520e5 100644
--- a/llvm/include/llvm-c/DebugInfo.h
+++ b/llvm/include/llvm-c/DebugInfo.h
@@ -785,14 +785,14 @@ LLVMMetadataRef LLVMDIBuilderCreateMemberType(
  * \param Type Type of the static member.
  * \param FlagsFlags to encode member attribute, e.g. private.
  * \param ConstantVal  Const initializer of the member.
+ * \param Tag  DWARF tag of the static member.
  * \param AlignInBits  Member alignment.
  */
-LLVMMetadataRef
-LLVMDIBuilderCreateStaticMemberType(
+LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(
 LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
 size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
 LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
-uint32_t AlignInBits);
+unsigned Tag, uint32_t AlignInBits);
 
 /**
  * Create debugging information entry for a pointer to member.
diff --git a/llvm/include/llvm/IR/DIBuilder.h b/llvm/include/llvm/IR/DIBuilder.h
index ecd6dd7b0a4f822..2be133e85e8c1e4 100644
--- a/llvm/include/llvm/IR/DIBuilder.h
+++ b/llvm/include/llvm/IR/DIBuilder.h
@@ -376,11 +376,12 @@ namespace llvm {
 /// \param Ty Type of the static member.
 /// \param Flags  Flags to encode member attribute, e.g. private.
 /// \param ValConst initializer of the member.
+/// \param TagDWARF tag of the static member.
 /// \param AlignInBits  Member alignment.
 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
   DIFile *File, unsigned LineNo,
   DIType *Ty, DINode::DIFlags Flags,
-  Constant *Val,
+  Constant *Val, unsigned Tag,
   uint32_t AlignInBits = 0);
 
 /// Create debugging information entry for Objective-C
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 1ce8c17f8a880f6..58a7e07d9b58d86 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -405,12 +405,11 @@ DIDerivedType *
 DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File,
   unsigned LineNumber, DIType *Ty,
   DINode::DIFlags Flags, llvm::Constant *Val,
-  uint32_t AlignInBits) {
+  unsigned Tag, uint32_t AlignInBits) {
   Flags |= DINode::FlagStaticMember;
-  return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
-LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
-AlignInBits, 0, std::nullopt, Flags,
-getConstantOrNull(Val));
+  return DIDerivedType::get(VMContext, Tag, Name, File, LineNumber,
+getNonCompileUnitScope(Scope), Ty, 0, AlignInBits,
+0, std::nullopt, Flags, getConstantOrNull(Val));
 }
 
 DIDerivedType *
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 390a27c4bc0c4dd..0f3590ec66bf2b9 100644
--- a/llvm/lib/

[clang] [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72235)

2023-11-14 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Michael Buch (Michael137)


Changes

This patch implements the DWARFv5 issue
161118.1: "DW_TAG for C++ static data members".

This will simplify LLDB's handling of static data
members greatly in the long term since we no longer need to differentiate 
non-static from static data
member declarations using non-portable heuristics.

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGDebugInfo.cpp (+6-2) 
- (modified) clang/test/CodeGenCXX/debug-info-static-inline-member.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/debug-info-static-member.cpp (+23-13) 


``diff
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 04ca02cfe858579..f3de91d4a39ebee 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1679,9 +1679,13 @@ CGDebugInfo::CreateRecordStaticField(const VarDecl *Var, 
llvm::DIType *RecordTy,
   StringRef VName = Var->getName();
 
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
+  auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
+ ? llvm::dwarf::DW_TAG_variable
+ : llvm::dwarf::DW_TAG_member;
   auto Align = getDeclAlignIfRequired(Var, CGM.getContext());
-  llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-  RecordTy, VName, VUnit, LineNumber, VTy, Flags, /* Val */ nullptr, 
Align);
+  llvm::DIDerivedType *GV =
+  DBuilder.createStaticMemberType(RecordTy, VName, VUnit, LineNumber, VTy,
+  Flags, /* Val */ nullptr, Tag, Align);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   StaticDataMemberDefinitionsToEmit.push_back(Var->getCanonicalDecl());
   return GV;
diff --git a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
index bfb7ad6b80fabf3..f2d4d9408a8297a 100644
--- a/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-inline-member.cpp
@@ -1,5 +1,5 @@
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
-// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -debug-info-kind=limited 
%s -emit-llvm -S -o - | FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=standalone %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
+// RUN: %clangxx -target arm64-apple-macosx11.0.0 -g -gdwarf-4 
-debug-info-kind=limited %s -emit-llvm -S -o - | FileCheck 
--check-prefixes=CHECK %s
 
 enum class Enum : int {
   VAL = -1
diff --git a/clang/test/CodeGenCXX/debug-info-static-member.cpp 
b/clang/test/CodeGenCXX/debug-info-static-member.cpp
index 578995801c6400b..a2d25e98ed1cb62 100644
--- a/clang/test/CodeGenCXX/debug-info-static-member.cpp
+++ b/clang/test/CodeGenCXX/debug-info-static-member.cpp
@@ -1,7 +1,8 @@
-// RUN: %clangxx -target x86_64-unknown-unknown -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++98 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-unknown-unknown -g -std=c++11 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,NOT-MS %s
-// RUN: %clangxx -target x86_64-windows-msvc -g %s -emit-llvm -S -o - | 
FileCheck --check-prefixes=CHECK %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 %s -emit-llvm -S 
-o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++98 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-4 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF4,NOT-MS %s
+// RUN: %clangxx -target x86_64-unknown-unknown -g -gdwarf-5 -std=c++11 %s 
-emit-llvm -S -o - | FileCheck --check-prefixes=CHECK,DWARF5 %s
+// RUN: %clangxx -target x86_64-windows-msvc -g -gdwarf-4 %s -emit-llvm -S -o 
- | FileCheck --check-prefixes=CHECK,DWARF4 %s
 // PR14471
 
 // CHECK: @{{.*}}a{{.*}} = dso_local global i32 4, align 4, !dbg [[A:![0-9]+]]
@@ -39,17 +40,20 @@ class C
 //
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "X"{{.*}})
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"anon_static_decl_struct"
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
+// DWARF4: !DIDerivedType(tag: DW_TAG_member, name: "anon_static_decl_var"
+// DWARF5: !DIDerivedType(tag: DW_TAG_variable, name: "anon_static_decl_var"
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: 
"static_decl_templ"
 // CHECK-NOT:  DIFlagFwdDecl
 // CHECK-SAME: ){{$}}
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "stat

[clang] [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72235)

2023-11-14 Thread Michael Buch via cfe-commits
https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/72235
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72235)

2023-11-14 Thread Michael Buch via cfe-commits
https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/72235
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][DebugInfo] DWARFv5: static data members declarations are DW_TAG_variable (PR #72235)

2023-11-14 Thread Michael Buch via cfe-commits
https://github.com/Michael137 edited 
https://github.com/llvm/llvm-project/pull/72235
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-14 Thread via cfe-commits
https://github.com/tomekpaszek updated 
https://github.com/llvm/llvm-project/pull/70338

>From b5ba0b3fde2c6662e19dfdf96a787621ec767460 Mon Sep 17 00:00:00 2001
From: Tomek Paszek 
Date: Sat, 11 Nov 2023 19:38:00 +0100
Subject: [PATCH 1/8] Added an option to ignore macro definitions.

---
 clang/include/clang/Format/Format.h |  5 +
 clang/lib/Format/Format.cpp |  2 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  2 ++
 clang/unittests/Format/ConfigParseTest.cpp  |  3 ++-
 clang/unittests/Format/FormatTest.cpp   | 16 
 5 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..3af7241441c8b13 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2442,6 +2442,10 @@ struct FormatStyle {
   /// 
`_
   /// \version 13
   std::vector IfMacros;
+  
+  /// Ignore formatting in preprocessor definitions.
+  /// \version 18
+  bool IgnorePPDefinitions;
 
   /// Specify whether access modifiers should have their own indentation level.
   ///
@@ -4719,6 +4723,7 @@ struct FormatStyle {
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
+   IgnorePPDefinitions == R.IgnorePPDefinitions &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index edb33f4af4defef..6e5ec754dfdcdd9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1000,6 +1000,7 @@ template <> struct MappingTraits {
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
+IO.mapOptional("IgnorePPDefinitions", Style.IgnorePPDefinitions);
 IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
 IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", 
Style.IncludeStyle.IncludeIsMainRegex);
@@ -1504,6 +1505,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
   LLVMStyle.IfMacros.push_back("KJ_IF_MAYBE");
+  LLVMStyle.IgnorePPDefinitions = false;
   LLVMStyle.IncludeStyle.IncludeCategories = {
   {"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0, false},
   {"^(<|\"(gtest|gmock|isl|json)/)", 3, 0, false},
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 280485d9a90d1bf..bbf6383ff7673f6 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1355,6 +1355,8 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
+if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective)
+  ShouldFormat = false;
 // We cannot format this line; if the reason is that the line had a
 // parsing error, remember that.
 if (ShouldFormat && TheLine.Type == LT_Invalid && Status) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index f90ed178d99c286..110df624d44573c 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -166,6 +166,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
+  CHECK_PARSE_BOOL(IgnorePPDefinitions);
   CHECK_PARSE_BOOL(IndentAccessModifiers);
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
@@ -198,7 +199,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
   CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
   CHECK_PARSE_BOOL(VerilogBreakBetweenInstancePorts);
-
+  
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements, Enabled);
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements,
   AcrossEmptyLines);
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b2d84f2ee389551..659132dcb9c3970 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24153,6 +24153,22 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   verifyNoChange("

[clang] [clang][analyzer] Restrict 'fopen' modeling to POSIX versions in SimpleStreamChecker (PR #72016)

2023-11-14 Thread Balázs Kéri via cfe-commits
balazske wrote:

The functional change looks good but the reformatting should be put into a 
separate change.

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


[PATCH] D141700: AMDGPU: Move enqueued block handling into clang

2023-11-14 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: llvm/lib/IR/CMakeLists.txt:84
   Demangle
+  TransformUtils
+

This introduces a circular dependency between LLVMCore and TransformUtils. 
Options are:

1. Move appendToUsed into Module
2. Don't bother with bitcode compatibility for this
3. Avoid depending on llvm.used. I know I tried to do this but it was so long 
ago I don't remember how I ended up on this solution 


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

https://reviews.llvm.org/D141700

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


[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits
https://github.com/Fznamznon updated 
https://github.com/llvm/llvm-project/pull/70829

>From ac30780250875802d13450d17e6959f9e2ad3a70 Mon Sep 17 00:00:00 2001
From: "Podchishchaeva, Mariya" 
Date: Tue, 31 Oct 2023 09:27:51 -0700
Subject: [PATCH 1/4] [clang] Fix false positive -Wmissing-field-initializer
 for anonymous unions

Normally warning is not reported when a field has default initializer.
Do so for anonymous unions with default initializers as well.
No release note since it is a regression in clang 18.

Fixes https://github.com/llvm/llvm-project/issues/70384
---
 clang/lib/Sema/SemaInit.cpp   | 99 +++
 .../SemaCXX/cxx2a-initializer-aggregates.cpp  | 66 -
 2 files changed, 122 insertions(+), 43 deletions(-)

diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index ec796def96ad3d8..881e67587e430e7 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -349,17 +349,13 @@ class InitListChecker {
   bool SubobjectIsDesignatorContext, unsigned &Index,
   InitListExpr *StructuredList,
   unsigned &StructuredIndex);
-  bool CheckDesignatedInitializer(const InitializedEntity &Entity,
-  InitListExpr *IList, DesignatedInitExpr *DIE,
-  unsigned DesigIdx,
-  QualType &CurrentObjectType,
-  RecordDecl::field_iterator *NextField,
-  llvm::APSInt *NextElementIndex,
-  unsigned &Index,
-  InitListExpr *StructuredList,
-  unsigned &StructuredIndex,
-  bool FinishSubobjectInit,
-  bool TopLevelObject);
+  bool CheckDesignatedInitializer(
+  const InitializedEntity &Entity, InitListExpr *IList,
+  DesignatedInitExpr *DIE, unsigned DesigIdx, QualType &CurrentObjectType,
+  RecordDecl::field_iterator *NextField, llvm::APSInt *NextElementIndex,
+  unsigned &Index, InitListExpr *StructuredList, unsigned &StructuredIndex,
+  bool FinishSubobjectInit, bool TopLevelObject,
+  llvm::SmallPtrSetImpl *InitializedFields = nullptr);
   InitListExpr *getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
QualType CurrentObjectType,
InitListExpr *StructuredList,
@@ -2248,7 +2244,8 @@ void InitListChecker::CheckStructUnionTypes(
   // the next field that we'll be initializing.
   bool DesignatedInitFailed = CheckDesignatedInitializer(
   Entity, IList, DIE, 0, DeclType, &Field, nullptr, Index,
-  StructuredList, StructuredIndex, true, TopLevelObject);
+  StructuredList, StructuredIndex, true, TopLevelObject,
+  &InitializedFields);
   if (DesignatedInitFailed)
 hadError = true;
 
@@ -2256,7 +2253,6 @@ void InitListChecker::CheckStructUnionTypes(
   DesignatedInitExpr::Designator *D = DIE->getDesignator(0);
   if (!VerifyOnly && D->isFieldDesignator()) {
 FieldDecl *F = D->getFieldDecl();
-InitializedFields.insert(F);
 if (!DesignatedInitFailed) {
   QualType ET = SemaRef.Context.getBaseElementType(F->getType());
   if (checkDestructorReference(ET, InitLoc, SemaRef)) {
@@ -2365,21 +2361,43 @@ void InitListChecker::CheckStructUnionTypes(
   !RD->isUnion()) {
 // It is possible we have one or more unnamed bitfields remaining.
 // Find first (if any) named field and emit warning.
-for (RecordDecl::field_iterator it = HasDesignatedInit ? RD->field_begin()
-   : Field,
-end = RD->field_end();
- it != end; ++it) {
-  if (HasDesignatedInit && InitializedFields.count(*it))
-continue;
+auto MissingFieldCheck = [&](const RecordDecl *Record,
+ RecordDecl::field_iterator StartField,
+ auto &&MissingFieldCheck) -> bool {
+  FieldDecl *FirstUninitialized = nullptr;
+  for (RecordDecl::field_iterator it = StartField,
+  end = Record->field_end();
+   it != end; ++it) {
+bool AllSet = false;
+if (it->isAnonymousStructOrUnion()) {
+  RecordDecl *RDAnon = it->getType()->getAsRecordDecl();
+  AllSet = MissingFieldCheck(RDAnon, RDAnon->field_begin(),
+ MissingFieldCheck);
+}
+
+if ((HasDesignatedInit && InitializedFields.count(*it)) ||
+it->hasInClassInitializer() || AllSet) {
+  if (Record->isUnion())
+return true;
+  continue;
+}
 
-  if (!it->isUnnamedBitfield() && !it->hasInClassInitializer() &&

[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits

@@ -727,6 +734,38 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 if (hadError || VerifyOnly) {
   // Do nothing
 } else if (Init < NumInits) {
+  if (WarnIfMissing) {
+auto CheckAnonMember = [&](const FieldDecl *FD,
+   auto &&CheckAnonMember) -> FieldDecl * {
+  FieldDecl *Uninitialized = nullptr;
+  RecordDecl *RD = FD->getType()->getAsRecordDecl();
+  assert(RD && "Not anonymous member checked?");
+  for (auto *F : RD->fields()) {
+if (F->isAnonymousStructOrUnion())
+  Uninitialized = CheckAnonMember(F, CheckAnonMember);
+else if (!F->isUnnamedBitfield() &&
+ !F->getType()->isIncompleteArrayType() && !Uninitialized 
&&
+ !F->hasInClassInitializer())
+  Uninitialized = F;
+
+if (RD->isUnion() && (F->hasInClassInitializer() || 
!Uninitialized))
+  return nullptr;
+  }

Fznamznon wrote:

Ok, done. Thanks for the catch!

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


[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits

@@ -654,11 +655,17 @@ void InitListChecker::FillInEmptyInitForBase(
   }
 }
 
-void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
-const InitializedEntity &ParentEntity,
-  InitListExpr *ILE,
-  bool &RequiresSecondPass,
-  bool FillWithNoInit) {
+static bool hasAnyDesignatedInits(const InitListExpr *IL) {
+  for (const Stmt *Init : *IL)
+if (isa_and_nonnull(Init))
+  return true;
+  return false;

Fznamznon wrote:

Ok, done.


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


[clang] [flang] [Flang][Clang] Add support for frame pointers in Flang (PR #72146)

2023-11-14 Thread Radu Salavat via cfe-commits
https://github.com/Radu2k updated 
https://github.com/llvm/llvm-project/pull/72146

>From 0b0f02eab4dc02adf79461bc865be6f7580938cf Mon Sep 17 00:00:00 2001
From: Radu2k 
Date: Mon, 13 Nov 2023 17:49:06 +
Subject: [PATCH] [Flang][Clang] Add support for frame pointers in Flang

---
 clang/include/clang/Driver/Options.td |  14 +-
 clang/lib/Driver/ToolChains/Clang.cpp | 133 -
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 141 ++
 clang/lib/Driver/ToolChains/CommonArgs.h  |   4 +
 clang/lib/Driver/ToolChains/Flang.cpp |  19 +++
 .../include/flang/Frontend/CodeGenOptions.def |   1 +
 flang/include/flang/Frontend/CodeGenOptions.h |  23 +++
 flang/include/flang/Tools/CrossToolHelpers.h  |   2 +
 flang/lib/Frontend/CompilerInvocation.cpp |  13 ++
 flang/lib/Frontend/FrontendActions.cpp|   5 +
 flang/test/Driver/driver-help-hidden.f90  |   1 +
 flang/test/Driver/driver-help.f90 |   2 +
 flang/test/Driver/frontend-forwarding.f90 |   2 +
 13 files changed, 222 insertions(+), 138 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d1b67a448b2a59b..bf99786d017b318 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3147,7 +3147,8 @@ def fno_ms_compatibility : Flag<["-"], 
"fno-ms-compatibility">, Group,
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, 
Group;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group,
   Visibility<[ClangOption, CC1Option]>;
-def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group;
+def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group,
+  Visibility<[ClangOption, FlangOption]>;
 defm operator_names : BoolFOption<"operator-names",
   LangOpts<"CXXOperatorNames">, Default,
   NegFlag>;
 
 def fomit_frame_pointer : Flag<["-"], "fomit-frame-pointer">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Omit the frame pointer from functions that don't need it. "
   "Some stack unwinding cases, such as profilers and sanitizers, may prefer 
specifying -fno-omit-frame-pointer. "
   "On many targets, -O1 and higher omit the frame pointer by default. "
@@ -6752,10 +6754,7 @@ def new_struct_path_tbaa : Flag<["-"], 
"new-struct-path-tbaa">,
 def mdebug_pass : Separate<["-"], "mdebug-pass">,
   HelpText<"Enable additional debug output">,
   MarshallingInfoString>;
-def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
-  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
-  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
-  MarshallingInfoEnum, "None">;
+
 def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">,
   HelpText<"Use IEEE 754 quadruple-precision for long double">,
   MarshallingInfoFlag>;
@@ -7368,6 +7367,11 @@ def pic_level : Separate<["-"], "pic-level">,
 def pic_is_pie : Flag<["-"], "pic-is-pie">,
   HelpText<"File is for a position independent executable">,
   MarshallingInfoFlag>;
+  
+def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
+  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
+  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
+  MarshallingInfoEnum, "None">;
 
 } // let Visibility = [CC1Option, FC1Option]
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3b98c7ae6e6ec66..3273bd1d2c0c6fa 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -409,139 +409,6 @@ static bool ShouldEnableAutolink(const ArgList &Args, 
const ToolChain &TC,
   Default);
 }
 
-static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
-  switch (Triple.getArch()){
-  default:
-return false;
-  case llvm::Triple::arm:
-  case llvm::Triple::thumb:
-// ARM Darwin targets require a frame pointer to be always present to aid
-// offline debugging via backtraces.
-return Triple.isOSDarwin();
-  }
-}
-
-static bool useFramePointerForTargetByDefault(const ArgList &Args,
-  const llvm::Triple &Triple) {
-  if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry))
-return true;
-
-  if (Triple.isAndroid()) {
-switch (Triple.getArch()) {
-case llvm::Triple::aarch64:
-case llvm::Triple::arm:
-case llvm::Triple::armeb:
-case llvm::Triple::thumb:
-case llvm::Triple::thumbeb:
-case llvm::Triple::riscv64:
-  return true;
-default:
-  break;
-}
-  }
-
-  switch (Triple.getArch()) {
-  case llvm::Triple::xcore:
-  case llvm::Triple::wasm32:
-  case llvm::Triple::wasm64:
-  case llvm::Triple::msp430:
-// XCore never wants frame pointers, regardless of OS.
-// WebAssembly never wants fra

[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

2023-11-14 Thread Mariya Podchishchaeva via cfe-commits

@@ -727,6 +729,44 @@ void InitListChecker::FillInEmptyInitForField(unsigned 
Init, FieldDecl *Field,
 if (hadError || VerifyOnly) {
   // Do nothing
 } else if (Init < NumInits) {

Fznamznon wrote:

> Maybe consider changing the L674 condition to an assert(Init < NumInits) and 
> simplify this too?

I'm not sure I understand the suggestion. The condition on L674 looks like:
```
if (Init >= NumInits || !ILE->getInit(Init)) {
```
Even if I only remove `Init >= NumInits`, build of check-clang starts asserting 
with
```
Assertion `Init < getNumInits() && "Initializer access out of range!"'
```

Removing `!ILE->getInit(Init)` also doesn't seem logical to me since 
`FillInEmptyInitForField` is called for all fields in a record.

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


[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-14 Thread Balázs Kéri via cfe-commits
https://github.com/balazske created 
https://github.com/llvm/llvm-project/pull/72242

Operators that are overloadable may be parsed as `CXXOperatorCallExpr` or as 
`UnaryOperator` (or `BinaryOperator`). This depends on the context and can be 
different if a similar construct is imported into an existing AST. The two 
"forms" of the operator call AST nodes should be detected as equivalent to 
allow AST import of these cases.

This fix has probably other consequences because if a structure is imported 
that has `CXXOperatorCallExpr` into an AST with an existing similar structure 
that has `UnaryOperator` (or binary), the additional data in the 
`CXXOperatorCallExpr` node is lost at the import (because the existing node 
will be used). I am not sure if this can cause problems.

From 5300f979c96eb2f88c298872f0519e274c155cfe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Tue, 14 Nov 2023 11:53:20 +0100
Subject: [PATCH] [clang][ASTImporter] Improve structural equivalence of
 overloadable operators.

Operators that are overloadable may be parsed as `CXXOperatorCallExpr`
or as `UnaryOperator` (or `BinaryOperator`). This depends on the context
and can be different if a similar construct is imported into an existing AST.
The two "forms" of the operator call AST nodes should be detected as
equivalent to allow AST import of these cases.

This fix has probably other consequences because if a structure is imported
that has `CXXOperatorCallExpr` into an AST with an existing similar structure
that has `UnaryOperator` (or binary), the additional data in the
`CXXOperatorCallExpr` node is lost at the import (because the existing node
will be used). I am not sure if this can cause problems.
---
 clang/lib/AST/ASTStructuralEquivalence.cpp|  57 ++
 .../AST/StructuralEquivalenceTest.cpp | 170 ++
 2 files changed, 227 insertions(+)

diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7b..b937ff0579ca02d 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -98,6 +98,8 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  QualType T1, QualType T2);
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  Decl *D1, Decl *D2);
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Stmt *S1, const Stmt *S2);
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const TemplateArgument &Arg1,
  const TemplateArgument &Arg2);
@@ -437,12 +439,67 @@ class StmtComparer {
 };
 } // namespace
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const UnaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return UnaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getSubExpr(), E2->getArg(0));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const UnaryOperator *E2) {
+  return E1->getOperator() ==
+ UnaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getSubExpr());
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const BinaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return BinaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getLHS(), E2->getArg(0)) &&
+ IsStructurallyEquivalent(Context, E1->getRHS(), E2->getArg(1));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const BinaryOperator *E2) {
+  return E1->getOperator() ==
+ BinaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getLHS()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(1), E2->getRHS());
+}
+
 /// Determine structural equivalence of two statements.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const Stmt *S1, const Stmt *S2) {
   if (!S1 || !S2)
 return S1 == S2;
 
+  // Check for statements with similar syntax but different AST.
+  // The unary and binary operators (like '+', '&') can be parsed as
+  // CXXOpe

[clang] [clang][ASTImporter] Improve structural equivalence of overloadable operators. (PR #72242)

2023-11-14 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)


Changes

Operators that are overloadable may be parsed as `CXXOperatorCallExpr` or as 
`UnaryOperator` (or `BinaryOperator`). This depends on the context and can be 
different if a similar construct is imported into an existing AST. The two 
"forms" of the operator call AST nodes should be detected as equivalent to 
allow AST import of these cases.

This fix has probably other consequences because if a structure is imported 
that has `CXXOperatorCallExpr` into an AST with an existing similar structure 
that has `UnaryOperator` (or binary), the additional data in the 
`CXXOperatorCallExpr` node is lost at the import (because the existing node 
will be used). I am not sure if this can cause problems.

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


2 Files Affected:

- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+57) 
- (modified) clang/unittests/AST/StructuralEquivalenceTest.cpp (+170) 


``diff
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 6bb4bf14b873d7b..b937ff0579ca02d 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -98,6 +98,8 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  QualType T1, QualType T2);
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  Decl *D1, Decl *D2);
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Stmt *S1, const Stmt *S2);
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const TemplateArgument &Arg1,
  const TemplateArgument &Arg2);
@@ -437,12 +439,67 @@ class StmtComparer {
 };
 } // namespace
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const UnaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return UnaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getSubExpr(), E2->getArg(0));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const UnaryOperator *E2) {
+  return E1->getOperator() ==
+ UnaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getSubExpr());
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const BinaryOperator *E1,
+ const CXXOperatorCallExpr *E2) {
+  return BinaryOperator::getOverloadedOperator(E1->getOpcode()) ==
+ E2->getOperator() &&
+ IsStructurallyEquivalent(Context, E1->getLHS(), E2->getArg(0)) &&
+ IsStructurallyEquivalent(Context, E1->getRHS(), E2->getArg(1));
+}
+
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const CXXOperatorCallExpr *E1,
+ const BinaryOperator *E2) {
+  return E1->getOperator() ==
+ BinaryOperator::getOverloadedOperator(E2->getOpcode()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(0), E2->getLHS()) &&
+ IsStructurallyEquivalent(Context, E1->getArg(1), E2->getRHS());
+}
+
 /// Determine structural equivalence of two statements.
 static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
  const Stmt *S1, const Stmt *S2) {
   if (!S1 || !S2)
 return S1 == S2;
 
+  // Check for statements with similar syntax but different AST.
+  // The unary and binary operators (like '+', '&') can be parsed as
+  // CXXOperatorCall too (and UnaryOperator or BinaryOperator).
+  // This depends on arguments with unresolved type and on the name lookup.
+  // The lookup results can be different in a "From" and "To" AST even if the
+  // compared structure is otherwise equivalent. For this reason we must treat
+  // these operators as equivalent even if they are represented by different 
AST
+  // nodes.
+  if (const auto *E2CXXOperatorCall = dyn_cast(S2)) {
+if (const auto *E1Unary = dyn_cast(S1))
+  return IsStructurallyEquivalent(Context, E1Unary, E2CXXOperatorCall);
+if (const auto *E1Binary = dyn_cast(S1))
+  return IsStructurallyEquivalent(Context, E1Binary, E2CXXOperatorCall);
+  }
+  if (const auto *E1CXXOperatorCall = dyn_cast(S1)) {
+if (const auto *E2Unary = dyn_cast(S2))
+  return IsStructurallyEquivalent(Context, E1CXXOperatorCall, E2Unary);
+  

[PATCH] D141700: AMDGPU: Move enqueued block handling into clang

2023-11-14 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm updated this revision to Diff 558095.
arsenm added a comment.

Drop bitcode auto upgrade handling


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

https://reviews.llvm.org/D141700

Files:
  clang/lib/CodeGen/Targets/AMDGPU.cpp
  clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel-linking.cl
  clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
  llvm/docs/AMDGPUUsage.rst
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/CMakeLists.txt
  llvm/lib/Target/AMDGPU/AMDGPU.h
  llvm/lib/Target/AMDGPU/AMDGPUExportKernelRuntimeHandles.cpp
  llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.cpp
  llvm/lib/Target/AMDGPU/AMDGPUHSAMetadataStreamer.h
  llvm/lib/Target/AMDGPU/AMDGPUOpenCLEnqueuedBlockLowering.cpp
  llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  llvm/lib/Target/AMDGPU/CMakeLists.txt
  llvm/test/CodeGen/AMDGPU/amdgpu-export-kernel-runtime-handles.ll
  llvm/test/CodeGen/AMDGPU/enqueue-kernel.ll
  llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
  llvm/test/CodeGen/AMDGPU/llc-pipeline.ll

Index: llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
===
--- llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -37,7 +37,7 @@
 ; GCN-O0-NEXT:Dominator Tree Construction
 ; GCN-O0-NEXT:Basic Alias Analysis (stateless AA impl)
 ; GCN-O0-NEXT:Function Alias Analysis Results
-; GCN-O0-NEXT:Lower OpenCL enqueued blocks
+; GCN-O0-NEXT:Externalize enqueued block runtime handles
 ; GCN-O0-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O0-NEXT:FunctionPass Manager
 ; GCN-O0-NEXT:  Expand Atomic instructions
@@ -178,7 +178,7 @@
 ; GCN-O1-NEXT:Dominator Tree Construction
 ; GCN-O1-NEXT:Basic Alias Analysis (stateless AA impl)
 ; GCN-O1-NEXT:Function Alias Analysis Results
-; GCN-O1-NEXT:Lower OpenCL enqueued blocks
+; GCN-O1-NEXT:Externalize enqueued block runtime handles
 ; GCN-O1-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-NEXT:AMDGPU Attributor
 ; GCN-O1-NEXT:  FunctionPass Manager
@@ -445,7 +445,7 @@
 ; GCN-O1-OPTS-NEXT:Dominator Tree Construction
 ; GCN-O1-OPTS-NEXT:Basic Alias Analysis (stateless AA impl)
 ; GCN-O1-OPTS-NEXT:Function Alias Analysis Results
-; GCN-O1-OPTS-NEXT:Lower OpenCL enqueued blocks
+; GCN-O1-OPTS-NEXT:Externalize enqueued block runtime handles
 ; GCN-O1-OPTS-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O1-OPTS-NEXT:AMDGPU Attributor
 ; GCN-O1-OPTS-NEXT:  FunctionPass Manager
@@ -736,7 +736,7 @@
 ; GCN-O2-NEXT:Dominator Tree Construction
 ; GCN-O2-NEXT:Basic Alias Analysis (stateless AA impl)
 ; GCN-O2-NEXT:Function Alias Analysis Results
-; GCN-O2-NEXT:Lower OpenCL enqueued blocks
+; GCN-O2-NEXT:Externalize enqueued block runtime handles
 ; GCN-O2-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O2-NEXT:AMDGPU Attributor
 ; GCN-O2-NEXT:  FunctionPass Manager
@@ -1037,7 +1037,7 @@
 ; GCN-O3-NEXT:Dominator Tree Construction
 ; GCN-O3-NEXT:Basic Alias Analysis (stateless AA impl)
 ; GCN-O3-NEXT:Function Alias Analysis Results
-; GCN-O3-NEXT:Lower OpenCL enqueued blocks
+; GCN-O3-NEXT:Externalize enqueued block runtime handles
 ; GCN-O3-NEXT:Lower uses of LDS variables from non-kernel functions
 ; GCN-O3-NEXT:AMDGPU Attributor
 ; GCN-O3-NEXT:  FunctionPass Manager
Index: llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
===
--- llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
+++ llvm/test/CodeGen/AMDGPU/hsa-metadata-from-llvm-ir-full.ll
@@ -14,7 +14,8 @@
 %struct.B = type { ptr addrspace(1) }
 %opencl.clk_event_t = type opaque
 
-@__test_block_invoke_kernel_runtime_handle = external addrspace(1) externally_initialized constant ptr addrspace(1)
+@__test_block_invoke_kernel_runtime_handle = external addrspace(1) externally_initialized constant ptr addrspace(1), section ".amdgpu.kernel.runtime.handle"
+@not.a.handle = external addrspace(1) externally_initialized constant ptr addrspace(1)
 
 ; CHECK:  ---
 ; CHECK-NEXT: amdhsa.kernels:
@@ -1678,7 +1679,7 @@
 ; CHECK:  .name:   __test_block_invoke_kernel
 ; CHECK:  .symbol: __test_block_invoke_kernel.kd
 define amdgpu_kernel void @__test_block_invoke_kernel(
-<{ i32, i32, ptr, ptr addrspace(1), i8 }> %arg) #1
+<{ i32, i32, ptr, ptr addrspace(1), i8 }> %arg) #1 !associated !112
 !kernel_arg_addr_space !1 !kernel_arg_access_qual !2 !kernel_arg_type !110
 !kernel_arg_base_type !110 !kernel_arg_type_qual !4 {
   ret void
@@ -1734,6 +1735,29 @@
   ret void
 }
 
+; Make sure the device_enqueue_symbol is not reported
+; CHECK: - .args:   []
+; CHECK-NEXT: .group_segment_fixed_size: 0
+; CHECK-NEXT: .kernarg

[clang] [clang] Fix --entry command line option (PR #69114)

2023-11-14 Thread Tuur Martens via cfe-commits
JohnyTheCarrot wrote:

Ping.

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


[llvm] [clang] [AArch64] Stack probing for dynamic allocas in SelectionDAG (PR #66525)

2023-11-14 Thread Sam Tebbs via cfe-commits
https://github.com/SamTebbs33 edited 
https://github.com/llvm/llvm-project/pull/66525
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AArch64] Stack probing for dynamic allocas in SelectionDAG (PR #66525)

2023-11-14 Thread Sam Tebbs via cfe-commits
https://github.com/SamTebbs33 approved this pull request.

Thanks Momchil. This looks good to me with a couple of questions. The tests are 
comprehensive as well.

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


[clang] [llvm] [AArch64] Stack probing for dynamic allocas in SelectionDAG (PR #66525)

2023-11-14 Thread Sam Tebbs via cfe-commits

@@ -861,6 +861,12 @@ def AArch64stilp : SDNode<"AArch64ISD::STILP", 
SDT_AArch64stilp, [SDNPHasChain,
 def AArch64stnp : SDNode<"AArch64ISD::STNP", SDT_AArch64stnp, [SDNPHasChain, 
SDNPMayStore, SDNPMemOperand]>;
 
 def AArch64tbl : SDNode<"AArch64ISD::TBL", SDT_AArch64TBL>;
+
+def AArch64probedalloca
+: SDNode<"AArch64ISD::PROBED_ALLOCA",
+ SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>,
+ [SDNPHasChain]>;

SamTebbs33 wrote:

Does this need a `SDNPMayStore` attribute?

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


[clang] [llvm] [AArch64] Stack probing for dynamic allocas in SelectionDAG (PR #66525)

2023-11-14 Thread Sam Tebbs via cfe-commits

@@ -9461,6 +9462,94 @@ bool AArch64InstrInfo::isReallyTriviallyReMaterializable(
   return TargetInstrInfo::isReallyTriviallyReMaterializable(MI);
 }
 
+MachineBasicBlock::iterator
+AArch64InstrInfo::probedStackAlloc(MachineBasicBlock::iterator MBBI,

SamTebbs33 wrote:

I think it would be useful for this function to have some comments that explain 
what it emits, so it can be understood isolated from the rest of this patch.

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


[clang] cc12449 - [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (#71795)

2023-11-14 Thread via cfe-commits
Author: Matthew Devereau
Date: 2023-11-14T11:27:41Z
New Revision: cc1244980b74f45a06e2002a33444ce757b577aa

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

LOG: [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (#71795)

Adds the builtins:
void svldr_zt(uint64_t zt, const void *rn)
void svstr_zt(uint64_t zt, void *rn)

And the intrinsics:
call void @llvm.aarch64.sme.ldr.zt(i32, ptr)
tail call void @llvm.aarch64.sme.str.zt(i32, ptr)

Patch by: Kerry McLaughlin 

Added: 
clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
llvm/test/CodeGen/AArch64/sme2-intrinsics-zt0.ll

Modified: 
clang/include/clang/Basic/arm_sme.td
llvm/include/llvm/IR/IntrinsicsAArch64.td
llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.h
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
llvm/lib/Target/AArch64/AArch64SMEInstrInfo.td
llvm/lib/Target/AArch64/SMEInstrFormats.td

Removed: 




diff  --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index b5655afdf419ecf..fb3f54ecff95080 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -298,3 +298,11 @@ multiclass ZAAddSub {
 
 defm SVADD : ZAAddSub<"add">;
 defm SVSUB : ZAAddSub<"sub">;
+
+//
+// Spill and fill of ZT0
+//
+let TargetGuard = "sme2" in {
+  def SVLDR_ZT : Inst<"svldr_zt", "viQ", "", MergeNone, "aarch64_sme_ldr_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+  def SVSTR_ZT : Inst<"svstr_zt", "vi%", "", MergeNone, "aarch64_sme_str_zt", 
[IsOverloadNone, IsStreamingCompatible, IsSharedZA, IsPreservesZA], 
[ImmCheck<0, ImmCheck0_0>]>;
+}

diff  --git a/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c 
b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
new file mode 100644
index 000..3d70ded6b469ba1
--- /dev/null
+++ b/clang/test/CodeGen/aarch64-sme2-intrinsics/acle_sme2_ldr_str_zt.c
@@ -0,0 +1,51 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+
+// REQUIRES: aarch64-registered-target
+
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -emit-llvm -o - -x c++ %s | opt -S -p 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - %s | 
opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64-none-linux-gnu 
-target-feature +sme2 -S -disable-O0-optnone -Werror -Wall -emit-llvm -o - -x 
c++ %s | opt -S -p mem2reg,instcombine,tailcallelim | FileCheck %s 
-check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme2 -S 
-disable-O0-optnone -Werror -Wall -o /dev/null %s
+
+#include 
+
+#ifdef SVE_OVERLOADED_FORMS
+// A simple used,unused... macro, long enough to represent any SVE builtin.
+#define SVE_ACLE_FUNC(A1,A2_UNUSED) A1
+#else
+#define SVE_ACLE_FUNC(A1,A2) A1##A2
+#endif
+
+// LDR ZT0
+
+// CHECK-LABEL: @test_svldr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svldr_ztPKv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.ldr.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svldr_zt(const void *base) __arm_streaming_compatible 
__arm_shared_za __arm_preserves_za {
+  svldr_zt(0, base);
+} ;
+
+
+// STR ZT0
+
+// CHECK-LABEL: @test_svstr_zt(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CHECK-NEXT:ret void
+//
+// CPP-CHECK-LABEL: @_Z13test_svstr_ztPv(
+// CPP-CHECK-NEXT:  entry:
+// CPP-CHECK-NEXT:tail call void @llvm.aarch64.sme.str.zt(i32 0, ptr 
[[BASE:%.*]])
+// CPP-CHECK-NEXT:ret void
+//
+void test_svstr_zt(void *base) __arm_streaming_compatible __arm_shared_za 
__arm_preserves_za {
+  svstr_zt(0, base);
+}

diff  --git a/llvm/include/llvm/IR/IntrinsicsAArch64.td 
b/llvm/include/llvm/IR/IntrinsicsAArch64.td
index a42e2c49cb477ba..9164604f7d78cbc 100644
--- a/llvm/include/llvm/IR/IntrinsicsAArch64.td
+++ b/llvm/include/llvm/IR/IntrinsicsAArch64.td
@@ -2679,10 +2679,10 @@ let TargetPrefix = "aarch64" in {
   def int_aarc

[clang] [llvm] [AArch64][SME2] Add ldr_zt, str_zt builtins and intrinsics (PR #71795)

2023-11-14 Thread Matthew Devereau via cfe-commits
https://github.com/MDevereau closed 
https://github.com/llvm/llvm-project/pull/71795
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [Flang][Clang] Add support for frame pointers in Flang (PR #72146)

2023-11-14 Thread Radu Salavat via cfe-commits
https://github.com/Radu2k updated 
https://github.com/llvm/llvm-project/pull/72146

>From 0b0f02eab4dc02adf79461bc865be6f7580938cf Mon Sep 17 00:00:00 2001
From: Radu2k 
Date: Mon, 13 Nov 2023 17:49:06 +
Subject: [PATCH 1/2] [Flang][Clang] Add support for frame pointers in Flang

---
 clang/include/clang/Driver/Options.td |  14 +-
 clang/lib/Driver/ToolChains/Clang.cpp | 133 -
 clang/lib/Driver/ToolChains/CommonArgs.cpp| 141 ++
 clang/lib/Driver/ToolChains/CommonArgs.h  |   4 +
 clang/lib/Driver/ToolChains/Flang.cpp |  19 +++
 .../include/flang/Frontend/CodeGenOptions.def |   1 +
 flang/include/flang/Frontend/CodeGenOptions.h |  23 +++
 flang/include/flang/Tools/CrossToolHelpers.h  |   2 +
 flang/lib/Frontend/CompilerInvocation.cpp |  13 ++
 flang/lib/Frontend/FrontendActions.cpp|   5 +
 flang/test/Driver/driver-help-hidden.f90  |   1 +
 flang/test/Driver/driver-help.f90 |   2 +
 flang/test/Driver/frontend-forwarding.f90 |   2 +
 13 files changed, 222 insertions(+), 138 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d1b67a448b2a59b..bf99786d017b318 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3147,7 +3147,8 @@ def fno_ms_compatibility : Flag<["-"], 
"fno-ms-compatibility">, Group,
 def fno_objc_legacy_dispatch : Flag<["-"], "fno-objc-legacy-dispatch">, 
Group;
 def fno_objc_weak : Flag<["-"], "fno-objc-weak">, Group,
   Visibility<[ClangOption, CC1Option]>;
-def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group;
+def fno_omit_frame_pointer : Flag<["-"], "fno-omit-frame-pointer">, 
Group,
+  Visibility<[ClangOption, FlangOption]>;
 defm operator_names : BoolFOption<"operator-names",
   LangOpts<"CXXOperatorNames">, Default,
   NegFlag>;
 
 def fomit_frame_pointer : Flag<["-"], "fomit-frame-pointer">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Omit the frame pointer from functions that don't need it. "
   "Some stack unwinding cases, such as profilers and sanitizers, may prefer 
specifying -fno-omit-frame-pointer. "
   "On many targets, -O1 and higher omit the frame pointer by default. "
@@ -6752,10 +6754,7 @@ def new_struct_path_tbaa : Flag<["-"], 
"new-struct-path-tbaa">,
 def mdebug_pass : Separate<["-"], "mdebug-pass">,
   HelpText<"Enable additional debug output">,
   MarshallingInfoString>;
-def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
-  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
-  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
-  MarshallingInfoEnum, "None">;
+
 def mabi_EQ_ieeelongdouble : Flag<["-"], "mabi=ieeelongdouble">,
   HelpText<"Use IEEE 754 quadruple-precision for long double">,
   MarshallingInfoFlag>;
@@ -7368,6 +7367,11 @@ def pic_level : Separate<["-"], "pic-level">,
 def pic_is_pie : Flag<["-"], "pic-is-pie">,
   HelpText<"File is for a position independent executable">,
   MarshallingInfoFlag>;
+  
+def mframe_pointer_EQ : Joined<["-"], "mframe-pointer=">,
+  HelpText<"Specify which frame pointers to retain.">, 
Values<"all,non-leaf,none">,
+  NormalizedValuesScope<"CodeGenOptions::FramePointerKind">, 
NormalizedValues<["All", "NonLeaf", "None"]>,
+  MarshallingInfoEnum, "None">;
 
 } // let Visibility = [CC1Option, FC1Option]
 
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 3b98c7ae6e6ec66..3273bd1d2c0c6fa 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -409,139 +409,6 @@ static bool ShouldEnableAutolink(const ArgList &Args, 
const ToolChain &TC,
   Default);
 }
 
-static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
-  switch (Triple.getArch()){
-  default:
-return false;
-  case llvm::Triple::arm:
-  case llvm::Triple::thumb:
-// ARM Darwin targets require a frame pointer to be always present to aid
-// offline debugging via backtraces.
-return Triple.isOSDarwin();
-  }
-}
-
-static bool useFramePointerForTargetByDefault(const ArgList &Args,
-  const llvm::Triple &Triple) {
-  if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry))
-return true;
-
-  if (Triple.isAndroid()) {
-switch (Triple.getArch()) {
-case llvm::Triple::aarch64:
-case llvm::Triple::arm:
-case llvm::Triple::armeb:
-case llvm::Triple::thumb:
-case llvm::Triple::thumbeb:
-case llvm::Triple::riscv64:
-  return true;
-default:
-  break;
-}
-  }
-
-  switch (Triple.getArch()) {
-  case llvm::Triple::xcore:
-  case llvm::Triple::wasm32:
-  case llvm::Triple::wasm64:
-  case llvm::Triple::msp430:
-// XCore never wants frame pointers, regardless of OS.
-// WebAssembly never wants

[clang] [llvm] [mlir] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-11-14 Thread Sam Tebbs via cfe-commits

@@ -4825,6 +4827,113 @@ SDValue AArch64TargetLowering::getPStateSM(SelectionDAG 
&DAG, SDValue Chain,
  Mask);
 }
 
+// Lower an SME LDR/STR ZA intrinsic to LDR_ZA_PSEUDO or STR_ZA.
+// Case 1: If the vector number (vecnum) is an immediate in range, it gets
+// folded into the instruction
+//ldr(%tileslice, %ptr, 11) -> ldr [%tileslice, 11], [%ptr, 11]
+// Case 2: If the vecnum is not an immediate, then it is used to modify the 
base
+// and tile slice registers
+//ldr(%tileslice, %ptr, %vecnum)
+//->
+//%svl = rdsvl
+//%ptr2 = %ptr + %svl * %vecnum
+//%tileslice2 = %tileslice + %vecnum
+//ldr [%tileslice2, 0], [%ptr2, 0]
+// Case 3: If the vecnum is an immediate out of range, then the same is done as
+// case 2, but the base and slice registers are modified by the greatest
+// multiple of 15 lower than the vecnum and the remainder is folded into the
+// instruction. This means that successive loads and stores that are offset 
from
+// each other can share the same base and slice register updates.
+//ldr(%tileslice, %ptr, 22)
+//ldr(%tileslice, %ptr, 23)
+//->
+//%svl = rdsvl
+//%ptr2 = %ptr + %svl * 15
+//%tileslice2 = %tileslice + 15
+//ldr [%tileslice2, 7], [%ptr2, 7]
+//ldr [%tileslice2, 8], [%ptr2, 8]
+// Case 4: If the vecnum is an add of an immediate, then the non-immediate
+// operand and the immediate can be folded into the instruction, like case 2.
+//ldr(%tileslice, %ptr, %vecnum + 7)
+//ldr(%tileslice, %ptr, %vecnum + 8)
+//->
+//%svl = rdsvl
+//%ptr2 = %ptr + %svl * %vecnum
+//%tileslice2 = %tileslice + %vecnum
+//ldr [%tileslice2, 7], [%ptr2, 7]
+//ldr [%tileslice2, 8], [%ptr2, 8]
+// Case 5: The vecnum being an add of an immediate out of range is also 
handled,
+// in which case the same remainder logic as case 3 is used.
+SDValue LowerSMELdrStr(SDValue N, SelectionDAG &DAG, bool IsLoad) {
+  SDLoc DL(N);
+
+  SDValue TileSlice = N->getOperand(2);
+  SDValue Base = N->getOperand(3);
+  SDValue VecNum = N->getOperand(4);
+  int Addend = 0;
+
+  // If the vnum is an add, we can fold that add into the instruction if the
+  // operand is an immediate. The range check is performed below.
+  if (VecNum.getOpcode() == ISD::ADD) {
+if (auto ImmNode = dyn_cast(VecNum.getOperand(1))) {
+  Addend = ImmNode->getSExtValue();
+  VecNum = VecNum.getOperand(0);
+}
+  }
+
+  SDValue Remainder = DAG.getTargetConstant(Addend, DL, MVT::i32);
+
+  // true if the base and slice registers need to be modified
+  bool NeedsAdd = true;
+  auto ImmNode = dyn_cast(VecNum);
+  if (ImmNode || Addend != 0) {
+int Imm = ImmNode ? ImmNode->getSExtValue() + Addend : Addend;
+Remainder = DAG.getTargetConstant(Imm % 16, DL, MVT::i32);
+if (Imm >= 0 && Imm <= 15) {
+  // If vnum is an immediate in range then we don't need to modify the tile
+  // slice and base register. We could also get here because Addend != 0 
but
+  // vecnum is not an immediate, in which case we still want the base and
+  // slice register to be modified
+  NeedsAdd = !ImmNode;

SamTebbs33 wrote:

I actually didn't realise that `SDValue()` is a falsey value. That certainly 
does eliminate the need for the `NeedsAdd` boolean. Thank you!

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


[clang] [flang] [flang] Add depdendent-lib option to flang -fc1 on Windows (PR #72121)

2023-11-14 Thread Tom Eccles via cfe-commits
https://github.com/tblah approved this pull request.

LGTM with Andrzej's comments

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


[clang] [clang][Interp] Implement __builtin_clrsb (PR #72243)

2023-11-14 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/72243

None

>From 0a5cc373736f6c9e29f4f8af438d37dd007f09e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 14 Nov 2023 12:42:03 +0100
Subject: [PATCH] [clang][Interp] Implement __builtin_clrsb

---
 clang/lib/AST/Interp/InterpBuiltin.cpp  | 16 
 clang/test/AST/Interp/builtin-functions.cpp | 17 -
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index f26d298f5b60045..69383d37440f704 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -439,6 +439,15 @@ static bool interp__builtin_popcount(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_clrsb(InterpState &S, CodePtr OpPC,
+  const InterpFrame *Frame,
+  const Function *Func, const CallExpr *Call) {
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  APSInt Val = peekToAPSInt(S.Stk, ArgT);
+  pushInt(S, Val.getBitWidth() - Val.getSignificantBits());
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -576,6 +585,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return retInt(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_clrsb:
+  case Builtin::BI__builtin_clrsbl:
+  case Builtin::BI__builtin_clrsbll:
+if (interp__builtin_clrsb(S, OpPC, Frame, F, Call))
+  return retInt(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index a78a0fbdf11b1d7..245d775bd366d53 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -274,6 +274,7 @@ namespace SourceLocation {
   }
 }
 
+#define BITSIZE(x) (sizeof(x) * 8)
 namespace popcount {
   static_assert(__builtin_popcount(~0u) == __CHAR_BIT__ * sizeof(unsigned 
int), "");
   static_assert(__builtin_popcount(0) == 0, "");
@@ -283,7 +284,6 @@ namespace popcount {
   static_assert(__builtin_popcountll(0) == 0, "");
 
   /// From test/Sema/constant-builtins-2.c
-#define BITSIZE(x) (sizeof(x) * 8)
   char popcount1[__builtin_popcount(0) == 0 ? 1 : -1];
   char popcount2[__builtin_popcount(0xF0F0) == 8 ? 1 : -1];
   char popcount3[__builtin_popcount(~0) == BITSIZE(int) ? 1 : -1];
@@ -295,3 +295,18 @@ namespace popcount {
   char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
   char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
 }
+
+namespace clrsb {
+  char clrsb1[__builtin_clrsb(0) == BITSIZE(int) - 1 ? 1 : -1];
+  char clrsb2[__builtin_clrsbl(0L) == BITSIZE(long) - 1 ? 1 : -1];
+  char clrsb3[__builtin_clrsbll(0LL) == BITSIZE(long long) - 1 ? 1 : -1];
+  char clrsb4[__builtin_clrsb(~0) == BITSIZE(int) - 1 ? 1 : -1];
+  char clrsb5[__builtin_clrsbl(~0L) == BITSIZE(long) - 1 ? 1 : -1];
+  char clrsb6[__builtin_clrsbll(~0LL) == BITSIZE(long long) - 1 ? 1 : -1];
+  char clrsb7[__builtin_clrsb(1) == BITSIZE(int) - 2 ? 1 : -1];
+  char clrsb8[__builtin_clrsb(~1) == BITSIZE(int) - 2 ? 1 : -1];
+  char clrsb9[__builtin_clrsb(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];
+  char clrsb10[__builtin_clrsb(~(1 << (BITSIZE(int) - 1))) == 0 ? 1 : -1];
+  char clrsb11[__builtin_clrsb(0xf) == BITSIZE(int) - 5 ? 1 : -1];
+  char clrsb12[__builtin_clrsb(~0x1f) == BITSIZE(int) - 6 ? 1 : -1];
+}

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


[clang] [clang][Interp] Implement __builtin_clrsb (PR #72243)

2023-11-14 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


2 Files Affected:

- (modified) clang/lib/AST/Interp/InterpBuiltin.cpp (+16) 
- (modified) clang/test/AST/Interp/builtin-functions.cpp (+16-1) 


``diff
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index f26d298f5b60045..69383d37440f704 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -439,6 +439,15 @@ static bool interp__builtin_popcount(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_clrsb(InterpState &S, CodePtr OpPC,
+  const InterpFrame *Frame,
+  const Function *Func, const CallExpr *Call) {
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  APSInt Val = peekToAPSInt(S.Stk, ArgT);
+  pushInt(S, Val.getBitWidth() - Val.getSignificantBits());
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -576,6 +585,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return retInt(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_clrsb:
+  case Builtin::BI__builtin_clrsbl:
+  case Builtin::BI__builtin_clrsbll:
+if (interp__builtin_clrsb(S, OpPC, Frame, F, Call))
+  return retInt(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index a78a0fbdf11b1d7..245d775bd366d53 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -274,6 +274,7 @@ namespace SourceLocation {
   }
 }
 
+#define BITSIZE(x) (sizeof(x) * 8)
 namespace popcount {
   static_assert(__builtin_popcount(~0u) == __CHAR_BIT__ * sizeof(unsigned 
int), "");
   static_assert(__builtin_popcount(0) == 0, "");
@@ -283,7 +284,6 @@ namespace popcount {
   static_assert(__builtin_popcountll(0) == 0, "");
 
   /// From test/Sema/constant-builtins-2.c
-#define BITSIZE(x) (sizeof(x) * 8)
   char popcount1[__builtin_popcount(0) == 0 ? 1 : -1];
   char popcount2[__builtin_popcount(0xF0F0) == 8 ? 1 : -1];
   char popcount3[__builtin_popcount(~0) == BITSIZE(int) ? 1 : -1];
@@ -295,3 +295,18 @@ namespace popcount {
   char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
   char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
 }
+
+namespace clrsb {
+  char clrsb1[__builtin_clrsb(0) == BITSIZE(int) - 1 ? 1 : -1];
+  char clrsb2[__builtin_clrsbl(0L) == BITSIZE(long) - 1 ? 1 : -1];
+  char clrsb3[__builtin_clrsbll(0LL) == BITSIZE(long long) - 1 ? 1 : -1];
+  char clrsb4[__builtin_clrsb(~0) == BITSIZE(int) - 1 ? 1 : -1];
+  char clrsb5[__builtin_clrsbl(~0L) == BITSIZE(long) - 1 ? 1 : -1];
+  char clrsb6[__builtin_clrsbll(~0LL) == BITSIZE(long long) - 1 ? 1 : -1];
+  char clrsb7[__builtin_clrsb(1) == BITSIZE(int) - 2 ? 1 : -1];
+  char clrsb8[__builtin_clrsb(~1) == BITSIZE(int) - 2 ? 1 : -1];
+  char clrsb9[__builtin_clrsb(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];
+  char clrsb10[__builtin_clrsb(~(1 << (BITSIZE(int) - 1))) == 0 ? 1 : -1];
+  char clrsb11[__builtin_clrsb(0xf) == BITSIZE(int) - 5 ? 1 : -1];
+  char clrsb12[__builtin_clrsb(~0x1f) == BITSIZE(int) - 6 ? 1 : -1];
+}

``




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


[clang-tools-extra] [clang-tidy] Improved readability-bool-conversion to be more consistent when using parentheses (PR #72068)

2023-11-14 Thread Félix-Antoine Constantin via cfe-commits
https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/72068

From 65eaa9e01bcd32dccf1e0c9bd3f2bdd3e53ccb2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Sun, 12 Nov 2023 16:07:13 -0500
Subject: [PATCH 1/3] [clang-tidy] Improved readability-bool-conversion to be
 more consistent when using parentheses

Fixes #71852
---
 .../ImplicitBoolConversionCheck.cpp   |  5 ++--
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../readability/implicit-bool-conversion.cpp  | 30 +++
 3 files changed, 37 insertions(+), 2 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 69e6d73c4fcd7bb..f0fca30de3b3c4d 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -152,7 +152,8 @@ StringRef getEquivalentBoolLiteralForExpr(const Expr 
*Expression,
 return "false";
   }
 
-  if (const auto *IntLit = dyn_cast(Expression)) {
+  if (const auto *IntLit =
+  dyn_cast(Expression->IgnoreParens())) {
 return (IntLit->getValue() == 0) ? "false" : "true";
   }
 
@@ -385,7 +386,7 @@ void ImplicitBoolConversionCheck::handleCastFromBool(
   << DestType;
 
   if (const auto *BoolLiteral =
-  dyn_cast(Cast->getSubExpr())) {
+  dyn_cast(Cast->getSubExpr()->IgnoreParens())) {
 Diag << tooling::fixit::createReplacement(
 *Cast, getEquivalentForBoolLiteral(BoolLiteral, DestType, Context));
   } else {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index f49c412118e7d98..ab9ef8cdfb37a00 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -412,6 +412,10 @@ Changes in existing checks
   do-while loops into account for the `AllowIntegerConditions` and
   `AllowPointerConditions` options.
 
+- Improved :doc:`readability-implicit-bool-conversion
+  ` check to provide
+  consistent suggestions when parentheses are added to the return value. 
+
 - Improved :doc:`readability-non-const-parameter
   ` check to ignore
   false-positives in initializer list of record.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
index 323cf813c047000..f7f5d506a9ce0e0 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.cpp
@@ -472,6 +472,36 @@ bool f(S& s) {
 
 } // namespace ignore_1bit_bitfields
 
+int implicitConversionReturnInt()
+{
+return true;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicit conversion bool -> 
'int'
+// CHECK-FIXES: return 1
+}
+
+int implicitConversionReturnIntWithParens()
+{
+return (true);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicit conversion bool -> 
'int'
+// CHECK-FIXES: return 1
+}
+
+
+bool implicitConversionReturnBool()
+{
+return 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicit conversion 'int' -> 
bool
+// CHECK-FIXES: return true
+}
+
+bool implicitConversionReturnBoolWithParens()
+{
+return (1);
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicit conversion 'int' -> 
bool
+// CHECK-FIXES: return true
+}
+
+
 namespace PR47000 {
   int to_int(bool x) { return int{x}; }
 

From f45ae6f72eb4585620bc567632c0d5b8019db79c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 
Date: Mon, 13 Nov 2023 20:42:43 -0500
Subject: [PATCH 2/3] fixup! [clang-tidy] Improved readability-bool-conversion
 to be more consistent when using parentheses

Updated ReleaseNotes.rst
---
 clang-tools-extra/docs/ReleaseNotes.rst | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ab9ef8cdfb37a00..2d1c222b5eaa114 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -410,11 +410,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to take
   do-while loops into account for the `AllowIntegerConditions` and
-  `AllowPointerConditions` options.
-
-- Improved :doc:`readability-implicit-bool-conversion
-  ` check to provide
-  consistent suggestions when parentheses are added to the return value. 
+  `AllowPointerConditions` options. It also now provides more consistent
+  suggestions when parentheses are added to the return value.
 
 - Improved :doc:`readability-non-const-parameter
   ` check to ignore

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/

[clang] ExtractAPI: use zero-based indices for line/column in symbol graph (PR #71753)

2023-11-14 Thread Daniel Grumberg via cfe-commits
https://github.com/daniel-grumberg closed 
https://github.com/llvm/llvm-project/pull/71753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 6353787 - ExtractAPI: use zero-based indices for line/column in symbol graph (#71753)

2023-11-14 Thread via cfe-commits
Author: QuietMisdreavus
Date: 2023-11-14T11:46:12Z
New Revision: 63537872aefe845ba40770112d0a2cf0927f27b8

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

LOG: ExtractAPI: use zero-based indices for line/column in symbol graph (#71753)

Other implementations of the symbol graph format use zero-based indices
for source locations, which causes problems when combined with clang's
current one-based indices. This commit sets ExtractAPI's symbol graph
output to use zero-based indices to align with other implementations.

rdar://107639783

Added: 


Modified: 
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
clang/test/ExtractAPI/anonymous_record_no_typedef.c
clang/test/ExtractAPI/availability.c
clang/test/ExtractAPI/bool.c
clang/test/ExtractAPI/bool.cpp
clang/test/ExtractAPI/class.cpp
clang/test/ExtractAPI/class_template.cpp
clang/test/ExtractAPI/class_template_param_inheritance.cpp
clang/test/ExtractAPI/class_template_partial_spec.cpp
clang/test/ExtractAPI/class_template_spec.cpp
clang/test/ExtractAPI/concept.cpp
clang/test/ExtractAPI/constructor_destructor.cpp
clang/test/ExtractAPI/conversions.cpp
clang/test/ExtractAPI/emit-symbol-graph/multi_file.c
clang/test/ExtractAPI/emit-symbol-graph/single_file.c
clang/test/ExtractAPI/enum.c
clang/test/ExtractAPI/field_template.cpp
clang/test/ExtractAPI/function_noexcepts.cpp
clang/test/ExtractAPI/global_func_template.cpp
clang/test/ExtractAPI/global_func_template_spec.cpp
clang/test/ExtractAPI/global_record.c
clang/test/ExtractAPI/global_record_multifile.c
clang/test/ExtractAPI/global_var_template.cpp
clang/test/ExtractAPI/global_var_template_partial_spec.cpp
clang/test/ExtractAPI/global_var_template_spec.cpp
clang/test/ExtractAPI/known_files_only.c
clang/test/ExtractAPI/language.c
clang/test/ExtractAPI/macro_undefined.c
clang/test/ExtractAPI/macros.c
clang/test/ExtractAPI/method_template.cpp
clang/test/ExtractAPI/method_template_spec.cpp
clang/test/ExtractAPI/methods.cpp
clang/test/ExtractAPI/multiple_inheritance.cpp
clang/test/ExtractAPI/namespace.cpp
clang/test/ExtractAPI/nested_namespaces.cpp
clang/test/ExtractAPI/objc_category.m
clang/test/ExtractAPI/objc_id_protocol.m
clang/test/ExtractAPI/objc_instancetype.m
clang/test/ExtractAPI/objc_interface.m
clang/test/ExtractAPI/objc_module_category.m
clang/test/ExtractAPI/objc_property.m
clang/test/ExtractAPI/objc_protocol.m
clang/test/ExtractAPI/objc_various_categories.m
clang/test/ExtractAPI/operator_overload.cpp
clang/test/ExtractAPI/relative_include.m
clang/test/ExtractAPI/simple_inheritance.cpp
clang/test/ExtractAPI/struct.c
clang/test/ExtractAPI/typedef.c
clang/test/ExtractAPI/typedef_anonymous_record.c
clang/test/ExtractAPI/typedef_chain.c
clang/test/ExtractAPI/typedef_struct_enum.c
clang/test/ExtractAPI/underscored.c

Removed: 




diff  --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp 
b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index f757522ef8e49db..931933b2bd1ac0e 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -109,8 +109,8 @@ Object serializeSourcePosition(const PresumedLoc &Loc) {
   assert(Loc.isValid() && "invalid source position");
 
   Object SourcePosition;
-  SourcePosition["line"] = Loc.getLine();
-  SourcePosition["character"] = Loc.getColumn();
+  SourcePosition["line"] = Loc.getLine() - 1;
+  SourcePosition["character"] = Loc.getColumn() - 1;
 
   return SourcePosition;
 }

diff  --git a/clang/test/ExtractAPI/anonymous_record_no_typedef.c 
b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
index 0890e3cbdb6d085..0e50f4a0948c94a 100644
--- a/clang/test/ExtractAPI/anonymous_record_no_typedef.c
+++ b/clang/test/ExtractAPI/anonymous_record_no_typedef.c
@@ -105,12 +105,12 @@ struct Vehicle {
   {
 "range": {
   "end": {
-"character": 29,
-"line": 3
+"character": 28,
+"line": 2
   },
   "start": {
-"character": 9,
-"line": 3
+"character": 8,
+"line": 2
   }
 },
 "text": "The type of vehicle."
@@ -127,8 +127,8 @@ struct Vehicle {
   },
   "location": {
 "position": {
-  "character": 5,
-  "line": 4
+  "character": 4,
+  "line": 3
 },
 "uri": "file://INPUT_DIR/input.h"
   },
@@ -163,8 +163,8 @@ struct Vehicle {
   },
   "location": {
 

[clang] [clang-format] Option to ignore PP directives (PR #70338)

2023-11-14 Thread via cfe-commits
https://github.com/tomekpaszek updated 
https://github.com/llvm/llvm-project/pull/70338

>From b5ba0b3fde2c6662e19dfdf96a787621ec767460 Mon Sep 17 00:00:00 2001
From: Tomek Paszek 
Date: Sat, 11 Nov 2023 19:38:00 +0100
Subject: [PATCH 1/9] Added an option to ignore macro definitions.

---
 clang/include/clang/Format/Format.h |  5 +
 clang/lib/Format/Format.cpp |  2 ++
 clang/lib/Format/UnwrappedLineFormatter.cpp |  2 ++
 clang/unittests/Format/ConfigParseTest.cpp  |  3 ++-
 clang/unittests/Format/FormatTest.cpp   | 16 
 5 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3e9d1915badd87f..3af7241441c8b13 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2442,6 +2442,10 @@ struct FormatStyle {
   /// 
`_
   /// \version 13
   std::vector IfMacros;
+  
+  /// Ignore formatting in preprocessor definitions.
+  /// \version 18
+  bool IgnorePPDefinitions;
 
   /// Specify whether access modifiers should have their own indentation level.
   ///
@@ -4719,6 +4723,7 @@ struct FormatStyle {
R.IncludeStyle.IncludeIsMainRegex &&
IncludeStyle.IncludeIsMainSourceRegex ==
R.IncludeStyle.IncludeIsMainSourceRegex &&
+   IgnorePPDefinitions == R.IgnorePPDefinitions &&
IndentAccessModifiers == R.IndentAccessModifiers &&
IndentCaseBlocks == R.IndentCaseBlocks &&
IndentCaseLabels == R.IndentCaseLabels &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index edb33f4af4defef..6e5ec754dfdcdd9 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1000,6 +1000,7 @@ template <> struct MappingTraits {
 IO.mapOptional("FixNamespaceComments", Style.FixNamespaceComments);
 IO.mapOptional("ForEachMacros", Style.ForEachMacros);
 IO.mapOptional("IfMacros", Style.IfMacros);
+IO.mapOptional("IgnorePPDefinitions", Style.IgnorePPDefinitions);
 IO.mapOptional("IncludeBlocks", Style.IncludeStyle.IncludeBlocks);
 IO.mapOptional("IncludeCategories", Style.IncludeStyle.IncludeCategories);
 IO.mapOptional("IncludeIsMainRegex", 
Style.IncludeStyle.IncludeIsMainRegex);
@@ -1504,6 +1505,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.ForEachMacros.push_back("Q_FOREACH");
   LLVMStyle.ForEachMacros.push_back("BOOST_FOREACH");
   LLVMStyle.IfMacros.push_back("KJ_IF_MAYBE");
+  LLVMStyle.IgnorePPDefinitions = false;
   LLVMStyle.IncludeStyle.IncludeCategories = {
   {"^\"(llvm|llvm-c|clang|clang-c)/", 2, 0, false},
   {"^(<|\"(gtest|gmock|isl|json)/)", 3, 0, false},
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 280485d9a90d1bf..bbf6383ff7673f6 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1355,6 +1355,8 @@ unsigned UnwrappedLineFormatter::format(
 bool FixIndentation = (FixBadIndentation || ContinueFormatting) &&
   Indent != TheLine.First->OriginalColumn;
 bool ShouldFormat = TheLine.Affected || FixIndentation;
+if (Style.IgnorePPDefinitions && TheLine.Type == LT_PreprocessorDirective)
+  ShouldFormat = false;
 // We cannot format this line; if the reason is that the line had a
 // parsing error, remember that.
 if (ShouldFormat && TheLine.Type == LT_Invalid && Status) {
diff --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index f90ed178d99c286..110df624d44573c 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -166,6 +166,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
+  CHECK_PARSE_BOOL(IgnorePPDefinitions);
   CHECK_PARSE_BOOL(IndentAccessModifiers);
   CHECK_PARSE_BOOL(IndentCaseLabels);
   CHECK_PARSE_BOOL(IndentCaseBlocks);
@@ -198,7 +199,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
   CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
   CHECK_PARSE_BOOL(VerilogBreakBetweenInstancePorts);
-
+  
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements, Enabled);
   CHECK_PARSE_NESTED_BOOL(AlignConsecutiveShortCaseStatements,
   AcrossEmptyLines);
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index b2d84f2ee389551..659132dcb9c3970 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24153,6 +24153,22 @@ TEST_F(FormatTest, WhitespaceSensitiveMacros) {
   verifyNoChange("

[clang-tools-extra] [include-cleaner] Make sure exports of stdlib also works for physical files (PR #72246)

2023-11-14 Thread kadir çetinkaya via cfe-commits
https://github.com/kadircet created 
https://github.com/llvm/llvm-project/pull/72246

This was creating discrepancy in cases where we might have a physical
file entry (e.g. because we followed a source location from a stdlib
file) and tried to find its exporters.


From 49ea3ae3468c5d67b2b6b03339d642e25d4fa6b0 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Tue, 14 Nov 2023 13:08:52 +0100
Subject: [PATCH] [include-cleaner] Make sure exports of stdlib also works for
 physical files

This was creating discrepancy in cases where we might have a physical
file entry (e.g. because we followed a source location from a stdlib
file) and tried to find its exporters.
---
 .../include-cleaner/lib/Record.cpp| 26 +--
 .../include-cleaner/unittests/RecordTest.cpp  |  2 ++
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp 
b/clang-tools-extra/include-cleaner/lib/Record.cpp
index 7a8e10a9c675496..a98129452e2bdde 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -232,6 +232,17 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   void checkForExport(FileID IncludingFile, int HashLine,
   std::optional IncludedHeader,
   OptionalFileEntryRef IncludedFile) {
+auto AddExport = [&] {
+  auto ExportingFileName = SM.getFileEntryForID(IncludingFile)->getName();
+  if (IncludedFile) {
+Out->IWYUExportBy[IncludedFile->getUniqueID()].push_back(
+ExportingFileName);
+  }
+  if (IncludedHeader && IncludedHeader->kind() == Header::Standard) {
+Out->StdIWYUExportBy[IncludedHeader->standard()].push_back(
+ExportingFileName);
+  }
+};
 if (ExportStack.empty())
   return;
 auto &Top = ExportStack.back();
@@ -240,20 +251,7 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
 // Make sure current include is covered by the export pragma.
 if ((Top.Block && HashLine > Top.SeenAtLine) ||
 Top.SeenAtLine == HashLine) {
-  if (IncludedHeader) {
-switch (IncludedHeader->kind()) {
-case Header::Physical:
-  Out->IWYUExportBy[IncludedHeader->physical().getUniqueID()]
-  .push_back(Top.Path);
-  break;
-case Header::Standard:
-  Out->StdIWYUExportBy[IncludedHeader->standard()].push_back(Top.Path);
-  break;
-case Header::Verbatim:
-  assert(false && "unexpected Verbatim header");
-  break;
-}
-  }
+  AddExport();
   // main-file #include with export pragma should never be removed.
   if (Top.SeenAtFile == SM.getMainFileID() && IncludedFile)
 Out->ShouldKeep.insert(IncludedFile->getUniqueID());
diff --git a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp 
b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
index 36850731d514539..dfefa66887b0f24 100644
--- a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -452,6 +452,8 @@ TEST_F(PragmaIncludeTest, IWYUExportForStandardHeaders) {
   auto &FM = Processed.fileManager();
   EXPECT_THAT(PI.getExporters(*tooling::stdlib::Header::named(""), FM),
   testing::UnorderedElementsAre(FileNamed("export.h")));
+  EXPECT_THAT(PI.getExporters(llvm::cantFail(FM.getFileRef("string")), FM),
+  testing::UnorderedElementsAre(FileNamed("export.h")));
 }
 
 TEST_F(PragmaIncludeTest, IWYUExportBlock) {

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


[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-11-14 Thread Ulrich Weigand via cfe-commits

@@ -1026,6 +1030,78 @@ void SystemZAsmPrinter::emitADASection() {
   OutStreamer->popSection();
 }
 
+static uint32_t getProductVersion(Module &M) {
+  if (auto *VersionVal = cast_or_null(
+  M.getModuleFlag("zos_product_major_version")))
+return cast(VersionVal->getValue())->getZExtValue();

uweigand wrote:

I think instead of these two casts, these days you're supposed to use the new 
`mdconst` interface, e.g. like
```
if (auto *VersionVal = mdconst::extract_or_null(
M.getModuleFlag("zos_product_major_version"))
```


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


[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-11-14 Thread Ulrich Weigand via cfe-commits

@@ -1026,6 +1030,78 @@ void SystemZAsmPrinter::emitADASection() {
   OutStreamer->popSection();
 }
 
+static uint32_t getProductVersion(Module &M) {
+  if (auto *VersionVal = cast_or_null(
+  M.getModuleFlag("zos_product_major_version")))
+return cast(VersionVal->getValue())->getZExtValue();
+  return LLVM_VERSION_MAJOR;
+}
+
+static uint32_t getProductRelease(Module &M) {
+  if (auto *ReleaseVal = cast_or_null(
+  M.getModuleFlag("zos_product_minor_version")))
+return cast(ReleaseVal->getValue())->getZExtValue();
+  return LLVM_VERSION_MINOR;
+}
+
+static uint32_t getProductPatch(Module &M) {
+  if (auto *PatchVal = cast_or_null(
+  M.getModuleFlag("zos_product_patchlevel")))
+return cast(PatchVal->getValue())->getZExtValue();
+  return LLVM_VERSION_PATCH;
+}
+
+static time_t getTranslationTime(Module &M) {
+  std::time_t Time = 0;
+  if (auto *Val = cast_or_null(
+  M.getModuleFlag("zos_translation_time"))) {
+long SecondsSinceEpoch = 
cast(Val->getValue())->getSExtValue();
+Time = static_cast(SecondsSinceEpoch);
+  }
+  return Time;
+}
+
+void SystemZAsmPrinter::emitIDRLSection(Module &M) {
+  OutStreamer->pushSection();
+  OutStreamer->switchSection(getObjFileLowering().getIDRLSection());
+  constexpr unsigned IDRLDataLength = 30;
+  std::time_t Time = getTranslationTime(M);
+
+  uint32_t ProductVersion = getProductVersion(M);
+  uint32_t ProductRelease = getProductRelease(M);
+
+  std::string ProductID;
+  if (auto *MD = M.getModuleFlag("zos_product_id"))
+ProductID = cast(MD)->getString().str();
+
+  if (ProductID.empty()) {
+char ProductIDFormatted[11]; // 10 + null.
+snprintf(ProductIDFormatted, sizeof(ProductIDFormatted), "LLVM  %02d%02d",
+ ProductVersion, ProductRelease);
+ProductID = ProductIDFormatted;
+  }
+
+  // Remove - from Product Id, which makes it consistent with legacy.
+  // The binder expects alphanumeric characters only.
+  std::size_t DashFound = ProductID.find("-");
+  if (DashFound != std::string::npos)
+ProductID.erase(ProductID.begin() + DashFound);

uweigand wrote:

Can there be multiple dashes, and if so, should they all be removed?   What 
about other disallowed characters?  At this point the ProductID could be 
user-provided in the IR, so shouldn't be careful here?

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


[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-11-14 Thread Ulrich Weigand via cfe-commits
https://github.com/uweigand edited 
https://github.com/llvm/llvm-project/pull/68926
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-11-14 Thread Ulrich Weigand via cfe-commits

@@ -1026,6 +1030,78 @@ void SystemZAsmPrinter::emitADASection() {
   OutStreamer->popSection();
 }
 
+static uint32_t getProductVersion(Module &M) {
+  if (auto *VersionVal = cast_or_null(
+  M.getModuleFlag("zos_product_major_version")))
+return cast(VersionVal->getValue())->getZExtValue();
+  return LLVM_VERSION_MAJOR;
+}
+
+static uint32_t getProductRelease(Module &M) {
+  if (auto *ReleaseVal = cast_or_null(
+  M.getModuleFlag("zos_product_minor_version")))
+return cast(ReleaseVal->getValue())->getZExtValue();
+  return LLVM_VERSION_MINOR;
+}
+
+static uint32_t getProductPatch(Module &M) {
+  if (auto *PatchVal = cast_or_null(
+  M.getModuleFlag("zos_product_patchlevel")))
+return cast(PatchVal->getValue())->getZExtValue();
+  return LLVM_VERSION_PATCH;
+}
+
+static time_t getTranslationTime(Module &M) {
+  std::time_t Time = 0;
+  if (auto *Val = cast_or_null(
+  M.getModuleFlag("zos_translation_time"))) {
+long SecondsSinceEpoch = 
cast(Val->getValue())->getSExtValue();
+Time = static_cast(SecondsSinceEpoch);
+  }
+  return Time;
+}
+
+void SystemZAsmPrinter::emitIDRLSection(Module &M) {
+  OutStreamer->pushSection();
+  OutStreamer->switchSection(getObjFileLowering().getIDRLSection());
+  constexpr unsigned IDRLDataLength = 30;
+  std::time_t Time = getTranslationTime(M);
+
+  uint32_t ProductVersion = getProductVersion(M);
+  uint32_t ProductRelease = getProductRelease(M);
+
+  std::string ProductID;
+  if (auto *MD = M.getModuleFlag("zos_product_id"))
+ProductID = cast(MD)->getString().str();
+
+  if (ProductID.empty()) {
+char ProductIDFormatted[11]; // 10 + null.
+snprintf(ProductIDFormatted, sizeof(ProductIDFormatted), "LLVM  %02d%02d",
+ ProductVersion, ProductRelease);

uweigand wrote:

In this case, `ProductVersion` and `ProductRelease` seem to be present twice, 
first as part of the ID and then again separately.  (This is different from 
when clang sets the ID as just "clang".)  Is this deliberate?

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


[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-11-14 Thread Ulrich Weigand via cfe-commits

@@ -1026,6 +1030,78 @@ void SystemZAsmPrinter::emitADASection() {
   OutStreamer->popSection();
 }
 
+static uint32_t getProductVersion(Module &M) {
+  if (auto *VersionVal = cast_or_null(
+  M.getModuleFlag("zos_product_major_version")))
+return cast(VersionVal->getValue())->getZExtValue();
+  return LLVM_VERSION_MAJOR;
+}
+
+static uint32_t getProductRelease(Module &M) {
+  if (auto *ReleaseVal = cast_or_null(
+  M.getModuleFlag("zos_product_minor_version")))
+return cast(ReleaseVal->getValue())->getZExtValue();
+  return LLVM_VERSION_MINOR;
+}
+
+static uint32_t getProductPatch(Module &M) {
+  if (auto *PatchVal = cast_or_null(
+  M.getModuleFlag("zos_product_patchlevel")))
+return cast(PatchVal->getValue())->getZExtValue();
+  return LLVM_VERSION_PATCH;
+}
+
+static time_t getTranslationTime(Module &M) {
+  std::time_t Time = 0;
+  if (auto *Val = cast_or_null(
+  M.getModuleFlag("zos_translation_time"))) {
+long SecondsSinceEpoch = 
cast(Val->getValue())->getSExtValue();
+Time = static_cast(SecondsSinceEpoch);
+  }
+  return Time;
+}
+
+void SystemZAsmPrinter::emitIDRLSection(Module &M) {
+  OutStreamer->pushSection();
+  OutStreamer->switchSection(getObjFileLowering().getIDRLSection());
+  constexpr unsigned IDRLDataLength = 30;
+  std::time_t Time = getTranslationTime(M);
+
+  uint32_t ProductVersion = getProductVersion(M);
+  uint32_t ProductRelease = getProductRelease(M);
+
+  std::string ProductID;
+  if (auto *MD = M.getModuleFlag("zos_product_id"))
+ProductID = cast(MD)->getString().str();
+
+  if (ProductID.empty()) {
+char ProductIDFormatted[11]; // 10 + null.
+snprintf(ProductIDFormatted, sizeof(ProductIDFormatted), "LLVM  %02d%02d",
+ ProductVersion, ProductRelease);
+ProductID = ProductIDFormatted;
+  }
+
+  // Remove - from Product Id, which makes it consistent with legacy.
+  // The binder expects alphanumeric characters only.
+  std::size_t DashFound = ProductID.find("-");
+  if (DashFound != std::string::npos)
+ProductID.erase(ProductID.begin() + DashFound);
+
+  SmallString TempStr;
+  raw_svector_ostream O(TempStr);
+  O << formatv("{0}{1,0-2:d}{2,0-2:d}{3:%Y-%m-%d %H:%M:%S}", ProductID.c_str(),
+   ProductVersion, ProductRelease, llvm::sys::toUtcTime(Time));

uweigand wrote:

Can this overflow?  In the default case above, you ensure the ProductID has 10 
bytes.  But in the case where the ID comes from the IR, its length can be 
anything, and is not checked here.

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


[llvm] [clang] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-11-14 Thread Ulrich Weigand via cfe-commits

@@ -976,6 +976,40 @@ void CodeGenModule::Release() {
   Context.getTypeSizeInChars(Context.getWideCharType()).getQuantity();
   getModule().addModuleFlag(llvm::Module::Error, "wchar_size", WCharWidth);
 
+  if (getTriple().isOSzOS()) {
+getModule().addModuleFlag(llvm::Module::Warning,
+  "zos_product_major_version",
+  uint32_t(CLANG_VERSION_MAJOR));
+getModule().addModuleFlag(llvm::Module::Warning,
+  "zos_product_minor_version",
+  uint32_t(CLANG_VERSION_MINOR));
+getModule().addModuleFlag(llvm::Module::Warning, "zos_product_patchlevel",
+  uint32_t(CLANG_VERSION_PATCHLEVEL));
+std::string ProductId;
+#ifdef CLANG_VENDOR
+ProductId = #CLANG_VENDOR;
+#else
+ProductId = "clang";
+#endif
+getModule().addModuleFlag(llvm::Module::Error, "zos_product_id",
+  llvm::MDString::get(VMContext, ProductId));
+
+// Record the language because we need it for the PPA2.
+StringRef lang_str = languageToString(
+LangStandard::getLangStandardForKind(LangOpts.LangStd).Language);
+getModule().addModuleFlag(llvm::Module::Error, "zos_cu_language",
+  llvm::MDString::get(VMContext, lang_str));
+
+time_t TT = PreprocessorOpts.SourceDateEpoch
+? *PreprocessorOpts.SourceDateEpoch
+: std::time(nullptr);
+getModule().addModuleFlag(llvm::Module::Max, "zos_translation_time",
+  static_cast(TT));
+
+getModule().addModuleFlag(llvm::Module::Error, "zos_le_char_mode",
+  llvm::MDString::get(VMContext, "ascii"));

uweigand wrote:

Is "ascii" the correct default here?   In either case, please add a comment 
stating multiple modes will be supported in the future, so we understand why 
this code is here.

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


[clang] [llvm] [SystemZ][z/OS] This change adds support for the PPA2 section in zOS (PR #68926)

2023-11-14 Thread Ulrich Weigand via cfe-commits
https://github.com/uweigand commented:

Please find a couple of additional comments inline, related to module flag 
processing.

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


[clang] clang/CodeGen/RISCV: test lowering of math builtins (PR #71399)

2023-11-14 Thread Ramkumar Ramachandra via cfe-commits
artagnon wrote:

Gentle ping.

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


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread Owen Pan via cfe-commits
https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/72251

Fixed #69610.

>From 8e61a470fc7e4cf11a6cf285668a7f9eca72702c Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Tue, 14 Nov 2023 05:05:14 -0800
Subject: [PATCH] [clang-format] Handle constrained auto in QualifierAlignment

Fixed #69610.
---
 clang/lib/Format/QualifierAlignmentFixer.cpp  |  5 +
 clang/unittests/Format/QualifierFixerTest.cpp | 10 ++
 2 files changed, 15 insertions(+)

diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 7167e50ec724eab..72464d367153934 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -345,6 +345,8 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 TypeToken = Next->getNextNonComment()->getNextNonComment();
   }
 }
+if (Next->is(tok::kw_auto))
+  TypeToken = Next;
 
 // Place the Qualifier at the end of the list of qualifiers.
 while (isQualifier(TypeToken->getNextNonComment())) {
@@ -446,6 +448,9 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
 return false;
   }
 
+  if (Tok->endsSequence(tok::kw_auto, tok::identifier))
+return false;
+
   return true;
 };
 
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 73814e7414f5e7d..a56323a88f4a04d 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -352,6 +352,11 @@ TEST_F(QualifierFixerTest, RightQualifier) {
   verifyFormat("auto const &ir = i;", "const auto &ir = i;", Style);
   verifyFormat("auto const *ip = &i;", "const auto *ip = &i;", Style);
 
+  verifyFormat("void f(Concept auto const &x);",
+   "void f(const Concept auto &x);", Style);
+  verifyFormat("void f(std::integral auto const &x);",
+   "void f(const std::integral auto &x);", Style);
+
   verifyFormat("Foo const> P;\n#if 0\n#else\n#endif",
"Foo> P;\n#if 0\n#else\n#endif", Style);
 
@@ -653,6 +658,11 @@ TEST_F(QualifierFixerTest, LeftQualifier) {
   verifyFormat("const auto &ir = i;", "auto const &ir = i;", Style);
   verifyFormat("const auto *ip = &i;", "auto const *ip = &i;", Style);
 
+  verifyFormat("void f(const Concept auto &x);",
+   "void f(Concept auto const &x);", Style);
+  verifyFormat("void f(const std::integral auto &x);",
+   "void f(std::integral auto const &x);", Style);
+
   verifyFormat("Foo> P;\n#if 0\n#else\n#endif",
"Foo const> P;\n#if 0\n#else\n#endif", Style);
 

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


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixed #69610.

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


2 Files Affected:

- (modified) clang/lib/Format/QualifierAlignmentFixer.cpp (+5) 
- (modified) clang/unittests/Format/QualifierFixerTest.cpp (+10) 


``diff
diff --git a/clang/lib/Format/QualifierAlignmentFixer.cpp 
b/clang/lib/Format/QualifierAlignmentFixer.cpp
index 7167e50ec724eab..72464d367153934 100644
--- a/clang/lib/Format/QualifierAlignmentFixer.cpp
+++ b/clang/lib/Format/QualifierAlignmentFixer.cpp
@@ -345,6 +345,8 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeRight(
 TypeToken = Next->getNextNonComment()->getNextNonComment();
   }
 }
+if (Next->is(tok::kw_auto))
+  TypeToken = Next;
 
 // Place the Qualifier at the end of the list of qualifiers.
 while (isQualifier(TypeToken->getNextNonComment())) {
@@ -446,6 +448,9 @@ const FormatToken 
*LeftRightQualifierAlignmentFixer::analyzeLeft(
 return false;
   }
 
+  if (Tok->endsSequence(tok::kw_auto, tok::identifier))
+return false;
+
   return true;
 };
 
diff --git a/clang/unittests/Format/QualifierFixerTest.cpp 
b/clang/unittests/Format/QualifierFixerTest.cpp
index 73814e7414f5e7d..a56323a88f4a04d 100644
--- a/clang/unittests/Format/QualifierFixerTest.cpp
+++ b/clang/unittests/Format/QualifierFixerTest.cpp
@@ -352,6 +352,11 @@ TEST_F(QualifierFixerTest, RightQualifier) {
   verifyFormat("auto const &ir = i;", "const auto &ir = i;", Style);
   verifyFormat("auto const *ip = &i;", "const auto *ip = &i;", Style);
 
+  verifyFormat("void f(Concept auto const &x);",
+   "void f(const Concept auto &x);", Style);
+  verifyFormat("void f(std::integral auto const &x);",
+   "void f(const std::integral auto &x);", Style);
+
   verifyFormat("Foo const> P;\n#if 0\n#else\n#endif",
"Foo> P;\n#if 0\n#else\n#endif", Style);
 
@@ -653,6 +658,11 @@ TEST_F(QualifierFixerTest, LeftQualifier) {
   verifyFormat("const auto &ir = i;", "auto const &ir = i;", Style);
   verifyFormat("const auto *ip = &i;", "auto const *ip = &i;", Style);
 
+  verifyFormat("void f(const Concept auto &x);",
+   "void f(Concept auto const &x);", Style);
+  verifyFormat("void f(const std::integral auto &x);",
+   "void f(std::integral auto const &x);", Style);
+
   verifyFormat("Foo> P;\n#if 0\n#else\n#endif",
"Foo const> P;\n#if 0\n#else\n#endif", Style);
 

``




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


[clang] [clang-format] Handle constrained auto in QualifierAlignment (PR #72251)

2023-11-14 Thread Emilia Kond via cfe-commits
https://github.com/rymiel approved this pull request.

A hooray for getting rid of invalid-code-generation

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Ilya Biryukov via cfe-commits

@@ -10088,9 +10088,13 @@ static bool allowAmbiguity(ASTContext &Context, const 
FunctionDecl *F1,
const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
-  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation() &&
-  declaresSameEntity(F1->getPrimaryTemplate(), F2->getPrimaryTemplate())) {
-return true;
+  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation()) {
+auto PT1 = F1->getPrimaryTemplate();
+auto PT2 = F2->getPrimaryTemplate();
+if (declaresSameEntity(PT1, PT2) ||

ilya-biryukov wrote:

Could we remove the check `getPrimaryTemplate` and instead only look at 
`getInstantiatedFromMemberTemplate`?

If `getPrimaryTemplate` matches, the `getInstantiatedFromMemberTemplate` will 
always match as well, right?

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov edited 
https://github.com/llvm/llvm-project/pull/72213
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][SVE2] Add builtins for moving multi-vectors to/from ZA (PR #71191)

2023-11-14 Thread Sam Tebbs via cfe-commits
https://github.com/SamTebbs33 approved this pull request.

LGTM

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Ilya Biryukov via cfe-commits

@@ -10088,9 +10088,13 @@ static bool allowAmbiguity(ASTContext &Context, const 
FunctionDecl *F1,
const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
-  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation() &&
-  declaresSameEntity(F1->getPrimaryTemplate(), F2->getPrimaryTemplate())) {
-return true;
+  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation()) {
+auto PT1 = F1->getPrimaryTemplate();
+auto PT2 = F2->getPrimaryTemplate();
+if (declaresSameEntity(PT1, PT2) ||

ilya-biryukov wrote:

I missed that `getInstantiatedFromMemberTemplate` will be null for non-member 
template function instantiations.
So I guess we still need it.

Could we add a test with two non-member templates that do **not** match each 
other and check the ambiguity is still there?

```
template  bool operator ==(Foo, Foo);
template  bool operator ==(Foo, Foo);

Foo() == Foo;
```

Because it's weird that `declaresSameEntity(nullptr, nullptr)` returns `false`, 
I'm worried that we miss a point where someone changes it to return `true` and 
we would get `declaresSameEntity(primary-template-1, primary-template-2) || 
true /*declaresSameEntity(null, null)*/` and start turning real ambiguities to 
warnings accidentally. It's useful to have a test that explicitly guards 
against that.

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


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov edited 
https://github.com/llvm/llvm-project/pull/72213
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Reapply Handle templated operators with reversed arguments (PR #72213)

2023-11-14 Thread Ilya Biryukov via cfe-commits

@@ -10088,9 +10088,13 @@ static bool allowAmbiguity(ASTContext &Context, const 
FunctionDecl *F1,
const FunctionDecl *F2) {
   if (declaresSameEntity(F1, F2))
 return true;
-  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation() &&
-  declaresSameEntity(F1->getPrimaryTemplate(), F2->getPrimaryTemplate())) {
-return true;
+  if (F1->isTemplateInstantiation() && F2->isTemplateInstantiation()) {
+auto PT1 = F1->getPrimaryTemplate();
+auto PT2 = F2->getPrimaryTemplate();
+if (declaresSameEntity(PT1, PT2) ||

ilya-biryukov wrote:

Also, I believe the crashes 
[here](https://buildkite.com/llvm-project/clang-ci/builds/6710#018bcc9e-fdcb-44f8-802e-f5e98303916c)
 are related: `getCommonPtr()` that you see in the stack trace is called  by 
`getInstantiatedFromMemberTemplate()`.

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


[clang] Supports viewing class member variables in lambda when using the vs debugger (PR #71564)

2023-11-14 Thread via cfe-commits
https://github.com/GkvJwa updated 
https://github.com/llvm/llvm-project/pull/71564

>From c014adafc88625e1f513494400f74a155f344cd4 Mon Sep 17 00:00:00 2001
From: GkvJwa 
Date: Wed, 8 Nov 2023 01:37:19 +0800
Subject: [PATCH] Supports viewing class member in lambda when using the vs
 debugger

Use "__this" in DataMemberRecord, make vs debugger can be parsed normally
---
 clang/lib/CodeGen/CGDebugInfo.cpp  |  4 +-
 clang/test/CodeGenCXX/lambda-this-info.cpp | 48 ++
 2 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/lambda-this-info.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..774bc0eae157f49 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1657,8 +1657,10 @@ void CGDebugInfo::CollectRecordLambdaFields(
   FieldDecl *f = *Field;
   llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
   QualType type = f->getType();
+  StringRef ThisName =
+  CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
   llvm::DIType *fieldType = createFieldType(
-  "this", type, f->getLocation(), f->getAccess(),
+  ThisName, type, f->getLocation(), f->getAccess(),
   layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
 
   elements.push_back(fieldType);
diff --git a/clang/test/CodeGenCXX/lambda-this-info.cpp 
b/clang/test/CodeGenCXX/lambda-this-info.cpp
new file mode 100644
index 000..4de4c69e6170c3c
--- /dev/null
+++ b/clang/test/CodeGenCXX/lambda-this-info.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -o %t.obj -- %s
+// RUN: llvm-pdbutil dump -all %t.obj | FileCheck %s
+
+class Foo {
+ public:
+  void foo() {
+int aa = 4;
+int bb = 5;
+int cc = 6;
+auto f = [=] {
+  int aaa = a + aa;
+  int bbb = b + bb;
+  int ccc = c + cc;
+};
+f();
+  }
+
+ private:
+  int a = 1;
+  int b = 2;
+  int c = 3;
+};
+
+int main() {
+  Foo f;
+  f.foo();
+
+  return 0;
+}
+
+// CHECK:   Types (.debug$T)
+// CHECK-NEXT: 
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_CLASS [size = 36] `Foo`
+// CHECK: unique name: `.?AVFoo@@`
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_FIELDLIST [size = 52]
+// CHECK: - LF_MEMBER [name = `a`, Type = 0x0074 (int), offset = 0, 
attrs = private]
+// CHECK: - LF_MEMBER [name = `b`, Type = 0x0074 (int), offset = 4, 
attrs = private]
+// CHECK: - LF_MEMBER [name = `c`, Type = 0x0074 (int), offset = 8, 
attrs = private]
+// CHECK: - LF_ONEMETHOD [name = `foo`]
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_POINTER [size = 12]
+// CHECK: referent = [[FooIndex:0x[^ ]*]], mode = pointer, opts = 
None, kind = ptr64
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_CLASS [size = 80] `Foo::foo::`
+// CHECK: unique name: `.?AV@?0??foo@Foo@@QEAAXXZ@`
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_FIELDLIST [size = 72]
+// CHECK: - LF_MEMBER [name = `__this`, Type = [[FooIndex:0x[^ ]*]], 
offset = 0, attrs = private]
+// CHECK: - LF_MEMBER [name = `aa`, Type = 0x0074 (int), offset = 8, 
attrs = private]
+// CHECK: - LF_MEMBER [name = `bb`, Type = 0x0074 (int), offset = 12, 
attrs = private]
+// CHECK: - LF_MEMBER [name = `cc`, Type = 0x0074 (int), offset = 16, 
attrs = private]

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


[llvm] [clang] [clang][AArch64] Pass down stack clash protection options to LLVM/Backend (PR #68993)

2023-11-14 Thread Sam Tebbs via cfe-commits
https://github.com/SamTebbs33 approved this pull request.

Looks good to me :+1: 

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


[clang] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-14 Thread via cfe-commits
https://github.com/thyecust created 
https://github.com/llvm/llvm-project/pull/72257

We can simplify this function and move some calculations out of loop.

>From 52b0204fec8394f9c2cfaeb3cc4f28e5d4c16170 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 21:51:55 +0800
Subject: [PATCH] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 1bf0d9aec8620e1..9c9e1a0fffb3c98 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;
 
-if (!TreatAllSuccessorsAsReachable) {
-  assert(PP);
-  TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
-}
-
-if (*TreatAllSuccessorsAsReachable) {
+if (TreatAllSuccessorsAsReachable) {
   B = UB;
-  break;
 }
   }
-  while (false);
 
   if (B) {
 unsigned blockID = B->getBlockID();

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


[clang] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-14 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: thyecust (thyecust)


Changes

We can simplify this function and move some calculations out of loop.

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


1 Files Affected:

- (modified) clang/lib/Analysis/ReachableCode.cpp (+9-12) 


``diff
diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 1bf0d9aec8620e1..9c9e1a0fffb3c98 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;
 
-if (!TreatAllSuccessorsAsReachable) {
-  assert(PP);
-  TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
-}
-
-if (*TreatAllSuccessorsAsReachable) {
+if (TreatAllSuccessorsAsReachable) {
   B = UB;
-  break;
 }
   }
-  while (false);
 
   if (B) {
 unsigned blockID = B->getBlockID();

``




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


[clang] Supports viewing class member variables in lambda when using the vs debugger (PR #71564)

2023-11-14 Thread via cfe-commits
https://github.com/GkvJwa updated 
https://github.com/llvm/llvm-project/pull/71564

>From 60fca5e4300aa88f18daa53f86b56a764834515a Mon Sep 17 00:00:00 2001
From: GkvJwa 
Date: Wed, 8 Nov 2023 01:37:19 +0800
Subject: [PATCH] Supports viewing class member in lambda when using the vs
 debugger

Use "__this" in the DataMemberRecord when generating pdb, so that the vs 
debugger can parse the  member vars in lambda normally
---
 clang/lib/CodeGen/CGDebugInfo.cpp  |  4 +-
 clang/test/CodeGenCXX/lambda-this-info.cpp | 48 ++
 2 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/lambda-this-info.cpp

diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 84a166d3ac3659c..774bc0eae157f49 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -1657,8 +1657,10 @@ void CGDebugInfo::CollectRecordLambdaFields(
   FieldDecl *f = *Field;
   llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
   QualType type = f->getType();
+  StringRef ThisName =
+  CGM.getCodeGenOpts().EmitCodeView ? "__this" : "this";
   llvm::DIType *fieldType = createFieldType(
-  "this", type, f->getLocation(), f->getAccess(),
+  ThisName, type, f->getLocation(), f->getAccess(),
   layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
 
   elements.push_back(fieldType);
diff --git a/clang/test/CodeGenCXX/lambda-this-info.cpp 
b/clang/test/CodeGenCXX/lambda-this-info.cpp
new file mode 100644
index 000..4de4c69e6170c3c
--- /dev/null
+++ b/clang/test/CodeGenCXX/lambda-this-info.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cl --target=x86_64-windows-msvc /c /Z7 -o %t.obj -- %s
+// RUN: llvm-pdbutil dump -all %t.obj | FileCheck %s
+
+class Foo {
+ public:
+  void foo() {
+int aa = 4;
+int bb = 5;
+int cc = 6;
+auto f = [=] {
+  int aaa = a + aa;
+  int bbb = b + bb;
+  int ccc = c + cc;
+};
+f();
+  }
+
+ private:
+  int a = 1;
+  int b = 2;
+  int c = 3;
+};
+
+int main() {
+  Foo f;
+  f.foo();
+
+  return 0;
+}
+
+// CHECK:   Types (.debug$T)
+// CHECK-NEXT: 
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_CLASS [size = 36] `Foo`
+// CHECK: unique name: `.?AVFoo@@`
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_FIELDLIST [size = 52]
+// CHECK: - LF_MEMBER [name = `a`, Type = 0x0074 (int), offset = 0, 
attrs = private]
+// CHECK: - LF_MEMBER [name = `b`, Type = 0x0074 (int), offset = 4, 
attrs = private]
+// CHECK: - LF_MEMBER [name = `c`, Type = 0x0074 (int), offset = 8, 
attrs = private]
+// CHECK: - LF_ONEMETHOD [name = `foo`]
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_POINTER [size = 12]
+// CHECK: referent = [[FooIndex:0x[^ ]*]], mode = pointer, opts = 
None, kind = ptr64
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_CLASS [size = 80] `Foo::foo::`
+// CHECK: unique name: `.?AV@?0??foo@Foo@@QEAAXXZ@`
+// CHECK:[[FooIndex:0x[^ ]*]] | LF_FIELDLIST [size = 72]
+// CHECK: - LF_MEMBER [name = `__this`, Type = [[FooIndex:0x[^ ]*]], 
offset = 0, attrs = private]
+// CHECK: - LF_MEMBER [name = `aa`, Type = 0x0074 (int), offset = 8, 
attrs = private]
+// CHECK: - LF_MEMBER [name = `bb`, Type = 0x0074 (int), offset = 12, 
attrs = private]
+// CHECK: - LF_MEMBER [name = `cc`, Type = 0x0074 (int), offset = 16, 
attrs = private]

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


[clang] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-14 Thread via cfe-commits
github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff daddf402d9a4e3bacc37098d990e56dc9957ca3e 
52b0204fec8394f9c2cfaeb3cc4f28e5d4c16170 -- clang/lib/Analysis/ReachableCode.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 9c9e1a0fff..257fb19e0f 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -345,7 +345,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 if (IncludeSometimesUnreachableEdges) {
   assert(PP);
   TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
+  shouldTreatSuccessorsAsReachable(item, *PP);
 } else {
   TreatAllSuccessorsAsReachable = false;
 }

``




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


[clang] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-14 Thread via cfe-commits
https://github.com/thyecust updated 
https://github.com/llvm/llvm-project/pull/72257

>From 52b0204fec8394f9c2cfaeb3cc4f28e5d4c16170 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 21:51:55 +0800
Subject: [PATCH 1/2] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 1bf0d9aec8620e1..9c9e1a0fffb3c98 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;
 
-if (!TreatAllSuccessorsAsReachable) {
-  assert(PP);
-  TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
-}
-
-if (*TreatAllSuccessorsAsReachable) {
+if (TreatAllSuccessorsAsReachable) {
   B = UB;
-  break;
 }
   }
-  while (false);
 
   if (B) {
 unsigned blockID = B->getBlockID();

>From e6ff52675af755e442ffd86906097271a7a3f596 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 22:01:14 +0800
Subject: [PATCH 2/2] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 9c9e1a0fffb3c98..0123730d8ff9798 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
-static bool isBuiltinUnreachable(const Stmt *S) {
+static isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
   return FDecl->getIdentifier() &&
@@ -345,7 +345,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 if (IncludeSometimesUnreachableEdges) {
   assert(PP);
   TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
+  shouldTreatSuccessorsAsReachable(item, *PP);
 } else {
   TreatAllSuccessorsAsReachable = false;
 }

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


[clang] [Sema] Check nullness of captured type before use (PR #72230)

2023-11-14 Thread Timm Baeder via cfe-commits

@@ -23,3 +23,9 @@ int pr43080(int i) { // expected-note {{declared here}}
   i; // expected-error {{variable 'i' cannot be implicitly captured in a 
lambda with no capture-default specified}}
   }();
 }
+
+void pr72198() {
+  int [_, b] = {0, 0}; // expected-error{{decomposition declaration cannot be 
declared with type 'int'; declared type must be 'auto' or reference to 'auto'}} 
\
+  expected-error{{excess elements in scalar 
initializer}}
+  [b]{}; // expected-warning{{expression result unused}}

tbaederr wrote:

```suggestion
  int [_, b] = {0, 0}; // expected-error {{decomposition declaration cannot be 
declared with type 'int'; declared type must be 'auto' or reference to 'auto'}} 
\
  expected-error {{excess elements in scalar 
initializer}}
  [b]{}; // expected-warning {{expression result unused}}
```

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


[clang] [clang][cleanup] simplify ReachableCode scanFromBlock (PR #72257)

2023-11-14 Thread via cfe-commits
https://github.com/thyecust updated 
https://github.com/llvm/llvm-project/pull/72257

>From 52b0204fec8394f9c2cfaeb3cc4f28e5d4c16170 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 21:51:55 +0800
Subject: [PATCH 1/3] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 21 +
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 1bf0d9aec8620e1..9c9e1a0fffb3c98 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -341,30 +341,27 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 // This allows us to potentially uncover some "always unreachable" code
 // within the "sometimes unreachable" code.
 // Look at the successors and mark then reachable.
-std::optional TreatAllSuccessorsAsReachable;
-if (!IncludeSometimesUnreachableEdges)
+bool TreatAllSuccessorsAsReachable;
+if (IncludeSometimesUnreachableEdges) {
+  assert(PP);
+  TreatAllSuccessorsAsReachable =
+shouldTreatSuccessorsAsReachable(item, *PP);
+} else {
   TreatAllSuccessorsAsReachable = false;
+}
 
 for (CFGBlock::const_succ_iterator I = item->succ_begin(),
  E = item->succ_end(); I != E; ++I) {
   const CFGBlock *B = *I;
-  if (!B) do {
+  if (!B) {
 const CFGBlock *UB = I->getPossiblyUnreachableBlock();
 if (!UB)
   break;
 
-if (!TreatAllSuccessorsAsReachable) {
-  assert(PP);
-  TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
-}
-
-if (*TreatAllSuccessorsAsReachable) {
+if (TreatAllSuccessorsAsReachable) {
   B = UB;
-  break;
 }
   }
-  while (false);
 
   if (B) {
 unsigned blockID = B->getBlockID();

>From e6ff52675af755e442ffd86906097271a7a3f596 Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 22:01:14 +0800
Subject: [PATCH 2/3] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 9c9e1a0fffb3c98..0123730d8ff9798 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
-static bool isBuiltinUnreachable(const Stmt *S) {
+static isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
   return FDecl->getIdentifier() &&
@@ -345,7 +345,7 @@ static unsigned scanFromBlock(const CFGBlock *Start,
 if (IncludeSometimesUnreachableEdges) {
   assert(PP);
   TreatAllSuccessorsAsReachable =
-shouldTreatSuccessorsAsReachable(item, *PP);
+  shouldTreatSuccessorsAsReachable(item, *PP);
 } else {
   TreatAllSuccessorsAsReachable = false;
 }

>From bcb3f98540cefc570432e541a929b61e9b89e08d Mon Sep 17 00:00:00 2001
From: thyecust 
Date: Tue, 14 Nov 2023 22:09:16 +0800
Subject: [PATCH 3/3] Update ReachableCode.cpp

---
 clang/lib/Analysis/ReachableCode.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/Analysis/ReachableCode.cpp 
b/clang/lib/Analysis/ReachableCode.cpp
index 0123730d8ff9798..257fb19e0fcfeb9 100644
--- a/clang/lib/Analysis/ReachableCode.cpp
+++ b/clang/lib/Analysis/ReachableCode.cpp
@@ -60,7 +60,7 @@ static bool isTrivialDoWhile(const CFGBlock *B, const Stmt 
*S) {
   return false;
 }
 
-static isBuiltinUnreachable(const Stmt *S) {
+static bool isBuiltinUnreachable(const Stmt *S) {
   if (const auto *DRE = dyn_cast(S))
 if (const auto *FDecl = dyn_cast(DRE->getDecl()))
   return FDecl->getIdentifier() &&

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


[clang] [clang] Use new interpreter in EvaluateAsConstantExpr if requested (PR #70763)

2023-11-14 Thread Aaron Ballman via cfe-commits

@@ -129,7 +129,13 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 
   /// Classifies a type.
   std::optional classify(const Expr *E) const {
-return E->isGLValue() ? PT_Ptr : classify(E->getType());
+if (E->isGLValue()) {
+  if (E->getType()->isFunctionType())
+return PT_FnPtr;
+  return PT_Ptr;
+}
+
+return classify(E->getType());

AaronBallman wrote:

This feels unrelated to the patch title; can you explain it a bit more? (It 
doesn't seem wrong, just not seeing how it ties to the test behavior changes.)

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


[clang] [clang][Interp] Fix stack peek offset for This ptr (PR #70663)

2023-11-14 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman approved this pull request.

LGTM

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


[clang] [clang][Interp] Fix variables refering to their own address (PR #70587)

2023-11-14 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman approved this pull request.

LGTM, lol, yes, everything is possible in C. :-D

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


[clang] [clang-tools-extra] [clang][AST] Fix crash in MatchChildASTVisitor::TraverseLambdaExpr (PR #70962)

2023-11-14 Thread Aaron Ballman via cfe-commits
AaronBallman wrote:

> * @AaronBallman Having a nullptr init capture seems fishy, do we actually 
> mean to allow capturing vla by reference here?

That does seem fishy to me -- I would expect VLA to behave the same as a 
constant-size array in terms of what we capture. So I think we do want to 
capture the VLA by reference (that's how we behave for constant-sized arrays).

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


[clang] [clang] Use new interpreter in EvaluateAsConstantExpr if requested (PR #70763)

2023-11-14 Thread Timm Baeder via cfe-commits

@@ -129,7 +129,13 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 
   /// Classifies a type.
   std::optional classify(const Expr *E) const {
-return E->isGLValue() ? PT_Ptr : classify(E->getType());
+if (E->isGLValue()) {
+  if (E->getType()->isFunctionType())
+return PT_FnPtr;
+  return PT_Ptr;
+}
+
+return classify(E->getType());

tbaederr wrote:

This is basically just an oversight;  This should've been added when we added 
function pointers. This case was just never exercised. I can tell you what test 
case trips this up as soon as my local build finished.

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


[clang] [clang] Use new interpreter in EvaluateAsConstantExpr if requested (PR #70763)

2023-11-14 Thread Aaron Ballman via cfe-commits

@@ -129,7 +129,13 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
 
   /// Classifies a type.
   std::optional classify(const Expr *E) const {
-return E->isGLValue() ? PT_Ptr : classify(E->getType());
+if (E->isGLValue()) {
+  if (E->getType()->isFunctionType())
+return PT_FnPtr;
+  return PT_Ptr;
+}
+
+return classify(E->getType());

AaronBallman wrote:

Ah, let's pull those changes from this PR and land them separately then.

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


[clang] [clang] Use new interpreter in EvaluateAsConstantExpr if requested (PR #70763)

2023-11-14 Thread Aaron Ballman via cfe-commits
https://github.com/AaronBallman approved this pull request.

LGTM with unrelated changes pulled; I'm fine landing this PR after landing the 
fix for the function pointer classification changes if necessary.

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


[PATCH] D148474: [Clang] Fix ResolveConstructorOverload to not select a conversion function if we are going use copy elision

2023-11-14 Thread Dimitry Andric via Phabricator via cfe-commits
dim accepted this revision.
dim added a comment.
This revision is now accepted and ready to land.

Yes, please. :)


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

https://reviews.llvm.org/D148474

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


[flang] [clang] [clang-tools-extra] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-14 Thread David Truby via cfe-commits
https://github.com/DavidTruby approved this pull request.

LGTM with a few small comments. Please wait for @jeanPerier to approve before 
merging.

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


[llvm] [clang] [flang] [clang-tools-extra] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-14 Thread David Truby via cfe-commits

@@ -13,6 +13,44 @@
 #include "flang/Runtime/command.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
+#include 

DavidTruby wrote:

We should use `cstring` instead of `string.h` and make sure all C standard 
functions are prefixed with `std::` since this is a C++ file

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


[flang] [llvm] [clang-tools-extra] [clang] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-14 Thread David Truby via cfe-commits

@@ -13,6 +13,44 @@
 #include "flang/Runtime/command.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
+#include 
+
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include 
+
+#include  // UNLEN=256
+#include  // wcstombs_s

DavidTruby wrote:

`cstdlib` instead of `stdlib.h`

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


[clang] [flang] [llvm] [clang-tools-extra] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-14 Thread David Truby via cfe-commits

@@ -37,5 +75,19 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
   (void)RTNAME(GetCommandArgument)(
   n, &value, nullptr, nullptr, __FILE__, __LINE__);
 }
+
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
+  std::array str;
+  int error = getlogin_r(str.data(), str.size());
+  assert(error == 0 && "getlogin_r returned an error");
+
+  // Trim space from right/end
+  int i = str.size();
+  while (' ' == str[--i]) {
+str[i] = 0;
+  }

DavidTruby wrote:

`std::replace(str.rbegin(), str.rend(), ' ', '\0');`
would be clearer I think?

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


[clang-tools-extra] [flang] [clang] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-14 Thread David Truby via cfe-commits

@@ -37,5 +75,19 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
   (void)RTNAME(GetCommandArgument)(
   n, &value, nullptr, nullptr, __FILE__, __LINE__);
 }
+
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
+  std::array str;
+  int error = getlogin_r(str.data(), str.size());
+  assert(error == 0 && "getlogin_r returned an error");
+
+  // Trim space from right/end
+  int i = str.size();
+  while (' ' == str[--i]) {
+str[i] = 0;
+  }
+  strncpy(reinterpret_cast(arg), str.data(), length);

DavidTruby wrote:

`std::strncpy`

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


[clang-tools-extra] [flang] [clang] [llvm] [flang ]GETLOG runtime and extension implementation: get login username (PR #70917)

2023-11-14 Thread David Truby via cfe-commits
https://github.com/DavidTruby edited 
https://github.com/llvm/llvm-project/pull/70917
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [flang] [clang] [llvm] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2023-11-14 Thread David Truby via cfe-commits
https://github.com/DavidTruby approved this pull request.

LGTM, maybe wait for @jeanPerier to check as well though. Thanks!

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


[clang] [clang] Add __has_feature(swiftcc) that checks whether the target supports the Swift calling convention (PR #72159)

2023-11-14 Thread Aaron Ballman via cfe-commits

@@ -99,6 +99,9 @@ FEATURE(memory_sanitizer,
 FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
 FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
 FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
+FEATURE(swiftcc,

AaronBallman wrote:

This is not a `FEATURE`, it's an `EXTENSION`: 
https://github.com/llvm/llvm-project/blob/33374c445d31bfe5b8c638900a09e85d5bc409ee/clang/include/clang/Basic/Features.def#L20

I think the other swift calling convention should be fixed at the same time, 
that looks like a simple oversight.

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


[clang] [clang] Add __has_feature(swiftcc) that checks whether the target supports the Swift calling convention (PR #72159)

2023-11-14 Thread Aaron Ballman via cfe-commits

@@ -99,6 +99,9 @@ FEATURE(memory_sanitizer,
 FEATURE(thread_sanitizer, LangOpts.Sanitize.has(SanitizerKind::Thread))
 FEATURE(dataflow_sanitizer, LangOpts.Sanitize.has(SanitizerKind::DataFlow))
 FEATURE(scudo, LangOpts.Sanitize.hasOneOf(SanitizerKind::Scudo))
+FEATURE(swiftcc,

AaronBallman wrote:

The changes also need to come with a test and a release note.

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


  1   2   3   4   5   >